2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* property_editor.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "property_editor.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2020-04-28 13:19:37 +00:00
|
|
|
#include "core/input/input.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "core/io/image_loader.h"
|
|
|
|
#include "core/io/marshalls.h"
|
|
|
|
#include "core/io/resource_loader.h"
|
2018-09-13 19:53:14 +00:00
|
|
|
#include "core/math/expression.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/object/class_db.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "core/os/keyboard.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/string/print_string.h"
|
|
|
|
#include "core/templates/pair.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "editor/array_property_edit.h"
|
|
|
|
#include "editor/create_dialog.h"
|
2017-10-17 14:39:31 +00:00
|
|
|
#include "editor/dictionary_property_edit.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "editor/editor_export.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_file_dialog.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "editor/editor_file_system.h"
|
|
|
|
#include "editor/editor_help.h"
|
|
|
|
#include "editor/editor_node.h"
|
2019-12-24 07:17:23 +00:00
|
|
|
#include "editor/editor_scale.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2019-12-24 07:17:23 +00:00
|
|
|
#include "editor/filesystem_dock.h"
|
2017-08-26 15:46:49 +00:00
|
|
|
#include "editor/multi_node_edit.h"
|
|
|
|
#include "editor/property_selector.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/scene_tree_dock.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/label.h"
|
2020-03-04 01:51:12 +00:00
|
|
|
#include "scene/main/window.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/resources/font.h"
|
2015-10-10 12:09:09 +00:00
|
|
|
#include "scene/resources/packed_scene.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/scene_string_names.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-22 12:20:28 +00:00
|
|
|
void EditorResourceConversionPlugin::_bind_methods() {
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL_BIND(_converts_to);
|
|
|
|
GDVIRTUAL_BIND(_handles, "resource");
|
|
|
|
GDVIRTUAL_BIND(_convert, "resource");
|
2017-09-22 12:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorResourceConversionPlugin::converts_to() const {
|
2021-08-22 01:52:44 +00:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_converts_to, ret)) {
|
|
|
|
return ret;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-22 12:20:28 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
2021-08-22 01:52:44 +00:00
|
|
|
bool ret;
|
|
|
|
if (GDVIRTUAL_CALL(_handles, p_resource, ret)) {
|
|
|
|
return ret;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-22 12:20:28 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> ret;
|
2021-08-22 01:52:44 +00:00
|
|
|
if (GDVIRTUAL_CALL(_convert, p_resource, ret)) {
|
|
|
|
return ret;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-22 12:20:28 +00:00
|
|
|
|
|
|
|
return Ref<Resource>();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void CustomPropertyEditor::_notification(int p_what) {
|
2022-02-16 14:17:55 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_WM_CLOSE_REQUEST: {
|
|
|
|
hide();
|
|
|
|
} break;
|
2017-06-18 20:16:54 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_menu_option(int p_which) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::INT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_FLAGS) {
|
2022-03-06 17:04:29 +00:00
|
|
|
int idx = menu->get_item_index(p_which);
|
|
|
|
uint32_t item_value = menu->get_item_metadata(idx);
|
|
|
|
uint32_t value = v;
|
|
|
|
// If the item wasn't previously checked it means it was pressed,
|
|
|
|
// otherwise it was unpressed.
|
|
|
|
if (!menu->is_item_checked(idx)) {
|
|
|
|
v = value | item_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2022-03-06 17:04:29 +00:00
|
|
|
v = value & ~item_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_ENUM) {
|
2018-10-09 14:10:22 +00:00
|
|
|
v = menu->get_item_metadata(p_which);
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
2016-08-31 15:49:45 +00:00
|
|
|
case Variant::STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_ENUM) {
|
|
|
|
v = hint_text.get_slice(",", p_which);
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2016-08-31 15:49:45 +00:00
|
|
|
}
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::OBJECT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_which) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJ_MENU_LOAD: {
|
2020-03-06 17:00:16 +00:00
|
|
|
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2017-03-05 15:44:50 +00:00
|
|
|
String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-11-28 00:11:20 +00:00
|
|
|
List<String> extensions;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < type.get_slice_count(","); i++) {
|
|
|
|
ResourceLoader::get_recognized_extensions_for_type(type.get_slice(",", i), &extensions);
|
2015-11-28 00:11:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 15:00:06 +00:00
|
|
|
HashSet<String> valid_extensions;
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &E : extensions) {
|
2021-07-16 03:45:57 +00:00
|
|
|
valid_extensions.insert(E);
|
2015-11-28 00:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
file->clear_filters();
|
2022-05-18 23:43:40 +00:00
|
|
|
for (const String &E : valid_extensions) {
|
|
|
|
file->add_filter("*." + E + " ; " + E.to_upper());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 16:45:19 +00:00
|
|
|
file->popup_file_dialog();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case OBJ_MENU_EDIT: {
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<RefCounted> r = v;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-13 19:03:10 +00:00
|
|
|
if (!r.is_null()) {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("resource_edit_request"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OBJ_MENU_CLEAR: {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = Variant();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case OBJ_MENU_MAKE_UNIQUE: {
|
2020-02-13 19:03:10 +00:00
|
|
|
Ref<Resource> res_orig = v;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (res_orig.is_null()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<PropertyInfo> property_list;
|
|
|
|
res_orig->get_property_list(&property_list);
|
2020-03-17 06:33:00 +00:00
|
|
|
List<Pair<String, Variant>> propvalues;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const PropertyInfo &pi : property_list) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Pair<String, Variant> p;
|
|
|
|
if (pi.usage & PROPERTY_USAGE_STORAGE) {
|
|
|
|
p.first = pi.name;
|
|
|
|
p.second = res_orig->get(pi.name);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
propvalues.push_back(p);
|
|
|
|
}
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
String orig_type = res_orig->get_class();
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
Object *inst = ClassDB::instantiate(orig_type);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
Ref<Resource> res = Ref<Resource>(Object::cast_to<Resource>(inst));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(res.is_null());
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const Pair<String, Variant> &p : propvalues) {
|
2017-03-05 15:44:50 +00:00
|
|
|
res->set(p.first, p.second);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:03:10 +00:00
|
|
|
v = res;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case OBJ_MENU_COPY: {
|
|
|
|
EditorSettings::get_singleton()->set_resource_clipboard(v);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OBJ_MENU_PASTE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = EditorSettings::get_singleton()->get_resource_clipboard();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2016-09-12 22:31:07 +00:00
|
|
|
case OBJ_MENU_NEW_SCRIPT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (Object::cast_to<Node>(owner)) {
|
2021-11-17 20:08:55 +00:00
|
|
|
SceneTreeDock::get_singleton()->open_script_dialog(Object::cast_to<Node>(owner), false);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-10-21 04:57:10 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case OBJ_MENU_EXTEND_SCRIPT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (Object::cast_to<Node>(owner)) {
|
2021-11-17 20:08:55 +00:00
|
|
|
SceneTreeDock::get_singleton()->open_script_dialog(Object::cast_to<Node>(owner), true);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-09-12 22:31:07 +00:00
|
|
|
|
|
|
|
} break;
|
2017-01-14 17:14:46 +00:00
|
|
|
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> r = v;
|
2021-11-17 20:08:55 +00:00
|
|
|
FileSystemDock *file_system_dock = FileSystemDock::get_singleton();
|
2017-01-14 17:14:46 +00:00
|
|
|
file_system_dock->navigate_to_path(r->get_path());
|
|
|
|
// Ensure that the FileSystem dock is visible.
|
2017-03-05 15:44:50 +00:00
|
|
|
TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
|
2022-03-04 22:16:33 +00:00
|
|
|
tab_container->set_current_tab(tab_container->get_tab_idx_from_control(file_system_dock));
|
2017-01-14 17:14:46 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {
|
2017-09-22 12:20:28 +00:00
|
|
|
if (p_which >= CONVERT_BASE_ID) {
|
|
|
|
int to_type = p_which - CONVERT_BASE_ID;
|
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(Ref<Resource>(v));
|
2017-09-22 12:20:28 +00:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(to_type, conversions.size());
|
|
|
|
|
|
|
|
Ref<Resource> new_res = conversions[to_type]->convert(v);
|
|
|
|
|
|
|
|
v = new_res;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2017-09-22 12:20:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-12-15 12:04:21 +00:00
|
|
|
ERR_FAIL_COND(inheritors_array.is_empty());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String intype = inheritors_array[p_which - TYPE_BASE_ID];
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (intype == "ViewportTexture") {
|
2017-01-10 04:04:31 +00:00
|
|
|
scene_tree->set_title(TTR("Pick a Viewport"));
|
2020-07-11 16:45:19 +00:00
|
|
|
scene_tree->popup_scenetree_dialog();
|
2017-03-05 15:44:50 +00:00
|
|
|
picking_viewport = true;
|
2017-01-10 04:04:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
Variant obj = ClassDB::instantiate(intype);
|
2018-02-25 00:41:26 +00:00
|
|
|
|
|
|
|
if (!obj) {
|
2018-07-29 03:36:43 +00:00
|
|
|
if (ScriptServer::is_global_class(intype)) {
|
|
|
|
obj = EditorNode::get_editor_data().script_class_instance(intype);
|
|
|
|
} else {
|
|
|
|
obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
|
|
|
|
}
|
2018-02-25 00:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_BREAK(!obj);
|
2017-08-24 20:58:51 +00:00
|
|
|
Resource *res = Object::cast_to<Resource>(obj);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_BREAK(!res);
|
|
|
|
if (owner && hint == PROPERTY_HINT_RESOURCE_TYPE && hint_text == "Script") {
|
2016-08-08 04:21:22 +00:00
|
|
|
//make visual script the right type
|
2017-03-05 15:44:50 +00:00
|
|
|
res->call("set_instance_base_type", owner->get_class());
|
2016-08-08 04:21:22 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-22 19:02:57 +00:00
|
|
|
EditorNode::get_editor_data().instantiate_object_properties(obj);
|
2021-01-06 19:25:05 +00:00
|
|
|
v = obj;
|
2020-10-22 19:02:57 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 14:46:08 +00:00
|
|
|
void CustomPropertyEditor::hide_menu() {
|
|
|
|
menu->hide();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant CustomPropertyEditor::get_variant() const {
|
2015-08-30 00:09:11 +00:00
|
|
|
return v;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-02 09:42:05 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String CustomPropertyEditor::get_name() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text) {
|
|
|
|
owner = p_owner;
|
|
|
|
updating = true;
|
|
|
|
name = p_name;
|
|
|
|
v = p_variant;
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
hint = p_hint;
|
|
|
|
hint_text = p_hint_text;
|
2014-02-10 01:10:30 +00:00
|
|
|
type_button->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (color_picker) {
|
2016-06-08 01:08:12 +00:00
|
|
|
color_picker->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
texture_preview->hide();
|
|
|
|
inheritors_array.clear();
|
|
|
|
text_edit->hide();
|
|
|
|
easing_draw->hide();
|
2015-08-30 00:09:11 +00:00
|
|
|
spinbox->hide();
|
|
|
|
slider->hide();
|
2017-12-25 10:31:53 +00:00
|
|
|
menu->clear();
|
2021-11-20 08:04:57 +00:00
|
|
|
menu->reset_size();
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
|
2020-06-10 14:31:58 +00:00
|
|
|
if (i < MAX_VALUE_EDITORS / 4) {
|
|
|
|
value_hboxes[i]->hide();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
value_editor[i]->hide();
|
|
|
|
value_label[i]->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (i < 4) {
|
2016-01-23 14:20:54 +00:00
|
|
|
scroll[i]->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
|
2015-08-30 00:09:11 +00:00
|
|
|
action_buttons[i]->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 01:20:57 +00:00
|
|
|
checks20gc->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
for (int i = 0; i < 20; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
checks20[i]->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-11-09 13:53:05 +00:00
|
|
|
type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2016-08-26 20:34:25 +00:00
|
|
|
case Variant::BOOL: {
|
2017-01-11 01:20:57 +00:00
|
|
|
checks20gc->show();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
CheckBox *c = checks20[0];
|
2016-08-26 20:34:25 +00:00
|
|
|
c->set_text("True");
|
2017-08-08 02:55:24 +00:00
|
|
|
checks20gc->set_position(Vector2(4, 4) * EDSCALE);
|
2016-08-26 20:34:25 +00:00
|
|
|
c->set_pressed(v);
|
|
|
|
c->show();
|
2017-01-11 01:20:57 +00:00
|
|
|
|
|
|
|
checks20gc->set_size(checks20gc->get_minimum_size());
|
2017-05-09 17:35:48 +00:00
|
|
|
set_size(checks20gc->get_position() + checks20gc->get_size() + c->get_size() + Vector2(4, 4) * EDSCALE);
|
2016-08-26 20:34:25 +00:00
|
|
|
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::INT:
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::FLOAT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_RANGE) {
|
2015-08-30 00:09:11 +00:00
|
|
|
int c = hint_text.get_slice_count(",");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
float min = 0, max = 100, step = type == Variant::FLOAT ? .01 : 1;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (c >= 1) {
|
2020-12-15 12:04:21 +00:00
|
|
|
if (!hint_text.get_slice(",", 0).is_empty()) {
|
2020-07-24 18:07:57 +00:00
|
|
|
min = hint_text.get_slice(",", 0).to_float();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (c >= 2) {
|
2020-12-15 12:04:21 +00:00
|
|
|
if (!hint_text.get_slice(",", 1).is_empty()) {
|
2020-07-24 18:07:57 +00:00
|
|
|
max = hint_text.get_slice(",", 1).to_float();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (c >= 3) {
|
2020-12-15 12:04:21 +00:00
|
|
|
if (!hint_text.get_slice(",", 2).is_empty()) {
|
2020-07-24 18:07:57 +00:00
|
|
|
step = hint_text.get_slice(",", 2).to_float();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (c >= 4 && hint_text.get_slice(",", 3) == "slider") {
|
2015-08-30 00:09:11 +00:00
|
|
|
slider->set_min(min);
|
|
|
|
slider->set_max(max);
|
2016-10-10 10:20:52 +00:00
|
|
|
slider->set_step(step);
|
2017-01-04 04:16:14 +00:00
|
|
|
slider->set_value(v);
|
2015-08-30 00:09:11 +00:00
|
|
|
slider->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
set_size(Size2(110, 30) * EDSCALE);
|
2015-08-30 00:09:11 +00:00
|
|
|
} else {
|
|
|
|
spinbox->set_min(min);
|
|
|
|
spinbox->set_max(max);
|
2016-10-10 10:20:52 +00:00
|
|
|
spinbox->set_step(step);
|
2017-01-04 04:16:14 +00:00
|
|
|
spinbox->set_value(v);
|
2015-08-30 00:09:11 +00:00
|
|
|
spinbox->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
set_size(Size2(70, 35) * EDSCALE);
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_ENUM) {
|
2016-08-26 20:34:25 +00:00
|
|
|
Vector<String> options = hint_text.split(",");
|
2018-10-09 14:10:22 +00:00
|
|
|
int current_val = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < options.size(); i++) {
|
2018-10-09 14:10:22 +00:00
|
|
|
Vector<String> text_split = options[i].split(":");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (text_split.size() != 1) {
|
2018-10-09 14:10:22 +00:00
|
|
|
current_val = text_split[1].to_int();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-10-09 14:10:22 +00:00
|
|
|
menu->add_item(text_split[0]);
|
|
|
|
menu->set_item_metadata(i, current_val);
|
|
|
|
current_val += 1;
|
2016-08-26 20:34:25 +00:00
|
|
|
}
|
2017-03-29 15:29:38 +00:00
|
|
|
menu->set_position(get_position());
|
2016-08-26 20:34:25 +00:00
|
|
|
menu->popup();
|
|
|
|
hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-26 20:34:25 +00:00
|
|
|
return false;
|
|
|
|
|
2021-03-08 19:56:33 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS ||
|
2021-10-28 13:19:35 +00:00
|
|
|
hint == PROPERTY_HINT_LAYERS_2D_RENDER ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_3D_PHYSICS ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_3D_RENDER ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) {
|
2017-01-11 01:20:57 +00:00
|
|
|
String basename;
|
|
|
|
switch (hint) {
|
2017-03-05 15:44:50 +00:00
|
|
|
case PROPERTY_HINT_LAYERS_2D_RENDER:
|
|
|
|
basename = "layer_names/2d_render";
|
|
|
|
break;
|
|
|
|
case PROPERTY_HINT_LAYERS_2D_PHYSICS:
|
|
|
|
basename = "layer_names/2d_physics";
|
|
|
|
break;
|
2021-03-08 19:56:33 +00:00
|
|
|
case PROPERTY_HINT_LAYERS_2D_NAVIGATION:
|
|
|
|
basename = "layer_names/2d_navigation";
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case PROPERTY_HINT_LAYERS_3D_RENDER:
|
|
|
|
basename = "layer_names/3d_render";
|
|
|
|
break;
|
|
|
|
case PROPERTY_HINT_LAYERS_3D_PHYSICS:
|
|
|
|
basename = "layer_names/3d_physics";
|
|
|
|
break;
|
2021-03-08 19:56:33 +00:00
|
|
|
case PROPERTY_HINT_LAYERS_3D_NAVIGATION:
|
|
|
|
basename = "layer_names/3d_navigation";
|
|
|
|
break;
|
2017-01-11 01:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
checks20gc->show();
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t flgs = v;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
Point2 ofs(4, 4);
|
|
|
|
ofs.y += 22 * i;
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
int idx = i * 10 + j;
|
|
|
|
CheckBox *c = checks20[idx];
|
2017-07-19 20:00:46 +00:00
|
|
|
c->set_text(ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(idx + 1)));
|
2017-03-05 15:44:50 +00:00
|
|
|
c->set_pressed(flgs & (1 << (i * 10 + j)));
|
2014-02-10 01:10:30 +00:00
|
|
|
c->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:20:57 +00:00
|
|
|
show();
|
|
|
|
|
2017-12-09 16:42:24 +00:00
|
|
|
checks20gc->set_position(Vector2(4, 4) * EDSCALE);
|
2017-01-11 01:20:57 +00:00
|
|
|
checks20gc->set_size(checks20gc->get_minimum_size());
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
set_size(Vector2(4, 4) * EDSCALE + checks20gc->get_position() + checks20gc->get_size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_EXP_EASING) {
|
2020-12-22 16:24:29 +00:00
|
|
|
easing_draw->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 5 * EDSCALE);
|
|
|
|
easing_draw->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -5 * EDSCALE);
|
|
|
|
easing_draw->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 5 * EDSCALE);
|
|
|
|
easing_draw->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -30 * EDSCALE);
|
|
|
|
type_button->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 3 * EDSCALE);
|
|
|
|
type_button->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -3 * EDSCALE);
|
|
|
|
type_button->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_END, -25 * EDSCALE);
|
|
|
|
type_button->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -7 * EDSCALE);
|
2018-04-22 17:36:01 +00:00
|
|
|
type_button->set_text(TTR("Preset..."));
|
2014-02-10 01:10:30 +00:00
|
|
|
type_button->get_popup()->clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR);
|
|
|
|
type_button->get_popup()->add_item(TTR("Ease In"), EASING_EASE_IN);
|
|
|
|
type_button->get_popup()->add_item(TTR("Ease Out"), EASING_EASE_OUT);
|
|
|
|
if (hint_text != "attenuation") {
|
|
|
|
type_button->get_popup()->add_item(TTR("Zero"), EASING_ZERO);
|
|
|
|
type_button->get_popup()->add_item(TTR("Easing In-Out"), EASING_IN_OUT);
|
|
|
|
type_button->get_popup()->add_item(TTR("Easing Out-In"), EASING_OUT_IN);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type_button->show();
|
|
|
|
easing_draw->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
set_size(Size2(200, 150) * EDSCALE);
|
|
|
|
} else if (hint == PROPERTY_HINT_FLAGS) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<String> flags = hint_text.split(",");
|
2022-03-06 17:04:29 +00:00
|
|
|
uint32_t value = v;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < flags.size(); i++) {
|
2022-03-06 17:04:29 +00:00
|
|
|
uint32_t current_val;
|
|
|
|
Vector<String> text_split = flags[i].split(":");
|
|
|
|
if (text_split.size() != 1) {
|
|
|
|
current_val = text_split[1].to_int();
|
|
|
|
} else {
|
|
|
|
current_val = 1 << i;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2022-03-06 17:04:29 +00:00
|
|
|
menu->add_check_item(text_split[0], current_val);
|
|
|
|
menu->set_item_metadata(i, current_val);
|
|
|
|
if ((value & current_val) == current_val) {
|
|
|
|
menu->set_item_checked(menu->get_item_index(current_val), true);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-29 15:29:38 +00:00
|
|
|
menu->set_position(get_position());
|
2014-02-10 01:10:30 +00:00
|
|
|
menu->popup();
|
|
|
|
hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
List<String> names;
|
|
|
|
names.push_back("value:");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(1, 1, 50, names);
|
2020-09-03 11:22:16 +00:00
|
|
|
value_editor[0]->set_text(TS->format_number(String::num(v)));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING: {
|
2021-09-23 11:08:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_LOCALE_ID) {
|
|
|
|
List<String> names;
|
|
|
|
names.push_back(TTR("Locale..."));
|
|
|
|
names.push_back(TTR("Clear"));
|
|
|
|
config_action_buttons(names);
|
|
|
|
} else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> names;
|
2018-04-22 17:36:01 +00:00
|
|
|
names.push_back(TTR("File..."));
|
2016-05-04 01:25:37 +00:00
|
|
|
names.push_back(TTR("Clear"));
|
2014-02-10 01:10:30 +00:00
|
|
|
config_action_buttons(names);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> names;
|
2018-04-22 17:36:01 +00:00
|
|
|
names.push_back(TTR("Dir..."));
|
2016-05-04 01:25:37 +00:00
|
|
|
names.push_back(TTR("Clear"));
|
2014-02-10 01:10:30 +00:00
|
|
|
config_action_buttons(names);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_ENUM) {
|
2016-08-31 15:49:45 +00:00
|
|
|
Vector<String> options = hint_text.split(",");
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < options.size(); i++) {
|
|
|
|
menu->add_item(options[i], i);
|
2016-08-31 15:49:45 +00:00
|
|
|
}
|
2017-03-29 15:29:38 +00:00
|
|
|
menu->set_position(get_position());
|
2016-08-31 15:49:45 +00:00
|
|
|
menu->popup();
|
|
|
|
hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-31 15:49:45 +00:00
|
|
|
return false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
text_edit->show();
|
|
|
|
text_edit->set_text(v);
|
2017-12-16 00:46:36 +00:00
|
|
|
text_edit->deselect();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
int button_margin = text_edit->get_theme_constant(SNAME("button_margin"), SNAME("Dialogs"));
|
|
|
|
int margin = text_edit->get_theme_constant(SNAME("margin"), SNAME("Dialogs"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
action_buttons[0]->set_anchor(SIDE_LEFT, Control::ANCHOR_END);
|
|
|
|
action_buttons[0]->set_anchor(SIDE_TOP, Control::ANCHOR_END);
|
|
|
|
action_buttons[0]->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
|
|
|
|
action_buttons[0]->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE));
|
|
|
|
action_buttons[0]->set_end(Point2(-margin, -margin));
|
2016-05-04 01:25:37 +00:00
|
|
|
action_buttons[0]->set_text(TTR("Close"));
|
2014-02-10 01:10:30 +00:00
|
|
|
action_buttons[0]->show();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_TYPE_STRING) {
|
2016-08-03 14:28:20 +00:00
|
|
|
if (!create_dialog) {
|
2017-03-05 15:44:50 +00:00
|
|
|
create_dialog = memnew(CreateDialog);
|
2020-02-21 17:28:45 +00:00
|
|
|
create_dialog->connect("create", callable_mp(this, &CustomPropertyEditor::_create_dialog_callback));
|
2016-08-03 14:28:20 +00:00
|
|
|
add_child(create_dialog);
|
|
|
|
}
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!hint_text.is_empty()) {
|
2016-08-03 14:28:20 +00:00
|
|
|
create_dialog->set_base_type(hint_text);
|
|
|
|
} else {
|
|
|
|
create_dialog->set_base_type("Object");
|
|
|
|
}
|
|
|
|
|
2017-03-16 20:58:45 +00:00
|
|
|
create_dialog->popup_create(false);
|
2016-08-03 14:28:20 +00:00
|
|
|
hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE) {
|
2020-02-21 17:28:45 +00:00
|
|
|
#define MAKE_PROPSELECT \
|
|
|
|
if (!property_select) { \
|
|
|
|
property_select = memnew(PropertySelector); \
|
|
|
|
property_select->connect("selected", callable_mp(this, &CustomPropertyEditor::_create_selected_property)); \
|
|
|
|
add_child(property_select); \
|
|
|
|
} \
|
2017-03-05 15:44:50 +00:00
|
|
|
hide();
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
MAKE_PROPSELECT;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant::Type type = Variant::NIL;
|
|
|
|
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
if (hint_text == Variant::get_type_name(Variant::Type(i))) {
|
|
|
|
type = Variant::Type(i);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
if (type != Variant::NIL) {
|
2017-03-05 15:44:50 +00:00
|
|
|
property_select->select_method_from_basic_type(type, v);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE) {
|
2016-08-23 22:29:07 +00:00
|
|
|
MAKE_PROPSELECT
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
property_select->select_method_from_base_type(hint_text, v);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_METHOD_OF_INSTANCE) {
|
2016-08-23 22:29:07 +00:00
|
|
|
MAKE_PROPSELECT
|
|
|
|
|
2020-05-13 09:31:51 +00:00
|
|
|
Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (instance) {
|
2017-03-05 15:44:50 +00:00
|
|
|
property_select->select_method_from_instance(instance, v);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_METHOD_OF_SCRIPT) {
|
2016-08-23 22:29:07 +00:00
|
|
|
MAKE_PROPSELECT
|
|
|
|
|
2020-05-13 09:31:51 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<Script>(obj)) {
|
|
|
|
property_select->select_method_from_script(Object::cast_to<Script>(obj), v);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE) {
|
2016-08-23 22:29:07 +00:00
|
|
|
MAKE_PROPSELECT
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant::Type type = Variant::NIL;
|
|
|
|
String tname = hint_text;
|
2022-02-03 16:03:38 +00:00
|
|
|
if (tname.contains(".")) {
|
2017-03-05 15:44:50 +00:00
|
|
|
tname = tname.get_slice(".", 0);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
if (tname == Variant::get_type_name(Variant::Type(i))) {
|
|
|
|
type = Variant::Type(Variant::Type(i));
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (type != Variant::NIL) {
|
2017-05-20 15:38:03 +00:00
|
|
|
property_select->select_property_from_basic_type(type, v);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE) {
|
2016-08-23 22:29:07 +00:00
|
|
|
MAKE_PROPSELECT
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
property_select->select_property_from_base_type(hint_text, v);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) {
|
2018-01-15 18:43:32 +00:00
|
|
|
MAKE_PROPSELECT
|
|
|
|
|
2020-05-13 09:31:51 +00:00
|
|
|
Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (instance) {
|
2017-03-05 15:44:50 +00:00
|
|
|
property_select->select_property_from_instance(instance, v);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
|
2016-08-23 22:29:07 +00:00
|
|
|
MAKE_PROPSELECT
|
|
|
|
|
2020-05-13 09:31:51 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<Script>(obj)) {
|
|
|
|
property_select->select_property_from_script(Object::cast_to<Script>(obj), v);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
return false;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
List<String> names;
|
|
|
|
names.push_back("string:");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(1, 1, 50, names);
|
|
|
|
value_editor[0]->set_text(v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("x");
|
|
|
|
field_names.push_back("y");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(2, 2, 10, field_names);
|
|
|
|
Vector2 vec = v;
|
|
|
|
value_editor[0]->set_text(String::num(vec.x));
|
|
|
|
value_editor[1]->set_text(String::num(vec.y));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::RECT2: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("x");
|
|
|
|
field_names.push_back("y");
|
|
|
|
field_names.push_back("w");
|
|
|
|
field_names.push_back("h");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(4, 4, 10, field_names);
|
|
|
|
Rect2 r = v;
|
2017-06-03 22:25:13 +00:00
|
|
|
value_editor[0]->set_text(String::num(r.position.x));
|
|
|
|
value_editor[1]->set_text(String::num(r.position.y));
|
2017-03-05 15:44:50 +00:00
|
|
|
value_editor[2]->set_text(String::num(r.size.x));
|
|
|
|
value_editor[3]->set_text(String::num(r.size.y));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("x");
|
|
|
|
field_names.push_back("y");
|
|
|
|
field_names.push_back("z");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(3, 3, 10, field_names);
|
|
|
|
Vector3 vec = v;
|
|
|
|
value_editor[0]->set_text(String::num(vec.x));
|
|
|
|
value_editor[1]->set_text(String::num(vec.y));
|
|
|
|
value_editor[2]->set_text(String::num(vec.z));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("x");
|
|
|
|
field_names.push_back("y");
|
|
|
|
field_names.push_back("z");
|
|
|
|
field_names.push_back("d");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(4, 4, 10, field_names);
|
|
|
|
Plane plane = v;
|
|
|
|
value_editor[0]->set_text(String::num(plane.normal.x));
|
|
|
|
value_editor[1]->set_text(String::num(plane.normal.y));
|
|
|
|
value_editor[2]->set_text(String::num(plane.normal.z));
|
2020-05-10 14:47:11 +00:00
|
|
|
value_editor[3]->set_text(String::num(plane.d));
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-01-20 07:02:02 +00:00
|
|
|
case Variant::QUATERNION: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("x");
|
|
|
|
field_names.push_back("y");
|
|
|
|
field_names.push_back("z");
|
|
|
|
field_names.push_back("w");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(4, 4, 10, field_names);
|
2021-01-20 07:02:02 +00:00
|
|
|
Quaternion q = v;
|
2017-03-05 15:44:50 +00:00
|
|
|
value_editor[0]->set_text(String::num(q.x));
|
|
|
|
value_editor[1]->set_text(String::num(q.y));
|
|
|
|
value_editor[2]->set_text(String::num(q.z));
|
|
|
|
value_editor[3]->set_text(String::num(q.w));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case Variant::AABB: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("px");
|
|
|
|
field_names.push_back("py");
|
|
|
|
field_names.push_back("pz");
|
|
|
|
field_names.push_back("sx");
|
|
|
|
field_names.push_back("sy");
|
|
|
|
field_names.push_back("sz");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(6, 3, 16, field_names);
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB aabb = v;
|
2017-06-06 18:33:51 +00:00
|
|
|
value_editor[0]->set_text(String::num(aabb.position.x));
|
|
|
|
value_editor[1]->set_text(String::num(aabb.position.y));
|
|
|
|
value_editor[2]->set_text(String::num(aabb.position.z));
|
2017-03-05 15:44:50 +00:00
|
|
|
value_editor[3]->set_text(String::num(aabb.size.x));
|
|
|
|
value_editor[4]->set_text(String::num(aabb.size.y));
|
|
|
|
value_editor[5]->set_text(String::num(aabb.size.z));
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case Variant::TRANSFORM2D: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("xx");
|
|
|
|
field_names.push_back("xy");
|
|
|
|
field_names.push_back("yx");
|
|
|
|
field_names.push_back("yy");
|
|
|
|
field_names.push_back("ox");
|
|
|
|
field_names.push_back("oy");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(6, 2, 16, field_names);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform2D basis = v;
|
|
|
|
for (int i = 0; i < 6; i++) {
|
2022-04-24 21:59:24 +00:00
|
|
|
value_editor[i]->set_text(String::num(basis.columns[i / 2][i % 2]));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case Variant::BASIS: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("xx");
|
|
|
|
field_names.push_back("xy");
|
|
|
|
field_names.push_back("xz");
|
|
|
|
field_names.push_back("yx");
|
|
|
|
field_names.push_back("yy");
|
|
|
|
field_names.push_back("yz");
|
|
|
|
field_names.push_back("zx");
|
|
|
|
field_names.push_back("zy");
|
|
|
|
field_names.push_back("zz");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(9, 3, 16, field_names);
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Basis basis = v;
|
|
|
|
for (int i = 0; i < 9; i++) {
|
2022-04-24 22:07:35 +00:00
|
|
|
value_editor[i]->set_text(String::num(basis.rows[i / 3][i % 3]));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-04-28 07:36:08 +00:00
|
|
|
case Variant::TRANSFORM3D: {
|
2017-03-02 09:42:05 +00:00
|
|
|
field_names.push_back("xx");
|
|
|
|
field_names.push_back("xy");
|
|
|
|
field_names.push_back("xz");
|
|
|
|
field_names.push_back("xo");
|
|
|
|
field_names.push_back("yx");
|
|
|
|
field_names.push_back("yy");
|
|
|
|
field_names.push_back("yz");
|
|
|
|
field_names.push_back("yo");
|
|
|
|
field_names.push_back("zx");
|
|
|
|
field_names.push_back("zy");
|
|
|
|
field_names.push_back("zz");
|
|
|
|
field_names.push_back("zo");
|
2017-03-05 15:44:50 +00:00
|
|
|
config_value_editors(12, 4, 16, field_names);
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D tr = v;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2022-04-24 22:07:35 +00:00
|
|
|
value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.rows[i / 3][i % 3]));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
value_editor[3]->set_text(String::num(tr.origin.x));
|
|
|
|
value_editor[7]->set_text(String::num(tr.origin.y));
|
|
|
|
value_editor[11]->set_text(String::num(tr.origin.z));
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::COLOR: {
|
2016-06-08 01:08:12 +00:00
|
|
|
if (!color_picker) {
|
|
|
|
//late init for performance
|
2017-03-05 15:44:50 +00:00
|
|
|
color_picker = memnew(ColorPicker);
|
2018-05-29 12:21:06 +00:00
|
|
|
color_picker->set_deferred_mode(true);
|
2021-12-26 18:58:33 +00:00
|
|
|
value_vbox->add_child(color_picker);
|
2016-06-08 01:08:12 +00:00
|
|
|
color_picker->hide();
|
2020-02-21 17:28:45 +00:00
|
|
|
color_picker->connect("color_changed", callable_mp(this, &CustomPropertyEditor::_color_changed));
|
2019-08-30 20:25:15 +00:00
|
|
|
|
|
|
|
// get default color picker mode from editor settings
|
|
|
|
int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
|
2020-05-14 14:41:43 +00:00
|
|
|
if (default_color_mode == 1) {
|
2019-08-30 20:25:15 +00:00
|
|
|
color_picker->set_hsv_mode(true);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (default_color_mode == 2) {
|
2019-08-30 20:25:15 +00:00
|
|
|
color_picker->set_raw_mode(true);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-02-23 10:22:46 +00:00
|
|
|
|
|
|
|
int picker_shape = EDITOR_GET("interface/inspector/default_color_picker_shape");
|
|
|
|
color_picker->set_picker_shape((ColorPicker::PickerShapeType)picker_shape);
|
2016-06-08 01:08:12 +00:00
|
|
|
}
|
2016-01-23 14:20:54 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
color_picker->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA);
|
2017-01-14 14:07:57 +00:00
|
|
|
color_picker->set_pick_color(v);
|
2016-07-01 13:55:35 +00:00
|
|
|
color_picker->set_focus_on_line_edit();
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::NODE_PATH: {
|
|
|
|
List<String> names;
|
2016-05-04 01:25:37 +00:00
|
|
|
names.push_back(TTR("Assign"));
|
|
|
|
names.push_back(TTR("Clear"));
|
2017-08-02 17:40:17 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) {
|
2017-08-02 17:40:17 +00:00
|
|
|
names.push_back(TTR("Select Node"));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-08-02 17:40:17 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
config_action_buttons(names);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::OBJECT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (hint != PROPERTY_HINT_RESOURCE_TYPE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) {
|
2020-03-12 12:37:40 +00:00
|
|
|
menu->add_item(TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
|
2016-09-12 22:31:07 +00:00
|
|
|
menu->add_separator();
|
2021-12-09 09:42:46 +00:00
|
|
|
} else if (!hint_text.is_empty()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-04-08 16:52:13 +00:00
|
|
|
Vector<EditorData::CustomType> custom_resources;
|
|
|
|
|
|
|
|
if (EditorNode::get_editor_data().get_custom_types().has("Resource")) {
|
|
|
|
custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < hint_text.get_slice_count(","); i++) {
|
|
|
|
String base = hint_text.get_slice(",", i);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-05-19 15:00:06 +00:00
|
|
|
HashSet<String> valid_inheritors;
|
2014-02-10 01:10:30 +00:00
|
|
|
valid_inheritors.insert(base);
|
2015-06-29 03:29:49 +00:00
|
|
|
List<StringName> inheritors;
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors);
|
2018-02-25 00:41:26 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
for (int j = 0; j < custom_resources.size(); j++) {
|
|
|
|
inheritors.push_back(custom_resources[j].name);
|
2018-02-25 00:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<StringName>::Element *E = inheritors.front();
|
|
|
|
while (E) {
|
2014-02-10 01:10:30 +00:00
|
|
|
valid_inheritors.insert(E->get());
|
2017-03-05 15:44:50 +00:00
|
|
|
E = E->next();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 23:43:40 +00:00
|
|
|
for (const String &j : valid_inheritors) {
|
|
|
|
const String &t = j;
|
2018-02-25 00:41:26 +00:00
|
|
|
|
|
|
|
bool is_custom_resource = false;
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> icon;
|
2020-12-15 12:04:21 +00:00
|
|
|
if (!custom_resources.is_empty()) {
|
2019-02-12 20:10:08 +00:00
|
|
|
for (int k = 0; k < custom_resources.size(); k++) {
|
|
|
|
if (custom_resources[k].name == t) {
|
2018-02-25 00:41:26 +00:00
|
|
|
is_custom_resource = true;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (custom_resources[k].icon.is_valid()) {
|
2019-02-12 20:10:08 +00:00
|
|
|
icon = custom_resources[k].icon;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-02-25 00:41:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
if (!is_custom_resource && (!ClassDB::can_instantiate(t) || ClassDB::is_virtual(t))) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-02-25 00:41:26 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
inheritors_array.push_back(t);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int id = TYPE_BASE_ID + idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-12 12:37:40 +00:00
|
|
|
menu->add_item(vformat(TTR("New %s"), t), id);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (menu->get_item_count()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
menu->add_separator();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 12:37:40 +00:00
|
|
|
menu->add_item(TTR("Load"), OBJ_MENU_LOAD);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
if (!Ref<Resource>(v).is_null()) {
|
2020-03-12 12:37:40 +00:00
|
|
|
menu->add_item(TTR("Edit"), OBJ_MENU_EDIT);
|
|
|
|
menu->add_item(TTR("Clear"), OBJ_MENU_CLEAR);
|
|
|
|
menu->add_item(TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
|
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> r = v;
|
2017-01-14 17:14:46 +00:00
|
|
|
if (r.is_valid() && r->get_path().is_resource_file()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
menu->add_separator();
|
2018-10-26 19:11:36 +00:00
|
|
|
menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
|
2017-01-14 17:14:46 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> cb = EditorSettings::get_singleton()->get_resource_clipboard();
|
2017-03-05 15:44:50 +00:00
|
|
|
bool paste_valid = false;
|
2016-01-10 14:33:45 +00:00
|
|
|
if (cb.is_valid()) {
|
2021-12-09 09:42:46 +00:00
|
|
|
if (hint_text.is_empty()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
paste_valid = true;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < hint_text.get_slice_count(","); i++) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ClassDB::is_parent_class(cb->get_class(), hint_text.get_slice(",", i))) {
|
|
|
|
paste_valid = true;
|
2016-01-10 14:33:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-10 14:33:45 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
if (!Ref<Resource>(v).is_null() || paste_valid) {
|
2014-02-10 01:10:30 +00:00
|
|
|
menu->add_separator();
|
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
if (!Ref<Resource>(v).is_null()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
menu->add_item(TTR("Copy"), OBJ_MENU_COPY);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (paste_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
menu->add_item(TTR("Paste"), OBJ_MENU_PASTE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
if (!Ref<Resource>(v).is_null()) {
|
|
|
|
Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(Ref<Resource>(v));
|
2017-09-22 12:20:28 +00:00
|
|
|
if (conversions.size()) {
|
|
|
|
menu->add_separator();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < conversions.size(); i++) {
|
|
|
|
String what = conversions[i]->converts_to();
|
2021-07-13 13:25:56 +00:00
|
|
|
menu->add_item(vformat(TTR("Convert to %s"), what), CONVERT_BASE_ID + i);
|
2017-09-22 12:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
menu->set_position(get_position());
|
2014-02-10 01:10:30 +00:00
|
|
|
menu->popup();
|
|
|
|
hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_BYTE_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::PACKED_INT32_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::PACKED_FLOAT32_ARRAY: {
|
|
|
|
} break;
|
|
|
|
case Variant::PACKED_INT64_ARRAY: {
|
|
|
|
} break;
|
|
|
|
case Variant::PACKED_FLOAT64_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_STRING_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_VECTOR3_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_COLOR_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_file_selected(String p_file) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_DIR) {
|
2017-07-19 20:00:46 +00:00
|
|
|
v = ProjectSettings::get_singleton()->localize_path(p_file);
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_GLOBAL_FILE || hint == PROPERTY_HINT_GLOBAL_DIR) {
|
|
|
|
v = p_file;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::OBJECT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> res = ResourceLoader::load(p_file, type);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (res.is_null()) {
|
2016-05-04 01:25:37 +00:00
|
|
|
error->set_text(TTR("Error loading file: Not a resource!"));
|
2020-03-06 17:00:16 +00:00
|
|
|
error->popup_centered();
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
v = res;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 11:08:50 +00:00
|
|
|
void CustomPropertyEditor::_locale_selected(String p_locale) {
|
|
|
|
if (type == Variant::STRING && hint == PROPERTY_HINT_LOCALE_ID) {
|
|
|
|
v = p_locale;
|
|
|
|
emit_signal(SNAME("variant_changed"));
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void CustomPropertyEditor::_type_create_selected(int p_idx) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (type == Variant::INT || type == Variant::FLOAT) {
|
2017-03-05 15:44:50 +00:00
|
|
|
float newval = 0;
|
|
|
|
switch (p_idx) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case EASING_LINEAR: {
|
2017-03-05 15:44:50 +00:00
|
|
|
newval = 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EASING_EASE_IN: {
|
2017-03-05 15:44:50 +00:00
|
|
|
newval = 2.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EASING_EASE_OUT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
newval = 0.5;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EASING_ZERO: {
|
2017-03-05 15:44:50 +00:00
|
|
|
newval = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EASING_IN_OUT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
newval = -0.5;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case EASING_OUT_IN: {
|
2017-03-05 15:44:50 +00:00
|
|
|
newval = -2.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v = newval;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
easing_draw->update();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (type == Variant::OBJECT) {
|
|
|
|
ERR_FAIL_INDEX(p_idx, inheritors_array.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String intype = inheritors_array[p_idx];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
Variant obj = ClassDB::instantiate(intype);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-02-25 00:41:26 +00:00
|
|
|
if (!obj) {
|
2018-07-29 03:36:43 +00:00
|
|
|
if (ScriptServer::is_global_class(intype)) {
|
|
|
|
obj = EditorNode::get_editor_data().script_class_instance(intype);
|
|
|
|
} else {
|
|
|
|
obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
|
|
|
|
}
|
2018-02-25 00:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(!obj);
|
2021-01-06 19:25:05 +00:00
|
|
|
ERR_FAIL_COND(!Object::cast_to<Resource>(obj));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-22 19:02:57 +00:00
|
|
|
EditorNode::get_editor_data().instantiate_object_properties(obj);
|
2021-01-06 19:25:05 +00:00
|
|
|
v = obj;
|
2020-10-22 19:02:57 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CustomPropertyEditor::_color_changed(const Color &p_color) {
|
|
|
|
v = p_color;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_node_path_selected(NodePath p_path) {
|
2017-01-10 04:04:31 +00:00
|
|
|
if (picking_viewport) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *to_node = get_node(p_path);
|
2017-08-24 20:58:51 +00:00
|
|
|
if (!Object::cast_to<Viewport>(to_node)) {
|
2017-08-23 20:25:14 +00:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
|
2017-01-10 04:04:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<ViewportTexture> vt;
|
2021-06-17 22:03:09 +00:00
|
|
|
vt.instantiate();
|
2017-01-10 04:04:31 +00:00
|
|
|
vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
|
|
|
|
vt->setup_local_to_scene();
|
2017-03-05 15:44:50 +00:00
|
|
|
v = vt;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2017-01-10 04:04:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-02 22:11:05 +00:00
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && !hint_text.is_empty()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *node = get_node(hint_text);
|
2016-08-02 22:11:05 +00:00
|
|
|
if (node) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *tonode = node->get_node(p_path);
|
2016-08-02 22:11:05 +00:00
|
|
|
if (tonode) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_path = node->get_path_to(tonode);
|
2016-08-02 22:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (owner) {
|
2020-04-01 23:20:12 +00:00
|
|
|
Node *node = nullptr;
|
2015-12-13 14:42:29 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (owner->is_class("Node")) {
|
2017-08-24 20:58:51 +00:00
|
|
|
node = Object::cast_to<Node>(owner);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (owner->is_class("ArrayPropertyEdit")) {
|
2017-08-24 20:58:51 +00:00
|
|
|
node = Object::cast_to<ArrayPropertyEdit>(owner)->get_node();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (owner->is_class("DictionaryPropertyEdit")) {
|
2017-10-17 14:39:31 +00:00
|
|
|
node = Object::cast_to<DictionaryPropertyEdit>(owner)->get_node();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-12-13 14:42:29 +00:00
|
|
|
if (!node) {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = p_path;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
|
|
|
call_deferred(SNAME("hide")); //to not mess with dialogs
|
2015-12-13 14:42:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *tonode = node->get_node(p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (tonode) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_path = node->get_path_to(tonode);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v = p_path;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
|
|
|
call_deferred(SNAME("hide")); //to not mess with dialogs
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_action_pressed(int p_which) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (updating) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2016-08-26 20:34:25 +00:00
|
|
|
case Variant::BOOL: {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = checks20[0]->is_pressed();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2016-08-26 20:34:25 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::INT: {
|
2021-03-08 19:56:33 +00:00
|
|
|
if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_2D_RENDER ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_3D_PHYSICS ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_3D_RENDER ||
|
|
|
|
hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t f = v;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (checks20[p_which]->is_pressed()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
f |= (1 << p_which);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
f &= ~(1 << p_which);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v = f;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
2021-09-23 11:08:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_LOCALE_ID) {
|
|
|
|
locale->popup_locale_dialog();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
|
|
|
|
if (p_which == 0) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (hint == PROPERTY_HINT_FILE) {
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_access(EditorFileDialog::ACCESS_RESOURCES);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-06 17:00:16 +00:00
|
|
|
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2014-02-10 01:10:30 +00:00
|
|
|
file->clear_filters();
|
|
|
|
|
|
|
|
file->clear_filters();
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!hint_text.is_empty()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<String> extensions = hint_text.split(",");
|
|
|
|
for (int i = 0; i < extensions.size(); i++) {
|
2014-04-05 15:39:30 +00:00
|
|
|
String filter = extensions[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
if (filter.begins_with(".")) {
|
2017-03-05 15:44:50 +00:00
|
|
|
filter = "*" + extensions[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (!filter.begins_with("*")) {
|
2017-03-05 15:44:50 +00:00
|
|
|
filter = "*." + extensions[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
file->add_filter(filter + " ; " + extensions[i].to_upper());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-11 16:45:19 +00:00
|
|
|
file->popup_file_dialog();
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = "";
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
|
|
|
|
if (p_which == 0) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (hint == PROPERTY_HINT_DIR) {
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_access(EditorFileDialog::ACCESS_RESOURCES);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-03-06 17:00:16 +00:00
|
|
|
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
|
2014-02-10 01:10:30 +00:00
|
|
|
file->clear_filters();
|
2020-07-11 16:45:19 +00:00
|
|
|
file->popup_file_dialog();
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = "";
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::NODE_PATH: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_which == 0) {
|
|
|
|
picking_viewport = false;
|
2017-01-10 04:04:31 +00:00
|
|
|
scene_tree->set_title(TTR("Pick a Node"));
|
2020-07-11 16:45:19 +00:00
|
|
|
scene_tree->popup_scenetree_dialog();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_which == 1) {
|
|
|
|
v = NodePath();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2017-08-02 17:40:17 +00:00
|
|
|
hide();
|
|
|
|
} else if (p_which == 2) {
|
2017-08-24 20:58:51 +00:00
|
|
|
if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) {
|
|
|
|
Node *target_node = Object::cast_to<Node>(owner)->get_node(v);
|
2017-08-02 17:40:17 +00:00
|
|
|
EditorNode::get_singleton()->get_editor_selection()->clear();
|
2021-11-17 20:08:55 +00:00
|
|
|
SceneTreeDock::get_singleton()->set_selected(target_node);
|
2017-08-02 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 13:47:50 +00:00
|
|
|
hide();
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
2017-08-02 17:40:17 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::OBJECT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_which == 0) {
|
2020-12-15 12:04:21 +00:00
|
|
|
ERR_FAIL_COND(inheritors_array.is_empty());
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String intype = inheritors_array[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
|
2021-06-17 22:03:09 +00:00
|
|
|
Variant obj = ClassDB::instantiate(intype);
|
2018-02-25 00:41:26 +00:00
|
|
|
|
|
|
|
if (!obj) {
|
2018-07-29 03:36:43 +00:00
|
|
|
if (ScriptServer::is_global_class(intype)) {
|
|
|
|
obj = EditorNode::get_editor_data().script_class_instance(intype);
|
|
|
|
} else {
|
|
|
|
obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
|
|
|
|
}
|
2018-02-25 00:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_BREAK(!obj);
|
2021-01-06 19:25:05 +00:00
|
|
|
ERR_BREAK(!Object::cast_to<Resource>(obj));
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2020-10-22 19:02:57 +00:00
|
|
|
EditorNode::get_editor_data().instantiate_object_properties(obj);
|
2021-01-06 19:25:05 +00:00
|
|
|
v = obj;
|
2020-10-22 19:02:57 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_which == 1) {
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_access(EditorFileDialog::ACCESS_RESOURCES);
|
2020-03-06 17:00:16 +00:00
|
|
|
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> extensions;
|
2017-03-05 15:44:50 +00:00
|
|
|
String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type(type, &extensions);
|
2014-02-10 01:10:30 +00:00
|
|
|
file->clear_filters();
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &E : extensions) {
|
2021-07-16 03:45:57 +00:00
|
|
|
file->add_filter("*." + E + " ; " + E.to_upper());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2020-07-11 16:45:19 +00:00
|
|
|
file->popup_file_dialog();
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_which == 2) {
|
2022-05-02 23:43:50 +00:00
|
|
|
Ref<Resource> r = v;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-13 19:03:10 +00:00
|
|
|
if (!r.is_null()) {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("resource_edit_request"));
|
2015-08-30 00:09:11 +00:00
|
|
|
hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_which == 3) {
|
|
|
|
v = Variant();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_which == 4) {
|
2020-02-13 19:03:10 +00:00
|
|
|
Ref<Resource> res_orig = v;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (res_orig.is_null()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<PropertyInfo> property_list;
|
|
|
|
res_orig->get_property_list(&property_list);
|
2020-03-17 06:33:00 +00:00
|
|
|
List<Pair<String, Variant>> propvalues;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const PropertyInfo &pi : property_list) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Pair<String, Variant> p;
|
|
|
|
if (pi.usage & PROPERTY_USAGE_STORAGE) {
|
|
|
|
p.first = pi.name;
|
|
|
|
p.second = res_orig->get(pi.name);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
propvalues.push_back(p);
|
|
|
|
}
|
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
Ref<Resource> res = Ref<Resource>(ClassDB::instantiate(res_orig->get_class()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(res.is_null());
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const Pair<String, Variant> &p : propvalues) {
|
2017-03-05 15:44:50 +00:00
|
|
|
res->set(p.first, p.second);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:03:10 +00:00
|
|
|
v = res;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) {
|
|
|
|
Ref<InputEventMouseMotion> mm = p_ev;
|
2016-01-23 14:20:54 +00:00
|
|
|
|
2021-08-13 21:31:57 +00:00
|
|
|
if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_LEFT) != MouseButton::NONE) {
|
2017-05-20 15:38:03 +00:00
|
|
|
float rel = mm->get_relative().x;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (rel == 0) {
|
2015-08-30 00:09:11 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool flip = hint_text == "attenuation";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (flip) {
|
2017-03-05 15:44:50 +00:00
|
|
|
rel = -rel;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float val = v;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (val == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
bool sg = val < 0;
|
|
|
|
val = Math::absf(val);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
val = Math::log(val) / Math::log((float)2.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
//logspace
|
2017-03-05 15:44:50 +00:00
|
|
|
val += rel * 0.05;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
val = Math::pow(2.0f, val);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (sg) {
|
2017-03-05 15:44:50 +00:00
|
|
|
val = -val;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v = val;
|
2014-02-10 01:10:30 +00:00
|
|
|
easing_draw->update();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_draw_easing() {
|
|
|
|
RID ci = easing_draw->get_canvas_item();
|
|
|
|
|
|
|
|
Size2 s = easing_draw->get_size();
|
2017-03-05 15:44:50 +00:00
|
|
|
Rect2 r(Point2(), s);
|
|
|
|
r = r.grow(3);
|
2021-07-17 21:22:52 +00:00
|
|
|
easing_draw->get_theme_stylebox(SNAME("normal"), SNAME("LineEdit"))->draw(ci, r);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int points = 48;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float prev = 1.0;
|
|
|
|
float exp = v;
|
|
|
|
bool flip = hint_text == "attenuation";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<Font> f = easing_draw->get_theme_font(SNAME("font"), SNAME("Label"));
|
|
|
|
int font_size = easing_draw->get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
|
|
|
Color color = easing_draw->get_theme_color(SNAME("font_color"), SNAME("Label"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 1; i <= points; i++) {
|
|
|
|
float ifl = i / float(points);
|
|
|
|
float iflp = (i - 1) / float(points);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float h = 1.0 - Math::ease(ifl, exp);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (flip) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ifl = 1.0 - ifl;
|
|
|
|
iflp = 1.0 - iflp;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(iflp * s.width, prev * s.height), Point2(ifl * s.width, h * s.height), color);
|
2017-03-05 15:44:50 +00:00
|
|
|
prev = h;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), String::num(exp, 2), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_text_edit_changed() {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = text_edit->get_text();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 14:28:20 +00:00
|
|
|
void CustomPropertyEditor::_create_dialog_callback() {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = create_dialog->get_selected_type();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2016-08-03 14:28:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CustomPropertyEditor::_create_selected_property(const String &p_prop) {
|
|
|
|
v = p_prop;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void CustomPropertyEditor::_modified(String p_string) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (updating) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-08-26 15:46:49 +00:00
|
|
|
|
2021-06-05 16:04:52 +00:00
|
|
|
Variant prev_v = v;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = true;
|
|
|
|
switch (type) {
|
2016-08-04 01:06:39 +00:00
|
|
|
case Variant::INT: {
|
2020-09-03 11:22:16 +00:00
|
|
|
String text = TS->parse_number(value_editor[0]->get_text());
|
2018-09-13 19:53:14 +00:00
|
|
|
Ref<Expression> expr;
|
2021-06-17 22:03:09 +00:00
|
|
|
expr.instantiate();
|
2018-09-13 19:53:14 +00:00
|
|
|
Error err = expr->parse(text);
|
|
|
|
if (err != OK) {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = value_editor[0]->get_text().to_int();
|
2018-09-13 19:53:14 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2020-04-01 23:20:12 +00:00
|
|
|
v = expr->execute(Array(), nullptr, false);
|
2018-09-13 19:53:14 +00:00
|
|
|
}
|
2016-08-04 01:06:39 +00:00
|
|
|
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2021-06-05 16:04:52 +00:00
|
|
|
}
|
2016-08-04 01:06:39 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::FLOAT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint != PROPERTY_HINT_EXP_EASING) {
|
2020-09-03 11:22:16 +00:00
|
|
|
String text = TS->parse_number(value_editor[0]->get_text());
|
2018-09-13 19:53:14 +00:00
|
|
|
v = _parse_real_expression(text);
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2021-06-05 16:04:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = value_editor[0]->get_text();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2: {
|
|
|
|
Vector2 vec;
|
2018-09-13 19:53:14 +00:00
|
|
|
vec.x = _parse_real_expression(value_editor[0]->get_text());
|
|
|
|
vec.y = _parse_real_expression(value_editor[1]->get_text());
|
2017-03-05 15:44:50 +00:00
|
|
|
v = vec;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::RECT2: {
|
|
|
|
Rect2 r2;
|
2018-09-13 19:53:14 +00:00
|
|
|
|
|
|
|
r2.position.x = _parse_real_expression(value_editor[0]->get_text());
|
|
|
|
r2.position.y = _parse_real_expression(value_editor[1]->get_text());
|
|
|
|
r2.size.x = _parse_real_expression(value_editor[2]->get_text());
|
|
|
|
r2.size.y = _parse_real_expression(value_editor[3]->get_text());
|
2017-03-05 15:44:50 +00:00
|
|
|
v = r2;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
Vector3 vec;
|
2018-09-13 19:53:14 +00:00
|
|
|
vec.x = _parse_real_expression(value_editor[0]->get_text());
|
|
|
|
vec.y = _parse_real_expression(value_editor[1]->get_text());
|
|
|
|
vec.z = _parse_real_expression(value_editor[2]->get_text());
|
2017-03-05 15:44:50 +00:00
|
|
|
v = vec;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
Plane pl;
|
2018-09-13 19:53:14 +00:00
|
|
|
pl.normal.x = _parse_real_expression(value_editor[0]->get_text());
|
|
|
|
pl.normal.y = _parse_real_expression(value_editor[1]->get_text());
|
|
|
|
pl.normal.z = _parse_real_expression(value_editor[2]->get_text());
|
2020-05-10 14:47:11 +00:00
|
|
|
pl.d = _parse_real_expression(value_editor[3]->get_text());
|
2017-03-05 15:44:50 +00:00
|
|
|
v = pl;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-01-20 07:02:02 +00:00
|
|
|
case Variant::QUATERNION: {
|
|
|
|
Quaternion q;
|
2018-09-13 19:53:14 +00:00
|
|
|
q.x = _parse_real_expression(value_editor[0]->get_text());
|
|
|
|
q.y = _parse_real_expression(value_editor[1]->get_text());
|
|
|
|
q.z = _parse_real_expression(value_editor[2]->get_text());
|
|
|
|
q.w = _parse_real_expression(value_editor[3]->get_text());
|
2017-03-05 15:44:50 +00:00
|
|
|
v = q;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case Variant::AABB: {
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 pos;
|
|
|
|
Vector3 size;
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2018-09-13 19:53:14 +00:00
|
|
|
pos.x = _parse_real_expression(value_editor[0]->get_text());
|
|
|
|
pos.y = _parse_real_expression(value_editor[1]->get_text());
|
|
|
|
pos.z = _parse_real_expression(value_editor[2]->get_text());
|
|
|
|
size.x = _parse_real_expression(value_editor[3]->get_text());
|
|
|
|
size.y = _parse_real_expression(value_editor[4]->get_text());
|
|
|
|
size.z = _parse_real_expression(value_editor[5]->get_text());
|
2017-11-17 02:09:00 +00:00
|
|
|
v = AABB(pos, size);
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case Variant::TRANSFORM2D: {
|
|
|
|
Transform2D m;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2022-04-24 21:59:24 +00:00
|
|
|
m.columns[i / 2][i % 2] = _parse_real_expression(value_editor[i]->get_text());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v = m;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case Variant::BASIS: {
|
|
|
|
Basis m;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2022-04-24 22:07:35 +00:00
|
|
|
m.rows[i / 3][i % 3] = _parse_real_expression(value_editor[i]->get_text());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v = m;
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-04-28 07:36:08 +00:00
|
|
|
case Variant::TRANSFORM3D: {
|
2017-01-11 03:52:51 +00:00
|
|
|
Basis basis;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2022-04-24 22:07:35 +00:00
|
|
|
basis.rows[i / 3][i % 3] = _parse_real_expression(value_editor[(i / 3) * 4 + i % 3]->get_text());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 origin;
|
2016-05-01 08:33:32 +00:00
|
|
|
|
2018-09-13 19:53:14 +00:00
|
|
|
origin.x = _parse_real_expression(value_editor[3]->get_text());
|
|
|
|
origin.y = _parse_real_expression(value_editor[7]->get_text());
|
|
|
|
origin.z = _parse_real_expression(value_editor[11]->get_text());
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
v = Transform3D(basis, origin);
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
|
|
|
_emit_changed_whole_or_field();
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::COLOR: {
|
|
|
|
} break;
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::NODE_PATH: {
|
2017-03-05 15:44:50 +00:00
|
|
|
v = NodePath(value_editor[0]->get_text());
|
2021-06-05 16:04:52 +00:00
|
|
|
if (v != prev_v) {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2021-06-05 16:04:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_BYTE_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::PACKED_INT32_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::PACKED_FLOAT32_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_STRING_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_VECTOR3_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case Variant::PACKED_COLOR_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 19:53:14 +00:00
|
|
|
real_t CustomPropertyEditor::_parse_real_expression(String text) {
|
|
|
|
Ref<Expression> expr;
|
2021-06-17 22:03:09 +00:00
|
|
|
expr.instantiate();
|
2018-09-13 19:53:14 +00:00
|
|
|
Error err = expr->parse(text);
|
|
|
|
real_t out;
|
|
|
|
if (err != OK) {
|
2020-07-24 18:07:57 +00:00
|
|
|
out = value_editor[0]->get_text().to_float();
|
2018-09-13 19:53:14 +00:00
|
|
|
} else {
|
2020-04-01 23:20:12 +00:00
|
|
|
out = expr->execute(Array(), nullptr, false);
|
2018-09-13 19:53:14 +00:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-03-02 09:42:05 +00:00
|
|
|
void CustomPropertyEditor::_emit_changed_whole_or_field() {
|
2021-08-13 21:31:57 +00:00
|
|
|
if (!Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2017-03-02 09:42:05 +00:00
|
|
|
} else {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_field_changed"), field_names[focused_value_editor]);
|
2017-03-02 09:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CustomPropertyEditor::_range_modified(double p_value) {
|
|
|
|
v = p_value;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("variant_changed"));
|
2015-08-30 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:16:00 +00:00
|
|
|
void CustomPropertyEditor::_focus_enter() {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case Variant::FLOAT:
|
2014-02-27 14:16:00 +00:00
|
|
|
case Variant::STRING:
|
|
|
|
case Variant::VECTOR2:
|
|
|
|
case Variant::RECT2:
|
|
|
|
case Variant::VECTOR3:
|
|
|
|
case Variant::PLANE:
|
2021-01-20 07:02:02 +00:00
|
|
|
case Variant::QUATERNION:
|
2017-11-17 02:09:00 +00:00
|
|
|
case Variant::AABB:
|
2017-01-11 03:52:51 +00:00
|
|
|
case Variant::TRANSFORM2D:
|
|
|
|
case Variant::BASIS:
|
2021-04-28 07:36:08 +00:00
|
|
|
case Variant::TRANSFORM3D: {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
|
2014-02-27 14:16:00 +00:00
|
|
|
if (value_editor[i]->has_focus()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
focused_value_editor = i;
|
2014-02-27 14:16:00 +00:00
|
|
|
value_editor[i]->select_all();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-27 14:16:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_focus_exit() {
|
2021-06-05 16:04:52 +00:00
|
|
|
_modified(String());
|
2014-02-27 14:16:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) {
|
2021-08-29 11:08:02 +00:00
|
|
|
Ref<StyleBox> sb = action_buttons[0]->get_theme_stylebox(SNAME("button"));
|
2020-12-22 16:24:29 +00:00
|
|
|
int margin_top = sb->get_margin(SIDE_TOP);
|
|
|
|
int margin_left = sb->get_margin(SIDE_LEFT);
|
|
|
|
int margin_bottom = sb->get_margin(SIDE_BOTTOM);
|
|
|
|
int margin_right = sb->get_margin(SIDE_RIGHT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-23 20:54:45 +00:00
|
|
|
int max_width = 0;
|
|
|
|
int height = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
|
|
|
|
if (i < p_strings.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
action_buttons[i]->show();
|
2015-08-30 00:09:11 +00:00
|
|
|
action_buttons[i]->set_text(p_strings[i]);
|
2017-12-23 20:54:45 +00:00
|
|
|
|
|
|
|
Size2 btn_m_size = action_buttons[i]->get_minimum_size();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (btn_m_size.width > max_width) {
|
2017-12-23 20:54:45 +00:00
|
|
|
max_width = btn_m_size.width;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-23 20:54:45 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
action_buttons[i]->hide();
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 20:54:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < p_strings.size(); i++) {
|
|
|
|
Size2 btn_m_size = action_buttons[i]->get_size();
|
|
|
|
action_buttons[i]->set_position(Point2(0, height) + Point2(margin_left, margin_top));
|
|
|
|
action_buttons[i]->set_size(Size2(max_width, btn_m_size.height));
|
|
|
|
|
|
|
|
height += btn_m_size.height;
|
|
|
|
}
|
|
|
|
set_size(Size2(max_width, height) + Size2(margin_left + margin_right, margin_top + margin_bottom));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings) {
|
2017-10-28 00:22:52 +00:00
|
|
|
int cell_width = 95;
|
|
|
|
int cell_height = 25;
|
|
|
|
int cell_margin = 5;
|
2017-03-05 15:44:50 +00:00
|
|
|
int rows = ((p_amount - 1) / p_columns) + 1;
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-10-28 00:22:52 +00:00
|
|
|
set_size(Size2(cell_margin + p_label_w + (cell_width + cell_margin + p_label_w) * p_columns, cell_margin + (cell_height + cell_margin) * rows) * EDSCALE);
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
|
2020-10-20 14:41:10 +00:00
|
|
|
value_label[i]->get_parent()->remove_child(value_label[i]);
|
|
|
|
value_editor[i]->get_parent()->remove_child(value_editor[i]);
|
|
|
|
|
|
|
|
int box_id = i / p_columns;
|
|
|
|
value_hboxes[box_id]->add_child(value_label[i]);
|
|
|
|
value_hboxes[box_id]->add_child(value_editor[i]);
|
|
|
|
|
2020-06-10 14:31:58 +00:00
|
|
|
if (i < MAX_VALUE_EDITORS / 4) {
|
|
|
|
if (i <= p_amount / 4) {
|
|
|
|
value_hboxes[i]->show();
|
|
|
|
} else {
|
|
|
|
value_hboxes[i]->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i < p_amount) {
|
2014-02-10 01:10:30 +00:00
|
|
|
value_editor[i]->show();
|
|
|
|
value_label[i]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
value_label[i]->set_text(i < p_strings.size() ? p_strings[i] : String(""));
|
2014-02-10 01:10:30 +00:00
|
|
|
value_editor[i]->set_editable(!read_only);
|
|
|
|
} else {
|
|
|
|
value_editor[i]->hide();
|
|
|
|
value_label[i]->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomPropertyEditor::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("variant_changed"));
|
|
|
|
ADD_SIGNAL(MethodInfo("variant_field_changed", PropertyInfo(Variant::STRING, "field")));
|
|
|
|
ADD_SIGNAL(MethodInfo("resource_edit_request"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2018-09-11 14:16:04 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
CustomPropertyEditor::CustomPropertyEditor() {
|
2020-06-10 14:31:58 +00:00
|
|
|
value_vbox = memnew(VBoxContainer);
|
|
|
|
add_child(value_vbox);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
|
2020-06-10 14:31:58 +00:00
|
|
|
if (i < MAX_VALUE_EDITORS / 4) {
|
|
|
|
value_hboxes[i] = memnew(HBoxContainer);
|
|
|
|
value_vbox->add_child(value_hboxes[i]);
|
|
|
|
value_hboxes[i]->hide();
|
|
|
|
}
|
|
|
|
int hbox_idx = i / 4;
|
2017-03-05 15:44:50 +00:00
|
|
|
value_label[i] = memnew(Label);
|
2020-06-10 14:31:58 +00:00
|
|
|
value_hboxes[hbox_idx]->add_child(value_label[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
value_label[i]->hide();
|
2020-06-10 14:31:58 +00:00
|
|
|
value_editor[i] = memnew(LineEdit);
|
|
|
|
value_hboxes[hbox_idx]->add_child(value_editor[i]);
|
|
|
|
value_editor[i]->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
value_editor[i]->hide();
|
2021-06-16 16:43:34 +00:00
|
|
|
value_editor[i]->connect("text_submitted", callable_mp(this, &CustomPropertyEditor::_modified));
|
2020-02-21 17:28:45 +00:00
|
|
|
value_editor[i]->connect("focus_entered", callable_mp(this, &CustomPropertyEditor::_focus_enter));
|
|
|
|
value_editor[i]->connect("focus_exited", callable_mp(this, &CustomPropertyEditor::_focus_exit));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
focused_value_editor = -1;
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
scroll[i] = memnew(HScrollBar);
|
2016-01-23 14:20:54 +00:00
|
|
|
scroll[i]->hide();
|
|
|
|
scroll[i]->set_min(0);
|
|
|
|
scroll[i]->set_max(1.0);
|
|
|
|
scroll[i]->set_step(0.01);
|
|
|
|
add_child(scroll[i]);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
checks20gc = memnew(GridContainer);
|
2017-01-11 01:20:57 +00:00
|
|
|
add_child(checks20gc);
|
|
|
|
checks20gc->set_columns(11);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
if (i == 5 || i == 15) {
|
|
|
|
Control *space = memnew(Control);
|
|
|
|
space->set_custom_minimum_size(Size2(20, 0) * EDSCALE);
|
2017-01-11 01:20:57 +00:00
|
|
|
checks20gc->add_child(space);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
checks20[i] = memnew(CheckBox);
|
2014-05-14 04:22:15 +00:00
|
|
|
checks20[i]->set_toggle_mode(true);
|
2020-03-12 12:37:40 +00:00
|
|
|
checks20[i]->set_focus_mode(Control::FOCUS_NONE);
|
2017-01-11 01:20:57 +00:00
|
|
|
checks20gc->add_child(checks20[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
checks20[i]->hide();
|
2020-02-21 17:28:45 +00:00
|
|
|
checks20[i]->connect("pressed", callable_mp(this, &CustomPropertyEditor::_action_pressed), make_binds(i));
|
2017-03-05 15:44:50 +00:00
|
|
|
checks20[i]->set_tooltip(vformat(TTR("Bit %d, val %d."), i, 1 << i));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
text_edit = memnew(TextEdit);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(text_edit);
|
2020-12-22 16:24:29 +00:00
|
|
|
text_edit->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
|
2021-08-29 11:08:02 +00:00
|
|
|
text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2020-12-22 16:24:29 +00:00
|
|
|
text_edit->set_offset(SIDE_BOTTOM, -30);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
text_edit->hide();
|
2020-02-21 17:28:45 +00:00
|
|
|
text_edit->connect("text_changed", callable_mp(this, &CustomPropertyEditor::_text_edit_changed));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
color_picker = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
file = memnew(EditorFileDialog);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(file);
|
2014-02-10 01:10:30 +00:00
|
|
|
file->hide();
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
file->connect("file_selected", callable_mp(this, &CustomPropertyEditor::_file_selected));
|
|
|
|
file->connect("dir_selected", callable_mp(this, &CustomPropertyEditor::_file_selected));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-09-23 11:08:50 +00:00
|
|
|
locale = memnew(EditorLocaleDialog);
|
|
|
|
value_vbox->add_child(locale);
|
|
|
|
locale->hide();
|
|
|
|
|
|
|
|
locale->connect("locale_selected", callable_mp(this, &CustomPropertyEditor::_locale_selected));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
error = memnew(ConfirmationDialog);
|
2016-05-04 01:25:37 +00:00
|
|
|
error->set_title(TTR("Error!"));
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(error);
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scene_tree = memnew(SceneTreeDialog);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(scene_tree);
|
2020-02-21 17:28:45 +00:00
|
|
|
scene_tree->connect("selected", callable_mp(this, &CustomPropertyEditor::_node_path_selected));
|
2015-06-22 03:03:19 +00:00
|
|
|
scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
texture_preview = memnew(TextureRect);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(texture_preview);
|
2014-02-10 01:10:30 +00:00
|
|
|
texture_preview->hide();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
easing_draw = memnew(Control);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(easing_draw);
|
2014-02-10 01:10:30 +00:00
|
|
|
easing_draw->hide();
|
2020-02-21 17:28:45 +00:00
|
|
|
easing_draw->connect("draw", callable_mp(this, &CustomPropertyEditor::_draw_easing));
|
|
|
|
easing_draw->connect("gui_input", callable_mp(this, &CustomPropertyEditor::_drag_easing));
|
2014-02-10 01:10:30 +00:00
|
|
|
easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
|
|
|
|
|
2017-07-29 10:38:16 +00:00
|
|
|
type_button = memnew(MenuButton);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(type_button);
|
2017-07-29 10:38:16 +00:00
|
|
|
type_button->hide();
|
2020-02-21 17:28:45 +00:00
|
|
|
type_button->get_popup()->connect("id_pressed", callable_mp(this, &CustomPropertyEditor::_type_create_selected));
|
2017-07-29 10:38:16 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
menu = memnew(PopupMenu);
|
2020-03-12 12:37:40 +00:00
|
|
|
// menu->set_pass_on_modal_close_click(false);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(menu);
|
2020-02-21 17:28:45 +00:00
|
|
|
menu->connect("id_pressed", callable_mp(this, &CustomPropertyEditor::_menu_option));
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
evaluator = nullptr;
|
2016-05-01 08:33:32 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
spinbox = memnew(SpinBox);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(spinbox);
|
2020-12-22 16:24:29 +00:00
|
|
|
spinbox->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
|
2020-02-21 17:28:45 +00:00
|
|
|
spinbox->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified));
|
2015-08-30 00:09:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
slider = memnew(HSlider);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(slider);
|
2020-12-22 16:24:29 +00:00
|
|
|
slider->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
|
2020-02-21 17:28:45 +00:00
|
|
|
slider->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified));
|
2016-08-03 14:28:20 +00:00
|
|
|
|
2021-08-29 11:08:02 +00:00
|
|
|
action_hboxes = memnew(HBoxContainer);
|
2021-11-25 02:58:47 +00:00
|
|
|
action_hboxes->set_alignment(BoxContainer::ALIGNMENT_CENTER);
|
2021-08-29 11:08:02 +00:00
|
|
|
value_vbox->add_child(action_hboxes);
|
|
|
|
for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
|
|
|
|
action_buttons[i] = memnew(Button);
|
|
|
|
action_buttons[i]->hide();
|
|
|
|
action_hboxes->add_child(action_buttons[i]);
|
|
|
|
Vector<Variant> binds;
|
|
|
|
binds.push_back(i);
|
|
|
|
action_buttons[i]->connect("pressed", callable_mp(this, &CustomPropertyEditor::_action_pressed), binds);
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
create_dialog = nullptr;
|
|
|
|
property_select = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|