Skip to content

Commit c3e7519

Browse files
committed
Allow @export_range to support numeric types
1 parent b94ca9b commit c3e7519

4 files changed

Lines changed: 58 additions & 23 deletions

File tree

doc/classes/@GlobalScope.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@
27752775
The property has no hint for the editor.
27762776
</constant>
27772777
<constant name="PROPERTY_HINT_RANGE" value="1" enum="PropertyHint">
2778-
Hints that an [int] or [float] property should be within a range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"or_greater"[/code] and/or [code]"or_less"[/code] to allow manual input going respectively above the max or below the min values.
2778+
Hints that a numeric type property (such as [int] or [float]) should be within a range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"or_greater"[/code] and/or [code]"or_less"[/code] to allow manual input going respectively above the max or below the min values.
27792779
[b]Example:[/b] [code]"-360,360,1,or_greater,or_less"[/code].
27802780
Additionally, other keywords can be included: [code]"exp"[/code] for exponential range editing, [code]"radians_as_degrees"[/code] for editing radian angles in degrees (the range values are also in degrees), [code]"degrees"[/code] to hint at an angle, [code]"prefer_slider"[/code] to show the slider for integers, [code]"hide_control"[/code] to hide the slider or up-down arrows, and [code]"suffix:px/s"[/code] to display a suffix indicating the value's unit (e.g. [code]px/s[/code] for pixels per second).
27812781
</constant>

editor/inspector/editor_properties.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,8 +2005,8 @@ void EditorPropertyRect2::setup(const EditorPropertyRangeHint &p_range_hint) {
20052005
if (p_range_hint.hide_control) {
20062006
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
20072007
}
2008-
spin[i]->set_allow_greater(true);
2009-
spin[i]->set_allow_lesser(true);
2008+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2009+
spin[i]->set_allow_lesser(p_range_hint.or_less);
20102010
spin[i]->set_suffix(p_range_hint.suffix);
20112011
}
20122012
}
@@ -2098,8 +2098,8 @@ void EditorPropertyRect2i::setup(const EditorPropertyRangeHint &p_range_hint) {
20982098
spin[i]->set_min(p_range_hint.min);
20992099
spin[i]->set_max(p_range_hint.max);
21002100
spin[i]->set_step(1);
2101-
spin[i]->set_allow_greater(true);
2102-
spin[i]->set_allow_lesser(true);
2101+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2102+
spin[i]->set_allow_lesser(p_range_hint.or_less);
21032103
spin[i]->set_suffix(p_range_hint.suffix);
21042104
spin[i]->set_editing_integer(true);
21052105
}
@@ -2195,8 +2195,8 @@ void EditorPropertyPlane::setup(const EditorPropertyRangeHint &p_range_hint) {
21952195
if (p_range_hint.hide_control) {
21962196
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
21972197
}
2198-
spin[i]->set_allow_greater(true);
2199-
spin[i]->set_allow_lesser(true);
2198+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2199+
spin[i]->set_allow_lesser(p_range_hint.or_less);
22002200
}
22012201
spin[3]->set_suffix(p_range_hint.suffix);
22022202
}
@@ -2346,8 +2346,8 @@ void EditorPropertyQuaternion::setup(const EditorPropertyRangeHint &p_range_hint
23462346
if (p_range_hint.hide_control) {
23472347
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
23482348
}
2349-
spin[i]->set_allow_greater(true);
2350-
spin[i]->set_allow_lesser(true);
2349+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2350+
spin[i]->set_allow_lesser(p_range_hint.or_less);
23512351
// Quaternion is inherently unitless, however someone may want to use it as
23522352
// a generic way to store 4 values, so we'll still respect the suffix.
23532353
spin[i]->set_suffix(p_range_hint.suffix);
@@ -2495,8 +2495,8 @@ void EditorPropertyAABB::setup(const EditorPropertyRangeHint &p_range_hint) {
24952495
if (p_range_hint.hide_control) {
24962496
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
24972497
}
2498-
spin[i]->set_allow_greater(true);
2499-
spin[i]->set_allow_lesser(true);
2498+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2499+
spin[i]->set_allow_lesser(p_range_hint.or_less);
25002500
spin[i]->set_suffix(p_range_hint.suffix);
25012501
}
25022502
}
@@ -2575,8 +2575,8 @@ void EditorPropertyTransform2D::setup(const EditorPropertyRangeHint &p_range_hin
25752575
if (p_range_hint.hide_control) {
25762576
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
25772577
}
2578-
spin[i]->set_allow_greater(true);
2579-
spin[i]->set_allow_lesser(true);
2578+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2579+
spin[i]->set_allow_lesser(p_range_hint.or_less);
25802580
if (i % 3 == 2) {
25812581
spin[i]->set_suffix(p_range_hint.suffix);
25822582
}
@@ -2659,8 +2659,8 @@ void EditorPropertyBasis::setup(const EditorPropertyRangeHint &p_range_hint) {
26592659
if (p_range_hint.hide_control) {
26602660
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
26612661
}
2662-
spin[i]->set_allow_greater(true);
2663-
spin[i]->set_allow_lesser(true);
2662+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2663+
spin[i]->set_allow_lesser(p_range_hint.or_less);
26642664
// Basis is inherently unitless, however someone may want to use it as
26652665
// a generic way to store 9 values, so we'll still respect the suffix.
26662666
spin[i]->set_suffix(p_range_hint.suffix);
@@ -2750,8 +2750,8 @@ void EditorPropertyTransform3D::setup(const EditorPropertyRangeHint &p_range_hin
27502750
if (p_range_hint.hide_control) {
27512751
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
27522752
}
2753-
spin[i]->set_allow_greater(true);
2754-
spin[i]->set_allow_lesser(true);
2753+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2754+
spin[i]->set_allow_lesser(p_range_hint.or_less);
27552755
if (i % 4 == 3) {
27562756
spin[i]->set_suffix(p_range_hint.suffix);
27572757
}
@@ -2849,8 +2849,8 @@ void EditorPropertyProjection::setup(const EditorPropertyRangeHint &p_range_hint
28492849
if (p_range_hint.hide_control) {
28502850
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
28512851
}
2852-
spin[i]->set_allow_greater(true);
2853-
spin[i]->set_allow_lesser(true);
2852+
spin[i]->set_allow_greater(p_range_hint.or_greater);
2853+
spin[i]->set_allow_lesser(p_range_hint.or_less);
28542854
if (i % 4 == 3) {
28552855
spin[i]->set_suffix(p_range_hint.suffix);
28562856
}

editor/inspector/editor_properties_vector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ void EditorPropertyVectorN::setup(const EditorPropertyRangeHint &p_range_hint, b
163163
if (p_range_hint.hide_control) {
164164
spin->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
165165
}
166-
spin->set_allow_greater(true);
167-
spin->set_allow_lesser(true);
166+
spin->set_allow_greater(p_range_hint.or_greater);
167+
spin->set_allow_lesser(p_range_hint.or_less);
168168
spin->set_suffix(p_range_hint.suffix);
169169
spin->set_editing_integer(p_is_int);
170170
}

modules/gdscript/gdscript_parser.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4727,8 +4727,43 @@ bool GDScriptParser::export_annotations(AnnotationNode *p_annotation, Node *p_ta
47274727
bool use_default_variable_type_check = true;
47284728

47294729
if (p_annotation->name == SNAME("@export_range")) {
4730-
if (export_type.builtin_type == Variant::INT) {
4731-
variable->export_info.type = Variant::INT;
4730+
use_default_variable_type_check = false;
4731+
4732+
switch (export_type.builtin_type) {
4733+
case Variant::NIL:
4734+
break;
4735+
case Variant::INT:
4736+
case Variant::FLOAT:
4737+
case Variant::VECTOR2:
4738+
case Variant::VECTOR2I:
4739+
case Variant::RECT2:
4740+
case Variant::RECT2I:
4741+
case Variant::VECTOR3:
4742+
case Variant::VECTOR3I:
4743+
case Variant::VECTOR4:
4744+
case Variant::VECTOR4I:
4745+
case Variant::TRANSFORM2D:
4746+
case Variant::TRANSFORM3D:
4747+
case Variant::PLANE:
4748+
case Variant::QUATERNION:
4749+
case Variant::AABB:
4750+
case Variant::BASIS:
4751+
case Variant::PROJECTION:
4752+
case Variant::PACKED_BYTE_ARRAY:
4753+
case Variant::PACKED_INT32_ARRAY:
4754+
case Variant::PACKED_INT64_ARRAY:
4755+
case Variant::PACKED_FLOAT32_ARRAY:
4756+
case Variant::PACKED_FLOAT64_ARRAY:
4757+
case Variant::PACKED_VECTOR2_ARRAY:
4758+
case Variant::PACKED_VECTOR3_ARRAY:
4759+
case Variant::PACKED_VECTOR4_ARRAY: {
4760+
variable->export_info.type = export_type.builtin_type;
4761+
break;
4762+
}
4763+
default: {
4764+
push_error(vformat(R"("@export_range" annotation requires a numeric variable or array, but %s was given instead.)", variable->get_datatype().to_string()), p_annotation);
4765+
return false;
4766+
}
47324767
}
47334768
} else if (p_annotation->name == SNAME("@export_multiline")) {
47344769
use_default_variable_type_check = false;

0 commit comments

Comments
 (0)