-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
151 lines (118 loc) · 3.37 KB
/
main.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
extends Control
signal date_update
var opened = false
var date_opened = false
var config = ConfigFile.new()
const CONFIG_PATH = "user://app_settings.cfg"
@onready var time_label: Label = $VBoxContainer/Time
@onready var am_pm: Label = $VBoxContainer/AmPM
@onready var date_label: Label = $Date
@onready var settings: Panel = $Settings
@onready var about: Panel = $Settings/About
@onready var display_date_button: Button = $Settings/VBoxContainer2/DisplayDate
#Sounds
@onready var click_sound: AudioStreamPlayer = $ClickSound
@onready var toggle_sound: AudioStreamPlayer = $ToggleSound
func _ready():
set_process(true)
date()
load_date_state()
func _process(_delta):
#var current_time = Time.get_time_string_from_system()
time_calc()
func _input(event):
if event.is_action_pressed("Open Menu"):
toggle_menu()
click_sound.play()
func _on_texture_button_pressed():
toggle_menu()
click_sound.play()
func toggle_menu():
opened = !opened
if opened:
settings.visible = true
else:
settings.visible = false
func time_calc():
# gets the dictionary of current time from the system
var current_time = Time.get_time_dict_from_system()
#var current_time = Time.get_time_string_from_system()
var hours = current_time.hour
var minutes = current_time.minute
var seconds = current_time.second
if seconds < 10:
seconds = "0" + str(seconds)
if minutes < 10:
minutes = "0" + str(minutes)
# converts the time to 12 hour format by substracting the current hour (24 hour format)
# to 12
#print(seconds)
if hours == 0:
hours = 12
time_label.text = str(hours) + ":" + str(minutes) + ":" + str(seconds)
am_pm.text = "AM"
date_update.emit()
elif hours < 12:
time_label.text = str(hours) + ":" + str(minutes) + ":" + str(seconds)
am_pm.text = "AM"
elif hours == 12:
time_label.text = str(hours) + ":" + str(minutes) + ":" + str(seconds)
am_pm.text = "PM"
else:
hours -= 12
time_label.text = str(hours) + ":" + str(minutes) + ":" + str(seconds)
am_pm.text = "PM"
func date():
# gets the dictionary of the current date fromt the system
var current_date = Time.get_date_dict_from_system()
var day = current_date.day
var month = current_date.month
var year = current_date.year
var all_months = {
1: "Jan",
2: "Feb",
3: "Mar",
4: "Apr",
5: "May",
6: "Jun",
7: "Jul",
8: "Aug",
9: "Sept",
10: "Oct",
11: "Nov",
12: "Dec",
}
var mapped_month = all_months.get(month)
date_label.text = str(day) +' ' + mapped_month + ' ' + str(year)
# date_update signal is catched here and a function to update the date is called
func _on_date_update() -> void:
date()
func _on_display_date_pressed():
display_date_label()
toggle_sound.play()
save_date_state()
func display_date_label():
date_opened = !date_opened
if date_opened:
date_label.visible = true
else:
date_label.visible = false
# ------------------------------------
func _on_about_min_time_pressed():
about.show()
toggle_sound.play()
func _on_close_pressed():
about.hide()
toggle_sound.play()
func _on_quit_pressed():
get_tree().quit()
func save_date_state():
config.set_value("UI", "date_opened", date_opened)
config.save(CONFIG_PATH)
func load_date_state():
var err = config.load(CONFIG_PATH)
if err == OK:
date_opened = config.get_value("UI", "date_opened", false)
date_label.visible = date_opened
if display_date_button:
display_date_button.button_pressed = date_opened