1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Move network status window to UI module

This commit is contained in:
Marijn van der Werf
2017-10-21 19:30:03 +02:00
parent b85f9c3f68
commit 4a4f9648a7
12 changed files with 122 additions and 25 deletions

View File

@@ -247,6 +247,11 @@
C685E51C1F8907850090598F /* Map.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C685E5171F8907840090598F /* Map.cpp */; };
C685E51D1F8907850090598F /* Research.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C685E5181F8907840090598F /* Research.cpp */; };
C6CB94F21EFFBF860065888F /* libfreetype.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B41CF3006400659A24 /* libfreetype.dylib */; };
C6D2BEE21F9BAA6C008B557C /* Ride.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D2BEE11F9BAA6C008B557C /* Ride.cpp */; };
C6D2BEE61F9BAACE008B557C /* TrackList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D2BEE31F9BAACC008B557C /* TrackList.cpp */; };
C6D2BEE71F9BAACE008B557C /* MapTooltip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D2BEE41F9BAACD008B557C /* MapTooltip.cpp */; };
C6D2BEE81F9BAACE008B557C /* MazeConstruction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D2BEE51F9BAACD008B557C /* MazeConstruction.cpp */; };
C6D2BEEA1F9BB83C008B557C /* NetworkStatus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D2BEE91F9BB83B008B557C /* NetworkStatus.cpp */; };
C6E96E361E0408B40076A04F /* libzip.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C6E96E351E0408B40076A04F /* libzip.dylib */; };
C6E96E371E040E040076A04F /* libzip.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C6E96E351E0408B40076A04F /* libzip.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
D41B73EF1C2101890080A7B9 /* libcurl.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D41B73EE1C2101890080A7B9 /* libcurl.tbd */; };
@@ -877,6 +882,11 @@
C686F9031CDBC3B7009F9BFC /* boat_ride.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = boat_ride.c; sourceTree = "<group>"; };
C686F9041CDBC3B7009F9BFC /* dingy_slide.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dingy_slide.c; sourceTree = "<group>"; };
C686F9051CDBC3B7009F9BFC /* log_flume.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = log_flume.c; sourceTree = "<group>"; };
C6D2BEE11F9BAA6C008B557C /* Ride.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Ride.cpp; sourceTree = "<group>"; };
C6D2BEE31F9BAACC008B557C /* TrackList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackList.cpp; sourceTree = "<group>"; };
C6D2BEE41F9BAACD008B557C /* MapTooltip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MapTooltip.cpp; sourceTree = "<group>"; };
C6D2BEE51F9BAACD008B557C /* MazeConstruction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MazeConstruction.cpp; sourceTree = "<group>"; };
C6D2BEE91F9BB83B008B557C /* NetworkStatus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkStatus.cpp; sourceTree = "<group>"; };
C6E96E331E0408A80076A04F /* zip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = zip.h; sourceTree = "<group>"; };
C6E96E341E0408A80076A04F /* zipconf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = zipconf.h; sourceTree = "<group>"; };
C6E96E351E0408B40076A04F /* libzip.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libzip.dylib; sourceTree = "<group>"; };
@@ -2725,6 +2735,7 @@
C666EE5B1F37ACB10061AA04 /* MapGen.cpp */,
C666EE5C1F37ACB10061AA04 /* Multiplayer.cpp */,
C666EE5D1F37ACB10061AA04 /* MusicCredits.cpp */,
C6D2BEE91F9BB83B008B557C /* NetworkStatus.cpp */,
C654DF231F69C0430040F43D /* NewCampaign.cpp */,
C685E5141F8907840090598F /* NewRide.cpp */,
C666EE5E1F37ACB10061AA04 /* News.cpp */,
@@ -3292,6 +3303,7 @@
4C93F18E1F8B747A00A9330D /* MotionSimulator.cpp in Sources */,
C666EE711F37ACB10061AA04 /* MapGen.cpp in Sources */,
4C93F17C1F8B747300A9330D /* Facility.cpp in Sources */,
C6D2BEEA1F9BB83C008B557C /* NetworkStatus.cpp in Sources */,
C64645011F3FA4120026AC2D /* Water.cpp in Sources */,
F76C88851EC5324E00FA49E2 /* OpenGLFramebuffer.cpp in Sources */,
4C93F1451F8B744400A9330D /* JuniorRollerCoaster.cpp in Sources */,
@@ -3452,7 +3464,6 @@
F76C868E1EC4E88400FA49E2 /* scenery.c in Sources */,
F76C868F1EC4E88400FA49E2 /* scenery_multiple.c in Sources */,
F76C86901EC4E88400FA49E2 /* surface.c in Sources */,
C666EE2D1F33E3800061AA04 /* NetworkStatus.cpp in Sources */,
F76C86921EC4E88400FA49E2 /* Paint.cpp in Sources */,
F76C86941EC4E88400FA49E2 /* paint_helpers.c in Sources */,
F76C86951EC4E88400FA49E2 /* litter.c in Sources */,

View File

@@ -146,6 +146,8 @@ public:
}
case WV_MAZE_CONSTRUCTION:
return window_maze_construction_open();
case WV_NETWORK_PASSWORD:
return window_network_status_open_password();
default:
return nullptr;
}
@@ -203,6 +205,12 @@ public:
}
case WC_MANAGE_TRACK_DESIGN:
return window_track_manage_open((track_design_file_ref *) intent->GetPointerExtra(INTENT_EXTRA_TRACK_DESIGN));
case WC_NETWORK_STATUS:
{
std::string message = intent->GetStringExtra(INTENT_EXTRA_MESSAGE);
close_callback callback = intent->GetCloseCallbackExtra(INTENT_EXTRA_CALLBACK);
return window_network_status_open(message.c_str(), callback);
}
case WC_RIDE:
return window_ride_main_open(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID));
case WC_TRACK_DESIGN_PLACE:
@@ -269,6 +277,19 @@ public:
}
}
void ForceClose(rct_windowclass windowClass) override
{
switch (windowClass)
{
case WC_NETWORK_STATUS:
window_network_status_close();
break;
default:
break;
}
}
void UpdateMapTooltip() override
{
window_map_tooltip_update_visibility();

View File

@@ -14,11 +14,12 @@
*****************************************************************************/
#pragma endregion
#include "../network/network.h"
#include <openrct2-ui/windows/Window.h>
#include "../interface/widget.h"
#include "../localisation/localisation.h"
#include "../util/util.h"
#include <openrct2/interface/widget.h>
#include <openrct2/localisation/localisation.h>
#include <openrct2/network/network.h>
#include <openrct2/util/util.h>
static char _password[33];
@@ -78,7 +79,7 @@ static rct_window_event_list window_network_status_events = {
static close_callback _onClose = nullptr;
void window_network_status_open(const char* text, close_callback onClose)
rct_window * window_network_status_open(const char* text, close_callback onClose)
{
_onClose = onClose;
safe_strcpy(window_network_status_text, text, sizeof(window_network_status_text));
@@ -86,7 +87,7 @@ void window_network_status_open(const char* text, close_callback onClose)
// Check if window is already open
rct_window *window = window_bring_to_front_by_class_with_flags(WC_NETWORK_STATUS, 0);
if (window != nullptr)
return;
return window;
window = window_create_centred(420, 90, &window_network_status_events, WC_NETWORK_STATUS, WF_10 | WF_TRANSPARENT);
@@ -103,6 +104,8 @@ void window_network_status_open(const char* text, close_callback onClose)
window->page = 0;
window->list_information_type = 0;
return window;
}
void window_network_status_close()
@@ -111,14 +114,16 @@ void window_network_status_close()
window_close_by_class(WC_NETWORK_STATUS);
}
void window_network_status_open_password()
rct_window * window_network_status_open_password()
{
rct_window* window;
window = window_bring_to_front_by_class(WC_NETWORK_STATUS);
if (window == nullptr)
return;
return nullptr;
window_text_input_raw_open(window, WIDX_PASSWORD, STR_PASSWORD_REQUIRED, STR_PASSWORD_REQUIRED_DESC, _password, 32);
return window;
}
static void window_network_status_onclose(rct_window *w)

View File

@@ -121,3 +121,7 @@ void window_map_tooltip_update_visibility();
rct_window * window_maze_construction_open();
void window_maze_construction_update_pressed_widgets();
rct_window * window_network_status_open(const char * text, close_callback onClose);
rct_window * window_network_status_open_password();
void window_network_status_close();

View File

@@ -1033,6 +1033,12 @@ extern "C"
windowManager->BroadcastIntent(intent);
}
void context_force_close_window_by_class(rct_windowclass windowClass)
{
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
windowManager->ForceClose(windowClass);
}
rct_window * context_show_error(rct_string_id title, rct_string_id message)
{
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();

View File

@@ -219,6 +219,7 @@ extern "C"
rct_window * context_show_error(rct_string_id title, rct_string_id message);
rct_window * context_open_intent(Intent * intent);
void context_broadcast_intent(Intent * intent);
void context_force_close_window_by_class(rct_windowclass wc);
void context_update_map_tooltip();
void context_input_handle_keyboard(bool isTitle);
bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path);

View File

@@ -508,6 +508,7 @@ enum {
WV_FINANCES_RESEARCH,
WV_RIDE_RESEARCH,
WV_MAZE_CONSTRUCTION,
WV_NETWORK_PASSWORD,
};
enum {
@@ -722,11 +723,6 @@ void ride_construction_toolupdate_entrance_exit(sint32 screenX, sint32 screenY);
void ride_construction_toolupdate_construct(sint32 screenX, sint32 screenY);
void ride_construction_tooldown_construct(sint32 screenX, sint32 screenY);
void window_network_status_open(const char* text, close_callback onClose);
void window_network_status_close();
void window_network_status_open_password();
void window_scenery_open();
void window_tile_inspector_open();
void window_tile_inspector_clear_clipboard();

View File

@@ -463,9 +463,13 @@ void Network::UpdateClient()
_lastConnectStatus = SOCKET_STATUS_RESOLVING;
char str_resolving[256];
format_string(str_resolving, 256, STR_MULTIPLAYER_RESOLVING, nullptr);
window_network_status_open(str_resolving, []() -> void {
auto intent = Intent(WC_NETWORK_STATUS);
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string { str_resolving });
intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void {
gNetwork.Close();
});
context_open_intent(&intent);
}
break;
}
@@ -476,9 +480,14 @@ void Network::UpdateClient()
_lastConnectStatus = SOCKET_STATUS_CONNECTING;
char str_connecting[256];
format_string(str_connecting, 256, STR_MULTIPLAYER_CONNECTING, nullptr);
window_network_status_open(str_connecting, []() -> void {
auto intent = Intent(WC_NETWORK_STATUS);
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string { str_connecting });
intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void {
gNetwork.Close();
});
context_open_intent(&intent);
server_connect_time = platform_get_ticks();
}
break;
@@ -490,9 +499,13 @@ void Network::UpdateClient()
Client_Send_TOKEN();
char str_authenticating[256];
format_string(str_authenticating, 256, STR_MULTIPLAYER_AUTHENTICATING, nullptr);
window_network_status_open(str_authenticating, []() -> void {
auto intent = Intent(WC_NETWORK_STATUS);
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string { str_authenticating });
intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void {
gNetwork.Close();
});
context_open_intent(&intent);
break;
}
default:
@@ -503,7 +516,7 @@ void Network::UpdateClient()
}
Close();
window_network_status_close();
context_force_close_window_by_class(WC_NETWORK_STATUS);
context_show_error(STR_UNABLE_TO_CONNECT_TO_SERVER, STR_NONE);
break;
}
@@ -515,7 +528,7 @@ void Network::UpdateClient()
if (!ProcessConnection(*server_connection)) {
// Do not show disconnect message window when password window closed/canceled
if (server_connection->AuthStatus == NETWORK_AUTH_REQUIREPASSWORD) {
window_network_status_close();
context_force_close_window_by_class(WC_NETWORK_STATUS);
} else {
char str_disconnected[256];
@@ -526,7 +539,9 @@ void Network::UpdateClient()
format_string(str_disconnected, 256, STR_MULTIPLAYER_DISCONNECTED_NO_REASON, nullptr);
}
window_network_status_open(str_disconnected, nullptr);
auto intent = Intent(WC_NETWORK_STATUS);
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string { str_disconnected });
context_open_intent(&intent);
}
Close();
}
@@ -647,7 +662,11 @@ void Network::CheckDesynchronizaton()
char str_desync[256];
format_string(str_desync, 256, STR_MULTIPLAYER_DESYNC, NULL);
window_network_status_open(str_desync, NULL);
auto intent = Intent(WC_NETWORK_STATUS);
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string { str_desync });
context_open_intent(&intent);
if (!gConfigNetwork.stay_connected) {
Close();
}
@@ -1690,7 +1709,7 @@ void Network::Client_Handle_AUTH(NetworkConnection& connection, NetworkPacket& p
connection.Socket->Disconnect();
break;
case NETWORK_AUTH_REQUIREPASSWORD:
window_network_status_open_password();
context_open_window_view(WV_NETWORK_PASSWORD);
break;
case NETWORK_AUTH_UNKNOWN_KEY_DISALLOWED:
connection.SetLastDisconnectReason(STR_MULTIPLAYER_UNKNOWN_KEY_DISALLOWED);
@@ -1912,12 +1931,17 @@ void Network::Client_Handle_MAP(NetworkConnection& connection, NetworkPacket& pa
char str_downloading_map[256];
uint32 downloading_map_args[2] = {(offset + chunksize) / 1024, size / 1024};
format_string(str_downloading_map, 256, STR_MULTIPLAYER_DOWNLOADING_MAP, downloading_map_args);
window_network_status_open(str_downloading_map, []() -> void {
auto intent = Intent(WC_NETWORK_STATUS);
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string { str_downloading_map });
intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void {
gNetwork.Close();
});
context_open_intent(&intent);
memcpy(&chunk_buffer[offset], (void*)packet.Read(chunksize), chunksize);
if (offset + chunksize == size) {
window_network_status_close();
context_force_close_window_by_class(WC_NETWORK_STATUS);
bool has_to_free = false;
uint8 *data = &chunk_buffer[0];
size_t data_size = size;

View File

@@ -27,6 +27,7 @@ namespace OpenRCT2 { namespace Ui
rct_window * ShowError(rct_string_id title, rct_string_id message) override { return nullptr; }
rct_window * OpenIntent(Intent * intent) override { return nullptr; };
void BroadcastIntent(Intent * intent) override { }
void ForceClose(rct_windowclass windowClass) override { }
void UpdateMapTooltip() override { }
void HandleKeyboard(bool isTitle) override { }
std::string GetKeyboardShortcutString(sint32 shortcut) override { return std::string(); }

View File

@@ -41,6 +41,7 @@ namespace OpenRCT2
virtual rct_window * OpenIntent(Intent * intent) abstract;
virtual void BroadcastIntent(Intent * intent) abstract;
virtual rct_window * ShowError(rct_string_id title, rct_string_id message) abstract;
virtual void ForceClose(rct_windowclass windowClass) abstract;
virtual void UpdateMapTooltip() abstract;
virtual void HandleKeyboard(bool isTitle) abstract;
virtual std::string GetKeyboardShortcutString(sint32 shortcut) abstract;

View File

@@ -51,6 +51,17 @@ Intent * Intent::putExtra(uint32 key, std::string value)
return this;
}
Intent * Intent::putExtra(uint32 key, close_callback value)
{
IntentData data = {};
data.closeCallbackVal = value;
data.type = IntentData::DT_CLOSE_CALLBACK;
_Data.insert(std::make_pair(key, data));
return this;
}
rct_windowclass Intent::GetWindowClass()
{
return this->_Class;
@@ -104,6 +115,18 @@ std::string Intent::GetStringExtra(uint32 key)
return data.stringVal;
}
close_callback Intent::GetCloseCallbackExtra(uint32 key)
{
if (_Data.count(key) == 0)
{
return nullptr;
}
auto data = _Data.at(key);
openrct2_assert(data.type == IntentData::DT_CLOSE_CALLBACK, "Actual type doesn't match requested type");
return data.closeCallbackVal;
}
extern "C" {
Intent *intent_create(rct_windowclass clss)
{

View File

@@ -12,13 +12,14 @@
#ifdef __cplusplus
struct IntentData
{
enum DATATYPE { DT_INT, DT_STRING, DT_POINTER } type;
enum DATATYPE { DT_INT, DT_STRING, DT_POINTER, DT_CLOSE_CALLBACK } type;
union {
uint32 unsignedInt;
sint32 signedInt;
} intVal;
std::string stringVal;
close_callback closeCallbackVal;
void * pointerVal;
};
@@ -34,10 +35,12 @@ public:
std::string GetStringExtra(uint32 key);
uint32 GetUIntExtra(uint32 key);
sint32 GetSIntExtra(uint32 key);
close_callback GetCloseCallbackExtra(uint32 key);
Intent * putExtra(uint32 key, uint32 value);
Intent * putExtra(uint32 key, void * value);
Intent * putExtra(uint32 key, sint32 value);
Intent * putExtra(uint32 key, std::string value);
Intent * putExtra(uint32 key, close_callback value);
};
#else
// Allow C code to use `Intent *`
@@ -62,6 +65,7 @@ extern "C" {
INTENT_EXTRA_RIDE_ENTRY_INDEX,
INTENT_EXTRA_TILE_ELEMENT,
INTENT_EXTRA_VEHICLE,
INTENT_EXTRA_MESSAGE,
};
enum {