summaryrefslogtreecommitdiff
path: root/editor/editor_inspector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r--editor/editor_inspector.cpp603
1 files changed, 524 insertions, 79 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 21ad71fe06..99a2b2aa67 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* editor_inspector.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#include "editor_inspector.h"
#include "array_property_edit.h"
#include "dictionary_property_edit.h"
@@ -7,11 +37,15 @@
#include "scene/resources/packed_scene.h"
// TODO:
-// arrays
+// arrays and dictionary
+// replace property editor in sectionedpropertyeditor
Size2 EditorProperty::get_minimum_size() const {
Size2 ms;
+ Ref<Font> font = get_font("font", "Tree");
+ ms.height = font->get_height();
+
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
@@ -21,6 +55,9 @@ Size2 EditorProperty::get_minimum_size() const {
continue;
if (!c->is_visible())
continue;
+ if (c == bottom_editor)
+ continue;
+
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
@@ -36,10 +73,12 @@ Size2 EditorProperty::get_minimum_size() const {
ms.width += check->get_width() + get_constant("hseparator", "Tree");
}
- if (label_layout == LABEL_LAYOUT_TOP) {
- Ref<Font> font = get_font("font", "Tree");
- ms.height += font->get_height();
+ if (bottom_editor != NULL && bottom_editor->is_visible()) {
ms.height += get_constant("vseparation", "Tree");
+ Size2 bems = bottom_editor->get_combined_minimum_size();
+ //bems.width += get_constant("item_margin", "Tree");
+ ms.height += bems.height;
+ ms.width = MAX(ms.width, bems.width);
}
return ms;
@@ -51,9 +90,16 @@ void EditorProperty::_notification(int p_what) {
Size2 size = get_size();
Rect2 rect;
+ Rect2 bottom_rect;
- if (label_layout == LABEL_LAYOUT_LEFT) {
- int child_room = size.width / 2;
+ right_child_rect = Rect2();
+ bottom_child_rect = Rect2();
+
+ {
+ int child_room = size.width * (1.0 - split_ratio);
+ Ref<Font> font = get_font("font", "Tree");
+ int height = font->get_height();
+ bool no_children = true;
//compute room needed
for (int i = 0; i < get_child_count(); i++) {
@@ -63,22 +109,29 @@ void EditorProperty::_notification(int p_what) {
continue;
if (c->is_set_as_toplevel())
continue;
+ if (c == bottom_editor)
+ continue;
Size2 minsize = c->get_combined_minimum_size();
child_room = MAX(child_room, minsize.width);
+ height = MAX(height, minsize.height);
+ no_children = false;
+ }
+
+ if (no_children) {
+ text_size = size.width;
+ rect = Rect2(size.width - 1, 0, 1, height);
+ } else {
+ text_size = MAX(0, size.width - (child_room + 4 * EDSCALE));
+ rect = Rect2(size.width - child_room, 0, child_room, height);
}
- text_size = MAX(0, size.width - child_room + 4 * EDSCALE);
+ if (bottom_editor) {
- rect = Rect2(text_size, 0, size.width - text_size, size.height);
- } else {
- Ref<Font> font = get_font("font", "Tree");
+ int m = 0; //get_constant("item_margin", "Tree");
- text_size = size.width;
- rect.position.x = 0;
- rect.position.y = font->get_height() + get_constant("vseparation", "Tree");
- rect.size = get_size();
- rect.size.height -= rect.position.y;
+ bottom_rect = Rect2(m, rect.size.height + get_constant("vseparation", "Tree"), size.width - m, bottom_editor->get_combined_minimum_size().height);
+ }
}
if (keying) {
@@ -101,8 +154,16 @@ void EditorProperty::_notification(int p_what) {
continue;
if (c->is_set_as_toplevel())
continue;
+ if (c == bottom_editor)
+ continue;
fit_child_in_rect(c, rect);
+ right_child_rect = rect;
+ }
+
+ if (bottom_editor) {
+ fit_child_in_rect(bottom_editor, bottom_rect);
+ bottom_child_rect = bottom_rect;
}
update(); //need to redraw text
@@ -110,10 +171,11 @@ void EditorProperty::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
Ref<Font> font = get_font("font", "Tree");
+ Color dark_color = get_color("dark_color_2", "Editor");
Size2 size = get_size();
- if (label_layout == LABEL_LAYOUT_TOP) {
- size.height = font->get_height();
+ if (bottom_editor) {
+ size.height = bottom_editor->get_margin(MARGIN_TOP);
} else if (label_reference) {
size.height = label_reference->get_size().height;
}
@@ -123,11 +185,18 @@ void EditorProperty::_notification(int p_what) {
draw_style_box(sb, Rect2(Vector2(), size));
}
+ if (draw_top_bg && right_child_rect != Rect2()) {
+ draw_rect(right_child_rect, dark_color);
+ }
+ if (bottom_child_rect != Rect2()) {
+ draw_rect(bottom_child_rect, dark_color);
+ }
+
Color color;
if (draw_red) {
color = get_color("error_color", "Editor");
} else {
- color = get_color("font_color", "Tree");
+ color = get_color("property_color", "Editor");
}
if (label.find(".") != -1) {
color.a = 0.5; //this should be un-hacked honestly, as it's used for editor overrides
@@ -203,7 +272,7 @@ void EditorProperty::_notification(int p_what) {
//int vs = get_constant("vseparation", "Tree");
Color guide_color = get_color("guide_color", "Tree");
int vs_height = get_size().height; // vs / 2;
- draw_line(Point2(0, vs_height), Point2(get_size().width, vs_height), guide_color);
+ // draw_line(Point2(0, vs_height), Point2(get_size().width, vs_height), guide_color);
}
}
@@ -472,6 +541,8 @@ bool EditorProperty::is_draw_red() const {
void EditorProperty::_focusable_focused(int p_index) {
+ if (!selectable)
+ return;
bool already_selected = selected;
selected = true;
selected_focusable = p_index;
@@ -548,7 +619,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- if (!selected) {
+ if (!selected && selectable) {
selected = true;
emit_signal("selected", property, -1);
update();
@@ -596,7 +667,10 @@ void EditorProperty::set_label_reference(Control *p_control) {
label_reference = p_control;
}
+void EditorProperty::set_bottom_editor(Control *p_control) {
+ bottom_editor = p_control;
+}
Variant EditorProperty::get_drag_data(const Point2 &p_point) {
if (property == StringName())
@@ -614,10 +688,60 @@ Variant EditorProperty::get_drag_data(const Point2 &p_point) {
return dp;
}
-void EditorProperty::set_label_layout(LabelLayout p_layout) {
- label_layout = p_layout;
- queue_sort();
- update();
+void EditorProperty::set_use_folding(bool p_use_folding) {
+
+ use_folding = p_use_folding;
+}
+
+bool EditorProperty::is_using_folding() const {
+
+ return use_folding;
+}
+
+void EditorProperty::expand_all_folding() {
+}
+
+void EditorProperty::collapse_all_folding() {
+}
+
+void EditorProperty::set_selectable(bool p_selectable) {
+ selectable = p_selectable;
+}
+
+bool EditorProperty::is_selectable() const {
+ return selectable;
+}
+
+void EditorProperty::set_name_split_ratio(float p_ratio) {
+ split_ratio = p_ratio;
+}
+
+float EditorProperty::get_name_split_ratio() const {
+
+ return split_ratio;
+}
+
+void EditorProperty::set_object_and_property(Object *p_object, const StringName &p_property) {
+ object = p_object;
+ property = p_property;
+}
+
+Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
+
+ tooltip_text = p_text;
+ EditorHelpBit *help_bit = memnew(EditorHelpBit);
+ help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
+ help_bit->get_rich_text()->set_fixed_size_to_width(300);
+
+ String text = TTR("Property: ") + "[u][b]" + p_text.get_slice("::", 0) + "[/b][/u]\n";
+ text += p_text.get_slice("::", 1).strip_edges();
+ help_bit->set_text(text);
+ help_bit->call_deferred("set_text", text); //hack so it uses proper theme once inside scene
+ return help_bit;
+}
+
+String EditorProperty::get_tooltip_text() const {
+ return tooltip_text;
}
void EditorProperty::_bind_methods() {
@@ -646,6 +770,8 @@ void EditorProperty::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &EditorProperty::_gui_input);
ClassDB::bind_method(D_METHOD("_focusable_focused"), &EditorProperty::_focusable_focused);
+ ClassDB::bind_method(D_METHOD("get_tooltip_text"), &EditorProperty::get_tooltip_text);
+
ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checkable"), "set_checkable", "is_checkable");
@@ -655,6 +781,7 @@ void EditorProperty::_bind_methods() {
ADD_SIGNAL(MethodInfo("property_changed", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
ADD_SIGNAL(MethodInfo("multiple_properties_changed", PropertyInfo(Variant::POOL_STRING_ARRAY, "properties"), PropertyInfo(Variant::ARRAY, "value")));
ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property")));
+ ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::STRING, "bool")));
ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::INT, "id")));
@@ -667,6 +794,10 @@ void EditorProperty::_bind_methods() {
EditorProperty::EditorProperty() {
+ draw_top_bg = true;
+ object = NULL;
+ split_ratio = 0.5;
+ selectable = true;
text_size = 0;
read_only = false;
checkable = false;
@@ -677,11 +808,12 @@ EditorProperty::EditorProperty() {
revert_hover = false;
check_hover = false;
can_revert = false;
+ use_folding = false;
property_usage = 0;
selected = false;
selected_focusable = -1;
label_reference = NULL;
- label_layout = LABEL_LAYOUT_LEFT;
+ bottom_editor = NULL;
}
////////////////////////////////////////////////
////////////////////////////////////////////////
@@ -725,6 +857,14 @@ void EditorInspectorPlugin::parse_begin(Object *p_object) {
get_script_instance()->call("parse_begin", p_object);
}
}
+
+void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) {
+
+ if (get_script_instance()) {
+ get_script_instance()->call("parse_category", p_object, p_parse_category);
+ }
+}
+
bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
if (get_script_instance()) {
@@ -755,10 +895,16 @@ void EditorInspectorPlugin::_bind_methods() {
MethodInfo vm;
vm.name = "can_handle";
+ vm.return_val.type = Variant::BOOL;
vm.arguments.push_back(PropertyInfo(Variant::OBJECT, "object"));
BIND_VMETHOD(vm);
vm.name = "parse_begin";
+ vm.return_val.type = Variant::NIL;
BIND_VMETHOD(vm);
+ vm.name = "parse_category";
+ vm.arguments.push_back(PropertyInfo(Variant::STRING, "category"));
+ BIND_VMETHOD(vm);
+ vm.arguments.pop_back();
vm.name = "parse_property";
vm.return_val.type = Variant::BOOL;
vm.arguments.push_back(PropertyInfo(Variant::INT, "type"));
@@ -768,8 +914,8 @@ void EditorInspectorPlugin::_bind_methods() {
vm.arguments.push_back(PropertyInfo(Variant::INT, "usage"));
BIND_VMETHOD(vm);
vm.arguments.clear();
- vm.return_val.type = Variant::NIL;
vm.name = "parse_end";
+ vm.return_val.type = Variant::NIL;
BIND_VMETHOD(vm);
}
@@ -802,6 +948,20 @@ void EditorInspectorCategory::_notification(int p_what) {
}
}
+Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const {
+
+ tooltip_text = p_text;
+ EditorHelpBit *help_bit = memnew(EditorHelpBit);
+ help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
+ help_bit->get_rich_text()->set_fixed_size_to_width(300);
+
+ String text = "[u][b]" + p_text.get_slice("::", 0) + "[/b][/u]\n";
+ text += p_text.get_slice("::", 1).strip_edges();
+ help_bit->set_text(text);
+ help_bit->call_deferred("set_text", text); //hack so it uses proper theme once inside scene
+ return help_bit;
+}
+
Size2 EditorInspectorCategory::get_minimum_size() const {
Ref<Font> font = get_font("font", "Tree");
@@ -817,12 +977,29 @@ Size2 EditorInspectorCategory::get_minimum_size() const {
return ms;
}
+void EditorInspectorCategory::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_tooltip_text"), &EditorInspectorCategory::get_tooltip_text);
+}
+
+String EditorInspectorCategory::get_tooltip_text() const {
+
+ return tooltip_text;
+}
+
EditorInspectorCategory::EditorInspectorCategory() {
}
////////////////////////////////////////////////
////////////////////////////////////////////////
+void EditorInspectorSection::_test_unfold() {
+
+ if (!vbox_added) {
+ add_child(vbox);
+ vbox_added = true;
+ }
+}
+
void EditorInspectorSection::_notification(int p_what) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
@@ -833,9 +1010,9 @@ void EditorInspectorSection::_notification(int p_what) {
#ifdef TOOLS_ENABLED
if (foldable) {
if (object->editor_is_section_unfolded(section)) {
- arrow = get_icon("arrow", "Tree");
+ arrow = get_icon("arrow_up", "Tree");
} else {
- arrow = get_icon("arrow_collapsed", "Tree");
+ arrow = get_icon("arrow", "Tree");
}
}
#endif
@@ -848,7 +1025,7 @@ void EditorInspectorSection::_notification(int p_what) {
}
offset.y += get_constant("vseparation", "Tree");
- offset.x += get_constant("item_margin", "Tree");
+ offset.x += get_constant("inspector_margin", "Editor");
Rect2 rect(offset, size - offset);
@@ -876,9 +1053,9 @@ void EditorInspectorSection::_notification(int p_what) {
#ifdef TOOLS_ENABLED
if (foldable) {
if (object->editor_is_section_unfolded(section)) {
- arrow = get_icon("arrow", "Tree");
+ arrow = get_icon("arrow_up", "Tree");
} else {
- arrow = get_icon("arrow_collapsed", "Tree");
+ arrow = get_icon("arrow", "Tree");
}
}
#endif
@@ -895,14 +1072,14 @@ void EditorInspectorSection::_notification(int p_what) {
int hs = get_constant("hseparation", "Tree");
+ Color color = get_color("font_color", "Tree");
+ draw_string(font, Point2(hs, font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width);
+
int ofs = 0;
if (arrow.is_valid()) {
- draw_texture(arrow, Point2(ofs, (h - arrow->get_height()) / 2).floor());
+ draw_texture(arrow, Point2(get_size().width - arrow->get_width(), (h - arrow->get_height()) / 2).floor());
ofs += hs + arrow->get_width();
}
-
- Color color = get_color("font_color", "Tree");
- draw_string(font, Point2(ofs, font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width);
}
}
@@ -924,8 +1101,8 @@ Size2 EditorInspectorSection::get_minimum_size() const {
}
Ref<Font> font = get_font("font", "Tree");
- ms.height += font->get_ascent() + get_constant("vseparation", "Tree");
- ms.width += get_constant("item_margin", "Tree");
+ ms.height += font->get_height() + get_constant("vseparation", "Tree");
+ ms.width += get_constant("inspector_margin", "Editor");
return ms;
}
@@ -938,16 +1115,20 @@ void EditorInspectorSection::setup(const String &p_section, const String &p_labe
bg_color = p_bg_color;
foldable = p_foldable;
+ if (!foldable && !vbox_added) {
+ add_child(vbox);
+ vbox_added = true;
+ }
+
#ifdef TOOLS_ENABLED
if (foldable) {
+ _test_unfold();
if (object->editor_is_section_unfolded(section)) {
vbox->show();
} else {
vbox->hide();
}
}
- // void editor_set_section_unfold(const String &p_section, bool p_unfolded);
-
#endif
}
@@ -960,6 +1141,9 @@ void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+
+ _test_unfold();
+
bool unfold = !object->editor_is_section_unfolded(section);
object->editor_set_section_unfold(section, unfold);
if (unfold) {
@@ -979,6 +1163,9 @@ void EditorInspectorSection::unfold() {
if (!foldable)
return;
+
+ _test_unfold();
+
#ifdef TOOLS_ENABLED
object->editor_set_section_unfold(section, true);
@@ -991,6 +1178,8 @@ void EditorInspectorSection::fold() {
if (!foldable)
return;
+ if (!vbox_added)
+ return; //kinda pointless
#ifdef TOOLS_ENABLED
object->editor_set_section_unfold(section, false);
@@ -1012,7 +1201,14 @@ EditorInspectorSection::EditorInspectorSection() {
object = NULL;
foldable = false;
vbox = memnew(VBoxContainer);
- add_child(vbox);
+ vbox_added = false;
+ //add_child(vbox);
+}
+
+EditorInspectorSection::~EditorInspectorSection() {
+ if (!vbox_added) {
+ memdelete(vbox);
+ }
}
////////////////////////////////////////////////
@@ -1021,6 +1217,30 @@ EditorInspectorSection::EditorInspectorSection() {
Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS];
int EditorInspector::inspector_plugin_count = 0;
+EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
+
+ for (int i = inspector_plugin_count - 1; i >= 0; i--) {
+
+ inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage);
+ if (inspector_plugins[i]->added_editors.size()) {
+ for (int j = 1; j < inspector_plugins[i]->added_editors.size(); j++) { //only keep first one
+ memdelete(inspector_plugins[i]->added_editors[j].property_editor);
+ }
+
+ EditorProperty *prop = Object::cast_to<EditorProperty>(inspector_plugins[i]->added_editors[0].property_editor);
+ if (prop) {
+
+ inspector_plugins[i]->added_editors.clear();
+ return prop;
+ } else {
+ memdelete(inspector_plugins[i]->added_editors[0].property_editor);
+ inspector_plugins[i]->added_editors.clear();
+ }
+ }
+ }
+ return NULL;
+}
+
void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS);
@@ -1066,6 +1286,55 @@ String EditorInspector::get_selected_path() const {
return property_selected;
}
+void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped) {
+
+ for (List<EditorInspectorPlugin::AddedEditor>::Element *F = ped->added_editors.front(); F; F = F->next()) {
+
+ EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
+ current_vbox->add_child(F->get().property_editor);
+
+ if (ep) {
+
+ ep->object = object;
+ ep->connect("property_changed", this, "_property_changed");
+ ep->connect("property_keyed", this, "_property_keyed");
+ ep->connect("property_keyed_with_value", this, "_property_keyed_with_value");
+ ep->connect("property_checked", this, "_property_checked");
+ ep->connect("selected", this, "_property_selected");
+ ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
+ ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
+ ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
+
+ if (F->get().properties.size()) {
+
+ if (F->get().properties.size() == 1) {
+ //since it's one, associate:
+ ep->property = F->get().properties[0];
+ ep->property_usage = 0;
+ }
+
+ if (F->get().label != String()) {
+ ep->set_label(F->get().label);
+ }
+
+ for (int i = 0; i < F->get().properties.size(); i++) {
+ String prop = F->get().properties[i];
+
+ if (!editor_property_map.has(prop)) {
+ editor_property_map[prop] = List<EditorProperty *>();
+ }
+ editor_property_map[prop].push_back(ep);
+ }
+ }
+
+ ep->set_read_only(read_only);
+ ep->update_property();
+ ep->update_reload_status();
+ }
+ }
+ ped->added_editors.clear();
+}
+
void EditorInspector::update_tree() {
//to update properly if all is refreshed
@@ -1100,8 +1369,10 @@ void EditorInspector::update_tree() {
String filter = search_box ? search_box->get_text() : "";
String group;
String group_base;
+ VBoxContainer *category_vbox = NULL;
- List<PropertyInfo> plist;
+ List<PropertyInfo>
+ plist;
object->get_property_list(&plist, true);
HashMap<String, VBoxContainer *> item_path;
@@ -1109,6 +1380,12 @@ void EditorInspector::update_tree() {
Color sscolor = get_color("prop_subsection", "Editor");
+ for (List<Ref<EditorInspectorPlugin> >::Element *E = valid_plugins.front(); E; E = E->next()) {
+ Ref<EditorInspectorPlugin> ped = E->get();
+ ped->parse_begin(object);
+ _parse_added_editors(main_vbox, ped);
+ }
+
for (List<PropertyInfo>::Element *I = plist.front(); I; I = I->next()) {
PropertyInfo &p = I->get();
@@ -1147,6 +1424,7 @@ void EditorInspector::update_tree() {
EditorInspectorCategory *category = memnew(EditorInspectorCategory);
main_vbox->add_child(category);
+ category_vbox = NULL; //reset
String type = p.name;
if (has_icon(type, "EditorIcons"))
@@ -1169,15 +1447,23 @@ void EditorInspector::update_tree() {
class_descr_cache[type] = descr.word_wrap(80);
}
- category->set_tooltip(TTR("Class:") + " " + p.name + (class_descr_cache[type] == "" ? "" : "\n\n" + class_descr_cache[type]));
+ category->set_tooltip(p.name + "::" + (class_descr_cache[type] == "" ? "" : class_descr_cache[type]));
+ }
+
+ for (List<Ref<EditorInspectorPlugin> >::Element *E = valid_plugins.front(); E; E = E->next()) {
+ Ref<EditorInspectorPlugin> ped = E->get();
+ ped->parse_category(object, p.name);
+ _parse_added_editors(main_vbox, ped);
}
+
continue;
} else if (!(p.usage & PROPERTY_USAGE_EDITOR))
continue;
- if (hide_script && p.name == "script")
+ if (p.name == "script" && (hide_script || bool(object->call("_hide_script_from_inspector")))) {
continue;
+ }
String basename = p.name;
if (group != "") {
@@ -1224,6 +1510,11 @@ void EditorInspector::update_tree() {
continue;
}
+ if (category_vbox == NULL) {
+ category_vbox = memnew(VBoxContainer);
+ main_vbox->add_child(category_vbox);
+ }
+
VBoxContainer *current_vbox = main_vbox;
{
@@ -1251,6 +1542,14 @@ void EditorInspector::update_tree() {
current_vbox = item_path[acc_path];
level = (MIN(level + 1, 4));
}
+
+ if (current_vbox == main_vbox) {
+ //do not add directly to the main vbox, given it has no spacing
+ if (category_vbox == NULL) {
+ category_vbox = memnew(VBoxContainer);
+ }
+ current_vbox = category_vbox;
+ }
}
bool checkable = false;
@@ -1260,12 +1559,19 @@ void EditorInspector::update_tree() {
checked = p.usage & PROPERTY_USAGE_CHECKED;
}
+ if (p.usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {
+ restart_request_props.insert(p.name);
+ }
+
String doc_hint;
if (use_doc_hints) {
StringName classname = object->get_class_name();
- StringName propname = p.name;
+ if (object_class != String()) {
+ classname = object_class;
+ }
+ StringName propname = property_prefix + p.name;
String descr;
bool found = false;
@@ -1308,27 +1614,18 @@ void EditorInspector::update_tree() {
#endif
for (List<Ref<EditorInspectorPlugin> >::Element *E = valid_plugins.front(); E; E = E->next()) {
Ref<EditorInspectorPlugin> ped = E->get();
- ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage);
- for (List<EditorInspectorPlugin::AddedEditor>::Element *F = ped->added_editors.front(); F; F = F->next()) {
+ bool exclusive = ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage);
+
+ List<EditorInspectorPlugin::AddedEditor> editors = ped->added_editors; //make a copy, since plugins may be used again in a sub-inspector
+ ped->added_editors.clear();
+
+ for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) {
EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
- current_vbox->add_child(F->get().property_editor);
if (ep) {
-
+ //set all this before the control gets the ENTER_TREE notification
ep->object = object;
- ep->connect("property_changed", this, "_property_changed");
- ep->connect("property_keyed", this, "_property_keyed");
- ep->connect("property_checked", this, "_property_checked");
- ep->connect("selected", this, "_property_selected");
- ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
- ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
- ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
- ep->set_tooltip(doc_hint);
- ep->set_draw_red(draw_red);
- ep->set_checkable(checkable);
- ep->set_checked(checked);
- ep->set_keying(keying);
if (F->get().properties.size()) {
@@ -1354,8 +1651,35 @@ void EditorInspector::update_tree() {
editor_property_map[prop].push_back(ep);
}
}
+ ep->set_draw_red(draw_red);
+ ep->set_use_folding(use_folding);
+ ep->set_checkable(checkable);
+ ep->set_checked(checked);
+ ep->set_keying(keying);
ep->set_read_only(read_only);
+ }
+
+ current_vbox->add_child(F->get().property_editor);
+
+ if (ep) {
+
+ ep->connect("property_changed", this, "_property_changed");
+ if (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED) {
+ ep->connect("property_changed", this, "_property_changed_update_all", varray(), CONNECT_DEFERRED);
+ }
+ ep->connect("property_keyed", this, "_property_keyed");
+ ep->connect("property_keyed_with_value", this, "_property_keyed_with_value");
+ ep->connect("property_checked", this, "_property_checked");
+ ep->connect("selected", this, "_property_selected");
+ ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
+ ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
+ ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
+ if (doc_hint != String()) {
+ ep->set_tooltip(property_prefix + p.name + "::" + doc_hint);
+ } else {
+ ep->set_tooltip(property_prefix + p.name);
+ }
ep->update_property();
ep->update_reload_status();
@@ -1364,10 +1688,19 @@ void EditorInspector::update_tree() {
}
}
}
- ped->added_editors.clear();
+
+ if (exclusive) {
+ break;
+ }
}
}
+ for (List<Ref<EditorInspectorPlugin> >::Element *E = valid_plugins.front(); E; E = E->next()) {
+ Ref<EditorInspectorPlugin> ped = E->get();
+ ped->parse_end();
+ _parse_added_editors(main_vbox, ped);
+ }
+
//see if this property exists and should be kept
}
void EditorInspector::update_property(const String &p_prop) {
@@ -1382,35 +1715,44 @@ void EditorInspector::update_property(const String &p_prop) {
void EditorInspector::_clear() {
- editor_property_map.clear();
- sections.clear();
- pending.clear();
- property_selected = StringName();
- property_focusable = -1;
while (main_vbox->get_child_count()) {
memdelete(main_vbox->get_child(0));
}
+ property_selected = StringName();
+ property_focusable = -1;
+ editor_property_map.clear();
+ sections.clear();
+ pending.clear();
+ restart_request_props.clear();
}
void EditorInspector::refresh() {
- if (refresh_countdown > 0)
+ if (refresh_countdown > 0 || changing)
return;
refresh_countdown = EditorSettings::get_singleton()->get("docks/property_editor/auto_refresh_interval");
}
-void EditorInspector::edit(Object *p_object) {
- if (object != p_object) {
- _clear();
- }
+Object *EditorInspector::get_edited_object() {
+ return object;
+}
+void EditorInspector::edit(Object *p_object) {
+ if (object == p_object)
+ return;
if (object) {
+ _clear();
object->remove_change_receptor(this);
}
object = p_object;
+
if (object) {
+ update_scroll_request = 0; //reset
+ if (scroll_cache.has(object->get_instance_id())) { //if exists, set something else
+ update_scroll_request = scroll_cache[object->get_instance_id()]; //done this way because wait until full size is accomodated
+ }
object->add_change_receptor(this);
update_tree();
}
@@ -1465,6 +1807,7 @@ void EditorInspector::register_text_enter(Node *p_line_edit) {
void EditorInspector::_filter_changed(const String &p_text) {
+ _clear();
update_tree();
}
@@ -1479,17 +1822,32 @@ void EditorInspector::set_use_folding(bool p_enable) {
update_tree();
}
+bool EditorInspector::is_using_folding() {
+ return use_folding;
+}
+
void EditorInspector::collapse_all_folding() {
for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) {
E->get()->fold();
}
+
+ for (Map<StringName, List<EditorProperty *> >::Element *F = editor_property_map.front(); F; F = F->next()) {
+ for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
+ E->get()->collapse_all_folding();
+ }
+ }
}
void EditorInspector::expand_all_folding() {
for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) {
E->get()->unfold();
}
+ for (Map<StringName, List<EditorProperty *> >::Element *F = editor_property_map.front(); F; F = F->next()) {
+ for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
+ E->get()->expand_all_folding();
+ }
+ }
}
void EditorInspector::set_scroll_offset(int p_offset) {
@@ -1500,6 +1858,19 @@ int EditorInspector::get_scroll_offset() const {
return get_v_scroll();
}
+void EditorInspector::set_use_sub_inspector_bg(bool p_enable) {
+
+ use_sub_inspector_bg = p_enable;
+ if (!is_inside_tree())
+ return;
+
+ if (use_sub_inspector_bg) {
+ add_style_override("bg", get_stylebox("sub_inspector_bg", "Editor"));
+ } else {
+ add_style_override("bg", get_stylebox("bg", "Tree"));
+ }
+}
+
void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) {
if (object != p_object) //may be undoing/redoing for a non edited object, so ignore
@@ -1575,9 +1946,7 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
}
undo_redo->add_do_method(this, "emit_signal", _prop_edited, p_name);
undo_redo->add_undo_method(this, "emit_signal", _prop_edited, p_name);
- changing++;
undo_redo->commit_action();
- changing--;
}
if (editor_property_map.has(p_name)) {
@@ -1587,9 +1956,25 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
}
}
-void EditorInspector::_property_changed(const String &p_path, const Variant &p_value) {
+void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, bool changing) {
+
+ // The "changing" variable must be true for properties that trigger events as typing occurs,
+ // like "text_changed" signal. eg: Text property of Label, Button, RichTextLabel, etc.
+ if (changing)
+ this->changing++;
_edit_set(p_path, p_value, false, "");
+
+ if (changing)
+ this->changing--;
+
+ if (restart_request_props.has(p_path)) {
+ emit_signal("restart_requested");
+ }
+}
+
+void EditorInspector::_property_changed_update_all(const String &p_path, const Variant &p_value) {
+ update_tree();
}
void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array p_values) {
@@ -1605,6 +1990,9 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array
undo_redo->create_action(TTR("Set Multiple:") + " " + names, UndoRedo::MERGE_ENDS);
for (int i = 0; i < p_paths.size(); i++) {
_edit_set(p_paths[i], p_values[i], false, "");
+ if (restart_request_props.has(p_paths[i])) {
+ emit_signal("restart_requested");
+ }
}
changing++;
undo_redo->commit_action();
@@ -1619,6 +2007,14 @@ void EditorInspector::_property_keyed(const String &p_path) {
emit_signal("property_keyed", p_path, object->get(p_path), false); //second param is deprecated
}
+void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value) {
+
+ if (!object)
+ return;
+
+ emit_signal("property_keyed", p_path, p_value, false); //second param is deprecated
+}
+
void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
if (!object)
@@ -1669,6 +2065,8 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable)
E->get()->deselect();
}
}
+
+ emit_signal("property_selected", p_path);
}
void EditorInspector::_object_id_selected(const String &p_path, ObjectID p_id) {
@@ -1692,7 +2090,11 @@ void EditorInspector::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
get_tree()->connect("node_removed", this, "_node_removed");
- add_style_override("bg", get_stylebox("bg", "Tree"));
+ if (use_sub_inspector_bg) {
+ add_style_override("bg", get_stylebox("sub_inspector_bg", "Editor"));
+ } else if (is_inside_tree()) {
+ add_style_override("bg", get_stylebox("bg", "Tree"));
+ }
}
if (p_what == NOTIFICATION_EXIT_TREE) {
@@ -1702,6 +2104,10 @@ void EditorInspector::_notification(int p_what) {
if (p_what == NOTIFICATION_PROCESS) {
+ if (update_scroll_request >= 0) {
+ get_v_scrollbar()->call_deferred("set_value", update_scroll_request);
+ update_scroll_request = -1;
+ }
if (refresh_countdown > 0) {
refresh_countdown -= get_process_delta_time();
if (refresh_countdown <= 0) {
@@ -1749,22 +2155,57 @@ void EditorInspector::_changed_callback(Object *p_changed, const char *p_prop) {
_edit_request_change(p_changed, p_prop);
}
+void EditorInspector::_vscroll_changed(double p_offset) {
+
+ if (update_scroll_request >= 0) //waiting, do nothing
+ return;
+
+ if (object) {
+ scroll_cache[object->get_instance_id()] = p_offset;
+ }
+}
+
+void EditorInspector::set_property_prefix(const String &p_prefix) {
+ property_prefix = p_prefix;
+}
+
+String EditorInspector::get_property_prefix() const {
+ return property_prefix;
+}
+
+void EditorInspector::set_object_class(const String &p_class) {
+ object_class = p_class;
+}
+
+String EditorInspector::get_object_class() const {
+ return object_class;
+}
+
void EditorInspector::_bind_methods() {
+ ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(false));
ClassDB::bind_method("_multiple_properties_changed", &EditorInspector::_multiple_properties_changed);
- ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed);
+ ClassDB::bind_method("_property_changed_update_all", &EditorInspector::_property_changed_update_all);
+
ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
ClassDB::bind_method("_node_removed", &EditorInspector::_node_removed);
ClassDB::bind_method("_filter_changed", &EditorInspector::_filter_changed);
ClassDB::bind_method("_property_keyed", &EditorInspector::_property_keyed);
+ ClassDB::bind_method("_property_keyed_with_value", &EditorInspector::_property_keyed_with_value);
ClassDB::bind_method("_property_checked", &EditorInspector::_property_checked);
ClassDB::bind_method("_property_selected", &EditorInspector::_property_selected);
ClassDB::bind_method("_resource_selected", &EditorInspector::_resource_selected);
ClassDB::bind_method("_object_id_selected", &EditorInspector::_object_id_selected);
+ ClassDB::bind_method("_vscroll_changed", &EditorInspector::_vscroll_changed);
+ ClassDB::bind_method("refresh", &EditorInspector::refresh);
+
+ ADD_SIGNAL(MethodInfo("property_selected", PropertyInfo(Variant::STRING, "property")));
ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property")));
ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "res"), PropertyInfo(Variant::STRING, "prop")));
ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("property_edited", PropertyInfo(Variant::STRING, "property")));
+ ADD_SIGNAL(MethodInfo("restart_requested"));
}
EditorInspector::EditorInspector() {
@@ -1772,10 +2213,10 @@ EditorInspector::EditorInspector() {
undo_redo = NULL;
main_vbox = memnew(VBoxContainer);
main_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
+ main_vbox->add_constant_override("separation", 0);
add_child(main_vbox);
- main_vbox->set_name("pipirulo");
- set_h_scroll(false);
- set_v_scroll(true);
+ set_enable_h_scroll(false);
+ set_enable_v_scroll(true);
show_categories = false;
hide_script = true;
@@ -1794,4 +2235,8 @@ EditorInspector::EditorInspector() {
_prop_edited = "property_edited";
set_process(true);
property_focusable = -1;
+ use_sub_inspector_bg = false;
+
+ get_v_scrollbar()->connect("value_changed", this, "_vscroll_changed");
+ update_scroll_request = -1;
}