diff options
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r-- | editor/editor_properties.cpp | 645 |
1 files changed, 445 insertions, 200 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 1f3ff1b332..81c4e48974 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -51,8 +51,9 @@ EditorPropertyNil::EditorPropertyNil() { ///////////////////// TEXT ///////////////////////// void EditorPropertyText::_text_entered(const String &p_string) { - if (updating) + if (updating) { return; + } if (text->has_focus()) { text->release_focus(); @@ -61,8 +62,9 @@ void EditorPropertyText::_text_entered(const String &p_string) { } void EditorPropertyText::_text_changed(const String &p_string) { - if (updating) + if (updating) { return; + } if (string_name) { emit_changed(get_edited_property(), StringName(p_string), "", true); @@ -82,6 +84,7 @@ void EditorPropertyText::update_property() { void EditorPropertyText::set_string_name(bool p_enabled) { string_name = p_enabled; } + void EditorPropertyText::set_placeholder(const String &p_string) { text->set_placeholder(p_string); } @@ -112,7 +115,6 @@ void EditorPropertyMultilineText::_text_changed() { } void EditorPropertyMultilineText::_open_big_text() { - if (!big_text_dialog) { big_text = memnew(TextEdit); big_text->connect("text_changed", callable_mp(this, &EditorPropertyMultilineText::_big_text_changed)); @@ -172,9 +174,7 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() { ///////////////////// TEXT ENUM ///////////////////////// void EditorPropertyTextEnum::_option_selected(int p_which) { - if (string_name) { - emit_changed(get_edited_property(), StringName(options->get_item_text(p_which))); } else { emit_changed(get_edited_property(), options->get_item_text(p_which)); @@ -182,7 +182,6 @@ void EditorPropertyTextEnum::_option_selected(int p_which) { } void EditorPropertyTextEnum::update_property() { - String which = get_edited_object()->get(get_edited_property()); for (int i = 0; i < options->get_item_count(); i++) { String t = options->get_item_text(i); @@ -213,15 +212,15 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() { add_focusable(options); options->connect("item_selected", callable_mp(this, &EditorPropertyTextEnum::_option_selected)); } + ///////////////////// PATH ///////////////////////// void EditorPropertyPath::_path_selected(const String &p_path) { - emit_changed(get_edited_property(), p_path); update_property(); } -void EditorPropertyPath::_path_pressed() { +void EditorPropertyPath::_path_pressed() { if (!dialog) { dialog = memnew(EditorFileDialog); dialog->connect("file_selected", callable_mp(this, &EditorPropertyPath::_path_selected)); @@ -257,33 +256,28 @@ void EditorPropertyPath::_path_pressed() { } void EditorPropertyPath::update_property() { - String full_path = get_edited_object()->get(get_edited_property()); path->set_text(full_path); path->set_tooltip(full_path); } void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder, bool p_global) { - extensions = p_extensions; folder = p_folder; global = p_global; } void EditorPropertyPath::set_save_mode() { - save_mode = true; } void EditorPropertyPath::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { path_edit->set_icon(get_theme_icon("Folder", "EditorIcons")); } } void EditorPropertyPath::_path_focus_exited() { - _path_selected(path->get_text()); } @@ -313,7 +307,6 @@ EditorPropertyPath::EditorPropertyPath() { ///////////////////// CLASS NAME ///////////////////////// void EditorPropertyClassName::setup(const String &p_base_type, const String &p_selected_type) { - base_type = p_base_type; dialog->set_base_type(base_type); selected_type = p_selected_type; @@ -321,7 +314,6 @@ void EditorPropertyClassName::setup(const String &p_base_type, const String &p_s } void EditorPropertyClassName::update_property() { - String s = get_edited_object()->get(get_edited_property()); property->set_text(s); selected_type = s; @@ -356,13 +348,11 @@ EditorPropertyClassName::EditorPropertyClassName() { ///////////////////// MEMBER ///////////////////////// void EditorPropertyMember::_property_selected(const String &p_selected) { - emit_changed(get_edited_property(), p_selected); update_property(); } void EditorPropertyMember::_property_select() { - if (!selector) { selector = memnew(PropertySelector); selector->connect("selected", callable_mp(this, &EditorPropertyMember::_property_selected)); @@ -372,60 +362,57 @@ void EditorPropertyMember::_property_select() { String current = get_edited_object()->get(get_edited_property()); if (hint == MEMBER_METHOD_OF_VARIANT_TYPE) { - Variant::Type type = Variant::NIL; for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (hint_text == Variant::get_type_name(Variant::Type(i))) { type = Variant::Type(i); } } - if (type != Variant::NIL) + if (type != Variant::NIL) { selector->select_method_from_basic_type(type, current); + } } else if (hint == MEMBER_METHOD_OF_BASE_TYPE) { - 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())); - if (instance) + 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())); if (Object::cast_to<Script>(obj)) { selector->select_method_from_script(Object::cast_to<Script>(obj), current); } } else if (hint == MEMBER_PROPERTY_OF_VARIANT_TYPE) { - Variant::Type type = Variant::NIL; String tname = hint_text; - if (tname.find(".") != -1) + if (tname.find(".") != -1) { tname = tname.get_slice(".", 0); + } for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (tname == Variant::get_type_name(Variant::Type(i))) { type = Variant::Type(Variant::Type(i)); } } - if (type != Variant::NIL) + if (type != Variant::NIL) { selector->select_property_from_basic_type(type, current); + } } else if (hint == MEMBER_PROPERTY_OF_BASE_TYPE) { - 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())); - if (instance) + 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())); if (Object::cast_to<Script>(obj)) { selector->select_property_from_script(Object::cast_to<Script>(obj), current); @@ -439,7 +426,6 @@ void EditorPropertyMember::setup(Type p_hint, const String &p_hint_text) { } void EditorPropertyMember::update_property() { - String full_path = get_edited_object()->get(get_edited_property()); property->set_text(full_path); } @@ -458,7 +444,6 @@ EditorPropertyMember::EditorPropertyMember() { ///////////////////// CHECK ///////////////////////// void EditorPropertyCheck::_checkbox_pressed() { - emit_changed(get_edited_property(), checkbox->is_pressed()); } @@ -482,13 +467,11 @@ EditorPropertyCheck::EditorPropertyCheck() { ///////////////////// ENUM ///////////////////////// void EditorPropertyEnum::_option_selected(int p_which) { - int64_t val = options->get_item_metadata(p_which); emit_changed(get_edited_property(), val); } void EditorPropertyEnum::update_property() { - int64_t which = get_edited_object()->get(get_edited_property()); for (int i = 0; i < options->get_item_count(); i++) { @@ -500,12 +483,12 @@ void EditorPropertyEnum::update_property() { } void EditorPropertyEnum::setup(const Vector<String> &p_options) { - 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) + if (text_split.size() != 1) { current_val = text_split[1].to_int64(); + } options->add_item(text_split[0]); options->set_item_metadata(i, current_val); current_val += 1; @@ -531,7 +514,6 @@ EditorPropertyEnum::EditorPropertyEnum() { ///////////////////// FLAGS ///////////////////////// void EditorPropertyFlags::_flag_toggled() { - uint32_t value = 0; for (int i = 0; i < flags.size(); i++) { if (flags[i]->is_pressed()) { @@ -545,14 +527,12 @@ void EditorPropertyFlags::_flag_toggled() { } void EditorPropertyFlags::update_property() { - uint32_t value = get_edited_object()->get(get_edited_property()); for (int i = 0; i < flags.size(); i++) { uint32_t val = 1; val <<= flag_indices[i]; if (value & val) { - flags[i]->set_pressed(true); } else { flags[i]->set_pressed(false); @@ -587,7 +567,6 @@ void EditorPropertyFlags::_bind_methods() { } EditorPropertyFlags::EditorPropertyFlags() { - vbox = memnew(VBoxContainer); add_child(vbox); } @@ -636,7 +615,6 @@ public: void _notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Rect2 rect; rect.size = get_size(); flag_rects.clear(); @@ -648,17 +626,17 @@ public: Color color = get_theme_color("highlight_color", "Editor"); for (int i = 0; i < 2; i++) { - Point2 ofs(4, vofs); - if (i == 1) + if (i == 1) { ofs.y += bsize + 1; + } ofs += rect.position; for (int j = 0; j < 10; j++) { - Point2 o = ofs + Point2(j * (bsize + 1), 0); - if (j >= 5) + if (j >= 5) { o.x += 1; + } uint32_t idx = i * 10 + j; bool on = value & (1 << idx); @@ -677,7 +655,6 @@ public: } static void _bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &EditorPropertyLayersGrid::_gui_input); ADD_SIGNAL(MethodInfo("flag_changed", PropertyInfo(Variant::INT, "flag"))); } @@ -687,19 +664,16 @@ public: } }; void EditorPropertyLayers::_grid_changed(uint32_t p_grid) { - emit_changed(get_edited_property(), p_grid); } void EditorPropertyLayers::update_property() { - uint32_t value = get_edited_object()->get(get_edited_property()); grid->set_flag(value); } void EditorPropertyLayers::setup(LayerType p_layer_type) { - String basename; switch (p_layer_type) { case LAYER_RENDER_2D: @@ -738,7 +712,6 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) { } void EditorPropertyLayers::_button_pressed() { - layers->clear(); for (int i = 0; i < 20; i++) { if (i == 5 || i == 10 || i == 15) { @@ -771,7 +744,6 @@ void EditorPropertyLayers::_bind_methods() { } EditorPropertyLayers::EditorPropertyLayers() { - HBoxContainer *hb = memnew(HBoxContainer); add_child(hb); grid = memnew(EditorPropertyLayersGrid); @@ -794,8 +766,9 @@ EditorPropertyLayers::EditorPropertyLayers() { ///////////////////// INT ///////////////////////// void EditorPropertyInteger::_value_changed(int64_t val) { - if (setting) + if (setting) { return; + } emit_changed(get_edited_property(), val); } @@ -835,14 +808,14 @@ EditorPropertyInteger::EditorPropertyInteger() { ///////////////////// OBJECT ID ///////////////////////// void EditorPropertyObjectID::_edit_pressed() { - emit_signal("object_id_selected", get_edited_property(), get_edited_object()->get(get_edited_property())); } void EditorPropertyObjectID::update_property() { String type = base_type; - if (type == "") + if (type == "") { type = "Object"; + } ObjectID id = get_edited_object()->get(get_edited_property()); if (id.is_valid()) { @@ -873,8 +846,9 @@ EditorPropertyObjectID::EditorPropertyObjectID() { ///////////////////// FLOAT ///////////////////////// void EditorPropertyFloat::_value_changed(double val) { - if (setting) + if (setting) { return; + } emit_changed(get_edited_property(), val); } @@ -890,7 +864,6 @@ 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) { - spin->set_min(p_min); spin->set_max(p_max); spin->set_step(p_step); @@ -912,7 +885,6 @@ EditorPropertyFloat::EditorPropertyFloat() { ///////////////////// EASING ///////////////////////// 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) { @@ -938,17 +910,19 @@ 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) { - float rel = mm->get_relative().x; - if (rel == 0) + if (rel == 0) { return; + } - if (flip) + if (flip) { rel = -rel; + } float val = get_edited_object()->get(get_edited_property()); - if (val == 0) + if (val == 0) { return; + } bool sg = val < 0; val = Math::absf(val); @@ -957,8 +931,9 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { val += rel * 0.05; val = Math::pow(2.0f, val); - if (sg) + if (sg) { val = -val; + } emit_changed(get_edited_property(), val); easing_draw->update(); @@ -966,7 +941,6 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { } void EditorPropertyEasing::_draw_easing() { - RID ci = easing_draw->get_canvas_item(); Size2 s = easing_draw->get_size(); @@ -987,7 +961,6 @@ void EditorPropertyEasing::_draw_easing() { Vector<Point2> lines; for (int i = 1; i <= points; i++) { - float ifl = i / float(points); float iflp = (i - 1) / float(points); @@ -1027,8 +1000,9 @@ void EditorPropertyEasing::_setup_spin() { } void EditorPropertyEasing::_spin_value_changed(double p_value) { - if (setting) + if (setting) { return; + } // 0 is a singularity, but both positive and negative values // are otherwise allowed. Enforce 0+ as workaround. @@ -1047,13 +1021,11 @@ void EditorPropertyEasing::_spin_focus_exited() { } void EditorPropertyEasing::setup(bool p_full, bool p_flip) { - flip = p_flip; full = p_full; } void EditorPropertyEasing::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { @@ -1075,7 +1047,6 @@ void EditorPropertyEasing::_bind_methods() { } EditorPropertyEasing::EditorPropertyEasing() { - easing_draw = memnew(Control); easing_draw->connect("draw", callable_mp(this, &EditorPropertyEasing::_draw_easing)); easing_draw->connect("gui_input", callable_mp(this, &EditorPropertyEasing::_drag_easing)); @@ -1107,8 +1078,9 @@ EditorPropertyEasing::EditorPropertyEasing() { ///////////////////// VECTOR2 ///////////////////////// void EditorPropertyVector2::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Vector2 v2; v2.x = spin[0]->get_value(); @@ -1128,7 +1100,6 @@ void EditorPropertyVector2::_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 < 2; i++) { - Color c = base; c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); @@ -1150,12 +1121,15 @@ void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, boo } } -EditorPropertyVector2::EditorPropertyVector2() { +EditorPropertyVector2::EditorPropertyVector2(bool p_force_wide) { bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing"); BoxContainer *bc; - if (horizontal) { + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { bc = memnew(HBoxContainer); add_child(bc); set_bottom_editor(bc); @@ -1186,8 +1160,9 @@ EditorPropertyVector2::EditorPropertyVector2() { ///////////////////// RECT2 ///////////////////////// void EditorPropertyRect2::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Rect2 r2; r2.position.x = spin[0]->get_value(); @@ -1206,17 +1181,18 @@ void EditorPropertyRect2::update_property() { spin[3]->set_value(val.size.y); setting = false; } + void EditorPropertyRect2::_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 < 4; i++) { - Color c = base; c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyRect2::_bind_methods() { } @@ -1231,13 +1207,15 @@ void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool } } -EditorPropertyRect2::EditorPropertyRect2() { - - bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing"); +EditorPropertyRect2::EditorPropertyRect2(bool p_force_wide) { + bool horizontal = !p_force_wide && bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing")); BoxContainer *bc; - if (horizontal) { + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { bc = memnew(HBoxContainer); add_child(bc); set_bottom_editor(bc); @@ -1268,8 +1246,9 @@ EditorPropertyRect2::EditorPropertyRect2() { ///////////////////// VECTOR3 ///////////////////////// void EditorPropertyVector3::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Vector3 v3; v3.x = spin[0]->get_value(); @@ -1286,17 +1265,18 @@ void EditorPropertyVector3::update_property() { spin[2]->set_value(val.z); setting = false; } + 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"); for (int i = 0; i < 3; i++) { - Color c = base; c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyVector3::_bind_methods() { } @@ -1311,12 +1291,15 @@ void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, boo } } -EditorPropertyVector3::EditorPropertyVector3() { +EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) { bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing"); BoxContainer *bc; - if (horizontal) { + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { bc = memnew(HBoxContainer); add_child(bc); set_bottom_editor(bc); @@ -1343,11 +1326,264 @@ EditorPropertyVector3::EditorPropertyVector3() { } setting = false; } + +///////////////////// VECTOR2i ///////////////////////// + +void EditorPropertyVector2i::_value_changed(double val, const String &p_name) { + if (setting) { + return; + } + + Vector2i v2; + v2.x = spin[0]->get_value(); + v2.y = spin[1]->get_value(); + emit_changed(get_edited_property(), v2, p_name); +} + +void EditorPropertyVector2i::update_property() { + Vector2i val = get_edited_object()->get(get_edited_property()); + setting = true; + spin[0]->set_value(val.x); + spin[1]->set_value(val.y); + setting = false; +} + +void EditorPropertyVector2i::_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 < 2; i++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} + +void EditorPropertyVector2i::_bind_methods() { +} + +void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider) { + for (int i = 0; i < 2; i++) { + spin[i]->set_min(p_min); + spin[i]->set_max(p_max); + spin[i]->set_step(1); + spin[i]->set_hide_slider(p_no_slider); + spin[i]->set_allow_greater(true); + spin[i]->set_allow_lesser(true); + } +} + +EditorPropertyVector2i::EditorPropertyVector2i(bool p_force_wide) { + bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing"); + + BoxContainer *bc; + + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { + bc = memnew(HBoxContainer); + add_child(bc); + set_bottom_editor(bc); + } else { + bc = memnew(VBoxContainer); + add_child(bc); + } + + static const char *desc[2] = { "x", "y" }; + for (int i = 0; i < 2; i++) { + spin[i] = memnew(EditorSpinSlider); + spin[i]->set_flat(true); + spin[i]->set_label(desc[i]); + bc->add_child(spin[i]); + add_focusable(spin[i]); + spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector2i::_value_changed), varray(desc[i])); + if (horizontal) { + spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); + } + } + + if (!horizontal) { + set_label_reference(spin[0]); //show text and buttons around this + } + setting = false; +} + +///////////////////// RECT2 ///////////////////////// + +void EditorPropertyRect2i::_value_changed(double val, const String &p_name) { + if (setting) { + return; + } + + Rect2i r2; + r2.position.x = spin[0]->get_value(); + r2.position.y = spin[1]->get_value(); + r2.size.x = spin[2]->get_value(); + r2.size.y = spin[3]->get_value(); + emit_changed(get_edited_property(), r2, p_name); +} + +void EditorPropertyRect2i::update_property() { + Rect2i val = get_edited_object()->get(get_edited_property()); + setting = true; + spin[0]->set_value(val.position.x); + spin[1]->set_value(val.position.y); + spin[2]->set_value(val.size.x); + spin[3]->set_value(val.size.y); + setting = false; +} + +void EditorPropertyRect2i::_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 < 4; i++) { + Color c = base; + c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} + +void EditorPropertyRect2i::_bind_methods() { +} + +void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider) { + for (int i = 0; i < 4; i++) { + spin[i]->set_min(p_min); + spin[i]->set_max(p_max); + spin[i]->set_step(1); + spin[i]->set_hide_slider(p_no_slider); + spin[i]->set_allow_greater(true); + spin[i]->set_allow_lesser(true); + } +} + +EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) { + bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing"); + + BoxContainer *bc; + + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { + bc = memnew(HBoxContainer); + add_child(bc); + set_bottom_editor(bc); + } else { + bc = memnew(VBoxContainer); + add_child(bc); + } + + static const char *desc[4] = { "x", "y", "w", "h" }; + for (int i = 0; i < 4; i++) { + spin[i] = memnew(EditorSpinSlider); + spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); + 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) { + spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); + } + } + + if (!horizontal) { + set_label_reference(spin[0]); //show text and buttons around this + } + setting = false; +} + +///////////////////// VECTOR3 ///////////////////////// + +void EditorPropertyVector3i::_value_changed(double val, const String &p_name) { + if (setting) { + return; + } + + Vector3i v3; + v3.x = spin[0]->get_value(); + v3.y = spin[1]->get_value(); + v3.z = spin[2]->get_value(); + emit_changed(get_edited_property(), v3, p_name); +} + +void EditorPropertyVector3i::update_property() { + Vector3i val = get_edited_object()->get(get_edited_property()); + setting = true; + spin[0]->set_value(val.x); + spin[1]->set_value(val.y); + spin[2]->set_value(val.z); + setting = false; +} + +void EditorPropertyVector3i::_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++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} + +void EditorPropertyVector3i::_bind_methods() { +} + +void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider) { + for (int i = 0; i < 3; i++) { + spin[i]->set_min(p_min); + spin[i]->set_max(p_max); + spin[i]->set_step(1); + spin[i]->set_hide_slider(p_no_slider); + spin[i]->set_allow_greater(true); + spin[i]->set_allow_lesser(true); + } +} + +EditorPropertyVector3i::EditorPropertyVector3i(bool p_force_wide) { + bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing"); + + BoxContainer *bc; + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { + bc = memnew(HBoxContainer); + add_child(bc); + set_bottom_editor(bc); + } else { + bc = memnew(VBoxContainer); + add_child(bc); + } + + static const char *desc[3] = { "x", "y", "z" }; + for (int i = 0; i < 3; i++) { + spin[i] = memnew(EditorSpinSlider); + spin[i]->set_flat(true); + spin[i]->set_label(desc[i]); + bc->add_child(spin[i]); + add_focusable(spin[i]); + spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector3i::_value_changed), varray(desc[i])); + if (horizontal) { + spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); + } + } + + if (!horizontal) { + set_label_reference(spin[0]); //show text and buttons around this + } + setting = false; +} + ///////////////////// PLANE ///////////////////////// void EditorPropertyPlane::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Plane p; p.normal.x = spin[0]->get_value(); @@ -1366,17 +1602,18 @@ void EditorPropertyPlane::update_property() { spin[3]->set_value(val.d); setting = false; } + void EditorPropertyPlane::_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++) { - Color c = base; c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyPlane::_bind_methods() { } @@ -1391,13 +1628,15 @@ void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool } } -EditorPropertyPlane::EditorPropertyPlane() { - +EditorPropertyPlane::EditorPropertyPlane(bool p_force_wide) { bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing"); BoxContainer *bc; - if (horizontal) { + if (p_force_wide) { + bc = memnew(HBoxContainer); + add_child(bc); + } else if (horizontal) { bc = memnew(HBoxContainer); add_child(bc); set_bottom_editor(bc); @@ -1428,8 +1667,9 @@ EditorPropertyPlane::EditorPropertyPlane() { ///////////////////// QUAT ///////////////////////// void EditorPropertyQuat::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Quat p; p.x = spin[0]->get_value(); @@ -1448,17 +1688,18 @@ void EditorPropertyQuat::update_property() { spin[3]->set_value(val.w); setting = false; } + void EditorPropertyQuat::_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++) { - Color c = base; c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyQuat::_bind_methods() { } @@ -1509,8 +1750,9 @@ EditorPropertyQuat::EditorPropertyQuat() { ///////////////////// AABB ///////////////////////// void EditorPropertyAABB::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } AABB p; p.position.x = spin[0]->get_value(); @@ -1535,17 +1777,18 @@ void EditorPropertyAABB::update_property() { setting = false; } + void EditorPropertyAABB::_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 < 6; i++) { - Color c = base; c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyAABB::_bind_methods() { } @@ -1583,8 +1826,9 @@ EditorPropertyAABB::EditorPropertyAABB() { ///////////////////// TRANSFORM2D ///////////////////////// void EditorPropertyTransform2D::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Transform2D p; p[0][0] = spin[0]->get_value(); @@ -1609,17 +1853,18 @@ void EditorPropertyTransform2D::update_property() { setting = false; } + void EditorPropertyTransform2D::_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 < 6; i++) { - Color c = base; c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyTransform2D::_bind_methods() { } @@ -1656,8 +1901,9 @@ EditorPropertyTransform2D::EditorPropertyTransform2D() { ///////////////////// BASIS ///////////////////////// void EditorPropertyBasis::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Basis p; p[0][0] = spin[0]->get_value(); @@ -1688,17 +1934,18 @@ void EditorPropertyBasis::update_property() { setting = false; } + void EditorPropertyBasis::_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 < 9; i++) { - Color c = base; c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyBasis::_bind_methods() { } @@ -1735,8 +1982,9 @@ EditorPropertyBasis::EditorPropertyBasis() { ///////////////////// TRANSFORM ///////////////////////// void EditorPropertyTransform::_value_changed(double val, const String &p_name) { - if (setting) + if (setting) { return; + } Transform p; p.basis[0][0] = spin[0]->get_value(); @@ -1773,17 +2021,18 @@ void EditorPropertyTransform::update_property() { setting = false; } + void EditorPropertyTransform::_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++) { - Color c = base; c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); spin[i]->set_custom_label_color(true, c); } } } + void EditorPropertyTransform::_bind_methods() { } @@ -1820,29 +2069,27 @@ EditorPropertyTransform::EditorPropertyTransform() { ////////////// COLOR PICKER ////////////////////// void EditorPropertyColor::_color_changed(const Color &p_color) { - emit_changed(get_edited_property(), p_color, "", true); } void EditorPropertyColor::_popup_closed() { - emit_changed(get_edited_property(), picker->get_pick_color(), "", false); } void EditorPropertyColor::_picker_created() { // get default color picker mode from editor settings int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode"); - if (default_color_mode == 1) + if (default_color_mode == 1) { picker->get_picker()->set_hsv_mode(true); - else if (default_color_mode == 2) + } else if (default_color_mode == 2) { picker->get_picker()->set_raw_mode(true); + } } void EditorPropertyColor::_bind_methods() { } void EditorPropertyColor::update_property() { - picker->set_pick_color(get_edited_object()->get(get_edited_property())); const Color color = picker->get_pick_color(); @@ -1868,7 +2115,6 @@ void EditorPropertyColor::setup(bool p_show_alpha) { } EditorPropertyColor::EditorPropertyColor() { - picker = memnew(ColorPickerButton); add_child(picker); picker->set_flat(true); @@ -1880,7 +2126,6 @@ EditorPropertyColor::EditorPropertyColor() { ////////////// NODE PATH ////////////////////// void EditorPropertyNodePath::_node_selected(const NodePath &p_path) { - NodePath path = p_path; Node *base_node = nullptr; @@ -1927,13 +2172,11 @@ void EditorPropertyNodePath::_node_assign() { } void EditorPropertyNodePath::_node_clear() { - emit_changed(get_edited_property(), NodePath()); update_property(); } void EditorPropertyNodePath::update_property() { - NodePath p = get_edited_object()->get(get_edited_property()); assign->set_tooltip(p); @@ -1974,14 +2217,12 @@ void EditorPropertyNodePath::update_property() { } void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root) { - base_hint = p_base_hint; valid_types = p_valid_types; use_path_from_scene_root = p_use_path_from_scene_root; } void EditorPropertyNodePath::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { Ref<Texture2D> t = get_theme_icon("Clear", "EditorIcons"); clear->set_icon(t); @@ -1992,7 +2233,6 @@ void EditorPropertyNodePath::_bind_methods() { } EditorPropertyNodePath::EditorPropertyNodePath() { - HBoxContainer *hbc = memnew(HBoxContainer); add_child(hbc); assign = memnew(Button); @@ -2031,7 +2271,6 @@ 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 + "'."); @@ -2055,8 +2294,9 @@ void EditorPropertyResource::_file_selected(const String &p_path) { } } - if (!any_type_matches) + 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)); + } } emit_changed(get_edited_property(), res); @@ -2064,11 +2304,9 @@ void EditorPropertyResource::_file_selected(const String &p_path) { } 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)); @@ -2079,7 +2317,6 @@ void EditorPropertyResource::_menu_option(int p_which) { List<String> extensions; for (int i = 0; i < type.get_slice_count(","); i++) { - ResourceLoader::get_recognized_extensions_for_type(type.get_slice(",", i), &extensions); } @@ -2090,7 +2327,6 @@ void EditorPropertyResource::_menu_option(int p_which) { file->clear_filters(); for (Set<String>::Element *E = valid_extensions.front(); E; E = E->next()) { - file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); } @@ -2098,37 +2334,32 @@ void EditorPropertyResource::_menu_option(int p_which) { } break; case OBJ_MENU_EDIT: { - RES res = get_edited_object()->get(get_edited_property()); if (!res.is_null()) { - emit_signal("resource_selected", get_edited_property(), res); } } break; case OBJ_MENU_CLEAR: { - 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()) + 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); } @@ -2145,7 +2376,6 @@ void EditorPropertyResource::_menu_option(int p_which) { 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); } @@ -2157,8 +2387,9 @@ void EditorPropertyResource::_menu_option(int p_which) { case OBJ_MENU_SAVE: { RES res = get_edited_object()->get(get_edited_property()); - if (res.is_null()) + if (res.is_null()) { return; + } EditorNode::get_singleton()->save_resource(res); } break; @@ -2169,21 +2400,18 @@ void EditorPropertyResource::_menu_option(int p_which) { } 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); } @@ -2196,14 +2424,12 @@ void EditorPropertyResource::_menu_option(int p_which) { 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_position_in_parent()); + 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); @@ -2221,7 +2447,6 @@ void EditorPropertyResource::_menu_option(int p_which) { 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.")); @@ -2283,7 +2508,6 @@ void EditorPropertyResource::_menu_option(int p_which) { } 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(); @@ -2311,7 +2535,6 @@ void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<T } void EditorPropertyResource::_update_menu_items() { - //////////////////// UPDATE MENU ////////////////////////// RES res = get_edited_object()->get(get_edited_property()); @@ -2331,7 +2554,6 @@ void EditorPropertyResource::_update_menu_items() { } for (int i = 0; i < base_type.get_slice_count(","); i++) { - String base = base_type.get_slice(",", i); Set<String> valid_inheritors; @@ -2368,20 +2590,23 @@ void EditorPropertyResource::_update_menu_items() { 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()) + 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))) + if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) { continue; + } inheritors_array.push_back(t); - if (!icon.is_valid()) + 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); @@ -2390,14 +2615,14 @@ void EditorPropertyResource::_update_menu_items() { } } - if (menu->get_item_count()) + 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); @@ -2412,32 +2637,31 @@ void EditorPropertyResource::_update_menu_items() { RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); bool paste_valid = false; if (cb.is_valid()) { - if (base_type == "") + if (base_type == "") { paste_valid = true; - else - for (int i = 0; i < base_type.get_slice_count(","); i++) + } 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 (!res.is_null() || paste_valid) { menu->add_separator(); if (!res.is_null()) { - menu->add_item(TTR("Copy"), OBJ_MENU_COPY); } if (paste_valid) { - menu->add_item(TTR("Paste"), OBJ_MENU_PASTE); } } if (!res.is_null()) { - Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(res); if (conversions.size()) { menu->add_separator(); @@ -2446,10 +2670,8 @@ void EditorPropertyResource::_update_menu_items() { 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"); } @@ -2459,7 +2681,6 @@ void EditorPropertyResource::_update_menu_items() { } void EditorPropertyResource::_update_menu() { - _update_menu_items(); Rect2 gt = edit->get_screen_rect(); @@ -2471,17 +2692,14 @@ void EditorPropertyResource::_update_menu() { } 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); } void EditorPropertyResource::_sub_inspector_resource_selected(const RES &p_resource, const String &p_property) { - emit_signal("resource_selected", String(get_edited_property()) + ":" + p_property, p_resource); } void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) { - emit_signal("object_id_selected", get_edited_property(), p_id); } @@ -2507,15 +2725,15 @@ void EditorPropertyResource::_open_editor_pressed() { } void EditorPropertyResource::_fold_other_editors(Object *p_self) { - if (this == p_self) { return; } RES res = get_edited_object()->get(get_edited_property()); - if (!res.is_valid()) + 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); @@ -2524,8 +2742,9 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) { } } - if (!use_editor) + if (!use_editor) { return; + } bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property()); opened_editor = false; @@ -2539,17 +2758,14 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) { } 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() && get_edited_object()->editor_is_section_unfolded(get_edited_property())) { - if (!sub_inspector) { sub_inspector = memnew(EditorInspector); sub_inspector->set_enable_v_scroll(false); @@ -2615,7 +2831,6 @@ void EditorPropertyResource::update_property() { 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()) { @@ -2646,12 +2861,10 @@ void EditorPropertyResource::_resource_selected() { } 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); } } @@ -2661,14 +2874,12 @@ void EditorPropertyResource::setup(const String &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; @@ -2686,7 +2897,6 @@ void EditorPropertyResource::_notification(int p_what) { } 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!")); @@ -2709,14 +2919,12 @@ void EditorPropertyResource::collapse_all_folding() { } void EditorPropertyResource::expand_all_folding() { - if (sub_inspector) { sub_inspector->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); @@ -2724,10 +2932,8 @@ void EditorPropertyResource::_button_draw() { } 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); } @@ -2735,7 +2941,6 @@ Variant EditorPropertyResource::get_drag_data_fw(const Point2 &p_point, Control } bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const { - String allowed_type = base_type; Dictionary drag_data = p_drag_data; @@ -2750,7 +2955,6 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const } if (drag_data.has("type") && String(drag_data["type"]) == "files") { - Vector<String> files = drag_data["files"]; if (files.size() == 1) { @@ -2758,7 +2962,6 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const 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)) { @@ -2773,11 +2976,10 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const } 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::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { +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; @@ -2791,7 +2993,6 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant & } if (drag_data.has("type") && String(drag_data["type"]) == "files") { - Vector<String> files = drag_data["files"]; if (files.size() == 1) { @@ -2811,7 +3012,6 @@ void EditorPropertyResource::set_use_sub_inspector(bool 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); @@ -2821,7 +3021,6 @@ void EditorPropertyResource::_bind_methods() { } EditorPropertyResource::EditorPropertyResource() { - opened_editor = false; sub_inspector = nullptr; sub_inspector_vbox = nullptr; @@ -2877,12 +3076,10 @@ 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 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"); switch (p_type) { - // atomic types case Variant::NIL: { EditorPropertyNil *editor = memnew(EditorPropertyNil); @@ -2893,7 +3090,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ add_property_editor(p_path, editor); } break; case Variant::INT: { - if (p_hint == PROPERTY_HINT_ENUM) { EditorPropertyEnum *editor = memnew(EditorPropertyEnum); Vector<String> options = p_hint_text.split(","); @@ -2907,7 +3103,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ 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) { - EditorPropertyLayers::LayerType lt = EditorPropertyLayers::LAYER_RENDER_2D; switch (p_hint) { case PROPERTY_HINT_LAYERS_2D_RENDER: @@ -2929,7 +3124,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ editor->setup(lt); add_property_editor(p_path, editor); } else if (p_hint == PROPERTY_HINT_OBJECT_ID) { - EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID); editor->setup(p_hint_text); add_property_editor(p_path, editor); @@ -2966,7 +3160,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } } break; case Variant::FLOAT: { - if (p_hint == PROPERTY_HINT_EXP_EASING) { EditorPropertyEasing *editor = memnew(EditorPropertyEasing); bool full = true; @@ -3019,7 +3212,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } } break; case Variant::STRING: { - if (p_hint == PROPERTY_HINT_ENUM) { EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); Vector<String> options = p_hint_text.split(","); @@ -3033,7 +3225,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ editor->setup("Object", p_hint_text); add_property_editor(p_path, 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; bool folder = p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_GLOBAL_DIR; @@ -3052,18 +3243,31 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ p_hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE || p_hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE || p_hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) { - EditorPropertyMember *editor = memnew(EditorPropertyMember); EditorPropertyMember::Type type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE; switch (p_hint) { - case PROPERTY_HINT_METHOD_OF_BASE_TYPE: type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE; break; - case PROPERTY_HINT_METHOD_OF_INSTANCE: type = EditorPropertyMember::MEMBER_METHOD_OF_INSTANCE; break; - case PROPERTY_HINT_METHOD_OF_SCRIPT: type = EditorPropertyMember::MEMBER_METHOD_OF_SCRIPT; break; - case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_VARIANT_TYPE; break; - case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE; break; - case PROPERTY_HINT_PROPERTY_OF_INSTANCE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE; break; - case PROPERTY_HINT_PROPERTY_OF_SCRIPT: type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT; break; + case PROPERTY_HINT_METHOD_OF_BASE_TYPE: + type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE; + break; + case PROPERTY_HINT_METHOD_OF_INSTANCE: + type = EditorPropertyMember::MEMBER_METHOD_OF_INSTANCE; + break; + case PROPERTY_HINT_METHOD_OF_SCRIPT: + type = EditorPropertyMember::MEMBER_METHOD_OF_SCRIPT; + break; + case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE: + type = EditorPropertyMember::MEMBER_PROPERTY_OF_VARIANT_TYPE; + break; + case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE: + type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE; + break; + case PROPERTY_HINT_PROPERTY_OF_INSTANCE: + type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE; + break; + case PROPERTY_HINT_PROPERTY_OF_SCRIPT: + type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT; + break; default: { } } @@ -3071,7 +3275,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ add_property_editor(p_path, editor); } else { - EditorPropertyText *editor = memnew(EditorPropertyText); if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { editor->set_placeholder(p_hint_text); @@ -3083,7 +3286,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ // math types case Variant::VECTOR2: { - EditorPropertyVector2 *editor = memnew(EditorPropertyVector2); + EditorPropertyVector2 *editor = memnew(EditorPropertyVector2(p_wide)); double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; @@ -3100,8 +3303,23 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ add_property_editor(p_path, 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); + + } break; case Variant::RECT2: { - EditorPropertyRect2 *editor = memnew(EditorPropertyRect2); + EditorPropertyRect2 *editor = memnew(EditorPropertyRect2(p_wide)); double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; @@ -3117,8 +3335,22 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ editor->setup(min, max, step, hide_slider); add_property_editor(p_path, editor); } break; + case Variant::RECT2I: { + EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i(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); + } break; case Variant::VECTOR3: { - EditorPropertyVector3 *editor = memnew(EditorPropertyVector3); + EditorPropertyVector3 *editor = memnew(EditorPropertyVector3(p_wide)); double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; @@ -3135,6 +3367,22 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ add_property_editor(p_path, 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); + + } break; case Variant::TRANSFORM2D: { EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D); double min = -65535, max = 65535, step = default_float_step; @@ -3154,7 +3402,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::PLANE: { - EditorPropertyPlane *editor = memnew(EditorPropertyPlane); + EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide)); double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; @@ -3247,7 +3495,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ add_property_editor(p_path, editor); } break; case Variant::STRING_NAME: { - if (p_hint == PROPERTY_HINT_ENUM) { EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); Vector<String> options = p_hint_text.split(","); @@ -3263,7 +3510,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } } break; case Variant::NODE_PATH: { - EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath); if (p_hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && p_hint_text != String()) { editor->setup(p_hint_text, Vector<StringName>(), (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT)); @@ -3291,7 +3537,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ for (int j = 0; j < p_hint_text.get_slice_count(","); j++) { String inherits = p_hint_text.get_slicec(',', j); if (ClassDB::is_parent_class(inherits, type)) { - editor->set_use_sub_inspector(false); } } |