mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 04:23:20 +01:00
fix #3158: close network status window doesn't abort
This commit is contained in:
@@ -503,6 +503,8 @@ typedef void (*scenarioselect_callback)(const utf8 *path);
|
||||
extern bool gLoadSaveTitleSequenceSave;
|
||||
extern modal_callback gLoadSaveCallback;
|
||||
|
||||
typedef void (*close_callback)();
|
||||
|
||||
// rct2: 0x01420078
|
||||
extern rct_window* g_window_list;
|
||||
|
||||
@@ -635,7 +637,7 @@ void window_news_options_open();
|
||||
void window_cheats_open();
|
||||
void window_multiplayer_open();
|
||||
void window_player_open(uint8 id);
|
||||
void window_network_status_open(const char* text);
|
||||
void window_network_status_open(const char* text, close_callback onClose);
|
||||
void window_network_status_close();
|
||||
void window_network_status_open_password();
|
||||
void window_server_list_open();
|
||||
|
||||
@@ -656,7 +656,9 @@ bool Network::BeginClient(const char* host, unsigned short port)
|
||||
|
||||
char str_resolving[256];
|
||||
format_string(str_resolving, STR_MULTIPLAYER_RESOLVING, NULL);
|
||||
window_network_status_open(str_resolving);
|
||||
window_network_status_open(str_resolving, []() -> void {
|
||||
gNetwork.Close();
|
||||
});
|
||||
|
||||
mode = NETWORK_MODE_CLIENT;
|
||||
|
||||
@@ -846,7 +848,9 @@ void Network::UpdateClient()
|
||||
if (connect(server_connection.socket, (sockaddr *)&(*server_address.ss), (*server_address.ss_len)) == SOCKET_ERROR && (LAST_SOCKET_ERROR() == EINPROGRESS || LAST_SOCKET_ERROR() == EWOULDBLOCK)){
|
||||
char str_connecting[256];
|
||||
format_string(str_connecting, STR_MULTIPLAYER_CONNECTING, NULL);
|
||||
window_network_status_open(str_connecting);
|
||||
window_network_status_open(str_connecting, []() -> void {
|
||||
gNetwork.Close();
|
||||
});
|
||||
server_connect_time = SDL_GetTicks();
|
||||
status = NETWORK_STATUS_CONNECTING;
|
||||
} else {
|
||||
@@ -899,7 +903,9 @@ void Network::UpdateClient()
|
||||
Client_Send_AUTH(gConfigNetwork.player_name, "");
|
||||
char str_authenticating[256];
|
||||
format_string(str_authenticating, STR_MULTIPLAYER_AUTHENTICATING, NULL);
|
||||
window_network_status_open(str_authenticating);
|
||||
window_network_status_open(str_authenticating, []() -> void {
|
||||
gNetwork.Close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}break;
|
||||
@@ -917,7 +923,7 @@ void Network::UpdateClient()
|
||||
format_string(str_disconnected, STR_MULTIPLAYER_DISCONNECTED_NO_REASON, NULL);
|
||||
}
|
||||
|
||||
window_network_status_open(str_disconnected);
|
||||
window_network_status_open(str_disconnected, NULL);
|
||||
}
|
||||
Close();
|
||||
}
|
||||
@@ -928,7 +934,7 @@ void Network::UpdateClient()
|
||||
_desynchronised = true;
|
||||
char str_desync[256];
|
||||
format_string(str_desync, STR_MULTIPLAYER_DESYNC, NULL);
|
||||
window_network_status_open(str_desync);
|
||||
window_network_status_open(str_desync, NULL);
|
||||
if (!gConfigNetwork.stay_connected) {
|
||||
Close();
|
||||
}
|
||||
@@ -1761,7 +1767,9 @@ void Network::Client_Handle_MAP(NetworkConnection& connection, NetworkPacket& pa
|
||||
char str_downloading_map[256];
|
||||
unsigned int downloading_map_args[2] = {(offset + chunksize) / 1000, size / 1000};
|
||||
format_string(str_downloading_map, STR_MULTIPLAYER_DOWNLOADING_MAP, downloading_map_args);
|
||||
window_network_status_open(str_downloading_map);
|
||||
window_network_status_open(str_downloading_map, []() -> void {
|
||||
gNetwork.Close();
|
||||
});
|
||||
memcpy(&chunk_buffer[offset], (void*)packet.Read(chunksize), chunksize);
|
||||
if (offset + chunksize == size) {
|
||||
window_network_status_close();
|
||||
|
||||
@@ -43,6 +43,7 @@ static rct_widget window_network_status_widgets[] = {
|
||||
|
||||
static char window_network_status_text[1024];
|
||||
|
||||
static void window_network_status_onclose(rct_window *w);
|
||||
static void window_network_status_mouseup(rct_window *w, int widgetIndex);
|
||||
static void window_network_status_update(rct_window *w);
|
||||
static void window_network_status_textinput(rct_window *w, int widgetIndex, char *text);
|
||||
@@ -50,7 +51,7 @@ 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 = {
|
||||
NULL,
|
||||
window_network_status_onclose,
|
||||
window_network_status_mouseup,
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -80,14 +81,15 @@ static rct_window_event_list window_network_status_events = {
|
||||
NULL
|
||||
};
|
||||
|
||||
void window_network_status_open(const char* text)
|
||||
{
|
||||
rct_window* window;
|
||||
static close_callback _onClose = NULL;
|
||||
|
||||
void window_network_status_open(const char* text, close_callback onClose)
|
||||
{
|
||||
_onClose = onClose;
|
||||
safe_strcpy(window_network_status_text, text, sizeof(window_network_status_text));
|
||||
|
||||
// Check if window is already open
|
||||
window = window_bring_to_front_by_class(WC_NETWORK_STATUS);
|
||||
rct_window *window = window_bring_to_front_by_class(WC_NETWORK_STATUS);
|
||||
if (window != NULL)
|
||||
return;
|
||||
|
||||
@@ -110,6 +112,7 @@ void window_network_status_open(const char* text)
|
||||
|
||||
void window_network_status_close()
|
||||
{
|
||||
_onClose = NULL;
|
||||
window_close_by_class(WC_NETWORK_STATUS);
|
||||
}
|
||||
|
||||
@@ -123,6 +126,13 @@ void window_network_status_open_password()
|
||||
window_text_input_raw_open(window, WIDX_PASSWORD, STR_PASSWORD_REQUIRED, STR_PASSWORD_REQUIRED_DESC, _password, 32);
|
||||
}
|
||||
|
||||
static void window_network_status_onclose(rct_window *w)
|
||||
{
|
||||
if (_onClose != NULL) {
|
||||
_onClose();
|
||||
}
|
||||
}
|
||||
|
||||
static void window_network_status_mouseup(rct_window *w, int widgetIndex)
|
||||
{
|
||||
switch (widgetIndex) {
|
||||
|
||||
Reference in New Issue
Block a user