Added proper archipelago textclient colors to the console
This commit is contained in:
@@ -134,19 +134,7 @@ bool ArchipelagoClient::StartClient() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tag = "[" + arg.type + "] ";
|
ArchipelagoConsole_PrintJson(arg.data);
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "soh/SohGui/SohGui.hpp"
|
#include "soh/SohGui/SohGui.hpp"
|
||||||
#include "soh/OTRGlobals.h"
|
#include "soh/OTRGlobals.h"
|
||||||
|
|
||||||
ImVector<char*> Items;
|
std::vector<std::list<APClient::TextNode>> Items;
|
||||||
bool autoScroll = true;
|
bool autoScroll = true;
|
||||||
|
|
||||||
using namespace UIWidgets;
|
using namespace UIWidgets;
|
||||||
@@ -19,7 +19,22 @@ void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage, ...) {
|
|||||||
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
||||||
buf[IM_ARRAYSIZE(buf) - 1] = 0;
|
buf[IM_ARRAYSIZE(buf) - 1] = 0;
|
||||||
va_end(args);
|
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() {
|
void ArchipelagoConsoleWindow::DrawElement() {
|
||||||
@@ -28,57 +43,60 @@ void ArchipelagoConsoleWindow::DrawElement() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.15f, 0.15f, 0.15f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.15f, 0.15f, 0.15f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 8.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 8.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15.0f, 12.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,
|
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding,
|
||||||
ImGuiWindowFlags_HorizontalScrollbar)) {
|
ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||||
|
|
||||||
for (int i = 0; i < Items.Size; i++) {
|
for (const std::list<APClient::TextNode>& line : Items) {
|
||||||
const char* item = Items[i];
|
for(const APClient::TextNode& node : line) {
|
||||||
ImVec4 color;
|
APClient* client = ArchipelagoClient::GetInstance().apClient.get();
|
||||||
bool hasColor = false;
|
std::string color;
|
||||||
if (strstr(item, "[ERROR]")) {
|
std::string text;
|
||||||
color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
|
||||||
hasColor = true;
|
if(node.type == "player_id") {
|
||||||
} else if (strstr(item, "[LOG]")) {
|
int id = std::stoi(node.text);
|
||||||
color = ImVec4(0.7f, 0.7f, 1.0f, 1.0f);
|
if (color.empty() && id == client->get_player_number()) color = "magenta";
|
||||||
hasColor = true;
|
else if(color.empty()) color = "yellow";
|
||||||
} else if (strstr(item, "[Found]")) {
|
text = client->get_player_alias(id);
|
||||||
color = ImVec4(0.24f, 0.64f, 0.69f, 1.00f);
|
} else if (node.type == "item_id") {
|
||||||
hasColor = true;
|
int64_t id = std::stoll(node.text);
|
||||||
} else if (strstr(item, "[Received]")) {
|
if(color.empty()) {
|
||||||
color = ImVec4(0.18f, 0.76f, 0.42f, 1.00f);
|
if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT) color = "plum";
|
||||||
hasColor = true;
|
else if (node.flags & APClient::ItemFlags::FLAG_NEVER_EXCLUDE) color = "slateblue";
|
||||||
} else if (strstr(item, "[ItemCheat]")) {
|
else if (node.flags & APClient::ItemFlags::FLAG_TRAP) color = "salmon";
|
||||||
color = ImVec4(0.97f, 0.26f, 0.26f, 1.00f);
|
else color = "cyan";
|
||||||
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) {
|
text = client->get_item_name(id, client->get_player_game(node.player));
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TextUnformatted(item);
|
ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(color));
|
||||||
|
ImGui::TextUnformatted(text.c_str());
|
||||||
if (hasColor) {
|
ImGui::SameLine();
|
||||||
ImGui::PopStyleColor();
|
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.
|
// 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::EndChild();
|
||||||
ImGui::PopStyleColor();
|
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);
|
||||||
|
}
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
#define ARCHIPELAGO_CONSOLE_WINDOW_H
|
#define ARCHIPELAGO_CONSOLE_WINDOW_H
|
||||||
|
|
||||||
#include <libultraship/libultraship.h>
|
#include <libultraship/libultraship.h>
|
||||||
|
#include <apclient.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
|
class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
|
||||||
public:
|
public:
|
||||||
@@ -16,5 +19,7 @@ class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage = false, ...);
|
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
|
#endif // ARCHIPELAGO_CONSOLE_WINDOW_H
|
||||||
Reference in New Issue
Block a user