2017-01-16 07:04:19 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* property_selector.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
#include "property_selector.h"
|
|
|
|
|
2022-08-01 14:04:35 +00:00
|
|
|
#include "editor/editor_help.h"
|
2018-09-02 21:40:51 +00:00
|
|
|
#include "editor/editor_node.h"
|
2024-01-15 12:14:55 +00:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2022-08-01 14:04:35 +00:00
|
|
|
#include "scene/gui/line_edit.h"
|
|
|
|
#include "scene/gui/tree.h"
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
void PropertySelector::_text_changed(const String &p_newtext) {
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2024-08-31 17:23:34 +00:00
|
|
|
void PropertySelector::_sbox_input(const Ref<InputEvent> &p_event) {
|
|
|
|
// Redirect navigational key events to the tree.
|
|
|
|
Ref<InputEventKey> key = p_event;
|
|
|
|
if (key.is_valid()) {
|
|
|
|
if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down")) {
|
|
|
|
search_options->gui_input(key);
|
|
|
|
search_box->accept_event();
|
|
|
|
|
|
|
|
TreeItem *root = search_options->get_root();
|
|
|
|
if (!root->get_first_child()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-08-31 17:23:34 +00:00
|
|
|
TreeItem *current = search_options->get_selected();
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-08-31 17:23:34 +00:00
|
|
|
TreeItem *item = search_options->get_next_selected(root);
|
|
|
|
while (item) {
|
|
|
|
item->deselect(0);
|
|
|
|
item = search_options->get_next_selected(item);
|
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-08-31 17:23:34 +00:00
|
|
|
current->select(0);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_update_search() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (properties) {
|
2016-08-23 22:29:07 +00:00
|
|
|
set_title(TTR("Select Property"));
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (virtuals_only) {
|
2017-09-12 10:58:18 +00:00
|
|
|
set_title(TTR("Select Virtual Method"));
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2016-08-23 22:29:07 +00:00
|
|
|
set_title(TTR("Select Method"));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
search_options->clear();
|
2024-04-11 08:21:44 +00:00
|
|
|
help_bit->set_custom_text(String(), String(), String());
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
TreeItem *root = search_options->create_item();
|
|
|
|
|
2020-08-19 16:28:05 +00:00
|
|
|
// Allow using spaces in place of underscores in the search string (makes the search more fault-tolerant).
|
|
|
|
const String search_text = search_box->get_text().replace(" ", "_");
|
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
if (properties) {
|
|
|
|
List<PropertyInfo> props;
|
|
|
|
|
|
|
|
if (instance) {
|
|
|
|
instance->get_property_list(&props, true);
|
|
|
|
} else if (type != Variant::NIL) {
|
|
|
|
Variant v;
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
2020-11-09 03:19:09 +00:00
|
|
|
Variant::construct(type, v, nullptr, 0, ce);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
v.get_property_list(&props);
|
|
|
|
} else {
|
|
|
|
Object *obj = ObjectDB::get_instance(script);
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<Script>(obj)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
props.push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
|
2017-08-24 20:58:51 +00:00
|
|
|
Object::cast_to<Script>(obj)->get_script_property_list(&props);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringName base = base_type;
|
|
|
|
while (base) {
|
|
|
|
props.push_back(PropertyInfo(Variant::NIL, base, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
|
2017-01-03 02:03:46 +00:00
|
|
|
ClassDB::get_property_list(base, &props, true);
|
|
|
|
base = ClassDB::get_parent_class(base);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
TreeItem *category = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
bool found = false;
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const PropertyInfo &E : props) {
|
2021-07-16 03:45:57 +00:00
|
|
|
if (E.usage == PROPERTY_USAGE_CATEGORY) {
|
2021-03-07 20:07:30 +00:00
|
|
|
if (category && category->get_first_child() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
category = search_options->create_item(root);
|
2021-07-16 03:45:57 +00:00
|
|
|
category->set_text(0, E.name);
|
2016-08-23 22:29:07 +00:00
|
|
|
category->set_selectable(0, false);
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> icon;
|
2021-07-16 03:45:57 +00:00
|
|
|
if (E.name == "Script Variables") {
|
2023-08-13 00:33:39 +00:00
|
|
|
icon = search_options->get_editor_theme_icon(SNAME("Script"));
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
2021-07-16 03:45:57 +00:00
|
|
|
icon = EditorNode::get_singleton()->get_class_icon(E.name);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
category->set_icon(0, icon);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
if (!(E.usage & PROPERTY_USAGE_EDITOR) && !(E.usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-05-06 08:26:10 +00:00
|
|
|
if (!search_box->get_text().is_empty() && !E.name.containsn(search_text)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2024-08-15 11:43:47 +00:00
|
|
|
if (!type_filter.is_empty() && !type_filter.has(E.type)) {
|
2018-06-07 15:46:14 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
TreeItem *item = search_options->create_item(category ? category : root);
|
2021-07-16 03:45:57 +00:00
|
|
|
item->set_text(0, E.name);
|
|
|
|
item->set_metadata(0, E.name);
|
2024-08-15 07:00:56 +00:00
|
|
|
item->set_icon(0, search_options->get_editor_theme_icon(Variant::get_type_name(E.type)));
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-05-06 08:26:10 +00:00
|
|
|
if (!found && !search_box->get_text().is_empty() && E.name.containsn(search_text)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
item->select(0);
|
|
|
|
found = true;
|
2024-09-01 23:18:54 +00:00
|
|
|
} else if (!found && search_box->get_text().is_empty() && E.name == selected) {
|
|
|
|
item->select(0);
|
|
|
|
found = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item->set_selectable(0, true);
|
2024-08-15 11:43:47 +00:00
|
|
|
|
|
|
|
_create_subproperties(item, E.type);
|
|
|
|
item->set_collapsed(true);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 20:07:30 +00:00
|
|
|
if (category && category->get_first_child() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
2024-09-01 23:18:54 +00:00
|
|
|
|
|
|
|
if (found) {
|
|
|
|
// As we call this while adding items, defer until list is completely populated.
|
|
|
|
callable_mp(search_options, &Tree::scroll_to_item).call_deferred(search_options->get_selected(), true);
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
|
|
|
|
if (type != Variant::NIL) {
|
|
|
|
Variant v;
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
2020-11-09 03:19:09 +00:00
|
|
|
Variant::construct(type, v, nullptr, 0, ce);
|
2016-08-23 22:29:07 +00:00
|
|
|
v.get_method_list(&methods);
|
|
|
|
} else {
|
2022-02-08 15:06:57 +00:00
|
|
|
Ref<Script> script_ref = Object::cast_to<Script>(ObjectDB::get_instance(script));
|
|
|
|
if (script_ref.is_valid()) {
|
|
|
|
if (script_ref->is_built_in()) {
|
|
|
|
script_ref->reload(true);
|
|
|
|
}
|
2024-06-05 15:24:59 +00:00
|
|
|
|
|
|
|
List<MethodInfo> script_methods;
|
|
|
|
script_ref->get_script_method_list(&script_methods);
|
|
|
|
|
|
|
|
methods.push_back(MethodInfo("*Script Methods")); // TODO: Split by inheritance.
|
|
|
|
|
|
|
|
for (const MethodInfo &mi : script_methods) {
|
|
|
|
if (mi.name.begins_with("@")) {
|
|
|
|
// GH-92782. GDScript inline setters/getters are historically present in `get_method_list()`
|
|
|
|
// and can be called using `Object.call()`. However, these functions are meant to be internal
|
|
|
|
// and their names are not valid identifiers, so let's hide them from the user.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
methods.push_back(mi);
|
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringName base = base_type;
|
|
|
|
while (base) {
|
|
|
|
methods.push_back(MethodInfo("*" + String(base)));
|
2017-09-12 10:58:18 +00:00
|
|
|
ClassDB::get_method_list(base, &methods, true, true);
|
2017-01-03 02:03:46 +00:00
|
|
|
base = ClassDB::get_parent_class(base);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
TreeItem *category = nullptr;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
bool script_methods = false;
|
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
for (MethodInfo &mi : methods) {
|
|
|
|
if (mi.name.begins_with("*")) {
|
2021-03-07 20:07:30 +00:00
|
|
|
if (category && category->get_first_child() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
category = search_options->create_item(root);
|
2021-07-16 03:45:57 +00:00
|
|
|
category->set_text(0, mi.name.replace_first("*", ""));
|
2016-08-23 22:29:07 +00:00
|
|
|
category->set_selectable(0, false);
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> icon;
|
2016-08-23 22:29:07 +00:00
|
|
|
script_methods = false;
|
2021-07-16 03:45:57 +00:00
|
|
|
String rep = mi.name.replace("*", "");
|
|
|
|
if (mi.name == "*Script Methods") {
|
2023-08-13 00:33:39 +00:00
|
|
|
icon = search_options->get_editor_theme_icon(SNAME("Script"));
|
2016-08-23 22:29:07 +00:00
|
|
|
script_methods = true;
|
|
|
|
} else {
|
2018-09-02 21:40:51 +00:00
|
|
|
icon = EditorNode::get_singleton()->get_class_icon(rep);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
category->set_icon(0, icon);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
String name = mi.name.get_slice(":", 0);
|
|
|
|
if (!script_methods && name.begins_with("_") && !(mi.flags & METHOD_FLAG_VIRTUAL)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
if (virtuals_only && !(mi.flags & METHOD_FLAG_VIRTUAL)) {
|
2017-09-12 10:58:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
if (!virtuals_only && (mi.flags & METHOD_FLAG_VIRTUAL)) {
|
2017-09-12 10:58:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2024-05-06 08:26:10 +00:00
|
|
|
if (!search_box->get_text().is_empty() && !name.containsn(search_text)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
TreeItem *item = search_options->create_item(category ? category : root);
|
|
|
|
|
|
|
|
String desc;
|
2022-02-03 16:03:38 +00:00
|
|
|
if (mi.name.contains(":")) {
|
2016-08-23 22:29:07 +00:00
|
|
|
desc = mi.name.get_slice(":", 1) + " ";
|
|
|
|
mi.name = mi.name.get_slice(":", 0);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (mi.return_val.type != Variant::NIL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
desc = Variant::get_type_name(mi.return_val.type);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2020-08-19 16:28:05 +00:00
|
|
|
desc = "void";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2020-08-19 16:28:05 +00:00
|
|
|
desc += vformat(" %s(", mi.name);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-04-15 13:18:34 +00:00
|
|
|
for (List<PropertyInfo>::Iterator arg_itr = mi.arguments.begin(); arg_itr != mi.arguments.end(); ++arg_itr) {
|
|
|
|
if (arg_itr != mi.arguments.begin()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
desc += ", ";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2024-04-15 13:18:34 +00:00
|
|
|
desc += arg_itr->name;
|
2020-08-19 16:28:05 +00:00
|
|
|
|
2024-04-15 13:18:34 +00:00
|
|
|
if (arg_itr->type == Variant::NIL) {
|
2020-08-19 16:28:05 +00:00
|
|
|
desc += ": Variant";
|
2024-04-15 13:18:34 +00:00
|
|
|
} else if (arg_itr->name.contains(":")) {
|
|
|
|
desc += vformat(": %s", arg_itr->name.get_slice(":", 1));
|
|
|
|
arg_itr->name = arg_itr->name.get_slice(":", 0);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2024-04-15 13:18:34 +00:00
|
|
|
desc += vformat(": %s", Variant::get_type_name(arg_itr->type));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 16:28:05 +00:00
|
|
|
desc += ")";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
if (mi.flags & METHOD_FLAG_CONST) {
|
2017-09-12 10:58:18 +00:00
|
|
|
desc += " const";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2021-07-16 03:45:57 +00:00
|
|
|
if (mi.flags & METHOD_FLAG_VIRTUAL) {
|
2017-09-12 10:58:18 +00:00
|
|
|
desc += " virtual";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
item->set_text(0, desc);
|
|
|
|
item->set_metadata(0, name);
|
|
|
|
item->set_selectable(0, true);
|
|
|
|
|
2024-05-06 08:26:10 +00:00
|
|
|
if (!found && !search_box->get_text().is_empty() && name.containsn(search_text)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
item->select(0);
|
|
|
|
found = true;
|
2024-09-01 23:18:54 +00:00
|
|
|
} else if (!found && search_box->get_text().is_empty() && name == selected) {
|
|
|
|
item->select(0);
|
|
|
|
found = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-07 20:07:30 +00:00
|
|
|
if (category && category->get_first_child() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
2024-09-01 23:18:54 +00:00
|
|
|
|
|
|
|
if (found) {
|
|
|
|
// As we call this while adding items, defer until list is completely populated.
|
|
|
|
callable_mp(search_options, &Tree::scroll_to_item).call_deferred(search_options->get_selected(), true);
|
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 17:23:34 +00:00
|
|
|
get_ok_button()->set_disabled(search_options->get_selected() == nullptr);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_confirmed() {
|
|
|
|
TreeItem *ti = search_options->get_selected();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!ti) {
|
2016-08-23 22:29:07 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("selected"), ti->get_metadata(0));
|
2016-08-23 22:29:07 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_item_selected() {
|
2024-04-11 08:21:44 +00:00
|
|
|
help_bit->set_custom_text(String(), String(), String());
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
TreeItem *item = search_options->get_selected();
|
2024-08-31 17:23:34 +00:00
|
|
|
get_ok_button()->set_disabled(item == nullptr);
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!item) {
|
2016-08-23 22:29:07 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
String name = item->get_metadata(0);
|
|
|
|
|
|
|
|
String class_type;
|
2019-07-20 06:09:57 +00:00
|
|
|
if (type != Variant::NIL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
class_type = Variant::get_type_name(type);
|
2021-12-09 09:42:46 +00:00
|
|
|
} else if (!base_type.is_empty()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
class_type = base_type;
|
2021-08-08 21:49:43 +00:00
|
|
|
} else if (instance) {
|
|
|
|
class_type = instance->get_class();
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String text;
|
2023-09-21 02:54:51 +00:00
|
|
|
while (!class_type.is_empty()) {
|
2024-04-11 08:21:44 +00:00
|
|
|
if (properties) {
|
|
|
|
if (ClassDB::has_property(class_type, name, true)) {
|
|
|
|
help_bit->parse_symbol("property|" + class_type + "|" + name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ClassDB::has_method(class_type, name, true)) {
|
|
|
|
help_bit->parse_symbol("method|" + class_type + "|" + name);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 02:54:51 +00:00
|
|
|
// It may be from a parent class, keep looking.
|
|
|
|
class_type = ClassDB::get_parent_class(class_type);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 21:49:16 +00:00
|
|
|
void PropertySelector::_hide_requested() {
|
2020-03-06 17:00:16 +00:00
|
|
|
_cancel_pressed(); // From AcceptDialog.
|
2020-02-27 21:49:16 +00:00
|
|
|
}
|
|
|
|
|
2024-08-15 11:43:47 +00:00
|
|
|
void PropertySelector::_create_subproperties(TreeItem *p_parent_item, Variant::Type p_type) {
|
|
|
|
switch (p_type) {
|
|
|
|
case Variant::VECTOR2: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::FLOAT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::VECTOR2I: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::INT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::RECT2: {
|
|
|
|
_create_subproperty(p_parent_item, "position", Variant::VECTOR2);
|
|
|
|
_create_subproperty(p_parent_item, "size", Variant::VECTOR2);
|
|
|
|
_create_subproperty(p_parent_item, "end", Variant::VECTOR2);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::RECT2I: {
|
|
|
|
_create_subproperty(p_parent_item, "position", Variant::VECTOR2I);
|
|
|
|
_create_subproperty(p_parent_item, "size", Variant::VECTOR2I);
|
|
|
|
_create_subproperty(p_parent_item, "end", Variant::VECTOR2I);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::FLOAT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::VECTOR3I: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::INT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::TRANSFORM2D: {
|
|
|
|
_create_subproperty(p_parent_item, "origin", Variant::VECTOR2);
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::VECTOR2);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::VECTOR2);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::VECTOR4: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "w", Variant::FLOAT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::VECTOR4I: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "w", Variant::INT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::PLANE: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "normal", Variant::VECTOR3);
|
|
|
|
_create_subproperty(p_parent_item, "d", Variant::FLOAT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::QUATERNION: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "w", Variant::FLOAT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::AABB: {
|
|
|
|
_create_subproperty(p_parent_item, "position", Variant::VECTOR3);
|
|
|
|
_create_subproperty(p_parent_item, "size", Variant::VECTOR3);
|
|
|
|
_create_subproperty(p_parent_item, "end", Variant::VECTOR3);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::BASIS: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::VECTOR3);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::VECTOR3);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::VECTOR3);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::TRANSFORM3D: {
|
|
|
|
_create_subproperty(p_parent_item, "basis", Variant::BASIS);
|
|
|
|
_create_subproperty(p_parent_item, "origin", Variant::VECTOR3);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::PROJECTION: {
|
|
|
|
_create_subproperty(p_parent_item, "x", Variant::VECTOR4);
|
|
|
|
_create_subproperty(p_parent_item, "y", Variant::VECTOR4);
|
|
|
|
_create_subproperty(p_parent_item, "z", Variant::VECTOR4);
|
|
|
|
_create_subproperty(p_parent_item, "w", Variant::VECTOR4);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::COLOR: {
|
|
|
|
_create_subproperty(p_parent_item, "r", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "g", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "b", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "a", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "r8", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "g8", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "b8", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "a8", Variant::INT);
|
|
|
|
_create_subproperty(p_parent_item, "h", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "s", Variant::FLOAT);
|
|
|
|
_create_subproperty(p_parent_item, "v", Variant::FLOAT);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_create_subproperty(TreeItem *p_parent_item, const String &p_name, Variant::Type p_type) {
|
|
|
|
if (!type_filter.is_empty() && !type_filter.has(p_type)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *item = search_options->create_item(p_parent_item);
|
|
|
|
item->set_text(0, p_name);
|
|
|
|
item->set_metadata(0, String(p_parent_item->get_metadata(0)) + ":" + p_name);
|
|
|
|
item->set_icon(0, search_options->get_editor_theme_icon(Variant::get_type_name(p_type)));
|
|
|
|
|
|
|
|
_create_subproperties(item, p_type);
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
void PropertySelector::_notification(int p_what) {
|
2022-02-16 14:17:55 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2024-05-14 12:28:18 +00:00
|
|
|
connect(SceneStringName(confirmed), callable_mp(this, &PropertySelector::_confirmed));
|
2022-02-16 14:17:55 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2024-05-14 12:28:18 +00:00
|
|
|
disconnect(SceneStringName(confirmed), callable_mp(this, &PropertySelector::_confirmed));
|
2022-02-16 14:17:55 +00:00
|
|
|
} break;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 10:58:18 +00:00
|
|
|
void PropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only) {
|
2016-08-23 22:29:07 +00:00
|
|
|
base_type = p_base;
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = p_virtuals_only;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::select_method_from_script(const Ref<Script> &p_script, const String &p_current) {
|
|
|
|
ERR_FAIL_COND(p_script.is_null());
|
|
|
|
base_type = p_script->get_instance_base_type();
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2017-08-07 10:17:31 +00:00
|
|
|
script = p_script->get_instance_id();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
void PropertySelector::select_method_from_basic_type(Variant::Type p_type, const String &p_current) {
|
|
|
|
ERR_FAIL_COND(p_type == Variant::NIL);
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = p_type;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::select_method_from_instance(Object *p_instance, const String &p_current) {
|
2017-01-03 02:03:46 +00:00
|
|
|
base_type = p_instance->get_class();
|
2016-08-23 22:29:07 +00:00
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
{
|
|
|
|
Ref<Script> scr = p_instance->get_script();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (scr.is_valid()) {
|
2017-08-07 10:17:31 +00:00
|
|
|
script = scr->get_instance_id();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::select_property_from_base_type(const String &p_base, const String &p_current) {
|
|
|
|
base_type = p_base;
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::select_property_from_script(const Ref<Script> &p_script, const String &p_current) {
|
|
|
|
ERR_FAIL_COND(p_script.is_null());
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
base_type = p_script->get_instance_base_type();
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2017-08-07 10:17:31 +00:00
|
|
|
script = p_script->get_instance_id();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
2017-12-09 21:07:45 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void PropertySelector::select_property_from_basic_type(Variant::Type p_type, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
ERR_FAIL_COND(p_type == Variant::NIL);
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = p_type;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::select_property_from_instance(Object *p_instance, const String &p_current) {
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
properties = true;
|
|
|
|
instance = p_instance;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
void PropertySelector::set_type_filter(const Vector<Variant::Type> &p_type_filter) {
|
|
|
|
type_filter = p_type_filter;
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
void PropertySelector::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name")));
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertySelector::PropertySelector() {
|
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
|
|
|
add_child(vbc);
|
2017-01-10 04:49:55 +00:00
|
|
|
//set_child_rect(vbc);
|
2016-08-23 22:29:07 +00:00
|
|
|
search_box = memnew(LineEdit);
|
|
|
|
vbc->add_margin_child(TTR("Search:"), search_box);
|
2024-05-14 09:42:00 +00:00
|
|
|
search_box->connect(SceneStringName(text_changed), callable_mp(this, &PropertySelector::_text_changed));
|
2024-05-13 14:56:03 +00:00
|
|
|
search_box->connect(SceneStringName(gui_input), callable_mp(this, &PropertySelector::_sbox_input));
|
2016-08-23 22:29:07 +00:00
|
|
|
search_options = memnew(Tree);
|
2024-03-17 08:28:18 +00:00
|
|
|
search_options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
|
2016-08-23 22:29:07 +00:00
|
|
|
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
2022-07-08 00:31:19 +00:00
|
|
|
set_ok_button_text(TTR("Open"));
|
2020-12-14 18:37:30 +00:00
|
|
|
get_ok_button()->set_disabled(true);
|
2016-08-23 22:29:07 +00:00
|
|
|
register_text_enter(search_box);
|
|
|
|
set_hide_on_ok(false);
|
2020-02-21 17:28:45 +00:00
|
|
|
search_options->connect("item_activated", callable_mp(this, &PropertySelector::_confirmed));
|
|
|
|
search_options->connect("cell_selected", callable_mp(this, &PropertySelector::_item_selected));
|
2016-08-23 22:29:07 +00:00
|
|
|
search_options->set_hide_root(true);
|
|
|
|
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit = memnew(EditorHelpBit);
|
2024-04-11 08:21:44 +00:00
|
|
|
help_bit->set_content_height_limits(80 * EDSCALE, 80 * EDSCALE);
|
2020-02-27 21:49:16 +00:00
|
|
|
help_bit->connect("request_hide", callable_mp(this, &PropertySelector::_hide_requested));
|
2024-04-11 08:21:44 +00:00
|
|
|
vbc->add_margin_child(TTR("Description:"), help_bit);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|