Repository navigation
Expand file tree
/
Copy pathmenu.gd
More file actions
77 lines (63 loc) · 2.38 KB
/
Copy pathmenu.gd
File metadata and controls
77 lines (63 loc) · 2.38 KB
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
extends Control
var timerPage = preload("res://timer.tscn")
var curButton
func _ready():
$makeTimer/VBoxContainer/LineEdit.text = ""
if $ScrollContainer/GridContainer.get_child_count() > 1 : return
for savedTimer in Data.loadProgram():
var timer:TimerPage = timerPage.instantiate()
timer._updateTime(savedTimer.highScore, timer.get_node("highScore"))
makeButton(savedTimer.fast, savedTimer.name, savedTimer.highScore)
func _on_add_timer_pressed():
$makeTimer.visible = true
func buttonDown(button):
$Timer.start()
curButton = button
func buttonUp(button):
if !$Timer.is_stopped():
$Timer.stop()
curButton = null
openTimer(button)
func openTimer(button):
get_tree().root.add_child(Data.timerList[button])
Data.timerList[button].button = button
get_tree().root.remove_child(self)
Data.menu = self
func _on_timer_timeout():
if curButton != null:
$confimDeleteTimer.visible = true
$confimDeleteTimer/VBoxContainer/Label.text = "Are you sure you want to delete " + curButton.text.get_slice("\n",0) + "?"
func _on_type_pressed(fast:bool):
$makeTimer.visible = false
var txt = "Timer"
if $makeTimer/VBoxContainer/LineEdit.text != "":
txt = $makeTimer/VBoxContainer/LineEdit.text
var button = makeButton(fast, txt)
Data.menu = self
Data.saveProgram()
openTimer(button)
func _on_cancel_pressed():
$makeTimer.visible = false
func _on_keep_timer_pressed():
$confimDeleteTimer.visible = false
func _on_delete_timer_pressed():
Data.timerList.erase(curButton)
$ScrollContainer/GridContainer.remove_child(curButton)
$confimDeleteTimer.visible = false
Data.saveProgram()
func makeButton(fast:bool, name := "Timer", highScore := 0):
var button:Button = load("res://timerButton.tscn").instantiate()
var timer:TimerPage = timerPage.instantiate()
timer.fast = fast
button.button_down.connect(buttonDown.bind(button))
button.button_up.connect(buttonUp.bind(button))
timer._updateTime(highScore, timer.get_node("highScore"))
timer.name = name
timer.highScore = highScore
button.get_node("HBoxContainer/nameLabel").text = name
button.get_node("HBoxContainer/scoreLabel").text = timer.get_node("highScore").text
Data.timerList[button] = timer
button.size_flags_horizontal = 3
$ScrollContainer/GridContainer.add_child(button)
$ScrollContainer/GridContainer.move_child($ScrollContainer/GridContainer.get_node("addTimer"),$ScrollContainer/GridContainer.get_child_count()-1)
return button