From 9246852c2589d35e9bec448ee6df84b07366ec43 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 4 Oct 2023 01:14:50 -0500 Subject: [PATCH] Theme keys are now sorted when loading so they appear in the right order down the line. --- Crawler/Crawler.cpp | 9 ++++++++- Crawler/TestSubMenu.cpp | 6 +++--- Crawler/Theme.h | 1 + Crawler/Version.h | 2 +- Crawler/assets/config/gfx/themes.txt | 2 +- Crawler/safemap.h | 18 +++++++++++------- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 1c27058a..5231d031 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -1690,7 +1690,14 @@ void Crawler::InitializeGraphics(){ } //Specifically split up the 9 patch image into multiple pieces for each theme. - for(auto&key:DATA["Themes"].GetKeys()){ + const auto&unordered_map=DATA["Themes"].GetKeys(); + std::vector>mappedKeys; + mappedKeys.reserve(unordered_map.size()); + for(auto&key:unordered_map){ + mappedKeys.push_back(key); + } + std::sort(mappedKeys.begin(),mappedKeys.end(),[](std::pair&key1,std::pair&key2){return key1.secondSetLabel("Theme\n"+Menu::themes[themeSelection].GetThemeName()); break; } @@ -53,7 +53,7 @@ const Menu Menu::InitializeTestSubMenu(){ int index=0; for(auto&theme:Menu::themes){ if(index==menu.I(A::INDEXED_THEME)){ - Menu::themeSelection=theme.first; + Menu::themeSelection=theme.displayName; ((MenuLabel*)(menu.components["THEME_DISPLAY"]))->SetLabel("Theme\n"+Menu::themes[themeSelection].GetThemeName()); break; } diff --git a/Crawler/Theme.h b/Crawler/Theme.h index 011b8cd4..52efc4c6 100644 --- a/Crawler/Theme.h +++ b/Crawler/Theme.h @@ -2,6 +2,7 @@ #include "olcPixelGameEngine.h" class Theme{ + friend class Menu; std::string displayName; std::string imgPath; diff --git a/Crawler/Version.h b/Crawler/Version.h index beb6e554..7efdda34 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1706 +#define VERSION_BUILD 1719 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/gfx/themes.txt b/Crawler/assets/config/gfx/themes.txt index 88118607..60f0b068 100644 --- a/Crawler/assets/config/gfx/themes.txt +++ b/Crawler/assets/config/gfx/themes.txt @@ -1,7 +1,7 @@ ThemeGlobal { # How long it takes for the fade-in/fade-out effect to occur. - HighlightTime = 0.6 + HighlightTime = 0.2 } Themes diff --git a/Crawler/safemap.h b/Crawler/safemap.h index 1ecd2ef6..cde6f16e 100644 --- a/Crawler/safemap.h +++ b/Crawler/safemap.h @@ -50,9 +50,11 @@ public: }; //A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection. +//This unordered map should return items inserted in order. Therefore internally, it's hosted as a vector. As such, if an item is added to this map it's possible the refernce becomes stale when another item is added due to a vector expanding. BEWARE! template class safeunorderedmap{ - std::unordered_mapmap; + std::unordered_mapmap; + std::vectoritems; bool initialized=false; public: O&operator[](T key){ @@ -62,18 +64,19 @@ public: } if(!initialized){ size_t originalSize=map.size(); - O&val=map[key]; + map[key]=items.size(); if(originalSize==map.size()){ std::cout<<"WARNING! A previously set value has been overwritten! Key: "<