aboutsummaryrefslogtreecommitdiff
path: root/game/src/MusicConductor/MusicUIController.gd
blob: f2c92251eca5fdb15fe00b04fcfff97850f7bbc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
extends Control

@export var songSelectorButton : OptionButton
@export var progressSlider : HSlider
@export var prevSongButton : Button
@export var playPauseButton : Button
@export var nextSongButton : Button
@export var widgetVisibilityButton : Button

var isMusicPlayerVisible : bool = true
var isUserDraggingProgressSlider : bool = false

# Called when the node enters the scene tree for the first time.
func _ready():
   for songName in MusicConductor.getAllSongNames():
      songSelectorButton.add_item(songName, songSelectorButton.item_count)
   updateSongNameVisual()


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
   if !isUserDraggingProgressSlider:
      progressSlider.value = MusicConductor.getCurrentSongProgressPercentage()

func updateSongNameVisual():
   songSelectorButton.selected = MusicConductor.getCurrentSongIndex()

func updatePlayPauseButtonVisual():
   playPauseButton.text = "||" if MusicConductor.isPaused() else ">"

func _on_play_pause_button_pressed():
   MusicConductor.togglePlayPause()
   updatePlayPauseButtonVisual()

func _on_next_song_button_pressed():
   MusicConductor.nextSong()
   updateSongNameVisual()
   updatePlayPauseButtonVisual()

func _on_previous_song_button_pressed():
   MusicConductor.prevSong()
   updateSongNameVisual()
   updatePlayPauseButtonVisual()

func _on_option_button_item_selected(index):
   # UIFUN-92
   MusicConductor.startSongByIndex(index)


func _on_progress_slider_drag_started():
   isUserDraggingProgressSlider = true


func _on_progress_slider_drag_ended(_value_changed):
   MusicConductor.scrubSongByPercentage(progressSlider.value)
   isUserDraggingProgressSlider = false
   updatePlayPauseButtonVisual()

func _on_music_ui_visibility_button_pressed():
   isMusicPlayerVisible = !isMusicPlayerVisible
   widgetVisibilityButton.text = "Hide Player" if isMusicPlayerVisible else "Show Player"
   songSelectorButton.visible = isMusicPlayerVisible
   progressSlider.visible = isMusicPlayerVisible
   prevSongButton.visible = isMusicPlayerVisible
   playPauseButton.visible = isMusicPlayerVisible
   nextSongButton.visible = isMusicPlayerVisible