diff options
Diffstat (limited to 'editor/inspector_dock.cpp')
-rw-r--r-- | editor/inspector_dock.cpp | 172 |
1 files changed, 82 insertions, 90 deletions
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index b65482cc6b..8f1b8838d8 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -68,15 +68,16 @@ void InspectorDock::_menu_option(int p_option) { case OBJECT_COPY_PARAMS: { editor_data->apply_changes_in_editors(); - if (current) + if (current) { editor_data->copy_object_params(current); + } } break; case OBJECT_PASTE_PARAMS: { editor_data->apply_changes_in_editors(); - if (current) + if (current) { editor_data->paste_object_params(current); - editor_data->get_undo_redo().clear_history(); + } } break; case OBJECT_UNIQUE_RESOURCES: { @@ -86,18 +87,16 @@ void InspectorDock::_menu_option(int p_option) { current->get_property_list(&props); Map<RES, RES> duplicates; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } Variant v = current->get(E->get().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(); } @@ -113,7 +112,7 @@ void InspectorDock::_menu_option(int p_option) { editor_data->get_undo_redo().clear_history(); - editor->get_editor_plugins_over()->edit(NULL); + editor->get_editor_plugins_over()->edit(nullptr); editor->get_editor_plugins_over()->edit(current); } break; @@ -141,7 +140,7 @@ void InspectorDock::_new_resource() { } void InspectorDock::_load_resource(const String &p_type) { - load_resource_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); + load_resource_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions); @@ -151,7 +150,7 @@ void InspectorDock::_load_resource(const String &p_type) { load_resource_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } - load_resource_dialog->popup_centered_ratio(); + load_resource_dialog->popup_file_dialog(); } void InspectorDock::_resource_file_selected(String p_file) { @@ -166,22 +165,23 @@ void InspectorDock::_resource_file_selected(String p_file) { } void InspectorDock::_save_resource(bool save_as) const { - uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current(); - Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; + ObjectID current = EditorNode::get_singleton()->get_editor_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)); - if (save_as) + if (save_as) { editor->save_resource_as(current_res); - else + } else { editor->save_resource(current_res); + } } void InspectorDock::_unref_resource() const { - uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current(); - Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; + ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current(); + Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr; ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj)); @@ -191,8 +191,8 @@ void InspectorDock::_unref_resource() const { } void InspectorDock::_copy_resource() const { - uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current(); - Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; + ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current(); + Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr; ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj)); @@ -215,10 +215,9 @@ void InspectorDock::_prepare_history() { history_menu->get_popup()->clear(); - Ref<Texture> base_icon = get_icon("Object", "EditorIcons"); + Ref<Texture2D> base_icon = get_theme_icon("Object", "EditorIcons"); Set<ObjectID> already; for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) { - ObjectID id = editor_history->get_history_obj(i); Object *obj = ObjectDB::get_instance(id); if (!obj || already.has(id)) { @@ -230,7 +229,7 @@ void InspectorDock::_prepare_history() { already.insert(id); - Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj, ""); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj, ""); if (icon.is_null()) { icon = base_icon; } @@ -238,16 +237,16 @@ void InspectorDock::_prepare_history() { String text; if (Object::cast_to<Resource>(obj)) { Resource *r = Object::cast_to<Resource>(obj); - if (r->get_path().is_resource_file()) + if (r->get_path().is_resource_file()) { text = r->get_path().get_file(); - else if (r->get_name() != String()) { + } else if (r->get_name() != String()) { text = r->get_name(); } else { text = r->get_class(); } } else if (Object::cast_to<Node>(obj)) { text = Object::cast_to<Node>(obj)->get_name(); - } else if (obj->is_class("ScriptEditorDebuggerInspectedObject")) { + } else if (obj->is_class("EditorDebuggerRemoteObject")) { text = obj->call("get_title"); } else { text = obj->get_class(); @@ -260,16 +259,17 @@ void InspectorDock::_prepare_history() { } } -void InspectorDock::_select_history(int p_idx) const { +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); Object *obj = ObjectDB::get_instance(id); - if (!obj) + if (!obj) { return; + } editor->push_item(obj); } -void InspectorDock::_resource_created() const { +void InspectorDock::_resource_created() { Object *c = new_resource_dialog->instance_selected(); ERR_FAIL_COND(!c); @@ -280,22 +280,26 @@ void InspectorDock::_resource_created() const { editor->push_item(c); } -void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) const { - if (p_res.is_null()) +void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) { + if (p_res.is_null()) { return; + } RES r = p_res; editor->push_item(r.operator->(), p_property); } void InspectorDock::_edit_forward() { - if (EditorNode::get_singleton()->get_editor_history()->next()) + if (EditorNode::get_singleton()->get_editor_history()->next()) { editor->edit_current(); + } } + void InspectorDock::_edit_back() { EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); - if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) + if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) { editor->edit_current(); + } } void InspectorDock::_menu_collapseall() { @@ -311,14 +315,15 @@ void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_valu } void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) { - Spatial *s = Object::cast_to<Spatial>(sp); - if (!s) + Node3D *s = Object::cast_to<Node3D>(sp); + if (!s) { return; + } AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key); } void InspectorDock::_warning_pressed() { - warning_dialog->popup_centered_minsize(); + warning_dialog->popup_centered(); } Container *InspectorDock::get_addon_area() { @@ -329,41 +334,29 @@ void InspectorDock::_notification(int p_what) { switch (p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { set_theme(editor->get_gui_base()->get_theme()); - resource_new_button->set_icon(get_icon("New", "EditorIcons")); - resource_load_button->set_icon(get_icon("Load", "EditorIcons")); - resource_save_button->set_icon(get_icon("Save", "EditorIcons")); - backward_button->set_icon(get_icon("Back", "EditorIcons")); - forward_button->set_icon(get_icon("Forward", "EditorIcons")); - history_menu->set_icon(get_icon("History", "EditorIcons")); - object_menu->set_icon(get_icon("Tools", "EditorIcons")); - warning->set_icon(get_icon("NodeWarning", "EditorIcons")); + resource_new_button->set_icon(get_theme_icon("New", "EditorIcons")); + resource_load_button->set_icon(get_theme_icon("Load", "EditorIcons")); + resource_save_button->set_icon(get_theme_icon("Save", "EditorIcons")); + backward_button->set_icon(get_theme_icon("Back", "EditorIcons")); + forward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + history_menu->set_icon(get_theme_icon("History", "EditorIcons")); + object_menu->set_icon(get_theme_icon("Tools", "EditorIcons")); + warning->set_icon(get_theme_icon("NodeWarning", "EditorIcons")); + warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor")); } break; } } void InspectorDock::_bind_methods() { - ClassDB::bind_method("_menu_option", &InspectorDock::_menu_option); - ClassDB::bind_method("update_keying", &InspectorDock::update_keying); - ClassDB::bind_method("_property_keyed", &InspectorDock::_property_keyed); - ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed); + ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed); // Still used by some connect_compat. - ClassDB::bind_method("_new_resource", &InspectorDock::_new_resource); - ClassDB::bind_method("_resource_file_selected", &InspectorDock::_resource_file_selected); - ClassDB::bind_method("_open_resource_selector", &InspectorDock::_open_resource_selector); ClassDB::bind_method("_unref_resource", &InspectorDock::_unref_resource); ClassDB::bind_method("_paste_resource", &InspectorDock::_paste_resource); ClassDB::bind_method("_copy_resource", &InspectorDock::_copy_resource); - ClassDB::bind_method("_select_history", &InspectorDock::_select_history); - ClassDB::bind_method("_prepare_history", &InspectorDock::_prepare_history); - ClassDB::bind_method("_resource_created", &InspectorDock::_resource_created); - ClassDB::bind_method("_resource_selected", &InspectorDock::_resource_selected, DEFVAL("")); ClassDB::bind_method("_menu_collapseall", &InspectorDock::_menu_collapseall); ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall); - ClassDB::bind_method("_warning_pressed", &InspectorDock::_warning_pressed); - ClassDB::bind_method("_edit_forward", &InspectorDock::_edit_forward); - ClassDB::bind_method("_edit_back", &InspectorDock::_edit_back); ADD_SIGNAL(MethodInfo("request_help")); } @@ -388,7 +381,6 @@ void InspectorDock::clear() { } void InspectorDock::update(Object *p_object) { - EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); backward_button->set_disabled(editor_history->is_at_beginning()); forward_button->set_disabled(editor_history->is_at_end()); @@ -409,7 +401,7 @@ void InspectorDock::update(Object *p_object) { editor_path->set_disabled(true); editor_path->set_text(""); editor_path->set_tooltip(""); - editor_path->set_icon(NULL); + editor_path->set_icon(nullptr); return; } @@ -447,19 +439,17 @@ void InspectorDock::update(Object *p_object) { p->add_separator(); p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES); p->add_separator(); - p->add_icon_shortcut(get_icon("HelpSearch", "EditorIcons"), ED_SHORTCUT("property_editor/open_help", TTR("Open in Help")), OBJECT_REQUEST_HELP); + p->add_icon_shortcut(get_theme_icon("HelpSearch", "EditorIcons"), ED_SHORTCUT("property_editor/open_help", TTR("Open in Help")), OBJECT_REQUEST_HELP); } List<MethodInfo> methods; p_object->get_method_list(&methods); if (!methods.empty()) { - bool found = false; List<MethodInfo>::Element *I = methods.front(); int i = 0; while (I) { - if (I->get().flags & METHOD_FLAG_EDITOR) { if (!found) { p->add_separator(); @@ -481,13 +471,10 @@ void InspectorDock::update_keying() { bool valid = false; if (AnimationPlayerEditor::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; } } @@ -506,54 +493,58 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { HBoxContainer *general_options_hb = memnew(HBoxContainer); add_child(general_options_hb); - resource_new_button = memnew(ToolButton); + 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_icon("New", "EditorIcons")); + resource_new_button->set_icon(get_theme_icon("New", "EditorIcons")); general_options_hb->add_child(resource_new_button); - resource_new_button->connect("pressed", this, "_new_resource"); + resource_new_button->connect("pressed", callable_mp(this, &InspectorDock::_new_resource)); resource_new_button->set_focus_mode(Control::FOCUS_NONE); - resource_load_button = memnew(ToolButton); + 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_icon("Load", "EditorIcons")); + resource_load_button->set_icon(get_theme_icon("Load", "EditorIcons")); general_options_hb->add_child(resource_load_button); - resource_load_button->connect("pressed", this, "_open_resource_selector"); + 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_icon("Save", "EditorIcons")); + resource_save_button->set_icon(get_theme_icon("Save", "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); - resource_save_button->get_popup()->connect("id_pressed", this, "_menu_option"); + resource_save_button->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option)); resource_save_button->set_focus_mode(Control::FOCUS_NONE); resource_save_button->set_disabled(true); general_options_hb->add_spacer(); - backward_button = memnew(ToolButton); + backward_button = memnew(Button); + backward_button->set_flat(true); general_options_hb->add_child(backward_button); - backward_button->set_icon(get_icon("Back", "EditorIcons")); + backward_button->set_icon(get_theme_icon("Back", "EditorIcons")); backward_button->set_flat(true); backward_button->set_tooltip(TTR("Go to the previous edited object in history.")); backward_button->set_disabled(true); - backward_button->connect("pressed", this, "_edit_back"); + backward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_back)); - forward_button = memnew(ToolButton); + forward_button = memnew(Button); + forward_button->set_flat(true); general_options_hb->add_child(forward_button); - forward_button->set_icon(get_icon("Forward", "EditorIcons")); + forward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); forward_button->set_flat(true); forward_button->set_tooltip(TTR("Go to the next edited object in history.")); forward_button->set_disabled(true); - forward_button->connect("pressed", this, "_edit_forward"); + 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_icon("History", "EditorIcons")); + history_menu->set_icon(get_theme_icon("History", "EditorIcons")); general_options_hb->add_child(history_menu); - history_menu->connect("about_to_show", this, "_prepare_history"); - history_menu->get_popup()->connect("id_pressed", this, "_select_history"); + 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 *node_info_hb = memnew(HBoxContainer); add_child(node_info_hb); @@ -563,30 +554,31 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { node_info_hb->add_child(editor_path); object_menu = memnew(MenuButton); - object_menu->set_icon(get_icon("Tools", "EditorIcons")); + object_menu->set_icon(get_theme_icon("Tools", "EditorIcons")); node_info_hb->add_child(object_menu); object_menu->set_tooltip(TTR("Object properties.")); - object_menu->get_popup()->connect("id_pressed", this, "_menu_option"); + object_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option)); new_resource_dialog = memnew(CreateDialog); editor->get_gui_base()->add_child(new_resource_dialog); new_resource_dialog->set_base_type("Resource"); - new_resource_dialog->connect("create", this, "_resource_created"); + new_resource_dialog->connect("create", callable_mp(this, &InspectorDock::_resource_created)); search = memnew(LineEdit); search->set_h_size_flags(Control::SIZE_EXPAND_FILL); search->set_placeholder(TTR("Filter properties")); - search->set_right_icon(get_icon("Search", "EditorIcons")); + search->set_right_icon(get_theme_icon("Search", "EditorIcons")); search->set_clear_button_enabled(true); add_child(search); warning = memnew(Button); add_child(warning); warning->set_text(TTR("Changes may be lost!")); - warning->set_icon(get_icon("NodeWarning", "EditorIcons")); + warning->set_icon(get_theme_icon("NodeWarning", "EditorIcons")); + warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor")); warning->set_clip_text(true); warning->hide(); - warning->connect("pressed", this, "_warning_pressed"); + warning->connect("pressed", callable_mp(this, &InspectorDock::_warning_pressed)); warning_dialog = memnew(AcceptDialog); editor->get_gui_base()->add_child(warning_dialog); @@ -594,7 +586,7 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { load_resource_dialog = memnew(EditorFileDialog); add_child(load_resource_dialog); load_resource_dialog->set_current_dir("res://"); - load_resource_dialog->connect("file_selected", this, "_resource_file_selected"); + load_resource_dialog->connect("file_selected", callable_mp(this, &InspectorDock::_resource_file_selected)); inspector = memnew(EditorInspector); add_child(inspector); @@ -610,8 +602,8 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { inspector->set_use_filter(true); // TODO: check me - inspector->connect("resource_selected", this, "_resource_selected"); - inspector->connect("property_keyed", this, "_property_keyed"); + inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected)); + inspector->connect("property_keyed", callable_mp(this, &InspectorDock::_property_keyed)); } InspectorDock::~InspectorDock() { |