2017-01-16 07:04:19 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* property_selector.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-01-16 07:04:19 +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. */
|
|
|
|
/*************************************************************************/
|
2016-08-23 22:29:07 +00:00
|
|
|
#include "property_selector.h"
|
|
|
|
|
2017-01-16 07:04:19 +00:00
|
|
|
#include "editor_scale.h"
|
2016-08-23 22:29:07 +00:00
|
|
|
#include "os/keyboard.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::_text_changed(const String &p_newtext) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::_sbox_input(const InputEvent &p_ie) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_ie.type == InputEvent::KEY) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_ie.key.scancode) {
|
2016-08-23 22:29:07 +00:00
|
|
|
case KEY_UP:
|
|
|
|
case KEY_DOWN:
|
|
|
|
case KEY_PAGEUP:
|
|
|
|
case KEY_PAGEDOWN: {
|
|
|
|
|
2017-01-08 19:28:12 +00:00
|
|
|
search_options->call("_gui_input", p_ie);
|
2016-08-23 22:29:07 +00:00
|
|
|
search_box->accept_event();
|
|
|
|
|
|
|
|
TreeItem *root = search_options->get_root();
|
|
|
|
if (!root->get_children())
|
|
|
|
break;
|
|
|
|
|
|
|
|
TreeItem *current = search_options->get_selected();
|
|
|
|
|
|
|
|
TreeItem *item = search_options->get_next_selected(root);
|
|
|
|
while (item) {
|
|
|
|
item->deselect(0);
|
|
|
|
item = search_options->get_next_selected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
current->select(0);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_update_search() {
|
|
|
|
|
|
|
|
if (properties)
|
|
|
|
set_title(TTR("Select Property"));
|
|
|
|
else
|
|
|
|
set_title(TTR("Select Method"));
|
|
|
|
|
|
|
|
search_options->clear();
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit->set_text("");
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
TreeItem *root = search_options->create_item();
|
|
|
|
|
|
|
|
if (properties) {
|
|
|
|
|
|
|
|
List<PropertyInfo> props;
|
|
|
|
|
|
|
|
if (instance) {
|
2017-03-05 15:44:50 +00:00
|
|
|
instance->get_property_list(&props, true);
|
|
|
|
} else if (type != Variant::NIL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
Variant v;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (type == Variant::INPUT_EVENT) {
|
2016-08-23 22:29:07 +00:00
|
|
|
InputEvent ie;
|
2017-03-05 15:44:50 +00:00
|
|
|
ie.type = event_type;
|
|
|
|
v = ie;
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
|
|
|
Variant::CallError ce;
|
2017-03-05 15:44:50 +00:00
|
|
|
v = Variant::construct(type, NULL, 0, ce);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v.get_property_list(&props);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(script);
|
|
|
|
if (obj && obj->cast_to<Script>()) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
props.push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
|
2016-08-23 22:29:07 +00:00
|
|
|
obj->cast_to<Script>()->get_script_property_list(&props);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName base = base_type;
|
|
|
|
while (base) {
|
|
|
|
props.push_back(PropertyInfo(Variant::NIL, base, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
|
|
|
|
ClassDB::get_property_list(base, &props, true);
|
|
|
|
base = ClassDB::get_parent_class(base);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *category = NULL;
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
|
|
|
|
Control::get_icon("MiniVariant", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniBoolean", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniInteger", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniFloat", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniString", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniVector2", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniRect2", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniVector3", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniMatrix2", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniPlane", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniQuat", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniAabb", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniMatrix3", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniTransform", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniColor", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniImage", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniPath", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniRid", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniObject", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniInput", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniDictionary", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniArray", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniRawArray", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniIntArray", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniFloatArray", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniStringArray", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniVector2Array", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniVector3Array", "EditorIcons"),
|
|
|
|
Control::get_icon("MiniColorArray", "EditorIcons")
|
2016-08-23 22:29:07 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
|
|
|
if (E->get().usage == PROPERTY_USAGE_CATEGORY) {
|
|
|
|
if (category && category->get_children() == NULL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
category = search_options->create_item(root);
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_text(0, E->get().name);
|
|
|
|
category->set_selectable(0, false);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
Ref<Texture> icon;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get().name == "Script Variables") {
|
|
|
|
icon = get_icon("Script", "EditorIcons");
|
|
|
|
} else if (has_icon(E->get().name, "EditorIcons")) {
|
|
|
|
icon = get_icon(E->get().name, "EditorIcons");
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
icon = get_icon("Object", "EditorIcons");
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_icon(0, icon);
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_EDITOR))
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1)
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = search_options->create_item(category ? category : root);
|
|
|
|
item->set_text(0, E->get().name);
|
|
|
|
item->set_metadata(0, E->get().name);
|
|
|
|
item->set_icon(0, type_icons[E->get().type]);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!found && search_box->get_text() != String() && E->get().name.find(search_box->get_text()) != -1) {
|
2016-08-23 22:29:07 +00:00
|
|
|
item->select(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
found = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
item->set_selectable(0, true);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (category && category->get_children() == NULL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (type != Variant::NIL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
Variant v;
|
|
|
|
Variant::CallError ce;
|
2017-03-05 15:44:50 +00:00
|
|
|
v = Variant::construct(type, NULL, 0, ce);
|
2016-08-23 22:29:07 +00:00
|
|
|
v.get_method_list(&methods);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(script);
|
|
|
|
if (obj && obj->cast_to<Script>()) {
|
|
|
|
|
|
|
|
methods.push_back(MethodInfo("*Script Methods"));
|
|
|
|
obj->cast_to<Script>()->get_script_method_list(&methods);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName base = base_type;
|
|
|
|
while (base) {
|
|
|
|
methods.push_back(MethodInfo("*" + String(base)));
|
|
|
|
ClassDB::get_method_list(base, &methods, true);
|
|
|
|
base = ClassDB::get_parent_class(base);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *category = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool found = false;
|
|
|
|
bool script_methods = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E->get().name.begins_with("*")) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (category && category->get_children() == NULL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
category = search_options->create_item(root);
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_text(0, E->get().name.replace_first("*", ""));
|
|
|
|
category->set_selectable(0, false);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
Ref<Texture> icon;
|
2017-03-05 15:44:50 +00:00
|
|
|
script_methods = false;
|
|
|
|
if (E->get().name == "*Script Methods") {
|
|
|
|
icon = get_icon("Script", "EditorIcons");
|
|
|
|
script_methods = true;
|
|
|
|
} else if (has_icon(E->get().name, "EditorIcons")) {
|
|
|
|
icon = get_icon(E->get().name, "EditorIcons");
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
icon = get_icon("Object", "EditorIcons");
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_icon(0, icon);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String name = E->get().name.get_slice(":", 0);
|
|
|
|
if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL))
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1)
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = search_options->create_item(category ? category : root);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
MethodInfo mi = E->get();
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
String desc;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mi.name.find(":") != -1) {
|
|
|
|
desc = mi.name.get_slice(":", 1) + " ";
|
|
|
|
mi.name = mi.name.get_slice(":", 0);
|
|
|
|
} else if (mi.return_val.type != Variant::NIL)
|
|
|
|
desc = Variant::get_type_name(mi.return_val.type);
|
2016-08-23 22:29:07 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
desc = "void ";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += " " + mi.name + " ( ";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < mi.arguments.size(); i++) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i > 0)
|
|
|
|
desc += ", ";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mi.arguments[i].type == Variant::NIL)
|
|
|
|
desc += "var ";
|
|
|
|
else if (mi.arguments[i].name.find(":") != -1) {
|
|
|
|
desc += mi.arguments[i].name.get_slice(":", 1) + " ";
|
|
|
|
mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0);
|
2016-08-23 22:29:07 +00:00
|
|
|
} else
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += Variant::get_type_name(mi.arguments[i].type) + " ";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += mi.arguments[i].name;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += " )";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
item->set_text(0, desc);
|
|
|
|
item->set_metadata(0, name);
|
|
|
|
item->set_selectable(0, true);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!found && search_box->get_text() != String() && name.find(search_box->get_text()) != -1) {
|
2016-08-23 22:29:07 +00:00
|
|
|
item->select(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
found = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (category && category->get_children() == NULL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
get_ok()->set_disabled(root->get_children() == NULL);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_confirmed() {
|
|
|
|
|
|
|
|
TreeItem *ti = search_options->get_selected();
|
|
|
|
if (!ti)
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("selected", ti->get_metadata(0));
|
2016-08-23 22:29:07 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_item_selected() {
|
|
|
|
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit->set_text("");
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = search_options->get_selected();
|
2016-08-23 22:29:07 +00:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
String name = item->get_metadata(0);
|
|
|
|
|
|
|
|
String class_type;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (properties && type == Variant::INPUT_EVENT) {
|
|
|
|
|
|
|
|
switch (event_type) {
|
|
|
|
case InputEvent::NONE: class_type = "InputEvent"; break;
|
|
|
|
case InputEvent::KEY: class_type = "InputEventKey"; break;
|
|
|
|
case InputEvent::MOUSE_MOTION: class_type = "InputEventMouseMotion"; break;
|
|
|
|
case InputEvent::MOUSE_BUTTON: class_type = "InputEventMouseButton"; break;
|
|
|
|
case InputEvent::JOYPAD_MOTION: class_type = "InputEventJoypadMotion"; break;
|
|
|
|
case InputEvent::JOYPAD_BUTTON: class_type = "InputEventJoypadButton"; break;
|
|
|
|
case InputEvent::SCREEN_TOUCH: class_type = "InputEventScreenTouch"; break;
|
|
|
|
case InputEvent::SCREEN_DRAG: class_type = "InputEventScreenDrag"; break;
|
|
|
|
case InputEvent::ACTION: class_type = "InputEventAction"; break;
|
2016-08-23 22:29:07 +00:00
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (type) {
|
2017-03-05 15:44:50 +00:00
|
|
|
class_type = Variant::get_type_name(type);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
class_type = base_type;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
DocData *dd = EditorHelp::get_doc_data();
|
2016-08-23 22:29:07 +00:00
|
|
|
String text;
|
|
|
|
|
|
|
|
if (properties) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String at_class = class_type;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (at_class != String()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < E->get().properties.size(); i++) {
|
|
|
|
if (E->get().properties[i].name == name) {
|
|
|
|
text = E->get().properties[i].description;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
at_class = ClassDB::get_parent_class(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (text == String()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
StringName setter;
|
|
|
|
StringName type;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ClassDB::get_setter_and_type_for_property(class_type, name, type, setter)) {
|
|
|
|
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(type);
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < E->get().methods.size(); i++) {
|
|
|
|
if (E->get().methods[i].name == setter.operator String()) {
|
|
|
|
text = E->get().methods[i].description;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String at_class = class_type;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (at_class != String()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < E->get().methods.size(); i++) {
|
|
|
|
if (E->get().methods[i].name == name) {
|
|
|
|
text = E->get().methods[i].description;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
at_class = ClassDB::get_parent_class(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (text == String())
|
2016-08-23 22:29:07 +00:00
|
|
|
return;
|
|
|
|
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit->set_text(text);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2016-08-24 02:15:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
connect("confirmed", this, "_confirmed");
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_method_from_base_type(const String &p_base, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = p_base;
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
|
|
|
script = 0;
|
|
|
|
properties = false;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_method_from_script(const Ref<Script> &p_script, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_script.is_null());
|
|
|
|
base_type = p_script->get_instance_base_type();
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
|
|
|
script = p_script->get_instance_ID();
|
|
|
|
properties = false;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_method_from_basic_type(Variant::Type p_type, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_type == Variant::NIL);
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = p_type;
|
|
|
|
script = 0;
|
|
|
|
properties = false;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_method_from_instance(Object *p_instance, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = p_instance->get_class();
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
|
|
|
script = 0;
|
2016-08-23 22:29:07 +00:00
|
|
|
{
|
|
|
|
Ref<Script> scr = p_instance->get_script();
|
|
|
|
if (scr.is_valid())
|
2017-03-05 15:44:50 +00:00
|
|
|
script = scr->get_instance_ID();
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = false;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_property_from_base_type(const String &p_base, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = p_base;
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
|
|
|
script = 0;
|
|
|
|
properties = true;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_property_from_script(const Ref<Script> &p_script, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_script.is_null());
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = p_script->get_instance_base_type();
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
|
|
|
script = p_script->get_instance_ID();
|
|
|
|
properties = true;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_property_from_basic_type(Variant::Type p_type, InputEvent::Type p_event_type, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_type == Variant::NIL);
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = p_type;
|
|
|
|
event_type = p_event_type;
|
|
|
|
script = 0;
|
|
|
|
properties = true;
|
|
|
|
instance = NULL;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_property_from_instance(Object *p_instance, const String &p_current) {
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
|
|
|
script = 0;
|
|
|
|
properties = true;
|
|
|
|
instance = p_instance;
|
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::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_text_changed"), &PropertySelector::_text_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_confirmed"), &PropertySelector::_confirmed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_sbox_input"), &PropertySelector::_sbox_input);
|
|
|
|
ClassDB::bind_method(D_METHOD("_item_selected"), &PropertySelector::_item_selected);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name")));
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertySelector::PropertySelector() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2016-08-23 22:29:07 +00:00
|
|
|
add_child(vbc);
|
2017-01-10 04:49:55 +00:00
|
|
|
//set_child_rect(vbc);
|
2017-03-05 15:44:50 +00:00
|
|
|
search_box = memnew(LineEdit);
|
|
|
|
vbc->add_margin_child(TTR("Search:"), search_box);
|
|
|
|
search_box->connect("text_changed", this, "_text_changed");
|
|
|
|
search_box->connect("gui_input", this, "_sbox_input");
|
|
|
|
search_options = memnew(Tree);
|
|
|
|
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
2016-08-23 22:29:07 +00:00
|
|
|
get_ok()->set_text(TTR("Open"));
|
|
|
|
get_ok()->set_disabled(true);
|
|
|
|
register_text_enter(search_box);
|
|
|
|
set_hide_on_ok(false);
|
2017-03-05 15:44:50 +00:00
|
|
|
search_options->connect("item_activated", this, "_confirmed");
|
|
|
|
search_options->connect("cell_selected", this, "_item_selected");
|
2016-08-23 22:29:07 +00:00
|
|
|
search_options->set_hide_root(true);
|
|
|
|
search_options->set_hide_folding(true);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
help_bit = memnew(EditorHelpBit);
|
|
|
|
vbc->add_margin_child(TTR("Description:"), help_bit);
|
|
|
|
help_bit->connect("request_hide", this, "_closed");
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|