OpenRCT2/src/openrct2-ui/windows/Multiplayer.cpp

1014 lines
37 KiB
C++
Raw Normal View History

2016-01-20 23:45:09 +01:00
/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 OpenRCT2 developers
2016-01-20 23:45:09 +01:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2016-01-20 23:45:09 +01:00
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-01-20 23:45:09 +01:00
*****************************************************************************/
2018-06-22 23:21:44 +02:00
#include <openrct2-ui/interface/Dropdown.h>
2018-01-03 00:13:37 +01:00
#include <openrct2-ui/interface/Widget.h>
2018-06-22 23:21:44 +02:00
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Game.h>
Split actions hpp files into separate h and cpp files (#13548) * Split up SmallSceneryPlace/Remove Added undo function for Remove Scenery * Refactor: Balloon and Banner actions hpp=>h/cpp * Refactor: rename all action *.hpp files to *.cpp This is preparation for separation in later commits. Note that without the complete set of commits in this branch, the code will not build. * Refactor Clear, Climate, Custom, and Footpath actions hpp=>h/cpp * VSCode: add src subdirectories to includePath * Refactor Guest actions hpp=>h/cpp * Refactor Land actions hpp=>h/cpp * Refactor LargeScenery actions hpp=>h/cpp * Refactor Load, Maze, Network actions hpp=>h/cpp * Refactor Park actions hpp=>h/cpp * Refactor/style: move private function declarations in actions *.h Previous action .h files included private function declarations with private member variables, before public function declarations. This commit re-orders the header files to the following order: - public member variables - private member variables - public functions - private functions * Refactor Pause action hpp=>h/cpp * Refactor Peep, Place, Player actions hpp=>h/cpp * Refactor Ride actions hpp=>h/cpp * Refactor Scenario, Set*, Sign* actions hpp=>h/cpp * Refactor SmallScenerySetColourAction hpp=>h/cpp * Refactor Staff actions hpp=>h/cpp * Refactor Surface, Tile, Track* actions hpp=>h/cpp * Refactor Wall and Water actions hpp=>h/cpp * Fix various includes and other compile errors Update includes for tests. Move static function declarations to .h files Add explicit includes to various files that were previously implicit (the required header was a nested include in an action hpp file, and the action .h file does not include that header) Move RideSetStatus string enum to the cpp file to avoid unused imports * Xcode: modify project file for actions refactor * Cleanup whitespace and end-of-file newlines Co-authored-by: duncanspumpkin <duncans_pumpkin@hotmail.co.uk>
2020-12-10 07:39:10 +01:00
#include <openrct2/actions/NetworkModifyGroupAction.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/config/Config.h>
#include <openrct2/drawing/Drawing.h>
2018-01-06 18:32:25 +01:00
#include <openrct2/localisation/Localisation.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/network/network.h>
#include <openrct2/sprites.h>
2017-12-13 13:02:24 +01:00
#include <openrct2/util/Util.h>
2016-01-20 23:45:09 +01:00
// clang-format off
2016-01-20 23:45:09 +01:00
enum {
WINDOW_MULTIPLAYER_PAGE_INFORMATION,
WINDOW_MULTIPLAYER_PAGE_PLAYERS,
WINDOW_MULTIPLAYER_PAGE_GROUPS,
WINDOW_MULTIPLAYER_PAGE_OPTIONS
2016-01-20 23:45:09 +01:00
};
enum WINDOW_MULTIPLAYER_WIDGET_IDX {
WIDX_BACKGROUND,
WIDX_TITLE,
WIDX_CLOSE,
WIDX_CONTENT_PANEL,
WIDX_TAB1,
WIDX_TAB2,
WIDX_TAB3,
WIDX_TAB4,
WIDX_HEADER_PLAYER = 8,
WIDX_HEADER_GROUP,
WIDX_HEADER_LAST_ACTION,
WIDX_HEADER_PING,
WIDX_LIST,
WIDX_DEFAULT_GROUP = 8,
WIDX_DEFAULT_GROUP_DROPDOWN,
WIDX_ADD_GROUP,
WIDX_REMOVE_GROUP,
WIDX_RENAME_GROUP,
WIDX_SELECTED_GROUP,
WIDX_SELECTED_GROUP_DROPDOWN,
WIDX_PERMISSIONS_LIST,
WIDX_LOG_CHAT_CHECKBOX = 8,
WIDX_LOG_SERVER_ACTIONS_CHECKBOX,
WIDX_KNOWN_KEYS_ONLY_CHECKBOX,
2016-01-20 23:45:09 +01:00
};
#define MAIN_MULTIPLAYER_WIDGETS \
MakeWidget({ 0, 0}, {340, 240}, WindowWidgetType::Frame, WindowColour::Primary ), /* panel / background */ \
MakeWidget({ 1, 1}, {338, 14}, WindowWidgetType::Caption, WindowColour::Primary, STR_NONE, STR_WINDOW_TITLE_TIP ), /* title bar */ \
MakeWidget({327, 2}, { 11, 12}, WindowWidgetType::CloseBox, WindowColour::Primary, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP ), /* close x button */ \
MakeWidget({ 0, 43}, {340, 197}, WindowWidgetType::Resize, WindowColour::Secondary ), /* content panel */ \
MakeTab ({ 3, 17}, STR_SHOW_SERVER_INFO_TIP), /* tab */ \
MakeTab ({ 34, 17}, STR_PLAYERS_TIP ), /* tab */ \
MakeTab ({ 65, 17}, STR_GROUPS_TIP ), /* tab */ \
MakeTab ({ 96, 17}, STR_OPTIONS_TIP ) /* tab */
2016-05-30 21:54:50 +02:00
static rct_widget window_multiplayer_information_widgets[] = {
MAIN_MULTIPLAYER_WIDGETS,
{ WIDGETS_END }
2016-05-30 21:54:50 +02:00
};
2016-01-20 23:45:09 +01:00
static rct_widget window_multiplayer_players_widgets[] = {
MAIN_MULTIPLAYER_WIDGETS,
MakeWidget({ 3, 46}, {173, 15}, WindowWidgetType::TableHeader, WindowColour::Primary , STR_PLAYER ), // Player name
MakeWidget({176, 46}, { 83, 15}, WindowWidgetType::TableHeader, WindowColour::Primary , STR_GROUP ), // Player name
MakeWidget({259, 46}, {100, 15}, WindowWidgetType::TableHeader, WindowColour::Primary , STR_LAST_ACTION), // Player name
MakeWidget({359, 46}, { 42, 15}, WindowWidgetType::TableHeader, WindowColour::Primary , STR_PING ), // Player name
MakeWidget({ 3, 60}, {334, 177}, WindowWidgetType::Scroll, WindowColour::Secondary, SCROLL_VERTICAL), // list
{ WIDGETS_END }
2016-01-20 23:45:09 +01:00
};
static rct_widget window_multiplayer_groups_widgets[] = {
MAIN_MULTIPLAYER_WIDGETS,
MakeWidget({141, 46}, {175, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // default group
MakeWidget({305, 47}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH),
MakeWidget({ 11, 65}, { 92, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_ADD_GROUP ), // add group button
MakeWidget({113, 65}, { 92, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_REMOVE_GROUP ), // remove group button
MakeWidget({215, 65}, { 92, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_RENAME_GROUP ), // rename group button
MakeWidget({ 72, 80}, {175, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // selected group
MakeWidget({236, 81}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH),
MakeWidget({ 3, 94}, {314, 207}, WindowWidgetType::Scroll, WindowColour::Secondary, SCROLL_VERTICAL ), // permissions list
{ WIDGETS_END }
};
static rct_widget window_multiplayer_options_widgets[] = {
MAIN_MULTIPLAYER_WIDGETS,
MakeWidget({3, 50}, {295, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_LOG_CHAT, STR_LOG_CHAT_TIP ),
MakeWidget({3, 64}, {295, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_LOG_SERVER_ACTIONS, STR_LOG_SERVER_ACTIONS_TIP ),
MakeWidget({3, 78}, {295, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_ALLOW_KNOWN_KEYS_ONLY, STR_ALLOW_KNOWN_KEYS_ONLY_TIP),
{ WIDGETS_END }
2016-01-20 23:45:09 +01:00
};
static rct_widget *window_multiplayer_page_widgets[] = {
window_multiplayer_information_widgets,
window_multiplayer_players_widgets,
window_multiplayer_groups_widgets,
window_multiplayer_options_widgets
2016-01-20 23:45:09 +01:00
};
2016-11-13 20:17:49 +01:00
static constexpr const uint64_t window_multiplayer_page_enabled_widgets[] = {
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_TAB4),
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_TAB4),
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_TAB4) | (1 << WIDX_DEFAULT_GROUP) | (1 << WIDX_DEFAULT_GROUP_DROPDOWN) | (1 << WIDX_ADD_GROUP) | (1 << WIDX_REMOVE_GROUP) | (1 << WIDX_RENAME_GROUP) | (1 << WIDX_SELECTED_GROUP) | (1 << WIDX_SELECTED_GROUP_DROPDOWN),
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_TAB4) | (1 << WIDX_LOG_CHAT_CHECKBOX) | (1 << WIDX_LOG_SERVER_ACTIONS_CHECKBOX) | (1 << WIDX_KNOWN_KEYS_ONLY_CHECKBOX),
2016-01-20 23:45:09 +01:00
};
static constexpr rct_string_id WindowMultiplayerPageTitles[] = {
STR_MULTIPLAYER_INFORMATION_TITLE,
STR_MULTIPLAYER_PLAYERS_TITLE,
STR_MULTIPLAYER_GROUPS_TITLE,
STR_MULTIPLAYER_OPTIONS_TITLE,
};
static uint8_t _selectedGroup = 0;
2017-05-01 15:41:45 +02:00
static void window_multiplayer_information_mouseup(rct_window *w, rct_widgetindex widgetIndex);
2016-05-30 21:54:50 +02:00
static void window_multiplayer_information_resize(rct_window *w);
static void window_multiplayer_information_update(rct_window *w);
static void window_multiplayer_information_invalidate(rct_window *w);
static void window_multiplayer_information_paint(rct_window *w, rct_drawpixelinfo *dpi);
2017-05-01 15:41:45 +02:00
static void window_multiplayer_players_mouseup(rct_window *w, rct_widgetindex widgetIndex);
2016-01-20 23:45:09 +01:00
static void window_multiplayer_players_resize(rct_window *w);
static void window_multiplayer_players_update(rct_window *w);
static void window_multiplayer_players_scrollgetsize(rct_window *w, int32_t scrollIndex, int32_t *width, int32_t *height);
static void window_multiplayer_players_scrollmousedown(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
static void window_multiplayer_players_scrollmouseover(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
2016-01-20 23:45:09 +01:00
static void window_multiplayer_players_invalidate(rct_window *w);
static void window_multiplayer_players_paint(rct_window *w, rct_drawpixelinfo *dpi);
static void window_multiplayer_players_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex);
2016-01-20 23:45:09 +01:00
2017-05-01 15:41:45 +02:00
static void window_multiplayer_groups_mouseup(rct_window *w, rct_widgetindex widgetIndex);
2016-01-20 23:45:09 +01:00
static void window_multiplayer_groups_resize(rct_window *w);
static void window_multiplayer_groups_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget);
static void window_multiplayer_groups_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
2016-01-20 23:45:09 +01:00
static void window_multiplayer_groups_update(rct_window *w);
static void window_multiplayer_groups_scrollgetsize(rct_window *w, int32_t scrollIndex, int32_t *width, int32_t *height);
static void window_multiplayer_groups_scrollmousedown(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
static void window_multiplayer_groups_scrollmouseover(rct_window *w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords);
2017-05-01 15:41:45 +02:00
static void window_multiplayer_groups_text_input(rct_window *w, rct_widgetindex widgetIndex, char *text);
2016-01-20 23:45:09 +01:00
static void window_multiplayer_groups_invalidate(rct_window *w);
static void window_multiplayer_groups_paint(rct_window *w, rct_drawpixelinfo *dpi);
static void window_multiplayer_groups_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex);
2016-01-20 23:45:09 +01:00
2017-05-01 15:41:45 +02:00
static void window_multiplayer_options_mouseup(rct_window *w, rct_widgetindex widgetIndex);
static void window_multiplayer_options_resize(rct_window *w);
static void window_multiplayer_options_update(rct_window *w);
static void window_multiplayer_options_invalidate(rct_window *w);
static void window_multiplayer_options_paint(rct_window *w, rct_drawpixelinfo *dpi);
static rct_window_event_list window_multiplayer_information_events([](auto& events)
{
events.mouse_up = &window_multiplayer_information_mouseup;
events.resize = &window_multiplayer_information_resize;
events.update = &window_multiplayer_information_update;
events.invalidate = &window_multiplayer_information_invalidate;
events.paint = &window_multiplayer_information_paint;
});
static rct_window_event_list window_multiplayer_players_events([](auto& events)
{
events.mouse_up = &window_multiplayer_players_mouseup;
events.resize = &window_multiplayer_players_resize;
events.update = &window_multiplayer_players_update;
events.get_scroll_size = &window_multiplayer_players_scrollgetsize;
events.scroll_mousedown = &window_multiplayer_players_scrollmousedown;
events.scroll_mouseover = &window_multiplayer_players_scrollmouseover;
events.invalidate = &window_multiplayer_players_invalidate;
events.paint = &window_multiplayer_players_paint;
events.scroll_paint = &window_multiplayer_players_scrollpaint;
});
static rct_window_event_list window_multiplayer_groups_events([](auto& events)
{
events.mouse_up = &window_multiplayer_groups_mouseup;
events.resize = &window_multiplayer_groups_resize;
events.mouse_down = &window_multiplayer_groups_mousedown;
events.dropdown = &window_multiplayer_groups_dropdown;
events.update = &window_multiplayer_groups_update;
events.get_scroll_size = &window_multiplayer_groups_scrollgetsize;
events.scroll_mousedown = &window_multiplayer_groups_scrollmousedown;
events.scroll_mouseover = &window_multiplayer_groups_scrollmouseover;
events.text_input = &window_multiplayer_groups_text_input;
events.invalidate = &window_multiplayer_groups_invalidate;
events.paint = &window_multiplayer_groups_paint;
events.scroll_paint = &window_multiplayer_groups_scrollpaint;
});
static rct_window_event_list window_multiplayer_options_events([](auto& events)
{
events.mouse_up = &window_multiplayer_options_mouseup;
events.resize = &window_multiplayer_options_resize;
events.update = &window_multiplayer_options_update;
events.invalidate = &window_multiplayer_options_invalidate;
events.paint = &window_multiplayer_options_paint;
});
2016-01-20 23:45:09 +01:00
static rct_window_event_list *window_multiplayer_page_events[] = {
&window_multiplayer_information_events,
&window_multiplayer_players_events,
&window_multiplayer_groups_events,
&window_multiplayer_options_events
2016-01-20 23:45:09 +01:00
};
// clang-format on
2016-01-20 23:45:09 +01:00
static constexpr const int32_t window_multiplayer_animation_divisor[] = { 4, 4, 2, 2 };
static constexpr const int32_t window_multiplayer_animation_frames[] = { 8, 8, 7, 4 };
2016-01-20 23:45:09 +01:00
2018-06-22 23:21:44 +02:00
static void window_multiplayer_draw_tab_images(rct_window* w, rct_drawpixelinfo* dpi);
static void window_multiplayer_set_page(rct_window* w, int32_t page);
2016-01-20 23:45:09 +01:00
2016-05-30 21:54:50 +02:00
static bool _windowInformationSizeDirty;
static ScreenCoordsXY _windowInformationSize;
2016-05-30 21:54:50 +02:00
2018-06-22 23:21:44 +02:00
rct_window* window_multiplayer_open()
2016-01-20 23:45:09 +01:00
{
// Check if window is already open
2018-06-22 23:21:44 +02:00
rct_window* window = window_bring_to_front_by_class(WC_MULTIPLAYER);
if (window == nullptr)
{
window = WindowCreateAutoPos(320, 144, &window_multiplayer_players_events, WC_MULTIPLAYER, WF_10 | WF_RESIZABLE);
window_multiplayer_set_page(window, WINDOW_MULTIPLAYER_PAGE_INFORMATION);
}
2017-08-06 05:22:00 +02:00
return window;
2016-01-20 23:45:09 +01:00
}
static void window_multiplayer_set_page(rct_window* w, int32_t page)
2016-05-30 21:54:50 +02:00
{
_windowInformationSizeDirty = true;
2016-05-30 21:54:50 +02:00
w->page = page;
w->frame_no = 0;
w->no_list_items = 0;
w->selected_list_item = -1;
2016-01-20 23:45:09 +01:00
w->enabled_widgets = window_multiplayer_page_enabled_widgets[page];
w->hold_down_widgets = 0;
w->event_handlers = window_multiplayer_page_events[page];
w->pressed_widgets = 0;
w->widgets = window_multiplayer_page_widgets[page];
w->widgets[WIDX_TITLE].text = WindowMultiplayerPageTitles[page];
window_event_resize_call(w);
window_event_invalidate_call(w);
WindowInitScrollWidgets(w);
w->Invalidate();
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_anchor_border_widgets(rct_window* w)
2016-01-20 23:45:09 +01:00
{
w->widgets[WIDX_BACKGROUND].right = w->width - 1;
w->widgets[WIDX_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_TITLE].right = w->width - 2;
w->widgets[WIDX_CONTENT_PANEL].right = w->width - 1;
w->widgets[WIDX_CONTENT_PANEL].bottom = w->height - 1;
w->widgets[WIDX_CLOSE].left = w->width - 13;
w->widgets[WIDX_CLOSE].right = w->width - 3;
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_set_pressed_tab(rct_window* w)
2016-01-20 23:45:09 +01:00
{
2018-06-22 23:21:44 +02:00
for (int32_t i = 0; i < 2; i++)
{
w->pressed_widgets &= ~(1 << (WIDX_TAB1 + i));
}
w->pressed_widgets |= 1LL << (WIDX_TAB1 + w->page);
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_show_group_dropdown(rct_window* w, rct_widget* widget)
2016-01-20 23:45:09 +01:00
{
2018-06-22 23:21:44 +02:00
rct_widget* dropdownWidget;
int32_t numItems, i;
2016-01-20 23:45:09 +01:00
dropdownWidget = widget - 1;
2016-01-20 23:45:09 +01:00
numItems = network_get_num_groups();
2016-01-20 23:45:09 +01:00
WindowDropdownShowTextCustomWidth(
{ w->windowPos.x + dropdownWidget->left, w->windowPos.y + dropdownWidget->top }, dropdownWidget->height() + 1,
w->colours[1], 0, 0, numItems, widget->right - dropdownWidget->left);
2016-01-20 23:45:09 +01:00
2018-06-22 23:21:44 +02:00
for (i = 0; i < network_get_num_groups(); i++)
{
gDropdownItemsFormat[i] = STR_OPTIONS_DROPDOWN_ITEM;
gDropdownItemsArgs[i] = reinterpret_cast<uintptr_t>(network_get_group_name(i));
}
2018-06-22 23:21:44 +02:00
if (widget == &window_multiplayer_groups_widgets[WIDX_DEFAULT_GROUP_DROPDOWN])
{
Dropdown::SetChecked(network_get_group_index(network_get_default_group()), true);
2018-06-22 23:21:44 +02:00
}
else if (widget == &window_multiplayer_groups_widgets[WIDX_SELECTED_GROUP_DROPDOWN])
{
Dropdown::SetChecked(network_get_group_index(_selectedGroup), true);
}
2016-01-20 23:45:09 +01:00
}
2016-05-30 21:54:50 +02:00
#pragma region Information page
2018-06-22 23:21:44 +02:00
static void window_multiplayer_information_mouseup(rct_window* w, rct_widgetindex widgetIndex)
{
switch (widgetIndex)
{
case WIDX_CLOSE:
window_close(w);
break;
case WIDX_TAB1:
case WIDX_TAB2:
case WIDX_TAB3:
case WIDX_TAB4:
if (w->page != widgetIndex - WIDX_TAB1)
{
window_multiplayer_set_page(w, widgetIndex - WIDX_TAB1);
}
break;
}
2016-05-30 21:54:50 +02:00
}
static ScreenCoordsXY window_multiplayer_information_get_size()
2016-05-30 21:54:50 +02:00
{
2018-06-22 23:21:44 +02:00
if (!_windowInformationSizeDirty)
{
return _windowInformationSize;
}
2016-05-30 21:54:50 +02:00
int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM);
// Base dimensions.
const int32_t width = 450;
int32_t height = 55;
int32_t numLines;
// Server name is displayed word-wrapped, so figure out how high it will be.
{
utf8* buffer = _strdup(network_get_server_name());
gfx_wrap_string(buffer, width, FontSpriteBase::MEDIUM, &numLines);
free(buffer);
height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2);
}
// Likewise, for the optional server description -- which can be a little longer.
const utf8* descString = network_get_server_description();
if (!str_is_null_or_empty(descString))
{
utf8* buffer = _strdup(descString);
gfx_wrap_string(buffer, width, FontSpriteBase::MEDIUM, &numLines);
free(buffer);
height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2);
}
// Finally, account for provider info, if present.
{
const utf8* providerName = network_get_server_provider_name();
if (!str_is_null_or_empty(providerName))
height += LIST_ROW_HEIGHT;
const utf8* providerEmail = network_get_server_provider_email();
if (!str_is_null_or_empty(providerEmail))
height += LIST_ROW_HEIGHT;
const utf8* providerWebsite = network_get_server_provider_website();
if (!str_is_null_or_empty(providerWebsite))
height += LIST_ROW_HEIGHT;
}
2016-05-30 21:54:50 +02:00
_windowInformationSizeDirty = false;
_windowInformationSize = { static_cast<int16_t>(width), static_cast<int16_t>(height) };
return _windowInformationSize;
2016-05-30 21:54:50 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_information_resize(rct_window* w)
2016-05-30 21:54:50 +02:00
{
auto size = window_multiplayer_information_get_size();
window_set_resize(w, size.x, size.y, size.x, size.y);
2016-05-30 21:54:50 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_information_update(rct_window* w)
2016-05-30 21:54:50 +02:00
{
w->frame_no++;
widget_invalidate(w, WIDX_TAB1 + w->page);
2016-05-30 21:54:50 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_information_invalidate(rct_window* w)
2016-05-30 21:54:50 +02:00
{
window_multiplayer_set_pressed_tab(w);
window_multiplayer_anchor_border_widgets(w);
window_align_tabs(w, WIDX_TAB1, WIDX_TAB4);
2016-05-30 21:54:50 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_information_paint(rct_window* w, rct_drawpixelinfo* dpi)
2016-05-30 21:54:50 +02:00
{
WindowDrawWidgets(w, dpi);
window_multiplayer_draw_tab_images(w, dpi);
rct_drawpixelinfo clippedDPI;
if (clip_drawpixelinfo(&clippedDPI, dpi, w->windowPos, w->width, w->height))
2018-06-22 23:21:44 +02:00
{
dpi = &clippedDPI;
auto screenCoords = ScreenCoordsXY{ 3, 50 };
int32_t width = w->width - 6;
2018-06-22 23:21:44 +02:00
const utf8* name = network_get_server_name();
{
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, width, STR_STRING, static_cast<void*>(&name), { w->colours[1] });
screenCoords.y += LIST_ROW_HEIGHT / 2;
}
2018-06-22 23:21:44 +02:00
const utf8* description = network_get_server_description();
if (!str_is_null_or_empty(description))
{
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, width, STR_STRING, static_cast<void*>(&description), { w->colours[1] });
screenCoords.y += LIST_ROW_HEIGHT / 2;
}
2018-06-22 23:21:44 +02:00
const utf8* providerName = network_get_server_provider_name();
if (!str_is_null_or_empty(providerName))
{
DrawTextBasic(dpi, screenCoords, STR_PROVIDER_NAME, static_cast<void*>(&providerName));
screenCoords.y += LIST_ROW_HEIGHT;
}
2018-06-22 23:21:44 +02:00
const utf8* providerEmail = network_get_server_provider_email();
if (!str_is_null_or_empty(providerEmail))
{
DrawTextBasic(dpi, screenCoords, STR_PROVIDER_EMAIL, static_cast<void*>(&providerEmail));
screenCoords.y += LIST_ROW_HEIGHT;
}
2018-06-22 23:21:44 +02:00
const utf8* providerWebsite = network_get_server_provider_website();
if (!str_is_null_or_empty(providerWebsite))
{
DrawTextBasic(dpi, screenCoords, STR_PROVIDER_WEBSITE, static_cast<void*>(&providerWebsite));
}
}
2016-05-30 21:54:50 +02:00
}
#pragma endregion
#pragma region Players page
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_mouseup(rct_window* w, rct_widgetindex widgetIndex)
{
switch (widgetIndex)
{
case WIDX_CLOSE:
window_close(w);
break;
case WIDX_TAB1:
case WIDX_TAB2:
case WIDX_TAB3:
case WIDX_TAB4:
if (w->page != widgetIndex - WIDX_TAB1)
{
window_multiplayer_set_page(w, widgetIndex - WIDX_TAB1);
}
break;
}
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_resize(rct_window* w)
2016-01-20 23:45:09 +01:00
{
window_set_resize(w, 420, 124, 500, 450);
2016-01-20 23:45:09 +01:00
w->no_list_items = network_get_num_players();
w->list_item_positions[0] = 0;
w->widgets[WIDX_HEADER_PING].right = w->width - 5;
w->selected_list_item = -1;
w->Invalidate();
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_update(rct_window* w)
2016-01-20 23:45:09 +01:00
{
w->frame_no++;
widget_invalidate(w, WIDX_TAB1 + w->page);
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height)
2016-01-20 23:45:09 +01:00
{
int32_t i;
2016-01-20 23:45:09 +01:00
2018-06-22 23:21:44 +02:00
if (w->selected_list_item != -1)
{
w->selected_list_item = -1;
w->Invalidate();
}
2016-01-20 23:45:09 +01:00
*height = network_get_num_players() * SCROLLABLE_ROW_HEIGHT;
i = *height - window_multiplayer_players_widgets[WIDX_LIST].bottom + window_multiplayer_players_widgets[WIDX_LIST].top + 21;
if (i < 0)
i = 0;
2018-06-22 23:21:44 +02:00
if (i < w->scrolls[0].v_top)
{
w->scrolls[0].v_top = i;
w->Invalidate();
}
2016-01-20 23:45:09 +01:00
}
static void window_multiplayer_players_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
2016-01-20 23:45:09 +01:00
{
int32_t index;
2016-01-20 23:45:09 +01:00
index = screenCoords.y / SCROLLABLE_ROW_HEIGHT;
if (index >= w->no_list_items)
return;
2016-01-20 23:45:09 +01:00
w->selected_list_item = index;
w->Invalidate();
2016-01-20 23:45:09 +01:00
window_player_open(network_get_player_id(index));
2016-01-20 23:45:09 +01:00
}
static void window_multiplayer_players_scrollmouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
2016-01-20 23:45:09 +01:00
{
int32_t index;
2016-01-20 23:45:09 +01:00
index = screenCoords.y / SCROLLABLE_ROW_HEIGHT;
if (index >= w->no_list_items)
return;
2016-01-20 23:45:09 +01:00
w->selected_list_item = index;
w->Invalidate();
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_invalidate(rct_window* w)
2016-01-20 23:45:09 +01:00
{
window_multiplayer_set_pressed_tab(w);
window_multiplayer_anchor_border_widgets(w);
window_multiplayer_players_widgets[WIDX_LIST].right = w->width - 4;
window_multiplayer_players_widgets[WIDX_LIST].bottom = w->height - 0x0F;
window_align_tabs(w, WIDX_TAB1, WIDX_TAB4);
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_paint(rct_window* w, rct_drawpixelinfo* dpi)
2016-01-20 23:45:09 +01:00
{
rct_string_id stringId;
2016-01-20 23:45:09 +01:00
WindowDrawWidgets(w, dpi);
window_multiplayer_draw_tab_images(w, dpi);
2016-01-20 23:45:09 +01:00
// Number of players
stringId = w->no_list_items == 1 ? STR_MULTIPLAYER_PLAYER_COUNT : STR_MULTIPLAYER_PLAYER_COUNT_PLURAL;
auto screenCoords = w->windowPos + ScreenCoordsXY{ 4, w->widgets[WIDX_LIST].bottom + 2 };
DrawTextBasic(dpi, screenCoords, stringId, &w->no_list_items, { w->colours[2] });
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_players_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
2016-01-20 23:45:09 +01:00
{
ScreenCoordsXY screenCoords;
screenCoords.y = 0;
2018-06-22 23:21:44 +02:00
for (int32_t i = 0; i < network_get_num_players(); i++)
{
if (screenCoords.y > dpi->y + dpi->height)
2018-06-22 23:21:44 +02:00
{
break;
}
if (screenCoords.y + SCROLLABLE_ROW_HEIGHT + 1 >= dpi->y)
{
2020-10-14 00:34:18 +02:00
thread_local std::string buffer;
buffer.reserve(512);
buffer.clear();
// Draw player name
colour_t colour = COLOUR_BLACK;
if (i == w->selected_list_item)
{
gfx_filter_rect(
dpi, 0, screenCoords.y, 800, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1, FilterPaletteID::PaletteDarken1);
2020-10-14 00:34:18 +02:00
buffer += network_get_player_name(i);
colour = w->colours[2];
}
else
{
2018-06-22 23:21:44 +02:00
if (network_get_player_flags(i) & NETWORK_PLAYER_FLAG_ISSERVER)
{
2020-10-14 00:34:18 +02:00
buffer += "{BABYBLUE}";
2018-06-22 23:21:44 +02:00
}
else
{
2020-10-14 00:34:18 +02:00
buffer += "{BLACK}";
}
2020-10-14 00:34:18 +02:00
buffer += network_get_player_name(i);
}
screenCoords.x = 0;
gfx_clip_string(buffer.data(), 230, FontSpriteBase::MEDIUM);
gfx_draw_string(dpi, screenCoords, buffer.c_str(), { colour });
// Draw group name
2020-10-14 00:34:18 +02:00
buffer.resize(0);
int32_t group = network_get_group_index(network_get_player_group(i));
2018-06-22 23:21:44 +02:00
if (group != -1)
{
2020-10-14 00:34:18 +02:00
buffer += "{BLACK}";
screenCoords.x = 173;
2020-10-14 00:34:18 +02:00
buffer += network_get_group_name(group);
gfx_clip_string(buffer.data(), 80, FontSpriteBase::MEDIUM);
gfx_draw_string(dpi, screenCoords, buffer.c_str(), { colour });
}
// Draw last action
int32_t action = network_get_player_last_action(i, 2000);
auto ft = Formatter();
2018-06-22 23:21:44 +02:00
if (action != -999)
{
ft.Add<rct_string_id>(network_get_action_name_string_id(action));
}
else
{
ft.Add<rct_string_id>(STR_ACTION_NA);
}
DrawTextEllipsised(dpi, { 256, screenCoords.y }, 100, STR_BLACK_STRING, ft);
// Draw ping
2020-10-14 00:34:18 +02:00
buffer.resize(0);
int32_t ping = network_get_player_ping(i);
2018-06-22 23:21:44 +02:00
if (ping <= 100)
{
2020-10-14 00:34:18 +02:00
buffer += "{GREEN}";
2018-06-22 23:21:44 +02:00
}
else if (ping <= 250)
{
2020-10-14 00:34:18 +02:00
buffer += "{YELLOW}";
2018-06-22 23:21:44 +02:00
}
else
{
2020-10-14 00:34:18 +02:00
buffer += "{RED}";
}
2020-10-14 00:34:18 +02:00
char pingBuffer[64]{};
snprintf(pingBuffer, sizeof(pingBuffer), "%d ms", ping);
buffer += pingBuffer;
screenCoords.x = 356;
gfx_draw_string(dpi, screenCoords, buffer.c_str(), { colour });
}
screenCoords.y += SCROLLABLE_ROW_HEIGHT;
}
2016-01-20 23:45:09 +01:00
}
#pragma endregion
#pragma region Groups page
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_mouseup(rct_window* w, rct_widgetindex widgetIndex)
{
switch (widgetIndex)
{
case WIDX_CLOSE:
window_close(w);
break;
case WIDX_TAB1:
case WIDX_TAB2:
case WIDX_TAB3:
case WIDX_TAB4:
if (w->page != widgetIndex - WIDX_TAB1)
{
window_multiplayer_set_page(w, widgetIndex - WIDX_TAB1);
}
break;
case WIDX_ADD_GROUP:
{
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::AddGroup);
GameActions::Execute(&networkModifyGroup);
}
break;
2018-06-22 23:21:44 +02:00
case WIDX_REMOVE_GROUP:
{
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, _selectedGroup);
GameActions::Execute(&networkModifyGroup);
}
break;
2018-06-22 23:21:44 +02:00
case WIDX_RENAME_GROUP:;
int32_t groupIndex = network_get_group_index(_selectedGroup);
const utf8* groupName = network_get_group_name(groupIndex);
window_text_input_raw_open(w, widgetIndex, STR_GROUP_NAME, STR_ENTER_NEW_NAME_FOR_THIS_GROUP, groupName, 32);
2018-06-22 23:21:44 +02:00
break;
}
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_resize(rct_window* w)
2016-01-20 23:45:09 +01:00
{
window_set_resize(w, 320, 200, 320, 500);
w->no_list_items = network_get_num_actions();
w->list_item_positions[0] = 0;
w->selected_list_item = -1;
w->Invalidate();
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget)
2016-01-20 23:45:09 +01:00
{
2018-06-22 23:21:44 +02:00
switch (widgetIndex)
{
case WIDX_DEFAULT_GROUP_DROPDOWN:
window_multiplayer_groups_show_group_dropdown(w, widget);
break;
case WIDX_SELECTED_GROUP_DROPDOWN:
window_multiplayer_groups_show_group_dropdown(w, widget);
break;
}
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_dropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex)
2016-01-20 23:45:09 +01:00
{
2018-06-22 23:21:44 +02:00
if (dropdownIndex == -1)
{
return;
}
2018-06-22 23:21:44 +02:00
switch (widgetIndex)
{
case WIDX_DEFAULT_GROUP_DROPDOWN:
{
auto networkModifyGroup = NetworkModifyGroupAction(
ModifyGroupType::SetDefault, network_get_group_id(dropdownIndex));
GameActions::Execute(&networkModifyGroup);
}
break;
2018-06-22 23:21:44 +02:00
case WIDX_SELECTED_GROUP_DROPDOWN:
_selectedGroup = network_get_group_id(dropdownIndex);
break;
}
w->Invalidate();
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_update(rct_window* w)
2016-01-20 23:45:09 +01:00
{
w->frame_no++;
widget_invalidate(w, WIDX_TAB1 + w->page);
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height)
{
int32_t i;
2018-06-22 23:21:44 +02:00
if (w->selected_list_item != -1)
{
w->selected_list_item = -1;
w->Invalidate();
}
*height = network_get_num_actions() * SCROLLABLE_ROW_HEIGHT;
i = *height - window_multiplayer_groups_widgets[WIDX_LIST].bottom + window_multiplayer_groups_widgets[WIDX_LIST].top + 21;
if (i < 0)
i = 0;
2018-06-22 23:21:44 +02:00
if (i < w->scrolls[0].v_top)
{
w->scrolls[0].v_top = i;
w->Invalidate();
}
}
static void window_multiplayer_groups_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
{
int32_t index;
index = screenCoords.y / SCROLLABLE_ROW_HEIGHT;
if (index >= w->no_list_items)
return;
w->selected_list_item = index;
w->Invalidate();
2019-05-13 20:53:33 +02:00
auto networkModifyGroup = NetworkModifyGroupAction(
ModifyGroupType::SetPermissions, _selectedGroup, "", index, PermissionState::Toggle);
GameActions::Execute(&networkModifyGroup);
}
static void window_multiplayer_groups_scrollmouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
{
int32_t index;
index = screenCoords.y / SCROLLABLE_ROW_HEIGHT;
if (index >= w->no_list_items)
return;
w->selected_list_item = index;
w->Invalidate();
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_text_input(rct_window* w, rct_widgetindex widgetIndex, char* text)
2016-01-22 07:32:40 +01:00
{
if (widgetIndex != WIDX_RENAME_GROUP)
return;
2016-01-22 07:32:40 +01:00
2017-08-15 10:07:44 +02:00
if (text == nullptr)
return;
2016-01-22 07:32:40 +01:00
2019-05-13 20:53:33 +02:00
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::SetName, _selectedGroup, text);
GameActions::Execute(&networkModifyGroup);
2016-01-22 07:32:40 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_invalidate(rct_window* w)
2016-01-20 23:45:09 +01:00
{
window_multiplayer_set_pressed_tab(w);
window_multiplayer_anchor_border_widgets(w);
window_multiplayer_groups_widgets[WIDX_PERMISSIONS_LIST].right = w->width - 4;
window_multiplayer_groups_widgets[WIDX_PERMISSIONS_LIST].bottom = w->height - 0x0F;
window_align_tabs(w, WIDX_TAB1, WIDX_TAB4);
2016-01-22 07:32:40 +01:00
// select other group if one is removed
2018-06-22 23:21:44 +02:00
while (network_get_group_index(_selectedGroup) == -1 && _selectedGroup > 0)
{
_selectedGroup--;
}
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_paint(rct_window* w, rct_drawpixelinfo* dpi)
2016-01-20 23:45:09 +01:00
{
2020-10-14 00:34:18 +02:00
thread_local std::string buffer;
WindowDrawWidgets(w, dpi);
window_multiplayer_draw_tab_images(w, dpi);
rct_widget* widget = &window_multiplayer_groups_widgets[WIDX_DEFAULT_GROUP];
int32_t group = network_get_group_index(network_get_default_group());
2018-06-22 23:21:44 +02:00
if (group != -1)
{
2020-10-14 00:34:18 +02:00
buffer.assign("{WINDOW_COLOUR_2}");
buffer += network_get_group_name(group);
auto ft = Formatter();
2020-10-14 00:34:18 +02:00
ft.Add<const char*>(buffer.c_str());
DrawTextEllipsised(
dpi, w->windowPos + ScreenCoordsXY{ widget->midX() - 5, widget->top }, widget->width() - 8, STR_STRING, ft,
{ TextAlignment::CENTRE });
}
auto screenPos = w->windowPos
+ ScreenCoordsXY{ window_multiplayer_groups_widgets[WIDX_CONTENT_PANEL].left + 4,
window_multiplayer_groups_widgets[WIDX_CONTENT_PANEL].top + 4 };
DrawTextBasic(dpi, screenPos, STR_DEFAULT_GROUP, {}, { w->colours[2] });
screenPos.y += 20;
gfx_fill_rect_inset(
dpi, screenPos.x, screenPos.y - 6, screenPos.x + 310, screenPos.y - 5, w->colours[1], INSET_RECT_FLAG_BORDER_INSET);
widget = &window_multiplayer_groups_widgets[WIDX_SELECTED_GROUP];
group = network_get_group_index(_selectedGroup);
2018-06-22 23:21:44 +02:00
if (group != -1)
{
2020-10-14 00:34:18 +02:00
buffer.assign("{WINDOW_COLOUR_2}");
buffer += network_get_group_name(group);
auto ft = Formatter();
2020-10-14 00:34:18 +02:00
ft.Add<const char*>(buffer.c_str());
DrawTextEllipsised(
dpi, w->windowPos + ScreenCoordsXY{ widget->midX() - 5, widget->top }, widget->width() - 8, STR_STRING, ft,
{ TextAlignment::CENTRE });
}
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_groups_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
2016-01-20 23:45:09 +01:00
{
auto screenCoords = ScreenCoordsXY{ 0, 0 };
auto dpiCoords = ScreenCoordsXY{ dpi->x, dpi->y };
gfx_fill_rect(
dpi, { dpiCoords, dpiCoords + ScreenCoordsXY{ dpi->width - 1, dpi->height - 1 } }, ColourMapA[w->colours[1]].mid_light);
2018-06-22 23:21:44 +02:00
for (int32_t i = 0; i < network_get_num_actions(); i++)
{
if (i == w->selected_list_item)
{
gfx_filter_rect(
dpi, 0, screenCoords.y, 800, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1, FilterPaletteID::PaletteDarken1);
}
if (screenCoords.y > dpi->y + dpi->height)
2018-06-22 23:21:44 +02:00
{
break;
}
if (screenCoords.y + SCROLLABLE_ROW_HEIGHT + 1 >= dpi->y)
{
int32_t groupindex = network_get_group_index(_selectedGroup);
2018-06-22 23:21:44 +02:00
if (groupindex != -1)
{
if (network_can_perform_action(groupindex, static_cast<NetworkPermission>(i)))
2018-06-22 23:21:44 +02:00
{
screenCoords.x = 0;
gfx_draw_string(dpi, screenCoords, u8"{WINDOW_COLOUR_2}✓", {});
}
}
// Draw action name
auto ft = Formatter();
ft.Add<uint16_t>(network_get_action_name_string_id(i));
DrawTextBasic(dpi, { 10, screenCoords.y }, STR_WINDOW_COLOUR_2_STRINGID, ft);
}
screenCoords.y += SCROLLABLE_ROW_HEIGHT;
}
2016-01-20 23:45:09 +01:00
}
#pragma endregion
#pragma region Options page
2018-06-22 23:21:44 +02:00
static void window_multiplayer_options_mouseup(rct_window* w, rct_widgetindex widgetIndex)
{
switch (widgetIndex)
{
case WIDX_CLOSE:
window_close(w);
break;
case WIDX_TAB1:
case WIDX_TAB2:
case WIDX_TAB3:
case WIDX_TAB4:
if (w->page != widgetIndex - WIDX_TAB1)
{
window_multiplayer_set_page(w, widgetIndex - WIDX_TAB1);
}
break;
case WIDX_LOG_CHAT_CHECKBOX:
gConfigNetwork.log_chat = !gConfigNetwork.log_chat;
config_save_default();
break;
case WIDX_LOG_SERVER_ACTIONS_CHECKBOX:
gConfigNetwork.log_server_actions = !gConfigNetwork.log_server_actions;
config_save_default();
break;
case WIDX_KNOWN_KEYS_ONLY_CHECKBOX:
gConfigNetwork.known_keys_only = !gConfigNetwork.known_keys_only;
config_save_default();
break;
}
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_options_resize(rct_window* w)
{
window_set_resize(w, 300, 100, 300, 100);
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_options_update(rct_window* w)
{
w->frame_no++;
widget_invalidate(w, WIDX_TAB1 + w->page);
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_options_invalidate(rct_window* w)
{
window_multiplayer_set_pressed_tab(w);
window_multiplayer_anchor_border_widgets(w);
window_align_tabs(w, WIDX_TAB1, WIDX_TAB4);
2018-06-22 23:21:44 +02:00
if (network_get_mode() == NETWORK_MODE_CLIENT)
{
w->widgets[WIDX_KNOWN_KEYS_ONLY_CHECKBOX].type = WindowWidgetType::Empty;
}
2016-05-30 19:01:17 +02:00
2020-11-03 22:29:22 +01:00
WidgetSetCheckboxValue(w, WIDX_LOG_CHAT_CHECKBOX, gConfigNetwork.log_chat);
WidgetSetCheckboxValue(w, WIDX_LOG_SERVER_ACTIONS_CHECKBOX, gConfigNetwork.log_server_actions);
WidgetSetCheckboxValue(w, WIDX_KNOWN_KEYS_ONLY_CHECKBOX, gConfigNetwork.known_keys_only);
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_options_paint(rct_window* w, rct_drawpixelinfo* dpi)
{
WindowDrawWidgets(w, dpi);
window_multiplayer_draw_tab_images(w, dpi);
}
#pragma endregion
2018-06-22 23:21:44 +02:00
static void window_multiplayer_draw_tab_image(rct_window* w, rct_drawpixelinfo* dpi, int32_t page, int32_t spriteIndex)
2016-01-20 23:45:09 +01:00
{
rct_widgetindex widgetIndex = WIDX_TAB1 + page;
2016-01-20 23:45:09 +01:00
2020-11-03 22:29:22 +01:00
if (!WidgetIsDisabled(w, widgetIndex))
2018-06-22 23:21:44 +02:00
{
if (w->page == page)
{
int32_t numFrames = window_multiplayer_animation_frames[w->page];
2018-06-22 23:21:44 +02:00
if (numFrames > 1)
{
int32_t frame = w->frame_no / window_multiplayer_animation_divisor[w->page];
spriteIndex += (frame % numFrames);
}
}
2016-01-20 23:45:09 +01:00
2020-03-01 20:32:35 +01:00
gfx_draw_sprite(
dpi, ImageId(spriteIndex),
w->windowPos + ScreenCoordsXY{ w->widgets[widgetIndex].left, w->widgets[widgetIndex].top });
}
2016-01-20 23:45:09 +01:00
}
2018-06-22 23:21:44 +02:00
static void window_multiplayer_draw_tab_images(rct_window* w, rct_drawpixelinfo* dpi)
2016-01-20 23:45:09 +01:00
{
window_multiplayer_draw_tab_image(w, dpi, WINDOW_MULTIPLAYER_PAGE_INFORMATION, SPR_TAB_KIOSKS_AND_FACILITIES_0);
window_multiplayer_draw_tab_image(w, dpi, WINDOW_MULTIPLAYER_PAGE_PLAYERS, SPR_TAB_GUESTS_0);
window_multiplayer_draw_tab_image(w, dpi, WINDOW_MULTIPLAYER_PAGE_GROUPS, SPR_TAB_STAFF_OPTIONS_0);
window_multiplayer_draw_tab_image(w, dpi, WINDOW_MULTIPLAYER_PAGE_OPTIONS, SPR_TAB_GEARS_0);
2016-01-20 23:45:09 +01:00
}