2017-06-01 21:55:10 +02:00
|
|
|
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
|
2015-07-23 00:55:43 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
2016-05-04 19:24:41 +02:00
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
2015-07-23 00:55:43 +02:00
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
2015-07-23 00:55:43 +02:00
|
|
|
*****************************************************************************/
|
2016-05-04 19:24:41 +02:00
|
|
|
#pragma endregion
|
2015-07-23 00:55:43 +02:00
|
|
|
|
2017-10-21 19:30:03 +02:00
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-08-02 00:20:32 +02:00
|
|
|
|
2018-01-03 00:13:37 +01:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2017-10-21 19:30:03 +02:00
|
|
|
#include <openrct2/network/network.h>
|
2017-12-13 13:02:24 +01:00
|
|
|
#include <openrct2/util/Util.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2015-07-23 00:55:43 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2015-12-16 21:48:27 +01:00
|
|
|
static char _password[33];
|
2015-11-02 04:12:14 +01:00
|
|
|
|
2015-07-23 00:55:43 +02:00
|
|
|
enum WINDOW_NETWORK_STATUS_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_PASSWORD
|
2015-07-23 00:55:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_network_status_widgets[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_FRAME, 0, 0, 440, 0, 90, 0xFFFFFFFF, STR_NONE }, // panel / background
|
|
|
|
{ WWT_CAPTION, 0, 1, 438, 1, 14, STR_NONE, STR_WINDOW_TITLE_TIP }, // title bar
|
|
|
|
{ WWT_CLOSEBOX, 0, 427, 437, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button
|
|
|
|
{ WIDGETS_END },
|
2015-07-23 00:55:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static char window_network_status_text[1024];
|
|
|
|
|
2016-03-23 00:27:49 +01:00
|
|
|
static void window_network_status_onclose(rct_window *w);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_network_status_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2015-07-23 00:55:43 +02:00
|
|
|
static void window_network_status_update(rct_window *w);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_network_status_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text);
|
2015-07-23 00:55:43 +02:00
|
|
|
static void window_network_status_invalidate(rct_window *w);
|
|
|
|
static void window_network_status_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
|
|
|
|
|
|
|
static rct_window_event_list window_network_status_events = {
|
2017-06-06 23:24:18 +02:00
|
|
|
window_network_status_onclose,
|
|
|
|
window_network_status_mouseup,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_network_status_update,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_network_status_textinput,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_network_status_invalidate,
|
|
|
|
window_network_status_paint,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr
|
2015-07-23 00:55:43 +02:00
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2015-07-23 00:55:43 +02:00
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
static close_callback _onClose = nullptr;
|
2015-07-23 00:55:43 +02:00
|
|
|
|
2017-10-21 19:30:03 +02:00
|
|
|
rct_window * window_network_status_open(const char* text, close_callback onClose)
|
2016-03-23 00:27:49 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
_onClose = onClose;
|
|
|
|
safe_strcpy(window_network_status_text, text, sizeof(window_network_status_text));
|
|
|
|
|
|
|
|
// Check if window is already open
|
|
|
|
rct_window *window = window_bring_to_front_by_class_with_flags(WC_NETWORK_STATUS, 0);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (window != nullptr)
|
2017-10-21 19:30:03 +02:00
|
|
|
return window;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window = window_create_centred(420, 90, &window_network_status_events, WC_NETWORK_STATUS, WF_10 | WF_TRANSPARENT);
|
|
|
|
|
|
|
|
window->widgets = window_network_status_widgets;
|
|
|
|
window->enabled_widgets = 1 << WIDX_CLOSE;
|
|
|
|
window_init_scroll_widgets(window);
|
|
|
|
window->no_list_items = 0;
|
|
|
|
window->selected_list_item = -1;
|
|
|
|
window->frame_no = 0;
|
|
|
|
window->min_width = 320;
|
|
|
|
window->min_height = 90;
|
|
|
|
window->max_width = window->min_width;
|
|
|
|
window->max_height = window->min_height;
|
|
|
|
|
|
|
|
window->page = 0;
|
|
|
|
window->list_information_type = 0;
|
2017-10-21 19:30:03 +02:00
|
|
|
|
|
|
|
return window;
|
2015-07-23 00:55:43 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 18:29:47 +02:00
|
|
|
void window_network_status_close()
|
|
|
|
{
|
2017-08-15 10:07:44 +02:00
|
|
|
_onClose = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
window_close_by_class(WC_NETWORK_STATUS);
|
2015-08-16 18:29:47 +02:00
|
|
|
}
|
|
|
|
|
2017-10-21 19:30:03 +02:00
|
|
|
rct_window * window_network_status_open_password()
|
2015-11-02 04:12:14 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window* window;
|
|
|
|
window = window_bring_to_front_by_class(WC_NETWORK_STATUS);
|
2017-08-15 10:07:44 +02:00
|
|
|
if (window == nullptr)
|
2017-10-21 19:30:03 +02:00
|
|
|
return nullptr;
|
2015-11-02 04:12:14 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window_text_input_raw_open(window, WIDX_PASSWORD, STR_PASSWORD_REQUIRED, STR_PASSWORD_REQUIRED_DESC, _password, 32);
|
2017-10-21 19:30:03 +02:00
|
|
|
|
|
|
|
return window;
|
2015-11-02 04:12:14 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 00:27:49 +01:00
|
|
|
static void window_network_status_onclose(rct_window *w)
|
|
|
|
{
|
2017-08-15 10:07:44 +02:00
|
|
|
if (_onClose != nullptr) {
|
2017-06-06 23:24:18 +02:00
|
|
|
_onClose();
|
|
|
|
}
|
2016-03-23 00:27:49 +01:00
|
|
|
}
|
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_network_status_mouseup(rct_window *w, rct_widgetindex widgetIndex)
|
2015-07-23 00:55:43 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
switch (widgetIndex) {
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-23 00:55:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void window_network_status_update(rct_window *w)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
widget_invalidate(w, WIDX_BACKGROUND);
|
2015-07-23 00:55:43 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_network_status_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text)
|
2015-11-02 04:12:14 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
_password[0] = '\0';
|
|
|
|
switch (widgetIndex) {
|
|
|
|
case WIDX_PASSWORD:
|
2017-08-15 10:07:44 +02:00
|
|
|
if (text != nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
safe_strcpy(_password, text, sizeof(_password));
|
|
|
|
break;
|
|
|
|
}
|
2017-08-15 10:07:44 +02:00
|
|
|
if (text == nullptr) {
|
2017-06-06 23:24:18 +02:00
|
|
|
network_shutdown_client();
|
|
|
|
} else {
|
|
|
|
network_send_password(_password);
|
|
|
|
}
|
2015-11-02 04:12:14 +01:00
|
|
|
}
|
|
|
|
|
2015-07-23 00:55:43 +02:00
|
|
|
static void window_network_status_invalidate(rct_window *w)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_network_status_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
|
|
|
window_network_status_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
|
|
|
|
window_network_status_widgets[WIDX_TITLE].right = w->width - 2;
|
|
|
|
window_network_status_widgets[WIDX_CLOSE].left = w->width - 2 - 0x0B;
|
|
|
|
window_network_status_widgets[WIDX_CLOSE].right = w->width - 2 - 0x0B + 0x0A;
|
2015-07-23 00:55:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void window_network_status_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
|
|
char buffer[sizeof(window_network_status_text) + 10];
|
|
|
|
char* lineCh = buffer;
|
|
|
|
lineCh = utf8_write_codepoint(lineCh, FORMAT_BLACK);
|
|
|
|
safe_strcpy(lineCh, window_network_status_text, sizeof(buffer) - (lineCh - buffer));
|
|
|
|
gfx_clip_string(buffer, w->widgets[WIDX_BACKGROUND].right - 50);
|
|
|
|
sint32 x = w->x + (w->width / 2);
|
|
|
|
sint32 y = w->y + (w->height / 2);
|
|
|
|
x -= gfx_get_string_width(buffer) / 2;
|
|
|
|
gfx_draw_string(dpi, buffer, COLOUR_BLACK, x, y);
|
2015-07-23 00:55:43 +02:00
|
|
|
}
|