Changed AP console text colors to enums
This commit is contained in:
@@ -146,64 +146,64 @@ bool ArchipelagoClient::StartClient() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ColoredTextNode> coloredNodes;
|
std::vector<AP_Text::ColoredTextNode> coloredNodes;
|
||||||
|
|
||||||
for (const APClient::TextNode& node : arg.data) {
|
for (const APClient::TextNode& node : arg.data) {
|
||||||
APClient* client = apClient.get();
|
APClient* client = apClient.get();
|
||||||
std::string color;
|
AP_Text::TextColor color = AP_Text::TextColor::COLOR_DEFAULT;
|
||||||
std::string text;
|
std::string text;
|
||||||
|
|
||||||
if (node.type == "player_id") {
|
if (node.type == "player_id") {
|
||||||
int id = std::stoi(node.text);
|
int id = std::stoi(node.text);
|
||||||
if (color.empty() && id == client->get_player_number())
|
if (color == AP_Text::TextColor::COLOR_DEFAULT && id == client->get_player_number())
|
||||||
color = "magenta";
|
color = AP_Text::TextColor::COLOR_MAGENTA;
|
||||||
else if (color.empty())
|
else if (color == AP_Text::TextColor::COLOR_DEFAULT)
|
||||||
color = "yellow";
|
color = AP_Text::TextColor::COLOR_YELLOW;
|
||||||
text = client->get_player_alias(id);
|
text = client->get_player_alias(id);
|
||||||
} else if (node.type == "item_id") {
|
} else if (node.type == "item_id") {
|
||||||
int64_t id = std::stoll(node.text);
|
int64_t id = std::stoll(node.text);
|
||||||
if (color.empty()) {
|
if (color == AP_Text::TextColor::COLOR_DEFAULT) {
|
||||||
if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT)
|
if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT)
|
||||||
color = "plum";
|
color = AP_Text::TextColor::COLOR_PLUM;
|
||||||
else if (node.flags & APClient::ItemFlags::FLAG_NEVER_EXCLUDE)
|
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)
|
else if (node.flags & APClient::ItemFlags::FLAG_TRAP)
|
||||||
color = "salmon";
|
color = AP_Text::TextColor::COLOR_SALMON;
|
||||||
else
|
else
|
||||||
color = "cyan";
|
color = AP_Text::TextColor::COLOR_CYAN;
|
||||||
}
|
}
|
||||||
text = client->get_item_name(id, client->get_player_game(node.player));
|
text = client->get_item_name(id, client->get_player_game(node.player));
|
||||||
} else if (node.type == "location_id") {
|
} else if (node.type == "location_id") {
|
||||||
int64_t id = std::stoll(node.text);
|
int64_t id = std::stoll(node.text);
|
||||||
if (color.empty())
|
if (color == AP_Text::TextColor::COLOR_DEFAULT)
|
||||||
color = "blue";
|
color = AP_Text::TextColor::COLOR_BLUE;
|
||||||
text = client->get_location_name(id, client->get_player_game(node.player));
|
text = client->get_location_name(id, client->get_player_game(node.player));
|
||||||
} else if (node.type == "hint_status") {
|
} else if (node.type == "hint_status") {
|
||||||
text = node.text;
|
text = node.text;
|
||||||
if (node.hintStatus == APClient::HINT_FOUND)
|
if (node.hintStatus == APClient::HINT_FOUND)
|
||||||
color = "green";
|
color = AP_Text::TextColor::COLOR_GREEN;
|
||||||
else if (node.hintStatus == APClient::HINT_UNSPECIFIED)
|
else if (node.hintStatus == APClient::HINT_UNSPECIFIED)
|
||||||
color = "grey";
|
color = AP_Text::TextColor::COLOR_GRAY;
|
||||||
else if (node.hintStatus == APClient::HINT_NO_PRIORITY)
|
else if (node.hintStatus == APClient::HINT_NO_PRIORITY)
|
||||||
color = "slateblue";
|
color = AP_Text::TextColor::COLOR_SLATEBLUE;
|
||||||
else if (node.hintStatus == APClient::HINT_AVOID)
|
else if (node.hintStatus == APClient::HINT_AVOID)
|
||||||
color = "salmon";
|
color = AP_Text::TextColor::COLOR_SALMON;
|
||||||
else if (node.hintStatus == APClient::HINT_PRIORITY)
|
else if (node.hintStatus == APClient::HINT_PRIORITY)
|
||||||
color = "plum";
|
color = AP_Text::TextColor::COLOR_PLUM;
|
||||||
else
|
else
|
||||||
color = "red"; // unknown status -> red
|
color = AP_Text::TextColor::COLOR_RED; // unknown status -> red
|
||||||
} else if (node.type == "ERROR") {
|
} else if (node.type == "ERROR") {
|
||||||
color = "ERROR";
|
color = AP_Text::TextColor::COLOR_ERROR;
|
||||||
text = node.text;
|
text = node.text;
|
||||||
} else if (node.type == "LOG") {
|
} else if (node.type == "LOG") {
|
||||||
color = "LOG";
|
color = AP_Text::TextColor::COLOR_LOG;
|
||||||
text = node.text;
|
text = node.text;
|
||||||
} else {
|
} else {
|
||||||
color = "white";
|
color = AP_Text::TextColor::COLOR_WHITE;
|
||||||
text = node.text;
|
text = node.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColoredTextNode Colornode;
|
AP_Text::ColoredTextNode Colornode;
|
||||||
Colornode.color = color;
|
Colornode.color = color;
|
||||||
Colornode.text = text;
|
Colornode.text = text;
|
||||||
coloredNodes.push_back(Colornode);
|
coloredNodes.push_back(Colornode);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include "ArchipelagoConsoleWindow.h"
|
||||||
|
#include "ArchipelagoTypes.h"
|
||||||
|
|
||||||
// Forward declaration
|
// Forward declaration
|
||||||
class APClient;
|
class APClient;
|
||||||
@@ -28,11 +30,6 @@ class ArchipelagoClient {
|
|||||||
uint64_t index;
|
uint64_t index;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColoredTextNode {
|
|
||||||
std::string text;
|
|
||||||
std::string color;
|
|
||||||
};
|
|
||||||
|
|
||||||
static ArchipelagoClient& GetInstance();
|
static ArchipelagoClient& GetInstance();
|
||||||
|
|
||||||
bool StartClient();
|
bool StartClient();
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
#include "soh/SohGui/UIWidgets.hpp"
|
#include "soh/SohGui/UIWidgets.hpp"
|
||||||
#include "soh/SohGui/SohGui.hpp"
|
#include "soh/SohGui/SohGui.hpp"
|
||||||
#include "soh/OTRGlobals.h"
|
#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;
|
bool autoScroll = true;
|
||||||
|
|
||||||
using namespace UIWidgets;
|
using namespace UIWidgets;
|
||||||
@@ -16,15 +17,15 @@ void ArchipelagoConsole_SendMessage(const char* fmt, ...) {
|
|||||||
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);
|
||||||
ArchipelagoClient::ColoredTextNode node;
|
AP_Text::ColoredTextNode node;
|
||||||
node.text = std::string(buf);
|
node.text = std::string(buf);
|
||||||
node.color = "white";
|
node.color = AP_Text::TextColor::COLOR_WHITE;
|
||||||
if (strstr(buf, "[ERROR]")) {
|
if (strstr(buf, "[ERROR]")) {
|
||||||
node.color = "ERROR";
|
node.color = AP_Text::TextColor::COLOR_ERROR;
|
||||||
} else if (strstr(buf, "[LOG]")) {
|
} 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);
|
line.push_back(node);
|
||||||
Items.push_back(line);
|
Items.push_back(line);
|
||||||
if (Items.size() > 50) {
|
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);
|
Items.push_back(nodes);
|
||||||
if (Items.size() > 50) {
|
if (Items.size() > 50) {
|
||||||
Items.erase(Items.begin());
|
Items.erase(Items.begin());
|
||||||
@@ -50,8 +51,8 @@ void ArchipelagoConsoleWindow::DrawElement() {
|
|||||||
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding,
|
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding,
|
||||||
ImGuiWindowFlags_HorizontalScrollbar)) {
|
ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||||
|
|
||||||
for (const std::vector<ArchipelagoClient::ColoredTextNode>& line : Items) {
|
for (const std::vector<AP_Text::ColoredTextNode>& line : Items) {
|
||||||
for (const ArchipelagoClient::ColoredTextNode& node : line) {
|
for (const AP_Text::ColoredTextNode& node : line) {
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(node.color));
|
ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(node.color));
|
||||||
ImGui::TextUnformatted(node.text.c_str());
|
ImGui::TextUnformatted(node.text.c_str());
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -99,35 +100,41 @@ void ArchipelagoConsoleWindow::DrawElement() {
|
|||||||
ImGui::PopStyleVar(4);
|
ImGui::PopStyleVar(4);
|
||||||
};
|
};
|
||||||
|
|
||||||
ImVec4 getColorVal(const std::string& color) { // TODO change color strings to an enum
|
ImVec4 ArchipelagoConsoleWindow::getColorVal(const AP_Text::TextColor color) {
|
||||||
if (color == "ERROR") {
|
using apt = AP_Text::TextColor;
|
||||||
return ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
switch(color) {
|
||||||
} else if (color == "LOG") {
|
case apt::COLOR_ERROR:
|
||||||
return ImVec4(0.7f, 0.7f, 1.0f, 1.0f);
|
return ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
||||||
} else if (color == "black") {
|
case apt::COLOR_LOG:
|
||||||
return ImVec4(0.000f, 0.000f, 0.000f, 1.00f);
|
return ImVec4(0.7f, 0.7f, 1.0f, 1.0f);
|
||||||
} else if (color == "red") {
|
case apt::COLOR_BLACK:
|
||||||
return ImVec4(0.933f, 0.000f, 0.000f, 1.00f);
|
return ImVec4(0.000f, 0.000f, 0.000f, 1.00f);
|
||||||
} else if (color == "green") {
|
case apt::COLOR_RED:
|
||||||
return ImVec4(0.000f, 1.000f, 0.498f, 1.00f);
|
return ImVec4(0.933f, 0.000f, 0.000f, 1.00f);
|
||||||
} else if (color == "yellow") {
|
case apt::COLOR_GREEN:
|
||||||
return ImVec4(0.980f, 0.980f, 0.824f, 1.00f);
|
return ImVec4(0.000f, 1.000f, 0.498f, 1.00f);
|
||||||
} else if (color == "blue") {
|
case apt::COLOR_YELLOW:
|
||||||
return ImVec4(0.392f, 0.584f, 0.929f, 1.00f);
|
return ImVec4(0.980f, 0.980f, 0.824f, 1.00f);
|
||||||
} else if (color == "cyan") {
|
case apt::COLOR_BLUE:
|
||||||
return ImVec4(0.000f, 0.933f, 0.933f, 1.00f);
|
return ImVec4(0.392f, 0.584f, 0.929f, 1.00f);
|
||||||
} else if (color == "magenta") {
|
case apt::COLOR_CYAN:
|
||||||
return ImVec4(0.933f, 0.000f, 0.933f, 1.00f);
|
return ImVec4(0.000f, 0.933f, 0.933f, 1.00f);
|
||||||
} else if (color == "slateblue") {
|
case apt::COLOR_MAGENTA:
|
||||||
return ImVec4(0.427f, 0.545f, 0.910f, 1.00f);
|
return ImVec4(0.933f, 0.000f, 0.933f, 1.00f);
|
||||||
} else if (color == "plum") {
|
case apt::COLOR_SLATEBLUE:
|
||||||
return ImVec4(0.686f, 0.600f, 0.937f, 1.00f);
|
return ImVec4(0.427f, 0.545f, 0.910f, 1.00f);
|
||||||
} else if (color == "salmon") {
|
case apt::COLOR_PLUM:
|
||||||
return ImVec4(0.980f, 0.502f, 0.447f, 1.00f);
|
return ImVec4(0.686f, 0.600f, 0.937f, 1.00f);
|
||||||
} else if (color == "white") {
|
case apt::COLOR_SALMON:
|
||||||
return ImVec4(0.93f, 0.93f, 0.93f, 1.00f);
|
return ImVec4(0.980f, 0.502f, 0.447f, 1.00f);
|
||||||
} else if (color == "orange") {
|
case apt::COLOR_ORANGE:
|
||||||
return ImVec4(1.000, 0.467f, 0.000f, 1.000f);
|
return ImVec4(1.000, 0.467f, 0.000f, 1.000f);
|
||||||
}
|
case apt::COLOR_GRAY:
|
||||||
return ImVec4(0.93f, 0.93f, 0.93f, 1.00f);
|
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);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3,15 +3,17 @@
|
|||||||
#define ARCHIPELAGO_CONSOLE_WINDOW_H
|
#define ARCHIPELAGO_CONSOLE_WINDOW_H
|
||||||
|
|
||||||
#include <libultraship/libultraship.h>
|
#include <libultraship/libultraship.h>
|
||||||
#include "Archipelago.h"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include "ArchipelagoTypes.h"
|
||||||
|
|
||||||
class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
|
class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
|
||||||
public:
|
public:
|
||||||
using GuiWindow::GuiWindow;
|
using GuiWindow::GuiWindow;
|
||||||
~ArchipelagoConsoleWindow(){};
|
~ArchipelagoConsoleWindow(){};
|
||||||
|
|
||||||
|
static ImVec4 getColorVal(const AP_Text::TextColor color);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InitElement() override{};
|
void InitElement() override{};
|
||||||
void DrawElement() override;
|
void DrawElement() override;
|
||||||
@@ -19,7 +21,6 @@ class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void ArchipelagoConsole_SendMessage(const char* fmt, ...);
|
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);
|
||||||
ImVec4 getColorVal(const std::string& color);
|
|
||||||
|
|
||||||
#endif // ARCHIPELAGO_CONSOLE_WINDOW_H
|
#endif // ARCHIPELAGO_CONSOLE_WINDOW_H
|
||||||
30
soh/soh/Network/Archipelago/ArchipelagoTypes.h
Normal file
30
soh/soh/Network/Archipelago/ArchipelagoTypes.h
Normal 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
|
||||||
Reference in New Issue
Block a user