From d53afb534d4aa86c6a82d898174e3fc975e62584 Mon Sep 17 00:00:00 2001 From: Jerom Venneker Date: Mon, 7 Jul 2025 19:22:17 +0200 Subject: [PATCH] Changed AP console text colors to enums --- soh/soh/Network/Archipelago/Archipelago.cpp | 46 +++++----- soh/soh/Network/Archipelago/Archipelago.h | 7 +- .../Archipelago/ArchipelagoConsoleWindow.cpp | 89 ++++++++++--------- .../Archipelago/ArchipelagoConsoleWindow.h | 7 +- .../Network/Archipelago/ArchipelagoTypes.h | 30 +++++++ 5 files changed, 107 insertions(+), 72 deletions(-) create mode 100644 soh/soh/Network/Archipelago/ArchipelagoTypes.h diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index 4421a90ba..264e91090 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -146,64 +146,64 @@ bool ArchipelagoClient::StartClient() { return; } - std::vector coloredNodes; + std::vector coloredNodes; for (const APClient::TextNode& node : arg.data) { APClient* client = apClient.get(); - std::string color; + AP_Text::TextColor color = AP_Text::TextColor::COLOR_DEFAULT; std::string text; if (node.type == "player_id") { int id = std::stoi(node.text); - if (color.empty() && id == client->get_player_number()) - color = "magenta"; - else if (color.empty()) - color = "yellow"; + if (color == AP_Text::TextColor::COLOR_DEFAULT && id == client->get_player_number()) + color = AP_Text::TextColor::COLOR_MAGENTA; + else if (color == AP_Text::TextColor::COLOR_DEFAULT) + color = AP_Text::TextColor::COLOR_YELLOW; text = client->get_player_alias(id); } else if (node.type == "item_id") { int64_t id = std::stoll(node.text); - if (color.empty()) { + if (color == AP_Text::TextColor::COLOR_DEFAULT) { if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT) - color = "plum"; + color = AP_Text::TextColor::COLOR_PLUM; else if (node.flags & APClient::ItemFlags::FLAG_NEVER_EXCLUDE) - color = "slateblue"; + color = AP_Text::TextColor::COLOR_SLATEBLUE; else if (node.flags & APClient::ItemFlags::FLAG_TRAP) - color = "salmon"; + color = AP_Text::TextColor::COLOR_SALMON; else - color = "cyan"; + color = AP_Text::TextColor::COLOR_CYAN; } text = client->get_item_name(id, client->get_player_game(node.player)); } else if (node.type == "location_id") { int64_t id = std::stoll(node.text); - if (color.empty()) - color = "blue"; + if (color == AP_Text::TextColor::COLOR_DEFAULT) + color = AP_Text::TextColor::COLOR_BLUE; text = client->get_location_name(id, client->get_player_game(node.player)); } else if (node.type == "hint_status") { text = node.text; if (node.hintStatus == APClient::HINT_FOUND) - color = "green"; + color = AP_Text::TextColor::COLOR_GREEN; else if (node.hintStatus == APClient::HINT_UNSPECIFIED) - color = "grey"; + color = AP_Text::TextColor::COLOR_GRAY; else if (node.hintStatus == APClient::HINT_NO_PRIORITY) - color = "slateblue"; + color = AP_Text::TextColor::COLOR_SLATEBLUE; else if (node.hintStatus == APClient::HINT_AVOID) - color = "salmon"; + color = AP_Text::TextColor::COLOR_SALMON; else if (node.hintStatus == APClient::HINT_PRIORITY) - color = "plum"; + color = AP_Text::TextColor::COLOR_PLUM; else - color = "red"; // unknown status -> red + color = AP_Text::TextColor::COLOR_RED; // unknown status -> red } else if (node.type == "ERROR") { - color = "ERROR"; + color = AP_Text::TextColor::COLOR_ERROR; text = node.text; } else if (node.type == "LOG") { - color = "LOG"; + color = AP_Text::TextColor::COLOR_LOG; text = node.text; } else { - color = "white"; + color = AP_Text::TextColor::COLOR_WHITE; text = node.text; } - ColoredTextNode Colornode; + AP_Text::ColoredTextNode Colornode; Colornode.color = color; Colornode.text = text; coloredNodes.push_back(Colornode); diff --git a/soh/soh/Network/Archipelago/Archipelago.h b/soh/soh/Network/Archipelago/Archipelago.h index ed77fb5ee..d71d5466d 100644 --- a/soh/soh/Network/Archipelago/Archipelago.h +++ b/soh/soh/Network/Archipelago/Archipelago.h @@ -5,6 +5,8 @@ #include #include #include +#include "ArchipelagoConsoleWindow.h" +#include "ArchipelagoTypes.h" // Forward declaration class APClient; @@ -28,11 +30,6 @@ class ArchipelagoClient { uint64_t index; }; - struct ColoredTextNode { - std::string text; - std::string color; - }; - static ArchipelagoClient& GetInstance(); bool StartClient(); diff --git a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp index 4ee7b1e06..f5b687169 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp +++ b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp @@ -3,8 +3,9 @@ #include "soh/SohGui/UIWidgets.hpp" #include "soh/SohGui/SohGui.hpp" #include "soh/OTRGlobals.h" +#include "ArchipelagoTypes.h" -std::vector> Items; +std::vector> Items; bool autoScroll = true; using namespace UIWidgets; @@ -16,15 +17,15 @@ void ArchipelagoConsole_SendMessage(const char* fmt, ...) { vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); buf[IM_ARRAYSIZE(buf) - 1] = 0; va_end(args); - ArchipelagoClient::ColoredTextNode node; + AP_Text::ColoredTextNode node; node.text = std::string(buf); - node.color = "white"; + node.color = AP_Text::TextColor::COLOR_WHITE; if (strstr(buf, "[ERROR]")) { - node.color = "ERROR"; + node.color = AP_Text::TextColor::COLOR_ERROR; } else if (strstr(buf, "[LOG]")) { - node.color = "LOG"; + node.color = AP_Text::TextColor::COLOR_LOG; } - std::vector line; + std::vector line; line.push_back(node); Items.push_back(line); if (Items.size() > 50) { @@ -32,7 +33,7 @@ void ArchipelagoConsole_SendMessage(const char* fmt, ...) { } } -void ArchipelagoConsole_PrintJson(const std::vector nodes) { +void ArchipelagoConsole_PrintJson(const std::vector nodes) { Items.push_back(nodes); if (Items.size() > 50) { Items.erase(Items.begin()); @@ -50,8 +51,8 @@ void ArchipelagoConsoleWindow::DrawElement() { if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding, ImGuiWindowFlags_HorizontalScrollbar)) { - for (const std::vector& line : Items) { - for (const ArchipelagoClient::ColoredTextNode& node : line) { + for (const std::vector& line : Items) { + for (const AP_Text::ColoredTextNode& node : line) { ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(node.color)); ImGui::TextUnformatted(node.text.c_str()); ImGui::SameLine(); @@ -99,35 +100,41 @@ void ArchipelagoConsoleWindow::DrawElement() { ImGui::PopStyleVar(4); }; -ImVec4 getColorVal(const std::string& color) { // TODO change color strings to an enum - if (color == "ERROR") { - return ImVec4(1.0f, 0.4f, 0.4f, 1.0f); - } else if (color == "LOG") { - return ImVec4(0.7f, 0.7f, 1.0f, 1.0f); - } else if (color == "black") { - return ImVec4(0.000f, 0.000f, 0.000f, 1.00f); - } else if (color == "red") { - return ImVec4(0.933f, 0.000f, 0.000f, 1.00f); - } else if (color == "green") { - return ImVec4(0.000f, 1.000f, 0.498f, 1.00f); - } else if (color == "yellow") { - return ImVec4(0.980f, 0.980f, 0.824f, 1.00f); - } else if (color == "blue") { - return ImVec4(0.392f, 0.584f, 0.929f, 1.00f); - } else if (color == "cyan") { - return ImVec4(0.000f, 0.933f, 0.933f, 1.00f); - } else if (color == "magenta") { - return ImVec4(0.933f, 0.000f, 0.933f, 1.00f); - } else if (color == "slateblue") { - return ImVec4(0.427f, 0.545f, 0.910f, 1.00f); - } else if (color == "plum") { - return ImVec4(0.686f, 0.600f, 0.937f, 1.00f); - } else if (color == "salmon") { - return ImVec4(0.980f, 0.502f, 0.447f, 1.00f); - } else if (color == "white") { - return ImVec4(0.93f, 0.93f, 0.93f, 1.00f); - } else if (color == "orange") { - return ImVec4(1.000, 0.467f, 0.000f, 1.000f); - } - return ImVec4(0.93f, 0.93f, 0.93f, 1.00f); -} \ No newline at end of file +ImVec4 ArchipelagoConsoleWindow::getColorVal(const AP_Text::TextColor color) { + using apt = AP_Text::TextColor; + switch(color) { + case apt::COLOR_ERROR: + return ImVec4(1.0f, 0.4f, 0.4f, 1.0f); + case apt::COLOR_LOG: + return ImVec4(0.7f, 0.7f, 1.0f, 1.0f); + case apt::COLOR_BLACK: + return ImVec4(0.000f, 0.000f, 0.000f, 1.00f); + case apt::COLOR_RED: + return ImVec4(0.933f, 0.000f, 0.000f, 1.00f); + case apt::COLOR_GREEN: + return ImVec4(0.000f, 1.000f, 0.498f, 1.00f); + case apt::COLOR_YELLOW: + return ImVec4(0.980f, 0.980f, 0.824f, 1.00f); + case apt::COLOR_BLUE: + return ImVec4(0.392f, 0.584f, 0.929f, 1.00f); + case apt::COLOR_CYAN: + return ImVec4(0.000f, 0.933f, 0.933f, 1.00f); + case apt::COLOR_MAGENTA: + return ImVec4(0.933f, 0.000f, 0.933f, 1.00f); + case apt::COLOR_SLATEBLUE: + return ImVec4(0.427f, 0.545f, 0.910f, 1.00f); + case apt::COLOR_PLUM: + return ImVec4(0.686f, 0.600f, 0.937f, 1.00f); + case apt::COLOR_SALMON: + return ImVec4(0.980f, 0.502f, 0.447f, 1.00f); + case apt::COLOR_ORANGE: + return ImVec4(1.000, 0.467f, 0.000f, 1.000f); + case apt::COLOR_GRAY: + return ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + case apt::COLOR_WHITE: + case apt::COLOR_DEFAULT: + default: + return ImVec4(0.93f, 0.93f, 0.93f, 1.00f); + }; +} + \ No newline at end of file diff --git a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h index cd782ce86..92f975fb2 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h +++ b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h @@ -3,15 +3,17 @@ #define ARCHIPELAGO_CONSOLE_WINDOW_H #include -#include "Archipelago.h" #include #include +#include "ArchipelagoTypes.h" class ArchipelagoConsoleWindow final : public Ship::GuiWindow { public: using GuiWindow::GuiWindow; ~ArchipelagoConsoleWindow(){}; + static ImVec4 getColorVal(const AP_Text::TextColor color); + protected: void InitElement() override{}; void DrawElement() override; @@ -19,7 +21,6 @@ class ArchipelagoConsoleWindow final : public Ship::GuiWindow { }; void ArchipelagoConsole_SendMessage(const char* fmt, ...); -void ArchipelagoConsole_PrintJson(const std::vector nodes); -ImVec4 getColorVal(const std::string& color); +void ArchipelagoConsole_PrintJson(const std::vector nodes); #endif // ARCHIPELAGO_CONSOLE_WINDOW_H \ No newline at end of file diff --git a/soh/soh/Network/Archipelago/ArchipelagoTypes.h b/soh/soh/Network/Archipelago/ArchipelagoTypes.h new file mode 100644 index 000000000..e2da978b1 --- /dev/null +++ b/soh/soh/Network/Archipelago/ArchipelagoTypes.h @@ -0,0 +1,30 @@ +#pragma once +#ifdef __cplusplus + +namespace AP_Text { + enum class TextColor : char { + COLOR_DEFAULT = 0, + COLOR_ERROR, + COLOR_LOG, + COLOR_BLACK, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_CYAN, + COLOR_MAGENTA, + COLOR_SLATEBLUE, + COLOR_PLUM, + COLOR_SALMON, + COLOR_WHITE, + COLOR_ORANGE, + COLOR_GRAY + }; + + struct ColoredTextNode { + std::string text; + AP_Text::TextColor color; + }; +} + +#endif \ No newline at end of file