Make property_*_revert methods multilevel and expose them for scripting

This commit is contained in:
Yuri Sizov
2022-08-12 21:43:14 +03:00
parent dbd1524362
commit 980f5f32f4
29 changed files with 327 additions and 126 deletions

View File

@ -432,11 +432,11 @@ bool EditorProperty::is_read_only() const {
}
Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid) {
if (p_object->has_method("property_can_revert") && p_object->call("property_can_revert", p_property)) {
if (p_object->property_can_revert(p_property)) {
if (r_is_valid) {
*r_is_valid = true;
}
return p_object->call("property_get_revert", p_property);
return p_object->property_get_revert(p_property);
}
return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid);

View File

@ -114,11 +114,11 @@ class SectionedInspectorFilter : public Object {
}
bool property_can_revert(const String &p_name) {
return edited->call("property_can_revert", section + "/" + p_name);
return edited->property_can_revert(section + "/" + p_name);
}
Variant property_get_revert(const String &p_name) {
return edited->call("property_get_revert", section + "/" + p_name);
return edited->property_get_revert(section + "/" + p_name);
}
protected:

View File

@ -1073,24 +1073,25 @@ Variant _EDITOR_GET(const String &p_setting) {
return EditorSettings::get_singleton()->get(p_setting);
}
bool EditorSettings::property_can_revert(const String &p_setting) {
if (!props.has(p_setting)) {
bool EditorSettings::_property_can_revert(const StringName &p_name) const {
if (!props.has(p_name)) {
return false;
}
if (!props[p_setting].has_default_value) {
if (!props[p_name].has_default_value) {
return false;
}
return props[p_setting].initial != props[p_setting].variant;
return props[p_name].initial != props[p_name].variant;
}
Variant EditorSettings::property_get_revert(const String &p_setting) {
if (!props.has(p_setting) || !props[p_setting].has_default_value) {
return Variant();
bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
if (!props.has(p_name) || !props[p_name].has_default_value) {
return false;
}
return props[p_setting].initial;
r_property = props[p_name].initial;
return true;
}
void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
@ -1621,8 +1622,6 @@ void EditorSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &EditorSettings::property_can_revert);
ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorSettings::property_get_revert);
ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);

View File

@ -100,6 +100,8 @@ private:
void _initial_set(const StringName &p_name, const Variant &p_value);
void _get_property_list(List<PropertyInfo> *p_list) const;
void _add_property_info_bind(const Dictionary &p_info);
bool _property_can_revert(const StringName &p_name) const;
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
void _load_defaults(Ref<ConfigFile> p_extra_config = Ref<ConfigFile>());
void _load_godot2_text_editor_theme();
@ -138,8 +140,6 @@ public:
_set_only(p_setting, p_value);
}
}
bool property_can_revert(const String &p_setting);
Variant property_get_revert(const String &p_setting);
void add_property_hint(const PropertyInfo &p_hint);
Array get_changed_settings() const;
bool check_changed_settings_in_group(const String &p_setting_prefix) const;

View File

@ -100,11 +100,6 @@ bool EditorPropertyFontOTObject::_get(const StringName &p_name, Variant &r_ret)
return false;
}
void EditorPropertyFontOTObject::_bind_methods() {
ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &EditorPropertyFontOTObject::property_can_revert);
ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorPropertyFontOTObject::property_get_revert);
}
void EditorPropertyFontOTObject::set_dict(const Dictionary &p_dict) {
dict = p_dict;
}
@ -121,7 +116,7 @@ Dictionary EditorPropertyFontOTObject::get_defaults() {
return defaults_dict;
}
bool EditorPropertyFontOTObject::property_can_revert(const String &p_name) {
bool EditorPropertyFontOTObject::_property_can_revert(const StringName &p_name) const {
String name = p_name;
if (name.begins_with("keys")) {
@ -136,18 +131,19 @@ bool EditorPropertyFontOTObject::property_can_revert(const String &p_name) {
return false;
}
Variant EditorPropertyFontOTObject::property_get_revert(const String &p_name) {
bool EditorPropertyFontOTObject::_property_get_revert(const StringName &p_name, Variant &r_property) const {
String name = p_name;
if (name.begins_with("keys")) {
int key = name.get_slicec('/', 1).to_int();
if (defaults_dict.has(key)) {
Vector3i range = defaults_dict[key];
return range.z;
r_property = range.z;
return true;
}
}
return Variant();
return false;
}
/*************************************************************************/

View File

@ -66,7 +66,8 @@ class EditorPropertyFontOTObject : public RefCounted {
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
static void _bind_methods();
bool _property_can_revert(const StringName &p_name) const;
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
public:
void set_dict(const Dictionary &p_dict);
@ -75,9 +76,6 @@ public:
void set_defaults(const Dictionary &p_dict);
Dictionary get_defaults();
bool property_can_revert(const String &p_name);
Variant property_get_revert(const String &p_name);
EditorPropertyFontOTObject(){};
};