Skip to content

Commit d898f37

Browse files
committed
Merge pull request #75482 from ajreckof/color-hint-for-arrays-and-dictionnaries
Add colored margin in Inspector for arrays and dictionaries
2 parents 479b2ab + cba9606 commit d898f37

File tree

9 files changed

+191
-116
lines changed

9 files changed

+191
-116
lines changed

doc/classes/EditorSettings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@
750750
- [b]Localized:[/b] Displays the localized string for the current editor language if a translation is available for the given property. If no translation is available, falls back to [b]Capitalized[/b].
751751
[b]Note:[/b] To display translated setting names in Project Settings and Editor Settings, use [member interface/editor/localize_settings] instead.
752752
</member>
753+
<member name="interface/inspector/delimitate_all_container_and_resources" type="bool" setter="" getter="">
754+
If [code]true[/code], add a margin around Array, Dictionary, and Resource Editors that are not already colored.
755+
[b]Note:[/b] If [member interface/inspector/nested_color_mode] is set to [b]Containers &amp; Resources[/b] this parameter will have no effect since those editors will already be colored
756+
</member>
753757
<member name="interface/inspector/disable_folding" type="bool" setter="" getter="">
754758
If [code]true[/code], forces all property groups to be expanded in the Inspector dock and prevents collapsing them.
755759
</member>
@@ -765,6 +769,12 @@
765769
<member name="interface/inspector/max_array_dictionary_items_per_page" type="int" setter="" getter="">
766770
The number of [Array] or [Dictionary] items to display on each "page" in the inspector. Higher values allow viewing more values per page, but take more time to load. This increased load time is noticeable when selecting nodes that have array or dictionary properties in the editor.
767771
</member>
772+
<member name="interface/inspector/nested_color_mode" type="int" setter="" getter="">
773+
Control which property editors are colored when they are opened.
774+
- [b]Containers &amp; Resources:[/b] Color all Array, Dictionary, and Resource Editors.
775+
- [b]Resources:[/b] Color all Resource Editors.
776+
- [b]External Resources:[/b] Color Resource Editors that edits an external resource.
777+
</member>
768778
<member name="interface/inspector/open_resources_in_current_inspector" type="bool" setter="" getter="">
769779
If [code]true[/code], subresources can be edited in the current inspector view. If the resource type is defined in [member interface/inspector/resources_to_open_in_new_inspector] or if this setting is [code]false[/code], attempting to edit a subresource always opens a new inspector view.
770780
</member>

editor/editor_inspector.cpp

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,49 @@ StringName EditorProperty::_get_revert_property() const {
489489
return property;
490490
}
491491

492+
void EditorProperty::_update_property_bg() {
493+
// This function is to be called on EditorPropertyResource, EditorPropertyArray, and EditorPropertyDictionary.
494+
// Behavior is undetermined on any other EditorProperty.
495+
if (!is_inside_tree()) {
496+
return;
497+
}
498+
499+
begin_bulk_theme_override();
500+
501+
if (bottom_editor) {
502+
ColorationMode nested_color_mode = (ColorationMode)(int)EDITOR_GET("interface/inspector/nested_color_mode");
503+
bool delimitate_all_container_and_resources = EDITOR_GET("interface/inspector/delimitate_all_container_and_resources");
504+
int count_subinspectors = 0;
505+
if (is_colored(nested_color_mode)) {
506+
Node *n = this;
507+
while (n) {
508+
EditorProperty *ep = Object::cast_to<EditorProperty>(n);
509+
if (ep && ep->is_colored(nested_color_mode)) {
510+
count_subinspectors++;
511+
}
512+
n = n->get_parent();
513+
}
514+
count_subinspectors = MIN(16, count_subinspectors);
515+
}
516+
add_theme_style_override(SNAME("DictionaryAddItem"), get_theme_stylebox("DictionaryAddItem" + itos(count_subinspectors), EditorStringName(EditorStyles)));
517+
add_theme_constant_override("v_separation", 0);
518+
if (delimitate_all_container_and_resources || is_colored(nested_color_mode)) {
519+
add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(EditorStyles)));
520+
add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(EditorStyles)));
521+
add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), EditorStringName(EditorStyles)));
522+
bottom_editor->add_theme_style_override("panel", get_theme_stylebox("sub_inspector_bg" + itos(count_subinspectors), EditorStringName(EditorStyles)));
523+
} else {
524+
bottom_editor->add_theme_style_override("panel", get_theme_stylebox("sub_inspector_bg_no_border", EditorStringName(EditorStyles)));
525+
}
526+
} else {
527+
remove_theme_style_override("bg_selected");
528+
remove_theme_style_override("bg");
529+
remove_theme_color_override("property_color");
530+
}
531+
end_bulk_theme_override();
532+
queue_redraw();
533+
}
534+
492535
void EditorProperty::update_editor_property_status() {
493536
if (property == StringName()) {
494537
return; //no property, so nothing to do
@@ -3481,8 +3524,8 @@ void EditorInspector::edit(Object *p_object) {
34813524

34823525
next_object = p_object; // Some plugins need to know the next edited object when clearing the inspector.
34833526
if (object) {
3484-
_clear();
34853527
object->disconnect("property_list_changed", callable_mp(this, &EditorInspector::_changed_callback));
3528+
_clear();
34863529
}
34873530
per_array_page.clear();
34883531

@@ -3676,30 +3719,11 @@ void EditorInspector::set_use_wide_editors(bool p_enable) {
36763719
wide_editors = p_enable;
36773720
}
36783721

3679-
void EditorInspector::_update_inspector_bg() {
3680-
if (sub_inspector) {
3681-
int count_subinspectors = 0;
3682-
Node *n = get_parent();
3683-
while (n) {
3684-
EditorInspector *ei = Object::cast_to<EditorInspector>(n);
3685-
if (ei && ei->sub_inspector) {
3686-
count_subinspectors++;
3687-
}
3688-
n = n->get_parent();
3689-
}
3690-
count_subinspectors = MIN(15, count_subinspectors);
3691-
add_theme_style_override("panel", get_theme_stylebox("sub_inspector_bg" + itos(count_subinspectors), EditorStringName(Editor)));
3692-
} else {
3693-
add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
3694-
}
3695-
}
36963722
void EditorInspector::set_sub_inspector(bool p_enable) {
36973723
sub_inspector = p_enable;
36983724
if (!is_inside_tree()) {
36993725
return;
37003726
}
3701-
3702-
_update_inspector_bg();
37033727
}
37043728

37053729
void EditorInspector::set_use_deletable_properties(bool p_enabled) {
@@ -4014,7 +4038,7 @@ void EditorInspector::_notification(int p_what) {
40144038
case NOTIFICATION_READY: {
40154039
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed));
40164040
set_process(is_visible_in_tree());
4017-
_update_inspector_bg();
4041+
add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
40184042
} break;
40194043

40204044
case NOTIFICATION_ENTER_TREE: {
@@ -4088,10 +4112,6 @@ void EditorInspector::_notification(int p_what) {
40884112
} break;
40894113

40904114
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
4091-
if (EditorThemeManager::is_generated_theme_outdated()) {
4092-
_update_inspector_bg();
4093-
}
4094-
40954115
bool needs_update = false;
40964116

40974117
if (use_settings_name_style && EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
@@ -4101,6 +4121,7 @@ void EditorInspector::_notification(int p_what) {
41014121
needs_update = true;
41024122
}
41034123
}
4124+
41044125
if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/inspector")) {
41054126
needs_update = true;
41064127
}

editor/editor_inspector.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class EditorProperty : public Container {
6767
MENU_OPEN_DOCUMENTATION,
6868
};
6969

70+
enum ColorationMode {
71+
COLORATION_CONTAINER_RESOURCE,
72+
COLORATION_RESOURCE,
73+
COLORATION_EXTERNAL,
74+
};
75+
7076
private:
7177
String label;
7278
int text_size;
@@ -141,6 +147,8 @@ class EditorProperty : public Container {
141147
virtual Variant _get_cache_value(const StringName &p_prop, bool &r_valid) const;
142148
virtual StringName _get_revert_property() const;
143149

150+
void _update_property_bg();
151+
144152
public:
145153
void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false);
146154

@@ -177,6 +185,8 @@ class EditorProperty : public Container {
177185
void set_keying(bool p_keying);
178186
bool is_keying() const;
179187

188+
virtual bool is_colored(ColorationMode p_mode) { return false; }
189+
180190
void set_deletable(bool p_enable);
181191
bool is_deletable() const;
182192
void add_focusable(Control *p_control);
@@ -557,8 +567,6 @@ class EditorInspector : public ScrollContainer {
557567

558568
bool _is_property_disabled_by_feature_profile(const StringName &p_property);
559569

560-
void _update_inspector_bg();
561-
562570
ConfirmationDialog *add_meta_dialog = nullptr;
563571
LineEdit *add_meta_name = nullptr;
564572
OptionButton *add_meta_type = nullptr;

editor/editor_properties.cpp

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "editor/property_selector.h"
4949
#include "editor/scene_tree_dock.h"
5050
#include "editor/themes/editor_scale.h"
51+
#include "editor/themes/editor_theme_manager.h"
5152
#include "scene/2d/gpu_particles_2d.h"
5253
#include "scene/3d/fog_volume.h"
5354
#include "scene/3d/gpu_particles_3d.h"
@@ -3220,42 +3221,6 @@ void EditorPropertyResource::_open_editor_pressed() {
32203221
}
32213222
}
32223223

3223-
void EditorPropertyResource::_update_property_bg() {
3224-
if (!is_inside_tree()) {
3225-
return;
3226-
}
3227-
3228-
updating_theme = true;
3229-
3230-
begin_bulk_theme_override();
3231-
if (sub_inspector != nullptr) {
3232-
int count_subinspectors = 0;
3233-
Node *n = get_parent();
3234-
while (n) {
3235-
EditorInspector *ei = Object::cast_to<EditorInspector>(n);
3236-
if (ei && ei->is_sub_inspector()) {
3237-
count_subinspectors++;
3238-
}
3239-
n = n->get_parent();
3240-
}
3241-
count_subinspectors = MIN(15, count_subinspectors);
3242-
3243-
add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), EditorStringName(Editor)));
3244-
add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(Editor)));
3245-
add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(Editor)));
3246-
add_theme_constant_override("v_separation", 0);
3247-
} else {
3248-
add_theme_color_override("property_color", get_theme_color(SNAME("property_color"), SNAME("EditorProperty")));
3249-
add_theme_style_override("bg_selected", get_theme_stylebox(SNAME("bg_selected"), SNAME("EditorProperty")));
3250-
add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("EditorProperty")));
3251-
add_theme_constant_override("v_separation", get_theme_constant(SNAME("v_separation"), SNAME("EditorProperty")));
3252-
}
3253-
end_bulk_theme_override();
3254-
3255-
updating_theme = false;
3256-
queue_redraw();
3257-
}
3258-
32593224
void EditorPropertyResource::_update_preferred_shader() {
32603225
Node *parent = get_parent();
32613226
EditorProperty *parent_property = nullptr;
@@ -3362,12 +3327,10 @@ void EditorPropertyResource::update_property() {
33623327
sub_inspector->set_read_only(is_read_only());
33633328
sub_inspector->set_use_folding(is_using_folding());
33643329

3365-
sub_inspector_vbox = memnew(VBoxContainer);
3366-
sub_inspector_vbox->set_mouse_filter(MOUSE_FILTER_STOP);
3367-
add_child(sub_inspector_vbox);
3368-
set_bottom_editor(sub_inspector_vbox);
3330+
sub_inspector->set_mouse_filter(MOUSE_FILTER_STOP);
3331+
add_child(sub_inspector);
3332+
set_bottom_editor(sub_inspector);
33693333

3370-
sub_inspector_vbox->add_child(sub_inspector);
33713334
resource_picker->set_toggle_pressed(true);
33723335

33733336
Array editor_list;
@@ -3383,20 +3346,18 @@ void EditorPropertyResource::update_property() {
33833346
_open_editor_pressed();
33843347
opened_editor = true;
33853348
}
3386-
3387-
_update_property_bg();
33883349
}
33893350

33903351
if (res.ptr() != sub_inspector->get_edited_object()) {
33913352
sub_inspector->edit(res.ptr());
3353+
_update_property_bg();
33923354
}
33933355

33943356
} else {
33953357
if (sub_inspector) {
33963358
set_bottom_editor(nullptr);
3397-
memdelete(sub_inspector_vbox);
3359+
memdelete(sub_inspector);
33983360
sub_inspector = nullptr;
3399-
sub_inspector_vbox = nullptr;
34003361

34013362
if (opened_editor) {
34023363
EditorNode::get_singleton()->hide_unused_editors();
@@ -3442,10 +3403,26 @@ void EditorPropertyResource::fold_resource() {
34423403
}
34433404
}
34443405

3406+
bool EditorPropertyResource::is_colored(ColorationMode p_mode) {
3407+
switch (p_mode) {
3408+
case COLORATION_CONTAINER_RESOURCE:
3409+
return sub_inspector != nullptr;
3410+
case COLORATION_RESOURCE:
3411+
return true;
3412+
case COLORATION_EXTERNAL:
3413+
if (sub_inspector) {
3414+
Resource *edited_resource = Object::cast_to<Resource>(sub_inspector->get_edited_object());
3415+
return edited_resource && !edited_resource->is_built_in();
3416+
}
3417+
break;
3418+
}
3419+
return false;
3420+
}
3421+
34453422
void EditorPropertyResource::_notification(int p_what) {
34463423
switch (p_what) {
34473424
case NOTIFICATION_THEME_CHANGED: {
3448-
if (!updating_theme) {
3425+
if (EditorThemeManager::is_generated_theme_outdated()) {
34493426
_update_property_bg();
34503427
}
34513428
} break;

editor/editor_properties.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,6 @@ class EditorPropertyResource : public EditorProperty {
699699

700700
bool use_sub_inspector = false;
701701
EditorInspector *sub_inspector = nullptr;
702-
VBoxContainer *sub_inspector_vbox = nullptr;
703-
bool updating_theme = false;
704702
bool opened_editor = false;
705703

706704
void _resource_selected(const Ref<Resource> &p_resource, bool p_inspect);
@@ -713,7 +711,6 @@ class EditorPropertyResource : public EditorProperty {
713711
void _sub_inspector_object_id_selected(int p_id);
714712

715713
void _open_editor_pressed();
716-
void _update_property_bg();
717714
void _update_preferred_shader();
718715

719716
protected:
@@ -731,6 +728,8 @@ class EditorPropertyResource : public EditorProperty {
731728
void set_use_sub_inspector(bool p_enable);
732729
void fold_resource();
733730

731+
virtual bool is_colored(ColorationMode p_mode) override;
732+
734733
EditorPropertyResource();
735734
};
736735

0 commit comments

Comments
 (0)