From 2fd9b77828bcc7c22594c7037db17efd11ba1909 Mon Sep 17 00:00:00 2001 From: Jean Jung Date: Tue, 28 Jun 2016 14:09:17 -0300 Subject: itemlist-get_selected_items --- scene/gui/item_list.cpp | 16 ++++++++++++++-- scene/gui/item_list.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 5379836746..d63c483ef9 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1245,6 +1245,19 @@ real_t ItemList::get_icon_scale() const { return icon_scale; } +Vector ItemList::get_selected_items() { + Vector selected; + for (int i = 0; i < items.size(); i++) { + if (items[i].selected) { + selected.push_back(i); + if (this->select_mode == SELECT_SINGLE) { + break; + } + } + } + return selected; +} + void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("add_item","text","icon:Texture","selectable"),&ItemList::add_item,DEFVAL(Variant()),DEFVAL(true)); @@ -1277,6 +1290,7 @@ void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("select","idx","single"),&ItemList::select,DEFVAL(true)); ObjectTypeDB::bind_method(_MD("unselect","idx"),&ItemList::unselect); ObjectTypeDB::bind_method(_MD("is_selected","idx"),&ItemList::is_selected); + ObjectTypeDB::bind_method(_MD("get_selected_items"),&ItemList::get_selected_items); ObjectTypeDB::bind_method(_MD("get_item_count"),&ItemList::get_item_count); ObjectTypeDB::bind_method(_MD("remove_item","idx"),&ItemList::remove_item); @@ -1330,8 +1344,6 @@ void ItemList::_bind_methods(){ ADD_SIGNAL( MethodInfo("item_activated",PropertyInfo(Variant::INT,"index"))); } - - ItemList::ItemList() { current=-1; diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index aa6dd64c50..e1902d1c1f 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -144,6 +144,7 @@ public: void select(int p_idx,bool p_single=true); void unselect(int p_idx); bool is_selected(int p_idx) const; + Vector get_selected_items(); void set_current(int p_current); int get_current() const; -- cgit v1.2.3