diff options
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r-- | editor/editor_properties.cpp | 451 |
1 files changed, 191 insertions, 260 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3feeaec070..8f716a2499 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -491,6 +491,7 @@ 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(":"); @@ -892,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; @@ -905,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); @@ -913,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() { @@ -921,7 +930,6 @@ EditorPropertyFloat::EditorPropertyFloat() { add_child(spin); add_focusable(spin); spin->connect("value_changed", callable_mp(this, &EditorPropertyFloat::_value_changed)); - setting = false; } ///////////////////// EASING ///////////////////////// @@ -1171,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); @@ -1179,6 +1187,7 @@ 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); } } @@ -1257,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); @@ -1265,6 +1274,7 @@ 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); } } @@ -1325,6 +1335,11 @@ 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); } @@ -1333,6 +1348,11 @@ void EditorPropertyVector3::update_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(p_vector.x); spin[1]->set_value(p_vector.y); @@ -1345,6 +1365,12 @@ Vector3 EditorPropertyVector3::get_vector() { 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; } @@ -1362,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); @@ -1370,6 +1397,7 @@ 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); } } @@ -1406,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 ///////////////////////// @@ -1444,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); @@ -1452,6 +1479,7 @@ 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); } } @@ -1530,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); @@ -1538,6 +1566,7 @@ 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); } } @@ -1624,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); @@ -1632,6 +1661,7 @@ 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); } } @@ -1709,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); @@ -1717,6 +1747,7 @@ 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); } } @@ -1795,7 +1826,7 @@ void EditorPropertyQuaternion::_notification(int p_what) { void EditorPropertyQuaternion::_bind_methods() { } -void EditorPropertyQuaternion::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); @@ -1803,6 +1834,7 @@ void EditorPropertyQuaternion::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); } } @@ -1884,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); @@ -1892,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); } } @@ -1960,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); @@ -1968,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); } } @@ -2041,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); @@ -2049,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); } } @@ -2130,7 +2165,7 @@ void EditorPropertyTransform3D::_notification(int p_what) { void EditorPropertyTransform3D::_bind_methods() { } -void EditorPropertyTransform3D::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); @@ -2138,6 +2173,7 @@ void EditorPropertyTransform3D::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); } } @@ -2535,7 +2571,7 @@ void EditorPropertyResource::_viewport_selected(const NodePath &p_path) { } Ref<ViewportTexture> vt; - vt.instance(); + vt.instantiate(); vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node)); vt->setup_local_to_scene(); @@ -2699,30 +2735,96 @@ void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) { } 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) { + 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, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, 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); + return editor; } else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_2D_RENDER || @@ -2755,41 +2857,20 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } 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: { @@ -2809,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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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: { @@ -2849,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; @@ -2867,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 || @@ -2905,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; @@ -2920,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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - hide_slider = false; - } + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1); + editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix); - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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::QUATERNION: { EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion); - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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::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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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::TRANSFORM3D: { EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D); - 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_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - 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; @@ -3125,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: { @@ -3152,12 +3087,12 @@ 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: { EditorPropertyRID *editor = memnew(EditorPropertyRID); - add_property_editor(p_path, editor); + return editor; } break; case Variant::OBJECT: { EditorPropertyResource *editor = memnew(EditorPropertyResource); @@ -3176,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; } |