Skip to content

Commit 109008b

Browse files
committed
Merge pull request godotengine#107765 from KoBeWi/overerrides
Improve editor settings override display
2 parents 16d3ba7 + 29148d7 commit 109008b

File tree

3 files changed

+64
-45
lines changed

3 files changed

+64
-45
lines changed

editor/icons/Hierarchy.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/settings/editor_settings_dialog.cpp

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,41 @@ EditorSettingsDialog::EditorSettingsDialog() {
10281028
EditorInspector::add_inspector_plugin(plugin);
10291029
}
10301030

1031+
void EditorSettingsPropertyWrapper::_setup_override_info() {
1032+
override_container = memnew(HBoxContainer);
1033+
1034+
override_icon = memnew(TextureRect);
1035+
override_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
1036+
override_container->add_child(override_icon);
1037+
1038+
Variant::Type type = ProjectSettings::get_singleton()->get_editor_setting_override(property).get_type();
1039+
override_editor_property = get_parent_inspector()->instantiate_property_editor(ProjectSettings::get_singleton(), type, ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property, hint, hint_text, usage);
1040+
override_editor_property->set_object_and_property(ProjectSettings::get_singleton(), ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property);
1041+
override_editor_property->set_read_only(true);
1042+
override_editor_property->set_label(TTR("Overridden in project"));
1043+
override_editor_property->set_h_size_flags(SIZE_EXPAND_FILL);
1044+
override_container->add_child(override_editor_property);
1045+
1046+
goto_button = memnew(Button);
1047+
goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings."));
1048+
override_container->add_child(goto_button);
1049+
if (EditorNode::get_singleton()) {
1050+
goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED);
1051+
}
1052+
1053+
remove_button = memnew(Button);
1054+
remove_button->set_tooltip_text(TTRC("Remove this override."));
1055+
override_container->add_child(remove_button);
1056+
remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override));
1057+
1058+
add_child(override_container);
1059+
1060+
if (is_ready()) {
1061+
// Setup icons.
1062+
_notification(NOTIFICATION_THEME_CHANGED);
1063+
}
1064+
}
1065+
10311066
void EditorSettingsPropertyWrapper::_update_override() {
10321067
// Don't allow overriding theme properties, because it causes problems. Overriding Project Manager settings makes no sense.
10331068
// TODO: Find a better way to define exception prefixes (if the list happens to grow).
@@ -1038,12 +1073,16 @@ void EditorSettingsPropertyWrapper::_update_override() {
10381073

10391074
const bool has_override = ProjectSettings::get_singleton()->is_project_loaded() && ProjectSettings::get_singleton()->has_editor_setting_override(property);
10401075
if (has_override) {
1041-
const Variant override_value = EDITOR_GET(property);
1042-
override_label->set_text(vformat(TTR("Overridden in project: %s"), override_value));
1043-
// In case the text is too long and trimmed.
1044-
override_label->set_tooltip_text(override_value);
1076+
if (!override_container) {
1077+
_setup_override_info();
1078+
}
1079+
override_editor_property->update_property();
1080+
set_bottom_editor(override_container);
1081+
override_container->show();
1082+
} else if (override_container) {
1083+
override_container->hide();
1084+
set_bottom_editor(nullptr);
10451085
}
1046-
override_info->set_visible(has_override);
10471086
can_override = !has_override;
10481087
}
10491088

@@ -1060,13 +1099,14 @@ void EditorSettingsPropertyWrapper::_remove_override() {
10601099
EditorNode::get_singleton()->notify_settings_overrides_changed();
10611100
_update_override();
10621101

1063-
if (requires_restart) {
1102+
if (usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {
10641103
restart_request_callback.call();
10651104
}
10661105
}
10671106

10681107
void EditorSettingsPropertyWrapper::_notification(int p_what) {
1069-
if (p_what == NOTIFICATION_THEME_CHANGED) {
1108+
if (override_container && p_what == NOTIFICATION_THEME_CHANGED) {
1109+
override_icon->set_texture(get_editor_theme_icon(SNAME("Hierarchy")));
10701110
goto_button->set_button_icon(get_editor_theme_icon(SNAME("MethodOverride")));
10711111
remove_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
10721112
}
@@ -1076,40 +1116,15 @@ void EditorSettingsPropertyWrapper::update_property() {
10761116
editor_property->update_property();
10771117
}
10781118

1079-
void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart) {
1080-
requires_restart = p_requires_restart;
1119+
void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, PropertyHint p_hint, const String &p_hint_text, uint32_t p_usage) {
1120+
hint = p_hint;
1121+
hint_text = p_hint_text;
1122+
usage = p_usage;
10811123

10821124
property = p_property;
1083-
container = memnew(VBoxContainer);
1084-
10851125
editor_property = p_editor_property;
1086-
editor_property->set_h_size_flags(SIZE_EXPAND_FILL);
1087-
container->add_child(editor_property);
1088-
1089-
override_info = memnew(HBoxContainer);
1090-
override_info->hide();
1091-
container->add_child(override_info);
1092-
1093-
override_label = memnew(Label);
1094-
override_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
1095-
override_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
1096-
override_label->set_mouse_filter(MOUSE_FILTER_STOP); // For tooltip.
1097-
override_label->set_h_size_flags(SIZE_EXPAND_FILL);
1098-
override_info->add_child(override_label);
1099-
1100-
goto_button = memnew(Button);
1101-
goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings."));
1102-
override_info->add_child(goto_button);
1103-
if (EditorNode::get_singleton()) {
1104-
goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED);
1105-
}
1106-
1107-
remove_button = memnew(Button);
1108-
remove_button->set_tooltip_text(TTRC("Remove this override."));
1109-
override_info->add_child(remove_button);
1110-
remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override));
1126+
add_child(editor_property);
11111127

1112-
add_child(container);
11131128
_update_override();
11141129

11151130
connect(SNAME("property_overridden"), callable_mp(this, &EditorSettingsPropertyWrapper::_create_override));
@@ -1134,8 +1149,9 @@ bool EditorSettingsInspectorPlugin::parse_property(Object *p_object, const Varia
11341149
EditorSettingsPropertyWrapper *editor = memnew(EditorSettingsPropertyWrapper);
11351150
EditorProperty *real_property = inspector->get_inspector()->instantiate_property_editor(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
11361151
real_property->set_object_and_property(p_object, p_path);
1152+
real_property->set_h_size_flags(Control::SIZE_EXPAND_FILL);
11371153
real_property->set_name_split_ratio(0.0);
1138-
editor->setup(property, real_property, bool(p_usage & PROPERTY_USAGE_RESTART_IF_CHANGED));
1154+
editor->setup(property, real_property, p_hint, p_hint_text, p_usage);
11391155

11401156
add_property_editor(p_path, editor);
11411157
current_object = nullptr;

editor/settings/editor_settings_dialog.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,19 @@ class EditorSettingsPropertyWrapper : public EditorProperty {
141141
GDCLASS(EditorSettingsPropertyWrapper, EditorProperty);
142142

143143
String property;
144-
EditorProperty *editor_property = nullptr;
144+
PropertyHint hint;
145+
String hint_text;
146+
uint32_t usage;
145147

146-
BoxContainer *container = nullptr;
148+
EditorProperty *editor_property = nullptr;
147149

148-
HBoxContainer *override_info = nullptr;
149-
Label *override_label = nullptr;
150+
HBoxContainer *override_container = nullptr;
151+
TextureRect *override_icon = nullptr;
152+
EditorProperty *override_editor_property = nullptr;
150153
Button *goto_button = nullptr;
151154
Button *remove_button = nullptr;
152155

153-
bool requires_restart = false;
154-
156+
void _setup_override_info();
155157
void _update_override();
156158
void _create_override();
157159
void _remove_override();
@@ -163,7 +165,7 @@ class EditorSettingsPropertyWrapper : public EditorProperty {
163165
static inline Callable restart_request_callback;
164166

165167
virtual void update_property() override;
166-
void setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart);
168+
void setup(const String &p_property, EditorProperty *p_editor_property, PropertyHint p_hint, const String &p_hint_text, uint32_t p_usage);
167169
};
168170

169171
class EditorSettingsInspectorPlugin : public EditorInspectorPlugin {

0 commit comments

Comments
 (0)