8 #ifndef HAVEACTION_HPP_ 9 #define HAVEACTION_HPP_ 11 #include <SFML/System/String.hpp> 14 #include "HaveEnabled.hpp" 18 using function_type = std::function<void (T)>;
23 using function_type = std::function<void ()>;
28 const char*
const main =
"main";
29 const char*
const destruction =
"destruction";
35 using function_type =
typename HaveActionHelper<T>::function_type;
38 mainActionType = ActionType::main;
41 doAction(ActionType::destruction);
43 virtual void onSetAction(
const sf::String& type) {}
44 virtual void setAction(function_type&& action,
const sf::String& type = ActionType::main) {
45 if(type == ActionType::main) {
46 onSetAction(mainActionType);
47 this->action[mainActionType] = action;
50 this->action[type] = action;
53 virtual void setAction(function_type& action,
const sf::String& type = ActionType::main) {
54 if(type == ActionType::main) {
55 onSetAction(mainActionType);
56 this->action[mainActionType] = action;
59 this->action[type] = action;
62 virtual void setAction(std::function<
void ()>&& action,
const sf::String& type = ActionType::main) {
63 if(type == ActionType::main) {
64 onSetAction(mainActionType);
65 actionVoid[mainActionType] = action;
68 actionVoid[type] = action;
71 virtual void setAction(std::function<
void ()>& action,
const sf::String& type = ActionType::main) {
72 if(type == ActionType::main) {
73 onSetAction(mainActionType);
74 actionVoid[mainActionType] = action;
77 actionVoid[type] = action;
80 virtual void doAction(
const sf::String& type = ActionType::main) {
82 if(he !=
nullptr && !he->isEnabled()) {
86 if(type == ActionType::main) {
87 if(action[mainActionType]) {
88 action[mainActionType](
dynamic_cast<T
>(*this));
89 }
else if(actionVoid[mainActionType]) {
90 actionVoid[mainActionType]();
94 action[type](
dynamic_cast<T
>(*this));
95 }
else if(actionVoid[type]) {
102 std::map<sf::String,function_type> action;
103 std::map<sf::String, std::function<void ()>> actionVoid;
104 sf::String mainActionType;
113 mainActionType = ActionType::main;
116 virtual void onSetAction(
const sf::String& type) {}
117 virtual void setAction(function_type&& action,
const sf::String& type = ActionType::main) {
118 if(type == ActionType::main) {
119 onSetAction(mainActionType);
120 this->action[mainActionType] = action;
123 this->action[type] = action;
126 virtual void setAction(function_type& action,
const sf::String& type = ActionType::main) {
127 if(type == ActionType::main) {
128 onSetAction(mainActionType);
129 this->action[mainActionType] = action;
132 this->action[type] = action;
135 virtual void doAction(
const sf::String& type = ActionType::main) {
137 if(he !=
nullptr && !he->isEnabled()) {
141 if(type == ActionType::main && action[mainActionType]) {
142 action[mainActionType]();
143 }
else if(action[type]) {
149 std::map<sf::String,function_type> action;
150 sf::String mainActionType;
Definition: Checkbox.hpp:13
Definition: HaveEnabled.hpp:15
Definition: HaveAction.hpp:33
Definition: HaveAction.hpp:17