summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/menu_button.cpp19
-rw-r--r--scene/gui/menu_button.h3
-rw-r--r--scene/main/viewport.cpp7
3 files changed, 23 insertions, 6 deletions
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 95ec618c3b..b4cb297900 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -71,13 +71,24 @@ PopupMenu *MenuButton::get_popup() const {
return popup;
}
+void MenuButton::_set_items(const Array &p_items) {
+
+ popup->set("items", p_items);
+}
+
Array MenuButton::_get_items() const {
return popup->get("items");
}
-void MenuButton::_set_items(const Array &p_items) {
- popup->set("items", p_items);
+void MenuButton::set_switch_on_hover(bool p_enabled) {
+
+ switch_on_hover = p_enabled;
+}
+
+bool MenuButton::is_switch_on_hover() {
+
+ return switch_on_hover;
}
void MenuButton::_bind_methods() {
@@ -86,9 +97,12 @@ void MenuButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &MenuButton::_unhandled_key_input);
ClassDB::bind_method(D_METHOD("_set_items"), &MenuButton::_set_items);
ClassDB::bind_method(D_METHOD("_get_items"), &MenuButton::_get_items);
+ ClassDB::bind_method(D_METHOD("set_switch_on_hover", "enable"), &MenuButton::set_switch_on_hover);
+ ClassDB::bind_method(D_METHOD("is_switch_on_hover"), &MenuButton::is_switch_on_hover);
ClassDB::bind_method(D_METHOD("set_disable_shortcuts", "disabled"), &MenuButton::set_disable_shortcuts);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "switch_on_hover"), "set_switch_on_hover", "is_switch_on_hover");
ADD_SIGNAL(MethodInfo("about_to_show"));
}
@@ -100,6 +114,7 @@ void MenuButton::set_disable_shortcuts(bool p_disabled) {
MenuButton::MenuButton() {
+ switch_on_hover = false;
set_flat(true);
set_disable_shortcuts(false);
set_enabled_focus_mode(FOCUS_NONE);
diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h
index 0636accfee..abc49f4988 100644
--- a/scene/gui/menu_button.h
+++ b/scene/gui/menu_button.h
@@ -41,6 +41,7 @@ class MenuButton : public Button {
GDCLASS(MenuButton, Button);
bool clicked;
+ bool switch_on_hover;
bool disable_shortcuts;
PopupMenu *popup;
@@ -57,6 +58,8 @@ public:
virtual void pressed();
PopupMenu *get_popup() const;
+ void set_switch_on_hover(bool p_enabled);
+ bool is_switch_on_hover();
void set_disable_shortcuts(bool p_disabled);
MenuButton();
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 3e27c86c67..5b1c2d8020 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1955,10 +1955,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
// 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.
- if (popup_menu_parent && menu_button &&
- popup_menu_parent->get_icon().is_null() &&
- menu_button->get_icon().is_null() &&
- (popup_menu->get_parent()->get_parent()->is_a_parent_of(menu_button) ||
+ if (popup_menu_parent && menu_button && popup_menu_parent->is_switch_on_hover() &&
+ !menu_button->is_disabled() && menu_button->is_switch_on_hover() &&
+ (popup_menu_parent->get_parent()->is_a_parent_of(menu_button) ||
menu_button->get_parent()->is_a_parent_of(popup_menu))) {
popup_menu->notification(Control::NOTIFICATION_MODAL_CLOSE);