WIP in the progress bar functionality

This commit is contained in:
JKuijperM 2024-03-25 12:13:57 +01:00
parent e17f8b4954
commit 67d7cd396e
4 changed files with 84 additions and 5 deletions

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://bsafhva6xh2nf"] [gd_scene load_steps=4 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="PackedScene" uid="uid://cxho0ur4g4r2c" path="res://Scenes/circular_progress_bar.tscn" id="2_ptdoy"]
[sub_resource type="LabelSettings" id="LabelSettings_gikwe"] [sub_resource type="LabelSettings" id="LabelSettings_gikwe"]
font_size = 100 font_size = 100
@ -150,6 +151,19 @@ max_value = 59.0
alignment = 2 alignment = 2
editable = false 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 = -20.0
offset_top = -100.0
offset_right = 20.0
offset_bottom = -60.0
grow_horizontal = 2
grow_vertical = 2
[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="PlayButton" to="." method="_on_play_button_pressed"]
[connection signal="pressed" from="PauseButton" to="." method="_on_pause_button_pressed"] [connection signal="pressed" from="PauseButton" to="." method="_on_pause_button_pressed"]

View File

@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://cxho0ur4g4r2c"]
[ext_resource type="Texture2D" uid="uid://c2bey6otu2m8m" path="res://Assets/flair_circle_red_0.png" id="1_uwsh4"]
[ext_resource type="Script" path="res://Scripts/circular_progress_bar.gd" id="2_c3xrc"]
[ext_resource type="Texture2D" uid="uid://rxgucw2h8hhv" path="res://Assets/flair_circle_border.png" id="3_o171a"]
[node name="CircularProgressBar" type="Control"]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("2_c3xrc")
[node name="TextureProgressBar" type="TextureProgressBar" parent="."]
offset_left = -64.0
offset_top = -64.0
offset_right = 64.0
offset_bottom = 64.0
value = 33.0
fill_mode = 4
texture_under = ExtResource("1_uwsh4")
texture_over = ExtResource("3_o171a")
texture_progress = ExtResource("1_uwsh4")
tint_under = Color(0, 0, 0, 0.278431)
tint_progress = Color(0, 0, 0.964706, 1)

View File

@ -3,9 +3,11 @@ extends CanvasLayer
@export var default_minutes = 1 @export var default_minutes = 1
var seconds var seconds
var minutes var minutes
var total_seconds
var timer_is_playing = false var timer_is_playing = false
signal play_timer signal play_timer
var edit_menu_visible = false
# 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():
@ -15,6 +17,10 @@ func _ready():
$SpinBoxMinutes.value = default_minutes $SpinBoxMinutes.value = default_minutes
$SpinBoxSeconds.get_line_edit().context_menu_enabled = false $SpinBoxSeconds.get_line_edit().context_menu_enabled = false
$SpinBoxSeconds.value = default_seconds $SpinBoxSeconds.value = default_seconds
# Calculate the total seconds
total_seconds = default_minutes * 60 + default_seconds
$CircularProgressBar.set_max_value(total_seconds)
$CircularProgressBar.set_value(total_seconds)
@ -26,11 +32,19 @@ func _process(delta):
func reset_timer(): func reset_timer():
seconds = default_seconds seconds = default_seconds
minutes = default_minutes minutes = default_minutes
# Calculate the total seconds
total_seconds = default_minutes * 60 + default_seconds
func reset_remaining_time_label(): func reset_remaining_time_label():
## Resets the value of the label ## Resets the value of the label
$RemainingTime.text = str(default_minutes) + ":" + str(default_seconds) $RemainingTime.text = str(default_minutes) + ":" + str(default_seconds)
func stop_timer():
## Stops the timer, sets as 'false' the timer_is_playing flag and also
## the property paused in the timer
timer_is_playing = false
$Timer.paused = false
$Timer.stop()
func _on_play_button_pressed(): func _on_play_button_pressed():
@ -48,8 +62,9 @@ func _on_timer_timeout():
minutes -= 1 minutes -= 1
seconds == 60 seconds == 60
seconds -= 1 seconds -= 1
total_seconds -= 1
$RemainingTime.text = str(minutes) + ":" + str(seconds) $RemainingTime.text = str(minutes) + ":" + str(seconds)
$CircularProgressBar.set_value(total_seconds)
func _on_pause_button_pressed(): func _on_pause_button_pressed():
@ -58,9 +73,7 @@ func _on_pause_button_pressed():
func _on_stop_button_pressed(): func _on_stop_button_pressed():
timer_is_playing = false stop_timer()
$Timer.paused = false
$Timer.stop()
reset_remaining_time_label() reset_remaining_time_label()
@ -74,6 +87,13 @@ func _on_edit_button_pressed():
$MinutesLabel.visible = !$MinutesLabel.visible $MinutesLabel.visible = !$MinutesLabel.visible
$SecondsLabel.visible = !$SecondsLabel.visible $SecondsLabel.visible = !$SecondsLabel.visible
# Check if the edit menu is not visible and stops the timer in this case
if !edit_menu_visible:
stop_timer()
# Toggle the value of 'edit_menu_visible'
edit_menu_visible = !edit_menu_visible
func _on_spin_box_minutes_value_changed(value): func _on_spin_box_minutes_value_changed(value):
default_minutes = $SpinBoxMinutes.value default_minutes = $SpinBoxMinutes.value

View File

@ -0,0 +1,20 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func set_value(value):
$TextureProgressBar.value = value
func set_min_value(value):
$TextureProgressBar.min_value = value
func set_max_value(value):
$TextureProgressBar.max_value = value