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.
This commit is contained in:
parent
4ab88b3014
commit
ae2d1719c8
@ -177,7 +177,14 @@ void Menu::InitializeCharacterMenuWindow(){
|
||||
Inventory::EquipItem(*equippedItem,slot);
|
||||
}
|
||||
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);
|
||||
if(Inventory::GetEquip(slot)==&itemInvRef){
|
||||
equip->SetSelected(true);
|
||||
|
@ -292,6 +292,18 @@ void Menu::Update(Crawler*game){
|
||||
}
|
||||
|
||||
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&button:value){
|
||||
if(button->renderInMain){
|
||||
|
@ -67,6 +67,8 @@ MenuComponent::~MenuComponent(){
|
||||
|
||||
void MenuComponent::AfterCreate(){}
|
||||
|
||||
void MenuComponent::BeforeUpdate(Crawler*game){}
|
||||
|
||||
void MenuComponent::Update(Crawler*game){
|
||||
if(hovered){
|
||||
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.
|
||||
};
|
||||
|
||||
class MenuComponent:IAttributable{
|
||||
class MenuComponent:public IAttributable{
|
||||
friend class Menu;
|
||||
friend class MenuItemButton;
|
||||
friend class ScrollableWindowComponent;
|
||||
@ -63,6 +63,12 @@ class MenuComponent:IAttributable{
|
||||
private:
|
||||
virtual bool GetHoverState(Crawler*game);
|
||||
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:
|
||||
float hoverEffect=0;
|
||||
std::string name="";
|
||||
@ -73,8 +79,6 @@ protected:
|
||||
bool background=true;
|
||||
bool showDefaultLabel=true;
|
||||
MenuFunc onClick;
|
||||
MenuType parentMenu=MenuType::ENUM_END;
|
||||
MenuComponent*parentComponent=nullptr;
|
||||
bool hovered=false;
|
||||
bool selectable=true;
|
||||
bool selectableViaKeyboard=true;
|
||||
@ -89,14 +93,11 @@ protected:
|
||||
//CALL THIS FOR A PARENT to check a child's DrawDecal validity!
|
||||
virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos);
|
||||
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,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
|
||||
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();
|
||||
//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!
|
||||
|
@ -86,6 +86,12 @@ public:
|
||||
this->hideQty=!show;
|
||||
}
|
||||
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{
|
||||
MenuIconButton::Update(game);
|
||||
valid=!itemRef.get().IsBlank();
|
||||
@ -110,10 +116,6 @@ protected:
|
||||
hoverState=true;
|
||||
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{
|
||||
|
@ -99,6 +99,11 @@ public:
|
||||
delete button;
|
||||
}
|
||||
protected:
|
||||
virtual inline void BeforeUpdate(Crawler*game)override{
|
||||
for(MenuComponent*component:components){
|
||||
component->BeforeUpdate(game);
|
||||
}
|
||||
}
|
||||
virtual inline void Update(Crawler*game)override{
|
||||
MenuComponent::Update(game);
|
||||
|
||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 1
|
||||
#define VERSION_BUILD 3592
|
||||
#define VERSION_BUILD 3598
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user