Add a BeforeUpdate event for components to handle mouse out events (specifically for equip item slots showing stat differences.) Corrects a bug with stat differences not refreshing on mouse out.

pull/28/head
sigonasr2 1 year ago
parent 4ab88b3014
commit ae2d1719c8
  1. 9
      Crawler/CharacterMenuWindow.cpp
  2. 12
      Crawler/Menu.cpp
  3. 2
      Crawler/MenuComponent.cpp
  4. 17
      Crawler/MenuComponent.h
  5. 10
      Crawler/MenuItemItemButton.h
  6. 5
      Crawler/ScrollableWindowComponent.h
  7. 2
      Crawler/Version.h

@ -177,7 +177,14 @@ void Menu::InitializeCharacterMenuWindow(){
Inventory::EquipItem(*equippedItem,slot); Inventory::EquipItem(*equippedItem,slot);
} }
return true; return true;
},DO_NOTHING); },[](MenuFuncData data){
for(int counter=0;ItemAttribute attribute:displayAttrs){
StatLabel*statDisplayLabel=Component<StatLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
statDisplayLabel->SetStatChangeAmt(0);
counter++;
}
return true;
});
equip->I(Attribute::EQUIP_TYPE)=int(slot); equip->I(Attribute::EQUIP_TYPE)=int(slot);
if(Inventory::GetEquip(slot)==&itemInvRef){ if(Inventory::GetEquip(slot)==&itemInvRef){
equip->SetSelected(true); equip->SetSelected(true);

@ -292,6 +292,18 @@ void Menu::Update(Crawler*game){
} }
KeyboardButtonNavigation(game,pos); KeyboardButtonNavigation(game,pos);
for(auto&[key,value]:buttons){
for(auto&button:value){
if(button->renderInMain){
button->BeforeUpdate(game);
}
}
}
for(auto&component:displayComponents){
if(component->renderInMain){
component->BeforeUpdate(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){

@ -67,6 +67,8 @@ MenuComponent::~MenuComponent(){
void MenuComponent::AfterCreate(){} void MenuComponent::AfterCreate(){}
void MenuComponent::BeforeUpdate(Crawler*game){}
void MenuComponent::Update(Crawler*game){ void MenuComponent::Update(Crawler*game){
if(hovered){ if(hovered){
hoverEffect=std::min("ThemeGlobal.HighlightTime"_F,hoverEffect+game->GetElapsedTime()); hoverEffect=std::min("ThemeGlobal.HighlightTime"_F,hoverEffect+game->GetElapsedTime());

@ -53,7 +53,7 @@ enum class ComponentAttr{
BACKGROUND=0b1000, //Renders the background of the menu theme for this component. BACKGROUND=0b1000, //Renders the background of the menu theme for this component.
}; };
class MenuComponent:IAttributable{ class MenuComponent:public IAttributable{
friend class Menu; friend class Menu;
friend class MenuItemButton; friend class MenuItemButton;
friend class ScrollableWindowComponent; friend class ScrollableWindowComponent;
@ -63,6 +63,12 @@ class MenuComponent:IAttributable{
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.
virtual void BeforeUpdate(Crawler*game);
void _Update(Crawler*game);
void _Draw(Crawler*game);
void _Draw(Crawler*game,vf2d parentPos);
void _DrawDecal(Crawler*game,bool focused);
void _DrawDecal(Crawler*game,vf2d parentPos,bool focused);
protected: protected:
float hoverEffect=0; float hoverEffect=0;
std::string name=""; std::string name="";
@ -73,8 +79,6 @@ protected:
bool background=true; bool background=true;
bool showDefaultLabel=true; bool showDefaultLabel=true;
MenuFunc onClick; MenuFunc onClick;
MenuType parentMenu=MenuType::ENUM_END;
MenuComponent*parentComponent=nullptr;
bool hovered=false; bool hovered=false;
bool selectable=true; bool selectable=true;
bool selectableViaKeyboard=true; bool selectableViaKeyboard=true;
@ -89,14 +93,11 @@ protected:
//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,vi2d drawPos); virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos);
public: public:
MenuType parentMenu=MenuType::ENUM_END;
MenuComponent*parentComponent=nullptr;
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,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,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(); virtual ~MenuComponent();
void _Update(Crawler*game);
void _Draw(Crawler*game);
void _Draw(Crawler*game,vf2d parentPos);
void _DrawDecal(Crawler*game,bool focused);
void _DrawDecal(Crawler*game,vf2d parentPos,bool focused);
vf2d GetPos(); vf2d GetPos();
//We picked up a draggable component, we should make a copy and return it here. If a nullptr is returned here, the pickup is not allowed. //We picked up a draggable component, we should make a copy and return it here. If a nullptr is returned here, the pickup is not allowed.
//WARNING!!! This allocates a brand new component when successful!!! Be prepared to clear it! //WARNING!!! This allocates a brand new component when successful!!! Be prepared to clear it!

@ -86,6 +86,12 @@ public:
this->hideQty=!show; this->hideQty=!show;
} }
protected: protected:
virtual inline void BeforeUpdate(Crawler*game)override{
if(!hovered&&runHoverFunctions&&hoverState){
hoverState=false;
onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
}
}
virtual inline void Update(Crawler*game)override{ virtual inline void Update(Crawler*game)override{
MenuIconButton::Update(game); MenuIconButton::Update(game);
valid=!itemRef.get().IsBlank(); valid=!itemRef.get().IsBlank();
@ -110,10 +116,6 @@ protected:
hoverState=true; hoverState=true;
onHover(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)}); onHover(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
} }
}else
if(runHoverFunctions&&hoverState){
hoverState=false;
onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)});
} }
} }
virtual inline void Draw(Crawler*game,vf2d parentPos)override{ virtual inline void Draw(Crawler*game,vf2d parentPos)override{

@ -99,6 +99,11 @@ public:
delete button; delete button;
} }
protected: protected:
virtual inline void BeforeUpdate(Crawler*game)override{
for(MenuComponent*component:components){
component->BeforeUpdate(game);
}
}
virtual inline void Update(Crawler*game)override{ virtual inline void Update(Crawler*game)override{
MenuComponent::Update(game); MenuComponent::Update(game);

@ -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 3592 #define VERSION_BUILD 3598
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save