38 #include "crab/crab.h" 39 #include "crab/metaengine.h" 40 #include "crab/ui/button.h" 44 namespace pyrodactyl {
75 if (_hoverIndex == -1) {
76 for (uint pos = 0; pos < _path.
size(); pos++)
77 if (_element[_path[pos]]._visible ==
true) {
78 _hoverIndex = _path[pos];
83 for (; curpos < _path.
size(); curpos++)
84 if ((
int)_path[curpos] == _hoverIndex)
87 for (uint nextloc = (curpos + 1) % _element.size(); nextloc != curpos; nextloc = (nextloc + 1) % _element.size())
88 if (_element[nextloc]._visible ==
true) {
89 _hoverIndex = _path[nextloc];
99 if (_hoverIndex == -1) {
100 for (uint pos = 0; pos < _path.
size(); pos++)
101 if (_element[_path[pos]]._visible ==
true) {
102 _hoverIndex = _path[pos];
107 for (; curpos < _path.
size(); curpos++)
108 if ((
int)_path[curpos] == _hoverIndex)
111 int nextloc = curpos - 1;
112 while (nextloc != (
int)curpos) {
114 nextloc = _element.size() - 1;
116 if (_element[nextloc]._visible ==
true) {
117 _hoverIndex = _path[nextloc];
130 using namespace pyrodactyl::input;
132 if (
g_engine->_inputManager->getKeyBindingMode() != KBM_UI) {
133 g_engine->_inputManager->setKeyBindingMode(KBM_UI);
136 if (!_element.empty()) {
137 if (_pathType != PATH_HORIZONTAL) {
138 if (
g_engine->_inputManager->state(IU_DOWN)) {
140 _latestInput = KEYBOARD;
141 }
else if (
g_engine->_inputManager->state(IU_UP)) {
143 _latestInput = KEYBOARD;
147 if (_pathType != PATH_VERTICAL) {
148 if (
g_engine->_inputManager->state(IU_RIGHT)) {
150 _latestInput = KEYBOARD;
151 }
else if (
g_engine->_inputManager->state(IU_LEFT)) {
153 _latestInput = KEYBOARD;
157 if (
g_engine->_inputManager->state(IU_ACCEPT) && _hoverIndex != -1)
161 if (_latestInput == KEYBOARD) {
164 for (
auto it = _element.begin(); it != _element.end(); ++it, ++i)
165 it->_hoverKey = (i == _hoverIndex);
178 _useKeyboard =
false;
179 _latestInput = MOUSE;
180 _pathType = PATH_DEFAULT;
185 _latestInput = MOUSE;
187 for (
auto &b : _element)
192 for (
auto &i : _element)
199 void load(rapidxml::xml_node<char> *node) {
200 if (nodeValid(node)) {
201 for (
auto n = node->first_node(); n !=
nullptr; n = n->next_sibling()) {
207 loadBool(_useKeyboard,
"keyboard", node,
false);
217 int handleEvents(
const Common::Event &event,
const int &xOffset = 0,
const int &yOffset = 0) {
220 int result = handleKeyboard(event);
226 g_engine->_inputManager->setKeyBindingMode(pyrodactyl::input::KBM_GAME);
235 _latestInput = MOUSE;
240 for (
auto it = _element.
begin(); it != _element.
end(); ++it, ++i) {
242 if (it->handleEvents(event, xOffset, yOffset) == BUAC_LCLICK) {
245 g_engine->_inputManager->setKeyBindingMode(pyrodactyl::input::KBM_GAME);
251 if (it->_hoverMouse && _latestInput == MOUSE) {
255 for (
auto &e : _element)
260 if (_latestInput == KEYBOARD) {
262 for (
auto &it : _element)
263 it._hoverMouse =
false;
271 void draw(
const int &XOffset = 0,
const int &YOffset = 0) {
272 for (
auto &it : _element)
273 it.draw(XOffset, YOffset);
279 void useKeyboard(
const bool &val) {
299 bool sameX =
true, sameY =
true;
301 if (!_element.
empty()) {
304 for (uint i = 1; i < _element.
size(); i++) {
307 int prevX = _element[i - 1].x;
308 int prevY = _element[i - 1].y;
310 if (sameX && _element[i].x != prevX)
313 if (sameY && _element[i].y != prevY)
320 _pathType = PATH_DEFAULT;
322 _pathType = PATH_VERTICAL;
324 _pathType = PATH_HORIZONTAL;
326 _pathType = PATH_DEFAULT;
337 #endif // CRAB_MENU_H bool isMouseEvent(const Event &event)
void clear()
Definition: array.h:320
iterator end()
Definition: array.h:379
iterator begin()
Definition: array.h:374
bool empty() const
Definition: array.h:351
void push_back(const T &element)
Definition: array.h:180
size_type size() const
Definition: array.h:315
Definition: moveeffect.h:37