-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPomodoroTimer.gd
177 lines (145 loc) · 5.09 KB
/
PomodoroTimer.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
###########################################################
# Pomodoro type work timer to help improve work schedule
#
###########################################################
# GPL License V3. Use / Edit and return to the community
#
###########################################################
extends Control
##########################################
# You must select the PomodoroTimer node
# and assign the two Script Variables there
# to the two dropdown nodes before this script will work
export (NodePath) var dropdownWork_path
export (NodePath) var dropdownBreak_path
##########################################
onready var dropdownWorkSounds = get_node(dropdownWork_path)
onready var dropdownBreakSounds = get_node(dropdownBreak_path)
onready var SoundPlayer = get_node("AudioStreamPlayer")
onready var t = get_node("Timer")
onready var progressMeter = get_node("ProgressBar")
onready var l = get_node("LabelHint")
#3 x included sound files are in root of project
var sound_array = ["Gong", "Soothe", "Alarm"]
var sample_library = {"0": preload("res://gong.wav"), "1": preload("res://soothe.wav"), "2": preload("res://alarm.wav")}
var playSounds = true
var soundWorkEnd = "0"
var soundBreakEnd = "0"
# defaults based on my likings. No ability to save on each run yet
var timeShortBreak = 300 #5 x 60 seconds
var timeLongBreak = 600 #10 x 60 seconds
var timeWorkPeriod = 1500 #25 x 60 seconds
var state = "stopped" #stopped, working, break
var lastState = state
func _ready():
add_sound_items()
func _process(delta):
#debug output
get_node("debugLabel-Timer").text = str(round(t.time_left))
#work out how much of the timer has progressed for the progressbar to update
progressMeter.value = t.time_left
func setProgressBarLimits(value):
progressMeter.max_value = value
print("progress max is: ", str(value))
#fill up the dropdown menus
func add_sound_items():
for item in sound_array:
dropdownWorkSounds.add_item(item)
dropdownBreakSounds.add_item(item)
func play_sample(var sound):
print("playing sound :", str(sound))
if playSounds:
if sample_library.has(sound):
SoundPlayer.stream = sample_library[sound]
SoundPlayer.play()
func _on_DropDownWorkEnd_item_selected( ID ):
#play the sound so they can hear it as a test
play_sample(str(ID))
#assign it as the sound to use
soundWorkEnd = str(ID)
func _on_DropDownBreakEnd_item_selected( ID ):
#play the sound so they can hear it as a test
play_sample(str(ID))
#assign it as the sound to use
soundBreakEnd = str(ID)
func _on_CheckButtonSound_pressed():
if playSounds:
playSounds = false
else:
playSounds = true
func changeTextValue( labelName, value):
var textValue
if value == 1:
textValue = str(value) + " minute"
else:
textValue = str(value) + " minutes"
get_node(labelName).set_text(textValue)
func _on_HSliderWork_value_changed( value ):
changeTextValue("Panel/VBoxContainer/HBoxContainer/LabelWorkMinutes", value)
timeWorkPeriod = value*60
func _on_HSliderBreakShort_value_changed( value ):
changeTextValue("Panel/VBoxContainer/HBoxContainer2/LabelBreakShortMinutes", value)
timeShortBreak = value*60
func _on_HSliderBreakLong_value_changed( value ):
changeTextValue("Panel/VBoxContainer/HBoxContainer3/LabelBreakLongMinutes", value)
timeLongBreak = value*60
func _on_ButtonWork_pressed():
#whilst we're here, update the progress bar's max value
setProgressBarLimits(timeWorkPeriod)
t.wait_time = timeWorkPeriod
t.start()
lastState = state
state = "working"
l.text = "I'm focused and working"
changeButtonStatus()
changeHintStatus()
func _on_ButtonBreakShort_pressed():
#whilst we're here, update the progress bar's max value
setProgressBarLimits(timeShortBreak)
t.wait_time = timeShortBreak
t.start()
lastState = state
state = "break"
l.text = "On a short break"
changeButtonStatus()
changeHintStatus()
func _on_ButtonBreakLong_pressed():
#whilst we're here, update the progress bar's max value
setProgressBarLimits(timeLongBreak)
t.wait_time = timeLongBreak
t.start()
lastState = state
state = "break"
l.text = "On a longer break"
changeButtonStatus()
changeHintStatus()
func _on_Timer_timeout():
if state == "working":
play_sample(soundWorkEnd)
lastState = state
state = "stopped"
elif state == "break":
play_sample(soundBreakEnd)
lastState = state
state = "stopped"
changeButtonStatus()
changeHintStatus()
OS.request_attention()
func changeButtonStatus():
if state == "stopped":
get_node("ButtonWork").text = "Start Work"
get_node("ButtonBreakLong").text = "Start Long Break"
get_node("ButtonBreakShort").text = "Start Short Break"
elif state == "break":
get_node("ButtonWork").text = "Start Work"
get_node("ButtonBreakLong").text = "Taking a Break"
get_node("ButtonBreakShort").text = "Taking a Break"
elif state == "working":
get_node("ButtonWork").text = "Currently Working"
get_node("ButtonBreakLong").text = "Start Long Break"
get_node("ButtonBreakShort").text = "Start Short Break"
func changeHintStatus():
if lastState == "working":
l.text = "Work finished. Time for a break."
elif lastState == "break":
l.text = "Break over. Time to focus onwork"