WIP music control
This commit is contained in:
parent
f59bec5bbe
commit
48b253b93a
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bsafhva6xh2nf"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bsafhva6xh2nf"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/TimerHUD.gd" id="1_k2tpr"]
|
||||
[ext_resource type="PackedScene" uid="uid://cxho0ur4g4r2c" path="res://Scenes/circular_progress_bar.tscn" id="2_ptdoy"]
|
||||
[ext_resource type="AudioStream" uid="uid://cfn6m777tj8sy" path="res://Assets/Bob_lennon_-_Gutalala_sudalala.mp3" id="3_nfvhu"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_gikwe"]
|
||||
font_size = 100
|
||||
@ -173,7 +174,17 @@ offset_right = 152.0
|
||||
offset_bottom = 110.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
value = 50.0
|
||||
min_value = -24.0
|
||||
max_value = 0.0
|
||||
value = -12.0
|
||||
|
||||
[node name="BackgroundMusic" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource("3_nfvhu")
|
||||
volume_db = -28.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||
[connection signal="pressed" from="PlayButton" to="." method="_on_play_button_pressed"]
|
||||
@ -182,3 +193,4 @@ value = 50.0
|
||||
[connection signal="pressed" from="EditButton" to="." method="_on_edit_button_pressed"]
|
||||
[connection signal="value_changed" from="SpinBoxMinutes" to="." method="_on_spin_box_minutes_value_changed"]
|
||||
[connection signal="value_changed" from="SpinBoxSeconds" to="." method="_on_spin_box_seconds_value_changed"]
|
||||
[connection signal="drag_ended" from="VolumeSlider" to="." method="_on_volume_slider_drag_ended"]
|
||||
|
||||
@ -1,17 +1,27 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@export var default_seconds = 30
|
||||
@export var default_minutes = 1
|
||||
|
||||
@onready var background_music = $BackgroundMusic
|
||||
|
||||
var seconds
|
||||
var minutes
|
||||
var max_seconds
|
||||
var current_seconds
|
||||
var timer_is_playing = false
|
||||
signal play_timer
|
||||
|
||||
var edit_menu_visible = false
|
||||
|
||||
signal play_timer
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
# Get the length of the music
|
||||
if background_music.stream:
|
||||
var stream_length = background_music.stream.get_length()
|
||||
default_minutes = int(stream_length / 60)
|
||||
default_seconds = int(fmod(stream_length, 60))
|
||||
|
||||
reset_remaining_time_label()
|
||||
|
||||
$SpinBoxMinutes.get_line_edit().context_menu_enabled = false
|
||||
@ -28,8 +38,6 @@ func _ready():
|
||||
current_seconds = max_seconds
|
||||
#$CircularProgressBar.set_max_value(current_seconds)
|
||||
$CircularProgressBar.set_value(calculate_equivalent_progress(current_seconds))
|
||||
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
@ -57,19 +65,22 @@ func stop_timer():
|
||||
$Timer.paused = false
|
||||
$Timer.stop()
|
||||
$CircularProgressBar.set_value(calculate_equivalent_progress(max_seconds))
|
||||
background_music.stop()
|
||||
|
||||
func calculate_equivalent_progress(value):
|
||||
return (value * 100) / max_seconds
|
||||
|
||||
func _on_play_button_pressed():
|
||||
|
||||
func _on_play_button_pressed():
|
||||
if $Timer.is_paused():
|
||||
$Timer.paused = false
|
||||
background_music.stream_paused = false
|
||||
timer_is_playing = true
|
||||
else:
|
||||
if !timer_is_playing:
|
||||
timer_is_playing = true
|
||||
reset_timer()
|
||||
$Timer.start()
|
||||
background_music.play()
|
||||
|
||||
func _on_timer_timeout():
|
||||
if seconds == 0:
|
||||
@ -78,6 +89,7 @@ func _on_timer_timeout():
|
||||
seconds == 60
|
||||
else:
|
||||
$Timer.stop()
|
||||
background_music.stop()
|
||||
elif seconds > 0:
|
||||
seconds -= 1
|
||||
current_seconds -= 1
|
||||
@ -91,6 +103,7 @@ func _on_timer_timeout():
|
||||
func _on_pause_button_pressed():
|
||||
timer_is_playing = false
|
||||
$Timer.paused = true
|
||||
background_music.stream_paused = true
|
||||
|
||||
|
||||
func _on_stop_button_pressed():
|
||||
@ -110,7 +123,7 @@ func _on_edit_button_pressed():
|
||||
|
||||
# Check if the edit menu is not visible and stops the timer in this case
|
||||
if !edit_menu_visible:
|
||||
stop_timer()
|
||||
stop_timer()
|
||||
|
||||
# Toggle the value of 'edit_menu_visible'
|
||||
edit_menu_visible = !edit_menu_visible
|
||||
@ -124,3 +137,8 @@ func _on_spin_box_minutes_value_changed(value):
|
||||
func _on_spin_box_seconds_value_changed(value):
|
||||
default_seconds = $SpinBoxSeconds.value
|
||||
reset_remaining_time_label()
|
||||
|
||||
|
||||
func _on_volume_slider_drag_ended(value_changed):
|
||||
background_music.volume_db = $VolumeSlider.value
|
||||
print($VolumeSlider.value)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user