Changed AP console text colors to enums

This commit is contained in:
Jerom Venneker
2025-07-07 19:22:17 +02:00
parent b700e0cc5f
commit d53afb534d
5 changed files with 107 additions and 72 deletions

View File

@@ -146,64 +146,64 @@ bool ArchipelagoClient::StartClient() {
return;
}
std::vector<ColoredTextNode> coloredNodes;
std::vector<AP_Text::ColoredTextNode> 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);

View File

@@ -5,6 +5,8 @@
#include <vector>
#include <nlohmann/json.hpp>
#include <queue>
#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();

View File

@@ -3,8 +3,9 @@
#include "soh/SohGui/UIWidgets.hpp"
#include "soh/SohGui/SohGui.hpp"
#include "soh/OTRGlobals.h"
#include "ArchipelagoTypes.h"
std::vector<std::vector<ArchipelagoClient::ColoredTextNode>> Items;
std::vector<std::vector<AP_Text::ColoredTextNode>> 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<ArchipelagoClient::ColoredTextNode> line;
std::vector<AP_Text::ColoredTextNode> 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<ArchipelagoClient::ColoredTextNode> nodes) {
void ArchipelagoConsole_PrintJson(const std::vector<AP_Text::ColoredTextNode> 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<ArchipelagoClient::ColoredTextNode>& line : Items) {
for (const ArchipelagoClient::ColoredTextNode& node : line) {
for (const std::vector<AP_Text::ColoredTextNode>& 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);
}
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);
};
}

View File

@@ -3,15 +3,17 @@
#define ARCHIPELAGO_CONSOLE_WINDOW_H
#include <libultraship/libultraship.h>
#include "Archipelago.h"
#include <vector>
#include <list>
#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<ArchipelagoClient::ColoredTextNode> nodes);
ImVec4 getColorVal(const std::string& color);
void ArchipelagoConsole_PrintJson(const std::vector<AP_Text::ColoredTextNode> nodes);
#endif // ARCHIPELAGO_CONSOLE_WINDOW_H

View File

@@ -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