diff --git a/editor/array_property_edit.cpp b/editor/array_property_edit.cpp deleted file mode 100644 index dd27b61df967..000000000000 --- a/editor/array_property_edit.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/**************************************************************************/ -/* array_property_edit.cpp */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 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 "array_property_edit.h" - -#include "core/io/marshalls.h" -#include "editor/editor_undo_redo_manager.h" - -#define ITEMS_PER_PAGE 100 - -Variant ArrayPropertyEdit::get_array() const { - Object *o = ObjectDB::get_instance(obj); - if (!o) { - return Array(); - } - Variant arr = o->get(property); - if (!arr.is_array()) { - Callable::CallError ce; - Variant::construct(default_type, arr, nullptr, 0, ce); - } - return arr; -} - -void ArrayPropertyEdit::_notif_change() { - notify_property_list_changed(); -} - -void ArrayPropertyEdit::_set_size(int p_size) { - Variant arr = get_array(); - arr.call("resize", p_size); - Object *o = ObjectDB::get_instance(obj); - if (!o) { - return; - } - - o->set(property, arr); -} - -void ArrayPropertyEdit::_set_value(int p_idx, const Variant &p_value) { - Variant arr = get_array(); - arr.set(p_idx, p_value); - Object *o = ObjectDB::get_instance(obj); - if (!o) { - return; - } - - o->set(property, arr); -} - -bool ArrayPropertyEdit::_set(const StringName &p_name, const Variant &p_value) { - String pn = p_name; - - if (pn.begins_with("array/")) { - if (pn == "array/size") { - Variant arr = get_array(); - int size = arr.call("size"); - - int newsize = p_value; - if (newsize == size) { - return true; - } - - EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - ur->create_action(TTR("Resize Array")); - ur->add_do_method(this, "_set_size", newsize); - ur->add_undo_method(this, "_set_size", size); - if (newsize < size) { - for (int i = newsize; i < size; i++) { - ur->add_undo_method(this, "_set_value", i, arr.get(i)); - } - } else if (newsize > size) { - Variant init; - Callable::CallError ce; - Variant::Type new_type = subtype; - if (new_type == Variant::NIL && size) { - new_type = arr.get(size - 1).get_type(); - } - if (new_type != Variant::NIL) { - Variant::construct(new_type, init, nullptr, 0, ce); - for (int i = size; i < newsize; i++) { - ur->add_do_method(this, "_set_value", i, init); - } - } - } - ur->add_do_method(this, "_notif_change"); - ur->add_undo_method(this, "_notif_change"); - ur->commit_action(); - return true; - } - if (pn == "array/page") { - page = p_value; - notify_property_list_changed(); - return true; - } - - } else if (pn.begins_with("indices")) { - if (pn.contains("_")) { - //type - int idx = pn.get_slicec('/', 1).get_slicec('_', 0).to_int(); - - int type = p_value; - - Variant arr = get_array(); - - Variant value = arr.get(idx); - if (value.get_type() != type && type >= 0 && type < Variant::VARIANT_MAX) { - Callable::CallError ce; - Variant new_value; - Variant::construct(Variant::Type(type), new_value, nullptr, 0, ce); - EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - - ur->create_action(TTR("Change Array Value Type")); - ur->add_do_method(this, "_set_value", idx, new_value); - ur->add_undo_method(this, "_set_value", idx, value); - ur->add_do_method(this, "_notif_change"); - ur->add_undo_method(this, "_notif_change"); - ur->commit_action(); - } - return true; - - } else { - int idx = pn.get_slicec('/', 1).to_int(); - Variant arr = get_array(); - - Variant value = arr.get(idx); - EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - - ur->create_action(TTR("Change Array Value")); - ur->add_do_method(this, "_set_value", idx, p_value); - ur->add_undo_method(this, "_set_value", idx, value); - ur->commit_action(); - return true; - } - } - - return false; -} - -bool ArrayPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const { - Variant arr = get_array(); - //int size = arr.call("size"); - - String pn = p_name; - if (pn.begins_with("array/")) { - if (pn == "array/size") { - r_ret = arr.call("size"); - return true; - } - if (pn == "array/page") { - r_ret = page; - return true; - } - } else if (pn.begins_with("indices")) { - if (pn.contains("_")) { - //type - int idx = pn.get_slicec('/', 1).get_slicec('_', 0).to_int(); - bool valid; - r_ret = arr.get(idx, &valid); - if (valid) { - r_ret = r_ret.get_type(); - } - return valid; - - } else { - int idx = pn.get_slicec('/', 1).to_int(); - bool valid; - r_ret = arr.get(idx, &valid); - - if (r_ret.get_type() == Variant::OBJECT && Object::cast_to(r_ret)) { - r_ret = Object::cast_to(r_ret)->get_object_id(); - } - - return valid; - } - } - - return false; -} - -void ArrayPropertyEdit::_get_property_list(List *p_list) const { - Variant arr = get_array(); - int size = arr.call("size"); - - p_list->push_back(PropertyInfo(Variant::INT, "array/size", PROPERTY_HINT_RANGE, "0,100000,1")); - int pages = size / ITEMS_PER_PAGE; - if (pages > 0) { - p_list->push_back(PropertyInfo(Variant::INT, "array/page", PROPERTY_HINT_RANGE, "0," + itos(pages) + ",1")); - } - - int offset = page * ITEMS_PER_PAGE; - - int items = MIN(size - offset, ITEMS_PER_PAGE); - - for (int i = 0; i < items; i++) { - Variant v = arr.get(i + offset); - bool is_typed = arr.get_type() != Variant::ARRAY || subtype != Variant::NIL; - - if (!is_typed) { - p_list->push_back(PropertyInfo(Variant::INT, "indices/" + itos(i + offset) + "_type", PROPERTY_HINT_ENUM, vtypes)); - } - - if (v.get_type() == Variant::OBJECT && Object::cast_to(v)) { - p_list->push_back(PropertyInfo(Variant::INT, "indices/" + itos(i + offset), PROPERTY_HINT_OBJECT_ID, "Object")); - continue; - } - - if (is_typed || v.get_type() != Variant::NIL) { - PropertyInfo pi(v.get_type(), "indices/" + itos(i + offset)); - if (subtype != Variant::NIL) { - pi.type = Variant::Type(subtype); - pi.hint = PropertyHint(subtype_hint); - pi.hint_string = subtype_hint_string; - } else if (v.get_type() == Variant::OBJECT) { - pi.hint = PROPERTY_HINT_RESOURCE_TYPE; - pi.hint_string = "Resource"; - } - - p_list->push_back(pi); - } - } -} - -void ArrayPropertyEdit::edit(Object *p_obj, const StringName &p_prop, const String &p_hint_string, Variant::Type p_deftype) { - page = 0; - property = p_prop; - obj = p_obj->get_instance_id(); - default_type = p_deftype; - - if (!p_hint_string.is_empty()) { - int hint_subtype_separator = p_hint_string.find(":"); - if (hint_subtype_separator >= 0) { - String subtype_string = p_hint_string.substr(0, hint_subtype_separator); - - int slash_pos = subtype_string.find("/"); - if (slash_pos >= 0) { - subtype_hint = PropertyHint(subtype_string.substr(slash_pos + 1, subtype_string.size() - slash_pos - 1).to_int()); - subtype_string = subtype_string.substr(0, slash_pos); - } - - subtype_hint_string = p_hint_string.substr(hint_subtype_separator + 1, p_hint_string.size() - hint_subtype_separator - 1); - subtype = Variant::Type(subtype_string.to_int()); - } - } -} - -Node *ArrayPropertyEdit::get_node() { - return Object::cast_to(ObjectDB::get_instance(obj)); -} - -bool ArrayPropertyEdit::_dont_undo_redo() { - return true; -} - -void ArrayPropertyEdit::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_size"), &ArrayPropertyEdit::_set_size); - ClassDB::bind_method(D_METHOD("_set_value"), &ArrayPropertyEdit::_set_value); - ClassDB::bind_method(D_METHOD("_notif_change"), &ArrayPropertyEdit::_notif_change); - ClassDB::bind_method(D_METHOD("_dont_undo_redo"), &ArrayPropertyEdit::_dont_undo_redo); -} - -ArrayPropertyEdit::ArrayPropertyEdit() { - page = 0; - for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) { - vtypes += ","; - } - vtypes += Variant::get_type_name(Variant::Type(i)); - } - default_type = Variant::NIL; - subtype = Variant::NIL; - subtype_hint = PROPERTY_HINT_NONE; - subtype_hint_string = ""; -} diff --git a/editor/array_property_edit.h b/editor/array_property_edit.h deleted file mode 100644 index 6e34a06943e7..000000000000 --- a/editor/array_property_edit.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************/ -/* array_property_edit.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 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. */ -/**************************************************************************/ - -#ifndef ARRAY_PROPERTY_EDIT_H -#define ARRAY_PROPERTY_EDIT_H - -#include "scene/main/node.h" - -class ArrayPropertyEdit : public RefCounted { - GDCLASS(ArrayPropertyEdit, RefCounted); - - int page; - ObjectID obj; - StringName property; - String vtypes; - String subtype_hint_string; - PropertyHint subtype_hint; - Variant::Type subtype; - Variant get_array() const; - Variant::Type default_type; - - void _notif_change(); - void _set_size(int p_size); - void _set_value(int p_idx, const Variant &p_value); - - bool _dont_undo_redo(); - -protected: - static void _bind_methods(); - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - -public: - void edit(Object *p_obj, const StringName &p_prop, const String &p_hint_string, Variant::Type p_deftype); - - Node *get_node(); - - ArrayPropertyEdit(); -}; - -#endif // ARRAY_PROPERTY_EDIT_H diff --git a/editor/dictionary_property_edit.cpp b/editor/dictionary_property_edit.cpp deleted file mode 100644 index ad59a1c16992..000000000000 --- a/editor/dictionary_property_edit.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************/ -/* dictionary_property_edit.cpp */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 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 "dictionary_property_edit.h" -#include "editor/editor_undo_redo_manager.h" - -void DictionaryPropertyEdit::_notif_change() { - notify_property_list_changed(); -} - -void DictionaryPropertyEdit::_set_key(const Variant &p_old_key, const Variant &p_new_key) { - // TODO: Set key of a dictionary is not allowed yet -} - -void DictionaryPropertyEdit::_set_value(const Variant &p_key, const Variant &p_value) { - Dictionary dict = get_dictionary(); - dict[p_key] = p_value; - Object *o = ObjectDB::get_instance(obj); - if (!o) { - return; - } - - o->set(property, dict); -} - -Variant DictionaryPropertyEdit::get_dictionary() const { - Object *o = ObjectDB::get_instance(obj); - if (!o) { - return Dictionary(); - } - Variant dict = o->get(property); - if (dict.get_type() != Variant::DICTIONARY) { - return Dictionary(); - } - return dict; -} - -void DictionaryPropertyEdit::_get_property_list(List *p_list) const { - Dictionary dict = get_dictionary(); - - Array keys = dict.keys(); - keys.sort(); - - for (int i = 0; i < keys.size(); i++) { - String index = itos(i); - - const Variant &key = keys[i]; - PropertyInfo pi(key.get_type(), index + ": key"); - p_list->push_back(pi); - - const Variant &value = dict[key]; - pi = PropertyInfo(value.get_type(), index + ": value"); - p_list->push_back(pi); - } -} - -void DictionaryPropertyEdit::edit(Object *p_obj, const StringName &p_prop) { - property = p_prop; - obj = p_obj->get_instance_id(); -} - -Node *DictionaryPropertyEdit::get_node() { - Object *o = ObjectDB::get_instance(obj); - if (!o) { - return nullptr; - } - - return cast_to(o); -} - -bool DictionaryPropertyEdit::_dont_undo_redo() { - return true; -} - -void DictionaryPropertyEdit::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_key"), &DictionaryPropertyEdit::_set_key); - ClassDB::bind_method(D_METHOD("_set_value"), &DictionaryPropertyEdit::_set_value); - ClassDB::bind_method(D_METHOD("_notif_change"), &DictionaryPropertyEdit::_notif_change); - ClassDB::bind_method(D_METHOD("_dont_undo_redo"), &DictionaryPropertyEdit::_dont_undo_redo); -} - -bool DictionaryPropertyEdit::_set(const StringName &p_name, const Variant &p_value) { - Dictionary dict = get_dictionary(); - Array keys = dict.keys(); - keys.sort(); - - String pn = p_name; - int slash = pn.find(": "); - if (slash != -1 && pn.length() > slash) { - String type = pn.substr(slash + 2, pn.length()); - int index = pn.substr(0, slash).to_int(); - if (type == "key" && index < keys.size()) { - const Variant &key = keys[index]; - EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - - ur->create_action(TTR("Change Dictionary Key")); - ur->add_do_method(this, "_set_key", key, p_value); - ur->add_undo_method(this, "_set_key", p_value, key); - ur->commit_action(); - - return true; - } else if (type == "value" && index < keys.size()) { - const Variant &key = keys[index]; - if (dict.has(key)) { - Variant value = dict[key]; - EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - - ur->create_action(TTR("Change Dictionary Value")); - ur->add_do_method(this, "_set_value", key, p_value); - ur->add_undo_method(this, "_set_value", key, value); - ur->commit_action(); - - return true; - } - } - } - - return false; -} - -bool DictionaryPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const { - Dictionary dict = get_dictionary(); - Array keys = dict.keys(); - keys.sort(); - - String pn = p_name; - int slash = pn.find(": "); - - if (slash != -1 && pn.length() > slash) { - String type = pn.substr(slash + 2, pn.length()); - int index = pn.substr(0, slash).to_int(); - - if (type == "key" && index < keys.size()) { - r_ret = keys[index]; - return true; - } else if (type == "value" && index < keys.size()) { - const Variant &key = keys[index]; - if (dict.has(key)) { - r_ret = dict[key]; - return true; - } - } - } - - return false; -} - -DictionaryPropertyEdit::DictionaryPropertyEdit() { -} diff --git a/editor/dictionary_property_edit.h b/editor/dictionary_property_edit.h deleted file mode 100644 index 197bb394d4f5..000000000000 --- a/editor/dictionary_property_edit.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************/ -/* dictionary_property_edit.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 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. */ -/**************************************************************************/ - -#ifndef DICTIONARY_PROPERTY_EDIT_H -#define DICTIONARY_PROPERTY_EDIT_H - -#include "scene/main/node.h" - -class DictionaryPropertyEdit : public RefCounted { - GDCLASS(DictionaryPropertyEdit, RefCounted); - - ObjectID obj; - StringName property; - - void _notif_change(); - void _set_key(const Variant &p_old_key, const Variant &p_new_key); - void _set_value(const Variant &p_key, const Variant &p_value); - - Variant get_dictionary() const; - - bool _dont_undo_redo(); - -protected: - static void _bind_methods(); - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - -public: - void edit(Object *p_obj, const StringName &p_prop); - - Node *get_node(); - - DictionaryPropertyEdit(); -}; - -#endif // DICTIONARY_PROPERTY_EDIT_H