aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--date_picker/date_picker.tscn51
-rw-r--r--date_picker/scroll_picker.gd124
2 files changed, 93 insertions, 82 deletions
diff --git a/date_picker/date_picker.tscn b/date_picker/date_picker.tscn
index 84b2089..440296a 100644
--- a/date_picker/date_picker.tscn
+++ b/date_picker/date_picker.tscn
@@ -10,15 +10,16 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="day_scroll" type="Control" parent="."]
+[node name="year_scroll" type="Control" parent="."]
anchor_right = 0.333
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
+max_value = 9999
-[node name="value_previous" type="Label" parent="day_scroll"]
+[node name="value_previous" type="Label" parent="year_scroll"]
anchor_right = 1.0
anchor_bottom = 0.333
mouse_filter = 1
@@ -28,7 +29,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="ColorRect" type="ColorRect" parent="day_scroll/value_previous"]
+[node name="ColorRect" type="ColorRect" parent="year_scroll/value_previous"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
@@ -37,7 +38,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="value" type="Label" parent="day_scroll"]
+[node name="value" type="Label" parent="year_scroll"]
anchor_top = 0.333
anchor_right = 1.0
anchor_bottom = 0.666
@@ -48,7 +49,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="ColorRect" type="ColorRect" parent="day_scroll/value"]
+[node name="ColorRect" type="ColorRect" parent="year_scroll/value"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
@@ -57,7 +58,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="value_next" type="Label" parent="day_scroll"]
+[node name="value_next" type="Label" parent="year_scroll"]
anchor_top = 0.666
anchor_right = 1.0
anchor_bottom = 1.0
@@ -68,7 +69,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="ColorRect" type="ColorRect" parent="day_scroll/value_next"]
+[node name="ColorRect" type="ColorRect" parent="year_scroll/value_next"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
@@ -77,11 +78,17 @@ __meta__ = {
"_edit_use_anchors_": false
}
+[node name="debug" type="Label" parent="year_scroll"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+
[node name="month_scroll" type="Control" parent="."]
anchor_left = 0.333
anchor_right = 0.666
anchor_bottom = 1.0
script = ExtResource( 1 )
+min_value = 1
+max_value = 12
[node name="value_previous" type="Label" parent="month_scroll"]
anchor_right = 1.0
@@ -142,13 +149,22 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="year_scroll" type="Control" parent="."]
+[node name="debug" type="Label" parent="month_scroll"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+
+[node name="day_scroll" type="Control" parent="."]
anchor_left = 0.666
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
+min_value = 1
+max_value = 31
-[node name="value_previous" type="Label" parent="year_scroll"]
+[node name="value_previous" type="Label" parent="day_scroll"]
anchor_right = 1.0
anchor_bottom = 0.333
mouse_filter = 1
@@ -158,7 +174,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="ColorRect" type="ColorRect" parent="year_scroll/value_previous"]
+[node name="ColorRect" type="ColorRect" parent="day_scroll/value_previous"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
@@ -167,7 +183,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="value" type="Label" parent="year_scroll"]
+[node name="value" type="Label" parent="day_scroll"]
anchor_top = 0.333
anchor_right = 1.0
anchor_bottom = 0.666
@@ -178,7 +194,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="ColorRect" type="ColorRect" parent="year_scroll/value"]
+[node name="ColorRect" type="ColorRect" parent="day_scroll/value"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
@@ -187,7 +203,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="value_next" type="Label" parent="year_scroll"]
+[node name="value_next" type="Label" parent="day_scroll"]
anchor_top = 0.666
anchor_right = 1.0
anchor_bottom = 1.0
@@ -198,7 +214,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="ColorRect" type="ColorRect" parent="year_scroll/value_next"]
+[node name="ColorRect" type="ColorRect" parent="day_scroll/value_next"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
@@ -207,6 +223,13 @@ __meta__ = {
"_edit_use_anchors_": false
}
+[node name="debug" type="Label" parent="day_scroll"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
[node name="split_previous" type="ColorRect" parent="."]
anchor_top = 0.333
anchor_right = 1.0
diff --git a/date_picker/scroll_picker.gd b/date_picker/scroll_picker.gd
index 1d184b9..02d5933 100644
--- a/date_picker/scroll_picker.gd
+++ b/date_picker/scroll_picker.gd
@@ -1,17 +1,28 @@
extends Control
-const MAX_POINTERS = 10
+const VELOCITY_DECAYING_FACTOR: float = 5.5
+const BINNING_THRESHOLD: float = 0.75
+const BINNING_ADJUST_P: float = 5.0
+
+export var min_value: int setget set_min_value
+export var max_value: int setget set_max_value
+var num_of_values: int
+
+func set_min_value(value: int):
+ min_value = value
+ num_of_values = max_value - min_value + 1
+
+func set_max_value(value: int):
+ max_value = value
+ num_of_values = max_value - min_value + 1
var pointer: Dictionary
var value: float = 0.0
var anchor: float = 0.0
-var pointer_id: int = -1
-var start_pos: float = 0.0
-var pos: float = 0.0
-var value_base_position: float
-var value_next_base_position: float
-var value_previous_base_position: float
+var current_value_base_position: float
+var next_value_base_position: float
+var previous_value_base_position: float
func _ready():
@@ -19,106 +30,83 @@ func _ready():
index = -1,
initial_position = Vector2.ZERO,
current_position = Vector2.ZERO,
- relative = Vector2.ZERO,
velocity = Vector2.ZERO,
is_active = false,
- timestamp = 0
}
- value_base_position = ($value as Label).rect_position.y
- value_next_base_position = ($value_next as Label).rect_position.y
- value_previous_base_position = ($value_previous as Label).rect_position.y
-
+ current_value_base_position = ($value as Label).rect_position.y
+ next_value_base_position = ($value_next as Label).rect_position.y
+ previous_value_base_position = ($value_previous as Label).rect_position.y
func _process(delta: float):
- var max_value := 10
+ # @DAM TODO It's weird that we use '-value'... check maths.
var scroll_unit_height := ($value as Label).rect_size.y
+ var normalized_value := - value / scroll_unit_height
+ var normalized_int_value := round(normalized_value) as int
+ # $debug.text = "%s | %s" % [normalized_value, normalized_int_value]
- pointer.velocity *= clamp((1.0 - 5.5 * delta), 0.0, 1.0)
+ pointer.velocity *= clamp((1.0 - VELOCITY_DECAYING_FACTOR * delta), 0.0, 1.0)
if pointer.is_active:
value = anchor + (pointer.current_position.y - pointer.initial_position.y)
elif is_zero_approx(pointer.velocity.y) == false:
value += pointer.velocity.y * delta
- if abs(pointer.velocity.y) < 50.0:
- var normalized_value := -value / scroll_unit_height
- var normalized_int_value := round(normalized_value) as int
- var logic_value := fposmod(normalized_int_value, max_value)
+ if abs(pointer.velocity.y) < BINNING_THRESHOLD * scroll_unit_height:
var fix := ((normalized_int_value as float) - normalized_value) * scroll_unit_height
- value -= fix * 5.0 * delta
-
-# pointer.timestamp = OS.get_ticks_msec()
-# ($test as TextureRect).rect_global_position.y = value
-# $debug.text = "value: %s\nvelocity: %s\n%s" % [value, pointer.velocity, pointer.relative]
- var current_pos = value
- var turn_over := scroll_unit_height * max_value
- if current_pos >= turn_over || current_pos < 0.0:
- value = fposmod(current_pos, turn_over)
-# elif current_pos < 0:
-# value = 800 - current_pos
-
-
- var normalized_value := -value / scroll_unit_height
- var normalized_int_value := round(normalized_value) as int
- var logic_value := fposmod(normalized_int_value, max_value)
- var logic_next_value := fposmod(normalized_int_value + 1, max_value)
- var logic_previous_value := fposmod(normalized_int_value - 1, max_value)
+ value -= fix * BINNING_ADJUST_P * delta
-# var value_base_position := ($value_previous as Label).rect_position.y # 140.0 # 180.0
-# var value_next_base_position := ($value_next as Label).rect_position.y #180.0 # 260.0
-# var value_previous_base_position := ($value as Label).rect_position.y #100.0
+ var logic_value := min_value + fposmod(normalized_int_value, num_of_values)
+ var logic_next_value := min_value + fposmod(normalized_int_value + 1, num_of_values)
+ var logic_previous_value := min_value + fposmod(normalized_int_value - 1, num_of_values)
$value.text = "%d" % logic_value
$value_next.text = "%d" % logic_next_value
$value_previous.text = "%d" % logic_previous_value
-# $debug.text = "%s" % normalized_value
- ($value as Label).rect_position.y = value_base_position - (normalized_value - normalized_int_value) * scroll_unit_height
- ($value_previous as Label).rect_position.y = value_previous_base_position - (normalized_value - normalized_int_value) * scroll_unit_height
- ($value_next as Label).rect_position.y = value_next_base_position - (normalized_value - normalized_int_value) * scroll_unit_height
+ var normalized_displacement := normalized_value - normalized_int_value
+ var displacement := normalized_displacement * scroll_unit_height
-# ($value as Label).modulate.a = (scroll_unit_height - (normalized_value - normalized_int_value) * scroll_unit_height) / (scroll_unit_height as float)
-# $debug.text = "%s ..." % [normalized_int_value - normalized_value]
- ($value_next as Label).modulate.a = ((normalized_value - normalized_int_value) + 0.5)
- ($value_previous as Label).modulate.a = ((normalized_int_value - normalized_value) + 0.5)
-# ($value_previous as Label).modulate.a = ((normalized_value + normalized_int_value) * scroll_unit_height) / (scroll_unit_height as float)
-#
-#func _input(event: InputEvent):
-# $log.text += "> input: %s\n" % event.to_string()
-# if event is InputEventScreenTouch && event.pressed == false:
-# pointer.index = -1
+ ($value as Label).rect_position.y = current_value_base_position - displacement
+ ($value_previous as Label).rect_position.y = previous_value_base_position - displacement
+ ($value_next as Label).rect_position.y = next_value_base_position - displacement
+
+ ($value_next as Label).modulate.a = normalized_displacement + 0.5
+ ($value_previous as Label).modulate.a = 0.5 - normalized_displacement
+
+ var current_pos := value
+ var turn_over := num_of_values * scroll_unit_height
+ if current_pos >= turn_over || current_pos < 0.0:
+ value = fposmod(current_pos, turn_over)
-func _gui_input(event: InputEvent):
-# get_tree().set_input_as_handled()
-# if event is InputEventScreenTouch && event.pressed == false:
-# $label.text = "AUTCH"
-# $log.text += "> event: %s\n" % event.to_string()
+func _gui_input(event: InputEvent):
+
+ # @DAM TODO When we release the pointer, we will receive an event that will se the 'current_position' as the last 'touch.position'.
if event is InputEventScreenTouch:
# if (event is InputEventScreenTouch && pointer.is_active && pointer.index == event.index
# || event is InputEventScreenTouch && pointer.is_active == false):
var touch := event as InputEventScreenTouch
pointer.is_active = event.pressed
pointer.current_position = touch.position
- var time := OS.get_ticks_msec()
if pointer.is_active:
pointer.index = touch.index
pointer.initial_position = touch.position
anchor = value
else:
pointer.index = -1
-# elif abs(pointer.timestamp - time) > 50.0:
-# pointer.velocity = Vector2.ZERO
-# if pointer.is_active == false:
-# $output.text += "%10d: touch %d\n" % [abs(pointer.timestamp - time), touch.index]
if event is InputEventScreenDrag && event.index == pointer.index:
var drag := event as InputEventScreenDrag
pointer.current_position = drag.position
pointer.velocity = drag.speed
-# $label.text = "%s"%drag.speed
- pointer.relative = drag.relative
- pointer.timestamp = OS.get_ticks_msec()
-# $output.text += "%10d: drag %d\n" % [pointer.timestamp, drag.index]
+
+
+func set_value(value: int):
+ breakpoint # @DAM TODO
+
+
+func get_value() -> int:
+ breakpoint # @DAM TODO
+ return 0