From 3f785656555ccc2fa1dde0f30c4dfe2ca6a3b08b Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 22 Oct 2023 10:35:53 -0500 Subject: [PATCH] Added properties for border and background control, vertically align uncentered labels by default. --- Crawler/CharacterInfoWindow.cpp | 8 ++++---- Crawler/MenuComponent.cpp | 8 ++++++-- Crawler/MenuComponent.h | 2 ++ Crawler/MenuLabel.h | 9 ++++++--- Crawler/Version.h | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Crawler/CharacterInfoWindow.cpp b/Crawler/CharacterInfoWindow.cpp index 26e6b28f..afa4b2af 100644 --- a/Crawler/CharacterInfoWindow.cpp +++ b/Crawler/CharacterInfoWindow.cpp @@ -17,7 +17,7 @@ void Menu::InitializeClassInfoWindow(){ Menu*classSelectionWindow=Menu::menus[CLASS_SELECTION]; ClassInfo data=classutils::GetClassInfo(classSelectionWindow->S(A::CLASS_SELECTION)); - MenuLabel*label=new MenuLabel(CLASS_INFO,{{0,8},{classInfoWindow->size.x,16}},data.className,2,true,true); + MenuLabel*label=new MenuLabel(CLASS_INFO,{{0,8},{classInfoWindow->size.x-1,28}},data.className,2,true,true,true,true); classInfoWindow->AddComponent("Class Name",label); @@ -28,9 +28,9 @@ void Menu::InitializeClassInfoWindow(){ vf2d baseStatsLabelPos={classInfoWindow->size.x/3,classInfoWindow->pos.y+20}; vf2d labelSize={2*classInfoWindow->size.x/3,16}; - MenuLabel*baseStatsLabel=new MenuLabel(CLASS_INFO,{baseStatsLabelPos,labelSize},"Base Stats",1,true,true); - MenuLabel*healthDisplayLabel=new MenuLabel(CLASS_INFO,{baseStatsLabelPos+vf2d{0,16*1+8},labelSize},"Health: "+std::to_string(data.baseHealth)+" + "+std::to_string(data.healthGrowthRate).substr(0,3)+" per level",1,false,true); - MenuLabel*atkDisplayLabel=new MenuLabel(CLASS_INFO,{baseStatsLabelPos+vf2d{0,16*2+8},labelSize},"Attack: "+std::to_string(data.baseAtk)+" + "+std::to_string(data.atkGrowthRate).substr(0,3)+" per level",1,false,true); + MenuLabel*baseStatsLabel=new MenuLabel(CLASS_INFO,{baseStatsLabelPos,labelSize},"Base Stats",1,true,true,true); + MenuLabel*healthDisplayLabel=new MenuLabel(CLASS_INFO,{baseStatsLabelPos+vf2d{0,16*1+8},labelSize},"Health: "+std::to_string(data.baseHealth)+" + "+std::to_string(data.healthGrowthRate).substr(0,3)+" per level",1,false,true,true); + MenuLabel*atkDisplayLabel=new MenuLabel(CLASS_INFO,{baseStatsLabelPos+vf2d{0,16*2+8},labelSize},"Attack: "+std::to_string(data.baseAtk)+" + "+std::to_string(data.atkGrowthRate).substr(0,3)+" per level",1,false,true,true); classInfoWindow->AddComponent("Base Stats Text",baseStatsLabel); classInfoWindow->AddComponent("Health Display Text",healthDisplayLabel); diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 49877e15..c458e4f8 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -28,11 +28,15 @@ void MenuComponent::_Update(Crawler*game){ } void MenuComponent::Draw(Crawler*game,vf2d parentPos,bool focused){ - game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)*(focused?1:"ThemeGlobal.MenuUnfocusedColorMult"_F)); + if(background){ + game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)*(focused?1:"ThemeGlobal.MenuUnfocusedColorMult"_F)); + } if(border){ game->DrawRect(rect.pos+parentPos,rect.size,focused?GREY:GREY*"ThemeGlobal.MenuUnfocusedColorMult"_F); } - game->DrawStringProp(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); + if(showDefaultLabel){ + game->DrawStringProp(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); + } } void MenuComponent::_Draw(Crawler*game,vf2d parentPos,bool focused){ diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 6e668d52..c594f6da 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -18,6 +18,8 @@ protected: std::string label; bool border=true; bool draggable=false; + bool background=true; + bool showDefaultLabel=true; MenuFunc onClick; MenuType parentMenu=MenuType::ENUM_END; MenuComponent*parentComponent=nullptr; diff --git a/Crawler/MenuLabel.h b/Crawler/MenuLabel.h index 1f22f101..61f09b0e 100644 --- a/Crawler/MenuLabel.h +++ b/Crawler/MenuLabel.h @@ -11,9 +11,11 @@ class MenuLabel:public MenuComponent{ bool centered=true; int scale=1; public: - inline MenuLabel(MenuType parent,geom2d::rectrect,std::string label,int scale=1,bool centered=true,bool shadow=false) + inline MenuLabel(MenuType parent,geom2d::rectrect,std::string label,int scale=1,bool centered=true,bool shadow=false,bool outline=false,bool background=false) :MenuComponent(parent,rect,label,MenuFunc{},false),scale(scale),centered(centered),shadow(shadow){ - border=false; + border=outline; + this->background=background; + showDefaultLabel=false; } inline void SetLabel(std::string text){ label=text; @@ -23,10 +25,11 @@ protected: MenuComponent::Update(game); } virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ + MenuComponent::Draw(game,parentPos,focused); std::string wrappedText=util::WrapText(game,label,rect.size.x,true,{float(scale),float(scale)}); vf2d drawPos=parentPos+rect.middle()-vf2d{game->GetTextSizeProp(wrappedText)}*float(scale)/2; //Assume centered. if(!centered){ - drawPos=rect.pos+parentPos; + drawPos=vf2d{rect.pos.x+2,rect.middle().y-game->GetTextSizeProp(wrappedText).y/2}+parentPos; //We should at least vertically align here. } if(shadow){ game->DrawShadowStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F,BLACK,{float(scale),float(scale)}); diff --git a/Crawler/Version.h b/Crawler/Version.h index 54bcfbc9..6afe01c7 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 2248 +#define VERSION_BUILD 2258 #define stringify(a) stringify_(a) #define stringify_(a) #a