Merge pull request #9496 from Noshyaar/pr-itemlist
ItemList: expose methods, in-editor items editing support
This commit is contained in:
commit
f4ff452a58
4 changed files with 118 additions and 0 deletions
|
@ -192,6 +192,45 @@ ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
|
|||
pp = NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue