2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* item_list_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2019-01-01 12:53:14 +01:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "item_list_editor_plugin.h"
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/io/resource_loader.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String name = p_name;
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = name.get_slice("/", 0).to_int();
|
|
|
|
String what = name.get_slice("/", 1);
|
|
|
|
|
|
|
|
if (what == "text")
|
|
|
|
set_item_text(idx, p_value);
|
|
|
|
else if (what == "icon")
|
|
|
|
set_item_icon(idx, p_value);
|
2018-03-24 02:51:26 +01:00
|
|
|
else if (what == "checkable") {
|
|
|
|
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
|
|
|
|
switch ((int)p_value) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
set_item_checkable(idx, p_value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
set_item_radio_checkable(idx, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (what == "checked")
|
2017-03-05 16:44:50 +01:00
|
|
|
set_item_checked(idx, p_value);
|
|
|
|
else if (what == "id")
|
|
|
|
set_item_id(idx, p_value);
|
|
|
|
else if (what == "enabled")
|
|
|
|
set_item_enabled(idx, p_value);
|
|
|
|
else if (what == "separator")
|
|
|
|
set_item_separator(idx, p_value);
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String name = p_name;
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = name.get_slice("/", 0).to_int();
|
|
|
|
String what = name.get_slice("/", 1);
|
|
|
|
|
|
|
|
if (what == "text")
|
|
|
|
r_ret = get_item_text(idx);
|
|
|
|
else if (what == "icon")
|
|
|
|
r_ret = get_item_icon(idx);
|
2018-03-24 02:51:26 +01:00
|
|
|
else if (what == "checkable") {
|
|
|
|
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
|
|
|
|
if (!is_item_checkable(idx)) {
|
|
|
|
r_ret = 0;
|
|
|
|
} else {
|
|
|
|
r_ret = is_item_radio_checkable(idx) ? 2 : 1;
|
|
|
|
}
|
|
|
|
} else if (what == "checked")
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = is_item_checked(idx);
|
|
|
|
else if (what == "id")
|
|
|
|
r_ret = get_item_id(idx);
|
|
|
|
else if (what == "enabled")
|
|
|
|
r_ret = is_item_enabled(idx);
|
|
|
|
else if (what == "separator")
|
|
|
|
r_ret = is_item_separator(idx);
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < get_item_count(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String base = itos(i) + "/";
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, base + "text"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
int flags = get_flags();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (flags & FLAG_CHECKABLE) {
|
2019-01-17 16:13:49 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, base + "checkable", PROPERTY_HINT_ENUM, "No,As checkbox,As radio button"));
|
2017-03-05 16:44:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (flags & FLAG_ID)
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, base + "id", PROPERTY_HINT_RANGE, "-1,4096"));
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (flags & FLAG_ENABLE)
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, base + "enabled"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (flags & FLAG_SEPARATOR)
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, base + "separator"));
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////// PLUGINS /////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListOptionButtonPlugin::set_object(Object *p_object) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
ob = Object::cast_to<OptionButton>(p_object);
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
bool ItemListOptionButtonPlugin::handles(Object *p_object) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
return p_object->is_class("OptionButton");
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
int ItemListOptionButtonPlugin::get_flags() const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return FLAG_ICON | FLAG_ID | FLAG_ENABLE;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListOptionButtonPlugin::add_item() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ob->add_item(vformat(TTR("Item %d"), ob->get_item_count()));
|
2016-03-09 00:00:52 +01:00
|
|
|
_change_notify();
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
int ItemListOptionButtonPlugin::get_item_count() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
return ob->get_item_count();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListOptionButtonPlugin::erase(int p_idx) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
ob->remove_item(p_idx);
|
2015-12-03 18:59:59 +01:00
|
|
|
_change_notify();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ob = NULL;
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ItemListPopupMenuPlugin::set_object(Object *p_object) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
if (p_object->is_class("MenuButton"))
|
2017-08-24 22:58:51 +02:00
|
|
|
pp = Object::cast_to<MenuButton>(p_object)->get_popup();
|
2015-12-03 18:59:59 +01:00
|
|
|
else
|
2017-08-24 22:58:51 +02:00
|
|
|
pp = Object::cast_to<PopupMenu>(p_object);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
bool ItemListPopupMenuPlugin::handles(Object *p_object) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
return p_object->is_class("PopupMenu") || p_object->is_class("MenuButton");
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
int ItemListPopupMenuPlugin::get_flags() const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return FLAG_ICON | FLAG_CHECKABLE | FLAG_ID | FLAG_ENABLE | FLAG_SEPARATOR;
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemListPopupMenuPlugin::add_item() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pp->add_item(vformat(TTR("Item %d"), pp->get_item_count()));
|
2015-12-03 18:59:59 +01:00
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ItemListPopupMenuPlugin::get_item_count() const {
|
|
|
|
|
|
|
|
return pp->get_item_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemListPopupMenuPlugin::erase(int p_idx) {
|
|
|
|
|
|
|
|
pp->remove_item(p_idx);
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pp = NULL;
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
|
|
|
|
2017-07-04 13:38:56 +02:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ItemListItemListPlugin::set_object(Object *p_object) {
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
pp = Object::cast_to<ItemList>(p_object);
|
2017-07-04 13:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ItemListEditor::_node_removed(Node *p_node) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_node == item_list) {
|
|
|
|
item_list = NULL;
|
2015-12-03 18:59:59 +01:00
|
|
|
hide();
|
|
|
|
dialog->hide();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemListEditor::_notification(int p_notification) {
|
|
|
|
|
2018-02-25 17:04:16 +01:00
|
|
|
if (p_notification == NOTIFICATION_ENTER_TREE || p_notification == NOTIFICATION_THEME_CHANGED) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
add_button->set_icon(get_icon("Add", "EditorIcons"));
|
|
|
|
del_button->set_icon(get_icon("Remove", "EditorIcons"));
|
2018-11-30 04:59:29 +01:00
|
|
|
} else if (p_notification == NOTIFICATION_READY) {
|
|
|
|
|
|
|
|
get_tree()->connect("node_removed", this, "_node_removed");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListEditor::_add_pressed() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (selected_idx == -1)
|
2015-12-03 18:59:59 +01:00
|
|
|
return;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
item_plugins[selected_idx]->add_item();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListEditor::_delete_pressed() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-09-11 15:53:50 +02:00
|
|
|
if (selected_idx == -1)
|
2015-12-03 18:59:59 +01:00
|
|
|
return;
|
|
|
|
|
2018-09-11 15:53:50 +02:00
|
|
|
String current_selected = (String)property_editor->get_selected_path();
|
|
|
|
|
|
|
|
if (current_selected == "")
|
2015-12-03 18:59:59 +01:00
|
|
|
return;
|
|
|
|
|
2018-09-11 15:53:50 +02:00
|
|
|
// FIXME: Currently relying on selecting a *property* to derive what item to delete
|
|
|
|
// e.g. you select "1/enabled" to delete item 1.
|
|
|
|
// This should be fixed so that you can delete by selecting the item section header,
|
|
|
|
// or a delete button on that header.
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2018-09-11 15:53:50 +02:00
|
|
|
int idx = current_selected.get_slice("/", 0).to_int();
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
item_plugins[selected_idx]->erase(idx);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListEditor::_edit_items() {
|
|
|
|
|
2018-08-28 19:13:24 +02:00
|
|
|
dialog->popup_centered(Vector2(300, 400) * EDSCALE);
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void ItemListEditor::edit(Node *p_item_list) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
item_list = p_item_list;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
if (!item_list) {
|
2017-03-05 16:44:50 +01:00
|
|
|
selected_idx = -1;
|
2015-12-03 18:59:59 +01:00
|
|
|
property_editor->edit(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < item_plugins.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
if (item_plugins[i]->handles(p_item_list)) {
|
|
|
|
|
|
|
|
item_plugins[i]->set_object(p_item_list);
|
2015-12-03 18:59:59 +01:00
|
|
|
property_editor->edit(item_plugins[i]);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-09-02 23:40:51 +02:00
|
|
|
toolbar_button->set_icon(EditorNode::get_singleton()->get_object_icon(item_list, ""));
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selected_idx = i;
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selected_idx = -1;
|
2015-12-03 18:59:59 +01:00
|
|
|
property_editor->edit(NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemListEditor::handles(Object *p_object) const {
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < item_plugins.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
if (item_plugins[i]->handles(p_object)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-12-03 18:59:59 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void ItemListEditor::_bind_methods() {
|
|
|
|
|
2018-11-30 04:59:29 +01:00
|
|
|
ClassDB::bind_method("_node_removed", &ItemListEditor::_node_removed);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method("_edit_items", &ItemListEditor::_edit_items);
|
|
|
|
ClassDB::bind_method("_add_button", &ItemListEditor::_add_pressed);
|
|
|
|
ClassDB::bind_method("_delete_button", &ItemListEditor::_delete_pressed);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ItemListEditor::ItemListEditor() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selected_idx = -1;
|
2019-02-22 21:42:29 +01:00
|
|
|
item_list = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
toolbar_button = memnew(ToolButton);
|
2016-05-04 03:25:37 +02:00
|
|
|
toolbar_button->set_text(TTR("Items"));
|
2015-12-03 18:59:59 +01:00
|
|
|
add_child(toolbar_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
toolbar_button->connect("pressed", this, "_edit_items");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
dialog = memnew(AcceptDialog);
|
2016-05-04 03:25:37 +02:00
|
|
|
dialog->set_title(TTR("Item List Editor"));
|
2017-03-05 16:44:50 +01:00
|
|
|
add_child(dialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2015-12-03 18:59:59 +01:00
|
|
|
dialog->add_child(vbc);
|
2017-01-10 05:49:55 +01:00
|
|
|
//dialog->set_child_rect(vbc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2015-12-03 18:59:59 +01:00
|
|
|
hbc->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
vbc->add_child(hbc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
add_button = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
add_button->set_text(TTR("Add"));
|
2015-12-03 18:59:59 +01:00
|
|
|
hbc->add_child(add_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
add_button->connect("pressed", this, "_add_button");
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
hbc->add_spacer();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
del_button = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
del_button->set_text(TTR("Delete"));
|
2015-12-03 18:59:59 +01:00
|
|
|
hbc->add_child(del_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
del_button->connect("pressed", this, "_delete_button");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-09-11 15:53:50 +02:00
|
|
|
property_editor = memnew(EditorInspector);
|
2015-12-03 18:59:59 +01:00
|
|
|
vbc->add_child(property_editor);
|
|
|
|
property_editor->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
ItemListEditor::~ItemListEditor() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < item_plugins.size(); i++)
|
|
|
|
memdelete(item_plugins[i]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemListEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
item_list_editor->edit(Object::cast_to<Node>(p_object));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemListEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
|
|
|
return item_list_editor->handles(p_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemListEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
|
|
|
item_list_editor->show();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
item_list_editor->hide();
|
|
|
|
item_list_editor->edit(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemListEditorPlugin::ItemListEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor = p_node;
|
|
|
|
item_list_editor = memnew(ItemListEditor);
|
2015-12-03 18:59:59 +01:00
|
|
|
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(item_list_editor);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
item_list_editor->hide();
|
2017-03-05 16:44:50 +01:00
|
|
|
item_list_editor->add_plugin(memnew(ItemListOptionButtonPlugin));
|
|
|
|
item_list_editor->add_plugin(memnew(ItemListPopupMenuPlugin));
|
2017-07-04 13:38:56 +02:00
|
|
|
item_list_editor->add_plugin(memnew(ItemListItemListPlugin));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ItemListEditorPlugin::~ItemListEditorPlugin() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|