diff --git a/Crawler/Animation.cpp b/Crawler/Animation.cpp index 5776b270..e9eec8b9 100644 --- a/Crawler/Animation.cpp +++ b/Crawler/Animation.cpp @@ -216,8 +216,6 @@ void sig::Animation::InitializeAnimations(){ if(!ANIMATION_DATA.count(imgFile)){ std::cout<<"WARNING! Animation data for "<Size()); - std::maptest; - test.begin(); } } } diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 432f5ac8..1c27058a 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -78,6 +78,7 @@ Crawler::Crawler() utils::datafile::Read(DATA,CONFIG_PATH + "class_directory"_S + cl + ".txt"); } utils::datafile::DEBUG_ACCESS_OPTIONS="debug_access_options"_I; + utils::datafile::INITIAL_SETUP_COMPLETE=true; } bool Crawler::OnUserCreate(){ @@ -1682,7 +1683,7 @@ void Crawler::InitializeGraphics(){ std::string key=val.first; std::string imgFile=DATA["Images"][key].GetString(); std::cout<<"Loading image "+imgFile+"..."<Update(); + DrawPartialSprite({0,0},sourceImg.Sprite(),{x*"Interface.9PatchSize"_i[0],y*"Interface.9PatchSize"_i[1]},{"Interface.9PatchSize"_i[0],"Interface.9PatchSize"_i[1]}); + patchImg.Decal()->Update(); SetDrawTarget(nullptr); } } SetPixelMode(prevMode); - Menu::themes[imgPath]=Theme{themeName,imgPath,DATA["Themes"][themeName]["ButtonColor"].GetPixel(),DATA["Themes"][themeName]["HighlightColor"].GetPixel()}; + std::cout<<"Theme "<Menu::stack; std::mapMenu::menus; -std::string Menu::themeSelection="9patch"; -safemapMenu::themes; +std::string Menu::themeSelection="BlueDefault"; +safeunorderedmapMenu::themes; INCLUDE_GFX @@ -90,7 +90,7 @@ void Menu::Update(Crawler*game){ void Menu::Draw(Crawler*game){ vf2d upperLeftPos=game->GetScreenSize()/2-size/2; - if(scaled){ + if(GetCurrentTheme().IsScaled()){ DrawScaledWindow(game,upperLeftPos); }else{ DrawTiledWindow(game,upperLeftPos); @@ -239,31 +239,32 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ } } -void Menu::SetScaledPatchBorder(bool scaled){ - this->scaled=scaled; -} - void Menu::DrawScaledWindow(Crawler*game,vf2d menuPos){ vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]}; //Upper-Left - game->DrawPartialDecal(menuPos-patchSize,patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*0},patchSize); + game->DrawPartialDecal(menuPos-patchSize,patchSize,GetPatchPart(0,0).Decal(),{patchSize.x*0,patchSize.y*0},patchSize); //Upper-Right - game->DrawPartialDecal(menuPos+vf2d{size.x,-patchSize.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*0},patchSize); + game->DrawPartialDecal(menuPos+vf2d{size.x,-patchSize.y},patchSize,GetPatchPart(2,0).Decal(),{patchSize.x*2,patchSize.y*0},patchSize); //Bottom-Left - game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*2},patchSize); + game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,size.y},patchSize,GetPatchPart(0,2).Decal(),{patchSize.x*0,patchSize.y*2},patchSize); //Bottom-Right - game->DrawPartialDecal(menuPos+vf2d{size.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*2},patchSize); + game->DrawPartialDecal(menuPos+vf2d{size.x,size.y},patchSize,GetPatchPart(2,2).Decal(),{patchSize.x*2,patchSize.y*2},patchSize); //Top - game->DrawPartialDecal(menuPos+vf2d{0,-patchSize.y},vf2d{size.x,patchSize.y},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*0},patchSize); + game->DrawPartialDecal(menuPos+vf2d{0,-patchSize.y},vf2d{size.x,patchSize.y},GetPatchPart(1,0).Decal(),{patchSize.x*1,patchSize.y*0},patchSize); //Left - game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,0},vf2d{patchSize.x,size.y},GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*1},patchSize); + game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,0},vf2d{patchSize.x,size.y},GetPatchPart(0,1).Decal(),{patchSize.x*0,patchSize.y*1},patchSize); //Right - game->DrawPartialDecal(menuPos+vf2d{size.x,0},vf2d{patchSize.x,size.y},GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*1},patchSize); + game->DrawPartialDecal(menuPos+vf2d{size.x,0},vf2d{patchSize.x,size.y},GetPatchPart(2,1).Decal(),{patchSize.x*2,patchSize.y*1},patchSize); //Bottom - game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*2},patchSize); + game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GetPatchPart(1,2).Decal(),{patchSize.x*1,patchSize.y*2},patchSize); //Center - game->DrawPartialDecal(menuPos,size,GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*1},patchSize); + if(GetCurrentTheme().HasBackground()){ + Decal*back=GetCurrentTheme().GetBackground(); + game->DrawPartialDecal(menuPos,size,back,{0,0},back->sprite->Size()); + }else{ + game->DrawPartialDecal(menuPos,size,GetPatchPart(1,1).Decal(),{patchSize.x*1,patchSize.y*1},patchSize); + } } void Menu::DrawTiledWindow(Crawler*game,vf2d menuPos){ @@ -286,9 +287,18 @@ void Menu::DrawTiledWindow(Crawler*game,vf2d menuPos){ //Bottom game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GetPatchPart(1,2).Decal(),{0,0},vf2d{size.x,patchSize.y}); //Center - game->DrawPartialDecal(menuPos,size,GetPatchPart(1,1).Decal(),{0,0},patchSize); + if(GetCurrentTheme().HasBackground()){ + Decal*back=GetCurrentTheme().GetBackground(); + game->DrawPartialDecal(menuPos,size,back,{0,0},size); + }else{ + game->DrawPartialDecal(menuPos,size,GetPatchPart(1,1).Decal(),{0,0},patchSize); + } } Renderable&Menu::GetPatchPart(int x,int y){ return GFX[themeSelection+"_"+std::to_string(x)+std::to_string(y)+".png"]; +} + +Theme&Menu::GetCurrentTheme(){ + return themes[themeSelection]; } \ No newline at end of file diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 34126e19..160c05eb 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -19,19 +19,17 @@ class Menu:IAttributable{ safemapcomponents; //A friendly way to interrogate any component we are interested in. vi2d selection={-1,-1}; vf2d size; //Size in tiles (24x24), every menu will be tile-based - bool scaled=false; //Whether or not the patch border is supposed to be scaled or tiled. public: Menu(); Menu(vf2d size); void AddComponent(std::string key,MenuComponent*button); void Update(Crawler*game); void Draw(Crawler*game); - void SetScaledPatchBorder(bool scaled); static void InitializeMenus(); static void OpenMenu(MenuType menu); static std::vectorstack; static std::string themeSelection; - static safemapthemes; + static safeunorderedmapthemes; private: void MenuSelect(Crawler*game); static const Menu InitializeTestMenu(); @@ -39,6 +37,8 @@ private: //X (0-3), Y (0-2) for specific 9-patch tile (tiled version). static Renderable&GetPatchPart(int x,int y); + static Theme&GetCurrentTheme(); + void KeyboardButtonNavigation(Crawler*game,vf2d menuPos); void DrawScaledWindow(Crawler*game,vf2d menuPos); void DrawTiledWindow(Crawler*game,vf2d menuPos); diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 3186a8fd..fcea6d65 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -9,14 +9,14 @@ MenuComponent::MenuComponent(geom2d::rectrect,std::string label,MenuType void MenuComponent::Update(Crawler*game){ if(hovered){ - hoverEffect=std::min(1.f,hoverEffect+game->GetElapsedTime()); + hoverEffect=std::min("ThemeGlobal.HighlightTime"_F,hoverEffect+game->GetElapsedTime()); }else{ hoverEffect=std::max(0.f,hoverEffect-game->GetElapsedTime()); } } void MenuComponent::Draw(Crawler*game,vf2d parentPos){ - game->FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect)); + game->FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); if(border){ game->DrawRectDecal(rect.pos+parentPos,rect.size,GREY); } diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 24363c95..ab393d70 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -536,7 +536,7 @@ bool Player::Hurt(int damage,bool onUpperLevel,float z){ } void Player::AddAnimation(std::string state){ - animation.AddState(state,ANIMATION_DATA[state]); + animation.AddState(state,ANIMATION_DATA.at(state)); } void Player::UpdateAnimation(std::string animState,int specificClass){ diff --git a/Crawler/TestSubMenu.cpp b/Crawler/TestSubMenu.cpp index e6e6bea1..b4ef80e2 100644 --- a/Crawler/TestSubMenu.cpp +++ b/Crawler/TestSubMenu.cpp @@ -17,8 +17,15 @@ const Menu Menu::InitializeTestSubMenu(){ }; testSubMenu.AddComponent("BACK",new MenuComponent({{24*1,24*1},{24*2,24*1}},"Go Back",goBack)); - - testSubMenu.I(A::INDEXED_THEME)=0; + + int index=0; + for(auto&theme:Menu::themes){ + if(theme.first==Menu::themeSelection){ + testSubMenu.I(A::INDEXED_THEME)=index; + break; + } + index++; + } MenuFunc themePrev=[](Menu&menu,Crawler*game){ bool found=false; diff --git a/Crawler/Theme.h b/Crawler/Theme.h index 6432f459..011b8cd4 100644 --- a/Crawler/Theme.h +++ b/Crawler/Theme.h @@ -5,11 +5,13 @@ class Theme{ std::string displayName; std::string imgPath; + bool tiled=true; Pixel buttonCol,highlightCol; + Decal*background; public: inline Theme(){} - inline Theme(std::string displayName,std::string imgPath,Pixel buttonCol,Pixel highlightCol) - :displayName(displayName),imgPath(imgPath),buttonCol(buttonCol),highlightCol(highlightCol){} + inline Theme(std::string displayName,std::string imgPath,bool tiled,Pixel buttonCol,Pixel highlightCol,Decal*background=nullptr) + :displayName(displayName),imgPath(imgPath),tiled(tiled),buttonCol(buttonCol),highlightCol(highlightCol),background(background){} inline Pixel GetButtonCol(){ return buttonCol; } @@ -19,4 +21,13 @@ public: inline std::string GetThemeName(){ return displayName; } + inline bool IsScaled(){ + return !tiled; + } + inline bool HasBackground(){ + return background!=nullptr; + } + inline Decal*GetBackground(){ + return background; + } }; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index e2c778e1..4104677b 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 1676 +#define VERSION_BUILD 1704 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/gfx/gfx.txt b/Crawler/assets/config/gfx/gfx.txt index 318880a1..ab560c1a 100644 --- a/Crawler/assets/config/gfx/gfx.txt +++ b/Crawler/assets/config/gfx/gfx.txt @@ -39,9 +39,6 @@ Images GFX_SkillOverlayIcon = skill_overlay_icon.png GFX_SkillOverlayIconOverlay = skill_overlay_icon_overlay.png - GFX_9Patch = themes/9patch.png - GFX_9Patch2 = themes/9patch_2.png - # Ability Icons GFX_Warrior_BattleCry_Icon = Ability Icons/battlecry.png GFX_Warrior_Block_Icon = Ability Icons/block.png diff --git a/Crawler/assets/config/gfx/themes.txt b/Crawler/assets/config/gfx/themes.txt index 44175e14..88118607 100644 --- a/Crawler/assets/config/gfx/themes.txt +++ b/Crawler/assets/config/gfx/themes.txt @@ -1,25 +1,63 @@ +ThemeGlobal +{ + # How long it takes for the fade-in/fade-out effect to occur. + HighlightTime = 0.6 +} + Themes { # Provide the patch image names without the .png extensions. BlueDefault { - Name = "9patch" + Name = 9patch ButtonColor = 0,0,64,255 HighlightColor = 0,200,200,255 # If set to 0, stretches the edges and center instead of tiling it. Tiled = 1 + + # Specifying a custom background from the assets directory uses that instead. + #CustomBack = image.png } Purple { - Name = "9patch_2" + Name = 9patch_2 ButtonColor = 40,16,71,255 HighlightColor = 192,128,238,255 # If set to 0, stretches the edges and center instead of tiling it. Tiled = 1 + + # Specifying a custom background from the assets directory uses that instead. + #CustomBack = themes/testback.png + } + NicoPink + { + Name = 9patch_3 + + ButtonColor = 208,73,182,255 + HighlightColor = 255,239,232,255 + + # If set to 0, stretches the edges and center instead of tiling it. + Tiled = 0 + + # Specifying a custom background from the assets directory uses that instead. + CustomBack = themes/testback.png + } + NicoPinkTiled + { + Name = 9patch_4 + + ButtonColor = 208,73,182,255 + HighlightColor = 255,239,232,255 + + # If set to 0, stretches the edges and center instead of tiling it. + Tiled = 1 + + # Specifying a custom background from the assets directory uses that instead. + CustomBack = themes/testtiledback.png } } \ No newline at end of file diff --git a/Crawler/assets/themes/9patch_3.png b/Crawler/assets/themes/9patch_3.png new file mode 100644 index 00000000..d24c475c Binary files /dev/null and b/Crawler/assets/themes/9patch_3.png differ diff --git a/Crawler/assets/themes/9patch_4.png b/Crawler/assets/themes/9patch_4.png new file mode 100644 index 00000000..d24c475c Binary files /dev/null and b/Crawler/assets/themes/9patch_4.png differ diff --git a/Crawler/assets/themes/testback.png b/Crawler/assets/themes/testback.png new file mode 100644 index 00000000..d72dcd52 Binary files /dev/null and b/Crawler/assets/themes/testback.png differ diff --git a/Crawler/assets/themes/testtiledback.png b/Crawler/assets/themes/testtiledback.png new file mode 100644 index 00000000..8a25dc90 Binary files /dev/null and b/Crawler/assets/themes/testtiledback.png differ diff --git a/Crawler/olcUTIL_DataFile.h b/Crawler/olcUTIL_DataFile.h index 506ccb3b..01f527e2 100644 --- a/Crawler/olcUTIL_DataFile.h +++ b/Crawler/olcUTIL_DataFile.h @@ -71,6 +71,7 @@ namespace olc::utils public: inline datafile() = default; inline static bool DEBUG_ACCESS_OPTIONS=false; + inline static bool INITIAL_SETUP_COMPLETE=false; public: // Sets the String Value of a Property (for a given index) @@ -444,6 +445,10 @@ namespace olc::utils // Check if this "node"'s map already contains an object with this name... if (m_mapObjects.count(name) == 0) { + if(INITIAL_SETUP_COMPLETE){ + std::cout<<"WARNING! Key "< +class safeunorderedmap{ + std::unordered_mapmap; + bool initialized=false; +public: + O&operator[](T key){ + if(initialized&&map.count(key)==0){ + std::cout<<"WARNING! Trying to get non-existent key "<