From e17f8b49549598f2d10d587c0dfdf35d9af4e9d0 Mon Sep 17 00:00:00 2001 From: JKuijperM Date: Sun, 24 Mar 2024 11:35:17 +0100 Subject: [PATCH] Added new functionality to the timer like the spinboxes to edit the default values --- Scenes/TimerHUD.tscn | 76 +++++++++++++++++++++++++++++++++++++++++--- Scripts/TimerHUD.gd | 35 +++++++++++++++++++- project.godot | 1 + 3 files changed, 107 insertions(+), 5 deletions(-) diff --git a/Scenes/TimerHUD.tscn b/Scenes/TimerHUD.tscn index cd86c49..16fe626 100644 --- a/Scenes/TimerHUD.tscn +++ b/Scenes/TimerHUD.tscn @@ -72,20 +72,88 @@ grow_vertical = 0 text = "Stop " -[node name="SpinBox" type="SpinBox" parent="."] +[node name="EditButton" type="Button" parent="."] anchors_preset = 7 anchor_left = 0.5 anchor_top = 1.0 anchor_right = 0.5 anchor_bottom = 1.0 -offset_left = -42.0 -offset_top = -31.0 -offset_right = 41.0625 +offset_left = 166.0 +offset_top = -199.0 +offset_right = 206.0 +offset_bottom = -168.0 grow_horizontal = 2 grow_vertical = 0 +size_flags_vertical = 6 +text = "Edit" + +[node name="MinutesLabel" type="Label" parent="."] +visible = false +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -77.0 +offset_top = -140.0 +offset_right = -37.0 +offset_bottom = -117.0 +grow_horizontal = 2 +grow_vertical = 0 +text = "Minutes" + +[node name="SecondsLabel" type="Label" parent="."] +visible = false +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = 32.0 +offset_top = -140.0 +offset_right = 72.0 +offset_bottom = -117.0 +grow_horizontal = 2 +grow_vertical = 0 +text = "Seconds" + +[node name="SpinBoxMinutes" type="SpinBox" parent="."] +visible = false +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -100.0 +offset_top = -100.0 +offset_bottom = -50.0 +grow_horizontal = 2 +grow_vertical = 0 +max_value = 60.0 +alignment = 2 +editable = false + +[node name="SpinBoxSeconds" type="SpinBox" parent="."] +visible = false +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = 10.0 +offset_top = -100.0 +offset_right = 110.0 +offset_bottom = -50.0 +grow_horizontal = 2 +grow_vertical = 0 +max_value = 59.0 +alignment = 2 editable = false [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"] [connection signal="pressed" from="StopButton" to="." method="_on_stop_button_pressed"] +[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"] diff --git a/Scripts/TimerHUD.gd b/Scripts/TimerHUD.gd index ed1bf19..c9db229 100644 --- a/Scripts/TimerHUD.gd +++ b/Scripts/TimerHUD.gd @@ -6,9 +6,16 @@ var minutes var timer_is_playing = false signal play_timer + # Called when the node enters the scene tree for the first time. func _ready(): - $RemainingTime.text = str(default_minutes) + ":" + str(default_seconds) + reset_remaining_time_label() + + $SpinBoxMinutes.get_line_edit().context_menu_enabled = false + $SpinBoxMinutes.value = default_minutes + $SpinBoxSeconds.get_line_edit().context_menu_enabled = false + $SpinBoxSeconds.value = default_seconds + # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -20,6 +27,10 @@ func reset_timer(): seconds = default_seconds minutes = default_minutes +func reset_remaining_time_label(): + ## Resets the value of the label + $RemainingTime.text = str(default_minutes) + ":" + str(default_seconds) + func _on_play_button_pressed(): @@ -50,3 +61,25 @@ func _on_stop_button_pressed(): timer_is_playing = false $Timer.paused = false $Timer.stop() + reset_remaining_time_label() + + +func _on_edit_button_pressed(): + ## Toggles the spinboxes (visible and editable) between true and false + $SpinBoxMinutes.visible = !$SpinBoxMinutes.visible + $SpinBoxMinutes.editable = !$SpinBoxMinutes.editable + $SpinBoxSeconds.visible = !$SpinBoxSeconds.visible + $SpinBoxSeconds.editable = !$SpinBoxSeconds.editable + + $MinutesLabel.visible = !$MinutesLabel.visible + $SecondsLabel.visible = !$SecondsLabel.visible + + +func _on_spin_box_minutes_value_changed(value): + default_minutes = $SpinBoxMinutes.value + reset_remaining_time_label() + + +func _on_spin_box_seconds_value_changed(value): + default_seconds = $SpinBoxSeconds.value + reset_remaining_time_label() diff --git a/project.godot b/project.godot index 4076c52..2e5afc9 100644 --- a/project.godot +++ b/project.godot @@ -22,6 +22,7 @@ window/size/viewport_height=720 window/stretch/mode="viewport" window/stretch/aspect="expand" window/handheld/orientation=1 +window/main_scene="res://Scenes/TimerHUD.tscn" [editor_plugins]