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)
114 int nextloc = curpos - 1;
115 while (nextloc != (
int)curpos) {
117 nextloc = _element.size() - 1;
119 if (_element[nextloc]._visible ==
true) {
120 _hoverIndex = _path[nextloc];
133 using namespace pyrodactyl::input;
135 if (
g_engine->_inputManager->getKeyBindingMode() != KBM_UI) {
136 g_engine->_inputManager->setKeyBindingMode(KBM_UI);
139 if (!_element.empty()) {
140 if (_pathType != PATH_HORIZONTAL) {
141 if (
g_engine->_inputManager->state(IU_DOWN)) {
143 _latestInput = KEYBOARD;
144 }
else if (
g_engine->_inputManager->state(IU_UP)) {
146 _latestInput = KEYBOARD;
150 if (_pathType != PATH_VERTICAL) {
151 if (
g_engine->_inputManager->state(IU_RIGHT)) {
153 _latestInput = KEYBOARD;
154 }
else if (
g_engine->_inputManager->state(IU_LEFT)) {
156 _latestInput = KEYBOARD;
160 if (
g_engine->_inputManager->state(IU_ACCEPT) && _hoverIndex != -1)
164 if (_latestInput == KEYBOARD) {
167 for (
auto it = _element.begin(); it != _element.end(); ++it, ++i)
168 it->_hoverKey = (i == _hoverIndex);
181 _useKeyboard =
false;
182 _latestInput = MOUSE;
183 _pathType = PATH_DEFAULT;
188 _latestInput = MOUSE;
190 for (
auto &b : _element)
195 for (
auto &i : _element)
202 void load(rapidxml::xml_node<char> *node) {
203 if (nodeValid(node)) {
204 for (
auto n = node->first_node(); n !=
nullptr; n = n->next_sibling()) {
210 loadBool(_useKeyboard,
"keyboard", node,
false);
220 int handleEvents(
const Common::Event &event,
const int &xOffset = 0,
const int &yOffset = 0) {
223 int result = handleKeyboard(event);
229 g_engine->_inputManager->setKeyBindingMode(pyrodactyl::input::KBM_GAME);
238 _latestInput = MOUSE;
243 for (
auto it = _element.
begin(); it != _element.
end(); ++it, ++i) {
245 if (it->handleEvents(event, xOffset, yOffset) == BUAC_LCLICK) {
248 g_engine->_inputManager->setKeyBindingMode(pyrodactyl::input::KBM_GAME);
254 if (it->_hoverMouse && _latestInput == MOUSE) {
258 for (
auto &e : _element)
263 if (_latestInput == KEYBOARD) {
265 for (
auto &it : _element)
266 it._hoverMouse =
false;
274 void draw(
const int &XOffset = 0,
const int &YOffset = 0) {
275 for (
auto &it : _element)
276 it.draw(XOffset, YOffset);
282 void useKeyboard(
const bool &val) {
302 bool sameX =
true, sameY =
true;
304 if (!_element.
empty()) {
307 for (uint i = 1; i < _element.
size(); i++) {
310 int prevX = _element[i - 1].x;
311 int prevY = _element[i - 1].y;
313 if (sameX && _element[i].x != prevX)
316 if (sameY && _element[i].y != prevY)
323 _pathType = PATH_DEFAULT;
325 _pathType = PATH_VERTICAL;
327 _pathType = PATH_HORIZONTAL;
329 _pathType = PATH_DEFAULT;
340 #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