aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/MusicConductor
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-06-24 00:55:45 +0200
committer GitHub <noreply@github.com>2023-06-24 00:55:45 +0200
commit432000a3ab73980fc6421b3587de4b97af30d3ad (patch)
tree4b80d98261252f25011e34b22a8d49767525559f /game/src/Game/MusicConductor
parent40cf0fa95e325f3bf875e42c11254da23192f506 (diff)
parent206cafc8bba310e4d4f35f4898ef3ac289abe81a (diff)
Merge pull request #131 from OpenVicProject/ui-cleanup
Localisation and UI focus cleanup
Diffstat (limited to 'game/src/Game/MusicConductor')
-rw-r--r--game/src/Game/MusicConductor/MusicConductor.gd26
-rw-r--r--game/src/Game/MusicConductor/MusicConductor.tscn3
-rw-r--r--game/src/Game/MusicConductor/MusicPlayer.tscn6
3 files changed, 27 insertions, 8 deletions
diff --git a/game/src/Game/MusicConductor/MusicConductor.gd b/game/src/Game/MusicConductor/MusicConductor.gd
index 98dd0eb..da0fb1e 100644
--- a/game/src/Game/MusicConductor/MusicConductor.gd
+++ b/game/src/Game/MusicConductor/MusicConductor.gd
@@ -5,6 +5,8 @@ extends Node
@export_dir var music_directory : String
@export var first_song_name : String
+@export var _audio_stream_player : AudioStreamPlayer
+
var _selected_track = 0
var _available_songs : Array[SongInfo] = []
var _auto_play_next_song : bool = true
@@ -13,6 +15,8 @@ var _auto_play_next_song : bool = true
## Used to keep keep consistency between scene changes
var is_music_player_visible : bool = true
+var _has_startup_happened : bool = false
+
func get_all_song_names() -> Array[String]:
var songNames : Array[String] = []
for si in _available_songs:
@@ -26,21 +30,24 @@ func get_current_song_name() -> String:
return _available_songs[_selected_track].song_name
func scrub_song_by_percentage(percentage: float) -> void:
- var percentInSeconds : float = (percentage / 100.0) * $AudioStreamPlayer.stream.get_length()
- $AudioStreamPlayer.play(percentInSeconds)
+ var percentInSeconds : float = (percentage / 100.0) * _audio_stream_player.stream.get_length()
+ _audio_stream_player.play(percentInSeconds)
func get_current_song_progress_percentage() -> float:
- return 100 * ($AudioStreamPlayer.get_playback_position() / $AudioStreamPlayer.stream.get_length())
+ return 100 * (_audio_stream_player.get_playback_position() / _audio_stream_player.stream.get_length())
func is_paused() -> bool:
- return $AudioStreamPlayer.stream_paused
+ return _audio_stream_player.stream_paused
+
+func set_paused(paused : bool) -> void:
+ _audio_stream_player.stream_paused = paused
func toggle_play_pause() -> void:
- $AudioStreamPlayer.stream_paused = !$AudioStreamPlayer.stream_paused
+ _audio_stream_player.stream_paused = !_audio_stream_player.stream_paused
func start_current_song() -> void:
- $AudioStreamPlayer.stream = _available_songs[_selected_track].song_stream
- $AudioStreamPlayer.play()
+ _audio_stream_player.stream = _available_songs[_selected_track].song_stream
+ _audio_stream_player.play()
# REQUIREMENTS
# * SS-70
@@ -69,7 +76,12 @@ func _ready():
_selected_track = _available_songs.size()
_available_songs.append(SongInfo.new(music_directory, fname))
start_current_song()
+ set_paused(true)
+func set_startup_music(play : bool) -> void:
+ if not _has_startup_happened:
+ _has_startup_happened = true
+ set_paused(not play)
func _on_audio_stream_player_finished():
if _auto_play_next_song:
diff --git a/game/src/Game/MusicConductor/MusicConductor.tscn b/game/src/Game/MusicConductor/MusicConductor.tscn
index 3c288be..a943f24 100644
--- a/game/src/Game/MusicConductor/MusicConductor.tscn
+++ b/game/src/Game/MusicConductor/MusicConductor.tscn
@@ -2,10 +2,11 @@
[ext_resource type="Script" path="res://src/Game/MusicConductor/MusicConductor.gd" id="1_56t1b"]
-[node name="MusicConductor" type="Node"]
+[node name="MusicConductor" type="Node" node_paths=PackedStringArray("_audio_stream_player")]
script = ExtResource("1_56t1b")
music_directory = "res://audio/music"
first_song_name = "The_Crown"
+_audio_stream_player = NodePath("AudioStreamPlayer")
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
bus = &"MUSIC_BUS"
diff --git a/game/src/Game/MusicConductor/MusicPlayer.tscn b/game/src/Game/MusicConductor/MusicPlayer.tscn
index 8d47ba0..498750d 100644
--- a/game/src/Game/MusicConductor/MusicPlayer.tscn
+++ b/game/src/Game/MusicConductor/MusicPlayer.tscn
@@ -20,6 +20,7 @@ _visbility_button = NodePath("MusicUIVisibilityButton")
editor_description = "UI-107"
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
+focus_mode = 0
alignment = 1
text_overrun_behavior = 3
fit_to_longest_item = false
@@ -28,6 +29,7 @@ fit_to_longest_item = false
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_vertical = 1
+focus_mode = 0
[node name="ButtonList" type="HBoxContainer" parent="."]
layout_mode = 2
@@ -36,21 +38,25 @@ mouse_filter = 2
[node name="PreviousSongButton" type="Button" parent="ButtonList"]
layout_mode = 2
+focus_mode = 0
text = "<"
[node name="PlayPauseButton" type="Button" parent="ButtonList"]
custom_minimum_size = Vector2(30, 0)
layout_mode = 2
+focus_mode = 0
text = "▶"
[node name="NextSongButton" type="Button" parent="ButtonList"]
layout_mode = 2
+focus_mode = 0
text = ">"
[node name="MusicUIVisibilityButton" type="Button" parent="."]
editor_description = "UI-106"
layout_mode = 2
size_flags_horizontal = 4
+focus_mode = 0
toggle_mode = true
text = "⬆"