diff options
Diffstat (limited to 'editor/inspector_dock.cpp')
-rw-r--r-- | editor/inspector_dock.cpp | 168 |
1 files changed, 78 insertions, 90 deletions
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 5622d0b145..f0fe48f4fc 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 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 */ @@ -30,8 +30,19 @@ #include "inspector_dock.h" +#include "editor/editor_file_dialog.h" +#include "editor/editor_node.h" #include "editor/editor_scale.h" -#include "editor/plugins/animation_player_editor_plugin.h" +#include "editor/plugins/script_editor_plugin.h" + +InspectorDock *InspectorDock::singleton = nullptr; + +void InspectorDock::_prepare_menu() { + PopupMenu *menu = object_menu->get_popup(); + for (int i = EditorPropertyNameProcessor::STYLE_RAW; i <= EditorPropertyNameProcessor::STYLE_LOCALIZED; i++) { + menu->set_item_checked(menu->get_item_index(PROPERTY_NAME_STYLE_RAW + i), i == property_name_style); + } +} void InspectorDock::_menu_option(int p_option) { _menu_option_confirm(p_option, false); @@ -73,7 +84,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { case OBJECT_REQUEST_HELP: { if (current) { - editor->set_visible_editor(EditorNode::EDITOR_SCRIPT); + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); emit_signal(SNAME("request_help"), current->get_class()); } } break; @@ -108,7 +119,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { Variant v = current->get(E->get().name); REF ref = v; RES res = ref; - if (v.is_ref() && ref.is_valid() && res.is_valid()) { + if (v.is_ref_counted() && ref.is_valid() && res.is_valid()) { // Valid resource which would be duplicated if action is confirmed. resource_propnames.append(E->get().name); } @@ -145,7 +156,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { } Variant v = current->get(prop_info.name); - if (v.is_ref()) { + if (v.is_ref_counted()) { REF ref = v; if (ref.is_valid()) { RES res = ref; @@ -156,7 +167,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { res = duplicates[res]; current->set(prop_info.name, res); - editor->get_inspector()->update_property(prop_info.name); + get_inspector_singleton()->update_property(prop_info.name); } } } @@ -165,12 +176,19 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { editor_data->get_undo_redo().clear_history(); - editor->get_editor_plugins_over()->edit(nullptr); - editor->get_editor_plugins_over()->edit(current); + EditorNode::get_singleton()->get_editor_plugins_over()->edit(nullptr); + EditorNode::get_singleton()->get_editor_plugins_over()->edit(current); } } break; + case PROPERTY_NAME_STYLE_RAW: + case PROPERTY_NAME_STYLE_CAPITALIZED: + case PROPERTY_NAME_STYLE_LOCALIZED: { + property_name_style = (EditorPropertyNameProcessor::Style)(p_option - PROPERTY_NAME_STYLE_RAW); + inspector->set_property_name_style(property_name_style); + } break; + default: { if (p_option >= OBJECT_METHOD_BASE) { ERR_FAIL_COND(!current); @@ -228,11 +246,11 @@ void InspectorDock::_resource_file_selected(String p_file) { return; }; - editor->push_item(res.operator->()); + EditorNode::get_singleton()->push_item(res.operator->()); } void InspectorDock::_save_resource(bool save_as) { - ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current(); + ObjectID current = EditorNode::get_singleton()->get_editor_selection_history()->get_current(); Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr; ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj)); @@ -240,25 +258,25 @@ void InspectorDock::_save_resource(bool save_as) { RES current_res = RES(Object::cast_to<Resource>(current_obj)); if (save_as) { - editor->save_resource_as(current_res); + EditorNode::get_singleton()->save_resource_as(current_res); } else { - editor->save_resource(current_res); + EditorNode::get_singleton()->save_resource(current_res); } } void InspectorDock::_unref_resource() { - ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current(); + ObjectID current = EditorNode::get_singleton()->get_editor_selection_history()->get_current(); Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr; ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj)); RES current_res = RES(Object::cast_to<Resource>(current_obj)); current_res->set_path(""); - editor->edit_current(); + EditorNode::get_singleton()->edit_current(); } void InspectorDock::_copy_resource() { - ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current(); + ObjectID current = EditorNode::get_singleton()->get_editor_selection_history()->get_current(); Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr; ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj)); @@ -271,7 +289,7 @@ void InspectorDock::_copy_resource() { void InspectorDock::_paste_resource() { RES r = EditorSettings::get_singleton()->get_resource_clipboard(); if (r.is_valid()) { - editor->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String()); + EditorNode::get_singleton()->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String()); } } @@ -282,7 +300,7 @@ void InspectorDock::_prepare_resource_extra_popup() { } void InspectorDock::_prepare_history() { - EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); + EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); int history_to = MAX(0, editor_history->get_history_len() - 25); @@ -312,7 +330,7 @@ void InspectorDock::_prepare_history() { Resource *r = Object::cast_to<Resource>(obj); if (r->get_path().is_resource_file()) { text = r->get_path().get_file(); - } else if (r->get_name() != String()) { + } else if (!r->get_name().is_empty()) { text = r->get_name(); } else { text = r->get_class(); @@ -334,12 +352,12 @@ void InspectorDock::_prepare_history() { void InspectorDock::_select_history(int p_idx) { //push it to the top, it is not correct, but it's more useful - ObjectID id = EditorNode::get_singleton()->get_editor_history()->get_history_obj(p_idx); + ObjectID id = EditorNode::get_singleton()->get_editor_selection_history()->get_history_obj(p_idx); Object *obj = ObjectDB::get_instance(id); if (!obj) { return; } - editor->push_item(obj); + EditorNode::get_singleton()->push_item(obj); } void InspectorDock::_resource_created() { @@ -349,7 +367,7 @@ void InspectorDock::_resource_created() { Resource *r = Object::cast_to<Resource>(c); ERR_FAIL_COND(!r); - editor->push_item(r); + EditorNode::get_singleton()->push_item(r); } void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) { @@ -358,19 +376,19 @@ void InspectorDock::_resource_selected(const RES &p_res, const String &p_propert } RES r = p_res; - editor->push_item(r.operator->(), p_property); + EditorNode::get_singleton()->push_item(r.operator->(), p_property); } void InspectorDock::_edit_forward() { - if (EditorNode::get_singleton()->get_editor_history()->next()) { - editor->edit_current(); + if (EditorNode::get_singleton()->get_editor_selection_history()->next()) { + EditorNode::get_singleton()->edit_current(); } } void InspectorDock::_edit_back() { - EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); + EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) { - editor->edit_current(); + EditorNode::get_singleton()->edit_current(); } } @@ -382,20 +400,6 @@ void InspectorDock::_menu_expandall() { inspector->expand_all_folding(); } -void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance) { - AnimationPlayerEditor::get_singleton()->get_track_editor()->insert_value_key(p_keyed, p_value, p_advance); -} - -void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform3D &p_key) { - Node3D *s = Object::cast_to<Node3D>(sp); - if (!s) { - return; - } - AnimationPlayerEditor::get_singleton()->get_track_editor()->insert_transform_key(s, p_sub, Animation::TYPE_POSITION_3D, p_key.origin); - AnimationPlayerEditor::get_singleton()->get_track_editor()->insert_transform_key(s, p_sub, Animation::TYPE_ROTATION_3D, p_key.basis.get_rotation_quaternion()); - AnimationPlayerEditor::get_singleton()->get_track_editor()->insert_transform_key(s, p_sub, Animation::TYPE_SCALE_3D, p_key.basis.get_scale()); -} - void InspectorDock::_warning_pressed() { warning_dialog->popup_centered(); } @@ -406,15 +410,17 @@ Container *InspectorDock::get_addon_area() { void InspectorDock::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - set_theme(editor->get_gui_base()->get_theme()); + set_theme(EditorNode::get_singleton()->get_gui_base()->get_theme()); resource_new_button->set_icon(get_theme_icon(SNAME("New"), SNAME("EditorIcons"))); resource_load_button->set_icon(get_theme_icon(SNAME("Load"), SNAME("EditorIcons"))); resource_save_button->set_icon(get_theme_icon(SNAME("Save"), SNAME("EditorIcons"))); resource_extra_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + open_docs_button->set_icon(get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons"))); PopupMenu *resource_extra_popup = resource_extra_button->get_popup(); resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_theme_icon(SNAME("ActionPaste"), SNAME("EditorIcons"))); @@ -430,6 +436,7 @@ void InspectorDock::_notification(int p_what) { history_menu->set_icon(get_theme_icon(SNAME("History"), SNAME("EditorIcons"))); object_menu->set_icon(get_theme_icon(SNAME("Tools"), SNAME("EditorIcons"))); + search->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); warning->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons"))); warning->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); } break; @@ -437,9 +444,6 @@ void InspectorDock::_notification(int p_what) { } void InspectorDock::_bind_methods() { - ClassDB::bind_method("update_keying", &InspectorDock::update_keying); - ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed); // Still used by some connect_compat. - ClassDB::bind_method("_unref_resource", &InspectorDock::_unref_resource); ClassDB::bind_method("_paste_resource", &InspectorDock::_paste_resource); ClassDB::bind_method("_copy_resource", &InspectorDock::_copy_resource); @@ -447,6 +451,8 @@ void InspectorDock::_bind_methods() { ClassDB::bind_method("_menu_collapseall", &InspectorDock::_menu_collapseall); ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall); + ClassDB::bind_method("edit_resource", &InspectorDock::edit_resource); + ADD_SIGNAL(MethodInfo("request_help")); } @@ -460,7 +466,7 @@ void InspectorDock::open_resource(const String &p_type) { void InspectorDock::set_warning(const String &p_message) { warning->hide(); - if (p_message != String()) { + if (!p_message.is_empty()) { warning->show(); warning_dialog->set_text(p_message); } @@ -470,7 +476,7 @@ void InspectorDock::clear() { } void InspectorDock::update(Object *p_object) { - EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); + EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); backward_button->set_disabled(editor_history->is_at_beginning()); forward_button->set_disabled(editor_history->is_at_end()); @@ -509,8 +515,19 @@ void InspectorDock::update(Object *p_object) { p->clear(); p->add_icon_shortcut(get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/expand_all", TTR("Expand All")), EXPAND_ALL); p->add_icon_shortcut(get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All")), COLLAPSE_ALL); - p->add_separator(); + p->add_separator(TTR("Property Name Style")); + p->add_radio_check_item(TTR("Raw"), PROPERTY_NAME_STYLE_RAW); + p->add_radio_check_item(TTR("Capitalized"), PROPERTY_NAME_STYLE_CAPITALIZED); + p->add_radio_check_item(TTR("Localized"), PROPERTY_NAME_STYLE_LOCALIZED); + + if (!EditorPropertyNameProcessor::is_localization_available()) { + const int index = p->get_item_index(PROPERTY_NAME_STYLE_LOCALIZED); + p->set_item_disabled(index, true); + p->set_item_tooltip(index, TTR("Localization not available for current language.")); + } + + p->add_separator(); p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Properties")), OBJECT_COPY_PARAMS); p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Properties")), OBJECT_PASTE_PARAMS); @@ -544,36 +561,24 @@ void InspectorDock::go_back() { _edit_back(); } -void InspectorDock::update_keying() { - bool valid = false; - - if (AnimationPlayerEditor::get_singleton()->get_track_editor()->has_keying()) { - EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); - if (editor_history->get_path_size() >= 1) { - Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0)); - if (Object::cast_to<Node>(obj)) { - valid = true; - } - } - } - - inspector->set_keying(valid); +EditorPropertyNameProcessor::Style InspectorDock::get_property_name_style() const { + return property_name_style; } -InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { +InspectorDock::InspectorDock(EditorData &p_editor_data) { + singleton = this; set_name("Inspector"); - set_theme(p_editor->get_gui_base()->get_theme()); - editor = p_editor; editor_data = &p_editor_data; + property_name_style = EditorPropertyNameProcessor::get_default_inspector_style(); + HBoxContainer *general_options_hb = memnew(HBoxContainer); add_child(general_options_hb); resource_new_button = memnew(Button); resource_new_button->set_flat(true); resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it.")); - resource_new_button->set_icon(get_theme_icon(SNAME("New"), SNAME("EditorIcons"))); general_options_hb->add_child(resource_new_button); resource_new_button->connect("pressed", callable_mp(this, &InspectorDock::_new_resource)); resource_new_button->set_focus_mode(Control::FOCUS_NONE); @@ -581,14 +586,12 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { resource_load_button = memnew(Button); resource_load_button->set_flat(true); resource_load_button->set_tooltip(TTR("Load an existing resource from disk and edit it.")); - resource_load_button->set_icon(get_theme_icon(SNAME("Load"), SNAME("EditorIcons"))); general_options_hb->add_child(resource_load_button); resource_load_button->connect("pressed", callable_mp(this, &InspectorDock::_open_resource_selector)); resource_load_button->set_focus_mode(Control::FOCUS_NONE); resource_save_button = memnew(MenuButton); resource_save_button->set_tooltip(TTR("Save the currently edited resource.")); - resource_save_button->set_icon(get_theme_icon(SNAME("Save"), SNAME("EditorIcons"))); general_options_hb->add_child(resource_save_button); resource_save_button->get_popup()->add_item(TTR("Save"), RESOURCE_SAVE); resource_save_button->get_popup()->add_item(TTR("Save As..."), RESOURCE_SAVE_AS); @@ -597,7 +600,6 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { resource_save_button->set_disabled(true); resource_extra_button = memnew(MenuButton); - resource_extra_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); resource_extra_button->set_tooltip(TTR("Extra resource options.")); general_options_hb->add_child(resource_extra_button); resource_extra_button->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_resource_extra_popup)); @@ -614,11 +616,6 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { backward_button = memnew(Button); backward_button->set_flat(true); general_options_hb->add_child(backward_button); - if (is_layout_rtl()) { - backward_button->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); - } else { - backward_button->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); - } backward_button->set_tooltip(TTR("Go to the previous edited object in history.")); backward_button->set_disabled(true); backward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_back)); @@ -626,25 +623,19 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { forward_button = memnew(Button); forward_button->set_flat(true); general_options_hb->add_child(forward_button); - if (is_layout_rtl()) { - forward_button->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); - } else { - forward_button->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); - } forward_button->set_tooltip(TTR("Go to the next edited object in history.")); forward_button->set_disabled(true); forward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_forward)); history_menu = memnew(MenuButton); history_menu->set_tooltip(TTR("History of recently edited objects.")); - history_menu->set_icon(get_theme_icon(SNAME("History"), SNAME("EditorIcons"))); general_options_hb->add_child(history_menu); history_menu->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_history)); history_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_select_history)); HBoxContainer *subresource_hb = memnew(HBoxContainer); add_child(subresource_hb); - editor_path = memnew(EditorPath(editor->get_editor_history())); + editor_path = memnew(EditorPath(EditorNode::get_singleton()->get_editor_selection_history())); editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL); subresource_hb->add_child(editor_path); @@ -652,13 +643,12 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { open_docs_button->set_flat(true); open_docs_button->set_disabled(true); open_docs_button->set_tooltip(TTR("Open documentation for this object.")); - open_docs_button->set_icon(get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons"))); open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation"))); subresource_hb->add_child(open_docs_button); open_docs_button->connect("pressed", callable_mp(this, &InspectorDock::_menu_option), varray(OBJECT_REQUEST_HELP)); new_resource_dialog = memnew(CreateDialog); - editor->get_gui_base()->add_child(new_resource_dialog); + EditorNode::get_singleton()->get_gui_base()->add_child(new_resource_dialog); new_resource_dialog->set_base_type("Resource"); new_resource_dialog->connect("create", callable_mp(this, &InspectorDock::_resource_created)); @@ -668,22 +658,19 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { search = memnew(LineEdit); search->set_h_size_flags(Control::SIZE_EXPAND_FILL); search->set_placeholder(TTR("Filter properties")); - search->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); search->set_clear_button_enabled(true); property_tools_hb->add_child(search); object_menu = memnew(MenuButton); object_menu->set_shortcut_context(this); - object_menu->set_icon(get_theme_icon(SNAME("Tools"), SNAME("EditorIcons"))); property_tools_hb->add_child(object_menu); object_menu->set_tooltip(TTR("Manage object properties.")); + object_menu->get_popup()->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_menu)); object_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option)); warning = memnew(Button); add_child(warning); warning->set_text(TTR("Changes may be lost!")); - warning->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons"))); - warning->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); warning->set_clip_text(true); warning->hide(); warning->connect("pressed", callable_mp(this, &InspectorDock::_warning_pressed)); @@ -712,7 +699,7 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { unique_resources_confirmation->connect("confirmed", callable_mp(this, &InspectorDock::_menu_confirm_current)); warning_dialog = memnew(AcceptDialog); - editor->get_gui_base()->add_child(warning_dialog); + EditorNode::get_singleton()->get_gui_base()->add_child(warning_dialog); load_resource_dialog = memnew(EditorFileDialog); add_child(load_resource_dialog); @@ -726,7 +713,8 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL); inspector->set_use_doc_hints(true); inspector->set_hide_script(false); - inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties"))); + inspector->set_hide_metadata(false); + inspector->set_property_name_style(EditorPropertyNameProcessor::get_default_inspector_style()); inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding"))); inspector->register_text_enter(search); inspector->set_undo_redo(&editor_data->get_undo_redo()); @@ -734,8 +722,8 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { inspector->set_use_filter(true); // TODO: check me inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected)); - inspector->connect("property_keyed", callable_mp(this, &InspectorDock::_property_keyed)); } InspectorDock::~InspectorDock() { + singleton = nullptr; } |