Converted boolean flags for component creation in windows to using enum bitwise attributes.
This commit is contained in:
parent
c82a3c5980
commit
2e248e30b4
@ -14,7 +14,7 @@ class CharacterAbilityPreviewComponent:public MenuLabel{
|
||||
Ability*ability;
|
||||
public:
|
||||
inline CharacterAbilityPreviewComponent(MenuType parent,geom2d::rect<float>rect,Ability*ability)
|
||||
:MenuLabel(parent,rect,"",1,true,false,true,true),ability(ability){}
|
||||
:MenuLabel(parent,rect,"",1,ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND),ability(ability){}
|
||||
protected:
|
||||
virtual void inline Update(Crawler*game)override{
|
||||
MenuLabel::Update(game);
|
||||
|
@ -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,0},{classInfoWindow->size.x-1,24}},data.className,2,true,true,true,true);
|
||||
MenuLabel*label=new MenuLabel(CLASS_INFO,{{0,0},{classInfoWindow->size.x-1,24}},data.className,2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND);
|
||||
|
||||
classInfoWindow->AddComponent("Class Name",label);
|
||||
|
||||
@ -28,10 +28,10 @@ void Menu::InitializeClassInfoWindow(){
|
||||
vf2d healthDisplayLabelPos={classInfoWindow->size.x/3,label->GetPos().y+24};
|
||||
vf2d labelSize={2*classInfoWindow->size.x/3-1,16};
|
||||
|
||||
MenuLabel*baseStatsLabel=new MenuLabel(CLASS_INFO,{{0,label->GetPos().y+24},{classInfoWindow->size.x/3,labelSize.y}},"Base Stats",1,true,true,true);
|
||||
MenuLabel*baseStatsLabel=new MenuLabel(CLASS_INFO,{{0,label->GetPos().y+24},{classInfoWindow->size.x/3,labelSize.y}},"Base Stats",1,ComponentAttr::SHADOW|ComponentAttr::OUTLINE);
|
||||
|
||||
MenuLabel*healthDisplayLabel=new MenuLabel(CLASS_INFO,{healthDisplayLabelPos+vf2d{0,16*0},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,{healthDisplayLabelPos+vf2d{0,16*1},labelSize},"Attack: "+std::to_string(data.baseAtk)+" + "+std::to_string(data.atkGrowthRate).substr(0,3)+" per level",1,false,true,true);
|
||||
MenuLabel*healthDisplayLabel=new MenuLabel(CLASS_INFO,{healthDisplayLabelPos+vf2d{0,16*0},labelSize},"Health: "+std::to_string(data.baseHealth)+" + "+std::to_string(data.healthGrowthRate).substr(0,3)+" per level",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE);
|
||||
MenuLabel*atkDisplayLabel=new MenuLabel(CLASS_INFO,{healthDisplayLabelPos+vf2d{0,16*1},labelSize},"Attack: "+std::to_string(data.baseAtk)+" + "+std::to_string(data.atkGrowthRate).substr(0,3)+" per level",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE);
|
||||
|
||||
classInfoWindow->AddComponent("Base Stats Text",baseStatsLabel);
|
||||
classInfoWindow->AddComponent("Health Display Text",healthDisplayLabel);
|
||||
|
@ -17,10 +17,10 @@ void Menu::InitializeClassSelectionWindow(){
|
||||
|
||||
vf2d outlineSize=classSelectionWindow->size-vf2d{13,13};
|
||||
|
||||
MenuLabel*classSelectionLabel=new MenuLabel(CLASS_SELECTION,{{4,20},{outlineSize.x,32}},"Choose a Character Class",2,true,true,true,true);
|
||||
MenuLabel*classSelectionLabel=new MenuLabel(CLASS_SELECTION,{{4,20},{outlineSize.x,32}},"Choose a Character Class",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND);
|
||||
classSelectionWindow->AddComponent("Class Selection Title Label",classSelectionLabel);
|
||||
|
||||
MenuLabel*outline=new MenuLabel(CLASS_SELECTION,{{4,4},outlineSize},"",1,true,false,true,false);
|
||||
MenuLabel*outline=new MenuLabel(CLASS_SELECTION,{{4,4},outlineSize},"",1,ComponentAttr::OUTLINE);
|
||||
|
||||
classSelectionWindow->AddComponent("Outline Border",outline);
|
||||
|
||||
@ -74,8 +74,8 @@ void Menu::InitializeClassSelectionWindow(){
|
||||
buttonStartPos.y+(buttonSize.y+buttonPadding.y+2*outlineSize.y/9)*float(i/3),
|
||||
};
|
||||
vf2d backgroundSize={floor(outlineSize.y/3-buttonPadding.y*3),outlineSize.y/3-buttonPadding.y*3}; //The floor is for fixing a small pixel rounding bug.
|
||||
MenuLabel*backgroundOutline=new MenuLabel(CLASS_SELECTION,{backgroundOffsetPos,backgroundSize},"",1,true,false,true,true);
|
||||
MenuLabel*classLabel=new MenuLabel(CLASS_SELECTION,{backgroundOffsetPos,buttonSize},className,1,true,true);
|
||||
MenuLabel*backgroundOutline=new MenuLabel(CLASS_SELECTION,{backgroundOffsetPos,backgroundSize},"",1,ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND);
|
||||
MenuLabel*classLabel=new MenuLabel(CLASS_SELECTION,{backgroundOffsetPos,buttonSize},className,1,ComponentAttr::SHADOW);
|
||||
MenuAnimatedIconToggleButton*classSprite=new MenuAnimatedIconToggleButton(CLASS_SELECTION,{backgroundOffsetPos+vf2d{0,12},backgroundSize+vf2d{0,-buttonSize.y-12}},classAnimationName,[](MenuFuncData data){
|
||||
data.menu.components["Confirm"]->Enable(true);
|
||||
data.menu.components["Confirm"]->S(A::CLASS_SELECTION)=data.component->S(A::CLASS_SELECTION);
|
||||
|
@ -30,8 +30,8 @@ void Menu::InitializeInventoryWindow(){
|
||||
|
||||
//We don't have to actually populate the inventory list because now when an item gets added, it will automatically add the correct component in for us.
|
||||
|
||||
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing-16)},{windowSize.x-4,windowSize.y-108}),"",1,false,true};
|
||||
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing-16)},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW};
|
||||
inventoryWindow->AddComponent("itemName",itemNameLabel);
|
||||
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing)},{windowSize.x-4,windowSize.y-108}),"",1,true,true};
|
||||
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing)},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW};
|
||||
inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel);
|
||||
}
|
@ -11,8 +11,8 @@ protected:
|
||||
private:
|
||||
float animationTime=0;
|
||||
public:
|
||||
inline MenuAnimatedIconButton(MenuType parent,geom2d::rect<float>rect,std::string animation,MenuFunc onClick,bool selectable=true)
|
||||
:MenuIconButton(parent,rect,nullptr,onClick,selectable),animation(animation){}
|
||||
inline MenuAnimatedIconButton(MenuType parent,geom2d::rect<float>rect,std::string animation,MenuFunc onClick,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
|
||||
:MenuIconButton(parent,rect,nullptr,onClick,attributes),animation(animation){}
|
||||
protected:
|
||||
virtual inline void Update(Crawler*game)override{
|
||||
MenuIconButton::Update(game);
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
typedef Attribute A;
|
||||
|
||||
MenuComponent::MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuFunc onClick,bool selectable,bool selectableViaKeyboard)
|
||||
:parentMenu(parent),rect(rect),label(label),menuDest(MenuType::ENUM_END),onClick(onClick),hoverEffect(0),selectable(selectable),selectableViaKeyboard(selectableViaKeyboard),memoryLeakInfo(Menu::GetMemoryLeakReportInfo()){
|
||||
MenuComponent::MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuFunc onClick,ButtonAttr attributes)
|
||||
:parentMenu(parent),rect(rect),label(label),menuDest(MenuType::ENUM_END),onClick(onClick),hoverEffect(0),selectable(!(attributes&ButtonAttr::UNSELECTABLE)),selectableViaKeyboard(!(attributes&ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)),memoryLeakInfo(Menu::GetMemoryLeakReportInfo()){
|
||||
Menu::unhandledComponents.push_back(this);
|
||||
}
|
||||
|
||||
MenuComponent::MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable,bool selectableViaKeyboard)
|
||||
:MenuComponent(parent,rect,label,onClick,selectable,selectableViaKeyboard){
|
||||
MenuComponent::MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes)
|
||||
:MenuComponent(parent,rect,label,onClick,attributes){
|
||||
//NOTE: This constructor also calls the other constructor above!
|
||||
this->menuDest=menuDest;
|
||||
}
|
||||
|
@ -1,6 +1,20 @@
|
||||
#pragma once
|
||||
#include "Menu.h"
|
||||
|
||||
enum class ButtonAttr{
|
||||
NONE=0b00,
|
||||
UNSELECTABLE=0b01, //Makes the component unselectable.
|
||||
UNSELECTABLE_VIA_KEYBOARD=0b10, //Makes the component unselectable via keyboard.
|
||||
};
|
||||
|
||||
enum class ComponentAttr{
|
||||
NONE=0b0000,
|
||||
LEFT_ALIGN=0b0001, //Labels are centered by default.
|
||||
SHADOW=0b0010, //Adds shadows to the label text.
|
||||
OUTLINE=0b0100, //Adds an outline around the component.
|
||||
BACKGROUND=0b1000, //Renders the background of the menu theme for this component.
|
||||
};
|
||||
|
||||
class MenuComponent:IAttributable{
|
||||
friend class Menu;
|
||||
friend class MenuItemButton;
|
||||
@ -36,8 +50,8 @@ protected:
|
||||
virtual bool GetHoverState(Crawler*game,MenuComponent*child);
|
||||
virtual void AfterCreate(); //Called after the creation of all menus finish.
|
||||
public:
|
||||
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true);
|
||||
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true);
|
||||
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
|
||||
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
|
||||
virtual ~MenuComponent();
|
||||
void _Update(Crawler*game);
|
||||
void _Draw(Crawler*game);
|
||||
@ -56,4 +70,24 @@ public:
|
||||
virtual void OnInventorySlotsUpdate(ITCategory cat);
|
||||
std::string GetLabel();
|
||||
void Enable(bool enabled);
|
||||
};
|
||||
};
|
||||
|
||||
constexpr auto operator|(ButtonAttr attribute,ButtonAttr attribute2) noexcept
|
||||
{
|
||||
return ButtonAttr(static_cast<std::underlying_type_t<ButtonAttr>>(attribute)|static_cast<std::underlying_type_t<ButtonAttr>>(attribute2));
|
||||
}
|
||||
|
||||
constexpr auto operator&(ButtonAttr attribute,ButtonAttr attribute2) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<ButtonAttr>>(attribute)&static_cast<std::underlying_type_t<ButtonAttr>>(attribute2);
|
||||
}
|
||||
|
||||
|
||||
constexpr auto operator|(ComponentAttr attribute,ComponentAttr attribute2) noexcept
|
||||
{
|
||||
return ComponentAttr(static_cast<std::underlying_type_t<ComponentAttr>>(attribute)|static_cast<std::underlying_type_t<ComponentAttr>>(attribute2));
|
||||
}
|
||||
constexpr auto operator&(ComponentAttr attribute,ComponentAttr attribute2) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<ComponentAttr>>(attribute)&static_cast<std::underlying_type_t<ComponentAttr>>(attribute2);
|
||||
}
|
@ -5,12 +5,17 @@
|
||||
|
||||
INCLUDE_game
|
||||
|
||||
enum class IconButtonAttr{
|
||||
SELECTABLE=0b0,
|
||||
NOT_SELECTABLE=int(ButtonAttr::UNSELECTABLE),
|
||||
};
|
||||
|
||||
class MenuIconButton:public MenuComponent{
|
||||
protected:
|
||||
Decal*icon;
|
||||
public:
|
||||
inline MenuIconButton(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick,bool selectable=true)
|
||||
:MenuComponent(parent,rect,"",onClick,selectable),icon(icon){}
|
||||
inline MenuIconButton(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
|
||||
:MenuComponent(parent,rect,"",onClick,ButtonAttr(attributes)),icon(icon){}
|
||||
protected:
|
||||
virtual inline void Update(Crawler*game)override{
|
||||
MenuComponent::Update(game);
|
||||
@ -21,4 +26,13 @@ protected:
|
||||
game->DrawSprite(parentPos+rect.middle()-icon->sprite->Size()/2,icon->sprite,1,Sprite::Flip::NONE);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
constexpr auto operator|(IconButtonAttr attribute,IconButtonAttr attribute2) noexcept
|
||||
{
|
||||
return IconButtonAttr(static_cast<std::underlying_type_t<IconButtonAttr>>(attribute)|static_cast<std::underlying_type_t<IconButtonAttr>>(attribute2));
|
||||
}
|
||||
constexpr auto operator&(IconButtonAttr attribute,IconButtonAttr attribute2) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<IconButtonAttr>>(attribute)&static_cast<std::underlying_type_t<IconButtonAttr>>(attribute2);
|
||||
}
|
@ -11,10 +11,10 @@ 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,bool outline=false,bool background=false)
|
||||
:MenuComponent(parent,rect,label,MenuFunc{},false),scale(scale),centered(centered),shadow(shadow){
|
||||
border=outline;
|
||||
this->background=background;
|
||||
inline MenuLabel(MenuType parent,geom2d::rect<float>rect,std::string label,int scale=1,ComponentAttr attributes=ComponentAttr::NONE)
|
||||
:MenuComponent(parent,rect,label,MenuFunc{},ButtonAttr::UNSELECTABLE|ButtonAttr::UNSELECTABLE_VIA_KEYBOARD),scale(scale),centered(!(attributes&ComponentAttr::LEFT_ALIGN)),shadow(attributes&ComponentAttr::SHADOW){
|
||||
border=attributes&ComponentAttr::OUTLINE;
|
||||
this->background=attributes&ComponentAttr::BACKGROUND;
|
||||
showDefaultLabel=false;
|
||||
}
|
||||
inline void SetLabel(std::string text){
|
||||
|
@ -23,7 +23,7 @@ protected:
|
||||
}
|
||||
public:
|
||||
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
|
||||
:MenuComponent(parent,rect,"",onClick,false){
|
||||
:MenuComponent(parent,rect,"",onClick,ButtonAttr::UNSELECTABLE|ButtonAttr::UNSELECTABLE_VIA_KEYBOARD){
|
||||
r.Create(rect.size.x,rect.size.y);
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ public:
|
||||
}
|
||||
protected:
|
||||
virtual inline void AfterCreate()override{
|
||||
upButton=new MenuComponent(parentMenu,{vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuButtonScrollSpeed"_I;},true,false);
|
||||
downButton=new MenuComponent(parentMenu,{rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuButtonScrollSpeed"_I;},true,false);
|
||||
upButton=new MenuComponent(parentMenu,{vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuButtonScrollSpeed"_I;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD);
|
||||
downButton=new MenuComponent(parentMenu,{rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuButtonScrollSpeed"_I;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD);
|
||||
//Let's use the internal name of this component to add unique names for sub-components.
|
||||
Menu::menus[parentMenu]->AddComponent(name+upButton->rect.pos.str()+"_"+upButton->rect.size.str(),upButton);
|
||||
Menu::menus[parentMenu]->AddComponent(name+downButton->rect.pos.str()+"_"+downButton->rect.size.str(),downButton);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 1
|
||||
#define VERSION_BUILD 2541
|
||||
#define VERSION_BUILD 2548
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user