Hover functionality moved out to MenuComponent so any component can utilize them.

pull/28/head
sigonasr2 1 year ago
parent 025a89788e
commit ac0f5c42aa
  1. 4
      Crawler/CharacterMenuWindow.cpp
  2. 4
      Crawler/Crawler.vcxproj
  3. 3
      Crawler/Crawler.vcxproj.filters
  4. 4
      Crawler/Menu.cpp
  5. 39
      Crawler/MenuComponent.cpp
  6. 12
      Crawler/MenuComponent.h
  7. 39
      Crawler/MenuItemButton.h
  8. 41
      Crawler/MenuItemItemButton.h
  9. 98
      Crawler/RowItemDisplay.h
  10. 3
      Crawler/ScrollableWindowComponent.h
  11. 2
      Crawler/Version.h

@ -57,7 +57,7 @@ void Menu::InitializeCharacterMenuWindow(){
Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,windowSize); Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,windowSize);
characterMenuWindow->ADD("Character Label",MenuLabel)({{0,-4},{float(windowSize.x)-1,24}},"Character",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END; characterMenuWindow->ADD("Character Label",MenuLabel)({{0,-4},{float(windowSize.x)-1,24}},"Character",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
characterMenuWindow->ADD("Equip Slot Outline",MenuComponent)({{0,28},{120,windowSize.y-48}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END; characterMenuWindow->ADD("Equip Slot Outline",MenuComponent)({{0,28},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END;
characterMenuWindow->ADD("Character Rotating Display",CharacterRotatingDisplay)({{135,28},{90,windowSize.y-48}},GFX[classutils::GetClassInfo(game->GetPlayer()->GetClassName()).classFullImgName].Decal())END; characterMenuWindow->ADD("Character Rotating Display",CharacterRotatingDisplay)({{135,28},{90,windowSize.y-48}},GFX[classutils::GetClassInfo(game->GetPlayer()->GetClassName()).classFullImgName].Decal())END;
const static std::array<ItemAttribute,7>displayAttrs{ const static std::array<ItemAttribute,7>displayAttrs{
@ -90,7 +90,7 @@ void Menu::InitializeCharacterMenuWindow(){
} }
equipmentWindowOpened=false; equipmentWindowOpened=false;
return true; return true;
})END; })DEPTH 0 END;
equipSelectionSelectButton->Enable(false); equipSelectionSelectButton->Enable(false);

@ -366,6 +366,10 @@
</ClInclude> </ClInclude>
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="resource1.h" /> <ClInclude Include="resource1.h" />
<ClInclude Include="RowItemDisplay.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="safemap.h" /> <ClInclude Include="safemap.h" />
<ClInclude Include="ScrollableWindowComponent.h" /> <ClInclude Include="ScrollableWindowComponent.h" />
<ClInclude Include="InventoryScrollableWindowComponent.h" /> <ClInclude Include="InventoryScrollableWindowComponent.h" />

@ -300,6 +300,9 @@
<ClInclude Include="olcPGEX_ViewPort.h"> <ClInclude Include="olcPGEX_ViewPort.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="RowItemDisplay.h">
<Filter>Header Files\Interface</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Player.cpp"> <ClCompile Include="Player.cpp">

@ -255,13 +255,13 @@ void Menu::Update(Crawler*game){
for(auto&[key,value]:buttons){ for(auto&[key,value]:buttons){
for(auto&button:value){ for(auto&button:value){
if(button->renderInMain){ if(button->renderInMain){
button->BeforeUpdate(game); button->_BeforeUpdate(game);
} }
} }
} }
for(auto&component:displayComponents){ for(auto&component:displayComponents){
if(component->renderInMain){ if(component->renderInMain){
component->BeforeUpdate(game); component->_BeforeUpdate(game);
} }
} }
for(auto&[key,value]:buttons){ for(auto&[key,value]:buttons){

@ -77,6 +77,10 @@ MenuComponent::~MenuComponent(){
void MenuComponent::AfterCreate(){} void MenuComponent::AfterCreate(){}
void MenuComponent::_BeforeUpdate(Crawler*game){
_OnMouseOut();
BeforeUpdate(game);
}
void MenuComponent::BeforeUpdate(Crawler*game){} void MenuComponent::BeforeUpdate(Crawler*game){}
void MenuComponent::Update(Crawler*game){ void MenuComponent::Update(Crawler*game){
@ -89,6 +93,7 @@ void MenuComponent::Update(Crawler*game){
void MenuComponent::_Update(Crawler*game){ void MenuComponent::_Update(Crawler*game){
if(!disabled){ if(!disabled){
_OnHover();
Update(game); Update(game);
} }
} }
@ -195,3 +200,37 @@ void MenuComponent::SetSelected(bool selected){
void MenuComponent::SetSelectionType(SelectionType selectionType){ void MenuComponent::SetSelectionType(SelectionType selectionType){
this->selectionType=selectionType; this->selectionType=selectionType;
} }
void MenuComponent::OnMouseOut(){};
void MenuComponent::OnHover(){};
void MenuComponent::_OnMouseOut(){
if(name=="Equip Item 2"){std::cout<<std::boolalpha<<hoverState<<","<<hovered<<","<<runHoverFunctions<<std::endl;}
if(!hovered){
if(runHoverFunctions){
if(hoverState){
hoverState=false;
onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
OnMouseOut();
}
}
}
}
void MenuComponent::_OnHover(){
if(hovered){
if(runHoverFunctions&&!hoverState){
hoverState=true;
onHover(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
OnHover();
}
}
}
void MenuComponent::SetHoverFunc(std::function<bool(MenuFuncData)>func){
runHoverFunctions=true;
onHover=func;
};
void MenuComponent::SetMouseOutFunc(std::function<bool(MenuFuncData)>func){
runHoverFunctions=true;
onMouseOut=func;
};

@ -67,13 +67,21 @@ class MenuComponent:public IAttributable{
friend class ScrollableWindowComponent; friend class ScrollableWindowComponent;
friend class InventoryScrollableWindowComponent; friend class InventoryScrollableWindowComponent;
friend class MenuItemItemButton; friend class MenuItemItemButton;
friend class RowItemDisplay;
MenuType menuDest; MenuType menuDest;
MenuFunc onHover=[](MenuFuncData dat){return true;};
MenuFunc onMouseOut=[](MenuFuncData dat){return true;};
bool hoverState=false;
bool runHoverFunctions=false;
private: private:
virtual bool GetHoverState(Crawler*game); virtual bool GetHoverState(Crawler*game);
std::pair<MenuType,std::string>memoryLeakInfo; //Used to identify memory leak hints for this component. std::pair<MenuType,std::string>memoryLeakInfo; //Used to identify memory leak hints for this component.
void _BeforeUpdate(Crawler*game);
virtual void BeforeUpdate(Crawler*game); virtual void BeforeUpdate(Crawler*game);
void _Update(Crawler*game); void _Update(Crawler*game);
void _DrawDecal(ViewPort&window,bool focused); void _DrawDecal(ViewPort&window,bool focused);
void _OnMouseOut();
void _OnHover();
bool selected=false; bool selected=false;
SelectionType selectionType=CROSSHAIR; SelectionType selectionType=CROSSHAIR;
protected: protected:
@ -103,6 +111,8 @@ protected:
virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos); virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos);
//CALL THIS FOR A PARENT to check a child's DrawDecal validity! //CALL THIS FOR A PARENT to check a child's DrawDecal validity!
virtual bool PointWithinParent(MenuComponent*child,geom2d::rect<float> drawRect); virtual bool PointWithinParent(MenuComponent*child,geom2d::rect<float> drawRect);
virtual void OnMouseOut();
virtual void OnHover();
public: public:
MenuType parentMenu=MenuType::ENUM_END; MenuType parentMenu=MenuType::ENUM_END;
MenuComponent*parentComponent=nullptr; MenuComponent*parentComponent=nullptr;
@ -128,4 +138,6 @@ public:
virtual void SetSelectionType(SelectionType selectionType)final; virtual void SetSelectionType(SelectionType selectionType)final;
virtual void Enable(bool enabled); virtual void Enable(bool enabled);
virtual void Cleanup(); virtual void Cleanup();
virtual void SetHoverFunc(std::function<bool(MenuFuncData)>func);
virtual void SetMouseOutFunc(std::function<bool(MenuFuncData)>func);
}; };

@ -57,10 +57,6 @@ private:
std::string itemNameLabelName; std::string itemNameLabelName;
std::string itemDescriptionLabelName; std::string itemDescriptionLabelName;
CompactText compact=COMPACT; CompactText compact=COMPACT;
bool hoverState=false;
bool runHoverFunctions=false;
MenuFunc onHover;
MenuFunc onMouseOut;
public: public:
int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected. int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected.
inline MenuItemButton(geom2d::rect<float>rect,std::vector<Item>&invRef,int invIndex,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE) inline MenuItemButton(geom2d::rect<float>rect,std::vector<Item>&invRef,int invIndex,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
@ -69,10 +65,12 @@ public:
valid=invRef.size()>invIndex; valid=invRef.size()>invIndex;
} }
inline MenuItemButton(geom2d::rect<float>rect,std::vector<Item>&invRef,int invIndex,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE) inline MenuItemButton(geom2d::rect<float>rect,std::vector<Item>&invRef,int invIndex,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuIconButton(rect,invRef.size()>invIndex?invRef[invIndex].Decal():nullptr,onClick,attributes),onHover(onHover),onMouseOut(onMouseOut),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){ :MenuIconButton(rect,invRef.size()>invIndex?invRef[invIndex].Decal():nullptr,onClick,attributes),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
draggable=false; draggable=false;
runHoverFunctions=true; runHoverFunctions=true;
valid=invRef.size()>invIndex; valid=invRef.size()>invIndex;
SetHoverFunc(onHover);
SetMouseOutFunc(onMouseOut);
} }
inline Item&GetItem(){ inline Item&GetItem(){
return Inventory::GetItem(invRef.at(inventoryIndex).Name()); return Inventory::GetItem(invRef.at(inventoryIndex).Name());
@ -87,21 +85,16 @@ public:
else this->compact=NON_COMPACT; else this->compact=NON_COMPACT;
} }
protected: protected:
virtual inline void BeforeUpdate(Crawler*game)override{ virtual inline void OnMouseOut()override{
if(!hovered&&runHoverFunctions&&hoverState){
hoverState=false;
if(itemNameLabelName!=""){ if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(false); Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(false);
} }
if(itemDescriptionLabelName!=""){ if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false); Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false);
} }
onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
}
} }
virtual inline void Update(Crawler*game)override{ void UpdateLabel(){
MenuIconButton::Update(game); if(invRef[inventoryIndex].IsBlank())return;
valid=invRef.size()>inventoryIndex&&ITEM_DATA.count(invRef[inventoryIndex].Name());
std::string labelNameText; std::string labelNameText;
std::string labelDescriptionText; std::string labelDescriptionText;
if(valid){ if(valid){
@ -113,24 +106,24 @@ protected:
labelNameText=""; labelNameText="";
labelDescriptionText=""; labelDescriptionText="";
} }
if(hovered){
if(itemNameLabelName!=""){ if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText; Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText;
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true);
} }
if(itemDescriptionLabelName!=""){ if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText; Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText;
}
if(runHoverFunctions&&!hoverState){
hoverState=true;
if(itemNameLabelName!=""&&labelNameText.length()>0){
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true);
}
if(itemDescriptionLabelName!=""&&labelDescriptionText.length()>0){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true); Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true);
} }
onHover(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
} }
virtual inline void OnHover()override{
UpdateLabel();
}
virtual inline void Update(Crawler*game)override{
MenuIconButton::Update(game);
valid=invRef.size()>inventoryIndex&&ITEM_DATA.count(invRef[inventoryIndex].Name());
if(hovered){
UpdateLabel();
} }
} }
virtual inline void DrawDecal(ViewPort&window,bool focused)override{ virtual inline void DrawDecal(ViewPort&window,bool focused)override{

@ -53,23 +53,21 @@ private:
std::reference_wrapper<Item>itemRef; std::reference_wrapper<Item>itemRef;
std::string itemNameLabelName; std::string itemNameLabelName;
std::string itemDescriptionLabelName; std::string itemDescriptionLabelName;
bool runHoverFunctions=false;
MenuFunc onHover;
MenuFunc onMouseOut;
bool hoverState=false;
bool hideQty=false; bool hideQty=false;
CompactText compact=COMPACT; CompactText compact=COMPACT;
public: public:
inline MenuItemItemButton(geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE) inline MenuItemItemButton(geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuIconButton(rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),onHover(DO_NOTHING){ :MenuIconButton(rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
draggable=false; draggable=false;
valid=!itemRef.IsBlank(); valid=!itemRef.IsBlank();
} }
inline MenuItemItemButton(geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="",IconButtonAttr attributes=IconButtonAttr::SELECTABLE) inline MenuItemItemButton(geom2d::rect<float>rect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="",IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
:MenuIconButton(rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),onHover(onHover),onMouseOut(onMouseOut){ :MenuIconButton(rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
runHoverFunctions=true; runHoverFunctions=true;
draggable=false; draggable=false;
valid=!itemRef.IsBlank(); valid=!itemRef.IsBlank();
SetHoverFunc(onHover);
SetMouseOutFunc(onMouseOut);
} }
inline Item&GetItem(){ inline Item&GetItem(){
return itemRef.get(); return itemRef.get();
@ -85,21 +83,19 @@ public:
else this->compact=NON_COMPACT; else this->compact=NON_COMPACT;
} }
protected: protected:
virtual inline void BeforeUpdate(Crawler*game)override{ virtual inline void OnMouseOut()override{
if(!hovered&&runHoverFunctions&&hoverState){
hoverState=false;
if(itemNameLabelName!=""){ if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(false); Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(false);
} }
if(itemDescriptionLabelName!=""){ if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false); Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false);
} }
onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
} }
virtual inline void OnHover()override{
UpdateLabel();
} }
virtual inline void Update(Crawler*game)override{ void UpdateLabel(){
MenuIconButton::Update(game); if(itemRef.get().IsBlank())return;
valid=!itemRef.get().IsBlank();
std::string labelNameText; std::string labelNameText;
std::string labelDescriptionText; std::string labelDescriptionText;
if(valid){ if(valid){
@ -111,24 +107,21 @@ protected:
labelNameText=""; labelNameText="";
labelDescriptionText=""; labelDescriptionText="";
} }
if(hovered){
if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText;
}
if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText;
}
if(runHoverFunctions&&!hoverState){
hoverState=true;
if(itemNameLabelName!=""&&labelNameText.length()>0){ if(itemNameLabelName!=""&&labelNameText.length()>0){
Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText;
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true); Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true);
} }
if(itemDescriptionLabelName!=""&&labelDescriptionText.length()>0){ if(itemDescriptionLabelName!=""&&labelDescriptionText.length()>0){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText;
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true); Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true);
} }
onHover(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
} }
virtual inline void Update(Crawler*game)override{
MenuIconButton::Update(game);
valid=!itemRef.get().IsBlank();
if(hovered){
UpdateLabel();
} }
} }
virtual inline void DrawDecal(ViewPort&window,bool focused)override{ virtual inline void DrawDecal(ViewPort&window,bool focused)override{

@ -0,0 +1,98 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2018 - 2022 OneLoneCoder.com
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#include "Item.h"
#include "Crawler.h"
#include "MenuLabel.h"
INCLUDE_game
class RowItemDisplay:public MenuComponent{
Item&itemRef;
std::string itemNameLabelName;
std::string itemDescriptionLabelName;
CompactText compact=NON_COMPACT;
public:
inline RowItemDisplay(geom2d::rect<float>rect,Item&itemRef,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,ButtonAttr attributes=ButtonAttr::NONE)
:MenuComponent(rect,"",onClick,attributes),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),itemRef(itemRef){
}
virtual inline void DrawDecal(ViewPort&window,bool focused)final{
float scaleFactor=rect.size.y/24;
vf2d iconSize=vf2d{scaleFactor,scaleFactor}*24.f;
window.DrawDecal(rect.pos+vf2d{2,2},itemRef.Decal(),{scaleFactor,scaleFactor});
window.DrawRectDecal(rect.pos+vf2d{2,2},iconSize);
window.DrawShadowStringPropDecal(rect.pos+vf2d{4,4}+iconSize,itemRef.Name());
std::string quantityText=std::format("x{}",itemRef.Amt());
vf2d qtyTextSize=game->GetTextSizeProp(quantityText);
window.DrawShadowStringPropDecal(rect.pos+rect.size-vf2d{2,2}+vf2d{-qtyTextSize.x,qtyTextSize.y},quantityText);
}
inline void SetCompactDescriptions(bool compact){
if(compact)this->compact=COMPACT;
else this->compact=NON_COMPACT;
}
virtual inline void OnMouseOut()override{
if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(false);
}
if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false);
}
}
virtual inline void OnHover()override{
std::string labelNameText;
std::string labelDescriptionText;
if(valid){
labelNameText=itemRef.Name();
labelDescriptionText=itemRef.Description(compact);
}else{
labelNameText="";
labelDescriptionText="";
}
if(itemNameLabelName!=""){
Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText;
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true);
}
if(itemDescriptionLabelName!=""){
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText;
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true);
}
}
};

@ -113,8 +113,9 @@ protected:
if(downButton){downButton->Enable(!disabled);} if(downButton){downButton->Enable(!disabled);}
} }
virtual inline void BeforeUpdate(Crawler*game)override{ virtual inline void BeforeUpdate(Crawler*game)override{
MenuComponent::BeforeUpdate(game);
for(MenuComponent*component:components){ for(MenuComponent*component:components){
component->BeforeUpdate(game); component->_BeforeUpdate(game);
} }
} }
virtual inline void Update(Crawler*game)override{ virtual inline void Update(Crawler*game)override{

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 3969 #define VERSION_BUILD 3990
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save