stick-the-quick/ui/LevelCardCutIn/LevelCardCutIn.gd

91 lines
2.5 KiB
GDScript3
Raw Permalink Normal View History

class_name LevelCardCutIn extends Control
enum Phase {COMING, STAYING, GOING}
signal storyboard_should_start_loading_level
@export var test_mode := false
@onready var level_label := (
$PanelContainer/VBoxContainer/Level as Label
)
@onready var mission_label := (
$PanelContainer/VBoxContainer/Mission as Label
)
@onready var best_time_label := (
$PanelContainer/VBoxContainer/BestTime as Label
)
@onready var audio_player := $AudioStreamPlayer as AudioStreamPlayer
var viewport_rect: Rect2
var phase := Phase.COMING
var time_came_usecs: int = -1
var level_descriptor: LevelDescriptor
var mission_descriptor: MissionDescriptor
var game_mode: LevelDescriptor.GameMode
var save_data: MapCompletionMark
func _ready() -> void:
viewport_rect = get_viewport().get_visible_rect()
get_viewport().size_changed.connect(_on_viewport_size_changed)
position = viewport_rect.position
position.x += viewport_rect.size.x
if not test_mode:
var args := UI.Args(self)
level_descriptor = args[&'level_descriptor']
mission_descriptor = args.get(&'mission_descriptor')
game_mode = args.get(
&'game_mode',
LevelDescriptor.GameMode.MISSION if mission_descriptor
else LevelDescriptor.GameMode.FREERUN
)
save_data = args.get(&'save_data')
modulate = level_descriptor.color
level_label.text = level_descriptor.name
match game_mode:
LevelDescriptor.GameMode.MISSION:
mission_label.text = mission_descriptor.name
if save_data:
best_time_label.text = (
TimeIntervalFormatting.format_realtime_interval(
save_data.best_time
)
)
pass
else:
best_time_label.visible = false
LevelDescriptor.GameMode.FREERUN:
mission_label.text = "Show your stuff!"
best_time_label.visible = false
_:
mission_label.visible = false
best_time_label.visible = false
func _on_viewport_size_changed() -> void:
viewport_rect = get_viewport().get_visible_rect()
func _process(_delta: float) -> void:
match phase:
Phase.COMING:
if abs(position.x - viewport_rect.position.x) < 1.0:
time_came_usecs = Time.get_ticks_usec()
phase = Phase.STAYING
if not test_mode:
storyboard_should_start_loading_level.emit()
else:
position.x = lerpf(
position.x, viewport_rect.position.x, 0.03125
)
Phase.STAYING:
pass
Phase.GOING:
if position.x < -viewport_rect.size.x:
UI.Return(self, true)
else:
position.x -= (
abs(viewport_rect.position.x - position.x) + 1.0
)
func on_loading_finished() -> void:
phase = Phase.GOING