diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2015-12-15 23:35:35 +0100 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2015-12-15 23:35:35 +0100 |
commit | d74c56289fe2801cd16e97787bd67dde32281a1d (patch) | |
tree | 4dd069e275bac22db098c7d1bda749951c07d5b3 /tools/editor | |
parent | 08cab3a17a4eba874c17cec41425f149846663a4 (diff) |
Fix Remove Item option in TileSet plugin
Diffstat (limited to 'tools/editor')
-rw-r--r-- | tools/editor/plugins/tile_set_editor_plugin.cpp | 47 | ||||
-rw-r--r-- | tools/editor/plugins/tile_set_editor_plugin.h | 7 |
2 files changed, 40 insertions, 14 deletions
diff --git a/tools/editor/plugins/tile_set_editor_plugin.cpp b/tools/editor/plugins/tile_set_editor_plugin.cpp index 09115472a8..b61fe6806b 100644 --- a/tools/editor/plugins/tile_set_editor_plugin.cpp +++ b/tools/editor/plugins/tile_set_editor_plugin.cpp @@ -145,10 +145,6 @@ void TileSetEditor::_menu_confirm() { switch(option) { - case MENU_OPTION_REMOVE_ITEM: { - - tileset->remove_tile(to_erase); - } break; case MENU_OPTION_MERGE_FROM_SCENE: case MENU_OPTION_CREATE_FROM_SCENE: { @@ -165,6 +161,27 @@ void TileSetEditor::_menu_confirm() { } } +void TileSetEditor::_name_dialog_confirm(const String& name) { + + switch (option) { + + case MENU_OPTION_REMOVE_ITEM: { + + int id=tileset->find_tile_by_name(name); + + if (id<0 && name.is_valid_integer()) + id=name.to_int(); + + if (tileset->has_tile(id)) { + tileset->remove_tile(id); + } else { + err_dialog->set_text("Could not find tile: " + name); + err_dialog->popup_centered(Size2(300, 60)); + } + } break; + } +} + void TileSetEditor::_menu_cbk(int p_option) { option=p_option; @@ -176,13 +193,9 @@ void TileSetEditor::_menu_cbk(int p_option) { } break; case MENU_OPTION_REMOVE_ITEM: { - String p = editor->get_property_editor()->get_selected_path(); - if (p.begins_with("/TileSet") && p.get_slice_count("/")>=2) { - - to_erase = p.get_slice("/",2).to_int(); - cd->set_text("Remove Item "+itos(to_erase)+"?"); - cd->popup_centered(Size2(300,60)); - } + nd->set_title("Remove Item"); + nd->set_text("Item name or ID:"); + nd->popup_centered(Size2(300, 95)); } break; case MENU_OPTION_CREATE_FROM_SCENE: { @@ -210,6 +223,7 @@ void TileSetEditor::_bind_methods() { ObjectTypeDB::bind_method("_menu_cbk",&TileSetEditor::_menu_cbk); ObjectTypeDB::bind_method("_menu_confirm",&TileSetEditor::_menu_confirm); + ObjectTypeDB::bind_method("_name_dialog_confirm",&TileSetEditor::_name_dialog_confirm); } TileSetEditor::TileSetEditor(EditorNode *p_editor) { @@ -222,7 +236,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { options->set_pos(Point2(1,1)); options->set_text("Theme"); options->get_popup()->add_item("Add Item",MENU_OPTION_ADD_ITEM); - options->get_popup()->add_item("Remove Selected Item",MENU_OPTION_REMOVE_ITEM); + options->get_popup()->add_item("Remove Item",MENU_OPTION_REMOVE_ITEM); options->get_popup()->add_separator(); options->get_popup()->add_item("Create from Scene",MENU_OPTION_CREATE_FROM_SCENE); options->get_popup()->add_item("Merge from Scene",MENU_OPTION_MERGE_FROM_SCENE); @@ -232,6 +246,15 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { add_child(cd); cd->get_ok()->connect("pressed", this,"_menu_confirm"); + nd = memnew(EditorNameDialog); + add_child(nd); + nd->set_hide_on_ok(true); + nd->get_line_edit()->set_margin(MARGIN_TOP,28); + nd->connect("name_confirmed", this,"_name_dialog_confirm"); + + err_dialog = memnew(AcceptDialog); + add_child(err_dialog); + err_dialog->set_title("Error"); } void TileSetEditorPlugin::edit(Object *p_node) { diff --git a/tools/editor/plugins/tile_set_editor_plugin.h b/tools/editor/plugins/tile_set_editor_plugin.h index df82df6993..0a646001ab 100644 --- a/tools/editor/plugins/tile_set_editor_plugin.h +++ b/tools/editor/plugins/tile_set_editor_plugin.h @@ -33,6 +33,7 @@ #include "scene/resources/tile_set.h" #include "tools/editor/editor_node.h" +#include "tools/editor/editor_name_dialog.h" class TileSetEditor : public Control { @@ -44,7 +45,8 @@ class TileSetEditor : public Control { EditorNode *editor; MenuButton *menu; ConfirmationDialog *cd; - int to_erase; + EditorNameDialog *nd; + AcceptDialog *err_dialog; enum { @@ -56,7 +58,8 @@ class TileSetEditor : public Control { int option; void _menu_cbk(int p_option); - void _menu_confirm(); + void _menu_confirm(); + void _name_dialog_confirm(const String& name); static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge); |