78 lines
2.3 KiB
GDScript
78 lines
2.3 KiB
GDScript
extends Node
|
|
|
|
@onready var Start: Button = %Start
|
|
@onready var Quit: Button = %Quit
|
|
@onready var background: TextureRect = %Background
|
|
@onready var music_player: AudioStreamPlayer = %MusicPlayer
|
|
@onready var transition_rect: ColorRect = %TransitionRect
|
|
@onready var version_label: Label = %VersionLabel
|
|
@onready var game_infos: Control = %GameInfos
|
|
|
|
@export var progression_backgrounds: Array[Texture2D] = []
|
|
@export var menu_music: AudioStream
|
|
@export var start_click_sound: AudioStream
|
|
|
|
const GAME_SCENE_PATH := "res://game/world/main.tscn"
|
|
const MUSIC_FADE_DURATION := 0.8
|
|
const SCREEN_FADE_DURATION := 0.6
|
|
|
|
var is_transitioning : bool = false
|
|
|
|
func _ready() -> void:
|
|
update_background()
|
|
setup_version_label()
|
|
play_menu_music()
|
|
fade_in_game_infos()
|
|
|
|
func _process(delta: float) -> void:
|
|
if !is_transitioning:
|
|
Start.grab_focus()
|
|
|
|
func update_background() -> void:
|
|
if progression_backgrounds.is_empty():
|
|
return
|
|
var stage : int = clampi(GameData.story_progress, 0, progression_backgrounds.size() - 1)
|
|
background.texture = progression_backgrounds[stage]
|
|
|
|
func setup_version_label() -> void:
|
|
var version : String = ProjectSettings.get_setting("application/config/version", "")
|
|
version_label.text = "v%s" % version if version != "" else ""
|
|
|
|
func play_menu_music() -> void:
|
|
if !menu_music: return
|
|
music_player.stream = menu_music
|
|
music_player.volume_db = -80.0
|
|
music_player.play()
|
|
var tween := create_tween()
|
|
tween.tween_property(music_player, "volume_db", 0.0, MUSIC_FADE_DURATION)
|
|
|
|
func fade_in_game_infos() -> void:
|
|
game_infos.modulate.a = 0.0
|
|
var tween := create_tween()
|
|
tween.tween_property(game_infos, "modulate:a", 1.0, 1.0)
|
|
|
|
func _on_start_pressed() -> void:
|
|
if is_transitioning: return
|
|
is_transitioning = true
|
|
play_click_sound()
|
|
start_transition_to(GAME_SCENE_PATH)
|
|
|
|
func play_click_sound() -> void:
|
|
UiAudio.play(start_click_sound)
|
|
|
|
func _on_quit_pressed() -> void:
|
|
get_tree().quit()
|
|
|
|
func start_transition_to(scene_path : String) -> void:
|
|
if music_player.playing:
|
|
var music_tween := create_tween()
|
|
music_tween.tween_property(music_player, "volume_db", -80.0, MUSIC_FADE_DURATION)
|
|
|
|
transition_rect.visible = true
|
|
transition_rect.modulate.a = 0.0
|
|
var screen_tween := create_tween()
|
|
screen_tween.tween_property(transition_rect, "modulate:a", 1.0, SCREEN_FADE_DURATION)
|
|
await screen_tween.finished
|
|
|
|
get_tree().change_scene_to_file(scene_path)
|