Hover functionality moved out to MenuComponent so any component can utilize them.
This commit is contained in:
@@ -77,6 +77,10 @@ MenuComponent::~MenuComponent(){
|
||||
|
||||
void MenuComponent::AfterCreate(){}
|
||||
|
||||
void MenuComponent::_BeforeUpdate(Crawler*game){
|
||||
_OnMouseOut();
|
||||
BeforeUpdate(game);
|
||||
}
|
||||
void MenuComponent::BeforeUpdate(Crawler*game){}
|
||||
|
||||
void MenuComponent::Update(Crawler*game){
|
||||
@@ -89,6 +93,7 @@ void MenuComponent::Update(Crawler*game){
|
||||
|
||||
void MenuComponent::_Update(Crawler*game){
|
||||
if(!disabled){
|
||||
_OnHover();
|
||||
Update(game);
|
||||
}
|
||||
}
|
||||
@@ -194,4 +199,38 @@ void MenuComponent::SetSelected(bool selected){
|
||||
|
||||
void MenuComponent::SetSelectionType(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;
|
||||
};
|
||||
Reference in New Issue
Block a user