summaryrefslogtreecommitdiff
path: root/editor/editor_properties.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r--editor/editor_properties.cpp1642
1 files changed, 603 insertions, 1039 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 81c4e48974..84105f0cb7 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 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 */
@@ -36,8 +36,9 @@
#include "editor_properties_array_dict.h"
#include "editor_scale.h"
#include "scene/main/window.h"
+#include "scene/resources/font.h"
-///////////////////// NULL /////////////////////////
+///////////////////// Nil /////////////////////////
void EditorPropertyNil::update_property() {
}
@@ -50,7 +51,7 @@ EditorPropertyNil::EditorPropertyNil() {
///////////////////// TEXT /////////////////////////
-void EditorPropertyText::_text_entered(const String &p_string) {
+void EditorPropertyText::_text_submitted(const String &p_string) {
if (updating) {
return;
}
@@ -76,7 +77,9 @@ void EditorPropertyText::_text_changed(const String &p_string) {
void EditorPropertyText::update_property() {
String s = get_edited_object()->get(get_edited_property());
updating = true;
- text->set_text(s);
+ if (text->get_text() != s) {
+ text->set_text(s);
+ }
text->set_editable(!is_read_only());
updating = false;
}
@@ -97,7 +100,7 @@ EditorPropertyText::EditorPropertyText() {
add_child(text);
add_focusable(text);
text->connect("text_changed", callable_mp(this, &EditorPropertyText::_text_changed));
- text->connect("text_entered", callable_mp(this, &EditorPropertyText::_text_entered));
+ text->connect("text_submitted", callable_mp(this, &EditorPropertyText::_text_submitted));
string_name = false;
updating = false;
@@ -132,9 +135,11 @@ void EditorPropertyMultilineText::_open_big_text() {
void EditorPropertyMultilineText::update_property() {
String t = get_edited_object()->get(get_edited_property());
- text->set_text(t);
- if (big_text && big_text->is_visible_in_tree()) {
- big_text->set_text(t);
+ if (text->get_text() != t) {
+ text->set_text(t);
+ if (big_text && big_text->is_visible_in_tree()) {
+ big_text->set_text(t);
+ }
}
}
@@ -145,7 +150,8 @@ void EditorPropertyMultilineText::_notification(int p_what) {
Ref<Texture2D> df = get_theme_icon("DistractionFree", "EditorIcons");
open_big_text->set_icon(df);
Ref<Font> font = get_theme_font("font", "Label");
- text->set_custom_minimum_size(Vector2(0, font->get_height() * 6));
+ int font_size = get_theme_font_size("font_size", "Label");
+ text->set_custom_minimum_size(Vector2(0, font->get_height(font_size) * 6));
} break;
}
@@ -164,7 +170,8 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() {
add_focusable(text);
hb->add_child(text);
text->set_h_size_flags(SIZE_EXPAND_FILL);
- open_big_text = memnew(ToolButton);
+ open_big_text = memnew(Button);
+ open_big_text->set_flat(true);
open_big_text->connect("pressed", callable_mp(this, &EditorPropertyMultilineText::_open_big_text));
hb->add_child(open_big_text);
big_text_dialog = nullptr;
@@ -252,7 +259,7 @@ void EditorPropertyPath::_path_pressed() {
dialog->set_current_path(full_path);
}
- dialog->popup_centered_ratio();
+ dialog->popup_file_dialog();
}
void EditorPropertyPath::update_property() {
@@ -288,8 +295,9 @@ EditorPropertyPath::EditorPropertyPath() {
HBoxContainer *path_hb = memnew(HBoxContainer);
add_child(path_hb);
path = memnew(LineEdit);
+ path->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE);
path_hb->add_child(path);
- path->connect("text_entered", callable_mp(this, &EditorPropertyPath::_path_selected));
+ path->connect("text_submitted", callable_mp(this, &EditorPropertyPath::_path_selected));
path->connect("focus_exited", callable_mp(this, &EditorPropertyPath::_path_focus_exited));
path->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -376,13 +384,13 @@ void EditorPropertyMember::_property_select() {
selector->select_method_from_base_type(hint_text, current);
} else if (hint == MEMBER_METHOD_OF_INSTANCE) {
- Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
+ Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
if (instance) {
selector->select_method_from_instance(instance, current);
}
} else if (hint == MEMBER_METHOD_OF_SCRIPT) {
- Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
+ Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
if (Object::cast_to<Script>(obj)) {
selector->select_method_from_script(Object::cast_to<Script>(obj), current);
}
@@ -407,13 +415,13 @@ void EditorPropertyMember::_property_select() {
selector->select_property_from_base_type(hint_text, current);
} else if (hint == MEMBER_PROPERTY_OF_INSTANCE) {
- Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
+ Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
if (instance) {
selector->select_property_from_instance(instance, current);
}
} else if (hint == MEMBER_PROPERTY_OF_SCRIPT) {
- Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
+ Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
if (Object::cast_to<Script>(obj)) {
selector->select_property_from_script(Object::cast_to<Script>(obj), current);
}
@@ -483,11 +491,12 @@ void EditorPropertyEnum::update_property() {
}
void EditorPropertyEnum::setup(const Vector<String> &p_options) {
+ options->clear();
int64_t current_val = 0;
for (int i = 0; i < p_options.size(); i++) {
Vector<String> text_split = p_options[i].split(":");
if (text_split.size() != 1) {
- current_val = text_split[1].to_int64();
+ current_val = text_split[1].to_int();
}
options->add_item(text_split[0]);
options->set_item_metadata(i, current_val);
@@ -581,13 +590,15 @@ public:
Vector<Rect2> flag_rects;
Vector<String> names;
Vector<String> tooltips;
+ int hovered_index;
- virtual Size2 get_minimum_size() const {
+ virtual Size2 get_minimum_size() const override {
Ref<Font> font = get_theme_font("font", "Label");
- return Vector2(0, font->get_height() * 2);
+ int font_size = get_theme_font_size("font_size", "Label");
+ return Vector2(0, font->get_height(font_size) * 2);
}
- virtual String get_tooltip(const Point2 &p_pos) const {
+ virtual String get_tooltip(const Point2 &p_pos) const override {
for (int i = 0; i < flag_rects.size(); i++) {
if (i < tooltips.size() && flag_rects[i].has_point(p_pos)) {
return tooltips[i];
@@ -596,56 +607,81 @@ public:
return String();
}
void _gui_input(const Ref<InputEvent> &p_ev) {
- Ref<InputEventMouseButton> mb = p_ev;
- if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
+ const Ref<InputEventMouseMotion> mm = p_ev;
+
+ if (mm.is_valid()) {
for (int i = 0; i < flag_rects.size(); i++) {
- if (flag_rects[i].has_point(mb->get_position())) {
- //toggle
- if (value & (1 << i)) {
- value &= ~(1 << i);
- } else {
- value |= (1 << i);
- }
- emit_signal("flag_changed", value);
+ if (flag_rects[i].has_point(mm->get_position())) {
+ // Used to highlight the hovered flag in the layers grid.
+ hovered_index = i;
update();
+ break;
}
}
}
+
+ const Ref<InputEventMouseButton> mb = p_ev;
+
+ if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT && mb->is_pressed() && hovered_index >= 0) {
+ // Toggle the flag.
+ // We base our choice on the hovered flag, so that it always matches the hovered flag.
+ if (value & (1 << hovered_index)) {
+ value &= ~(1 << hovered_index);
+ } else {
+ value |= (1 << hovered_index);
+ }
+
+ emit_signal("flag_changed", value);
+ update();
+ }
}
void _notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- Rect2 rect;
- rect.size = get_size();
- flag_rects.clear();
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ Rect2 rect;
+ rect.size = get_size();
+ flag_rects.clear();
+
+ const int bsize = (rect.size.height * 80 / 100) / 2;
+ const int h = bsize * 2 + 1;
+ const int vofs = (rect.size.height - h) / 2;
+
+ Color color = get_theme_color("highlight_color", "Editor");
+ for (int i = 0; i < 2; i++) {
+ Point2 ofs(4, vofs);
+ if (i == 1) {
+ ofs.y += bsize + 1;
+ }
- int bsize = (rect.size.height * 80 / 100) / 2;
+ ofs += rect.position;
+ for (int j = 0; j < 10; j++) {
+ Point2 o = ofs + Point2(j * (bsize + 1), 0);
+ if (j >= 5) {
+ o.x += 1;
+ }
- int h = bsize * 2 + 1;
- int vofs = (rect.size.height - h) / 2;
+ const int idx = i * 10 + j;
+ const bool on = value & (1 << idx);
+ Rect2 rect2 = Rect2(o, Size2(bsize, bsize));
- Color color = get_theme_color("highlight_color", "Editor");
- for (int i = 0; i < 2; i++) {
- Point2 ofs(4, vofs);
- if (i == 1) {
- ofs.y += bsize + 1;
- }
+ color.a = on ? 0.6 : 0.2;
+ if (idx == hovered_index) {
+ // Add visual feedback when hovering a flag.
+ color.a += 0.15;
+ }
- ofs += rect.position;
- for (int j = 0; j < 10; j++) {
- Point2 o = ofs + Point2(j * (bsize + 1), 0);
- if (j >= 5) {
- o.x += 1;
+ draw_rect(rect2, color);
+ flag_rects.push_back(rect2);
}
-
- uint32_t idx = i * 10 + j;
- bool on = value & (1 << idx);
- Rect2 rect2 = Rect2(o, Size2(bsize, bsize));
- color.a = on ? 0.6 : 0.2;
- draw_rect(rect2, color);
- flag_rects.push_back(rect2);
}
- }
+ } break;
+ case NOTIFICATION_MOUSE_EXIT: {
+ hovered_index = -1;
+ update();
+ } break;
+ default:
+ break;
}
}
@@ -661,6 +697,7 @@ public:
EditorPropertyLayersGrid() {
value = 0;
+ hovered_index = -1; // Nothing is hovered.
}
};
void EditorPropertyLayers::_grid_changed(uint32_t p_grid) {
@@ -682,12 +719,18 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) {
case LAYER_PHYSICS_2D:
basename = "layer_names/2d_physics";
break;
+ case LAYER_NAVIGATION_2D:
+ basename = "layer_names/2d_navigation";
+ break;
case LAYER_RENDER_3D:
basename = "layer_names/3d_render";
break;
case LAYER_PHYSICS_3D:
basename = "layer_names/3d_physics";
break;
+ case LAYER_NAVIGATION_3D:
+ basename = "layer_names/3d_navigation";
+ break;
}
Vector<String> names;
@@ -695,12 +738,12 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) {
for (int i = 0; i < 20; i++) {
String name;
- if (ProjectSettings::get_singleton()->has_setting(basename + "/layer_" + itos(i + 1))) {
- name = ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(i + 1));
+ if (ProjectSettings::get_singleton()->has_setting(basename + vformat("/layer_%d", i))) {
+ name = ProjectSettings::get_singleton()->get(basename + vformat("/layer_%d", i));
}
if (name == "") {
- name = TTR("Layer") + " " + itos(i + 1);
+ name = vformat(TTR("Layer %d"), i);
}
names.push_back(name);
@@ -752,7 +795,7 @@ EditorPropertyLayers::EditorPropertyLayers() {
hb->add_child(grid);
button = memnew(Button);
button->set_toggle_mode(true);
- button->set_text("..");
+ button->set_text("...");
button->connect("pressed", callable_mp(this, &EditorPropertyLayers::_button_pressed));
hb->add_child(button);
set_bottom_editor(hb);
@@ -850,11 +893,17 @@ void EditorPropertyFloat::_value_changed(double val) {
return;
}
+ if (angle_in_radians) {
+ val = Math::deg2rad(val);
+ }
emit_changed(get_edited_property(), val);
}
void EditorPropertyFloat::update_property() {
double val = get_edited_object()->get(get_edited_property());
+ if (angle_in_radians) {
+ val = Math::rad2deg(val);
+ }
setting = true;
spin->set_value(val);
setting = false;
@@ -863,7 +912,8 @@ void EditorPropertyFloat::update_property() {
void EditorPropertyFloat::_bind_methods() {
}
-void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser) {
+void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix, bool p_angle_in_radians) {
+ angle_in_radians = p_angle_in_radians;
spin->set_min(p_min);
spin->set_max(p_max);
spin->set_step(p_step);
@@ -871,6 +921,7 @@ void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool
spin->set_exp_ratio(p_exp_range);
spin->set_allow_greater(p_greater);
spin->set_allow_lesser(p_lesser);
+ spin->set_suffix(p_suffix);
}
EditorPropertyFloat::EditorPropertyFloat() {
@@ -879,7 +930,6 @@ EditorPropertyFloat::EditorPropertyFloat() {
add_child(spin);
add_focusable(spin);
spin->connect("value_changed", callable_mp(this, &EditorPropertyFloat::_value_changed));
- setting = false;
}
///////////////////// EASING /////////////////////////
@@ -887,11 +937,11 @@ EditorPropertyFloat::EditorPropertyFloat() {
void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
const Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid()) {
- if (mb->is_doubleclick() && mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->is_double_click() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
_setup_spin();
}
- if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
+ if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
preset->set_position(easing_draw->get_screen_transform().xform(mb->get_position()));
preset->popup();
@@ -900,7 +950,7 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
easing_draw->update();
}
- if (mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
dragging = mb->is_pressed();
// Update to display the correct dragging color
easing_draw->update();
@@ -909,7 +959,7 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
const Ref<InputEventMouseMotion> mm = p_ev;
- if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
+ if (dragging && mm.is_valid() && mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT) {
float rel = mm->get_relative().x;
if (rel == 0) {
return;
@@ -920,14 +970,11 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
}
float val = get_edited_object()->get(get_edited_property());
- if (val == 0) {
- return;
- }
bool sg = val < 0;
val = Math::absf(val);
val = Math::log(val) / Math::log((float)2.0);
- //logspace
+ // Logarithmic space.
val += rel * 0.05;
val = Math::pow(2.0f, val);
@@ -935,6 +982,16 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
val = -val;
}
+ // 0 is a singularity, but both positive and negative values
+ // are otherwise allowed. Enforce 0+ as workaround.
+ if (Math::is_zero_approx(val)) {
+ val = 0.00001;
+ }
+
+ // Limit to a reasonable value to prevent the curve going into infinity,
+ // which can cause crashes and other issues.
+ val = CLAMP(val, -1'000'000, 1'000'000);
+
emit_changed(get_edited_property(), val);
easing_draw->update();
}
@@ -945,12 +1002,12 @@ void EditorPropertyEasing::_draw_easing() {
Size2 s = easing_draw->get_size();
- const int points = 48;
+ const int point_count = 48;
- float prev = 1.0;
const float exp = get_edited_object()->get(get_edited_property());
const Ref<Font> f = get_theme_font("font", "Label");
+ int font_size = get_theme_font_size("font_size", "Label");
const Color font_color = get_theme_color("font_color", "Label");
Color line_color;
if (dragging) {
@@ -959,25 +1016,32 @@ void EditorPropertyEasing::_draw_easing() {
line_color = get_theme_color("font_color", "Label") * Color(1, 1, 1, 0.9);
}
- Vector<Point2> lines;
- for (int i = 1; i <= points; i++) {
- float ifl = i / float(points);
- float iflp = (i - 1) / float(points);
+ Vector<Point2> points;
+ for (int i = 0; i <= point_count; i++) {
+ float ifl = i / float(point_count);
const float h = 1.0 - Math::ease(ifl, exp);
if (flip) {
ifl = 1.0 - ifl;
- iflp = 1.0 - iflp;
}
- lines.push_back(Point2(ifl * s.width, h * s.height));
- lines.push_back(Point2(iflp * s.width, prev * s.height));
- prev = h;
+ points.push_back(Point2(ifl * s.width, h * s.height));
}
- easing_draw->draw_multiline(lines, line_color, 1.0);
- f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), font_color);
+ easing_draw->draw_polyline(points, line_color, 1.0, true);
+ // Draw more decimals for small numbers since higher precision is usually required for fine adjustments.
+ int decimals;
+ if (Math::abs(exp) < 0.1 - CMP_EPSILON) {
+ decimals = 4;
+ } else if (Math::abs(exp) < 1 - CMP_EPSILON) {
+ decimals = 3;
+ } else if (Math::abs(exp) < 10 - CMP_EPSILON) {
+ decimals = 2;
+ } else {
+ decimals = 1;
+ }
+ f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), TS->format_number(rtos(exp).pad_decimals(decimals)), HALIGN_LEFT, -1, font_size, font_color);
}
void EditorPropertyEasing::update_property() {
@@ -994,7 +1058,7 @@ void EditorPropertyEasing::_set_preset(int p_preset) {
void EditorPropertyEasing::_setup_spin() {
setting = true;
spin->setup_and_show();
- spin->get_line_edit()->set_text(rtos(get_edited_object()->get(get_edited_property())));
+ spin->get_line_edit()->set_text(TS->format_number(rtos(get_edited_object()->get(get_edited_property()))));
setting = false;
spin->show();
}
@@ -1009,6 +1073,11 @@ void EditorPropertyEasing::_spin_value_changed(double p_value) {
if (Math::is_zero_approx(p_value)) {
p_value = 0.00001;
}
+
+ // Limit to a reasonable value to prevent the curve going into infinity,
+ // which can cause crashes and other issues.
+ p_value = CLAMP(p_value, -1'000'000, 1'000'000);
+
emit_changed(get_edited_property(), p_value);
_spin_focus_exited();
}
@@ -1038,7 +1107,7 @@ void EditorPropertyEasing::_notification(int p_what) {
preset->add_icon_item(get_theme_icon("CurveInOut", "EditorIcons"), "In-Out", EASING_IN_OUT);
preset->add_icon_item(get_theme_icon("CurveOutIn", "EditorIcons"), "Out-In", EASING_OUT_IN);
}
- easing_draw->set_custom_minimum_size(Size2(0, get_theme_font("font", "Label")->get_height() * 2));
+ easing_draw->set_custom_minimum_size(Size2(0, get_theme_font("font", "Label")->get_height(get_theme_font_size("font_size", "Label")) * 2));
} break;
}
}
@@ -1110,7 +1179,7 @@ void EditorPropertyVector2::_notification(int p_what) {
void EditorPropertyVector2::_bind_methods() {
}
-void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 2; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1118,11 +1187,12 @@ void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, boo
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyVector2::EditorPropertyVector2(bool p_force_wide) {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing");
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector2_editing"));
BoxContainer *bc;
@@ -1196,7 +1266,7 @@ void EditorPropertyRect2::_notification(int p_what) {
void EditorPropertyRect2::_bind_methods() {
}
-void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1204,21 +1274,26 @@ void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyRect2::EditorPropertyRect2(bool p_force_wide) {
- bool horizontal = !p_force_wide && bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
-
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
+ bool grid = false;
BoxContainer *bc;
if (p_force_wide) {
bc = memnew(HBoxContainer);
add_child(bc);
} else if (horizontal) {
- bc = memnew(HBoxContainer);
+ bc = memnew(VBoxContainer);
add_child(bc);
set_bottom_editor(bc);
+
+ bc->add_child(memnew(HBoxContainer));
+ bc->add_child(memnew(HBoxContainer));
+ grid = true;
} else {
bc = memnew(VBoxContainer);
add_child(bc);
@@ -1229,7 +1304,13 @@ EditorPropertyRect2::EditorPropertyRect2(bool p_force_wide) {
spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true);
- bc->add_child(spin[i]);
+
+ if (grid) {
+ bc->get_child(i / 2)->add_child(spin[i]);
+ } else {
+ bc->add_child(spin[i]);
+ }
+
add_focusable(spin[i]);
spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyRect2::_value_changed), varray(desc[i]));
if (horizontal) {
@@ -1254,18 +1335,45 @@ void EditorPropertyVector3::_value_changed(double val, const String &p_name) {
v3.x = spin[0]->get_value();
v3.y = spin[1]->get_value();
v3.z = spin[2]->get_value();
+ if (angle_in_radians) {
+ v3.x = Math::deg2rad(v3.x);
+ v3.y = Math::deg2rad(v3.y);
+ v3.z = Math::deg2rad(v3.z);
+ }
emit_changed(get_edited_property(), v3, p_name);
}
void EditorPropertyVector3::update_property() {
- Vector3 val = get_edited_object()->get(get_edited_property());
+ update_using_vector(get_edited_object()->get(get_edited_property()));
+}
+
+void EditorPropertyVector3::update_using_vector(Vector3 p_vector) {
+ if (angle_in_radians) {
+ p_vector.x = Math::rad2deg(p_vector.x);
+ p_vector.y = Math::rad2deg(p_vector.y);
+ p_vector.z = Math::rad2deg(p_vector.z);
+ }
setting = true;
- spin[0]->set_value(val.x);
- spin[1]->set_value(val.y);
- spin[2]->set_value(val.z);
+ spin[0]->set_value(p_vector.x);
+ spin[1]->set_value(p_vector.y);
+ spin[2]->set_value(p_vector.z);
setting = false;
}
+Vector3 EditorPropertyVector3::get_vector() {
+ Vector3 v3;
+ v3.x = spin[0]->get_value();
+ v3.y = spin[1]->get_value();
+ v3.z = spin[2]->get_value();
+ if (angle_in_radians) {
+ v3.x = Math::deg2rad(v3.x);
+ v3.y = Math::deg2rad(v3.y);
+ v3.z = Math::deg2rad(v3.z);
+ }
+
+ return v3;
+}
+
void EditorPropertyVector3::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color("accent_color", "Editor");
@@ -1280,7 +1388,8 @@ void EditorPropertyVector3::_notification(int p_what) {
void EditorPropertyVector3::_bind_methods() {
}
-void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix, bool p_angle_in_radians) {
+ angle_in_radians = p_angle_in_radians;
for (int i = 0; i < 3; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1288,11 +1397,12 @@ void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, boo
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
BoxContainer *bc;
@@ -1324,7 +1434,6 @@ EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) {
if (!horizontal) {
set_label_reference(spin[0]); //show text and buttons around this
}
- setting = false;
}
///////////////////// VECTOR2i /////////////////////////
@@ -1362,7 +1471,7 @@ void EditorPropertyVector2i::_notification(int p_what) {
void EditorPropertyVector2i::_bind_methods() {
}
-void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider) {
+void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 2; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1370,11 +1479,12 @@ void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider) {
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyVector2i::EditorPropertyVector2i(bool p_force_wide) {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing");
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector2_editing"));
BoxContainer *bc;
@@ -1409,7 +1519,7 @@ EditorPropertyVector2i::EditorPropertyVector2i(bool p_force_wide) {
setting = false;
}
-///////////////////// RECT2 /////////////////////////
+///////////////////// RECT2i /////////////////////////
void EditorPropertyRect2i::_value_changed(double val, const String &p_name) {
if (setting) {
@@ -1448,7 +1558,7 @@ void EditorPropertyRect2i::_notification(int p_what) {
void EditorPropertyRect2i::_bind_methods() {
}
-void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider) {
+void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1456,21 +1566,26 @@ void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider) {
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
-
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
+ bool grid = false;
BoxContainer *bc;
if (p_force_wide) {
bc = memnew(HBoxContainer);
add_child(bc);
} else if (horizontal) {
- bc = memnew(HBoxContainer);
+ bc = memnew(VBoxContainer);
add_child(bc);
set_bottom_editor(bc);
+
+ bc->add_child(memnew(HBoxContainer));
+ bc->add_child(memnew(HBoxContainer));
+ grid = true;
} else {
bc = memnew(VBoxContainer);
add_child(bc);
@@ -1481,7 +1596,13 @@ EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) {
spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]);
spin[i]->set_flat(true);
- bc->add_child(spin[i]);
+
+ if (grid) {
+ bc->get_child(i / 2)->add_child(spin[i]);
+ } else {
+ bc->add_child(spin[i]);
+ }
+
add_focusable(spin[i]);
spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyRect2i::_value_changed), varray(desc[i]));
if (horizontal) {
@@ -1495,7 +1616,7 @@ EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) {
setting = false;
}
-///////////////////// VECTOR3 /////////////////////////
+///////////////////// VECTOR3i /////////////////////////
void EditorPropertyVector3i::_value_changed(double val, const String &p_name) {
if (setting) {
@@ -1532,7 +1653,7 @@ void EditorPropertyVector3i::_notification(int p_what) {
void EditorPropertyVector3i::_bind_methods() {
}
-void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider) {
+void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 3; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1540,11 +1661,12 @@ void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider) {
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyVector3i::EditorPropertyVector3i(bool p_force_wide) {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
BoxContainer *bc;
if (p_force_wide) {
@@ -1617,7 +1739,7 @@ void EditorPropertyPlane::_notification(int p_what) {
void EditorPropertyPlane::_bind_methods() {
}
-void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1625,11 +1747,12 @@ void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
EditorPropertyPlane::EditorPropertyPlane(bool p_force_wide) {
- bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
+ bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
BoxContainer *bc;
@@ -1664,14 +1787,14 @@ EditorPropertyPlane::EditorPropertyPlane(bool p_force_wide) {
setting = false;
}
-///////////////////// QUAT /////////////////////////
+///////////////////// QUATERNION /////////////////////////
-void EditorPropertyQuat::_value_changed(double val, const String &p_name) {
+void EditorPropertyQuaternion::_value_changed(double val, const String &p_name) {
if (setting) {
return;
}
- Quat p;
+ Quaternion p;
p.x = spin[0]->get_value();
p.y = spin[1]->get_value();
p.z = spin[2]->get_value();
@@ -1679,8 +1802,8 @@ void EditorPropertyQuat::_value_changed(double val, const String &p_name) {
emit_changed(get_edited_property(), p, p_name);
}
-void EditorPropertyQuat::update_property() {
- Quat val = get_edited_object()->get(get_edited_property());
+void EditorPropertyQuaternion::update_property() {
+ Quaternion val = get_edited_object()->get(get_edited_property());
setting = true;
spin[0]->set_value(val.x);
spin[1]->set_value(val.y);
@@ -1689,7 +1812,7 @@ void EditorPropertyQuat::update_property() {
setting = false;
}
-void EditorPropertyQuat::_notification(int p_what) {
+void EditorPropertyQuaternion::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color("accent_color", "Editor");
for (int i = 0; i < 3; i++) {
@@ -1700,10 +1823,10 @@ void EditorPropertyQuat::_notification(int p_what) {
}
}
-void EditorPropertyQuat::_bind_methods() {
+void EditorPropertyQuaternion::_bind_methods() {
}
-void EditorPropertyQuat::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1711,10 +1834,11 @@ void EditorPropertyQuat::setup(double p_min, double p_max, double p_step, bool p
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
-EditorPropertyQuat::EditorPropertyQuat() {
+EditorPropertyQuaternion::EditorPropertyQuaternion() {
bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
BoxContainer *bc;
@@ -1735,7 +1859,7 @@ EditorPropertyQuat::EditorPropertyQuat() {
spin[i]->set_label(desc[i]);
bc->add_child(spin[i]);
add_focusable(spin[i]);
- spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyQuat::_value_changed), varray(desc[i]));
+ spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyQuaternion::_value_changed), varray(desc[i]));
if (horizontal) {
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
}
@@ -1792,7 +1916,7 @@ void EditorPropertyAABB::_notification(int p_what) {
void EditorPropertyAABB::_bind_methods() {
}
-void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 6; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1800,6 +1924,7 @@ void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
@@ -1868,7 +1993,7 @@ void EditorPropertyTransform2D::_notification(int p_what) {
void EditorPropertyTransform2D::_bind_methods() {
}
-void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 6; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1876,6 +2001,7 @@ void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step,
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
@@ -1949,7 +2075,7 @@ void EditorPropertyBasis::_notification(int p_what) {
void EditorPropertyBasis::_bind_methods() {
}
-void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 9; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -1957,6 +2083,7 @@ void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
@@ -1981,12 +2108,12 @@ EditorPropertyBasis::EditorPropertyBasis() {
///////////////////// TRANSFORM /////////////////////////
-void EditorPropertyTransform::_value_changed(double val, const String &p_name) {
+void EditorPropertyTransform3D::_value_changed(double val, const String &p_name) {
if (setting) {
return;
}
- Transform p;
+ Transform3D p;
p.basis[0][0] = spin[0]->get_value();
p.basis[1][0] = spin[1]->get_value();
p.basis[2][0] = spin[2]->get_value();
@@ -2003,26 +2130,28 @@ void EditorPropertyTransform::_value_changed(double val, const String &p_name) {
emit_changed(get_edited_property(), p, p_name);
}
-void EditorPropertyTransform::update_property() {
- Transform val = get_edited_object()->get(get_edited_property());
- setting = true;
- spin[0]->set_value(val.basis[0][0]);
- spin[1]->set_value(val.basis[1][0]);
- spin[2]->set_value(val.basis[2][0]);
- spin[3]->set_value(val.basis[0][1]);
- spin[4]->set_value(val.basis[1][1]);
- spin[5]->set_value(val.basis[2][1]);
- spin[6]->set_value(val.basis[0][2]);
- spin[7]->set_value(val.basis[1][2]);
- spin[8]->set_value(val.basis[2][2]);
- spin[9]->set_value(val.origin[0]);
- spin[10]->set_value(val.origin[1]);
- spin[11]->set_value(val.origin[2]);
+void EditorPropertyTransform3D::update_property() {
+ update_using_transform(get_edited_object()->get(get_edited_property()));
+}
+void EditorPropertyTransform3D::update_using_transform(Transform3D p_transform) {
+ setting = true;
+ spin[0]->set_value(p_transform.basis[0][0]);
+ spin[1]->set_value(p_transform.basis[1][0]);
+ spin[2]->set_value(p_transform.basis[2][0]);
+ spin[3]->set_value(p_transform.basis[0][1]);
+ spin[4]->set_value(p_transform.basis[1][1]);
+ spin[5]->set_value(p_transform.basis[2][1]);
+ spin[6]->set_value(p_transform.basis[0][2]);
+ spin[7]->set_value(p_transform.basis[1][2]);
+ spin[8]->set_value(p_transform.basis[2][2]);
+ spin[9]->set_value(p_transform.origin[0]);
+ spin[10]->set_value(p_transform.origin[1]);
+ spin[11]->set_value(p_transform.origin[2]);
setting = false;
}
-void EditorPropertyTransform::_notification(int p_what) {
+void EditorPropertyTransform3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color("accent_color", "Editor");
for (int i = 0; i < 12; i++) {
@@ -2033,10 +2162,10 @@ void EditorPropertyTransform::_notification(int p_what) {
}
}
-void EditorPropertyTransform::_bind_methods() {
+void EditorPropertyTransform3D::_bind_methods() {
}
-void EditorPropertyTransform::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
+void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
for (int i = 0; i < 12; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
@@ -2044,10 +2173,11 @@ void EditorPropertyTransform::setup(double p_min, double p_max, double p_step, b
spin[i]->set_hide_slider(p_no_slider);
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
+ spin[i]->set_suffix(p_suffix);
}
}
-EditorPropertyTransform::EditorPropertyTransform() {
+EditorPropertyTransform3D::EditorPropertyTransform3D() {
GridContainer *g = memnew(GridContainer);
g->set_columns(3);
add_child(g);
@@ -2060,7 +2190,7 @@ EditorPropertyTransform::EditorPropertyTransform() {
g->add_child(spin[i]);
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
add_focusable(spin[i]);
- spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyTransform::_value_changed), varray(desc[i]));
+ spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyTransform3D::_value_changed), varray(desc[i]));
}
set_bottom_editor(g);
setting = false;
@@ -2069,11 +2199,18 @@ EditorPropertyTransform::EditorPropertyTransform() {
////////////// COLOR PICKER //////////////////////
void EditorPropertyColor::_color_changed(const Color &p_color) {
+ // Cancel the color change if the current color is identical to the new one.
+ if (get_edited_object()->get(get_edited_property()) == p_color) {
+ return;
+ }
+
emit_changed(get_edited_property(), p_color, "", true);
}
void EditorPropertyColor::_popup_closed() {
- emit_changed(get_edited_property(), picker->get_pick_color(), "", false);
+ if (picker->get_pick_color() != last_color) {
+ emit_changed(get_edited_property(), picker->get_pick_color(), "", false);
+ }
}
void EditorPropertyColor::_picker_created() {
@@ -2084,6 +2221,13 @@ void EditorPropertyColor::_picker_created() {
} else if (default_color_mode == 2) {
picker->get_picker()->set_raw_mode(true);
}
+
+ int picker_shape = EDITOR_GET("interface/inspector/default_color_picker_shape");
+ picker->get_picker()->set_picker_shape((ColorPicker::PickerShapeType)picker_shape);
+}
+
+void EditorPropertyColor::_picker_opening() {
+ last_color = picker->get_pick_color();
}
void EditorPropertyColor::_bind_methods() {
@@ -2121,6 +2265,7 @@ EditorPropertyColor::EditorPropertyColor() {
picker->connect("color_changed", callable_mp(this, &EditorPropertyColor::_color_changed));
picker->connect("popup_closed", callable_mp(this, &EditorPropertyColor::_popup_closed));
picker->connect("picker_created", callable_mp(this, &EditorPropertyColor::_picker_created));
+ picker->get_popup()->connect("about_to_popup", callable_mp(this, &EditorPropertyColor::_picker_opening));
}
////////////// NODE PATH //////////////////////
@@ -2147,7 +2292,7 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
base_node = get_edited_object()->call("get_root_path");
}
- if (!base_node && Object::cast_to<Reference>(get_edited_object())) {
+ if (!base_node && Object::cast_to<RefCounted>(get_edited_object())) {
Node *to_node = get_node(p_path);
ERR_FAIL_COND(!to_node);
path = get_tree()->get_edited_scene_root()->get_path_to(to_node);
@@ -2168,7 +2313,7 @@ void EditorPropertyNodePath::_node_assign() {
add_child(scene_tree);
scene_tree->connect("selected", callable_mp(this, &EditorPropertyNodePath::_node_selected));
}
- scene_tree->popup_centered_ratio();
+ scene_tree->popup_scenetree_dialog();
}
void EditorPropertyNodePath::_node_clear() {
@@ -2270,427 +2415,64 @@ EditorPropertyRID::EditorPropertyRID() {
////////////// RESOURCE //////////////////////
-void EditorPropertyResource::_file_selected(const String &p_path) {
- RES res = ResourceLoader::load(p_path);
-
- ERR_FAIL_COND_MSG(res.is_null(), "Cannot load resource from path '" + p_path + "'.");
-
- List<PropertyInfo> prop_list;
- get_edited_object()->get_property_list(&prop_list);
- String property_types;
-
- for (List<PropertyInfo>::Element *E = prop_list.front(); E; E = E->next()) {
- if (E->get().name == get_edited_property() && (E->get().hint & PROPERTY_HINT_RESOURCE_TYPE)) {
- property_types = E->get().hint_string;
- }
- }
- if (!property_types.empty()) {
- bool any_type_matches = false;
- const Vector<String> split_property_types = property_types.split(",");
- for (int i = 0; i < split_property_types.size(); ++i) {
- if (res->is_class(split_property_types[i])) {
- any_type_matches = true;
- break;
- }
- }
-
- if (!any_type_matches) {
- EditorNode::get_singleton()->show_warning(vformat(TTR("The selected resource (%s) does not match any type expected for this property (%s)."), res->get_class(), property_types));
- }
+void EditorPropertyResource::_resource_selected(const RES &p_resource) {
+ if (use_sub_inspector) {
+ bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
+ get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
+ update_property();
+ } else {
+ emit_signal("resource_selected", get_edited_property(), p_resource);
}
-
- emit_changed(get_edited_property(), res);
- update_property();
}
-void EditorPropertyResource::_menu_option(int p_which) {
- // scene_tree->popup_centered_ratio();
- switch (p_which) {
- case OBJ_MENU_LOAD: {
- if (!file) {
- file = memnew(EditorFileDialog);
- file->connect("file_selected", callable_mp(this, &EditorPropertyResource::_file_selected));
- add_child(file);
- }
- file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
- String type = base_type;
-
- List<String> extensions;
- for (int i = 0; i < type.get_slice_count(","); i++) {
- ResourceLoader::get_recognized_extensions_for_type(type.get_slice(",", i), &extensions);
- }
-
- Set<String> valid_extensions;
- for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
- valid_extensions.insert(E->get());
- }
-
- file->clear_filters();
- for (Set<String>::Element *E = valid_extensions.front(); E; E = E->next()) {
- file->add_filter("*." + E->get() + " ; " + E->get().to_upper());
- }
-
- file->popup_centered_ratio();
- } break;
-
- case OBJ_MENU_EDIT: {
- RES res = get_edited_object()->get(get_edited_property());
+void EditorPropertyResource::_resource_changed(const RES &p_resource) {
+ // Make visual script the correct type.
+ Ref<Script> s = p_resource;
+ if (get_edited_object() && s.is_valid()) {
+ s->call("set_instance_base_type", get_edited_object()->get_class());
+ }
- if (!res.is_null()) {
- emit_signal("resource_selected", get_edited_property(), res);
- }
- } break;
- case OBJ_MENU_CLEAR: {
+ // Prevent the creation of invalid ViewportTextures when possible.
+ Ref<ViewportTexture> vpt = p_resource;
+ if (vpt.is_valid()) {
+ Resource *r = Object::cast_to<Resource>(get_edited_object());
+ if (r && r->get_path().is_resource_file()) {
+ EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on resources saved as a file.\nResource needs to belong to a scene."));
emit_changed(get_edited_property(), RES());
update_property();
-
- } break;
-
- case OBJ_MENU_MAKE_UNIQUE: {
- RES res_orig = get_edited_object()->get(get_edited_property());
- if (res_orig.is_null()) {
- return;
- }
-
- List<PropertyInfo> property_list;
- res_orig->get_property_list(&property_list);
- List<Pair<String, Variant>> propvalues;
-
- for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
- Pair<String, Variant> p;
- PropertyInfo &pi = E->get();
- if (pi.usage & PROPERTY_USAGE_STORAGE) {
- p.first = pi.name;
- p.second = res_orig->get(pi.name);
- }
-
- propvalues.push_back(p);
- }
-
- String orig_type = res_orig->get_class();
-
- Object *inst = ClassDB::instance(orig_type);
-
- Ref<Resource> res = Ref<Resource>(Object::cast_to<Resource>(inst));
-
- ERR_FAIL_COND(res.is_null());
-
- for (List<Pair<String, Variant>>::Element *E = propvalues.front(); E; E = E->next()) {
- Pair<String, Variant> &p = E->get();
- res->set(p.first, p.second);
- }
-
- emit_changed(get_edited_property(), res);
- update_property();
-
- } break;
-
- case OBJ_MENU_SAVE: {
- RES res = get_edited_object()->get(get_edited_property());
- if (res.is_null()) {
- return;
- }
- EditorNode::get_singleton()->save_resource(res);
- } break;
-
- case OBJ_MENU_COPY: {
- RES res = get_edited_object()->get(get_edited_property());
-
- EditorSettings::get_singleton()->set_resource_clipboard(res);
-
- } break;
- case OBJ_MENU_PASTE: {
- RES res = EditorSettings::get_singleton()->get_resource_clipboard();
- emit_changed(get_edited_property(), res);
- update_property();
-
- } break;
- case OBJ_MENU_NEW_SCRIPT: {
- if (Object::cast_to<Node>(get_edited_object())) {
- EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(get_edited_object()), false);
- }
-
- } break;
- case OBJ_MENU_EXTEND_SCRIPT: {
- if (Object::cast_to<Node>(get_edited_object())) {
- EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(get_edited_object()), true);
- }
-
- } break;
- case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
- RES res = get_edited_object()->get(get_edited_property());
-
- FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
- file_system_dock->navigate_to_path(res->get_path());
- // Ensure that the FileSystem dock is visible.
- TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
- tab_container->set_current_tab(file_system_dock->get_index());
- } break;
- default: {
- RES res = get_edited_object()->get(get_edited_property());
-
- if (p_which >= CONVERT_BASE_ID) {
- int to_type = p_which - CONVERT_BASE_ID;
-
- Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(res);
-
- ERR_FAIL_INDEX(to_type, conversions.size());
-
- Ref<Resource> new_res = conversions[to_type]->convert(res);
-
- emit_changed(get_edited_property(), new_res);
- update_property();
- break;
- }
- ERR_FAIL_COND(inheritors_array.empty());
-
- String intype = inheritors_array[p_which - TYPE_BASE_ID];
-
- if (intype == "ViewportTexture") {
- Resource *r = Object::cast_to<Resource>(get_edited_object());
- if (r && r->get_path().is_resource_file()) {
- EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on resources saved as a file.\nResource needs to belong to a scene."));
- return;
- }
-
- if (r && !r->is_local_to_scene()) {
- EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on this resource because it's not set as local to scene.\nPlease switch on the 'local to scene' property on it (and all resources containing it up to a node)."));
- return;
- }
-
- if (!scene_tree) {
- scene_tree = memnew(SceneTreeDialog);
- Vector<StringName> valid_types;
- valid_types.push_back("Viewport");
- scene_tree->get_scene_tree()->set_valid_types(valid_types);
- scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
- add_child(scene_tree);
- scene_tree->connect("selected", callable_mp(this, &EditorPropertyResource::_viewport_selected));
- scene_tree->set_title(TTR("Pick a Viewport"));
- }
- scene_tree->popup_centered_ratio();
-
- return;
- }
-
- Object *obj = nullptr;
-
- if (ScriptServer::is_global_class(intype)) {
- obj = ClassDB::instance(ScriptServer::get_global_class_native_base(intype));
- if (obj) {
- Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype));
- if (script.is_valid()) {
- obj->set_script(Variant(script));
- }
- }
- } else {
- obj = ClassDB::instance(intype);
- }
-
- if (!obj) {
- obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
- }
-
- ERR_BREAK(!obj);
- Resource *resp = Object::cast_to<Resource>(obj);
- ERR_BREAK(!resp);
- if (get_edited_object() && base_type != String() && base_type == "Script") {
- //make visual script the right type
- resp->call("set_instance_base_type", get_edited_object()->get_class());
- }
-
- res = Ref<Resource>(resp);
- emit_changed(get_edited_property(), res);
- update_property();
-
- } break;
- }
-}
-
-void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj) {
- RES p = get_edited_object()->get(get_edited_property());
- if (p.is_valid() && p->get_instance_id() == p_obj) {
- String type = p->get_class_name();
-
- if (ClassDB::is_parent_class(type, "Script")) {
- assign->set_text(p->get_path().get_file());
return;
}
- if (p_preview.is_valid()) {
- preview->set_margin(MARGIN_LEFT, assign->get_icon()->get_width() + assign->get_theme_stylebox("normal")->get_default_margin(MARGIN_LEFT) + get_theme_constant("hseparation", "Button"));
- if (type == "GradientTexture") {
- preview->set_stretch_mode(TextureRect::STRETCH_SCALE);
- assign->set_custom_minimum_size(Size2(1, 1));
- } else {
- preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
- assign->set_custom_minimum_size(Size2(1, thumbnail_size));
- }
- preview->set_texture(p_preview);
- assign->set_text("");
- }
- }
-}
-
-void EditorPropertyResource::_update_menu_items() {
- //////////////////// UPDATE MENU //////////////////////////
- RES res = get_edited_object()->get(get_edited_property());
-
- menu->clear();
-
- if (get_edited_property() == "script" && base_type == "Script" && Object::cast_to<Node>(get_edited_object())) {
- menu->add_icon_item(get_theme_icon("ScriptCreate", "EditorIcons"), TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
- menu->add_icon_item(get_theme_icon("ScriptExtend", "EditorIcons"), TTR("Extend Script"), OBJ_MENU_EXTEND_SCRIPT);
- menu->add_separator();
- } else if (base_type != "") {
- int idx = 0;
-
- Vector<EditorData::CustomType> custom_resources;
-
- if (EditorNode::get_editor_data().get_custom_types().has("Resource")) {
- custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
- }
-
- for (int i = 0; i < base_type.get_slice_count(","); i++) {
- String base = base_type.get_slice(",", i);
-
- Set<String> valid_inheritors;
- valid_inheritors.insert(base);
- List<StringName> inheritors;
- ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors);
-
- for (int j = 0; j < custom_resources.size(); j++) {
- inheritors.push_back(custom_resources[j].name);
- }
-
- List<StringName>::Element *E = inheritors.front();
- while (E) {
- valid_inheritors.insert(E->get());
- E = E->next();
- }
-
- List<StringName> global_classes;
- ScriptServer::get_global_class_list(&global_classes);
- E = global_classes.front();
- while (E) {
- if (EditorNode::get_editor_data().script_class_is_parent(E->get(), base_type)) {
- valid_inheritors.insert(E->get());
- }
- E = E->next();
- }
-
- for (Set<String>::Element *F = valid_inheritors.front(); F; F = F->next()) {
- const String &t = F->get();
-
- bool is_custom_resource = false;
- Ref<Texture2D> icon;
- if (!custom_resources.empty()) {
- for (int j = 0; j < custom_resources.size(); j++) {
- if (custom_resources[j].name == t) {
- is_custom_resource = true;
- if (custom_resources[j].icon.is_valid()) {
- icon = custom_resources[j].icon;
- }
- break;
- }
- }
- }
-
- if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) {
- continue;
- }
-
- inheritors_array.push_back(t);
-
- if (!icon.is_valid()) {
- icon = get_theme_icon(has_theme_icon(t, "EditorIcons") ? t : "Object", "EditorIcons");
- }
-
- int id = TYPE_BASE_ID + idx;
- menu->add_icon_item(icon, vformat(TTR("New %s"), t), id);
-
- idx++;
- }
- }
-
- if (menu->get_item_count()) {
- menu->add_separator();
- }
- }
-
- menu->add_icon_item(get_theme_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD);
-
- if (!res.is_null()) {
- menu->add_icon_item(get_theme_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT);
- menu->add_icon_item(get_theme_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR);
- menu->add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
- menu->add_icon_item(get_theme_icon("Save", "EditorIcons"), TTR("Save"), OBJ_MENU_SAVE);
- RES r = res;
- if (r.is_valid() && r->get_path().is_resource_file()) {
- menu->add_separator();
- menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
- }
- }
-
- RES cb = EditorSettings::get_singleton()->get_resource_clipboard();
- bool paste_valid = false;
- if (cb.is_valid()) {
- if (base_type == "") {
- paste_valid = true;
- } else {
- for (int i = 0; i < base_type.get_slice_count(","); i++) {
- if (ClassDB::is_parent_class(cb->get_class(), base_type.get_slice(",", i))) {
- paste_valid = true;
- break;
- }
- }
+ if (r && !r->is_local_to_scene()) {
+ EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on this resource because it's not set as local to scene.\nPlease switch on the 'local to scene' property on it (and all resources containing it up to a node)."));
+ emit_changed(get_edited_property(), RES());
+ update_property();
+ return;
}
}
- if (!res.is_null() || paste_valid) {
- menu->add_separator();
+ emit_changed(get_edited_property(), p_resource);
+ update_property();
- if (!res.is_null()) {
- menu->add_item(TTR("Copy"), OBJ_MENU_COPY);
- }
+ // Automatically suggest setting up the path for a ViewportTexture.
+ if (vpt.is_valid() && vpt->get_viewport_path_in_scene().is_empty()) {
+ if (!scene_tree) {
+ scene_tree = memnew(SceneTreeDialog);
+ scene_tree->set_title(TTR("Pick a Viewport"));
- if (paste_valid) {
- menu->add_item(TTR("Paste"), OBJ_MENU_PASTE);
- }
- }
+ Vector<StringName> valid_types;
+ valid_types.push_back("Viewport");
+ scene_tree->get_scene_tree()->set_valid_types(valid_types);
+ scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
- if (!res.is_null()) {
- Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(res);
- if (conversions.size()) {
- menu->add_separator();
+ add_child(scene_tree);
+ scene_tree->connect("selected", callable_mp(this, &EditorPropertyResource::_viewport_selected));
}
- for (int i = 0; i < conversions.size(); i++) {
- String what = conversions[i]->converts_to();
- Ref<Texture2D> icon;
- if (has_theme_icon(what, "EditorIcons")) {
- icon = get_theme_icon(what, "EditorIcons");
- } else {
- icon = get_theme_icon(what, "Resource");
- }
- menu->add_icon_item(icon, vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i);
- }
+ scene_tree->popup_scenetree_dialog();
}
}
-void EditorPropertyResource::_update_menu() {
- _update_menu_items();
-
- Rect2 gt = edit->get_screen_rect();
- menu->set_as_minsize();
- int ms = menu->get_contents_minimum_size().width;
- Vector2 popup_pos = gt.position + gt.size - Vector2(ms, 0);
- menu->set_position(popup_pos);
- menu->popup();
-}
-
void EditorPropertyResource::_sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool) {
emit_signal("property_keyed_with_value", String(get_edited_property()) + ":" + p_property, p_value, false);
}
@@ -2703,24 +2485,11 @@ void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) {
emit_signal("object_id_selected", get_edited_property(), p_id);
}
-void EditorPropertyResource::_button_input(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_valid()) {
- if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
- _update_menu_items();
- Vector2 pos = get_screen_position() + mb->get_position();
- //pos = assign->get_global_transform().xform(pos);
- menu->set_as_minsize();
- menu->set_position(pos);
- menu->popup();
- }
- }
-}
-
void EditorPropertyResource::_open_editor_pressed() {
RES res = get_edited_object()->get(get_edited_property());
if (res.is_valid()) {
- EditorNode::get_singleton()->call_deferred("edit_item_resource", res); //may clear the editor so do it deferred
+ // May clear the editor so do it deferred.
+ EditorNode::get_singleton()->call_deferred("edit_item_resource", res);
}
}
@@ -2730,39 +2499,123 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) {
}
RES res = get_edited_object()->get(get_edited_property());
-
if (!res.is_valid()) {
return;
}
+
bool use_editor = false;
for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
if (ep->handles(res.ptr())) {
use_editor = true;
+ break;
}
}
-
if (!use_editor) {
return;
}
- bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
opened_editor = false;
+ bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
if (unfolded) {
- //refold
- assign->set_pressed(false);
+ // Refold.
+ resource_picker->set_toggle_pressed(false);
get_edited_object()->editor_set_section_unfold(get_edited_property(), false);
update_property();
}
}
+void EditorPropertyResource::_update_property_bg() {
+ if (!is_inside_tree()) {
+ return;
+ }
+
+ updating_theme = true;
+
+ if (sub_inspector != nullptr) {
+ int count_subinspectors = 0;
+ Node *n = get_parent();
+ while (n) {
+ EditorInspector *ei = Object::cast_to<EditorInspector>(n);
+ if (ei && ei->is_sub_inspector()) {
+ count_subinspectors++;
+ }
+ n = n->get_parent();
+ }
+ count_subinspectors = MIN(15, count_subinspectors);
+
+ add_theme_color_override("property_color", get_theme_color("sub_inspector_property_color", "Editor"));
+ add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg_selected" + itos(count_subinspectors), "Editor"));
+ add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), "Editor"));
+
+ add_theme_constant_override("font_offset", get_theme_constant("sub_inspector_font_offset", "Editor"));
+ add_theme_constant_override("vseparation", 0);
+ } else {
+ add_theme_color_override("property_color", get_theme_color("property_color", "EditorProperty"));
+ add_theme_style_override("bg_selected", get_theme_stylebox("bg_selected", "EditorProperty"));
+ add_theme_style_override("bg", get_theme_stylebox("bg", "EditorProperty"));
+ add_theme_constant_override("vseparation", get_theme_constant("vseparation", "EditorProperty"));
+ add_theme_constant_override("font_offset", get_theme_constant("font_offset", "EditorProperty"));
+ }
+
+ updating_theme = false;
+ update();
+}
+
+void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
+ Node *to_node = get_node(p_path);
+ if (!Object::cast_to<Viewport>(to_node)) {
+ EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
+ return;
+ }
+
+ Ref<ViewportTexture> vt;
+ vt.instantiate();
+ vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
+ vt->setup_local_to_scene();
+
+ emit_changed(get_edited_property(), vt);
+ update_property();
+}
+
+void EditorPropertyResource::setup(Object *p_object, const String &p_path, const String &p_base_type) {
+ if (resource_picker) {
+ resource_picker->disconnect("resource_selected", callable_mp(this, &EditorPropertyResource::_resource_selected));
+ resource_picker->disconnect("resource_changed", callable_mp(this, &EditorPropertyResource::_resource_changed));
+ memdelete(resource_picker);
+ }
+
+ if (p_path == "script" && p_base_type == "Script" && Object::cast_to<Node>(p_object)) {
+ EditorScriptPicker *script_picker = memnew(EditorScriptPicker);
+ script_picker->set_script_owner(Object::cast_to<Node>(p_object));
+ resource_picker = script_picker;
+ } else {
+ resource_picker = memnew(EditorResourcePicker);
+ }
+
+ resource_picker->set_base_type(p_base_type);
+ resource_picker->set_editable(true);
+ resource_picker->set_h_size_flags(SIZE_EXPAND_FILL);
+ add_child(resource_picker);
+
+ resource_picker->connect("resource_selected", callable_mp(this, &EditorPropertyResource::_resource_selected));
+ resource_picker->connect("resource_changed", callable_mp(this, &EditorPropertyResource::_resource_changed));
+
+ for (int i = 0; i < resource_picker->get_child_count(); i++) {
+ Button *b = Object::cast_to<Button>(resource_picker->get_child(i));
+ if (b) {
+ add_focusable(b);
+ }
+ }
+}
+
void EditorPropertyResource::update_property() {
RES res = get_edited_object()->get(get_edited_property());
if (use_sub_inspector) {
- if (res.is_valid() != assign->is_toggle_mode()) {
- assign->set_toggle_mode(res.is_valid());
+ if (res.is_valid() != resource_picker->is_toggle_mode()) {
+ resource_picker->set_toggle_mode(res.is_valid());
}
if (res.is_valid() && get_edited_object()->editor_is_section_unfolded(get_edited_property())) {
@@ -2772,7 +2625,7 @@ void EditorPropertyResource::update_property() {
sub_inspector->set_use_doc_hints(true);
sub_inspector->set_sub_inspector(true);
- sub_inspector->set_enable_capitalize_paths(true);
+ sub_inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties")));
sub_inspector->connect("property_keyed", callable_mp(this, &EditorPropertyResource::_sub_inspector_property_keyed));
sub_inspector->connect("resource_selected", callable_mp(this, &EditorPropertyResource::_sub_inspector_resource_selected));
@@ -2787,7 +2640,7 @@ void EditorPropertyResource::update_property() {
set_bottom_editor(sub_inspector_vbox);
sub_inspector_vbox->add_child(sub_inspector);
- assign->set_pressed(true);
+ resource_picker->set_toggle_pressed(true);
bool use_editor = false;
for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
@@ -2798,118 +2651,39 @@ void EditorPropertyResource::update_property() {
}
if (use_editor) {
- //open editor directly and hide other open of these
+ // Open editor directly and hide other such editors which are currently open.
_open_editor_pressed();
if (is_inside_tree()) {
get_tree()->call_deferred("call_group", "_editor_resource_properties", "_fold_other_editors", this);
}
opened_editor = true;
}
+
+ _update_property_bg();
}
if (res.ptr() != sub_inspector->get_edited_object()) {
sub_inspector->edit(res.ptr());
}
- sub_inspector->refresh();
} else {
if (sub_inspector) {
set_bottom_editor(nullptr);
memdelete(sub_inspector_vbox);
sub_inspector = nullptr;
sub_inspector_vbox = nullptr;
+
if (opened_editor) {
EditorNode::get_singleton()->hide_top_editors();
opened_editor = false;
}
- }
- }
- }
-
- preview->set_texture(Ref<Texture2D>());
- if (res == RES()) {
- assign->set_icon(Ref<Texture2D>());
- assign->set_text(TTR("[empty]"));
- } else {
- assign->set_icon(EditorNode::get_singleton()->get_object_icon(res.operator->(), "Object"));
-
- if (res->get_name() != String()) {
- assign->set_text(res->get_name());
- } else if (res->get_path().is_resource_file()) {
- assign->set_text(res->get_path().get_file());
- assign->set_tooltip(res->get_path());
- } else {
- assign->set_text(res->get_class());
- }
-
- if (res->get_path().is_resource_file()) {
- assign->set_tooltip(res->get_path());
- }
-
- //preview will override the above, so called at the end
- EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_resource_preview", res->get_instance_id());
- }
-}
-
-void EditorPropertyResource::_resource_selected() {
- RES res = get_edited_object()->get(get_edited_property());
- if (res.is_null()) {
- edit->set_pressed(true);
- _update_menu();
- return;
- }
-
- if (use_sub_inspector) {
- bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
- get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
- update_property();
- } else {
- emit_signal("resource_selected", get_edited_property(), res);
- }
-}
-
-void EditorPropertyResource::setup(const String &p_base_type) {
- base_type = p_base_type;
-}
-
-void EditorPropertyResource::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- Ref<Texture2D> t = get_theme_icon("select_arrow", "Tree");
- edit->set_icon(t);
- }
-
- if (p_what == NOTIFICATION_DRAG_BEGIN) {
- if (is_visible_in_tree()) {
- if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
- dropping = true;
- assign->update();
+ _update_property_bg();
}
}
}
- if (p_what == NOTIFICATION_DRAG_END) {
- if (dropping) {
- dropping = false;
- assign->update();
- }
- }
-}
-
-void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
- Node *to_node = get_node(p_path);
- if (!Object::cast_to<Viewport>(to_node)) {
- EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
- return;
- }
-
- Ref<ViewportTexture> vt;
- vt.instance();
- vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
- vt->setup_local_to_scene();
-
- emit_changed(get_edited_property(), vt);
- update_property();
+ resource_picker->set_edited_resource(res);
}
void EditorPropertyResource::collapse_all_folding() {
@@ -2924,145 +2698,29 @@ void EditorPropertyResource::expand_all_folding() {
}
}
-void EditorPropertyResource::_button_draw() {
- if (dropping) {
- Color color = get_theme_color("accent_color", "Editor");
- assign->draw_rect(Rect2(Point2(), assign->get_size()), color, false);
- }
-}
-
-Variant EditorPropertyResource::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
- RES res = get_edited_object()->get(get_edited_property());
- if (res.is_valid()) {
- return EditorNode::get_singleton()->drag_resource(res, p_from);
- }
-
- return Variant();
-}
-
-bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const {
- String allowed_type = base_type;
-
- Dictionary drag_data = p_drag_data;
- if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
- Ref<Resource> res = drag_data["resource"];
- for (int i = 0; i < allowed_type.get_slice_count(","); i++) {
- String at = allowed_type.get_slice(",", i).strip_edges();
- if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) {
- return true;
- }
- }
- }
-
- if (drag_data.has("type") && String(drag_data["type"]) == "files") {
- Vector<String> files = drag_data["files"];
-
- if (files.size() == 1) {
- String file = files[0];
- String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
-
- if (ftype != "") {
- for (int i = 0; i < allowed_type.get_slice_count(","); i++) {
- String at = allowed_type.get_slice(",", i).strip_edges();
- if (ClassDB::is_parent_class(ftype, at)) {
- return true;
- }
- }
- }
- }
- }
-
- return false;
-}
-
-bool EditorPropertyResource::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
- return _is_drop_valid(p_data);
+void EditorPropertyResource::set_use_sub_inspector(bool p_enable) {
+ use_sub_inspector = p_enable;
}
-void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- ERR_FAIL_COND(!_is_drop_valid(p_data));
-
- Dictionary drag_data = p_data;
- if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
- Ref<Resource> res = drag_data["resource"];
- if (res.is_valid()) {
- emit_changed(get_edited_property(), res);
- update_property();
- return;
- }
- }
-
- if (drag_data.has("type") && String(drag_data["type"]) == "files") {
- Vector<String> files = drag_data["files"];
-
- if (files.size() == 1) {
- String file = files[0];
- RES res = ResourceLoader::load(file);
- if (res.is_valid()) {
- emit_changed(get_edited_property(), res);
- update_property();
- return;
+void EditorPropertyResource::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ if (!updating_theme) {
+ _update_property_bg();
}
- }
+ } break;
}
}
-void EditorPropertyResource::set_use_sub_inspector(bool p_enable) {
- use_sub_inspector = p_enable;
-}
-
void EditorPropertyResource::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_resource_preview"), &EditorPropertyResource::_resource_preview);
- ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &EditorPropertyResource::get_drag_data_fw);
- ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &EditorPropertyResource::can_drop_data_fw);
- ClassDB::bind_method(D_METHOD("drop_data_fw"), &EditorPropertyResource::drop_data_fw);
ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed);
ClassDB::bind_method(D_METHOD("_fold_other_editors"), &EditorPropertyResource::_fold_other_editors);
}
EditorPropertyResource::EditorPropertyResource() {
- opened_editor = false;
- sub_inspector = nullptr;
- sub_inspector_vbox = nullptr;
use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"));
- HBoxContainer *hbc = memnew(HBoxContainer);
- add_child(hbc);
- assign = memnew(Button);
- assign->set_flat(true);
- assign->set_h_size_flags(SIZE_EXPAND_FILL);
- assign->set_clip_text(true);
- assign->connect("pressed", callable_mp(this, &EditorPropertyResource::_resource_selected));
- assign->set_drag_forwarding(this);
- assign->connect("draw", callable_mp(this, &EditorPropertyResource::_button_draw));
- hbc->add_child(assign);
- add_focusable(assign);
-
- preview = memnew(TextureRect);
- preview->set_expand(true);
- preview->set_anchors_and_margins_preset(PRESET_WIDE);
- preview->set_margin(MARGIN_TOP, 1);
- preview->set_margin(MARGIN_BOTTOM, -1);
- preview->set_margin(MARGIN_RIGHT, -1);
- assign->add_child(preview);
- assign->connect("gui_input", callable_mp(this, &EditorPropertyResource::_button_input));
-
- menu = memnew(PopupMenu);
- add_child(menu);
- edit = memnew(Button);
- edit->set_flat(true);
- edit->set_toggle_mode(true);
- menu->connect("id_pressed", callable_mp(this, &EditorPropertyResource::_menu_option));
- menu->connect("popup_hide", callable_mp((BaseButton *)edit, &BaseButton::set_pressed), varray(false));
- edit->connect("pressed", callable_mp(this, &EditorPropertyResource::_update_menu));
- hbc->add_child(edit);
- edit->connect("gui_input", callable_mp(this, &EditorPropertyResource::_button_input));
- add_focusable(edit);
-
- file = nullptr;
- scene_tree = nullptr;
- dropping = false;
-
add_to_group("_editor_resource_properties");
}
@@ -3076,33 +2734,104 @@ void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) {
//do none
}
-bool EditorInspectorDefaultPlugin::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) {
- float default_float_step = EDITOR_GET("interface/inspector/default_float_step");
+bool EditorInspectorDefaultPlugin::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) {
+ Control *editor = EditorInspectorDefaultPlugin::get_editor_for_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
+ if (editor) {
+ add_property_editor(p_path, editor);
+ }
+ return false;
+}
+
+void EditorInspectorDefaultPlugin::parse_end() {
+ //do none
+}
+
+struct EditorPropertyRangeHint {
+ bool angle_in_degrees = false;
+ bool greater = true;
+ bool lesser = true;
+ double min = -99999;
+ double max = 99999;
+ double step = 0;
+ String suffix;
+ bool exp_range = false;
+ bool hide_slider = true;
+ bool radians = false;
+};
+
+static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const String &p_hint_text, double p_default_step) {
+ EditorPropertyRangeHint hint;
+ hint.step = p_default_step;
+ bool degrees = false;
+ if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
+ hint.greater = false; //if using ranged, assume false by default
+ hint.lesser = false;
+
+ hint.min = p_hint_text.get_slice(",", 0).to_float();
+ hint.max = p_hint_text.get_slice(",", 1).to_float();
+ if (p_hint_text.get_slice_count(",") >= 3) {
+ hint.step = p_hint_text.get_slice(",", 2).to_float();
+ }
+ hint.hide_slider = false;
+ for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
+ String slice = p_hint_text.get_slice(",", i).strip_edges();
+ if (slice == "radians") {
+ hint.radians = true;
+ } else if (slice == "degrees") {
+ degrees = true;
+ } else if (slice == "or_greater") {
+ hint.greater = true;
+ } else if (slice == "or_lesser") {
+ hint.lesser = true;
+ } else if (slice == "noslider") {
+ hint.hide_slider = true;
+ } else if (slice == "exp") {
+ hint.exp_range = true;
+ } else if (slice.begins_with("suffix:")) {
+ hint.suffix = " " + slice.replace_first("suffix:", "").strip_edges();
+ }
+ }
+ }
+
+ if ((hint.radians || degrees) && hint.suffix == String()) {
+ hint.suffix = U"\u00B0";
+ }
+
+ return hint;
+}
+
+EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_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) {
+ double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
switch (p_type) {
// atomic types
case Variant::NIL: {
EditorPropertyNil *editor = memnew(EditorPropertyNil);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::BOOL: {
EditorPropertyCheck *editor = memnew(EditorPropertyCheck);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::INT: {
if (p_hint == PROPERTY_HINT_ENUM) {
EditorPropertyEnum *editor = memnew(EditorPropertyEnum);
Vector<String> options = p_hint_text.split(",");
editor->setup(options);
- add_property_editor(p_path, editor);
+ return editor;
} else if (p_hint == PROPERTY_HINT_FLAGS) {
EditorPropertyFlags *editor = memnew(EditorPropertyFlags);
Vector<String> options = p_hint_text.split(",");
editor->setup(options);
- add_property_editor(p_path, editor);
-
- } else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_2D_RENDER || p_hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_3D_RENDER) {
+ return editor;
+
+ } else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS ||
+ p_hint == PROPERTY_HINT_LAYERS_2D_RENDER ||
+ p_hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION ||
+ p_hint == PROPERTY_HINT_LAYERS_3D_PHYSICS ||
+ p_hint == PROPERTY_HINT_LAYERS_3D_RENDER ||
+ p_hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) {
EditorPropertyLayers::LayerType lt = EditorPropertyLayers::LAYER_RENDER_2D;
switch (p_hint) {
case PROPERTY_HINT_LAYERS_2D_RENDER:
@@ -3111,52 +2840,37 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case PROPERTY_HINT_LAYERS_2D_PHYSICS:
lt = EditorPropertyLayers::LAYER_PHYSICS_2D;
break;
+ case PROPERTY_HINT_LAYERS_2D_NAVIGATION:
+ lt = EditorPropertyLayers::LAYER_NAVIGATION_2D;
+ break;
case PROPERTY_HINT_LAYERS_3D_RENDER:
lt = EditorPropertyLayers::LAYER_RENDER_3D;
break;
case PROPERTY_HINT_LAYERS_3D_PHYSICS:
lt = EditorPropertyLayers::LAYER_PHYSICS_3D;
break;
+ case PROPERTY_HINT_LAYERS_3D_NAVIGATION:
+ lt = EditorPropertyLayers::LAYER_NAVIGATION_3D;
+ break;
default: {
} //compiler could be smarter here and realize this can't happen
}
EditorPropertyLayers *editor = memnew(EditorPropertyLayers);
editor->setup(lt);
- add_property_editor(p_path, editor);
+ return editor;
} else if (p_hint == PROPERTY_HINT_OBJECT_ID) {
EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID);
editor->setup(p_hint_text);
- add_property_editor(p_path, editor);
+ return editor;
} else {
EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
- int min = 0, max = 65535, step = 1;
- bool greater = true, lesser = true;
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- greater = false; //if using ranged, assume false by default
- lesser = false;
- min = p_hint_text.get_slice(",", 0).to_int();
- max = p_hint_text.get_slice(",", 1).to_int();
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_int();
- }
+ editor->setup(hint.min, hint.max, hint.step, hint.greater, hint.lesser);
- for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
- String slice = p_hint_text.get_slice(",", i).strip_edges();
- if (slice == "or_greater") {
- greater = true;
- }
- if (slice == "or_lesser") {
- lesser = true;
- }
- }
- }
-
- editor->setup(min, max, step, greater, lesser);
-
- add_property_editor(p_path, editor);
+ return editor;
}
} break;
case Variant::FLOAT: {
@@ -3176,39 +2890,15 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(full, flip);
- add_property_editor(p_path, editor);
+ return editor;
} else {
EditorPropertyFloat *editor = memnew(EditorPropertyFloat);
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
- bool exp_range = false;
- bool greater = true, lesser = true;
-
- if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && p_hint_text.get_slice_count(",") >= 2) {
- greater = false; //if using ranged, assume false by default
- lesser = false;
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- exp_range = p_hint == PROPERTY_HINT_EXP_RANGE;
- for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
- String slice = p_hint_text.get_slice(",", i).strip_edges();
- if (slice == "or_greater") {
- greater = true;
- }
- if (slice == "or_lesser") {
- lesser = true;
- }
- }
- }
- editor->setup(min, max, step, hide_slider, exp_range, greater, lesser);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.exp_range, hint.greater, hint.lesser, hint.suffix, hint.radians);
- add_property_editor(p_path, editor);
+ return editor;
}
} break;
case Variant::STRING: {
@@ -3216,14 +2906,14 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
Vector<String> options = p_hint_text.split(",");
editor->setup(options);
- add_property_editor(p_path, editor);
+ return editor;
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
- add_property_editor(p_path, editor);
+ return editor;
} else if (p_hint == PROPERTY_HINT_TYPE_STRING) {
EditorPropertyClassName *editor = memnew(EditorPropertyClassName);
editor->setup("Object", p_hint_text);
- add_property_editor(p_path, editor);
+ return editor;
} else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) {
Vector<String> extensions = p_hint_text.split(",");
bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE;
@@ -3234,7 +2924,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
if (save) {
editor->set_save_mode();
}
- add_property_editor(p_path, editor);
+ return editor;
} else if (p_hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE ||
p_hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE ||
p_hint == PROPERTY_HINT_METHOD_OF_INSTANCE ||
@@ -3272,14 +2962,14 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
}
editor->setup(type, p_hint_text);
- add_property_editor(p_path, editor);
+ return editor;
} else {
EditorPropertyText *editor = memnew(EditorPropertyText);
if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
editor->set_placeholder(p_hint_text);
}
- add_property_editor(p_path, editor);
+ return editor;
}
} break;
@@ -3287,204 +2977,82 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case Variant::VECTOR2: {
EditorPropertyVector2 *editor = memnew(EditorPropertyVector2(p_wide));
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::VECTOR2I: {
EditorPropertyVector2i *editor = memnew(EditorPropertyVector2i(p_wide));
- int min = -65535, max = 65535;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- hide_slider = false;
- }
-
- editor->setup(min, max, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
+ editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::RECT2: {
EditorPropertyRect2 *editor = memnew(EditorPropertyRect2(p_wide));
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::RECT2I: {
EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i(p_wide));
- int min = -65535, max = 65535;
- bool hide_slider = true;
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
+ editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix);
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- hide_slider = false;
- }
-
- editor->setup(min, max, hide_slider);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::VECTOR3: {
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3(p_wide));
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix, hint.radians);
+ return editor;
} break;
case Variant::VECTOR3I: {
EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i(p_wide));
- int min = -65535, max = 65535;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
-
- hide_slider = false;
- }
-
- editor->setup(min, max, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
+ editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::TRANSFORM2D: {
EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::PLANE: {
EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide));
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
- case Variant::QUAT: {
- EditorPropertyQuat *editor = memnew(EditorPropertyQuat);
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ case Variant::QUATERNION: {
+ EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::AABB: {
EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
case Variant::BASIS: {
EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
- case Variant::TRANSFORM: {
- EditorPropertyTransform *editor = memnew(EditorPropertyTransform);
- double min = -65535, max = 65535, step = default_float_step;
- bool hide_slider = true;
-
- if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
- min = p_hint_text.get_slice(",", 0).to_double();
- max = p_hint_text.get_slice(",", 1).to_double();
- if (p_hint_text.get_slice_count(",") >= 3) {
- step = p_hint_text.get_slice(",", 2).to_double();
- }
- hide_slider = false;
- }
-
- editor->setup(min, max, step, hide_slider);
- add_property_editor(p_path, editor);
+ case Variant::TRANSFORM3D: {
+ EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D);
+ EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
+ editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
+ return editor;
} break;
@@ -3492,21 +3060,21 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case Variant::COLOR: {
EditorPropertyColor *editor = memnew(EditorPropertyColor);
editor->setup(p_hint != PROPERTY_HINT_COLOR_NO_ALPHA);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::STRING_NAME: {
if (p_hint == PROPERTY_HINT_ENUM) {
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
Vector<String> options = p_hint_text.split(",");
editor->setup(options, true);
- add_property_editor(p_path, editor);
+ return editor;
} else {
EditorPropertyText *editor = memnew(EditorPropertyText);
if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
editor->set_placeholder(p_hint_text);
}
editor->set_string_name(true);
- add_property_editor(p_path, editor);
+ return editor;
}
} break;
case Variant::NODE_PATH: {
@@ -3519,16 +3087,16 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
Vector<StringName> sn = Variant(types); //convert via variant
editor->setup(NodePath(), sn, (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT));
}
- add_property_editor(p_path, editor);
+ return editor;
} break;
- case Variant::_RID: {
+ case Variant::RID: {
EditorPropertyRID *editor = memnew(EditorPropertyRID);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::OBJECT: {
EditorPropertyResource *editor = memnew(EditorPropertyResource);
- editor->setup(p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
+ editor->setup(p_object, p_path, p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
String open_in_new = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector");
@@ -3543,70 +3111,66 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
}
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::DICTIONARY: {
EditorPropertyDictionary *editor = memnew(EditorPropertyDictionary);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::ARRAY, p_hint_text);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_BYTE_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_BYTE_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_INT32_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_INT32_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_INT64_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_INT64_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_FLOAT32_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_FLOAT64_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_STRING_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_STRING_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_VECTOR2_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_VECTOR3_ARRAY);
- add_property_editor(p_path, editor);
+ return editor;
} break;
case Variant::PACKED_COLOR_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_COLOR_ARRAY);
- add_property_editor(p_path, editor);
+
} break;
default: {
}
}
- return false; //can be overridden, although it will most likely be last anyway
-}
-
-void EditorInspectorDefaultPlugin::parse_end() {
- //do none
+ return nullptr;
}