Added proper archipelago textclient colors to the console

This commit is contained in:
Jerom Venneker
2025-05-28 22:52:14 +02:00
parent cc40d3ca86
commit 422b7d1950
3 changed files with 103 additions and 59 deletions

View File

@@ -134,19 +134,7 @@ bool ArchipelagoClient::StartClient() {
return;
}
std::string tag = "[" + arg.type + "] ";
const int slot = apClient->get_player_number();
if(arg.type == "ItemSend") {
if((*arg.item).player == slot) {
tag = "[Found] ";
} else if (*arg.receiving == slot ) {
tag = "[Received] ";
}
}
std::string text = tag + apClient->render_json(arg.data, APClient::RenderFormat::TEXT);
ArchipelagoConsole_SendMessage(text.c_str(), false);
ArchipelagoConsole_PrintJson(arg.data);
});
return true;

View File

@@ -4,7 +4,7 @@
#include "soh/SohGui/SohGui.hpp"
#include "soh/OTRGlobals.h"
ImVector<char*> Items;
std::vector<std::list<APClient::TextNode>> Items;
bool autoScroll = true;
using namespace UIWidgets;
@@ -19,7 +19,22 @@ void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage, ...) {
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
Items.push_back(strdup(buf));
APClient::TextNode node;
if (strstr(buf, "[ERROR]")) {
node.type = "ERROR";
node.color = "ERROR";
} else if (strstr(buf, "[LOG]")) {
node.type = "LOG";
node.color = "LOG";
}
node.text = std::string(buf);
std::list<APClient::TextNode> line;
line.push_back(node);
Items.push_back(line);
}
void ArchipelagoConsole_PrintJson(const std::list<APClient::TextNode> nodes) {
Items.push_back(nodes);
}
void ArchipelagoConsoleWindow::DrawElement() {
@@ -28,57 +43,60 @@ void ArchipelagoConsoleWindow::DrawElement() {
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.15f, 0.15f, 0.15f, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 8.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15.0f, 12.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 2.0f));
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding,
ImGuiWindowFlags_HorizontalScrollbar)) {
for (int i = 0; i < Items.Size; i++) {
const char* item = Items[i];
ImVec4 color;
bool hasColor = false;
if (strstr(item, "[ERROR]")) {
color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
hasColor = true;
} else if (strstr(item, "[LOG]")) {
color = ImVec4(0.7f, 0.7f, 1.0f, 1.0f);
hasColor = true;
} else if (strstr(item, "[Found]")) {
color = ImVec4(0.24f, 0.64f, 0.69f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Received]")) {
color = ImVec4(0.18f, 0.76f, 0.42f, 1.00f);
hasColor = true;
} else if (strstr(item, "[ItemCheat]")) {
color = ImVec4(0.97f, 0.26f, 0.26f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Hint]")) {
color = ImVec4(0.89f, 0.45f, 1.00f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Join]")) {
color = ImVec4(0.00f, 0.80f, 0.11f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Part]")) {
color = ImVec4(1.00f, 0.01f, 0.01f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Goal]")) {
color = ImVec4(0.00f, 0.70f, 0.21f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Release]")) {
color = ImVec4(0.51f, 0.21f, 0.61f, 1.00f);
hasColor = true;
} else if (strstr(item, "[Collect]")) {
color = ImVec4(0.51f, 0.21f, 0.61f, 1.00f);
hasColor = true;
}
if (hasColor) {
ImGui::PushStyleColor(ImGuiCol_Text, color);
}
for (const std::list<APClient::TextNode>& line : Items) {
for(const APClient::TextNode& node : line) {
APClient* client = ArchipelagoClient::GetInstance().apClient.get();
std::string color;
std::string text;
ImGui::TextUnformatted(item);
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";
text = client->get_player_alias(id);
} else if (node.type == "item_id") {
int64_t id = std::stoll(node.text);
if(color.empty()) {
if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT) color = "plum";
else if (node.flags & APClient::ItemFlags::FLAG_NEVER_EXCLUDE) color = "slateblue";
else if (node.flags & APClient::ItemFlags::FLAG_TRAP) color = "salmon";
else 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";
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";
else if (node.hintStatus == APClient::HINT_UNSPECIFIED) color = "grey";
else if (node.hintStatus == APClient::HINT_NO_PRIORITY) color = "slateblue";
else if (node.hintStatus == APClient::HINT_AVOID) color = "salmon";
else if (node.hintStatus == APClient::HINT_PRIORITY) color = "plum";
else color = "red"; // unknown status -> red
} else if (node.type == "ERROR") {
color = "ERROR";
text = node.text;
} else if (node.type == "LOG") {
color = "LOG";
text = node.text;
} else {
color = "white";
text = node.text;
}
if (hasColor) {
ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(color));
ImGui::TextUnformatted(text.c_str());
ImGui::SameLine();
ImGui::PopStyleColor();
}
ImGui::NewLine();
}
// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
@@ -89,5 +107,38 @@ void ArchipelagoConsoleWindow::DrawElement() {
}
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::PopStyleVar(2);
ImGui::PopStyleVar(3);
};
ImVec4 getColorVal(const std::string& color) {
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);
}

View File

@@ -3,6 +3,9 @@
#define ARCHIPELAGO_CONSOLE_WINDOW_H
#include <libultraship/libultraship.h>
#include <apclient.hpp>
#include <vector>
#include <list>
class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
public:
@@ -16,5 +19,7 @@ class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
};
void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage = false, ...);
void ArchipelagoConsole_PrintJson(const std::list<APClient::TextNode> nodes);
ImVec4 getColorVal(const std::string& color);
#endif // ARCHIPELAGO_CONSOLE_WINDOW_H