Theme keys are now sorted when loading so they appear in the right order down the line.
This commit is contained in:
parent
2224065304
commit
9246852c25
@ -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<std::pair<std::string,size_t>>mappedKeys;
|
||||
mappedKeys.reserve(unordered_map.size());
|
||||
for(auto&key:unordered_map){
|
||||
mappedKeys.push_back(key);
|
||||
}
|
||||
std::sort(mappedKeys.begin(),mappedKeys.end(),[](std::pair<std::string,size_t>&key1,std::pair<std::string,size_t>&key2){return key1.second<key2.second;});
|
||||
for(auto&key:mappedKeys){
|
||||
std::string themeName=key.first;
|
||||
std::string imgPath=DATA["Themes"][themeName]["Name"].GetString();
|
||||
Renderable&img=GFX["theme_img_directory"_S+imgPath+".png"];
|
||||
|
||||
@ -20,7 +20,7 @@ const Menu Menu::InitializeTestSubMenu(){
|
||||
|
||||
int index=0;
|
||||
for(auto&theme:Menu::themes){
|
||||
if(theme.first==Menu::themeSelection){
|
||||
if(theme.displayName==Menu::themeSelection){
|
||||
testSubMenu.I(A::INDEXED_THEME)=index;
|
||||
break;
|
||||
}
|
||||
@ -36,7 +36,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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
class Theme{
|
||||
friend class Menu;
|
||||
std::string displayName;
|
||||
std::string imgPath;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<typename T,typename O>
|
||||
class safeunorderedmap{
|
||||
std::unordered_map<T,O>map;
|
||||
std::unordered_map<T,int>map;
|
||||
std::vector<O>items;
|
||||
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: "<<key<<std::endl;
|
||||
throw;
|
||||
}
|
||||
return val;
|
||||
items.push_back({});
|
||||
return items[map[key]];
|
||||
}else{
|
||||
return map[key];
|
||||
return items[map[key]];
|
||||
}
|
||||
}
|
||||
O&at(T key){
|
||||
return map.at(key);
|
||||
return items[map.at(key)];
|
||||
}
|
||||
size_t count(T key){
|
||||
return map.count(key);
|
||||
@ -88,11 +91,12 @@ public:
|
||||
void Reset(){
|
||||
initialized=false;
|
||||
map.clear();
|
||||
items.clear();
|
||||
}
|
||||
auto begin()const{
|
||||
return map.begin();
|
||||
return items.begin();
|
||||
}
|
||||
auto end()const{
|
||||
return map.end();
|
||||
return items.end();
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user