diff --git a/Crawler/CharacterAbilityPreviewComponent.h b/Crawler/CharacterAbilityPreviewComponent.h index 5e93662c..dcc5bf64 100644 --- a/Crawler/CharacterAbilityPreviewComponent.h +++ b/Crawler/CharacterAbilityPreviewComponent.h @@ -14,7 +14,7 @@ class CharacterAbilityPreviewComponent:public MenuLabel{ Ability*ability; public: inline CharacterAbilityPreviewComponent(MenuType parent,geom2d::rectrect,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); diff --git a/Crawler/CharacterInfoWindow.cpp b/Crawler/CharacterInfoWindow.cpp index 49b4fde5..e773b7db 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,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); diff --git a/Crawler/ClassSelectionWindow.cpp b/Crawler/ClassSelectionWindow.cpp index cade5415..baaa85ca 100644 --- a/Crawler/ClassSelectionWindow.cpp +++ b/Crawler/ClassSelectionWindow.cpp @@ -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); diff --git a/Crawler/InventoryWindow.cpp b/Crawler/InventoryWindow.cpp index c2d840ba..7b4ae140 100644 --- a/Crawler/InventoryWindow.cpp +++ b/Crawler/InventoryWindow.cpp @@ -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(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing-16)},{windowSize.x-4,windowSize.y-108}),"",1,false,true}; + MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect(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(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing)},{windowSize.x-4,windowSize.y-108}),"",1,true,true}; + MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing)},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW}; inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel); } \ No newline at end of file diff --git a/Crawler/MenuAnimatedIconButton.h b/Crawler/MenuAnimatedIconButton.h index f108511f..2fd35dcf 100644 --- a/Crawler/MenuAnimatedIconButton.h +++ b/Crawler/MenuAnimatedIconButton.h @@ -11,8 +11,8 @@ protected: private: float animationTime=0; public: - inline MenuAnimatedIconButton(MenuType parent,geom2d::rectrect,std::string animation,MenuFunc onClick,bool selectable=true) - :MenuIconButton(parent,rect,nullptr,onClick,selectable),animation(animation){} + inline MenuAnimatedIconButton(MenuType parent,geom2d::rectrect,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); diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 3953c9b4..1dd0a2bd 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -3,13 +3,13 @@ typedef Attribute A; -MenuComponent::MenuComponent(MenuType parent,geom2d::rectrect,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::rectrect,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::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable,bool selectableViaKeyboard) - :MenuComponent(parent,rect,label,onClick,selectable,selectableViaKeyboard){ +MenuComponent::MenuComponent(MenuType parent,geom2d::rectrect,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; } diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index ba2d58c1..51b22eef 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -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::rectrect,std::string label,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true); - MenuComponent(MenuType parent,geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true); + MenuComponent(MenuType parent,geom2d::rectrect,std::string label,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE); + MenuComponent(MenuType parent,geom2d::rectrect,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); -}; \ No newline at end of file +}; + +constexpr auto operator|(ButtonAttr attribute,ButtonAttr attribute2) noexcept +{ + return ButtonAttr(static_cast>(attribute)|static_cast>(attribute2)); +} + +constexpr auto operator&(ButtonAttr attribute,ButtonAttr attribute2) noexcept +{ + return static_cast>(attribute)&static_cast>(attribute2); +} + + +constexpr auto operator|(ComponentAttr attribute,ComponentAttr attribute2) noexcept +{ + return ComponentAttr(static_cast>(attribute)|static_cast>(attribute2)); +} +constexpr auto operator&(ComponentAttr attribute,ComponentAttr attribute2) noexcept +{ + return static_cast>(attribute)&static_cast>(attribute2); +} \ No newline at end of file diff --git a/Crawler/MenuIconButton.h b/Crawler/MenuIconButton.h index b5a4493f..f64bd37c 100644 --- a/Crawler/MenuIconButton.h +++ b/Crawler/MenuIconButton.h @@ -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::rectrect,Decal*icon,MenuFunc onClick,bool selectable=true) - :MenuComponent(parent,rect,"",onClick,selectable),icon(icon){} + inline MenuIconButton(MenuType parent,geom2d::rectrect,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); } } -}; \ No newline at end of file +}; + +constexpr auto operator|(IconButtonAttr attribute,IconButtonAttr attribute2) noexcept +{ + return IconButtonAttr(static_cast>(attribute)|static_cast>(attribute2)); +} +constexpr auto operator&(IconButtonAttr attribute,IconButtonAttr attribute2) noexcept +{ + return static_cast>(attribute)&static_cast>(attribute2); +} \ No newline at end of file diff --git a/Crawler/MenuLabel.h b/Crawler/MenuLabel.h index cbdcf334..bb2cfd0c 100644 --- a/Crawler/MenuLabel.h +++ b/Crawler/MenuLabel.h @@ -11,10 +11,10 @@ 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,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::rectrect,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){ diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index 68030260..37964d50 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -23,7 +23,7 @@ protected: } public: inline ScrollableWindowComponent(MenuType parent,geom2d::rectrect,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); diff --git a/Crawler/Version.h b/Crawler/Version.h index 68abf291..59538151 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -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