Editor: Fix categories and tooltips in `TileSet` editor

This commit is contained in:
Danil Alexeev 2024-05-14 10:23:14 +03:00
parent 557f63d037
commit 5a5b18c2fc
No known key found for this signature in database
GPG Key ID: 124453E157DA8DC7
6 changed files with 27 additions and 22 deletions

View File

@ -3699,12 +3699,8 @@ void EditorHelpBit::set_custom_text(const String &p_type, const String &p_name,
} }
} }
void EditorHelpBit::prepend_description(const String &p_text) { void EditorHelpBit::set_description(const String &p_text) {
if (help_data.description.is_empty()) {
help_data.description = p_text; help_data.description = p_text;
} else {
help_data.description = p_text + "\n" + help_data.description;
}
if (is_inside_tree()) { if (is_inside_tree()) {
_update_labels(); _update_labels();

View File

@ -311,7 +311,8 @@ protected:
public: public:
void parse_symbol(const String &p_symbol); void parse_symbol(const String &p_symbol);
void set_custom_text(const String &p_type, const String &p_name, const String &p_description); void set_custom_text(const String &p_type, const String &p_name, const String &p_description);
void prepend_description(const String &p_text); void set_description(const String &p_text);
_FORCE_INLINE_ String get_description() const { return help_data.description; }
void set_content_height_limits(float p_min, float p_max); void set_content_height_limits(float p_min, float p_max);
void update_content_height(); void update_content_height();

View File

@ -975,13 +975,17 @@ Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
if (inspector) { if (inspector) {
const String custom_description = inspector->get_custom_property_description(p_text); const String custom_description = inspector->get_custom_property_description(p_text);
if (!custom_description.is_empty()) { if (!custom_description.is_empty()) {
help_bit->prepend_description(custom_description); help_bit->set_description(custom_description);
} }
} }
} }
if (!custom_warning.is_empty()) { if (!custom_warning.is_empty()) {
help_bit->prepend_description("[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + custom_warning + "[/color][/b]"); String description = "[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + custom_warning + "[/color][/b]";
if (!help_bit->get_description().is_empty()) {
description += "\n" + help_bit->get_description();
}
help_bit->set_description(description);
} }
EditorHelpBitTooltip::show_tooltip(help_bit, const_cast<EditorProperty *>(this)); EditorHelpBitTooltip::show_tooltip(help_bit, const_cast<EditorProperty *>(this));
@ -2857,7 +2861,11 @@ void EditorInspector::update_tree() {
vbox_per_path.clear(); vbox_per_path.clear();
editor_inspector_array_per_prefix.clear(); editor_inspector_array_per_prefix.clear();
if (!show_categories) { // `hint_script` should contain a native class name or a script path.
// Otherwise the category was probably added via `@export_category` or `_get_property_list()`.
const bool is_custom_category = p.hint_string.is_empty();
if ((is_custom_category && !show_custom_categories) || (!is_custom_category && !show_standard_categories)) {
continue; continue;
} }
@ -2876,7 +2884,7 @@ void EditorInspector::update_tree() {
} }
// Treat custom categories as second-level ones. Do not skip a normal category if it is followed by a custom one. // Treat custom categories as second-level ones. Do not skip a normal category if it is followed by a custom one.
// Skip in the other 3 cases (normal -> normal, custom -> custom, custom -> normal). // Skip in the other 3 cases (normal -> normal, custom -> custom, custom -> normal).
if ((N->get().usage & PROPERTY_USAGE_CATEGORY) && (p.hint_string.is_empty() || !N->get().hint_string.is_empty())) { if ((N->get().usage & PROPERTY_USAGE_CATEGORY) && (is_custom_category || !N->get().hint_string.is_empty())) {
valid = false; valid = false;
break; break;
} }
@ -2891,10 +2899,8 @@ void EditorInspector::update_tree() {
main_vbox->add_child(category); main_vbox->add_child(category);
category_vbox = nullptr; //reset category_vbox = nullptr; //reset
// `hint_script` should contain a native class name or a script path.
// Otherwise the category was probably added via `@export_category` or `_get_property_list()`.
// Do not add an icon, do not change the current class (`doc_name`) for custom categories. // Do not add an icon, do not change the current class (`doc_name`) for custom categories.
if (p.hint_string.is_empty()) { if (is_custom_category) {
category->label = p.name; category->label = p.name;
category->set_tooltip_text(p.name); category->set_tooltip_text(p.name);
} else { } else {
@ -3596,8 +3602,9 @@ void EditorInspector::set_autoclear(bool p_enable) {
autoclear = p_enable; autoclear = p_enable;
} }
void EditorInspector::set_show_categories(bool p_show) { void EditorInspector::set_show_categories(bool p_show_standard, bool p_show_custom) {
show_categories = p_show; show_standard_categories = p_show_standard;
show_custom_categories = p_show_custom;
update_tree(); update_tree();
} }
@ -4151,7 +4158,7 @@ String EditorInspector::get_property_prefix() const {
} }
void EditorInspector::add_custom_property_description(const String &p_class, const String &p_property, const String &p_description) { void EditorInspector::add_custom_property_description(const String &p_class, const String &p_property, const String &p_description) {
const String key = vformat("property|%s|%s|", p_class, p_property); const String key = vformat("property|%s|%s", p_class, p_property);
custom_property_descriptions[key] = p_description; custom_property_descriptions[key] = p_description;
} }

View File

@ -494,7 +494,8 @@ class EditorInspector : public ScrollContainer {
// //
LineEdit *search_box = nullptr; LineEdit *search_box = nullptr;
bool show_categories = false; bool show_standard_categories = false;
bool show_custom_categories = false;
bool hide_script = true; bool hide_script = true;
bool hide_metadata = true; bool hide_metadata = true;
bool use_doc_hints = false; bool use_doc_hints = false;
@ -610,7 +611,7 @@ public:
void set_autoclear(bool p_enable); void set_autoclear(bool p_enable);
void set_show_categories(bool p_show); void set_show_categories(bool p_show_standard, bool p_show_custom);
void set_use_doc_hints(bool p_enable); void set_use_doc_hints(bool p_enable);
void set_hide_script(bool p_hide); void set_hide_script(bool p_hide);
void set_hide_metadata(bool p_hide); void set_hide_metadata(bool p_hide);

View File

@ -787,7 +787,7 @@ InspectorDock::InspectorDock(EditorData &p_editor_data) {
inspector = memnew(EditorInspector); inspector = memnew(EditorInspector);
add_child(inspector); add_child(inspector);
inspector->set_autoclear(true); inspector->set_autoclear(true);
inspector->set_show_categories(true); inspector->set_show_categories(true, true);
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL); inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
inspector->set_use_doc_hints(true); inspector->set_use_doc_hints(true);
inspector->set_hide_script(false); inspector->set_hide_script(false);

View File

@ -2555,7 +2555,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
tile_inspector = memnew(EditorInspector); tile_inspector = memnew(EditorInspector);
tile_inspector->set_v_size_flags(SIZE_EXPAND_FILL); tile_inspector->set_v_size_flags(SIZE_EXPAND_FILL);
tile_inspector->set_show_categories(true); tile_inspector->set_show_categories(false, true);
tile_inspector->set_use_doc_hints(true); tile_inspector->set_use_doc_hints(true);
tile_inspector->set_use_folding(true); tile_inspector->set_use_folding(true);
tile_inspector->connect("property_selected", callable_mp(this, &TileSetAtlasSourceEditor::_inspector_property_selected)); tile_inspector->connect("property_selected", callable_mp(this, &TileSetAtlasSourceEditor::_inspector_property_selected));
@ -2609,7 +2609,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
atlas_source_inspector = memnew(EditorInspector); atlas_source_inspector = memnew(EditorInspector);
atlas_source_inspector->set_v_size_flags(SIZE_EXPAND_FILL); atlas_source_inspector->set_v_size_flags(SIZE_EXPAND_FILL);
atlas_source_inspector->set_show_categories(true); atlas_source_inspector->set_show_categories(false, true);
atlas_source_inspector->set_use_doc_hints(true); atlas_source_inspector->set_use_doc_hints(true);
atlas_source_inspector->add_inspector_plugin(memnew(TileSourceInspectorPlugin)); atlas_source_inspector->add_inspector_plugin(memnew(TileSourceInspectorPlugin));
middle_vbox_container->add_child(atlas_source_inspector); middle_vbox_container->add_child(atlas_source_inspector);