aboutsummaryrefslogtreecommitdiff
path: root/game/src/MusicConductor/MusicPlayer.gd
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-03-08 23:15:15 +0100
committer Spartan322 <Megacake1234@gmail.com>2023-03-09 02:18:39 +0100
commit99c99ce56bb3e73e65ff70352d4c9eef3d7f0f86 (patch)
treef3808a85792e5d58db8297211e5887b0c92d29d5 /game/src/MusicConductor/MusicPlayer.gd
parentec0584d9fafd96753aed73e7c388da8e2f5b3833 (diff)
Fix up MusicPlayer for future work
Add music import files Rename MusicUIController to MusicPlayer Adjust MusicPlayer node position, offset, and anchors Adjust MusicConductor, MusicPlayer, and SongInfo style to conform with other GDScript files Correct capability for MusicPlayer to desync from the MusicConductor Adjusted MusicPlayer button text to use media player unicode symbols Adjust MusicPlayer to correct mouse filter problems Adjust MusicPlayer to appear more consistent Correct lack of path_join use in SongInfo Correct mouse filter problems in OptionsMenu
Diffstat (limited to 'game/src/MusicConductor/MusicPlayer.gd')
-rw-r--r--game/src/MusicConductor/MusicPlayer.gd68
1 files changed, 68 insertions, 0 deletions
diff --git a/game/src/MusicConductor/MusicPlayer.gd b/game/src/MusicConductor/MusicPlayer.gd
new file mode 100644
index 0000000..baf8a43
--- /dev/null
+++ b/game/src/MusicConductor/MusicPlayer.gd
@@ -0,0 +1,68 @@
+extends Control
+
+@export var _song_selector_button : OptionButton
+@export var _progress_slider : HSlider
+@export var _previous_song_button : Button
+@export var _play_pause_button : Button
+@export var _next_song_button : Button
+@export var _visbility_button : Button
+
+var _is_user_dragging_progress_slider : bool = false
+
+func _ready():
+ for songName in MusicConductor.get_all_song_names():
+ _song_selector_button.add_item(songName, _song_selector_button.item_count)
+ _update_song_name_visual()
+ _update_play_pause_button()
+ _set_music_player_visible(MusicConductor.is_music_player_visible)
+
+
+func _process(_delta):
+ if !_is_user_dragging_progress_slider:
+ _progress_slider.value = MusicConductor.get_current_song_progress_percentage()
+
+func _update_song_name_visual():
+ _song_selector_button.selected = MusicConductor.get_current_song_index()
+
+func _update_play_pause_button():
+ _play_pause_button.text = "◼" if MusicConductor.is_paused() else "▶"
+
+func _on_play_pause_button_pressed():
+ MusicConductor.toggle_play_pause()
+ _update_play_pause_button()
+
+func _on_next_song_button_pressed():
+ MusicConductor.select_next_song()
+ _update_song_name_visual()
+ _update_play_pause_button()
+
+func _on_previous_song_button_pressed():
+ MusicConductor.select_previous_song()
+ _update_song_name_visual()
+ _update_play_pause_button()
+
+func _on_option_button_item_selected(index):
+ # UIFUN-92
+ MusicConductor.start_song_by_index(index)
+
+
+func _on_progress_slider_drag_started():
+ _is_user_dragging_progress_slider = true
+
+
+func _on_progress_slider_drag_ended(_value_changed):
+ MusicConductor.scrub_song_by_percentage(_progress_slider.value)
+ _is_user_dragging_progress_slider = false
+ _update_play_pause_button()
+
+func _set_music_player_visible(is_player_visible : bool) -> void:
+ MusicConductor.is_music_player_visible = is_player_visible
+ _visbility_button.text = "⬆️" if is_player_visible else "⬇"
+ _song_selector_button.visible = is_player_visible
+ _progress_slider.visible = is_player_visible
+ _previous_song_button.visible = is_player_visible
+ _play_pause_button.visible = is_player_visible
+ _next_song_button.visible = is_player_visible
+
+func _on_music_ui_visibility_button_pressed():
+ _set_music_player_visible(not MusicConductor.is_music_player_visible)