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.cpp143
1 files changed, 79 insertions, 64 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 738b2f9f82..4dd57cb1a8 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -380,7 +380,7 @@ StringName EditorProperty::get_edited_property() {
void EditorProperty::update_property() {
if (get_script_instance()) {
- get_script_instance()->call("update_property");
+ get_script_instance()->call("_update_property");
}
}
@@ -417,7 +417,7 @@ bool EditorPropertyRevert::may_node_be_in_instance(Node *p_node) {
return might_be; // or might not be
}
-bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value) {
+bool EditorPropertyRevert::get_instantiated_node_original_property(Node *p_node, const StringName &p_prop, Variant &value) {
Node *node = p_node;
Node *orig = node;
@@ -524,7 +524,7 @@ bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringNam
if (node && EditorPropertyRevert::may_node_be_in_instance(node)) {
//check for difference including instantiation
Variant vorig;
- if (EditorPropertyRevert::get_instanced_node_original_property(node, p_property, vorig)) {
+ if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) {
Variant v = p_object->get(p_property);
if (EditorPropertyRevert::is_node_property_different(node, v, vorig)) {
@@ -741,7 +741,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
if (use_keying_next()) {
if (property == "frame_coords" && (object->is_class("Sprite2D") || object->is_class("Sprite3D"))) {
- Vector2 new_coords = object->get(property);
+ Vector2i new_coords = object->get(property);
new_coords.x++;
if (new_coords.x >= object->get("hframes").operator int64_t()) {
new_coords.x = 0;
@@ -753,7 +753,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
call_deferred("emit_changed", property, object->get(property).operator int64_t() + 1, "", false);
}
- call_deferred("update_property");
+ call_deferred("_update_property");
}
}
if (delete_rect.has_point(mpos)) {
@@ -764,7 +764,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
Variant vorig;
Node *node = Object::cast_to<Node>(object);
- if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instanced_node_original_property(node, property, vorig)) {
+ if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instantiated_node_original_property(node, property, vorig)) {
emit_changed(property, vorig.duplicate(true));
update_property();
return;
@@ -965,9 +965,7 @@ void EditorProperty::_bind_methods() {
ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id")));
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx")));
- MethodInfo vm;
- vm.name = "update_property";
- BIND_VMETHOD(vm);
+ BIND_VMETHOD(MethodInfo("_update_property"));
}
EditorProperty::EditorProperty() {
@@ -1023,24 +1021,24 @@ void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const St
bool EditorInspectorPlugin::can_handle(Object *p_object) {
if (get_script_instance()) {
- return get_script_instance()->call("can_handle", p_object);
+ return get_script_instance()->call("_can_handle", p_object);
}
return false;
}
void EditorInspectorPlugin::parse_begin(Object *p_object) {
if (get_script_instance()) {
- get_script_instance()->call("parse_begin", 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);
+ 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, bool p_wide) {
+bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
if (get_script_instance()) {
Variant arg[6] = {
p_object, p_type, p_path, p_hint, p_hint_text, p_usage
@@ -1050,14 +1048,14 @@ bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_typ
};
Callable::CallError err;
- return get_script_instance()->call("parse_property", (const Variant **)&argptr, 6, err);
+ return get_script_instance()->call("_parse_property", (const Variant **)&argptr, 6, err);
}
return false;
}
void EditorInspectorPlugin::parse_end() {
if (get_script_instance()) {
- get_script_instance()->call("parse_end");
+ get_script_instance()->call("_parse_end");
}
}
@@ -1066,30 +1064,11 @@ void EditorInspectorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor"), &EditorInspectorPlugin::add_property_editor);
ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties);
- 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"));
- vm.arguments.push_back(PropertyInfo(Variant::STRING, "path"));
- vm.arguments.push_back(PropertyInfo(Variant::INT, "hint"));
- vm.arguments.push_back(PropertyInfo(Variant::STRING, "hint_text"));
- vm.arguments.push_back(PropertyInfo(Variant::INT, "usage"));
- BIND_VMETHOD(vm);
- vm.arguments.clear();
- vm.name = "parse_end";
- vm.return_val.type = Variant::NIL;
- BIND_VMETHOD(vm);
+ BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_handle", PropertyInfo(Variant::OBJECT, "object")));
+ BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_begin"));
+ BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_category", PropertyInfo(Variant::STRING, "category")));
+ BIND_VMETHOD(MethodInfo(Variant::BOOL, "_parse_property", PropertyInfo(Variant::INT, "type"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "hint"), PropertyInfo(Variant::STRING, "hint_text"), PropertyInfo(Variant::INT, "usage")));
+ BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_end"));
}
////////////////////////////////////////////////
@@ -1097,9 +1076,12 @@ void EditorInspectorPlugin::_bind_methods() {
void EditorInspectorCategory::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- draw_rect(Rect2(Vector2(), get_size()), bg_color);
- Ref<Font> font = get_theme_font("font", "Tree");
- int font_size = get_theme_font_size("font_size", "Tree");
+ Ref<StyleBox> sb = get_theme_stylebox("prop_category_style", "Editor");
+
+ draw_style_box(sb, Rect2(Vector2(), get_size()));
+
+ Ref<Font> font = get_theme_font("bold", "EditorFonts");
+ int font_size = get_theme_font_size("bold_size", "EditorFonts");
int hs = get_theme_constant("hseparation", "Tree");
@@ -1181,8 +1163,9 @@ void EditorInspectorSection::_test_unfold() {
void EditorInspectorSection::_notification(int p_what) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
- Ref<Font> font = get_theme_font("font", "Tree");
- int font_size = get_theme_font_size("font_size", "Tree");
+ Ref<Font> font = get_theme_font("bold", "EditorFonts");
+ int font_size = get_theme_font_size("bold_size", "EditorFonts");
+
Ref<Texture2D> arrow;
if (foldable) {
@@ -1199,15 +1182,19 @@ void EditorInspectorSection::_notification(int p_what) {
Size2 size = get_size();
Point2 offset;
+ Rect2 rect;
offset.y = font->get_height(font_size);
if (arrow.is_valid()) {
offset.y = MAX(offset.y, arrow->get_height());
}
offset.y += get_theme_constant("vseparation", "Tree");
- offset.x += get_theme_constant("inspector_margin", "Editor");
-
- Rect2 rect(offset, size - offset);
+ if (is_layout_rtl()) {
+ rect = Rect2(offset, size - offset - Vector2(get_theme_constant("inspector_margin", "Editor"), 0));
+ } else {
+ offset.x += get_theme_constant("inspector_margin", "Editor");
+ rect = Rect2(offset, size - offset);
+ }
//set children
for (int i = 0; i < get_child_count(); i++) {
@@ -1233,15 +1220,19 @@ void EditorInspectorSection::_notification(int p_what) {
bool rtl = is_layout_rtl();
if (foldable) {
- if (rtl) {
- arrow = get_theme_icon("arrow_collapsed_mirrored", "Tree");
+ if (object->editor_is_section_unfolded(section)) {
+ arrow = get_theme_icon("arrow", "Tree");
} else {
- arrow = get_theme_icon("arrow_collapsed", "Tree");
+ if (is_layout_rtl()) {
+ arrow = get_theme_icon("arrow_collapsed_mirrored", "Tree");
+ } else {
+ arrow = get_theme_icon("arrow_collapsed", "Tree");
+ }
}
}
- Ref<Font> font = get_theme_font("font", "Tree");
- int font_size = get_theme_font_size("font_size", "Tree");
+ Ref<Font> font = get_theme_font("bold", "EditorFonts");
+ int font_size = get_theme_font_size("bold_size", "EditorFonts");
int h = font->get_height(font_size);
if (arrow.is_valid()) {
@@ -1249,12 +1240,15 @@ void EditorInspectorSection::_notification(int p_what) {
}
h += get_theme_constant("vseparation", "Tree");
- draw_rect(Rect2(Vector2(), Vector2(get_size().width, h)), bg_color);
+ Color c = bg_color;
+ c.a *= 0.4;
+ draw_rect(Rect2(Vector2(), Vector2(get_size().width, h)), c);
- const int arrow_margin = 3;
- Color color = get_theme_color("font_color", "Tree");
- float text_width = get_size().width - Math::round((16 + arrow_margin) * EDSCALE);
- draw_string(font, Point2(rtl ? 0 : Math::round((16 + arrow_margin) * EDSCALE), font->get_ascent(font_size) + (h - font->get_height(font_size)) / 2).floor(), label, rtl ? HALIGN_RIGHT : HALIGN_LEFT, text_width, font_size, color);
+ const int arrow_margin = 2;
+ const int arrow_width = arrow.is_valid() ? arrow->get_width() : 0;
+ Color color = get_theme_color("font_color");
+ float text_width = get_size().width - Math::round(arrow_width + arrow_margin * EDSCALE);
+ draw_string(font, Point2(rtl ? 0 : Math::round(arrow_width + arrow_margin * EDSCALE), font->get_ascent(font_size) + (h - font->get_height(font_size)) / 2).floor(), label, rtl ? HALIGN_RIGHT : HALIGN_LEFT, text_width, font_size, color);
if (arrow.is_valid()) {
if (rtl) {
@@ -1279,7 +1273,7 @@ void EditorInspectorSection::_notification(int p_what) {
Control *editor_property = Object::cast_to<Control>(vbox->get_child(child_idx));
// Test can_drop_data and can_drop_data_fw, since can_drop_data only works if set up with forwarding or if script attached.
- if (editor_property && (editor_property->can_drop_data(Point2(), dd) || editor_property->call("can_drop_data_fw", Point2(), dd, this))) {
+ if (editor_property && (editor_property->can_drop_data(Point2(), dd) || editor_property->call("_can_drop_data_fw", Point2(), dd, this))) {
children_can_drop = true;
break;
}
@@ -1443,7 +1437,7 @@ 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, bool p_wide) {
+EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
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, p_wide);
if (inspector_plugins[i]->added_editors.size()) {
@@ -1626,7 +1620,7 @@ void EditorInspector::update_tree() {
bool draw_red = false;
- {
+ if (is_inside_tree()) {
Node *nod = Object::cast_to<Node>(object);
Node *es = EditorNode::get_singleton()->get_edited_scene();
if (nod && es != nod && nod->get_owner() != es) {
@@ -1737,7 +1731,6 @@ void EditorInspector::update_tree() {
}
category->label = type;
- category->bg_color = get_theme_color("prop_category", "Editor");
if (use_doc_hints) {
StringName type2 = p.name;
if (!class_descr_cache.has(type2)) {
@@ -1809,12 +1802,12 @@ void EditorInspector::update_tree() {
basename = group + "/" + basename;
}
- String name = (basename.find("/") != -1) ? basename.right(basename.rfind("/") + 1) : basename;
+ String name = (basename.find("/") != -1) ? basename.substr(basename.rfind("/") + 1) : basename;
if (capitalize_paths) {
int dot = name.find(".");
if (dot != -1) {
- String ov = name.right(dot);
+ String ov = name.substr(dot);
name = name.substr(0, dot);
name = name.capitalize();
name += ov;
@@ -1824,7 +1817,13 @@ void EditorInspector::update_tree() {
}
}
- String path = basename.left(basename.rfind("/"));
+ String path;
+ {
+ int idx = basename.rfind("/");
+ if (idx > -1) {
+ path = basename.left(idx);
+ }
+ }
if (use_filter && filter != "") {
String cat = path;
@@ -2266,6 +2265,22 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
undo_redo->add_do_property(object, p_name, p_value);
undo_redo->add_undo_property(object, p_name, object->get(p_name));
+ Variant v_undo_redo = (Object *)undo_redo;
+ Variant v_object = object;
+ Variant v_name = p_name;
+ for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_undo_redo_inspector_hook_callback().size(); i++) {
+ const Callable &callback = EditorNode::get_singleton()->get_editor_data().get_undo_redo_inspector_hook_callback()[i];
+
+ const Variant *p_arguments[] = { &v_undo_redo, &v_object, &v_name, &p_value };
+ Variant return_value;
+ Callable::CallError call_error;
+
+ callback.call(p_arguments, 4, return_value, call_error);
+ if (call_error.error != Callable::CallError::CALL_OK) {
+ ERR_PRINT("Invalid UndoRedo callback.");
+ }
+ }
+
if (p_refresh_all) {
undo_redo->add_do_method(this, "_edit_request_change", object, "");
undo_redo->add_undo_method(this, "_edit_request_change", object, "");