2018-05-17 08:01:47 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* inspector_dock.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2018-05-17 08:01:47 +02:00
|
|
|
/* */
|
|
|
|
/* 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 "inspector_dock.h"
|
|
|
|
|
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_settings.h"
|
|
|
|
#include "editor/plugins/animation_player_editor_plugin.h"
|
|
|
|
|
|
|
|
void InspectorDock::_menu_option(int p_option) {
|
|
|
|
switch (p_option) {
|
2018-09-05 04:03:10 +02:00
|
|
|
case EXPAND_ALL: {
|
|
|
|
_menu_expandall();
|
|
|
|
} break;
|
|
|
|
case COLLAPSE_ALL: {
|
|
|
|
_menu_collapseall();
|
|
|
|
} break;
|
2018-08-20 18:38:18 +02:00
|
|
|
case RESOURCE_MAKE_BUILT_IN: {
|
|
|
|
_unref_resource();
|
|
|
|
} break;
|
|
|
|
case RESOURCE_COPY: {
|
|
|
|
_copy_resource();
|
|
|
|
} break;
|
|
|
|
case RESOURCE_EDIT_CLIPBOARD: {
|
|
|
|
_paste_resource();
|
|
|
|
} break;
|
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
case RESOURCE_SAVE: {
|
|
|
|
_save_resource(false);
|
|
|
|
} break;
|
|
|
|
case RESOURCE_SAVE_AS: {
|
|
|
|
_save_resource(true);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case OBJECT_REQUEST_HELP: {
|
|
|
|
if (current) {
|
|
|
|
editor->set_visible_editor(EditorNode::EDITOR_SCRIPT);
|
|
|
|
emit_signal("request_help", current->get_class());
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case OBJECT_COPY_PARAMS: {
|
|
|
|
editor_data->apply_changes_in_editors();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (current) {
|
2018-05-17 08:01:47 +02:00
|
|
|
editor_data->copy_object_params(current);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case OBJECT_PASTE_PARAMS: {
|
|
|
|
editor_data->apply_changes_in_editors();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (current) {
|
2018-05-17 08:01:47 +02:00
|
|
|
editor_data->paste_object_params(current);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
} 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 (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
|
2018-05-17 08:01:47 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
res = duplicates[res];
|
|
|
|
|
|
|
|
current->set(E->get().name, res);
|
2018-09-16 01:50:20 +02:00
|
|
|
editor->get_inspector()->update_property(E->get().name);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().clear_history();
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
editor->get_editor_plugins_over()->edit(nullptr);
|
2018-05-17 08:01:47 +02:00
|
|
|
editor->get_editor_plugins_over()->edit(current);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
if (p_option >= OBJECT_METHOD_BASE) {
|
|
|
|
ERR_FAIL_COND(!current);
|
|
|
|
|
|
|
|
int idx = p_option - OBJECT_METHOD_BASE;
|
|
|
|
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
current->get_method_list(&methods);
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX(idx, methods.size());
|
|
|
|
String name = methods[idx].name;
|
|
|
|
|
2019-04-08 11:03:37 +02:00
|
|
|
current->call(name);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_new_resource() {
|
|
|
|
new_resource_dialog->popup_create(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_load_resource(const String &p_type) {
|
2020-03-06 18:00:16 +01:00
|
|
|
load_resource_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
List<String> extensions;
|
|
|
|
ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions);
|
|
|
|
|
|
|
|
load_resource_dialog->clear_filters();
|
|
|
|
for (int i = 0; i < extensions.size(); i++) {
|
|
|
|
load_resource_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
|
|
|
|
}
|
|
|
|
|
2020-07-11 18:45:19 +02:00
|
|
|
load_resource_dialog->popup_file_dialog();
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_resource_file_selected(String p_file) {
|
|
|
|
RES res = ResourceLoader::load(p_file);
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
if (res.is_null()) {
|
|
|
|
warning_dialog->set_text(TTR("Failed to load resource."));
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
editor->push_item(res.operator->());
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:29:59 +02:00
|
|
|
void InspectorDock::_save_resource(bool save_as) {
|
2020-02-12 18:24:06 +01:00
|
|
|
ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current();
|
2020-04-02 01:20:12 +02:00
|
|
|
Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
|
2018-05-17 08:01:47 +02:00
|
|
|
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
RES current_res = RES(Object::cast_to<Resource>(current_obj));
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (save_as) {
|
2018-05-17 08:01:47 +02:00
|
|
|
editor->save_resource_as(current_res);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-05-17 08:01:47 +02:00
|
|
|
editor->save_resource(current_res);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:29:59 +02:00
|
|
|
void InspectorDock::_unref_resource() {
|
2020-02-12 18:24:06 +01:00
|
|
|
ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current();
|
2020-04-02 01:20:12 +02:00
|
|
|
Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
|
2018-05-17 08:01:47 +02:00
|
|
|
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
RES current_res = RES(Object::cast_to<Resource>(current_obj));
|
|
|
|
current_res->set_path("");
|
|
|
|
editor->edit_current();
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:29:59 +02:00
|
|
|
void InspectorDock::_copy_resource() {
|
2020-02-12 18:24:06 +01:00
|
|
|
ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current();
|
2020-04-02 01:20:12 +02:00
|
|
|
Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
|
2018-05-17 08:01:47 +02:00
|
|
|
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
RES current_res = RES(Object::cast_to<Resource>(current_obj));
|
|
|
|
|
|
|
|
EditorSettings::get_singleton()->set_resource_clipboard(current_res);
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:29:59 +02:00
|
|
|
void InspectorDock::_paste_resource() {
|
2018-05-17 08:01:47 +02:00
|
|
|
RES r = EditorSettings::get_singleton()->get_resource_clipboard();
|
|
|
|
if (r.is_valid()) {
|
|
|
|
editor->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_prepare_history() {
|
|
|
|
EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
|
|
|
|
|
|
|
|
int history_to = MAX(0, editor_history->get_history_len() - 25);
|
|
|
|
|
|
|
|
history_menu->get_popup()->clear();
|
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<Texture2D> base_icon = get_theme_icon("Object", "EditorIcons");
|
2018-05-17 08:01:47 +02:00
|
|
|
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)) {
|
|
|
|
if (history_to > 0) {
|
|
|
|
history_to--;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
already.insert(id);
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj, "");
|
2018-09-02 23:40:51 +02:00
|
|
|
if (icon.is_null()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
icon = base_icon;
|
2018-09-02 23:40:51 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
String text;
|
|
|
|
if (Object::cast_to<Resource>(obj)) {
|
|
|
|
Resource *r = Object::cast_to<Resource>(obj);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r->get_path().is_resource_file()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
text = r->get_path().get_file();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (r->get_name() != String()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
text = r->get_name();
|
|
|
|
} else {
|
|
|
|
text = r->get_class();
|
|
|
|
}
|
|
|
|
} else if (Object::cast_to<Node>(obj)) {
|
|
|
|
text = Object::cast_to<Node>(obj)->get_name();
|
2020-02-07 02:52:05 +01:00
|
|
|
} else if (obj->is_class("EditorDebuggerRemoteObject")) {
|
2018-05-17 08:01:47 +02:00
|
|
|
text = obj->call("get_title");
|
|
|
|
} else {
|
|
|
|
text = obj->get_class();
|
|
|
|
}
|
|
|
|
|
2019-09-05 00:38:23 +02:00
|
|
|
if (i == editor_history->get_history_pos() && current) {
|
2018-05-17 08:01:47 +02:00
|
|
|
text = "[" + text + "]";
|
|
|
|
}
|
|
|
|
history_menu->get_popup()->add_icon_item(icon, text, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 17:44:59 +01:00
|
|
|
void InspectorDock::_select_history(int p_idx) {
|
2018-05-17 08:01:47 +02:00
|
|
|
//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);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!obj) {
|
2018-05-17 08:01:47 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
editor->push_item(obj);
|
|
|
|
}
|
|
|
|
|
2020-02-21 17:44:59 +01:00
|
|
|
void InspectorDock::_resource_created() {
|
2021-01-06 20:25:05 +01:00
|
|
|
Variant c = new_resource_dialog->instance_selected();
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!c);
|
|
|
|
Resource *r = Object::cast_to<Resource>(c);
|
|
|
|
ERR_FAIL_COND(!r);
|
|
|
|
|
2021-01-06 20:25:05 +01:00
|
|
|
editor->push_item(r);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 17:44:59 +01:00
|
|
|
void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_res.is_null()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
RES r = p_res;
|
|
|
|
editor->push_item(r.operator->(), p_property);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_edit_forward() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (EditorNode::get_singleton()->get_editor_history()->next()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
editor->edit_current();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
void InspectorDock::_edit_back() {
|
|
|
|
EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
|
2020-05-14 16:41:43 +02:00
|
|
|
if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) {
|
2018-05-17 08:01:47 +02:00
|
|
|
editor->edit_current();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_menu_collapseall() {
|
|
|
|
inspector->collapse_all_folding();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_menu_expandall() {
|
|
|
|
inspector->expand_all_folding();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance) {
|
2018-06-07 17:46:14 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_track_editor()->insert_value_key(p_keyed, p_value, p_advance);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D *s = Object::cast_to<Node3D>(sp);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!s) {
|
2018-05-17 08:01:47 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-06-07 17:46:14 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::_warning_pressed() {
|
2020-03-06 18:00:16 +01:00
|
|
|
warning_dialog->popup_centered();
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Container *InspectorDock::get_addon_area() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-10-05 20:37:26 +02:00
|
|
|
void InspectorDock::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2020-09-03 13:22:16 +02:00
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED:
|
|
|
|
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
|
2018-10-05 20:37:26 +02:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
|
|
|
set_theme(editor->get_gui_base()->get_theme());
|
2020-03-12 13:37:40 +01:00
|
|
|
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"));
|
2020-09-03 13:22:16 +02:00
|
|
|
if (is_layout_rtl()) {
|
|
|
|
backward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
|
|
|
|
forward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
|
|
|
|
} else {
|
|
|
|
backward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
|
|
|
|
forward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
|
|
|
|
}
|
2020-03-12 13:37:40 +01:00
|
|
|
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"));
|
2018-10-05 20:37:26 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
void InspectorDock::_bind_methods() {
|
|
|
|
ClassDB::bind_method("update_keying", &InspectorDock::update_keying);
|
2020-02-21 23:26:13 +01:00
|
|
|
ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed); // Still used by some connect_compat.
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
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("_menu_collapseall", &InspectorDock::_menu_collapseall);
|
|
|
|
ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall);
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("request_help"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::edit_resource(const Ref<Resource> &p_resource) {
|
|
|
|
_resource_selected(p_resource, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::open_resource(const String &p_type) {
|
|
|
|
_load_resource(p_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectorDock::set_warning(const String &p_message) {
|
|
|
|
warning->hide();
|
|
|
|
if (p_message != String()) {
|
|
|
|
warning->show();
|
|
|
|
warning_dialog->set_text(p_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
history_menu->set_disabled(true);
|
|
|
|
if (editor_history->get_history_len() > 0) {
|
|
|
|
history_menu->set_disabled(false);
|
|
|
|
}
|
|
|
|
editor_path->update_path();
|
|
|
|
|
|
|
|
current = p_object;
|
|
|
|
|
|
|
|
if (!p_object) {
|
|
|
|
object_menu->set_disabled(true);
|
|
|
|
warning->hide();
|
|
|
|
search->set_editable(false);
|
|
|
|
|
2019-09-04 23:30:03 +02:00
|
|
|
editor_path->set_disabled(true);
|
2019-09-04 08:41:49 +02:00
|
|
|
editor_path->set_text("");
|
|
|
|
editor_path->set_tooltip("");
|
2020-04-02 01:20:12 +02:00
|
|
|
editor_path->set_icon(nullptr);
|
2019-09-04 08:41:49 +02:00
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_resource = p_object->is_class("Resource");
|
|
|
|
bool is_node = p_object->is_class("Node");
|
|
|
|
|
|
|
|
object_menu->set_disabled(false);
|
|
|
|
search->set_editable(true);
|
2019-09-04 23:30:03 +02:00
|
|
|
editor_path->set_disabled(false);
|
2018-12-13 22:24:25 +01:00
|
|
|
resource_save_button->set_disabled(!is_resource);
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
PopupMenu *p = object_menu->get_popup();
|
|
|
|
|
|
|
|
p->clear();
|
2018-09-13 04:53:10 +02:00
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/expand_all", TTR("Expand All Properties")), EXPAND_ALL);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All Properties")), COLLAPSE_ALL);
|
2018-05-17 08:01:47 +02:00
|
|
|
p->add_separator();
|
|
|
|
if (is_resource) {
|
|
|
|
p->add_item(TTR("Save"), RESOURCE_SAVE);
|
|
|
|
p->add_item(TTR("Save As..."), RESOURCE_SAVE_AS);
|
|
|
|
p->add_separator();
|
|
|
|
}
|
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Params")), OBJECT_COPY_PARAMS);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Params")), OBJECT_PASTE_PARAMS);
|
|
|
|
p->add_separator();
|
2018-08-20 18:38:18 +02:00
|
|
|
|
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource Clipboard")), RESOURCE_EDIT_CLIPBOARD);
|
2018-05-17 08:01:47 +02:00
|
|
|
if (is_resource) {
|
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
|
2018-08-20 18:38:18 +02:00
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Built-In")), RESOURCE_MAKE_BUILT_IN);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_resource || is_node) {
|
|
|
|
p->add_separator();
|
|
|
|
p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
|
|
|
|
p->add_separator();
|
2020-03-12 13:37:40 +01:00
|
|
|
p->add_icon_shortcut(get_theme_icon("HelpSearch", "EditorIcons"), ED_SHORTCUT("property_editor/open_help", TTR("Open in Help")), OBJECT_REQUEST_HELP);
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
p_object->get_method_list(&methods);
|
|
|
|
|
2020-12-15 13:04:21 +01:00
|
|
|
if (!methods.is_empty()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
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();
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
I = I->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-07 17:46:14 +02:00
|
|
|
void InspectorDock::go_back() {
|
|
|
|
_edit_back();
|
|
|
|
}
|
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
void InspectorDock::update_keying() {
|
|
|
|
bool valid = false;
|
|
|
|
|
2018-06-07 17:46:14 +02:00
|
|
|
if (AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) {
|
2018-05-17 08:01:47 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
|
|
|
|
set_name("Inspector");
|
|
|
|
set_theme(p_editor->get_gui_base()->get_theme());
|
|
|
|
|
|
|
|
editor = p_editor;
|
|
|
|
editor_data = &p_editor_data;
|
|
|
|
|
|
|
|
HBoxContainer *general_options_hb = memnew(HBoxContainer);
|
|
|
|
add_child(general_options_hb);
|
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
resource_new_button = memnew(Button);
|
|
|
|
resource_new_button->set_flat(true);
|
2018-05-17 08:01:47 +02:00
|
|
|
resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it."));
|
2020-03-12 13:37:40 +01:00
|
|
|
resource_new_button->set_icon(get_theme_icon("New", "EditorIcons"));
|
2018-05-17 08:01:47 +02:00
|
|
|
general_options_hb->add_child(resource_new_button);
|
2020-02-20 19:32:36 +01:00
|
|
|
resource_new_button->connect("pressed", callable_mp(this, &InspectorDock::_new_resource));
|
2018-05-17 08:01:47 +02:00
|
|
|
resource_new_button->set_focus_mode(Control::FOCUS_NONE);
|
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
resource_load_button = memnew(Button);
|
|
|
|
resource_load_button->set_flat(true);
|
2018-05-17 08:01:47 +02:00
|
|
|
resource_load_button->set_tooltip(TTR("Load an existing resource from disk and edit it."));
|
2020-03-12 13:37:40 +01:00
|
|
|
resource_load_button->set_icon(get_theme_icon("Load", "EditorIcons"));
|
2018-05-17 08:01:47 +02:00
|
|
|
general_options_hb->add_child(resource_load_button);
|
2020-02-21 18:28:45 +01:00
|
|
|
resource_load_button->connect("pressed", callable_mp(this, &InspectorDock::_open_resource_selector));
|
2018-05-17 08:01:47 +02:00
|
|
|
resource_load_button->set_focus_mode(Control::FOCUS_NONE);
|
|
|
|
|
2018-12-13 22:24:25 +01:00
|
|
|
resource_save_button = memnew(MenuButton);
|
|
|
|
resource_save_button->set_tooltip(TTR("Save the currently edited resource."));
|
2020-03-12 13:37:40 +01:00
|
|
|
resource_save_button->set_icon(get_theme_icon("Save", "EditorIcons"));
|
2018-12-13 22:24:25 +01:00
|
|
|
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);
|
2020-02-21 18:28:45 +01:00
|
|
|
resource_save_button->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
|
2018-12-13 22:24:25 +01:00
|
|
|
resource_save_button->set_focus_mode(Control::FOCUS_NONE);
|
|
|
|
resource_save_button->set_disabled(true);
|
|
|
|
|
2018-05-17 08:01:47 +02:00
|
|
|
general_options_hb->add_spacer();
|
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
backward_button = memnew(Button);
|
|
|
|
backward_button->set_flat(true);
|
2018-05-17 08:01:47 +02:00
|
|
|
general_options_hb->add_child(backward_button);
|
2020-09-03 13:22:16 +02:00
|
|
|
if (is_layout_rtl()) {
|
|
|
|
backward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
|
|
|
|
} else {
|
|
|
|
backward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
|
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
backward_button->set_tooltip(TTR("Go to the previous edited object in history."));
|
|
|
|
backward_button->set_disabled(true);
|
2020-02-21 18:28:45 +01:00
|
|
|
backward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_back));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
forward_button = memnew(Button);
|
|
|
|
forward_button->set_flat(true);
|
2018-05-17 08:01:47 +02:00
|
|
|
general_options_hb->add_child(forward_button);
|
2020-09-03 13:22:16 +02:00
|
|
|
if (is_layout_rtl()) {
|
|
|
|
forward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
|
|
|
|
} else {
|
|
|
|
forward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
|
|
|
|
}
|
2018-05-17 08:01:47 +02:00
|
|
|
forward_button->set_tooltip(TTR("Go to the next edited object in history."));
|
|
|
|
forward_button->set_disabled(true);
|
2020-02-21 18:28:45 +01:00
|
|
|
forward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_forward));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
history_menu = memnew(MenuButton);
|
|
|
|
history_menu->set_tooltip(TTR("History of recently edited objects."));
|
2020-03-12 13:37:40 +01:00
|
|
|
history_menu->set_icon(get_theme_icon("History", "EditorIcons"));
|
2018-05-17 08:01:47 +02:00
|
|
|
general_options_hb->add_child(history_menu);
|
2020-03-12 13:37:40 +01:00
|
|
|
history_menu->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_history));
|
2020-02-21 18:28:45 +01:00
|
|
|
history_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_select_history));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
HBoxContainer *node_info_hb = memnew(HBoxContainer);
|
|
|
|
add_child(node_info_hb);
|
|
|
|
|
|
|
|
editor_path = memnew(EditorPath(editor->get_editor_history()));
|
|
|
|
editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
node_info_hb->add_child(editor_path);
|
|
|
|
|
|
|
|
object_menu = memnew(MenuButton);
|
2020-09-17 03:40:00 +02:00
|
|
|
object_menu->set_shortcut_context(this);
|
2020-03-12 13:37:40 +01:00
|
|
|
object_menu->set_icon(get_theme_icon("Tools", "EditorIcons"));
|
2018-05-17 08:01:47 +02:00
|
|
|
node_info_hb->add_child(object_menu);
|
|
|
|
object_menu->set_tooltip(TTR("Object properties."));
|
2020-02-21 18:28:45 +01:00
|
|
|
object_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
new_resource_dialog = memnew(CreateDialog);
|
|
|
|
editor->get_gui_base()->add_child(new_resource_dialog);
|
|
|
|
new_resource_dialog->set_base_type("Resource");
|
2020-02-21 18:28:45 +01:00
|
|
|
new_resource_dialog->connect("create", callable_mp(this, &InspectorDock::_resource_created));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
search = memnew(LineEdit);
|
|
|
|
search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2018-05-18 02:45:12 +02:00
|
|
|
search->set_placeholder(TTR("Filter properties"));
|
2020-03-12 13:37:40 +01:00
|
|
|
search->set_right_icon(get_theme_icon("Search", "EditorIcons"));
|
2018-07-26 13:45:38 +02:00
|
|
|
search->set_clear_button_enabled(true);
|
2018-05-17 08:01:47 +02:00
|
|
|
add_child(search);
|
|
|
|
|
|
|
|
warning = memnew(Button);
|
|
|
|
add_child(warning);
|
|
|
|
warning->set_text(TTR("Changes may be lost!"));
|
2020-03-12 13:37:40 +01:00
|
|
|
warning->set_icon(get_theme_icon("NodeWarning", "EditorIcons"));
|
|
|
|
warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor"));
|
2020-01-29 16:52:07 +01:00
|
|
|
warning->set_clip_text(true);
|
2018-05-17 08:01:47 +02:00
|
|
|
warning->hide();
|
2020-02-21 18:28:45 +01:00
|
|
|
warning->connect("pressed", callable_mp(this, &InspectorDock::_warning_pressed));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
warning_dialog = memnew(AcceptDialog);
|
|
|
|
editor->get_gui_base()->add_child(warning_dialog);
|
|
|
|
|
|
|
|
load_resource_dialog = memnew(EditorFileDialog);
|
|
|
|
add_child(load_resource_dialog);
|
|
|
|
load_resource_dialog->set_current_dir("res://");
|
2020-02-21 18:28:45 +01:00
|
|
|
load_resource_dialog->connect("file_selected", callable_mp(this, &InspectorDock::_resource_file_selected));
|
2018-05-17 08:01:47 +02:00
|
|
|
|
|
|
|
inspector = memnew(EditorInspector);
|
|
|
|
add_child(inspector);
|
|
|
|
inspector->set_autoclear(true);
|
|
|
|
inspector->set_show_categories(true);
|
|
|
|
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
inspector->set_use_doc_hints(true);
|
2019-07-22 12:03:57 +02:00
|
|
|
inspector->set_hide_script(false);
|
2018-06-14 20:36:38 +02:00
|
|
|
inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties")));
|
|
|
|
inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
|
2018-05-17 08:01:47 +02:00
|
|
|
inspector->register_text_enter(search);
|
|
|
|
inspector->set_undo_redo(&editor_data->get_undo_redo());
|
|
|
|
|
|
|
|
inspector->set_use_filter(true); // TODO: check me
|
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected));
|
|
|
|
inspector->connect("property_keyed", callable_mp(this, &InspectorDock::_property_keyed));
|
2018-05-17 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InspectorDock::~InspectorDock() {
|
|
|
|
}
|