Popupmenu now uses UI actions instead of keys

This commit is contained in:
Fabio Alessandrelli 2017-12-31 04:42:25 +01:00
parent be7bfdfac3
commit 4a71483a65

View File

@ -211,16 +211,7 @@ void PopupMenu::_scroll(float p_factor, const Point2 &p_over) {
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event; if (p_event->is_action("ui_down") && p_event->is_pressed()) {
if (k.is_valid()) {
if (!k->is_pressed())
return;
switch (k->get_scancode()) {
case KEY_DOWN: {
int search_from = mouse_over + 1; int search_from = mouse_over + 1;
if (search_from >= items.size()) if (search_from >= items.size())
@ -235,11 +226,11 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
mouse_over = i; mouse_over = i;
update(); update();
accept_event();
break; break;
} }
} }
} break; } else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
case KEY_UP: {
int search_from = mouse_over - 1; int search_from = mouse_over - 1;
if (search_from < 0) if (search_from < 0)
@ -254,43 +245,33 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
mouse_over = i; mouse_over = i;
update(); update();
accept_event();
break; break;
} }
} }
} break; } else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
case KEY_LEFT: {
Node *n = get_parent(); Node *n = get_parent();
if (!n) if (n && Object::cast_to<PopupMenu>(n)) {
break;
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
if (!pm)
break;
hide(); hide();
} break; accept_event();
}
} else if (p_event->is_action("ui_right") && p_event->is_pressed()) {
case KEY_RIGHT: { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) {
if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over)
_activate_submenu(mouse_over); _activate_submenu(mouse_over);
} break; accept_event();
}
case KEY_ENTER: } else if (p_event->is_action("ui_accept") && p_event->is_pressed()) {
case KEY_KP_ENTER: {
if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) {
if (items[mouse_over].submenu != "" && submenu_over != mouse_over) { if (items[mouse_over].submenu != "" && submenu_over != mouse_over) {
_activate_submenu(mouse_over); _activate_submenu(mouse_over);
break; } else {
}
activate_item(mouse_over); activate_item(mouse_over);
} }
} break; accept_event();
} }
} }