| 1 | /**************************************************************************/ |
| 2 | /* inspector_dock.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "inspector_dock.h" |
| 32 | |
| 33 | #include "editor/editor_node.h" |
| 34 | #include "editor/editor_scale.h" |
| 35 | #include "editor/editor_settings.h" |
| 36 | #include "editor/editor_string_names.h" |
| 37 | #include "editor/editor_undo_redo_manager.h" |
| 38 | #include "editor/filesystem_dock.h" |
| 39 | #include "editor/gui/editor_file_dialog.h" |
| 40 | #include "editor/gui/editor_object_selector.h" |
| 41 | #include "editor/plugins/script_editor_plugin.h" |
| 42 | |
| 43 | InspectorDock *InspectorDock::singleton = nullptr; |
| 44 | |
| 45 | void InspectorDock::() { |
| 46 | PopupMenu * = object_menu->get_popup(); |
| 47 | for (int i = EditorPropertyNameProcessor::STYLE_RAW; i <= EditorPropertyNameProcessor::STYLE_LOCALIZED; i++) { |
| 48 | menu->set_item_checked(menu->get_item_index(PROPERTY_NAME_STYLE_RAW + i), i == property_name_style); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void InspectorDock::(int p_option) { |
| 53 | _menu_option_confirm(p_option, false); |
| 54 | } |
| 55 | |
| 56 | void InspectorDock::() { |
| 57 | _menu_option_confirm(current_option, true); |
| 58 | } |
| 59 | |
| 60 | void InspectorDock::(int p_option, bool p_confirmed) { |
| 61 | if (!p_confirmed) { |
| 62 | current_option = p_option; |
| 63 | } |
| 64 | |
| 65 | switch (p_option) { |
| 66 | case EXPAND_ALL: { |
| 67 | _menu_expandall(); |
| 68 | } break; |
| 69 | case COLLAPSE_ALL: { |
| 70 | _menu_collapseall(); |
| 71 | } break; |
| 72 | case EXPAND_REVERTABLE: { |
| 73 | _menu_expand_revertable(); |
| 74 | } break; |
| 75 | |
| 76 | case RESOURCE_SAVE: { |
| 77 | _save_resource(false); |
| 78 | } break; |
| 79 | case RESOURCE_SAVE_AS: { |
| 80 | _save_resource(true); |
| 81 | } break; |
| 82 | |
| 83 | case RESOURCE_MAKE_BUILT_IN: { |
| 84 | _unref_resource(); |
| 85 | } break; |
| 86 | case RESOURCE_COPY: { |
| 87 | _copy_resource(); |
| 88 | } break; |
| 89 | case RESOURCE_EDIT_CLIPBOARD: { |
| 90 | _paste_resource(); |
| 91 | } break; |
| 92 | case RESOURCE_SHOW_IN_FILESYSTEM: { |
| 93 | Ref<Resource> current_res = _get_current_resource(); |
| 94 | ERR_FAIL_COND(current_res.is_null()); |
| 95 | FileSystemDock::get_singleton()->navigate_to_path(current_res->get_path()); |
| 96 | } break; |
| 97 | |
| 98 | case OBJECT_REQUEST_HELP: { |
| 99 | if (current) { |
| 100 | EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); |
| 101 | emit_signal(SNAME("request_help" ), current->get_class()); |
| 102 | } |
| 103 | } break; |
| 104 | |
| 105 | case OBJECT_COPY_PARAMS: { |
| 106 | editor_data->apply_changes_in_editors(); |
| 107 | if (current) { |
| 108 | editor_data->copy_object_params(current); |
| 109 | } |
| 110 | } break; |
| 111 | |
| 112 | case OBJECT_PASTE_PARAMS: { |
| 113 | editor_data->apply_changes_in_editors(); |
| 114 | if (current) { |
| 115 | editor_data->paste_object_params(current); |
| 116 | } |
| 117 | } break; |
| 118 | |
| 119 | case OBJECT_UNIQUE_RESOURCES: { |
| 120 | if (!p_confirmed) { |
| 121 | Vector<String> resource_propnames; |
| 122 | |
| 123 | if (current) { |
| 124 | List<PropertyInfo> props; |
| 125 | current->get_property_list(&props); |
| 126 | |
| 127 | for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { |
| 128 | if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { |
| 129 | continue; |
| 130 | } |
| 131 | |
| 132 | Variant v = current->get(E->get().name); |
| 133 | Ref<RefCounted> ref = v; |
| 134 | Ref<Resource> res = ref; |
| 135 | if (v.is_ref_counted() && ref.is_valid() && res.is_valid()) { |
| 136 | // Valid resource which would be duplicated if action is confirmed. |
| 137 | resource_propnames.append(E->get().name); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (resource_propnames.size()) { |
| 143 | unique_resources_list_tree->clear(); |
| 144 | TreeItem *root = unique_resources_list_tree->create_item(); |
| 145 | |
| 146 | for (int i = 0; i < resource_propnames.size(); i++) { |
| 147 | String propname = resource_propnames[i].replace("/" , " / " ); |
| 148 | |
| 149 | TreeItem *ti = unique_resources_list_tree->create_item(root); |
| 150 | ti->set_text(0, bool(EDITOR_GET("interface/inspector/capitalize_properties" )) ? propname.capitalize() : propname); |
| 151 | } |
| 152 | |
| 153 | unique_resources_label->set_text(TTR("The following resources will be duplicated and embedded within this resource/object." )); |
| 154 | unique_resources_confirmation->popup_centered(); |
| 155 | } else { |
| 156 | current_option = -1; |
| 157 | unique_resources_label->set_text(TTR("This object has no resources." )); |
| 158 | unique_resources_confirmation->popup_centered(); |
| 159 | } |
| 160 | } else { |
| 161 | editor_data->apply_changes_in_editors(); |
| 162 | |
| 163 | if (current) { |
| 164 | List<PropertyInfo> props; |
| 165 | current->get_property_list(&props); |
| 166 | HashMap<Ref<Resource>, Ref<Resource>> duplicates; |
| 167 | for (const PropertyInfo &prop_info : props) { |
| 168 | if (!(prop_info.usage & PROPERTY_USAGE_STORAGE)) { |
| 169 | continue; |
| 170 | } |
| 171 | |
| 172 | Variant v = current->get(prop_info.name); |
| 173 | if (v.is_ref_counted()) { |
| 174 | Ref<RefCounted> ref = v; |
| 175 | if (ref.is_valid()) { |
| 176 | Ref<Resource> res = ref; |
| 177 | if (res.is_valid()) { |
| 178 | if (!duplicates.has(res)) { |
| 179 | duplicates[res] = res->duplicate(); |
| 180 | } |
| 181 | res = duplicates[res]; |
| 182 | |
| 183 | current->set(prop_info.name, res); |
| 184 | get_inspector_singleton()->update_property(prop_info.name); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | int history_id = EditorUndoRedoManager::get_singleton()->get_history_id_for_object(current); |
| 192 | EditorUndoRedoManager::get_singleton()->clear_history(true, history_id); |
| 193 | |
| 194 | EditorNode::get_singleton()->edit_item(current, inspector); |
| 195 | } |
| 196 | |
| 197 | } break; |
| 198 | |
| 199 | case PROPERTY_NAME_STYLE_RAW: |
| 200 | case PROPERTY_NAME_STYLE_CAPITALIZED: |
| 201 | case PROPERTY_NAME_STYLE_LOCALIZED: { |
| 202 | property_name_style = (EditorPropertyNameProcessor::Style)(p_option - PROPERTY_NAME_STYLE_RAW); |
| 203 | inspector->set_property_name_style(property_name_style); |
| 204 | } break; |
| 205 | |
| 206 | default: { |
| 207 | if (p_option >= OBJECT_METHOD_BASE) { |
| 208 | ERR_FAIL_NULL(current); |
| 209 | |
| 210 | int idx = p_option - OBJECT_METHOD_BASE; |
| 211 | |
| 212 | List<MethodInfo> methods; |
| 213 | current->get_method_list(&methods); |
| 214 | |
| 215 | ERR_FAIL_INDEX(idx, methods.size()); |
| 216 | String name = methods[idx].name; |
| 217 | |
| 218 | current->call(name); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void InspectorDock::_new_resource() { |
| 225 | new_resource_dialog->popup_create(true); |
| 226 | } |
| 227 | |
| 228 | void InspectorDock::_load_resource(const String &p_type) { |
| 229 | load_resource_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); |
| 230 | |
| 231 | List<String> extensions; |
| 232 | ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions); |
| 233 | |
| 234 | load_resource_dialog->clear_filters(); |
| 235 | for (int i = 0; i < extensions.size(); i++) { |
| 236 | load_resource_dialog->add_filter("*." + extensions[i], extensions[i].to_upper()); |
| 237 | } |
| 238 | |
| 239 | const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions" ))).split("," , false); |
| 240 | for (int i = 0; i < textfile_ext.size(); i++) { |
| 241 | load_resource_dialog->add_filter("*." + textfile_ext[i], textfile_ext[i].to_upper()); |
| 242 | } |
| 243 | |
| 244 | load_resource_dialog->popup_file_dialog(); |
| 245 | } |
| 246 | |
| 247 | void InspectorDock::_resource_file_selected(String p_file) { |
| 248 | Ref<Resource> res; |
| 249 | if (ResourceLoader::exists(p_file, "" )) { |
| 250 | res = ResourceLoader::load(p_file); |
| 251 | } else { |
| 252 | const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions" ))).split("," , false); |
| 253 | if (textfile_ext.has(p_file.get_extension())) { |
| 254 | res = ScriptEditor::get_singleton()->open_file(p_file); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if (res.is_null()) { |
| 259 | info_dialog->set_text(TTR("Failed to load resource." )); |
| 260 | return; |
| 261 | }; |
| 262 | |
| 263 | EditorNode::get_singleton()->push_item(res.operator->()); |
| 264 | } |
| 265 | |
| 266 | void InspectorDock::_save_resource(bool save_as) { |
| 267 | Ref<Resource> current_res = _get_current_resource(); |
| 268 | ERR_FAIL_COND(current_res.is_null()); |
| 269 | |
| 270 | if (save_as) { |
| 271 | EditorNode::get_singleton()->save_resource_as(current_res); |
| 272 | } else { |
| 273 | EditorNode::get_singleton()->save_resource(current_res); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void InspectorDock::_unref_resource() { |
| 278 | Ref<Resource> current_res = _get_current_resource(); |
| 279 | ERR_FAIL_COND(current_res.is_null()); |
| 280 | current_res->set_path("" ); |
| 281 | EditorNode::get_singleton()->edit_current(); |
| 282 | } |
| 283 | |
| 284 | void InspectorDock::_copy_resource() { |
| 285 | Ref<Resource> current_res = _get_current_resource(); |
| 286 | ERR_FAIL_COND(current_res.is_null()); |
| 287 | EditorSettings::get_singleton()->set_resource_clipboard(current_res); |
| 288 | } |
| 289 | |
| 290 | void InspectorDock::_paste_resource() { |
| 291 | Ref<Resource> r = EditorSettings::get_singleton()->get_resource_clipboard(); |
| 292 | if (r.is_valid()) { |
| 293 | EditorNode::get_singleton()->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String()); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | void InspectorDock::() { |
| 298 | Ref<Resource> r = EditorSettings::get_singleton()->get_resource_clipboard(); |
| 299 | PopupMenu * = resource_extra_button->get_popup(); |
| 300 | popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null()); |
| 301 | |
| 302 | Ref<Resource> current_res = _get_current_resource(); |
| 303 | popup->set_item_disabled(popup->get_item_index(RESOURCE_SHOW_IN_FILESYSTEM), current_res.is_null() || current_res->is_built_in()); |
| 304 | } |
| 305 | |
| 306 | Ref<Resource> InspectorDock::_get_current_resource() const { |
| 307 | ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current(); |
| 308 | Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr; |
| 309 | return Ref<Resource>(Object::cast_to<Resource>(current_obj)); |
| 310 | } |
| 311 | |
| 312 | void InspectorDock::_prepare_history() { |
| 313 | EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); |
| 314 | |
| 315 | int history_to = MAX(0, editor_history->get_history_len() - 25); |
| 316 | |
| 317 | history_menu->get_popup()->clear(); |
| 318 | |
| 319 | HashSet<ObjectID> already; |
| 320 | for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) { |
| 321 | ObjectID id = editor_history->get_history_obj(i); |
| 322 | Object *obj = ObjectDB::get_instance(id); |
| 323 | if (!obj || already.has(id)) { |
| 324 | if (history_to > 0) { |
| 325 | history_to--; |
| 326 | } |
| 327 | continue; |
| 328 | } |
| 329 | |
| 330 | already.insert(id); |
| 331 | |
| 332 | Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj, "Object" ); |
| 333 | |
| 334 | String text; |
| 335 | if (obj->has_method("_get_editor_name" )) { |
| 336 | text = obj->call("_get_editor_name" ); |
| 337 | } else if (Object::cast_to<Resource>(obj)) { |
| 338 | Resource *r = Object::cast_to<Resource>(obj); |
| 339 | if (r->get_path().is_resource_file()) { |
| 340 | text = r->get_path().get_file(); |
| 341 | } else if (!r->get_name().is_empty()) { |
| 342 | text = r->get_name(); |
| 343 | } else { |
| 344 | text = r->get_class(); |
| 345 | } |
| 346 | } else if (Object::cast_to<Node>(obj)) { |
| 347 | text = Object::cast_to<Node>(obj)->get_name(); |
| 348 | } else if (obj->is_class("EditorDebuggerRemoteObject" )) { |
| 349 | text = obj->call("get_title" ); |
| 350 | } else { |
| 351 | text = obj->get_class(); |
| 352 | } |
| 353 | |
| 354 | if (i == editor_history->get_history_pos() && current) { |
| 355 | text += " " + TTR("(Current)" ); |
| 356 | } |
| 357 | history_menu->get_popup()->add_icon_item(icon, text, i); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | void InspectorDock::_select_history(int p_idx) { |
| 362 | // Push it to the top, it is not correct, but it's more useful. |
| 363 | ObjectID id = EditorNode::get_singleton()->get_editor_selection_history()->get_history_obj(p_idx); |
| 364 | Object *obj = ObjectDB::get_instance(id); |
| 365 | if (!obj) { |
| 366 | return; |
| 367 | } |
| 368 | EditorNode::get_singleton()->push_item(obj); |
| 369 | } |
| 370 | |
| 371 | void InspectorDock::_resource_created() { |
| 372 | Variant c = new_resource_dialog->instantiate_selected(); |
| 373 | |
| 374 | ERR_FAIL_COND(!c); |
| 375 | Resource *r = Object::cast_to<Resource>(c); |
| 376 | ERR_FAIL_NULL(r); |
| 377 | |
| 378 | EditorNode::get_singleton()->push_item(r); |
| 379 | } |
| 380 | |
| 381 | void InspectorDock::_resource_selected(const Ref<Resource> &p_res, const String &p_property) { |
| 382 | if (p_res.is_null()) { |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | Ref<Resource> r = p_res; |
| 387 | EditorNode::get_singleton()->push_item(r.operator->(), p_property); |
| 388 | } |
| 389 | |
| 390 | void InspectorDock::_edit_forward() { |
| 391 | if (EditorNode::get_singleton()->get_editor_selection_history()->next()) { |
| 392 | EditorNode::get_singleton()->edit_current(); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | void InspectorDock::_edit_back() { |
| 397 | EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); |
| 398 | if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) { |
| 399 | EditorNode::get_singleton()->edit_current(); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | void InspectorDock::() { |
| 404 | inspector->collapse_all_folding(); |
| 405 | } |
| 406 | |
| 407 | void InspectorDock::_menu_expandall() { |
| 408 | inspector->expand_all_folding(); |
| 409 | } |
| 410 | |
| 411 | void InspectorDock::_menu_expand_revertable() { |
| 412 | inspector->expand_revertable(); |
| 413 | } |
| 414 | |
| 415 | void InspectorDock::_info_pressed() { |
| 416 | info_dialog->popup_centered(); |
| 417 | } |
| 418 | |
| 419 | Container *InspectorDock::get_addon_area() { |
| 420 | return this; |
| 421 | } |
| 422 | |
| 423 | void InspectorDock::_notification(int p_what) { |
| 424 | switch (p_what) { |
| 425 | case NOTIFICATION_THEME_CHANGED: |
| 426 | case NOTIFICATION_TRANSLATION_CHANGED: |
| 427 | case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { |
| 428 | resource_new_button->set_icon(get_editor_theme_icon(SNAME("New" ))); |
| 429 | resource_load_button->set_icon(get_editor_theme_icon(SNAME("Load" ))); |
| 430 | resource_save_button->set_icon(get_editor_theme_icon(SNAME("Save" ))); |
| 431 | resource_extra_button->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl" ))); |
| 432 | open_docs_button->set_icon(get_editor_theme_icon(SNAME("HelpSearch" ))); |
| 433 | |
| 434 | PopupMenu * = resource_extra_button->get_popup(); |
| 435 | resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_editor_theme_icon(SNAME("ActionPaste" ))); |
| 436 | resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_COPY), get_editor_theme_icon(SNAME("ActionCopy" ))); |
| 437 | |
| 438 | if (is_layout_rtl()) { |
| 439 | backward_button->set_icon(get_editor_theme_icon(SNAME("Forward" ))); |
| 440 | forward_button->set_icon(get_editor_theme_icon(SNAME("Back" ))); |
| 441 | } else { |
| 442 | backward_button->set_icon(get_editor_theme_icon(SNAME("Back" ))); |
| 443 | forward_button->set_icon(get_editor_theme_icon(SNAME("Forward" ))); |
| 444 | } |
| 445 | |
| 446 | history_menu->set_icon(get_editor_theme_icon(SNAME("History" ))); |
| 447 | object_menu->set_icon(get_editor_theme_icon(SNAME("Tools" ))); |
| 448 | search->set_right_icon(get_editor_theme_icon(SNAME("Search" ))); |
| 449 | if (info_is_warning) { |
| 450 | info->set_icon(get_editor_theme_icon(SNAME("NodeWarning" ))); |
| 451 | info->add_theme_color_override("font_color" , get_theme_color(SNAME("warning_color" ), EditorStringName(Editor))); |
| 452 | } else { |
| 453 | info->set_icon(get_editor_theme_icon(SNAME("NodeInfo" ))); |
| 454 | info->add_theme_color_override("font_color" , get_theme_color(SNAME("font_color" ), EditorStringName(Editor))); |
| 455 | } |
| 456 | } break; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | void InspectorDock::_bind_methods() { |
| 461 | ClassDB::bind_method("_unref_resource" , &InspectorDock::_unref_resource); |
| 462 | ClassDB::bind_method("_paste_resource" , &InspectorDock::_paste_resource); |
| 463 | ClassDB::bind_method("_copy_resource" , &InspectorDock::_copy_resource); |
| 464 | |
| 465 | ClassDB::bind_method("_menu_collapseall" , &InspectorDock::_menu_collapseall); |
| 466 | ClassDB::bind_method("_menu_expandall" , &InspectorDock::_menu_expandall); |
| 467 | |
| 468 | ClassDB::bind_method("edit_resource" , &InspectorDock::edit_resource); |
| 469 | |
| 470 | ClassDB::bind_method("store_script_properties" , &InspectorDock::store_script_properties); |
| 471 | ClassDB::bind_method("apply_script_properties" , &InspectorDock::apply_script_properties); |
| 472 | |
| 473 | ADD_SIGNAL(MethodInfo("request_help" )); |
| 474 | } |
| 475 | |
| 476 | void InspectorDock::edit_resource(const Ref<Resource> &p_resource) { |
| 477 | _resource_selected(p_resource, "" ); |
| 478 | } |
| 479 | |
| 480 | void InspectorDock::open_resource(const String &p_type) { |
| 481 | _load_resource(p_type); |
| 482 | } |
| 483 | |
| 484 | void InspectorDock::set_info(const String &p_button_text, const String &p_message, bool p_is_warning) { |
| 485 | info->hide(); |
| 486 | info_is_warning = p_is_warning; |
| 487 | |
| 488 | if (info_is_warning) { |
| 489 | info->set_icon(get_editor_theme_icon(SNAME("NodeWarning" ))); |
| 490 | info->add_theme_color_override("font_color" , get_theme_color(SNAME("warning_color" ), EditorStringName(Editor))); |
| 491 | } else { |
| 492 | info->set_icon(get_editor_theme_icon(SNAME("NodeInfo" ))); |
| 493 | info->add_theme_color_override("font_color" , get_theme_color(SNAME("font_color" ), EditorStringName(Editor))); |
| 494 | } |
| 495 | |
| 496 | if (!p_button_text.is_empty() && !p_message.is_empty()) { |
| 497 | info->show(); |
| 498 | info->set_text(p_button_text); |
| 499 | info_dialog->set_text(p_message); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | void InspectorDock::clear() { |
| 504 | } |
| 505 | |
| 506 | void InspectorDock::update(Object *p_object) { |
| 507 | EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); |
| 508 | backward_button->set_disabled(editor_history->is_at_beginning()); |
| 509 | forward_button->set_disabled(editor_history->is_at_end()); |
| 510 | |
| 511 | history_menu->set_disabled(true); |
| 512 | if (editor_history->get_history_len() > 0) { |
| 513 | history_menu->set_disabled(false); |
| 514 | } |
| 515 | object_selector->update_path(); |
| 516 | |
| 517 | current = p_object; |
| 518 | |
| 519 | const bool is_object = p_object != nullptr; |
| 520 | const bool is_resource = is_object && p_object->is_class("Resource" ); |
| 521 | const bool is_text_file = is_object && p_object->is_class("TextFile" ); |
| 522 | const bool is_node = is_object && p_object->is_class("Node" ); |
| 523 | |
| 524 | object_menu->set_disabled(!is_object || is_text_file); |
| 525 | search->set_editable(is_object && !is_text_file); |
| 526 | resource_save_button->set_disabled(!is_resource || is_text_file); |
| 527 | open_docs_button->set_disabled(is_text_file || (!is_resource && !is_node)); |
| 528 | |
| 529 | PopupMenu * = resource_extra_button->get_popup(); |
| 530 | resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource || is_text_file); |
| 531 | resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource || is_text_file); |
| 532 | |
| 533 | if (!is_object || is_text_file) { |
| 534 | info->hide(); |
| 535 | object_selector->clear_path(); |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | object_selector->enable_path(); |
| 540 | |
| 541 | PopupMenu *p = object_menu->get_popup(); |
| 542 | |
| 543 | p->clear(); |
| 544 | p->add_icon_shortcut(get_editor_theme_icon(SNAME("GuiTreeArrowDown" )), ED_SHORTCUT("property_editor/expand_all" , TTR("Expand All" )), EXPAND_ALL); |
| 545 | p->add_icon_shortcut(get_editor_theme_icon(SNAME("GuiTreeArrowRight" )), ED_SHORTCUT("property_editor/collapse_all" , TTR("Collapse All" )), COLLAPSE_ALL); |
| 546 | // Calling it 'revertable' internally, because that's what the implementation is based on, but labeling it as 'non-default' because that's more user friendly, even if not 100% accurate. |
| 547 | p->add_shortcut(ED_SHORTCUT("property_editor/expand_revertable" , TTR("Expand Non-Default" )), EXPAND_REVERTABLE); |
| 548 | |
| 549 | p->add_separator(TTR("Property Name Style" )); |
| 550 | p->add_radio_check_item(TTR("Raw" ), PROPERTY_NAME_STYLE_RAW); |
| 551 | p->add_radio_check_item(TTR("Capitalized" ), PROPERTY_NAME_STYLE_CAPITALIZED); |
| 552 | p->add_radio_check_item(TTR("Localized" ), PROPERTY_NAME_STYLE_LOCALIZED); |
| 553 | |
| 554 | if (!EditorPropertyNameProcessor::is_localization_available()) { |
| 555 | const int index = p->get_item_index(PROPERTY_NAME_STYLE_LOCALIZED); |
| 556 | p->set_item_disabled(index, true); |
| 557 | p->set_item_tooltip(index, TTR("Localization not available for current language." )); |
| 558 | } |
| 559 | |
| 560 | p->add_separator(); |
| 561 | p->add_shortcut(ED_SHORTCUT("property_editor/copy_params" , TTR("Copy Properties" )), OBJECT_COPY_PARAMS); |
| 562 | p->add_shortcut(ED_SHORTCUT("property_editor/paste_params" , TTR("Paste Properties" )), OBJECT_PASTE_PARAMS); |
| 563 | |
| 564 | if (is_resource || is_node) { |
| 565 | p->add_separator(); |
| 566 | p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique" , TTR("Make Sub-Resources Unique" )), OBJECT_UNIQUE_RESOURCES); |
| 567 | } |
| 568 | |
| 569 | List<MethodInfo> methods; |
| 570 | p_object->get_method_list(&methods); |
| 571 | |
| 572 | if (!methods.is_empty()) { |
| 573 | bool found = false; |
| 574 | List<MethodInfo>::Element *I = methods.front(); |
| 575 | int i = 0; |
| 576 | while (I) { |
| 577 | if (I->get().flags & METHOD_FLAG_EDITOR) { |
| 578 | if (!found) { |
| 579 | p->add_separator(); |
| 580 | found = true; |
| 581 | } |
| 582 | p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i); |
| 583 | } |
| 584 | i++; |
| 585 | I = I->next(); |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | void InspectorDock::go_back() { |
| 591 | _edit_back(); |
| 592 | } |
| 593 | |
| 594 | EditorPropertyNameProcessor::Style InspectorDock::get_property_name_style() const { |
| 595 | return property_name_style; |
| 596 | } |
| 597 | |
| 598 | void InspectorDock::store_script_properties(Object *p_object) { |
| 599 | ERR_FAIL_NULL(p_object); |
| 600 | ScriptInstance *si = p_object->get_script_instance(); |
| 601 | if (!si) { |
| 602 | return; |
| 603 | } |
| 604 | si->get_property_state(stored_properties); |
| 605 | } |
| 606 | |
| 607 | void InspectorDock::apply_script_properties(Object *p_object) { |
| 608 | ERR_FAIL_NULL(p_object); |
| 609 | ScriptInstance *si = p_object->get_script_instance(); |
| 610 | if (!si) { |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | for (const Pair<StringName, Variant> &E : stored_properties) { |
| 615 | Variant current_prop; |
| 616 | if (si->get(E.first, current_prop) && current_prop.get_type() == E.second.get_type()) { |
| 617 | si->set(E.first, E.second); |
| 618 | } |
| 619 | } |
| 620 | stored_properties.clear(); |
| 621 | } |
| 622 | |
| 623 | InspectorDock::InspectorDock(EditorData &p_editor_data) { |
| 624 | singleton = this; |
| 625 | set_name("Inspector" ); |
| 626 | |
| 627 | editor_data = &p_editor_data; |
| 628 | |
| 629 | property_name_style = EditorPropertyNameProcessor::get_default_inspector_style(); |
| 630 | |
| 631 | HBoxContainer *general_options_hb = memnew(HBoxContainer); |
| 632 | add_child(general_options_hb); |
| 633 | |
| 634 | resource_new_button = memnew(Button); |
| 635 | resource_new_button->set_flat(true); |
| 636 | resource_new_button->set_tooltip_text(TTR("Create a new resource in memory and edit it." )); |
| 637 | general_options_hb->add_child(resource_new_button); |
| 638 | resource_new_button->connect("pressed" , callable_mp(this, &InspectorDock::_new_resource)); |
| 639 | resource_new_button->set_focus_mode(Control::FOCUS_NONE); |
| 640 | |
| 641 | resource_load_button = memnew(Button); |
| 642 | resource_load_button->set_flat(true); |
| 643 | resource_load_button->set_tooltip_text(TTR("Load an existing resource from disk and edit it." )); |
| 644 | general_options_hb->add_child(resource_load_button); |
| 645 | resource_load_button->connect("pressed" , callable_mp(this, &InspectorDock::_open_resource_selector)); |
| 646 | resource_load_button->set_focus_mode(Control::FOCUS_NONE); |
| 647 | |
| 648 | resource_save_button = memnew(MenuButton); |
| 649 | resource_save_button->set_tooltip_text(TTR("Save the currently edited resource." )); |
| 650 | general_options_hb->add_child(resource_save_button); |
| 651 | resource_save_button->get_popup()->add_item(TTR("Save" ), RESOURCE_SAVE); |
| 652 | resource_save_button->get_popup()->add_item(TTR("Save As..." ), RESOURCE_SAVE_AS); |
| 653 | resource_save_button->get_popup()->connect("id_pressed" , callable_mp(this, &InspectorDock::_menu_option)); |
| 654 | resource_save_button->set_focus_mode(Control::FOCUS_NONE); |
| 655 | resource_save_button->set_disabled(true); |
| 656 | |
| 657 | resource_extra_button = memnew(MenuButton); |
| 658 | resource_extra_button->set_tooltip_text(TTR("Extra resource options." )); |
| 659 | general_options_hb->add_child(resource_extra_button); |
| 660 | resource_extra_button->connect("about_to_popup" , callable_mp(this, &InspectorDock::_prepare_resource_extra_popup)); |
| 661 | resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/paste_resource" , TTR("Edit Resource from Clipboard" )), RESOURCE_EDIT_CLIPBOARD); |
| 662 | resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/copy_resource" , TTR("Copy Resource" )), RESOURCE_COPY); |
| 663 | resource_extra_button->get_popup()->set_item_disabled(1, true); |
| 664 | resource_extra_button->get_popup()->add_separator(); |
| 665 | resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/show_in_filesystem" , TTR("Show in FileSystem" )), RESOURCE_SHOW_IN_FILESYSTEM); |
| 666 | resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/unref_resource" , TTR("Make Resource Built-In" )), RESOURCE_MAKE_BUILT_IN); |
| 667 | resource_extra_button->get_popup()->set_item_disabled(3, true); |
| 668 | resource_extra_button->get_popup()->connect("id_pressed" , callable_mp(this, &InspectorDock::_menu_option)); |
| 669 | |
| 670 | general_options_hb->add_spacer(); |
| 671 | |
| 672 | backward_button = memnew(Button); |
| 673 | backward_button->set_flat(true); |
| 674 | general_options_hb->add_child(backward_button); |
| 675 | backward_button->set_tooltip_text(TTR("Go to previous edited object in history." )); |
| 676 | backward_button->set_disabled(true); |
| 677 | backward_button->connect("pressed" , callable_mp(this, &InspectorDock::_edit_back)); |
| 678 | |
| 679 | forward_button = memnew(Button); |
| 680 | forward_button->set_flat(true); |
| 681 | general_options_hb->add_child(forward_button); |
| 682 | forward_button->set_tooltip_text(TTR("Go to next edited object in history." )); |
| 683 | forward_button->set_disabled(true); |
| 684 | forward_button->connect("pressed" , callable_mp(this, &InspectorDock::_edit_forward)); |
| 685 | |
| 686 | history_menu = memnew(MenuButton); |
| 687 | history_menu->set_tooltip_text(TTR("History of recently edited objects." )); |
| 688 | general_options_hb->add_child(history_menu); |
| 689 | history_menu->connect("about_to_popup" , callable_mp(this, &InspectorDock::_prepare_history)); |
| 690 | history_menu->get_popup()->connect("id_pressed" , callable_mp(this, &InspectorDock::_select_history)); |
| 691 | |
| 692 | HBoxContainer *subresource_hb = memnew(HBoxContainer); |
| 693 | add_child(subresource_hb); |
| 694 | object_selector = memnew(EditorObjectSelector(EditorNode::get_singleton()->get_editor_selection_history())); |
| 695 | object_selector->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 696 | subresource_hb->add_child(object_selector); |
| 697 | |
| 698 | open_docs_button = memnew(Button); |
| 699 | open_docs_button->set_flat(true); |
| 700 | open_docs_button->set_disabled(true); |
| 701 | open_docs_button->set_tooltip_text(TTR("Open documentation for this object." )); |
| 702 | open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help" , TTR("Open Documentation" ))); |
| 703 | subresource_hb->add_child(open_docs_button); |
| 704 | open_docs_button->connect("pressed" , callable_mp(this, &InspectorDock::_menu_option).bind(OBJECT_REQUEST_HELP)); |
| 705 | |
| 706 | new_resource_dialog = memnew(CreateDialog); |
| 707 | EditorNode::get_singleton()->get_gui_base()->add_child(new_resource_dialog); |
| 708 | new_resource_dialog->set_base_type("Resource" ); |
| 709 | new_resource_dialog->connect("create" , callable_mp(this, &InspectorDock::_resource_created)); |
| 710 | |
| 711 | HBoxContainer *property_tools_hb = memnew(HBoxContainer); |
| 712 | add_child(property_tools_hb); |
| 713 | |
| 714 | search = memnew(LineEdit); |
| 715 | search->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 716 | search->set_placeholder(TTR("Filter Properties" )); |
| 717 | search->set_clear_button_enabled(true); |
| 718 | property_tools_hb->add_child(search); |
| 719 | |
| 720 | object_menu = memnew(MenuButton); |
| 721 | object_menu->set_shortcut_context(this); |
| 722 | property_tools_hb->add_child(object_menu); |
| 723 | object_menu->set_tooltip_text(TTR("Manage object properties." )); |
| 724 | object_menu->get_popup()->connect("about_to_popup" , callable_mp(this, &InspectorDock::_prepare_menu)); |
| 725 | object_menu->get_popup()->connect("id_pressed" , callable_mp(this, &InspectorDock::_menu_option)); |
| 726 | |
| 727 | info = memnew(Button); |
| 728 | add_child(info); |
| 729 | info->set_clip_text(true); |
| 730 | info->hide(); |
| 731 | info->connect("pressed" , callable_mp(this, &InspectorDock::_info_pressed)); |
| 732 | |
| 733 | unique_resources_confirmation = memnew(ConfirmationDialog); |
| 734 | add_child(unique_resources_confirmation); |
| 735 | |
| 736 | VBoxContainer *container = memnew(VBoxContainer); |
| 737 | unique_resources_confirmation->add_child(container); |
| 738 | |
| 739 | unique_resources_label = memnew(Label); |
| 740 | container->add_child(unique_resources_label); |
| 741 | |
| 742 | unique_resources_list_tree = memnew(Tree); |
| 743 | unique_resources_list_tree->set_hide_root(true); |
| 744 | unique_resources_list_tree->set_columns(1); |
| 745 | unique_resources_list_tree->set_column_title(0, TTR("Property" )); |
| 746 | unique_resources_list_tree->set_custom_minimum_size(Size2(0, 200 * EDSCALE)); |
| 747 | container->add_child(unique_resources_list_tree); |
| 748 | |
| 749 | Label *bottom_label = memnew(Label); |
| 750 | bottom_label->set_text(TTR("This cannot be undone. Are you sure?" )); |
| 751 | container->add_child(bottom_label); |
| 752 | |
| 753 | unique_resources_confirmation->connect("confirmed" , callable_mp(this, &InspectorDock::_menu_confirm_current)); |
| 754 | |
| 755 | info_dialog = memnew(AcceptDialog); |
| 756 | EditorNode::get_singleton()->get_gui_base()->add_child(info_dialog); |
| 757 | |
| 758 | load_resource_dialog = memnew(EditorFileDialog); |
| 759 | add_child(load_resource_dialog); |
| 760 | load_resource_dialog->set_current_dir("res://" ); |
| 761 | load_resource_dialog->connect("file_selected" , callable_mp(this, &InspectorDock::_resource_file_selected)); |
| 762 | |
| 763 | inspector = memnew(EditorInspector); |
| 764 | add_child(inspector); |
| 765 | inspector->set_autoclear(true); |
| 766 | inspector->set_show_categories(true); |
| 767 | inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 768 | inspector->set_use_doc_hints(true); |
| 769 | inspector->set_hide_script(false); |
| 770 | inspector->set_hide_metadata(false); |
| 771 | inspector->set_use_settings_name_style(false); |
| 772 | inspector->set_property_name_style(property_name_style); |
| 773 | inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding" ))); |
| 774 | inspector->register_text_enter(search); |
| 775 | |
| 776 | inspector->set_use_filter(true); // TODO: check me |
| 777 | |
| 778 | inspector->connect("resource_selected" , callable_mp(this, &InspectorDock::_resource_selected)); |
| 779 | } |
| 780 | |
| 781 | InspectorDock::~InspectorDock() { |
| 782 | singleton = nullptr; |
| 783 | } |
| 784 | |