aboutsummaryrefslogtreecommitdiff
path: root/editor/plugins/item_list_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/item_list_editor_plugin.cpp')
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp185
1 files changed, 91 insertions, 94 deletions
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index f31074a9d..fabbf07a1 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -30,81 +30,81 @@
#include "io/resource_loader.h"
-bool ItemListPlugin::_set(const StringName& p_name, const Variant& p_value) {
+bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
- int idx = name.get_slice("/",0).to_int();
- String what=name.get_slice("/",1);
+ 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);
- else if (what=="checkable")
- set_item_checkable(idx,p_value);
- else if (what=="checked")
- 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);
+ if (what == "text")
+ set_item_text(idx, p_value);
+ else if (what == "icon")
+ set_item_icon(idx, p_value);
+ else if (what == "checkable")
+ set_item_checkable(idx, p_value);
+ else if (what == "checked")
+ 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);
else
return false;
return true;
}
-bool ItemListPlugin::_get(const StringName& p_name,Variant &r_ret) const {
+bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
- int idx = name.get_slice("/",0).to_int();
- String what=name.get_slice("/",1);
+ 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);
- else if (what=="checkable")
- r_ret=is_item_checkable(idx);
- else if (what=="checked")
- 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);
+ if (what == "text")
+ r_ret = get_item_text(idx);
+ else if (what == "icon")
+ r_ret = get_item_icon(idx);
+ else if (what == "checkable")
+ r_ret = is_item_checkable(idx);
+ else if (what == "checked")
+ 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);
else
return false;
return true;
}
-void ItemListPlugin::_get_property_list( List<PropertyInfo> *p_list) const {
+void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
- for(int i=0;i<get_item_count();i++) {
+ for (int i = 0; i < get_item_count(); i++) {
- String base=itos(i)+"/";
+ String base = itos(i) + "/";
- p_list->push_back( PropertyInfo(Variant::STRING,base+"text") );
- p_list->push_back( PropertyInfo(Variant::OBJECT,base+"icon",PROPERTY_HINT_RESOURCE_TYPE,"Texture") );
+ p_list->push_back(PropertyInfo(Variant::STRING, base + "text"));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
int flags = get_flags();
- if (flags&FLAG_CHECKABLE) {
- p_list->push_back( PropertyInfo(Variant::BOOL,base+"checkable") );
- p_list->push_back( PropertyInfo(Variant::BOOL,base+"checked") );
+ if (flags & FLAG_CHECKABLE) {
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "checkable"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked"));
}
- if (flags&FLAG_ID)
- p_list->push_back( PropertyInfo(Variant::INT,base+"id",PROPERTY_HINT_RANGE,"-1,4096") );
+ if (flags & FLAG_ID)
+ p_list->push_back(PropertyInfo(Variant::INT, base + "id", PROPERTY_HINT_RANGE, "-1,4096"));
- if (flags&FLAG_ENABLE)
- p_list->push_back( PropertyInfo(Variant::BOOL,base+"enabled") );
+ if (flags & FLAG_ENABLE)
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "enabled"));
- if (flags&FLAG_SEPARATOR)
- p_list->push_back( PropertyInfo(Variant::BOOL,base+"separator") );
+ if (flags & FLAG_SEPARATOR)
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "separator"));
}
}
@@ -124,12 +124,12 @@ bool ItemListOptionButtonPlugin::handles(Object *p_object) const {
int ItemListOptionButtonPlugin::get_flags() const {
- return FLAG_ICON|FLAG_ID|FLAG_ENABLE;
+ return FLAG_ICON | FLAG_ID | FLAG_ENABLE;
}
void ItemListOptionButtonPlugin::add_item() {
- ob->add_item( vformat(TTR("Item %d"),ob->get_item_count()));
+ ob->add_item(vformat(TTR("Item %d"), ob->get_item_count()));
_change_notify();
}
@@ -146,7 +146,7 @@ void ItemListOptionButtonPlugin::erase(int p_idx) {
ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() {
- ob=NULL;
+ ob = NULL;
}
///////////////////////////////////////////////////////////////
@@ -166,12 +166,12 @@ bool ItemListPopupMenuPlugin::handles(Object *p_object) const {
int ItemListPopupMenuPlugin::get_flags() const {
- return FLAG_ICON|FLAG_CHECKABLE|FLAG_ID|FLAG_ENABLE|FLAG_SEPARATOR;
+ return FLAG_ICON | FLAG_CHECKABLE | FLAG_ID | FLAG_ENABLE | FLAG_SEPARATOR;
}
void ItemListPopupMenuPlugin::add_item() {
- pp->add_item( vformat(TTR("Item %d"),pp->get_item_count()));
+ pp->add_item(vformat(TTR("Item %d"), pp->get_item_count()));
_change_notify();
}
@@ -188,7 +188,7 @@ void ItemListPopupMenuPlugin::erase(int p_idx) {
ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
- pp=NULL;
+ pp = NULL;
}
///////////////////////////////////////////////////////////////
@@ -197,8 +197,8 @@ ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
void ItemListEditor::_node_removed(Node *p_node) {
- if(p_node==item_list) {
- item_list=NULL;
+ if (p_node == item_list) {
+ item_list = NULL;
hide();
dialog->hide();
}
@@ -206,16 +206,16 @@ void ItemListEditor::_node_removed(Node *p_node) {
void ItemListEditor::_notification(int p_notification) {
- if (p_notification==NOTIFICATION_ENTER_TREE) {
+ if (p_notification == NOTIFICATION_ENTER_TREE) {
- add_button->set_icon(get_icon("Add","EditorIcons"));
- del_button->set_icon(get_icon("Remove","EditorIcons"));
+ add_button->set_icon(get_icon("Add", "EditorIcons"));
+ del_button->set_icon(get_icon("Remove", "EditorIcons"));
}
}
void ItemListEditor::_add_pressed() {
- if (selected_idx==-1)
+ if (selected_idx == -1)
return;
item_plugins[selected_idx]->add_item();
@@ -228,12 +228,12 @@ void ItemListEditor::_delete_pressed() {
if (!ti)
return;
- if (ti->get_parent()!=tree->get_root())
+ if (ti->get_parent() != tree->get_root())
return;
int idx = ti->get_text(0).to_int();
- if (selected_idx==-1)
+ if (selected_idx == -1)
return;
item_plugins[selected_idx]->erase(idx);
@@ -246,15 +246,15 @@ void ItemListEditor::_edit_items() {
void ItemListEditor::edit(Node *p_item_list) {
- item_list=p_item_list;
+ item_list = p_item_list;
if (!item_list) {
- selected_idx=-1;
+ selected_idx = -1;
property_editor->edit(NULL);
return;
}
- for(int i=0;i<item_plugins.size();i++) {
+ for (int i = 0; i < item_plugins.size(); i++) {
if (item_plugins[i]->handles(p_item_list)) {
item_plugins[i]->set_object(p_item_list);
@@ -265,18 +265,18 @@ void ItemListEditor::edit(Node *p_item_list) {
else
toolbar_button->set_icon(Ref<Texture>());
- selected_idx=i;
+ selected_idx = i;
return;
}
}
- selected_idx=-1;
+ selected_idx = -1;
property_editor->edit(NULL);
}
bool ItemListEditor::handles(Object *p_object) const {
- for(int i=0;i<item_plugins.size();i++) {
+ for (int i = 0; i < item_plugins.size(); i++) {
if (item_plugins[i]->handles(p_object)) {
return true;
}
@@ -287,47 +287,47 @@ bool ItemListEditor::handles(Object *p_object) const {
void ItemListEditor::_bind_methods() {
- ClassDB::bind_method("_edit_items",&ItemListEditor::_edit_items);
- ClassDB::bind_method("_add_button",&ItemListEditor::_add_pressed);
- ClassDB::bind_method("_delete_button",&ItemListEditor::_delete_pressed);
+ ClassDB::bind_method("_edit_items", &ItemListEditor::_edit_items);
+ ClassDB::bind_method("_add_button", &ItemListEditor::_add_pressed);
+ ClassDB::bind_method("_delete_button", &ItemListEditor::_delete_pressed);
}
ItemListEditor::ItemListEditor() {
- selected_idx=-1;
+ selected_idx = -1;
- add_child( memnew( VSeparator ) );
+ add_child(memnew(VSeparator));
- toolbar_button = memnew( ToolButton );
+ toolbar_button = memnew(ToolButton);
toolbar_button->set_text(TTR("Items"));
add_child(toolbar_button);
- toolbar_button->connect("pressed",this,"_edit_items");
+ toolbar_button->connect("pressed", this, "_edit_items");
- dialog = memnew( AcceptDialog );
+ dialog = memnew(AcceptDialog);
dialog->set_title(TTR("Item List Editor"));
- add_child( dialog );
+ add_child(dialog);
- VBoxContainer *vbc = memnew( VBoxContainer );
+ VBoxContainer *vbc = memnew(VBoxContainer);
dialog->add_child(vbc);
//dialog->set_child_rect(vbc);
- HBoxContainer *hbc = memnew( HBoxContainer );
+ HBoxContainer *hbc = memnew(HBoxContainer);
hbc->set_h_size_flags(SIZE_EXPAND_FILL);
vbc->add_child(hbc);
- add_button = memnew( Button );
+ add_button = memnew(Button);
add_button->set_text(TTR("Add"));
hbc->add_child(add_button);
- add_button->connect("pressed",this,"_add_button");
+ add_button->connect("pressed", this, "_add_button");
hbc->add_spacer();
- del_button = memnew( Button );
+ del_button = memnew(Button);
del_button->set_text(TTR("Delete"));
hbc->add_child(del_button);
- del_button->connect("pressed",this,"_delete_button");
+ del_button->connect("pressed", this, "_delete_button");
- property_editor = memnew( PropertyEditor );
+ property_editor = memnew(PropertyEditor);
property_editor->hide_top_label();
property_editor->set_subsection_selectable(true);
vbc->add_child(property_editor);
@@ -338,8 +338,8 @@ ItemListEditor::ItemListEditor() {
ItemListEditor::~ItemListEditor() {
- for(int i=0;i<item_plugins.size();i++)
- memdelete( item_plugins[i] );
+ for (int i = 0; i < item_plugins.size(); i++)
+ memdelete(item_plugins[i]);
}
void ItemListEditorPlugin::edit(Object *p_object) {
@@ -365,17 +365,14 @@ void ItemListEditorPlugin::make_visible(bool p_visible) {
ItemListEditorPlugin::ItemListEditorPlugin(EditorNode *p_node) {
- editor=p_node;
- item_list_editor = memnew( ItemListEditor );
+ editor = p_node;
+ item_list_editor = memnew(ItemListEditor);
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(item_list_editor);
item_list_editor->hide();
- item_list_editor->add_plugin( memnew( ItemListOptionButtonPlugin ) );
- item_list_editor->add_plugin( memnew( ItemListPopupMenuPlugin ) );
+ item_list_editor->add_plugin(memnew(ItemListOptionButtonPlugin));
+ item_list_editor->add_plugin(memnew(ItemListPopupMenuPlugin));
}
-ItemListEditorPlugin::~ItemListEditorPlugin()
-{
+ItemListEditorPlugin::~ItemListEditorPlugin() {
}
-
-