Skip to content

Commit b9d2558

Browse files
committed
Fix implementation of property_can_revert() in various classes
1 parent db66bd3 commit b9d2558

File tree

6 files changed

+32
-65
lines changed

6 files changed

+32
-65
lines changed

core/config/project_settings.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,22 +1167,16 @@ bool ProjectSettings::is_project_loaded() const {
11671167
}
11681168

11691169
bool ProjectSettings::_property_can_revert(const StringName &p_name) const {
1170-
if (!props.has(p_name)) {
1171-
return false;
1172-
}
1173-
1174-
return props[p_name].initial != props[p_name].variant;
1170+
return props.has(p_name);
11751171
}
11761172

11771173
bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
1178-
if (!props.has(p_name)) {
1179-
return false;
1174+
const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name);
1175+
if (value) {
1176+
r_property = value->value().initial.duplicate();
1177+
return true;
11801178
}
1181-
1182-
// Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value.
1183-
r_property = props[p_name].initial.duplicate();
1184-
1185-
return true;
1179+
return false;
11861180
}
11871181

11881182
void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {

editor/editor_settings.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,24 +1424,20 @@ Variant _EDITOR_GET(const String &p_setting) {
14241424
}
14251425

14261426
bool EditorSettings::_property_can_revert(const StringName &p_name) const {
1427-
if (!props.has(p_name)) {
1428-
return false;
1429-
}
1430-
1431-
if (!props[p_name].has_default_value) {
1432-
return false;
1427+
const VariantContainer *property = props.getptr(p_name);
1428+
if (property) {
1429+
return property->has_default_value;
14331430
}
1434-
1435-
return props[p_name].initial != props[p_name].variant;
1431+
return false;
14361432
}
14371433

14381434
bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
1439-
if (!props.has(p_name) || !props[p_name].has_default_value) {
1440-
return false;
1435+
const VariantContainer *value = props.getptr(p_name);
1436+
if (value && value->has_default_value) {
1437+
r_property = value->initial;
1438+
return true;
14411439
}
1442-
1443-
r_property = props[p_name].initial;
1444-
return true;
1440+
return false;
14451441
}
14461442

14471443
void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {

editor/multi_node_edit.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,9 @@ bool MultiNodeEdit::_property_can_revert(const StringName &p_name) const {
186186
}
187187

188188
if (ClassDB::has_property(get_edited_class_name(), p_name)) {
189-
StringName class_name;
190189
for (const NodePath &E : nodes) {
191190
Node *node = es->get_node_or_null(E);
192-
if (!node) {
193-
continue;
194-
}
195-
196-
class_name = node->get_class_name();
197-
}
198-
199-
Variant default_value = ClassDB::class_get_default_property_value(class_name, p_name);
200-
for (const NodePath &E : nodes) {
201-
Node *node = es->get_node_or_null(E);
202-
if (!node) {
203-
continue;
204-
}
205-
206-
if (node->get(p_name) != default_value) {
207-
// A node that doesn't have the default value has been found, so show the revert button.
191+
if (node) {
208192
return true;
209193
}
210194
}

editor/plugins/font_config_plugin.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,8 @@ bool EditorPropertyFontOTObject::_property_can_revert(const StringName &p_name)
121121

122122
if (name.begins_with("keys")) {
123123
int key = name.get_slicec('/', 1).to_int();
124-
if (defaults_dict.has(key) && dict.has(key)) {
125-
int value = dict[key];
126-
Vector3i range = defaults_dict[key];
127-
return range.z != value;
128-
}
124+
return defaults_dict.has(key) && dict.has(key);
129125
}
130-
131126
return false;
132127
}
133128

@@ -142,7 +137,6 @@ bool EditorPropertyFontOTObject::_property_get_revert(const StringName &p_name,
142137
return true;
143138
}
144139
}
145-
146140
return false;
147141
}
148142

scene/3d/node_3d.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,15 +1181,16 @@ void Node3D::_validate_property(PropertyInfo &p_property) const {
11811181
}
11821182

11831183
bool Node3D::_property_can_revert(const StringName &p_name) const {
1184-
if (p_name == "basis") {
1184+
const String sname = p_name;
1185+
if (sname == "basis") {
11851186
return true;
1186-
} else if (p_name == "scale") {
1187+
} else if (sname == "scale") {
11871188
return true;
1188-
} else if (p_name == "quaternion") {
1189+
} else if (sname == "quaternion") {
11891190
return true;
1190-
} else if (p_name == "rotation") {
1191+
} else if (sname == "rotation") {
11911192
return true;
1192-
} else if (p_name == "position") {
1193+
} else if (sname == "position") {
11931194
return true;
11941195
}
11951196
return false;
@@ -1198,35 +1199,36 @@ bool Node3D::_property_can_revert(const StringName &p_name) const {
11981199
bool Node3D::_property_get_revert(const StringName &p_name, Variant &r_property) const {
11991200
bool valid = false;
12001201

1201-
if (p_name == "basis") {
1202+
const String sname = p_name;
1203+
if (sname == "basis") {
12021204
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
12031205
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
12041206
r_property = Transform3D(variant).get_basis();
12051207
} else {
12061208
r_property = Basis();
12071209
}
1208-
} else if (p_name == "scale") {
1210+
} else if (sname == "scale") {
12091211
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
12101212
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
12111213
r_property = Transform3D(variant).get_basis().get_scale();
12121214
} else {
12131215
r_property = Vector3(1.0, 1.0, 1.0);
12141216
}
1215-
} else if (p_name == "quaternion") {
1217+
} else if (sname == "quaternion") {
12161218
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
12171219
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
12181220
r_property = Quaternion(Transform3D(variant).get_basis().get_rotation_quaternion());
12191221
} else {
12201222
r_property = Quaternion();
12211223
}
1222-
} else if (p_name == "rotation") {
1224+
} else if (sname == "rotation") {
12231225
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
12241226
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
12251227
r_property = Transform3D(variant).get_basis().get_euler_normalized(data.euler_rotation_order);
12261228
} else {
12271229
r_property = Vector3();
12281230
}
1229-
} else if (p_name == "position") {
1231+
} else if (sname == "position") {
12301232
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
12311233
if (valid) {
12321234
r_property = Transform3D(variant).get_origin();

scene/resources/material.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,11 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
382382

383383
bool ShaderMaterial::_property_can_revert(const StringName &p_name) const {
384384
if (shader.is_valid()) {
385-
const StringName *pr = remap_cache.getptr(p_name);
386-
if (pr) {
387-
Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), *pr);
388-
Variant current_value = get_shader_parameter(*pr);
389-
return default_value.get_type() != Variant::NIL && default_value != current_value;
390-
} else if (p_name == "render_priority" || p_name == "next_pass") {
385+
if (remap_cache.has(p_name)) {
391386
return true;
392387
}
388+
const String sname = p_name;
389+
return sname == "render_priority" || sname == "next_pass";
393390
}
394391
return false;
395392
}

0 commit comments

Comments
 (0)