From 756de5575ec76c324b0c066f3a1be25289ab5372 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 21 Apr 2025 10:38:41 +0200 Subject: [PATCH] Move EditorPropertyRevert to it's own file. --- editor/editor_folding.cpp | 1 + editor/editor_inspector.cpp | 22 +------------ editor/editor_inspector.h | 10 ------ editor/editor_property_revert.cpp | 55 +++++++++++++++++++++++++++++++ editor/editor_property_revert.h | 49 +++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 31 deletions(-) create mode 100644 editor/editor_property_revert.cpp create mode 100644 editor/editor_property_revert.h diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 4cb4405f3..a81f182ee 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -42,6 +42,7 @@ #include "core/variant/array.h" #include "core/variant/variant.h" #include "editor_inspector.h" +#include "editor_property_revert.h" #include "editor_settings.h" #include "scene/main/node.h" diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 603e39aa1..047f24a76 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -51,6 +51,7 @@ #include "editor/editor_help.h" #include "editor_node.h" #include "editor_property_name_processor.h" +#include "editor_property_revert.h" #include "editor_scale.h" #include "editor_settings.h" #include "multi_node_edit.h" @@ -367,27 +368,6 @@ bool EditorProperty::is_read_only() const { return read_only; } -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 (r_is_valid) { - *r_is_valid = true; - } - return p_object->call("property_get_revert", p_property); - } - - return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid); -} - -bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { - bool is_valid_revert = false; - Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert); - if (!is_valid_revert) { - return false; - } - Variant current_value = p_object->get(p_property); - return PropertyUtils::is_property_value_different(current_value, revert_value); -} - void EditorProperty::update_revert_and_pin_status() { if (property == StringName()) { return; //no property, so nothing to do diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 4138cd62f..504d10778 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -69,16 +69,6 @@ class PanelContainer; class TextureRect; class SpinBox; -class EditorPropertyRevert { -public: - static bool get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value, bool p_check_class_default = true); - static bool is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig); - static bool is_property_value_different(const Variant &p_a, const Variant &p_b); - static Variant get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid); - - static bool can_property_revert(Object *p_object, const StringName &p_property); -}; - class EditorProperty : public Container { GDCLASS(EditorProperty, Container); diff --git a/editor/editor_property_revert.cpp b/editor/editor_property_revert.cpp new file mode 100644 index 000000000..60848d7bb --- /dev/null +++ b/editor/editor_property_revert.cpp @@ -0,0 +1,55 @@ +/*************************************************************************/ +/* editor_property_revert.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "editor_property_revert.h" + +#include "scene/main/property_utils.h" + +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 (r_is_valid) { + *r_is_valid = true; + } + return p_object->call("property_get_revert", p_property); + } + + return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid); +} + +bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { + bool is_valid_revert = false; + Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert); + if (!is_valid_revert) { + return false; + } + Variant current_value = p_object->get(p_property); + return PropertyUtils::is_property_value_different(current_value, revert_value); +} diff --git a/editor/editor_property_revert.h b/editor/editor_property_revert.h new file mode 100644 index 000000000..ffd566e84 --- /dev/null +++ b/editor/editor_property_revert.h @@ -0,0 +1,49 @@ +#ifndef EDITOR_PROPERTY_REVERT_H +#define EDITOR_PROPERTY_REVERT_H + +/*************************************************************************/ +/* editor_property_revert.h */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "core/object/object.h" +#include "core/string/string_name.h" +#include "core/variant/variant.h" + +class EditorPropertyRevert { +public: + //static bool get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value, bool p_check_class_default = true); + //static bool is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig); + //static bool is_property_value_different(const Variant &p_a, const Variant &p_b); + + static Variant get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid); + static bool can_property_revert(Object *p_object, const StringName &p_property); +}; + +#endif // EDITOR_PROPERTY_REVERT_H