Added properties for border and background control, vertically align uncentered labels by default.

pull/28/head
sigonasr2 1 year ago
parent e189d4b516
commit 3f78565655
  1. 8
      Crawler/CharacterInfoWindow.cpp
  2. 8
      Crawler/MenuComponent.cpp
  3. 2
      Crawler/MenuComponent.h
  4. 9
      Crawler/MenuLabel.h
  5. 2
      Crawler/Version.h

@ -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);

@ -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){

@ -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;

@ -11,9 +11,11 @@ class MenuLabel:public MenuComponent{
bool centered=true;
int scale=1;
public:
inline MenuLabel(MenuType parent,geom2d::rect<float>rect,std::string label,int scale=1,bool centered=true,bool shadow=false)
inline MenuLabel(MenuType parent,geom2d::rect<float>rect,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)});

@ -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

Loading…
Cancel
Save