From 3d5ba95b96c14ecb5254f4f3ee29e5a583b330c0 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Mon, 21 Nov 2022 15:02:38 -0400 Subject: [PATCH] custom textbox colors Co-authored-by: Misa Elizabeth Kai --- desktop_version/src/BlockV.cpp | 10 +++++++++ desktop_version/src/CustomLevels.cpp | 31 ++++++++++++++++++++++++++++ desktop_version/src/CustomLevels.h | 3 +++ desktop_version/src/Script.cpp | 9 ++++++++ 4 files changed, 53 insertions(+) diff --git a/desktop_version/src/BlockV.cpp b/desktop_version/src/BlockV.cpp index b88c5fa6..bd82390a 100644 --- a/desktop_version/src/BlockV.cpp +++ b/desktop_version/src/BlockV.cpp @@ -2,6 +2,7 @@ #include +#include "CustomLevels.h" #include "Font.h" blockclass::blockclass(void) @@ -48,6 +49,15 @@ void blockclass::rectset(const int xi, const int yi, const int wi, const int hi) void blockclass::setblockcolour(const char* col) { +#ifndef NO_CUSTOM_LEVELS + if (cl.customcolours.count(col) != 0) + { + r = cl.customcolours[col].r; + g = cl.customcolours[col].g; + b = cl.customcolours[col].b; + } + else // Turn the if into an else if so we don't run the default colour processing +#endif if (SDL_strcmp(col, "cyan") == 0) { r = 164; diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 2e956254..de6a5eff 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -389,6 +389,8 @@ void customlevelclass::reset(void) script.clearcustom(); onewaycol_override = false; + + customcolours.clear(); } const int* customlevelclass::loadlevel( int rxi, int ryi ) @@ -1285,6 +1287,35 @@ next: script.customscripts.push_back(script_); } } + + if (SDL_strcmp(pKey, "TextboxColours") == 0) + { + for (tinyxml2::XMLElement* textColourElement = pElem->FirstChildElement(); textColourElement; textColourElement = textColourElement->NextSiblingElement()) + { + if (SDL_strcmp(textColourElement->Value(), "colour") == 0) + { + int r = 255; + int g = 255; + int b = 255; + + textColourElement->QueryIntAttribute("r", &r); + textColourElement->QueryIntAttribute("g", &g); + textColourElement->QueryIntAttribute("b", &b); + + const char* name = textColourElement->Attribute("name"); + + if (name != NULL) + { + SDL_Colour colour; + colour.r = r; + colour.g = g; + colour.b = b; + + customcolours[name] = colour; + } + } + } + } } if (mapwidth < maxwidth) diff --git a/desktop_version/src/CustomLevels.h b/desktop_version/src/CustomLevels.h index 0000a705..13f6c79d 100644 --- a/desktop_version/src/CustomLevels.h +++ b/desktop_version/src/CustomLevels.h @@ -6,6 +6,7 @@ #include #include #include +#include class CustomEntity { @@ -169,6 +170,8 @@ public: SDL_Color getonewaycol(int rx, int ry); SDL_Color getonewaycol(void); bool onewaycol_override; + + std::map customcolours; }; std::string translate_title(const std::string& title, bool* is_gettext); diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 1be4c5a4..1235c092 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -442,6 +442,15 @@ void scriptclass::run(void) { //oh boy //first word is the colour. +#ifndef NO_CUSTOM_LEVELS + if (cl.customcolours.count(words[1]) != 0) + { + r = cl.customcolours[words[1]].r; + g = cl.customcolours[words[1]].g; + b = cl.customcolours[words[1]].b; + } + else // Turn the if into an else if so we don't run the default colour processing +#endif if (words[1] == "cyan") { r = 164;