Modifications in organizations of the UI and created a settings window. Still working in the selection of music

This commit is contained in:
JKuijperM 2024-03-31 16:58:25 +02:00
parent 48b253b93a
commit e4d54291dc
8 changed files with 398 additions and 203 deletions

View File

@ -1,196 +1,201 @@
[gd_scene load_steps=5 format=3 uid="uid://bsafhva6xh2nf"] [gd_scene load_steps=9 format=3 uid="uid://bsafhva6xh2nf"]
[ext_resource type="Script" path="res://Scripts/TimerHUD.gd" id="1_k2tpr"] [ext_resource type="Script" path="res://Scripts/TimerHUD.gd" id="1_k2tpr"]
[ext_resource type="Texture2D" uid="uid://r110qxfj048e" path="res://Assets/grey_panel_480x720.png" id="2_02r40"]
[ext_resource type="PackedScene" uid="uid://cxho0ur4g4r2c" path="res://Scenes/circular_progress_bar.tscn" id="2_ptdoy"] [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"] [ext_resource type="AudioStream" uid="uid://ce4iak7i31m6t" path="res://Assets/Sounds/MyVeryOwnDeadShip.ogg" id="3_ammvr"]
[ext_resource type="AudioStream" uid="uid://bdnqyf6n8f83g" path="res://Assets/Sounds/alert_klaxxon.wav" id="4_ltch4"]
[sub_resource type="LabelSettings" id="LabelSettings_gikwe"] [ext_resource type="Texture2D" uid="uid://c245n812q2pet" path="res://Assets/musicOn.png" id="5_sqe4u"]
font_size = 100 [ext_resource type="Texture2D" uid="uid://cun5e60lsax4b" path="res://Assets/audioOn.png" id="6_6gv2t"]
[ext_resource type="PackedScene" uid="uid://cnytyqfx2oecx" path="res://Scenes/settings_menu.tscn" id="8_05rx5"]
[node name="TimerHUD" type="CanvasLayer"] [node name="TimerHUD" type="CanvasLayer"]
script = ExtResource("1_k2tpr") script = ExtResource("1_k2tpr")
[node name="TextureRect" type="TextureRect" parent="."]
visible = false
offset_left = 12.0
offset_top = 12.0
offset_right = 492.0
offset_bottom = 732.0
texture = ExtResource("2_02r40")
[node name="ColorRect" type="ColorRect" parent="."]
offset_left = 12.0
offset_top = 12.0
offset_right = 468.0
offset_bottom = 708.0
color = Color(0.372549, 0.764706, 0.568627, 1)
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
[node name="RemainingTime" type="Label" parent="."] [node name="BackgroundMusic" type="AudioStreamPlayer" parent="."]
anchors_preset = 8 stream = ExtResource("3_ammvr")
anchor_left = 0.5 volume_db = -28.0
anchor_top = 0.5
anchor_right = 0.5 [node name="AlertSound" type="AudioStreamPlayer" parent="."]
anchor_bottom = 0.5 stream = ExtResource("4_ltch4")
offset_left = -240.0 volume_db = -28.0
offset_top = -183.0
offset_right = 240.0 [node name="MarginContainer" type="MarginContainer" parent="."]
offset_bottom = -46.0 anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
text = "xx:xx" theme_override_constants/margin_left = 12
label_settings = SubResource("LabelSettings_gikwe") theme_override_constants/margin_top = 12
horizontal_alignment = 1 theme_override_constants/margin_right = 12
vertical_alignment = 1 theme_override_constants/margin_bottom = 12
[node name="PlayButton" type="Button" parent="."] [node name="VBoxContainer2" type="VBoxContainer" parent="MarginContainer"]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -50.0
offset_top = -208.0
offset_right = 50.0
offset_bottom = -158.0
grow_horizontal = 2
grow_vertical = 0
size_flags_vertical = 6
text = "PLAY"
[node name="PauseButton" type="Button" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer2"]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5 size_flags_horizontal = 8
anchor_top = 1.0 size_flags_vertical = 0
anchor_right = 0.5
anchor_bottom = 1.0 [node name="SettingsButton" type="Button" parent="MarginContainer/VBoxContainer2/VBoxContainer"]
offset_left = -153.5 layout_mode = 2
offset_top = -208.0 text = "Settings
offset_right = -53.5
offset_bottom = -158.0
grow_horizontal = 2
grow_vertical = 0
text = "Pause
" "
[node name="StopButton" type="Button" parent="."] [node name="ExitButton" type="Button" parent="MarginContainer/VBoxContainer2/VBoxContainer"]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5 text = "Close
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = 52.98
offset_top = -208.0
offset_right = 152.98
offset_bottom = -158.0
grow_horizontal = 2
grow_vertical = 0
text = "Stop
" "
[node name="EditButton" type="Button" parent="."] [node name="CircularProgressBar" parent="MarginContainer/VBoxContainer2" instance=ExtResource("2_ptdoy")]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5 size_flags_vertical = 3
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = 166.0
offset_top = -197.0
offset_right = 206.0
offset_bottom = -166.0
grow_horizontal = 2
grow_vertical = 0
size_flags_vertical = 6
text = "Edit"
[node name="MinutesLabel" type="Label" parent="."] [node name="VBoxContainer2" type="VBoxContainer" parent="MarginContainer/VBoxContainer2"]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5 size_flags_vertical = 10
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -88.5
offset_top = -138.0
offset_right = -25.5
offset_bottom = -115.0
grow_horizontal = 2
grow_vertical = 0
text = "Minutes"
[node name="SecondsLabel" type="Label" parent="."] [node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2"]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5 size_flags_horizontal = 4
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = 20.0
offset_top = -138.0
offset_right = 84.0
offset_bottom = -115.0
grow_horizontal = 2
grow_vertical = 0
text = "Seconds"
[node name="SpinBoxMinutes" type="SpinBox" parent="."] [node name="TextureRect" type="TextureRect" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer2"]
anchors_preset = 7 layout_mode = 2
anchor_left = 0.5 texture = ExtResource("5_sqe4u")
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -100.0
offset_top = -98.0
offset_bottom = -48.0
grow_horizontal = 2
grow_vertical = 0
max_value = 60.0
alignment = 2
editable = false
[node name="SpinBoxSeconds" type="SpinBox" parent="."] [node name="VolumeMusicSlider" type="HSlider" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer2"]
anchors_preset = 7 custom_minimum_size = Vector2(300, 0)
anchor_left = 0.5 layout_mode = 2
anchor_top = 1.0 size_flags_vertical = 1
anchor_right = 0.5 size_flags_stretch_ratio = 0.0
anchor_bottom = 1.0
offset_left = 10.0
offset_top = -98.0
offset_right = 110.0
offset_bottom = -48.0
grow_horizontal = 2
grow_vertical = 0
max_value = 59.0
alignment = 2
editable = false
[node name="CircularProgressBar" parent="." instance=ExtResource("2_ptdoy")]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = 1.52588e-05
offset_top = -104.0
offset_right = 1.52588e-05
offset_bottom = -104.0
grow_horizontal = 2
grow_vertical = 2
size_flags_vertical = 4
[node name="VolumeSlider" type="HSlider" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -144.0
offset_top = 90.0
offset_right = 152.0
offset_bottom = 110.0
grow_horizontal = 2
grow_vertical = 2
min_value = -24.0 min_value = -24.0
max_value = 0.0 max_value = 0.0
value = -12.0 value = -12.0
[node name="BackgroundMusic" type="AudioStreamPlayer" parent="."] [node name="HBoxContainer4" type="HBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2"]
stream = ExtResource("3_nfvhu") layout_mode = 2
volume_db = -28.0 size_flags_horizontal = 4
[node name="HBoxContainer" type="HBoxContainer" parent="."] [node name="TextureRect" type="TextureRect" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer4"]
offset_right = 40.0 layout_mode = 2
offset_bottom = 40.0 texture = ExtResource("6_6gv2t")
[node name="VolumeSoundSlider" type="HSlider" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer4"]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
size_flags_vertical = 1
size_flags_stretch_ratio = 0.0
min_value = -24.0
max_value = 0.0
value = -12.0
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 4
[node name="PauseButton" type="Button" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
text = "Pause
"
[node name="PlayButton" type="Button" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
size_flags_vertical = 6
text = "PLAY"
[node name="StopButton" type="Button" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
text = "Stop
"
[node name="EditButton" type="Button" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer"]
custom_minimum_size = Vector2(40, 30)
layout_mode = 2
size_flags_vertical = 6
text = "Edit"
[node name="HBoxContainer3" type="HBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 4
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3"]
layout_mode = 2
size_flags_horizontal = 4
[node name="MinutesLabel" type="Label" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer"]
layout_mode = 2
text = "Minutes"
horizontal_alignment = 1
[node name="SpinBoxMinutes" type="SpinBox" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer"]
layout_mode = 2
max_value = 60.0
alignment = 2
editable = false
[node name="VBoxContainer2" type="VBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3"]
layout_mode = 2
size_flags_horizontal = 4
[node name="SecondsLabel" type="Label" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer2"]
layout_mode = 2
text = "Seconds"
horizontal_alignment = 1
[node name="SpinBoxSeconds" type="SpinBox" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer2"]
custom_minimum_size = Vector2(30, 30)
layout_mode = 2
max_value = 59.0
alignment = 2
editable = false
[node name="HBoxContainer5" type="HBoxContainer" parent="MarginContainer/VBoxContainer2/VBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 4
[node name="UntilEndSecondsLabel" type="Label" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer5"]
layout_mode = 2
text = "Seconds until the end"
[node name="UntilEndSecondsCB" type="CheckBox" parent="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer5"]
layout_mode = 2
[node name="SettingsMenu" parent="." instance=ExtResource("8_05rx5")]
visible = false
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
[connection signal="pressed" from="PlayButton" to="." method="_on_play_button_pressed"] [connection signal="pressed" from="MarginContainer/VBoxContainer2/VBoxContainer/SettingsButton" to="." method="_on_settings_button_pressed"]
[connection signal="pressed" from="PauseButton" to="." method="_on_pause_button_pressed"] [connection signal="pressed" from="MarginContainer/VBoxContainer2/VBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"]
[connection signal="pressed" from="StopButton" to="." method="_on_stop_button_pressed"] [connection signal="drag_ended" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer2/VolumeMusicSlider" to="." method="_on_volume_music_slider_drag_ended"]
[connection signal="pressed" from="EditButton" to="." method="_on_edit_button_pressed"] [connection signal="value_changed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer2/VolumeMusicSlider" to="." method="_on_volume_music_slider_value_changed"]
[connection signal="value_changed" from="SpinBoxMinutes" to="." method="_on_spin_box_minutes_value_changed"] [connection signal="value_changed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer4/VolumeSoundSlider" to="." method="_on_volume_sound_slider_value_changed"]
[connection signal="value_changed" from="SpinBoxSeconds" to="." method="_on_spin_box_seconds_value_changed"] [connection signal="pressed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer/PauseButton" to="." method="_on_pause_button_pressed"]
[connection signal="drag_ended" from="VolumeSlider" to="." method="_on_volume_slider_drag_ended"] [connection signal="pressed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer/PlayButton" to="." method="_on_play_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer/StopButton" to="." method="_on_stop_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer/EditButton" to="." method="_on_edit_button_pressed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer/SpinBoxMinutes" to="." method="_on_spin_box_minutes_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer2/SpinBoxSeconds" to="." method="_on_spin_box_seconds_value_changed"]
[connection signal="back_settings_menu" from="SettingsMenu" to="." method="_on_settings_menu_back_settings_menu"]
[connection signal="selected_music_file" from="SettingsMenu" to="." method="_on_settings_menu_selected_music_file"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://cxho0ur4g4r2c"] [gd_scene load_steps=9 format=3 uid="uid://cxho0ur4g4r2c"]
[ext_resource type="Script" path="res://Scripts/circular_progress_bar.gd" id="2_c3xrc"] [ext_resource type="Script" path="res://Scripts/circular_progress_bar.gd" id="2_c3xrc"]
[ext_resource type="Shader" path="res://Scripts/Shaders/circular_progress_bar.gdshader" id="4_8eawh"] [ext_resource type="Shader" path="res://Scripts/Shaders/circular_progress_bar.gdshader" id="4_8eawh"]
@ -11,21 +11,24 @@ colors = PackedColorArray(0, 0, 0, 0.521569)
gradient = SubResource("Gradient_0ph84") gradient = SubResource("Gradient_0ph84")
[sub_resource type="Gradient" id="Gradient_0ugux"] [sub_resource type="Gradient" id="Gradient_0ugux"]
offsets = PackedFloat32Array(1) offsets = PackedFloat32Array(0, 0.116883)
colors = PackedColorArray(0, 0, 0.921569, 1) colors = PackedColorArray(1, 0.00392157, 0, 1, 0, 0, 0.921569, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_kdn2m"] [sub_resource type="GradientTexture1D" id="GradientTexture1D_kdn2m"]
gradient = SubResource("Gradient_0ugux") gradient = SubResource("Gradient_0ugux")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ht6os"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_ht6os"]
shader = ExtResource("4_8eawh") shader = ExtResource("4_8eawh")
shader_parameter/value = 25.0 shader_parameter/value = 21.19
shader_parameter/thickness = 15.0 shader_parameter/thickness = 15.0
shader_parameter/offset = null shader_parameter/offset = null
shader_parameter/smoothing = 5.0 shader_parameter/smoothing = 5.0
shader_parameter/fg = SubResource("GradientTexture1D_kdn2m") shader_parameter/fg = SubResource("GradientTexture1D_kdn2m")
shader_parameter/bg = SubResource("GradientTexture1D_fwgo2") shader_parameter/bg = SubResource("GradientTexture1D_fwgo2")
[sub_resource type="LabelSettings" id="LabelSettings_gssec"]
font_size = 100
[node name="CircularProgressBar" type="Control"] [node name="CircularProgressBar" type="Control"]
layout_mode = 3 layout_mode = 3
anchors_preset = 0 anchors_preset = 0
@ -47,3 +50,18 @@ offset_left = -155.0
offset_top = -155.0 offset_top = -155.0
offset_right = 155.0 offset_right = 155.0
offset_bottom = 155.0 offset_bottom = 155.0
[node name="RemainingTime" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.5
anchor_top = 0.517
anchor_right = 0.5
anchor_bottom = 0.517
offset_left = -120.0
offset_top = -68.51
offset_right = 127.0
offset_bottom = 68.49
size_flags_horizontal = 4
text = "xx:xx"
label_settings = SubResource("LabelSettings_gssec")

73
Scenes/settings_menu.tscn Normal file
View File

@ -0,0 +1,73 @@
[gd_scene load_steps=3 format=3 uid="uid://cnytyqfx2oecx"]
[ext_resource type="Script" path="res://Scripts/settings_menu.gd" id="1_5guik"]
[sub_resource type="LabelSettings" id="LabelSettings_68hly"]
font_size = 20
[node name="SettingsMenu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_5guik")
[node name="FileDialog" type="FileDialog" parent="."]
title = "Open a File"
initial_position = 2
size = Vector2i(392, 250)
ok_button_text = "Open"
dialog_hide_on_ok = true
file_mode = 0
access = 2
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_top = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_bottom = 12
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/separation = -48
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Options"
horizontal_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
[node name="BacgroundMusicLabel" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Background music: "
label_settings = SubResource("LabelSettings_68hly")
[node name="BacgroundMusicLineEdit" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="SelectMusicButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Open file"
[node name="BackButton" type="Button" parent="MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
text = "Back"
[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer/SelectMusicButton" to="." method="_on_select_music_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/BackButton" to="." method="_on_back_button_pressed"]

View File

@ -2,8 +2,8 @@ extends Control
var seconds var seconds
var minutes var minutes
var default_seconds = 30 var default_seconds = 10
var default_minutes = 1 var default_minutes = 0
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
reset_timer() reset_timer()

View File

@ -2,8 +2,28 @@ extends CanvasLayer
@export var default_seconds = 30 @export var default_seconds = 30
@export var default_minutes = 1 @export var default_minutes = 1
@export var alert_seconds = 5
@onready var background_music = $BackgroundMusic # AudioStreamPlayer
@onready var background_music: AudioStreamPlayer = $BackgroundMusic
@onready var alert_sound: AudioStreamPlayer = $AlertSound
# SpinBox
@onready var sb_minutes: SpinBox = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer/SpinBoxMinutes
@onready var sb_seconds: SpinBox = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer2/SpinBoxSeconds
# Label
@onready var minutes_label: Label = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer/MinutesLabel
@onready var seconds_label: Label = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer3/VBoxContainer2/SecondsLabel
@onready var until_end_sec_label: Label = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer5/UntilEndSecondsLabel
# Checkbox
@onready var until_end_sec_cb: CheckBox = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer5/UntilEndSecondsCB
# Slider
@onready var volume_music_slider: Slider = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer2/VolumeMusicSlider
@onready var volume_sound_slider: Slider = $MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer4/VolumeSoundSlider
# Control
@onready var settings_menu: Control = $SettingsMenu
@onready var circular_progress_bar: Control = $MarginContainer/VBoxContainer2/CircularProgressBar
# MarginContainer
@onready var margin_container: MarginContainer = $MarginContainer
var seconds var seconds
var minutes var minutes
@ -24,20 +44,23 @@ func _ready():
reset_remaining_time_label() reset_remaining_time_label()
$SpinBoxMinutes.get_line_edit().context_menu_enabled = false # Initialize the status of the edit components
$SpinBoxMinutes.value = default_minutes sb_minutes.get_line_edit().context_menu_enabled = false
$SpinBoxSeconds.get_line_edit().context_menu_enabled = false sb_minutes.value = default_minutes
$SpinBoxSeconds.value = default_seconds sb_seconds.get_line_edit().context_menu_enabled = false
$SpinBoxMinutes.visible = false sb_seconds.value = default_seconds
$SpinBoxSeconds.visible = false sb_minutes.visible = false
$MinutesLabel.visible = false sb_seconds.visible = false
$SecondsLabel.visible = false minutes_label.visible = false
seconds_label.visible = false
until_end_sec_cb.visible = false
until_end_sec_label.visible = false
# Calculate the total seconds # Calculate the total seconds
max_seconds = default_minutes * 60 + default_seconds max_seconds = default_minutes * 60 + default_seconds
current_seconds = max_seconds current_seconds = max_seconds
#$CircularProgressBar.set_max_value(current_seconds) #$CircularProgressBar.set_max_value(current_seconds)
$CircularProgressBar.set_value(calculate_equivalent_progress(current_seconds)) circular_progress_bar.set_value(calculate_equivalent_progress(current_seconds))
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
@ -56,7 +79,7 @@ func reset_remaining_time_label():
## Resets the value of the label ## Resets the value of the label
var minutes_str = str(default_minutes) if default_minutes >= 10 else "0" + str(default_minutes) var minutes_str = str(default_minutes) if default_minutes >= 10 else "0" + str(default_minutes)
var seconds_str = str(default_seconds) if default_seconds >= 10 else "0" + str(default_seconds) var seconds_str = str(default_seconds) if default_seconds >= 10 else "0" + str(default_seconds)
$RemainingTime.text = minutes_str + ":" + seconds_str circular_progress_bar.set_remining_time(minutes_str + ":" + seconds_str)
func stop_timer(): func stop_timer():
## Stops the timer, sets as 'false' the timer_is_playing flag and also ## Stops the timer, sets as 'false' the timer_is_playing flag and also
@ -64,12 +87,22 @@ func stop_timer():
timer_is_playing = false timer_is_playing = false
$Timer.paused = false $Timer.paused = false
$Timer.stop() $Timer.stop()
$CircularProgressBar.set_value(calculate_equivalent_progress(max_seconds)) circular_progress_bar.set_value(calculate_equivalent_progress(max_seconds))
background_music.stop() background_music.stop()
func calculate_equivalent_progress(value): func calculate_equivalent_progress(value):
return (value * 100) / max_seconds return (value * 100) / max_seconds
func play_music():
if background_music.stream:
if until_end_sec_cb.button_pressed:
var start_from_second = background_music.stream.get_length() - \
(default_minutes * 60 + default_seconds)
background_music.play(start_from_second)
else:
background_music.play()
func _on_play_button_pressed(): func _on_play_button_pressed():
if $Timer.is_paused(): if $Timer.is_paused():
$Timer.paused = false $Timer.paused = false
@ -80,24 +113,26 @@ func _on_play_button_pressed():
timer_is_playing = true timer_is_playing = true
reset_timer() reset_timer()
$Timer.start() $Timer.start()
background_music.play() play_music()
func _on_timer_timeout(): func _on_timer_timeout():
if seconds == 0: if seconds == 0:
if minutes > 0: if minutes > 0:
minutes -= 1 minutes -= 1
seconds == 60 seconds = 59
else: else:
$Timer.stop() stop_timer()
background_music.stop() reset_remaining_time_label()
elif seconds > 0: elif seconds > 0:
seconds -= 1 seconds -= 1
if seconds == alert_seconds and minutes == 0:
alert_sound.play()
current_seconds -= 1 current_seconds -= 1
var minutes_str = str(minutes) if minutes >= 10 else "0" + str(minutes) var minutes_str = str(minutes) if minutes >= 10 else "0" + str(minutes)
var seconds_str = str(seconds) if seconds >= 10 else "0" + str(seconds) var seconds_str = str(seconds) if seconds >= 10 else "0" + str(seconds)
$RemainingTime.text = minutes_str + ":" + seconds_str circular_progress_bar.set_remining_time(minutes_str + ":" + seconds_str)
$CircularProgressBar.set_value(calculate_equivalent_progress(current_seconds)) circular_progress_bar.set_value(calculate_equivalent_progress(current_seconds))
func _on_pause_button_pressed(): func _on_pause_button_pressed():
@ -113,13 +148,16 @@ func _on_stop_button_pressed():
func _on_edit_button_pressed(): func _on_edit_button_pressed():
## Toggles the spinboxes (visible and editable) between true and false ## Toggles the spinboxes (visible and editable) between true and false
$SpinBoxMinutes.visible = !$SpinBoxMinutes.visible sb_minutes.visible = !sb_minutes.visible
$SpinBoxMinutes.editable = !$SpinBoxMinutes.editable sb_minutes.editable = !sb_minutes.editable
$SpinBoxSeconds.visible = !$SpinBoxSeconds.visible sb_seconds.visible = !sb_seconds.visible
$SpinBoxSeconds.editable = !$SpinBoxSeconds.editable sb_seconds.editable = !sb_seconds.editable
minutes_label.visible = !minutes_label.visible
seconds_label.visible = !seconds_label.visible
until_end_sec_cb.visible = !until_end_sec_cb.visible
until_end_sec_label.visible = !until_end_sec_label.visible
$MinutesLabel.visible = !$MinutesLabel.visible
$SecondsLabel.visible = !$SecondsLabel.visible
# Check if the edit menu is not visible and stops the timer in this case # Check if the edit menu is not visible and stops the timer in this case
if !edit_menu_visible: if !edit_menu_visible:
@ -130,15 +168,42 @@ func _on_edit_button_pressed():
func _on_spin_box_minutes_value_changed(value): func _on_spin_box_minutes_value_changed(value):
default_minutes = $SpinBoxMinutes.value default_minutes = sb_minutes.value
reset_remaining_time_label() reset_remaining_time_label()
func _on_spin_box_seconds_value_changed(value): func _on_spin_box_seconds_value_changed(value):
default_seconds = $SpinBoxSeconds.value default_seconds = sb_seconds.value
reset_remaining_time_label() reset_remaining_time_label()
func _on_volume_slider_drag_ended(value_changed): func _on_exit_button_pressed():
background_music.volume_db = $VolumeSlider.value get_tree().quit()
print($VolumeSlider.value)
func _on_settings_button_pressed():
margin_container.visible = false
settings_menu.set_process(true)
settings_menu.visible = true
func _on_volume_music_slider_value_changed(value):
background_music.volume_db = value
func _on_volume_sound_slider_value_changed(value):
alert_sound.volume_db = value
func _on_settings_menu_back_settings_menu():
margin_container.visible = true
settings_menu.visible = false
reset_timer()
reset_remaining_time_label()
func _on_settings_menu_selected_music_file():
print(settings_menu.music_path)
background_music.stream = load(settings_menu.music_path)

View File

@ -12,3 +12,5 @@ func _process(delta):
func set_value(value): func set_value(value):
$Panel.material.set_shader_parameter("value", value) $Panel.material.set_shader_parameter("value", value)
func set_remining_time(txt):
$RemainingTime.text = txt

31
Scripts/settings_menu.gd Normal file
View File

@ -0,0 +1,31 @@
class_name SettingsMenu
extends Control
@onready var back_button: Button = $MarginContainer/VBoxContainer/BackButton
@onready var file_dialog: FileDialog = $FileDialog
@onready var music_line_edit: LineEdit = $MarginContainer/VBoxContainer/HBoxContainer/BacgroundMusicLineEdit
var music_path: String
signal back_settings_menu
signal selected_music_file
# Called when the node enters the scene tree for the first time.
func _ready():
set_process(false)
func _on_back_button_pressed():
back_settings_menu.emit()
set_process(false)
func _on_select_music_button_pressed():
file_dialog.popup()
func _on_file_dialog_file_selected(path):
music_line_edit.text = path.split('/')[-1]
music_path = path
selected_music_file.emit()

View File

@ -19,6 +19,7 @@ config/icon="res://icon.svg"
window/size/viewport_width=480 window/size/viewport_width=480
window/size/viewport_height=720 window/size/viewport_height=720
window/size/resizable=false
window/stretch/mode="viewport" window/stretch/mode="viewport"
window/stretch/aspect="expand" window/stretch/aspect="expand"
window/handheld/orientation=1 window/handheld/orientation=1