From 7d403089ec01ffc6d1429f6ebf401949152ada3c Mon Sep 17 00:00:00 2001 From: Kagernac Date: Fri, 7 Jun 2024 18:38:32 -0700 Subject: [PATCH] Cleaner implementation Retrieved the Colours straight from Settings Made tagname clearer in openmw_list.skin.xml Fixed minor formatting issue in validate.cpp, textcolours.cpp Updated skin variables to be const and string_view --- apps/openmw/mwgui/dialogue.cpp | 4 ++-- apps/openmw/mwgui/textcolours.cpp | 2 -- components/fallback/validate.cpp | 3 +-- components/widgets/tags.cpp | 24 ++++-------------------- files/data/mygui/openmw_list.skin.xml | 12 ++++++------ 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index ba40fa92e1..56d2699175 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -794,8 +794,8 @@ namespace MWGui if (!Settings::gui().mColorTopicEnable) return; - std::string specificSkin = "MW_ListLine_Specific"; - std::string exhaustedSkin = "MW_ListLine_Exhausted"; + const std::string_view specificSkin = "MW_ListLine_Specific"; + const std::string_view exhaustedSkin = "MW_ListLine_Exhausted"; for (const std::string& keyword : mKeywords) { diff --git a/apps/openmw/mwgui/textcolours.cpp b/apps/openmw/mwgui/textcolours.cpp index 981817a4a9..77afa5e265 100644 --- a/apps/openmw/mwgui/textcolours.cpp +++ b/apps/openmw/mwgui/textcolours.cpp @@ -11,7 +11,6 @@ namespace MWGui return MyGUI::Colour::parse(MyGUI::LanguageManager::getInstance().replaceTags("#{fontcolour=" + type + "}")); } - void TextColours::loadColours() { header = getTextColour("header"); @@ -33,6 +32,5 @@ namespace MWGui journalTopic = getTextColour("journal_topic"); journalTopicOver = getTextColour("journal_topic_over"); journalTopicPressed = getTextColour("journal_topic_pressed"); - } } diff --git a/components/fallback/validate.cpp b/components/fallback/validate.cpp index f6868e56f4..571f0f9b19 100644 --- a/components/fallback/validate.cpp +++ b/components/fallback/validate.cpp @@ -109,8 +109,7 @@ static const std::set allowedKeysNonNumeric = { "Blood_Model_0 "FontColor_color_link", "FontColor_color_link_over", "FontColor_color_link_pressed", "FontColor_color_magic", "FontColor_color_magic_fill", "FontColor_color_misc", "FontColor_color_negative", "FontColor_color_normal", "FontColor_color_normal_over", "FontColor_color_normal_pressed", "FontColor_color_notify", - "FontColor_color_positive", "FontColor_color_weapon_fill", - "Fonts_Font_0", "Fonts_Font_1", "Fonts_Font_2", + "FontColor_color_positive", "FontColor_color_weapon_fill", "Fonts_Font_0", "Fonts_Font_1", "Fonts_Font_2", "Level_Up_Default", "Moons_Script_Color", "Movies_Company_Logo", "Movies_Morrowind_Logo", "Movies_New_Game", "Question_10_AnswerOne", "Question_10_AnswerThree", "Question_10_AnswerTwo", "Question_10_Question", "Question_10_Sound", "Question_1_AnswerOne", "Question_1_AnswerThree", "Question_1_AnswerTwo", diff --git a/components/widgets/tags.cpp b/components/widgets/tags.cpp index 1477470024..d5796c35b5 100644 --- a/components/widgets/tags.cpp +++ b/components/widgets/tags.cpp @@ -12,7 +12,7 @@ namespace Gui { std::string_view fontcolour = "fontcolour="; std::string_view fontcolourhtml = "fontcolourhtml="; - std::string_view fontcolouroptional = "fontcolouroptional="; + std::string_view fontcolouroptional = "fontcoloursetting="; if (tag.starts_with(fontcolour)) { @@ -61,25 +61,9 @@ namespace Gui } else if (tag.starts_with(fontcolouroptional)) { - std::string_view category = "GUI"; - std::string colortag = ""; - colortag += tag.substr(fontcolouroptional.length()); - std::string str = Settings::Manager::getString(colortag, category); - if (str.empty()) - throw std::runtime_error("Unable to map setting to value: " + colortag); - - std::string ret[4]; - unsigned int j = 0; - for (unsigned int i = 0; i < str.length(); ++i) - { - if (str[i] == ' ') - j++; - else if (str[i] != ' ') - ret[j] += str[i]; - } - MyGUI::Colour col(MyGUI::utility::parseFloat(ret[0]), MyGUI::utility::parseFloat(ret[1]), - MyGUI::utility::parseFloat(ret[2]), MyGUI::utility::parseFloat(ret[3])); - out = col.print(); + std::string_view colortag = tag.substr(fontcolouroptional.length()); + const MyGUI::Colour& customColour = Settings::get("GUI", colortag).get(); + out = customColour.print(); return true; } return false; diff --git a/files/data/mygui/openmw_list.skin.xml b/files/data/mygui/openmw_list.skin.xml index 45551429ed..30ebdca35d 100644 --- a/files/data/mygui/openmw_list.skin.xml +++ b/files/data/mygui/openmw_list.skin.xml @@ -129,9 +129,9 @@ - - - + + + @@ -140,9 +140,9 @@ - - - + + +