diff options
Diffstat (limited to 'scene/gui/popup_menu.cpp')
-rw-r--r-- | scene/gui/popup_menu.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 7936ee39cb..3cbf18b768 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -912,11 +912,24 @@ void PopupMenu::activate_item(int p_item) { Node *next = get_parent(); PopupMenu *pop = next->cast_to<PopupMenu>(); while (pop) { - pop->hide(); - next = next->get_parent(); - pop = next->cast_to<PopupMenu>(); + // We close all parents that are chained together, + // with hide_on_item_selection enabled + if(hide_on_item_selection && pop->is_hide_on_item_selection()) { + pop->hide(); + next = next->get_parent(); + pop = next->cast_to<PopupMenu>(); + } + else { + // Break out of loop when the next parent has + // hide_on_item_selection disabled + break; + } + } + // Hides popup by default; unless otherwise specified + // by using set_hide_on_item_selection + if (hide_on_item_selection) { + hide(); } - hide(); } @@ -1032,6 +1045,16 @@ void PopupMenu::_set_items(const Array& p_items){ } +// Hide on item selection determines whether or not the popup will close after item selection +void PopupMenu::set_hide_on_item_selection(bool p_enabled) { + + hide_on_item_selection=p_enabled; +} + +bool PopupMenu::is_hide_on_item_selection() { + + return hide_on_item_selection; +} String PopupMenu::get_tooltip(const Point2& p_pos) const { @@ -1120,9 +1143,13 @@ void PopupMenu::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_items"),&PopupMenu::_set_items); ObjectTypeDB::bind_method(_MD("_get_items"),&PopupMenu::_get_items); + ObjectTypeDB::bind_method(_MD("set_hide_on_item_selection","enable"),&PopupMenu::set_hide_on_item_selection); + ObjectTypeDB::bind_method(_MD("is_hide_on_item_selection"),&PopupMenu::is_hide_on_item_selection); + ObjectTypeDB::bind_method(_MD("_submenu_timeout"),&PopupMenu::_submenu_timeout); ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"items",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_items"),_SCS("_get_items") ); + ADD_PROPERTYNO( PropertyInfo(Variant::BOOL, "hide_on_item_selection" ), _SCS("set_hide_on_item_selection"), _SCS("is_hide_on_item_selection") ); ADD_SIGNAL( MethodInfo("item_pressed", PropertyInfo( Variant::INT,"ID") ) ); @@ -1141,6 +1168,7 @@ PopupMenu::PopupMenu() { set_focus_mode(FOCUS_ALL); set_as_toplevel(true); + set_hide_on_item_selection(true); submenu_timer = memnew( Timer ); submenu_timer->set_wait_time(0.3); |