2018-08-29 22:38:13 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_sectioned_inspector.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
#include "editor_sectioned_inspector.h"
|
2020-05-12 17:01:17 +02:00
|
|
|
|
2024-09-21 15:11:58 +02:00
|
|
|
#include "editor/editor_inspector.h"
|
2022-03-03 11:25:11 +01:00
|
|
|
#include "editor/editor_property_name_processor.h"
|
2023-08-13 02:33:39 +02:00
|
|
|
#include "editor/editor_string_names.h"
|
2024-01-15 13:14:55 +01:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2024-09-21 15:11:58 +02:00
|
|
|
#include "scene/gui/check_button.h"
|
|
|
|
#include "scene/gui/tree.h"
|
2020-05-12 17:01:17 +02:00
|
|
|
|
2022-03-23 02:46:59 +01:00
|
|
|
static bool _property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) {
|
2024-05-06 10:26:10 +02:00
|
|
|
if (p_property_path.containsn(p_filter)) {
|
2022-03-17 18:16:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vector<String> sections = p_property_path.split("/");
|
|
|
|
for (int i = 0; i < sections.size(); i++) {
|
2023-10-05 15:12:10 +02:00
|
|
|
if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i], p_style, p_property_path))) {
|
2022-03-17 18:16:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
class SectionedInspectorFilter : public Object {
|
|
|
|
GDCLASS(SectionedInspectorFilter, Object);
|
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
Object *edited = nullptr;
|
2018-07-19 23:58:15 +02:00
|
|
|
String section;
|
2020-11-24 10:12:55 +01:00
|
|
|
bool allow_sub = false;
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!edited) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
String name = p_name;
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!section.is_empty()) {
|
2018-07-19 23:58:15 +02:00
|
|
|
name = section + "/" + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid;
|
|
|
|
edited->set(name, p_value, &valid);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!edited) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
String name = p_name;
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!section.is_empty()) {
|
2018-07-19 23:58:15 +02:00
|
|
|
name = section + "/" + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid = false;
|
|
|
|
|
|
|
|
r_ret = edited->get(name, &valid);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!edited) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
edited->get_property_list(&pinfo);
|
2021-07-16 05:45:57 +02:00
|
|
|
for (PropertyInfo &pi : pinfo) {
|
2018-07-19 23:58:15 +02:00
|
|
|
int sp = pi.name.find("/");
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (pi.name == "resource_path" || pi.name == "resource_name" || pi.name == "resource_local_to_scene" || pi.name.begins_with("script/") || pi.name.begins_with("_global_script")) { //skip resource stuff
|
2018-07-19 23:58:15 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
if (sp == -1) {
|
|
|
|
pi.name = "global/" + pi.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pi.name.begins_with(section + "/")) {
|
|
|
|
pi.name = pi.name.replace_first(section + "/", "");
|
2022-02-03 17:03:38 +01:00
|
|
|
if (!allow_sub && pi.name.contains("/")) {
|
2018-07-19 23:58:15 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
p_list->push_back(pi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 20:15:04 +02:00
|
|
|
bool _property_can_revert(const StringName &p_name) const {
|
2022-08-12 20:43:14 +02:00
|
|
|
return edited->property_can_revert(section + "/" + p_name);
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
2022-09-02 20:15:04 +02:00
|
|
|
bool _property_get_revert(const StringName &p_name, Variant &r_property) const {
|
|
|
|
r_property = edited->property_get_revert(section + "/" + p_name);
|
|
|
|
return true;
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_section(const String &p_section, bool p_allow_sub) {
|
|
|
|
section = p_section;
|
|
|
|
allow_sub = p_allow_sub;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_edited(Object *p_edited) {
|
|
|
|
edited = p_edited;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void SectionedInspector::_bind_methods() {
|
|
|
|
ClassDB::bind_method("update_category_list", &SectionedInspector::update_category_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::_section_selected() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!sections->get_selected()) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2019-07-11 09:56:08 +02:00
|
|
|
selected_category = sections->get_selected()->get_metadata(0);
|
2021-03-07 21:07:30 +01:00
|
|
|
filter->set_section(selected_category, sections->get_selected()->get_first_child() == nullptr);
|
2019-07-11 09:56:08 +02:00
|
|
|
inspector->set_property_prefix(selected_category + "/");
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::set_current_section(const String &p_section) {
|
|
|
|
if (section_map.has(p_section)) {
|
2022-10-06 12:51:30 +02:00
|
|
|
TreeItem *item = section_map[p_section];
|
|
|
|
item->select(0);
|
|
|
|
sections->scroll_to_item(item);
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String SectionedInspector::get_current_section() const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (sections->get_selected()) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return sections->get_selected()->get_metadata(0);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-07-19 23:58:15 +02:00
|
|
|
return "";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String SectionedInspector::get_full_item_path(const String &p_item) {
|
|
|
|
String base = get_current_section();
|
|
|
|
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!base.is_empty()) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return base + "/" + p_item;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-07-19 23:58:15 +02:00
|
|
|
return p_item;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::edit(Object *p_object) {
|
|
|
|
if (!p_object) {
|
2020-02-12 18:24:06 +01:00
|
|
|
obj = ObjectID();
|
2018-07-19 23:58:15 +02:00
|
|
|
sections->clear();
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
filter->set_edited(nullptr);
|
|
|
|
inspector->edit(nullptr);
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectID id = p_object->get_instance_id();
|
|
|
|
|
|
|
|
inspector->set_object_class(p_object->get_class());
|
|
|
|
|
|
|
|
if (obj != id) {
|
|
|
|
obj = id;
|
|
|
|
update_category_list();
|
|
|
|
|
|
|
|
filter->set_edited(p_object);
|
|
|
|
inspector->edit(filter);
|
|
|
|
|
2019-07-11 09:56:08 +02:00
|
|
|
TreeItem *first_item = sections->get_root();
|
|
|
|
if (first_item) {
|
2021-03-07 21:07:30 +01:00
|
|
|
while (first_item->get_first_child()) {
|
|
|
|
first_item = first_item->get_first_child();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-07-11 09:56:08 +02:00
|
|
|
|
|
|
|
first_item->select(0);
|
|
|
|
selected_category = first_item->get_metadata(0);
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
update_category_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::update_category_list() {
|
|
|
|
sections->clear();
|
|
|
|
|
|
|
|
Object *o = ObjectDB::get_instance(obj);
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!o) {
|
2018-07-19 23:58:15 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
o->get_property_list(&pinfo);
|
|
|
|
|
|
|
|
section_map.clear();
|
|
|
|
|
|
|
|
TreeItem *root = sections->create_item();
|
|
|
|
section_map[""] = root;
|
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
String filter_text;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (search_box) {
|
2022-09-29 11:53:28 +02:00
|
|
|
filter_text = search_box->get_text();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-07-11 09:56:08 +02:00
|
|
|
|
2022-03-23 02:46:59 +01:00
|
|
|
const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
|
|
|
|
const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
|
|
|
|
|
2021-07-16 05:45:57 +02:00
|
|
|
for (PropertyInfo &pi : pinfo) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (pi.usage & PROPERTY_USAGE_CATEGORY) {
|
2018-07-19 23:58:15 +02:00
|
|
|
continue;
|
2022-11-29 02:42:19 +01:00
|
|
|
} else if (!(pi.usage & PROPERTY_USAGE_EDITOR) ||
|
|
|
|
(filter_text.is_empty() && restrict_to_basic && !(pi.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) {
|
2018-07-19 23:58:15 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2022-02-03 17:03:38 +01:00
|
|
|
if (pi.name.contains(":") || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script")) {
|
2018-07-19 23:58:15 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
if (!filter_text.is_empty() && !_property_path_matches(pi.name, filter_text, name_style)) {
|
2019-10-24 21:56:05 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-10-24 21:56:05 +02:00
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
int sp = pi.name.find("/");
|
2020-05-14 16:41:43 +02:00
|
|
|
if (sp == -1) {
|
2019-01-23 00:09:22 +01:00
|
|
|
pi.name = "global/" + pi.name;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
Vector<String> sectionarr = pi.name.split("/");
|
|
|
|
String metasection;
|
|
|
|
|
|
|
|
int sc = MIN(2, sectionarr.size() - 1);
|
|
|
|
|
|
|
|
for (int i = 0; i < sc; i++) {
|
|
|
|
TreeItem *parent = section_map[metasection];
|
2023-08-13 02:33:39 +02:00
|
|
|
//parent->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
|
|
|
parent->set_custom_font(0, get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
metasection += "/" + sectionarr[i];
|
|
|
|
} else {
|
|
|
|
metasection = sectionarr[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!section_map.has(metasection)) {
|
|
|
|
TreeItem *ms = sections->create_item(parent);
|
|
|
|
section_map[metasection] = ms;
|
2022-03-23 02:46:59 +01:00
|
|
|
|
2023-10-05 15:12:10 +02:00
|
|
|
const String text = EditorPropertyNameProcessor::get_singleton()->process_name(sectionarr[i], name_style, pi.name);
|
|
|
|
const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(sectionarr[i], tooltip_style, pi.name);
|
2022-03-23 02:46:59 +01:00
|
|
|
|
|
|
|
ms->set_text(0, text);
|
2022-08-29 15:55:49 +02:00
|
|
|
ms->set_tooltip_text(0, tooltip);
|
2018-07-19 23:58:15 +02:00
|
|
|
ms->set_metadata(0, metasection);
|
|
|
|
ms->set_selectable(0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == sc - 1) {
|
|
|
|
//if it has children, make selectable
|
|
|
|
section_map[metasection]->set_selectable(0, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (section_map.has(selected_category)) {
|
|
|
|
section_map[selected_category]->select(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inspector->update_tree();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::register_search_box(LineEdit *p_box) {
|
|
|
|
search_box = p_box;
|
|
|
|
inspector->register_text_enter(p_box);
|
2024-05-14 11:42:00 +02:00
|
|
|
search_box->connect(SceneStringName(text_changed), callable_mp(this, &SectionedInspector::_search_changed));
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 15:11:58 +02:00
|
|
|
void SectionedInspector::register_advanced_toggle(CheckButton *p_toggle) {
|
|
|
|
advanced_toggle = p_toggle;
|
|
|
|
advanced_toggle->connect(SceneStringName(toggled), callable_mp(this, &SectionedInspector::_advanced_toggled));
|
|
|
|
_advanced_toggled(advanced_toggle->is_pressed());
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
void SectionedInspector::_search_changed(const String &p_what) {
|
2024-09-21 15:11:58 +02:00
|
|
|
if (advanced_toggle) {
|
|
|
|
if (p_what.is_empty()) {
|
|
|
|
advanced_toggle->set_pressed_no_signal(!restrict_to_basic);
|
|
|
|
advanced_toggle->set_disabled(false);
|
|
|
|
advanced_toggle->set_tooltip_text(String());
|
|
|
|
} else {
|
|
|
|
advanced_toggle->set_pressed_no_signal(true);
|
|
|
|
advanced_toggle->set_disabled(true);
|
|
|
|
advanced_toggle->set_tooltip_text(TTR("Advanced settings are always shown when searching."));
|
|
|
|
}
|
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
update_category_list();
|
|
|
|
}
|
|
|
|
|
2024-09-21 15:11:58 +02:00
|
|
|
void SectionedInspector::_advanced_toggled(bool p_toggled_on) {
|
|
|
|
restrict_to_basic = !p_toggled_on;
|
|
|
|
update_category_list();
|
|
|
|
inspector->set_restrict_to_basic_settings(restrict_to_basic);
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 15:11:58 +02:00
|
|
|
EditorInspector *SectionedInspector::get_inspector() {
|
|
|
|
return inspector;
|
2021-02-17 17:44:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-08 21:07:33 +01:00
|
|
|
SectionedInspector::SectionedInspector() :
|
|
|
|
sections(memnew(Tree)),
|
|
|
|
filter(memnew(SectionedInspectorFilter)),
|
2020-05-12 17:01:17 +02:00
|
|
|
inspector(memnew(EditorInspector)) {
|
2022-02-08 10:14:58 +01:00
|
|
|
add_theme_constant_override("autohide", 1); // Fixes the dragger always showing up
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
VBoxContainer *left_vb = memnew(VBoxContainer);
|
2019-08-31 20:39:13 +02:00
|
|
|
left_vb->set_custom_minimum_size(Size2(190, 0) * EDSCALE);
|
2018-07-19 23:58:15 +02:00
|
|
|
add_child(left_vb);
|
|
|
|
|
2024-03-17 09:28:18 +01:00
|
|
|
sections->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
|
2018-07-19 23:58:15 +02:00
|
|
|
sections->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
sections->set_hide_root(true);
|
|
|
|
|
|
|
|
left_vb->add_child(sections, true);
|
|
|
|
|
|
|
|
VBoxContainer *right_vb = memnew(VBoxContainer);
|
|
|
|
right_vb->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
|
|
|
|
right_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
add_child(right_vb);
|
|
|
|
|
|
|
|
inspector->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
right_vb->add_child(inspector, true);
|
|
|
|
inspector->set_use_doc_hints(true);
|
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
sections->connect("cell_selected", callable_mp(this, &SectionedInspector::_section_selected));
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SectionedInspector::~SectionedInspector() {
|
|
|
|
memdelete(filter);
|
|
|
|
}
|