summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-11-01 17:01:51 -0300
committerGitHub <noreply@github.com>2018-11-01 17:01:51 -0300
commit65e3ef705b0f45866e3bb4a75bafa374a559d1f0 (patch)
treebedb5cf57007a9c30b5c492b61854935ed6e6e0c /scene
parent755249f7d9e67ff83d46747cf9804ee8b0b0b742 (diff)
parent592eda7ad9458ef1677565e2b86afd9aad45fed1 (diff)
Merge pull request #21962 from YeldhamDev/switch_hover_submenu
Fix MenuButton hover switching not happening with submenus open
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/popup_menu.cpp18
-rw-r--r--scene/main/viewport.cpp10
2 files changed, 25 insertions, 3 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 3239641c2f..f84b75d8d8 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -557,6 +557,21 @@ void PopupMenu::_notification(int p_what) {
mouse_over = -1;
update();
}
+
+ for (int i = 0; i < items.size(); i++) {
+ if (items[i].submenu == "")
+ continue;
+
+ Node *n = get_node(items[i].submenu);
+ if (!n)
+ continue;
+
+ PopupMenu *pm = Object::cast_to<PopupMenu>(n);
+ if (!pm || !pm->is_visible())
+ continue;
+
+ pm->hide();
+ }
} break;
}
}
@@ -1012,8 +1027,7 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
code |= KEY_MASK_SHIFT;
}
- int il = items.size();
- for (int i = 0; i < il; i++) {
+ for (int i = 0; i < items.size(); i++) {
if (is_item_disabled(i) || items[i].shortcut_is_disabled)
continue;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 6bf1d12086..a28b6fd6de 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1839,8 +1839,16 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
MenuButton *popup_menu_parent = NULL;
MenuButton *menu_button = Object::cast_to<MenuButton>(over);
- if (popup_menu)
+ if (popup_menu) {
popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent());
+ if (!popup_menu_parent) {
+ // Go through the parents to see if there's a MenuButton at the end.
+ while (Object::cast_to<PopupMenu>(popup_menu->get_parent())) {
+ popup_menu = Object::cast_to<PopupMenu>(popup_menu->get_parent());
+ }
+ popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent());
+ }
+ }
// If the mouse is over a menu button, this menu will open automatically
// if there is already a pop-up menu open at the same hierarchical level.