Remove scroll snap in gardens view

This commit is contained in:
Adrien Ufferte
2026-01-06 14:02:58 +01:00
parent 52c5f4c9d8
commit 65ade9aa6d
+2 -47
View File
@@ -41,7 +41,6 @@ var points: Array[Array] = []
var lesson_distribution: Array[int] = []
var is_scrolling: bool = false
var scroll_beginning_garden: int = 0
var scroll_tween: Tween
var is_locked: bool = false
var in_minigame_selection: bool = false
var current_lesson_number: int = -1
@@ -1184,61 +1183,17 @@ func _on_scroll_container_gui_input(event: InputEvent) -> void:
return
if event.is_action_pressed("left_click"):
is_scrolling = true
_commit_scroll_position()
if scroll_tween:
scroll_tween.stop()
scroll_tween = null
elif event.is_action_released("left_click"):
is_scrolling = false
_snap_after_drag()
return
if is_scrolling and event is InputEventMouseMotion:
var motion_event: InputEventMouseMotion = event
scroll_container.scroll_horizontal -= int(motion_event.relative.x)
func _animate_scroll_to(p_target_scroll: int, p_duration: float) -> void:
if scroll_tween:
scroll_tween.stop()
scroll_tween = null
scroll_tween = create_tween()
scroll_tween.set_ease(Tween.EASE_OUT)
scroll_tween.set_trans(Tween.TRANS_SPRING)
scroll_tween.tween_property(
scroll_container,
"scroll_horizontal",
p_target_scroll,
p_duration
)
await scroll_tween.finished
_commit_scroll_position()
func _commit_scroll_position() -> void:
scroll_beginning_garden = int(float(scroll_container.scroll_horizontal) / GARDEN_SIZE)
func _scroll_by_garden(p_direction: int) -> void:
var target_scroll: int = scroll_container.scroll_horizontal + p_direction * GARDEN_SIZE
_animate_scroll_to(target_scroll, 0.6)
func _snap_after_drag() -> void:
var scroll_delta: int = scroll_container.scroll_horizontal - scroll_beginning_garden * GARDEN_SIZE
var target_scroll: int = scroll_beginning_garden * GARDEN_SIZE
var is_garden_changed: bool = false
if scroll_delta < -400:
target_scroll -= GARDEN_SIZE
is_garden_changed = true
left_audio_stream_player.play()
elif scroll_delta > 400:
target_scroll += GARDEN_SIZE
is_garden_changed = true
right_audio_stream_player.play()
if is_garden_changed:
current_garden = garden_parent.get_child(int(float(target_scroll) / GARDEN_SIZE))
current_garden.pop_animation()
_animate_scroll_to(target_scroll, 1.0)
var target_scroll: int = scroll_container.scroll_horizontal + p_direction * 200
scroll_container.scroll_horizontal = target_scroll
func _on_back_button_pressed() -> void: