From 9986cf70058011fed81c8a2bba4df47e3e58b3ba Mon Sep 17 00:00:00 2001 From: hilfazer Date: Thu, 30 May 2019 20:16:40 +0200 Subject: editor save/delete layout dialog with layout list --- editor/editor_layouts_dialog.cpp | 138 ++++++++++++++++++++++++++++++++ editor/editor_layouts_dialog.h | 60 ++++++++++++++ editor/editor_name_dialog.cpp | 93 --------------------- editor/editor_name_dialog.h | 57 ------------- editor/editor_node.cpp | 6 +- editor/editor_node.h | 5 +- editor/plugins/tile_set_editor_plugin.h | 1 - 7 files changed, 205 insertions(+), 155 deletions(-) create mode 100644 editor/editor_layouts_dialog.cpp create mode 100644 editor/editor_layouts_dialog.h delete mode 100644 editor/editor_name_dialog.cpp delete mode 100644 editor/editor_name_dialog.h diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp new file mode 100644 index 0000000000..01e4762196 --- /dev/null +++ b/editor/editor_layouts_dialog.cpp @@ -0,0 +1,138 @@ +/*************************************************************************/ +/* editor_layouts_dialog.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ + +#include "editor_layouts_dialog.h" +#include "core/class_db.h" +#include "core/io/config_file.h" +#include "core/os/keyboard.h" +#include "editor/editor_settings.h" +#include "scene/gui/item_list.h" +#include "scene/gui/line_edit.h" + +void EditorLayoutsDialog::_line_gui_input(const Ref &p_event) { + Ref k = p_event; + + if (k.is_valid()) { + + if (!k->is_pressed()) + return; + + switch (k->get_scancode()) { + case KEY_KP_ENTER: + case KEY_ENTER: { + + if (get_hide_on_ok()) + hide(); + ok_pressed(); + accept_event(); + } break; + case KEY_ESCAPE: { + + hide(); + accept_event(); + } break; + } + } +} + +void EditorLayoutsDialog::_bind_methods() { + ClassDB::bind_method("_line_gui_input", &EditorLayoutsDialog::_line_gui_input); + + ADD_SIGNAL(MethodInfo("name_confirmed", PropertyInfo(Variant::STRING, "name"))); +} + +void EditorLayoutsDialog::ok_pressed() { + + if (layout_names->is_anything_selected()) { + + Vector const selected_items = layout_names->get_selected_items(); + for (int i = 0; i < selected_items.size(); ++i) { + + emit_signal("name_confirmed", layout_names->get_item_text(selected_items[i])); + } + } else if (name->is_visible() && name->get_text() != "") { + + emit_signal("name_confirmed", name->get_text()); + } +} + +void EditorLayoutsDialog::_post_popup() { + + ConfirmationDialog::_post_popup(); + name->clear(); + layout_names->clear(); + + Ref config; + config.instance(); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); + if (err != OK) { + + return; + } + + List layouts; + config.ptr()->get_sections(&layouts); + + for (List::Element *E = layouts.front(); E; E = E->next()) { + + layout_names->add_item(**E); + } +} + +EditorLayoutsDialog::EditorLayoutsDialog() { + + makevb = memnew(VBoxContainer); + add_child(makevb); + makevb->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5); + makevb->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5); + + layout_names = memnew(ItemList); + makevb->add_child(layout_names); + layout_names->set_visible(true); + layout_names->set_margin(MARGIN_TOP, 5); + layout_names->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5); + layout_names->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5); + layout_names->set_v_size_flags(Control::SIZE_EXPAND_FILL); + layout_names->set_select_mode(ItemList::SelectMode::SELECT_MULTI); + layout_names->set_allow_rmb_select(true); + + name = memnew(LineEdit); + makevb->add_child(name); + name->set_margin(MARGIN_TOP, 5); + name->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5); + name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5); + name->connect("gui_input", this, "_line_gui_input"); + name->connect("focus_entered", layout_names, "unselect_all"); +} + +void EditorLayoutsDialog::set_name_line_enabled(bool p_enabled) { + + name->set_visible(p_enabled); +} diff --git a/editor/editor_layouts_dialog.h b/editor/editor_layouts_dialog.h new file mode 100644 index 0000000000..5e3a1d5a46 --- /dev/null +++ b/editor/editor_layouts_dialog.h @@ -0,0 +1,60 @@ +/*************************************************************************/ +/* editor_layouts_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ + +#ifndef EDITOR_LAYOUTS_DIALOG_H +#define EDITOR_LAYOUTS_DIALOG_H + +#include "scene/gui/dialogs.h" + +class LineEdit; +class ItemList; + +class EditorLayoutsDialog : public ConfirmationDialog { + + GDCLASS(EditorLayoutsDialog, ConfirmationDialog); + + LineEdit *name; + ItemList *layout_names; + VBoxContainer *makevb; + + void _line_gui_input(const Ref &p_event); + +protected: + static void _bind_methods(); + virtual void ok_pressed(); + virtual void _post_popup(); + +public: + EditorLayoutsDialog(); + + void set_name_line_enabled(bool p_enabled); +}; + +#endif // EDITOR_LAYOUTS_DIALOG_H diff --git a/editor/editor_name_dialog.cpp b/editor/editor_name_dialog.cpp deleted file mode 100644 index 63a91a594c..0000000000 --- a/editor/editor_name_dialog.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************************/ -/* editor_name_dialog.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* 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. */ -/*************************************************************************/ - -#include "editor_name_dialog.h" - -#include "core/class_db.h" -#include "core/os/keyboard.h" - -void EditorNameDialog::_line_gui_input(const Ref &p_event) { - - Ref k = p_event; - - if (k.is_valid()) { - - if (!k->is_pressed()) - return; - - switch (k->get_scancode()) { - case KEY_KP_ENTER: - case KEY_ENTER: { - - if (get_hide_on_ok()) - hide(); - ok_pressed(); - accept_event(); - } break; - case KEY_ESCAPE: { - - hide(); - accept_event(); - } break; - } - } -} - -void EditorNameDialog::_post_popup() { - - ConfirmationDialog::_post_popup(); - name->clear(); - name->grab_focus(); -} - -void EditorNameDialog::ok_pressed() { - - if (name->get_text() != "") { - emit_signal("name_confirmed", name->get_text()); - } -} - -void EditorNameDialog::_bind_methods() { - - ClassDB::bind_method("_line_gui_input", &EditorNameDialog::_line_gui_input); - - ADD_SIGNAL(MethodInfo("name_confirmed", PropertyInfo(Variant::STRING, "name"))); -} - -EditorNameDialog::EditorNameDialog() { - makevb = memnew(VBoxContainer); - add_child(makevb); - name = memnew(LineEdit); - makevb->add_child(name); - name->set_margin(MARGIN_TOP, 5); - name->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5); - name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5); - name->connect("gui_input", this, "_line_gui_input"); -} diff --git a/editor/editor_name_dialog.h b/editor/editor_name_dialog.h deleted file mode 100644 index 314fc27124..0000000000 --- a/editor/editor_name_dialog.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************/ -/* editor_name_dialog.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* 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. */ -/*************************************************************************/ - -#ifndef EDITOR_NAME_DIALOG_H -#define EDITOR_NAME_DIALOG_H - -#include "scene/gui/dialogs.h" -#include "scene/gui/line_edit.h" - -class EditorNameDialog : public ConfirmationDialog { - - GDCLASS(EditorNameDialog, ConfirmationDialog); - - VBoxContainer *makevb; - LineEdit *name; - - void _line_gui_input(const Ref &p_event); - -protected: - static void _bind_methods(); - virtual void ok_pressed(); - virtual void _post_popup(); - -public: - LineEdit *get_line_edit() { return name; } - - EditorNameDialog(); -}; - -#endif // EDITOR_NAME_DIALOG_H diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 2d2f67314d..b441ba48c7 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4249,6 +4249,7 @@ void EditorNode::_layout_menu_option(int p_id) { layout_dialog->set_title(TTR("Save Layout")); layout_dialog->get_ok()->set_text(TTR("Save")); layout_dialog->popup_centered(); + layout_dialog->set_name_line_enabled(true); } break; case SETTINGS_LAYOUT_DELETE: { @@ -4256,6 +4257,7 @@ void EditorNode::_layout_menu_option(int p_id) { layout_dialog->set_title(TTR("Delete Layout")); layout_dialog->get_ok()->set_text(TTR("Delete")); layout_dialog->popup_centered(); + layout_dialog->set_name_line_enabled(false); } break; case SETTINGS_LAYOUT_DEFAULT: { @@ -6019,10 +6021,10 @@ EditorNode::EditorNode() { progress_hb = memnew(BackgroundProgress); - layout_dialog = memnew(EditorNameDialog); + layout_dialog = memnew(EditorLayoutsDialog); gui_base->add_child(layout_dialog); layout_dialog->set_hide_on_ok(false); - layout_dialog->set_size(Size2(175, 70) * EDSCALE); + layout_dialog->set_size(Size2(225, 270) * EDSCALE); layout_dialog->connect("name_confirmed", this, "_dialog_action"); update_menu = memnew(MenuButton); diff --git a/editor/editor_node.h b/editor/editor_node.h index f3bc95c409..40fdb856a7 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -41,8 +41,8 @@ #include "editor/editor_feature_profile.h" #include "editor/editor_folding.h" #include "editor/editor_inspector.h" +#include "editor/editor_layouts_dialog.h" #include "editor/editor_log.h" -#include "editor/editor_name_dialog.h" #include "editor/editor_plugin.h" #include "editor/editor_resource_preview.h" #include "editor/editor_run.h" @@ -85,6 +85,7 @@ #include "scene/gui/tool_button.h" #include "scene/gui/tree.h" #include "scene/gui/viewport_container.h" + /** @author Juan Linietsky */ @@ -307,7 +308,7 @@ private: int overridden_default_layout; Ref default_layout; PopupMenu *editor_layouts; - EditorNameDialog *layout_dialog; + EditorLayoutsDialog *layout_dialog; ConfirmationDialog *custom_build_manage_templates; ConfirmationDialog *install_android_build_template; diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index b417414ae0..04e8d65155 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -31,7 +31,6 @@ #ifndef TILE_SET_EDITOR_PLUGIN_H #define TILE_SET_EDITOR_PLUGIN_H -#include "editor/editor_name_dialog.h" #include "editor/editor_node.h" #include "scene/2d/sprite.h" #include "scene/resources/concave_polygon_shape_2d.h" -- cgit v1.2.3