From 67d7cd396e254d332bf99ebb70a22ca5aba056e9 Mon Sep 17 00:00:00 2001 From: JKuijperM Date: Mon, 25 Mar 2024 12:13:57 +0100 Subject: [PATCH] WIP in the progress bar functionality --- Scenes/TimerHUD.tscn | 16 +++++++++++++++- Scenes/circular_progress_bar.tscn | 25 +++++++++++++++++++++++++ Scripts/TimerHUD.gd | 28 ++++++++++++++++++++++++---- Scripts/circular_progress_bar.gd | 20 ++++++++++++++++++++ 4 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 Scenes/circular_progress_bar.tscn create mode 100644 Scripts/circular_progress_bar.gd diff --git a/Scenes/TimerHUD.tscn b/Scenes/TimerHUD.tscn index 16fe626..bad323a 100644 --- a/Scenes/TimerHUD.tscn +++ b/Scenes/TimerHUD.tscn @@ -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="PackedScene" uid="uid://cxho0ur4g4r2c" path="res://Scenes/circular_progress_bar.tscn" id="2_ptdoy"] [sub_resource type="LabelSettings" id="LabelSettings_gikwe"] font_size = 100 @@ -150,6 +151,19 @@ 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 = -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="pressed" from="PlayButton" to="." method="_on_play_button_pressed"] [connection signal="pressed" from="PauseButton" to="." method="_on_pause_button_pressed"] diff --git a/Scenes/circular_progress_bar.tscn b/Scenes/circular_progress_bar.tscn new file mode 100644 index 0000000..ac8d51c --- /dev/null +++ b/Scenes/circular_progress_bar.tscn @@ -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) diff --git a/Scripts/TimerHUD.gd b/Scripts/TimerHUD.gd index c9db229..799f676 100644 --- a/Scripts/TimerHUD.gd +++ b/Scripts/TimerHUD.gd @@ -3,9 +3,11 @@ extends CanvasLayer @export var default_minutes = 1 var seconds var minutes +var total_seconds var timer_is_playing = false signal play_timer +var edit_menu_visible = false # Called when the node enters the scene tree for the first time. func _ready(): @@ -15,6 +17,10 @@ func _ready(): $SpinBoxMinutes.value = default_minutes $SpinBoxSeconds.get_line_edit().context_menu_enabled = false $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(): seconds = default_seconds minutes = default_minutes + # Calculate the total seconds + total_seconds = default_minutes * 60 + default_seconds func reset_remaining_time_label(): ## Resets the value of the label $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(): @@ -48,8 +62,9 @@ func _on_timer_timeout(): minutes -= 1 seconds == 60 seconds -= 1 - + total_seconds -= 1 $RemainingTime.text = str(minutes) + ":" + str(seconds) + $CircularProgressBar.set_value(total_seconds) func _on_pause_button_pressed(): @@ -58,9 +73,7 @@ func _on_pause_button_pressed(): func _on_stop_button_pressed(): - timer_is_playing = false - $Timer.paused = false - $Timer.stop() + stop_timer() reset_remaining_time_label() @@ -73,6 +86,13 @@ func _on_edit_button_pressed(): $MinutesLabel.visible = !$MinutesLabel.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): diff --git a/Scripts/circular_progress_bar.gd b/Scripts/circular_progress_bar.gd new file mode 100644 index 0000000..472dcc8 --- /dev/null +++ b/Scripts/circular_progress_bar.gd @@ -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