diff options
author | James Buck <jamesbuck11@gmail.com> | 2019-06-09 14:44:36 -0500 |
---|---|---|
committer | James Buck <jamesbuck11@gmail.com> | 2019-06-09 14:44:36 -0500 |
commit | 17e1be6478595444f9d306e658040a90ac2936a7 (patch) | |
tree | ab84433f43d2de14e7e0e14335db1caa2732eac8 /scene/gui | |
parent | abbbde87e28982150d30e748b89c5303384909ca (diff) |
Connect OptionButton selection to menu's "index_pressed" signal
Simplifies code and fixes bug where only the first item with a given
ID could be selected.
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/option_button.cpp | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 7027fceb84..872402e9e1 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -86,24 +86,7 @@ void OptionButton::_focused(int p_which) { void OptionButton::_selected(int p_which) { - int selid = -1; - for (int i = 0; i < popup->get_item_count(); i++) { - - bool is_clicked = popup->get_item_id(i) == p_which; - if (is_clicked) { - selid = i; - break; - } - } - - if (selid == -1 && p_which >= 0 && p_which < popup->get_item_count()) { - _select(p_which, true); - } else { - - ERR_FAIL_COND(selid == -1); - - _select(selid, true); - } + _select(p_which, true); } void OptionButton::pressed() { @@ -355,7 +338,7 @@ OptionButton::OptionButton() { popup->set_pass_on_modal_close_click(false); popup->set_notify_transform(true); popup->set_allow_search(true); - popup->connect("id_pressed", this, "_selected"); + popup->connect("index_pressed", this, "_selected"); popup->connect("id_focused", this, "_focused"); popup->connect("popup_hide", this, "set_pressed", varray(false)); } |