Added new functionality to the timer like the spinboxes to edit the default values

This commit is contained in:
JKuijperM 2024-03-24 11:35:17 +01:00
parent bf1b4bec86
commit e17f8b4954
3 changed files with 107 additions and 5 deletions

View File

@ -72,20 +72,88 @@ grow_vertical = 0
text = "Stop text = "Stop
" "
[node name="SpinBox" type="SpinBox" parent="."] [node name="EditButton" type="Button" parent="."]
anchors_preset = 7 anchors_preset = 7
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = -42.0 offset_left = 166.0
offset_top = -31.0 offset_top = -199.0
offset_right = 41.0625 offset_right = 206.0
offset_bottom = -168.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 0 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 editable = 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="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"]
[connection signal="pressed" from="StopButton" to="." method="_on_stop_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"]

View File

@ -6,9 +6,16 @@ var minutes
var timer_is_playing = false var timer_is_playing = false
signal play_timer signal play_timer
# 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():
$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. # Called every frame. 'delta' is the elapsed time since the previous frame.
@ -20,6 +27,10 @@ func reset_timer():
seconds = default_seconds seconds = default_seconds
minutes = default_minutes 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(): func _on_play_button_pressed():
@ -50,3 +61,25 @@ func _on_stop_button_pressed():
timer_is_playing = false timer_is_playing = false
$Timer.paused = false $Timer.paused = false
$Timer.stop() $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()

View File

@ -22,6 +22,7 @@ window/size/viewport_height=720
window/stretch/mode="viewport" window/stretch/mode="viewport"
window/stretch/aspect="expand" window/stretch/aspect="expand"
window/handheld/orientation=1 window/handheld/orientation=1
window/main_scene="res://Scenes/TimerHUD.tscn"
[editor_plugins] [editor_plugins]