Toggle Interface implementation. Class toggling connections created and class switching via class selection menu completed.
parent
598ce523e9
commit
cedb465c79
@ -0,0 +1,34 @@ |
|||||||
|
#pragma once |
||||||
|
#include "MenuAnimatedIconButton.h" |
||||||
|
#include "DEFINES.h" |
||||||
|
#include "Crawler.h" |
||||||
|
#include "Toggleable.h" |
||||||
|
|
||||||
|
INCLUDE_game |
||||||
|
|
||||||
|
class MenuAnimatedIconToggleButton:public MenuAnimatedIconButton,public IToggleable{ |
||||||
|
protected: |
||||||
|
MenuFunc _onClick; //What the user-defined behavior is. This toggle has its own custom-built onClick stuff to do.
|
||||||
|
private: |
||||||
|
float animationTime=0; |
||||||
|
public: |
||||||
|
inline MenuAnimatedIconToggleButton(MenuType parent,geom2d::rect<float>rect,std::string animation,MenuFunc onClick) |
||||||
|
:MenuAnimatedIconButton(parent,rect,animation,[](MenuFuncData data){ |
||||||
|
MenuAnimatedIconToggleButton*button=(MenuAnimatedIconToggleButton*)data.component; |
||||||
|
button->Select(); |
||||||
|
button->_onClick(data); |
||||||
|
}),_onClick(onClick){} |
||||||
|
protected: |
||||||
|
virtual inline void Update(Crawler*game)override{ |
||||||
|
MenuAnimatedIconButton::Update(game); |
||||||
|
if(IsSelected()){ |
||||||
|
hoverEffect="ThemeGlobal.HighlightTime"_F; //A hack that allows us to make it look like we have this selected.
|
||||||
|
} |
||||||
|
} |
||||||
|
virtual inline void Draw(Crawler*game,vf2d parentPos)override{ |
||||||
|
MenuAnimatedIconButton::Draw(game,parentPos); |
||||||
|
if(IsSelected()){ |
||||||
|
game->DrawRect(rect.pos+vi2d{2,2},rect.size-vi2d{4,4},YELLOW); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,42 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
class IToggleable{ |
||||||
|
friend class Crawler; |
||||||
|
public: |
||||||
|
inline std::vector<IToggleable*>GetToggleGroup(){ |
||||||
|
return toggleGroup; |
||||||
|
} |
||||||
|
inline void Select(){ |
||||||
|
for(IToggleable*item:toggleGroup){ |
||||||
|
item->selected=false; |
||||||
|
} |
||||||
|
selected=true; |
||||||
|
} |
||||||
|
inline bool IsSelected(){ |
||||||
|
return selected; |
||||||
|
} |
||||||
|
inline void SetToggleGroup(){ |
||||||
|
if(toggleGroupInitialized){ |
||||||
|
std::cout<<"WARNING! Toggle group for this component was set twice for some reason! THIS SHOULD NOT BE HAPPENING!"<<std::endl; |
||||||
|
throw; |
||||||
|
} |
||||||
|
toggleGroupInitialized=true; |
||||||
|
std::erase_if(uninitializedToggleGroupItems,[&](IToggleable*item){return this==item;}); |
||||||
|
} |
||||||
|
inline void SetToggleGroup(std::vector<IToggleable*>toggleGroup){ |
||||||
|
this->toggleGroup=toggleGroup; |
||||||
|
SetToggleGroup(); |
||||||
|
} |
||||||
|
inline IToggleable(){ |
||||||
|
uninitializedToggleGroupItems.push_back(this); |
||||||
|
if("debug_toggleable_items"_I){ |
||||||
|
std::cout<<"\tInitialized Toggle Item Ptr: 0x"<<std::hex<<this<<std::endl; |
||||||
|
} |
||||||
|
} |
||||||
|
protected: |
||||||
|
std::vector<IToggleable*>toggleGroup; |
||||||
|
private: |
||||||
|
bool selected=false; |
||||||
|
bool toggleGroupInitialized=false; |
||||||
|
inline static std::vector<IToggleable*>uninitializedToggleGroupItems; |
||||||
|
}; |
Loading…
Reference in new issue