summaryrefslogtreecommitdiff
path: root/editor/inspector_dock.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-09-16 11:01:46 +0200
committerGitHub <noreply@github.com>2021-09-16 11:01:46 +0200
commita124087a88a754893d2839496e54ca2a86c6fb2d (patch)
tree9eae2900a3703d5aefc2eefcebb6c1f7a54ecb1f /editor/inspector_dock.cpp
parentf24a98024df84023936de9c7a0c7b787c76c6294 (diff)
parent7249d2555bae1220b75044ec4582dee3dcb861c2 (diff)
Merge pull request #41949 from EricEzaM/PR/inspector-sub-resources-unique-confirm
Added confirmation dialog for making sub-resources unique.
Diffstat (limited to 'editor/inspector_dock.cpp')
-rw-r--r--editor/inspector_dock.cpp128
1 files changed, 102 insertions, 26 deletions
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp
index 778046f45c..04ddf3552b 100644
--- a/editor/inspector_dock.cpp
+++ b/editor/inspector_dock.cpp
@@ -30,11 +30,22 @@
#include "inspector_dock.h"
-#include "editor/editor_node.h"
-#include "editor/editor_settings.h"
+#include "editor/editor_scale.h"
#include "editor/plugins/animation_player_editor_plugin.h"
void InspectorDock::_menu_option(int p_option) {
+ _menu_option_confirm(p_option, false);
+}
+
+void InspectorDock::_menu_confirm_current() {
+ _menu_option_confirm(current_option, true);
+}
+
+void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) {
+ if (!p_confirmed) {
+ current_option = p_option;
+ }
+
switch (p_option) {
case EXPAND_ALL: {
_menu_expandall();
@@ -82,39 +93,81 @@ void InspectorDock::_menu_option(int p_option) {
} break;
case OBJECT_UNIQUE_RESOURCES: {
- editor_data->apply_changes_in_editors();
- if (current) {
- List<PropertyInfo> props;
- current->get_property_list(&props);
- Map<RES, RES> duplicates;
- for (const PropertyInfo &E : props) {
- if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
- continue;
- }
+ if (!p_confirmed) {
+ Vector<String> resource_propnames;
- Variant v = current->get(E.name);
- if (v.is_ref()) {
+ if (current) {
+ List<PropertyInfo> props;
+ current->get_property_list(&props);
+
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
+ continue;
+ }
+
+ Variant v = current->get(E->get().name);
REF ref = v;
- if (ref.is_valid()) {
- RES res = ref;
- if (res.is_valid()) {
- if (!duplicates.has(res)) {
- duplicates[res] = res->duplicate();
- }
- res = duplicates[res];
+ RES res = ref;
+ if (v.is_ref() && ref.is_valid() && res.is_valid()) {
+ // Valid resource which would be duplicated if action is confirmed.
+ resource_propnames.append(E->get().name);
+ }
+ }
+ }
+
+ if (resource_propnames.size()) {
+ unique_resources_list_tree->clear();
+ TreeItem *root = unique_resources_list_tree->create_item();
- current->set(E.name, res);
- editor->get_inspector()->update_property(E.name);
+ for (int i = 0; i < resource_propnames.size(); i++) {
+ String propname = resource_propnames[i].replace("/", " / ");
+
+ TreeItem *ti = unique_resources_list_tree->create_item(root);
+ ti->set_text(0, bool(EDITOR_GET("interface/inspector/capitalize_properties")) ? propname.capitalize() : propname);
+ }
+
+ unique_resources_confirmation->popup_centered();
+ } else {
+ unique_resources_confirmation->set_text(TTR("This object has no resources."));
+ current_option = -1;
+ unique_resources_confirmation->popup_centered();
+ }
+ } else {
+ editor_data->apply_changes_in_editors();
+
+ if (current) {
+ List<PropertyInfo> props;
+ current->get_property_list(&props);
+ Map<RES, RES> duplicates;
+ for (const PropertyInfo &prop_info : props) {
+ if (!(prop_info.usage & PROPERTY_USAGE_STORAGE)) {
+ continue;
+ }
+
+ Variant v = current->get(prop_info.name);
+ if (v.is_ref()) {
+ REF ref = v;
+ if (ref.is_valid()) {
+ RES res = ref;
+ if (res.is_valid()) {
+ if (!duplicates.has(res)) {
+ duplicates[res] = res->duplicate();
+ }
+ res = duplicates[res];
+
+ current->set(prop_info.name, res);
+ editor->get_inspector()->update_property(prop_info.name);
+ }
}
}
}
}
- }
- editor_data->get_undo_redo().clear_history();
+ editor_data->get_undo_redo().clear_history();
- editor->get_editor_plugins_over()->edit(nullptr);
- editor->get_editor_plugins_over()->edit(current);
+ editor->get_editor_plugins_over()->edit(nullptr);
+ editor->get_editor_plugins_over()->edit(current);
+ }
} break;
@@ -619,6 +672,29 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
warning->hide();
warning->connect("pressed", callable_mp(this, &InspectorDock::_warning_pressed));
+ unique_resources_confirmation = memnew(ConfirmationDialog);
+ add_child(unique_resources_confirmation);
+
+ VBoxContainer *container = memnew(VBoxContainer);
+ unique_resources_confirmation->add_child(container);
+
+ Label *top_label = memnew(Label);
+ top_label->set_text(TTR("The following resources will be duplicated and embedded within this resource/object."));
+ container->add_child(top_label);
+
+ unique_resources_list_tree = memnew(Tree);
+ unique_resources_list_tree->set_hide_root(true);
+ unique_resources_list_tree->set_columns(1);
+ unique_resources_list_tree->set_column_title(0, TTR("Property"));
+ unique_resources_list_tree->set_custom_minimum_size(Size2(0, 200 * EDSCALE));
+ container->add_child(unique_resources_list_tree);
+
+ Label *bottom_label = memnew(Label);
+ bottom_label->set_text(TTR("This cannot be undone. Are you sure?"));
+ container->add_child(bottom_label);
+
+ unique_resources_confirmation->connect("confirmed", callable_mp(this, &InspectorDock::_menu_confirm_current));
+
warning_dialog = memnew(AcceptDialog);
editor->get_gui_base()->add_child(warning_dialog);