Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Fix categories and tooltips in TileSet editor #91932

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (help_data.description.is_empty()) {
help_data.description = p_text;
} else {
help_data.description = p_text + "\n" + help_data.description;
}
void EditorHelpBit::set_description(const String &p_text) {
help_data.description = p_text;

if (is_inside_tree()) {
_update_labels();
Expand Down
3 changes: 2 additions & 1 deletion editor/editor_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ class EditorHelpBit : public VBoxContainer {
public:
void parse_symbol(const String &p_symbol);
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 update_content_height();
Expand Down
27 changes: 17 additions & 10 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,13 +975,17 @@ Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
if (inspector) {
const String custom_description = inspector->get_custom_property_description(p_text);
if (!custom_description.is_empty()) {
help_bit->prepend_description(custom_description);
help_bit->set_description(custom_description);
}
}
}

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));
Expand Down Expand Up @@ -2857,7 +2861,11 @@ void EditorInspector::update_tree() {
vbox_per_path.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;
}

Expand All @@ -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.
// 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;
break;
}
Expand All @@ -2891,10 +2899,8 @@ void EditorInspector::update_tree() {
main_vbox->add_child(category);
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.
if (p.hint_string.is_empty()) {
if (is_custom_category) {
category->label = p.name;
category->set_tooltip_text(p.name);
} else {
Expand Down Expand Up @@ -3596,8 +3602,9 @@ void EditorInspector::set_autoclear(bool p_enable) {
autoclear = p_enable;
}

void EditorInspector::set_show_categories(bool p_show) {
show_categories = p_show;
void EditorInspector::set_show_categories(bool p_show_standard, bool p_show_custom) {
show_standard_categories = p_show_standard;
show_custom_categories = p_show_custom;
update_tree();
}

Expand Down Expand Up @@ -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) {
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;
}

Expand Down
5 changes: 3 additions & 2 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ class EditorInspector : public ScrollContainer {
//

LineEdit *search_box = nullptr;
bool show_categories = false;
bool show_standard_categories = false;
bool show_custom_categories = false;
bool hide_script = true;
bool hide_metadata = true;
bool use_doc_hints = false;
Expand Down Expand Up @@ -610,7 +611,7 @@ class EditorInspector : public ScrollContainer {

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_hide_script(bool p_hide);
void set_hide_metadata(bool p_hide);
Expand Down
2 changes: 1 addition & 1 deletion editor/inspector_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ InspectorDock::InspectorDock(EditorData &p_editor_data) {
inspector = memnew(EditorInspector);
add_child(inspector);
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_use_doc_hints(true);
inspector->set_hide_script(false);
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/tiles/tile_set_atlas_source_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {

tile_inspector = memnew(EditorInspector);
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_folding(true);
tile_inspector->connect("property_selected", callable_mp(this, &TileSetAtlasSourceEditor::_inspector_property_selected));
Expand Down Expand Up @@ -2609,7 +2609,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {

atlas_source_inspector = memnew(EditorInspector);
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->add_inspector_plugin(memnew(TileSourceInspectorPlugin));
middle_vbox_container->add_child(atlas_source_inspector);
Expand Down
Loading