2018-08-29 20:38:13 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_sectioned_inspector.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2018-08-29 20:38:13 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
#include "editor_sectioned_inspector.h"
|
2022-02-28 12:06:31 +00:00
|
|
|
|
|
|
|
#include "editor_property_name_processor.h"
|
2018-07-19 21:58:15 +00:00
|
|
|
#include "editor_scale.h"
|
2022-02-28 12:06:31 +00:00
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
class SectionedInspectorFilter : public Object {
|
|
|
|
GDCLASS(SectionedInspectorFilter, Object);
|
|
|
|
|
|
|
|
Object *edited;
|
|
|
|
String section;
|
|
|
|
bool allow_sub;
|
|
|
|
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!edited) {
|
2018-07-19 21:58:15 +00:00
|
|
|
return false;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
String name = p_name;
|
|
|
|
if (section != "") {
|
|
|
|
name = section + "/" + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid;
|
|
|
|
edited->set(name, p_value, &valid);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!edited) {
|
2018-07-19 21:58:15 +00:00
|
|
|
return false;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
String name = p_name;
|
|
|
|
if (section != "") {
|
|
|
|
name = section + "/" + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid = false;
|
|
|
|
|
|
|
|
r_ret = edited->get(name, &valid);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!edited) {
|
2018-07-19 21:58:15 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
edited->get_property_list(&pinfo);
|
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
|
|
|
PropertyInfo pi = E->get();
|
|
|
|
int sp = pi.name.find("/");
|
|
|
|
|
2021-05-05 10:44:11 +00: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 21:58:15 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
if (sp == -1) {
|
|
|
|
pi.name = "global/" + pi.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pi.name.begins_with(section + "/")) {
|
|
|
|
pi.name = pi.name.replace_first(section + "/", "");
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!allow_sub && pi.name.find("/") != -1) {
|
2018-07-19 21:58:15 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
p_list->push_back(pi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool property_can_revert(const String &p_name) {
|
|
|
|
return edited->call("property_can_revert", section + "/" + p_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant property_get_revert(const String &p_name) {
|
|
|
|
return edited->call("property_get_revert", section + "/" + p_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods() {
|
|
|
|
ClassDB::bind_method("property_can_revert", &SectionedInspectorFilter::property_can_revert);
|
|
|
|
ClassDB::bind_method("property_get_revert", &SectionedInspectorFilter::property_get_revert);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_section(const String &p_section, bool p_allow_sub) {
|
|
|
|
section = p_section;
|
|
|
|
allow_sub = p_allow_sub;
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_edited(Object *p_edited) {
|
|
|
|
edited = p_edited;
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionedInspectorFilter() {
|
2021-05-04 14:00:45 +00:00
|
|
|
edited = nullptr;
|
2018-07-19 21:58:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void SectionedInspector::_bind_methods() {
|
|
|
|
ClassDB::bind_method("_section_selected", &SectionedInspector::_section_selected);
|
|
|
|
ClassDB::bind_method("_search_changed", &SectionedInspector::_search_changed);
|
|
|
|
|
|
|
|
ClassDB::bind_method("update_category_list", &SectionedInspector::update_category_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::_section_selected() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!sections->get_selected()) {
|
2018-07-19 21:58:15 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
2019-07-11 07:56:08 +00:00
|
|
|
selected_category = sections->get_selected()->get_metadata(0);
|
2021-05-04 14:00:45 +00:00
|
|
|
filter->set_section(selected_category, sections->get_selected()->get_children() == nullptr);
|
2019-07-11 07:56:08 +00:00
|
|
|
inspector->set_property_prefix(selected_category + "/");
|
2018-07-19 21:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::set_current_section(const String &p_section) {
|
|
|
|
if (section_map.has(p_section)) {
|
|
|
|
section_map[p_section]->select(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String SectionedInspector::get_current_section() const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (sections->get_selected()) {
|
2018-07-19 21:58:15 +00:00
|
|
|
return sections->get_selected()->get_metadata(0);
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2018-07-19 21:58:15 +00:00
|
|
|
return "";
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String SectionedInspector::get_full_item_path(const String &p_item) {
|
|
|
|
String base = get_current_section();
|
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (base != "") {
|
2018-07-19 21:58:15 +00:00
|
|
|
return base + "/" + p_item;
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2018-07-19 21:58:15 +00:00
|
|
|
return p_item;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::edit(Object *p_object) {
|
|
|
|
if (!p_object) {
|
2019-11-20 15:22:16 +00:00
|
|
|
obj = 0;
|
2018-07-19 21:58:15 +00:00
|
|
|
sections->clear();
|
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
filter->set_edited(nullptr);
|
|
|
|
inspector->edit(nullptr);
|
2018-07-19 21:58:15 +00: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 07:56:08 +00:00
|
|
|
TreeItem *first_item = sections->get_root();
|
|
|
|
if (first_item) {
|
2021-05-05 10:44:11 +00:00
|
|
|
while (first_item->get_children()) {
|
2019-07-11 07:56:08 +00:00
|
|
|
first_item = first_item->get_children();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2019-07-11 07:56:08 +00:00
|
|
|
|
|
|
|
first_item->select(0);
|
|
|
|
selected_category = first_item->get_metadata(0);
|
2018-07-19 21:58:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
update_category_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::update_category_list() {
|
|
|
|
sections->clear();
|
|
|
|
|
|
|
|
Object *o = ObjectDB::get_instance(obj);
|
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!o) {
|
2018-07-19 21:58:15 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
o->get_property_list(&pinfo);
|
|
|
|
|
|
|
|
section_map.clear();
|
|
|
|
|
|
|
|
TreeItem *root = sections->create_item();
|
|
|
|
section_map[""] = root;
|
|
|
|
|
2019-07-11 07:56:08 +00:00
|
|
|
String filter;
|
2021-05-05 10:44:11 +00:00
|
|
|
if (search_box) {
|
2019-07-11 07:56:08 +00:00
|
|
|
filter = search_box->get_text();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2019-07-11 07:56:08 +00:00
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
|
|
|
PropertyInfo pi = E->get();
|
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (pi.usage & PROPERTY_USAGE_CATEGORY) {
|
2018-07-19 21:58:15 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
} else if (!(pi.usage & PROPERTY_USAGE_EDITOR)) {
|
2018-07-19 21:58:15 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (pi.name.find(":") != -1 || 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 21:58:15 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00:00
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!filter.empty() && pi.name.findn(filter) == -1 && pi.name.replace("/", " ").capitalize().findn(filter) == -1) {
|
2019-10-24 19:56:05 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2019-10-24 19:56:05 +00:00
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
int sp = pi.name.find("/");
|
2021-05-05 10:44:11 +00:00
|
|
|
if (sp == -1) {
|
2019-01-22 23:09:22 +00:00
|
|
|
pi.name = "global/" + pi.name;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-07-19 21:58:15 +00: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];
|
|
|
|
parent->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
|
|
|
|
|
|
|
|
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-02-28 12:06:31 +00:00
|
|
|
ms->set_text(0, EditorPropertyNameProcessor::get_singleton()->process_name(sectionarr[i]));
|
|
|
|
ms->set_tooltip(0, EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(sectionarr[i]));
|
2018-07-19 21:58:15 +00: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);
|
|
|
|
search_box->connect("text_changed", this, "_search_changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionedInspector::_search_changed(const String &p_what) {
|
|
|
|
update_category_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorInspector *SectionedInspector::get_inspector() {
|
|
|
|
return inspector;
|
|
|
|
}
|
|
|
|
|
2018-12-08 20:07:33 +00:00
|
|
|
SectionedInspector::SectionedInspector() :
|
2019-11-20 15:22:16 +00:00
|
|
|
obj(0),
|
2018-12-08 20:07:33 +00:00
|
|
|
sections(memnew(Tree)),
|
|
|
|
filter(memnew(SectionedInspectorFilter)),
|
|
|
|
inspector(memnew(EditorInspector)),
|
2021-05-04 14:00:45 +00:00
|
|
|
search_box(nullptr) {
|
2018-07-19 21:58:15 +00:00
|
|
|
add_constant_override("autohide", 1); // Fixes the dragger always showing up
|
|
|
|
|
|
|
|
VBoxContainer *left_vb = memnew(VBoxContainer);
|
2019-08-31 18:39:13 +00:00
|
|
|
left_vb->set_custom_minimum_size(Size2(190, 0) * EDSCALE);
|
2018-07-19 21:58:15 +00:00
|
|
|
add_child(left_vb);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
sections->connect("cell_selected", this, "_section_selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionedInspector::~SectionedInspector() {
|
|
|
|
memdelete(filter);
|
|
|
|
}
|