From 53118cc9e30573f946bc33b4d51654a2ec8ea52e Mon Sep 17 00:00:00 2001 From: aMannus Date: Tue, 1 Jul 2025 23:00:58 +0200 Subject: [PATCH] Improvements in connection UI + random cleanup --- soh/soh/Enhancements/randomizer/context.cpp | 6 ++-- soh/soh/Network/Archipelago/Archipelago.cpp | 32 ++++--------------- soh/soh/Network/Archipelago/Archipelago.h | 4 +-- .../Archipelago/ArchipelagoSettingsWindow.cpp | 32 ++++++++++++++++--- soh/soh/OTRGlobals.cpp | 8 ----- soh/soh/OTRGlobals.h | 2 -- .../ovl_file_choose/z_file_choose.c | 1 - 7 files changed, 39 insertions(+), 46 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/context.cpp b/soh/soh/Enhancements/randomizer/context.cpp index 37b20d0bd..069d0394b 100644 --- a/soh/soh/Enhancements/randomizer/context.cpp +++ b/soh/soh/Enhancements/randomizer/context.cpp @@ -421,9 +421,9 @@ void Context::ParseArchipelago() { mSeedGenerated = false; mSpoilerLoaded = false; - ArchipelagoClient& ap_client = ArchipelagoClient::GetInstance(); - ParseArchipelagoItemsLocations(ap_client.GetScoutedItems()); - ParseArchipelagoOptions(ap_client.GetSlotData()); + ArchipelagoClient& apClient = ArchipelagoClient::GetInstance(); + ParseArchipelagoItemsLocations(apClient.GetScoutedItems()); + ParseArchipelagoOptions(apClient.GetSlotData()); mEntranceShuffler->UnshuffleAllEntrances(); mDungeons->ResetAllDungeons(); mTrials->RemoveAllTrials(); diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index c649df32d..b445576a7 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -52,8 +52,8 @@ bool ArchipelagoClient::StartClient() { apClient->set_socket_error_handler([&](const std::string& msg) { retries++; - if(retries > AP_Client_consts::MAX_RETRIES) { - ArchipelagoConsole_SendMessage("[ERROR] Could not connect to server"); + if(retries >= AP_Client_consts::MAX_RETRIES) { + ArchipelagoConsole_SendMessage("[ERROR] Could not connect to server after several tries.\nAre the entered server address and slot name correct?"); CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 2); // Connection error disconnecting = true; return; @@ -418,31 +418,11 @@ const std::vector& ArchipelagoClient::GetScoutedItems return scoutedItems; } -const char* ArchipelagoClient::GetConnectionStatus() { +uint8_t ArchipelagoClient::GetConnectionStatus() { if (!apClient) { - return "Disconnected!"; - } - - APClient::State clientStatus = apClient->get_state(); - - switch (clientStatus) { - case APClient::State::DISCONNECTED: { - return "Disconnected!"; - } - case APClient::State::SOCKET_CONNECTING: { - return "Socket Connecting!"; - } - case APClient::State::SOCKET_CONNECTED: { - return "Socket Connected!"; - } - case APClient::State::ROOM_INFO: { - return "Room info Received!"; - } - case APClient::State::SLOT_CONNECTED: { - return "Slot Connected!"; - } - default: - return ""; + return (uint8_t)APClient::State::DISCONNECTED; + } else { + return (uint8_t)apClient->get_state(); } } diff --git a/soh/soh/Network/Archipelago/Archipelago.h b/soh/soh/Network/Archipelago/Archipelago.h index 2d090fac5..aa282e2a8 100644 --- a/soh/soh/Network/Archipelago/Archipelago.h +++ b/soh/soh/Network/Archipelago/Archipelago.h @@ -15,7 +15,7 @@ static constexpr int MAX_PLAYER_NAME_LENGHT = 17; static constexpr int MAX_PASSWORD_LENGTH = 32; static constexpr char const* AP_GAME_NAME = "Ship of Harkinian"; -static constexpr int MAX_RETRIES = 6; +static constexpr int MAX_RETRIES = 3; } // namespace AP_Client_consts class ArchipelagoClient { @@ -47,7 +47,7 @@ class ArchipelagoClient { // getters const std::string GetSlotName() const; - const char* GetConnectionStatus(); + uint8_t GetConnectionStatus(); const nlohmann::json GetSlotData(); const std::vector& GetScoutedItems(); diff --git a/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp b/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp index 3fc6793ec..d44d908d4 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp +++ b/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp @@ -7,7 +7,7 @@ #include "soh/SaveManager.h" void ArchipelagoSettingsWindow::DrawElement() { - ArchipelagoClient& AP_client = ArchipelagoClient::GetInstance(); + ArchipelagoClient& apClient = ArchipelagoClient::GetInstance(); ImGui::SeparatorText("Connection info"); @@ -38,12 +38,36 @@ void ArchipelagoSettingsWindow::DrawElement() { ImGui::PopStyleColor(); UIWidgets::PopStyleCombobox(); - if (UIWidgets::Button("Connect", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) { - bool success = AP_client.StartClient(); + if (!apClient.IsConnected()) { + if (UIWidgets::Button("Connect", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) { + bool success = apClient.StartClient(); + } + } else { + if (UIWidgets::Button("Disconnect", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) { + bool success = apClient.StopClient(); + } } ImGui::SameLine(); - ImGui::Text(ArchipelagoClient::GetInstance().GetConnectionStatus()); + + uint8_t clientStatus = apClient.GetConnectionStatus(); + switch (clientStatus) { + case 1: + case 2: + case 3: + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 0.7f, 0.7f, 1.0f)); + ImGui::Text("Connecting..."); + break; + case 4: + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 1.0f, 0.5f, 1.0f)); + ImGui::Text("Connected"); + break; + default: + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.5f, 0.5f, 1.0f)); + ImGui::Text("Not Connected"); + break; + } + ImGui::PopStyleColor(); static bool sArchipelagoTexturesLoaded = false; if (!sArchipelagoTexturesLoaded) { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 54e756c16..6932f2101 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -2233,14 +2233,6 @@ extern "C" void Randomizer_ShowRandomizerMenu() { SohGui::ShowRandomizerSettingsMenu(); } -extern "C" void Archipelago_Connect() { - ArchipelagoClient::GetInstance().StartClient(); -} - -extern "C" void Archipelago_Disconnect() { - ArchipelagoClient::GetInstance().StopClient(); -} - extern "C" void Archipelago_ShowArchipelagoMenu() { SohGui::ShowArchipelagoSettingsMenu(); } diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 0c5bd64b4..e3d4e9048 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -155,8 +155,6 @@ uint8_t Randomizer_IsSpoilerLoaded(); void Randomizer_SetSpoilerLoaded(bool spoilerLoaded); uint8_t Randomizer_GenerateRandomizer(); void Randomizer_ShowRandomizerMenu(); -void Archipelago_Connect(); -void Archipelago_Disconnect(); void Archipelago_ShowArchipelagoMenu(); int CustomMessage_RetrieveIfExists(PlayState* play); void Overlay_DisplayText(float duration, const char* text); diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 7da12906a..6ec8fbe48 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1806,7 +1806,6 @@ void FileChoose_UpdateArchipelagoMenu(GameState* thisx) { if (CHECK_BTN_ALL(input->press.button, BTN_A)) { if (this->archipelagoIndex == ASM_START_ARCHIPELAGO) { - uint16_t testnumber = CVarGetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 0); // Only continue when connected to a slot and locations are scouted. if (CVarGetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 0) != 4) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,