92 lines
3.1 KiB
GDScript
92 lines
3.1 KiB
GDScript
extends Control
|
|
|
|
@export var radio: Radio
|
|
@export var scroll_speed: float = 60.0
|
|
@export var wheel_speed: float = -2.0
|
|
|
|
@onready var track_label: Label = $%TrackLabel
|
|
@onready var prev_track_button: Button = $%PrevTrackButton
|
|
@onready var play_track_button: Button = $%PlayTrackButton
|
|
@onready var pause_track_button: Button = $%PauseTrackButton
|
|
@onready var next_track_button: Button = $%NextTrackButton
|
|
@onready var increase_volume_button: Button = $%IncreaseVolumeButton
|
|
@onready var decrease_volume_button: Button = $%DecreaseVolumeButton
|
|
@onready var left_wheel: TextureRect = $%LeftWheel
|
|
@onready var right_wheel: TextureRect = $%RightWheel
|
|
@onready var background: TextureRect = $%Background
|
|
|
|
func _ready() -> void:
|
|
prev_track_button.pressed.connect(_on_prev_track_button_pressed)
|
|
play_track_button.pressed.connect(_on_play_track_button_pressed)
|
|
pause_track_button.pressed.connect(_on_pause_track_button_pressed)
|
|
next_track_button.pressed.connect(_on_next_track_button_pressed)
|
|
increase_volume_button.pressed.connect(_on_increase_volume_button_pressed)
|
|
decrease_volume_button.pressed.connect(_on_decrease_volume_button_pressed)
|
|
if radio:
|
|
radio.track_changed.connect(_on_radio_track_changed)
|
|
if radio.stream and radio.stream.resource_path:
|
|
track_label.text = radio.stream.resource_path.get_file().get_basename().capitalize()
|
|
else:
|
|
track_label.text = "Unknown Track"
|
|
|
|
func _process(delta: float) -> void:
|
|
if radio and radio.playing and not radio.stream_paused:
|
|
if left_wheel:
|
|
left_wheel.rotation += wheel_speed * delta
|
|
if right_wheel:
|
|
right_wheel.rotation += wheel_speed * delta
|
|
|
|
if track_label and track_label.get_parent_control():
|
|
track_label.position.x += scroll_speed * delta
|
|
|
|
var text_width = track_label.get_minimum_size().x
|
|
|
|
var text_left_edge = track_label.position.x + (track_label.size.x - text_width) / 2.0
|
|
|
|
if text_left_edge > track_label.get_parent_control().size.x:
|
|
track_label.position.x = -(track_label.size.x + text_width) / 2.0
|
|
|
|
func _on_radio_track_changed(track_name: String) -> void:
|
|
track_label.text = track_name
|
|
|
|
func _play_button_tween() -> void:
|
|
TweenFX.stop_all(background)
|
|
background.scale = Vector2.ONE
|
|
background.rotation = 0.0
|
|
background.modulate.a = 1.0
|
|
TweenFX.press_rotate(background)
|
|
|
|
func _on_prev_track_button_pressed() -> void:
|
|
if radio:
|
|
radio.prev_track()
|
|
_play_button_tween()
|
|
|
|
func _on_play_track_button_pressed() -> void:
|
|
if radio:
|
|
if !radio.stream:
|
|
radio.next_track()
|
|
else:
|
|
radio.unpause()
|
|
_play_button_tween()
|
|
|
|
func _on_pause_track_button_pressed() -> void:
|
|
if radio:
|
|
if radio.stream:
|
|
radio.pause()
|
|
_play_button_tween()
|
|
|
|
func _on_next_track_button_pressed() -> void:
|
|
if radio:
|
|
radio.next_track()
|
|
_play_button_tween()
|
|
|
|
func _on_increase_volume_button_pressed() -> void:
|
|
var current_vol = AudioManager.get_audio_bus_volume("Music", 1.0)
|
|
AudioManager.set_audio_bus_volume("Music", current_vol + 0.1)
|
|
_play_button_tween()
|
|
|
|
func _on_decrease_volume_button_pressed() -> void:
|
|
var current_vol = AudioManager.get_audio_bus_volume("Music", 1.0)
|
|
AudioManager.set_audio_bus_volume("Music", current_vol - 0.1)
|
|
_play_button_tween()
|