summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPoommetee Ketson <poommetee@protonmail.com>2017-07-04 18:38:56 +0700
committerPoommetee Ketson <poommetee@protonmail.com>2017-07-04 20:12:33 +0700
commit3aff102fc3a9db4bcebdee844c8f6c02147bf371 (patch)
tree65ace4fcea8282b30bf222c268033d13c1078c0e
parenta2586a21196aaf6327a312915b777dec4d3859cc (diff)
ItemList: expose methods, in-editor items editing support
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp40
-rw-r--r--editor/plugins/item_list_editor_plugin.h29
-rw-r--r--scene/gui/item_list.cpp46
-rw-r--r--scene/gui/item_list.h3
4 files changed, 118 insertions, 0 deletions
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index 7f56286f08..f567abc5b1 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -193,6 +193,45 @@ ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
}
///////////////////////////////////////////////////////////////
+
+void ItemListItemListPlugin::set_object(Object *p_object) {
+
+ pp = p_object->cast_to<ItemList>();
+}
+
+bool ItemListItemListPlugin::handles(Object *p_object) const {
+
+ return p_object->is_class("ItemList");
+}
+
+int ItemListItemListPlugin::get_flags() const {
+
+ return FLAG_ICON | FLAG_ENABLE;
+}
+
+void ItemListItemListPlugin::add_item() {
+
+ pp->add_item(vformat(TTR("Item %d"), pp->get_item_count()));
+ _change_notify();
+}
+
+int ItemListItemListPlugin::get_item_count() const {
+
+ return pp->get_item_count();
+}
+
+void ItemListItemListPlugin::erase(int p_idx) {
+
+ pp->remove_item(p_idx);
+ _change_notify();
+}
+
+ItemListItemListPlugin::ItemListItemListPlugin() {
+
+ pp = NULL;
+}
+
+///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
@@ -373,6 +412,7 @@ ItemListEditorPlugin::ItemListEditorPlugin(EditorNode *p_node) {
item_list_editor->hide();
item_list_editor->add_plugin(memnew(ItemListOptionButtonPlugin));
item_list_editor->add_plugin(memnew(ItemListPopupMenuPlugin));
+ item_list_editor->add_plugin(memnew(ItemListItemListPlugin));
}
ItemListEditorPlugin::~ItemListEditorPlugin() {
diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h
index 042e88839f..4fed8e49f5 100644
--- a/editor/plugins/item_list_editor_plugin.h
+++ b/editor/plugins/item_list_editor_plugin.h
@@ -167,6 +167,35 @@ public:
///////////////////////////////////////////////////////////////
+class ItemListItemListPlugin : public ItemListPlugin {
+
+ GDCLASS(ItemListItemListPlugin, ItemListPlugin);
+
+ ItemList *pp;
+
+public:
+ virtual void set_object(Object *p_object);
+ virtual bool handles(Object *p_object) const;
+ virtual int get_flags() const;
+
+ virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); }
+ virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); }
+
+ virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); }
+ virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); }
+
+ virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); }
+ virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); }
+
+ virtual void add_item();
+ virtual int get_item_count() const;
+ virtual void erase(int p_idx);
+
+ ItemListItemListPlugin();
+};
+
+///////////////////////////////////////////////////////////////
+
class ItemListEditor : public HBoxContainer {
GDCLASS(ItemListEditor, HBoxContainer);
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 2f0c7b9aaf..160b7b151a 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -1223,6 +1223,36 @@ Vector<int> ItemList::get_selected_items() {
return selected;
}
+void ItemList::_set_items(const Array &p_items) {
+
+ ERR_FAIL_COND(p_items.size() % 3);
+ clear();
+
+ for (int i = 0; i < p_items.size(); i += 3) {
+
+ String text = p_items[i + 0];
+ Ref<Texture> icon = p_items[i + 1];
+ bool disabled = p_items[i + 2];
+
+ int idx = get_item_count();
+ add_item(text, icon);
+ set_item_disabled(idx, disabled);
+ }
+}
+
+Array ItemList::_get_items() const {
+
+ Array items;
+ for (int i = 0; i < get_item_count(); i++) {
+
+ items.push_back(get_item_text(i));
+ items.push_back(get_item_icon(i));
+ items.push_back(is_item_disabled(i));
+ }
+
+ return items;
+}
+
void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_item", "text", "icon:Texture", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true));
@@ -1302,6 +1332,22 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("_scroll_changed"), &ItemList::_scroll_changed);
ClassDB::bind_method(D_METHOD("_gui_input"), &ItemList::_gui_input);
+ ClassDB::bind_method(D_METHOD("_set_items"), &ItemList::_set_items);
+ ClassDB::bind_method(D_METHOD("_get_items"), &ItemList::_get_items);
+
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items");
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines");
+ ADD_GROUP("Columns", "");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_columns"), "set_max_columns", "get_max_columns");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "fixed_column_width"), "set_fixed_column_width", "get_fixed_column_width");
+ ADD_GROUP("Icon", "");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode");
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale");
+
BIND_CONSTANT(ICON_MODE_TOP);
BIND_CONSTANT(ICON_MODE_LEFT);
BIND_CONSTANT(SELECT_SINGLE);
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index c7abc2990f..9cb7016b60 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -103,6 +103,9 @@ private:
real_t icon_scale;
+ Array _get_items() const;
+ void _set_items(const Array &p_items);
+
void _scroll_changed(double);
void _gui_input(const Ref<InputEvent> &p_event);