Merge pull request #95175 from KoBeWi/bruh_can_revert

Fix implementation of `property_can_revert()` in various classes
This commit is contained in:
Thaddeus Crews 2024-10-10 18:13:16 -05:00
commit 9d5a7321a5
No known key found for this signature in database
GPG key ID: 62181B86FE9E5D84
6 changed files with 32 additions and 65 deletions

View file

@ -1167,22 +1167,16 @@ bool ProjectSettings::is_project_loaded() const {
} }
bool ProjectSettings::_property_can_revert(const StringName &p_name) const { bool ProjectSettings::_property_can_revert(const StringName &p_name) const {
if (!props.has(p_name)) { return props.has(p_name);
return false;
}
return props[p_name].initial != props[p_name].variant;
} }
bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const { bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
if (!props.has(p_name)) { const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name);
return false; if (value) {
r_property = value->value().initial.duplicate();
return true;
} }
return false;
// Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value.
r_property = props[p_name].initial.duplicate();
return true;
} }
void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) { void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {

View file

@ -1424,24 +1424,20 @@ Variant _EDITOR_GET(const String &p_setting) {
} }
bool EditorSettings::_property_can_revert(const StringName &p_name) const { bool EditorSettings::_property_can_revert(const StringName &p_name) const {
if (!props.has(p_name)) { const VariantContainer *property = props.getptr(p_name);
return false; if (property) {
return property->has_default_value;
} }
return false;
if (!props[p_name].has_default_value) {
return false;
}
return props[p_name].initial != props[p_name].variant;
} }
bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const { bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
if (!props.has(p_name) || !props[p_name].has_default_value) { const VariantContainer *value = props.getptr(p_name);
return false; if (value && value->has_default_value) {
r_property = value->initial;
return true;
} }
return false;
r_property = props[p_name].initial;
return true;
} }
void EditorSettings::add_property_hint(const PropertyInfo &p_hint) { void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {

View file

@ -186,25 +186,9 @@ bool MultiNodeEdit::_property_can_revert(const StringName &p_name) const {
} }
if (ClassDB::has_property(get_edited_class_name(), p_name)) { if (ClassDB::has_property(get_edited_class_name(), p_name)) {
StringName class_name;
for (const NodePath &E : nodes) { for (const NodePath &E : nodes) {
Node *node = es->get_node_or_null(E); Node *node = es->get_node_or_null(E);
if (!node) { if (node) {
continue;
}
class_name = node->get_class_name();
}
Variant default_value = ClassDB::class_get_default_property_value(class_name, p_name);
for (const NodePath &E : nodes) {
Node *node = es->get_node_or_null(E);
if (!node) {
continue;
}
if (node->get(p_name) != default_value) {
// A node that doesn't have the default value has been found, so show the revert button.
return true; return true;
} }
} }

View file

@ -121,13 +121,8 @@ bool EditorPropertyFontOTObject::_property_can_revert(const StringName &p_name)
if (name.begins_with("keys")) { if (name.begins_with("keys")) {
int key = name.get_slicec('/', 1).to_int(); int key = name.get_slicec('/', 1).to_int();
if (defaults_dict.has(key) && dict.has(key)) { return defaults_dict.has(key) && dict.has(key);
int value = dict[key];
Vector3i range = defaults_dict[key];
return range.z != value;
}
} }
return false; return false;
} }
@ -142,7 +137,6 @@ bool EditorPropertyFontOTObject::_property_get_revert(const StringName &p_name,
return true; return true;
} }
} }
return false; return false;
} }

View file

@ -1181,15 +1181,16 @@ void Node3D::_validate_property(PropertyInfo &p_property) const {
} }
bool Node3D::_property_can_revert(const StringName &p_name) const { bool Node3D::_property_can_revert(const StringName &p_name) const {
if (p_name == "basis") { const String sname = p_name;
if (sname == "basis") {
return true; return true;
} else if (p_name == "scale") { } else if (sname == "scale") {
return true; return true;
} else if (p_name == "quaternion") { } else if (sname == "quaternion") {
return true; return true;
} else if (p_name == "rotation") { } else if (sname == "rotation") {
return true; return true;
} else if (p_name == "position") { } else if (sname == "position") {
return true; return true;
} }
return false; return false;
@ -1198,35 +1199,36 @@ bool Node3D::_property_can_revert(const StringName &p_name) const {
bool Node3D::_property_get_revert(const StringName &p_name, Variant &r_property) const { bool Node3D::_property_get_revert(const StringName &p_name, Variant &r_property) const {
bool valid = false; bool valid = false;
if (p_name == "basis") { const String sname = p_name;
if (sname == "basis") {
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
r_property = Transform3D(variant).get_basis(); r_property = Transform3D(variant).get_basis();
} else { } else {
r_property = Basis(); r_property = Basis();
} }
} else if (p_name == "scale") { } else if (sname == "scale") {
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
r_property = Transform3D(variant).get_basis().get_scale(); r_property = Transform3D(variant).get_basis().get_scale();
} else { } else {
r_property = Vector3(1.0, 1.0, 1.0); r_property = Vector3(1.0, 1.0, 1.0);
} }
} else if (p_name == "quaternion") { } else if (sname == "quaternion") {
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
r_property = Quaternion(Transform3D(variant).get_basis().get_rotation_quaternion()); r_property = Quaternion(Transform3D(variant).get_basis().get_rotation_quaternion());
} else { } else {
r_property = Quaternion(); r_property = Quaternion();
} }
} else if (p_name == "rotation") { } else if (sname == "rotation") {
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
r_property = Transform3D(variant).get_basis().get_euler_normalized(data.euler_rotation_order); r_property = Transform3D(variant).get_basis().get_euler_normalized(data.euler_rotation_order);
} else { } else {
r_property = Vector3(); r_property = Vector3();
} }
} else if (p_name == "position") { } else if (sname == "position") {
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
if (valid) { if (valid) {
r_property = Transform3D(variant).get_origin(); r_property = Transform3D(variant).get_origin();

View file

@ -382,14 +382,11 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
bool ShaderMaterial::_property_can_revert(const StringName &p_name) const { bool ShaderMaterial::_property_can_revert(const StringName &p_name) const {
if (shader.is_valid()) { if (shader.is_valid()) {
const StringName *pr = remap_cache.getptr(p_name); if (remap_cache.has(p_name)) {
if (pr) {
Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), *pr);
Variant current_value = get_shader_parameter(*pr);
return default_value.get_type() != Variant::NIL && default_value != current_value;
} else if (p_name == "render_priority" || p_name == "next_pass") {
return true; return true;
} }
const String sname = p_name;
return sname == "render_priority" || sname == "next_pass";
} }
return false; return false;
} }