-
Notifications
You must be signed in to change notification settings - Fork 0
/
choice.lua
99 lines (68 loc) · 2.04 KB
/
choice.lua
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
choice = {}
function choice.load()
choice.set()
end
function choice.set(choices)
if choices and choices[1] then -- Проверяем присутствует ли хотя бы один выбор
for i = 1, #choice do -- Очищаем предыдущие выборы
choice[i] = nil
end
for i = 1, #choices do
choice[i] = choices[i] -- Вставляем новые
end
choice.select(1)
return
end
choice.set({{"Закрыть", function() game.map() end}})
end
function choice.draw()
if choice[1] then -- Проверяем присутсвуют ли варианты выбора
local sx = screen.size.x / #choice -- размер блока выбора
for i = 1, #choice do
if choice[i] == choice.selected then
love.graphics.printf(" "..choice[i][1], font.smallinverted, sx * (i - 1), 112, sx, "center")
else
love.graphics.printf(" "..choice[i][1], font.small, sx * (i - 1), 112, sx, "center")
end
end
end
end
function choice.select(i)
choice.selected = choice[i]
choice.selected.i = i
end
function choice.next()
if choice.selected.i < #choice then
choice.select(choice.selected.i+1)
return true
end
return false
end
function choice.prev()
if choice.selected.i > 1 then
choice.select(choice.selected.i-1)
return true
end
return false
end
function choice.choose()
choice.selected[2]()
end
function choice.update(key)
if choice[1] then
if key == "return" or key == "space" then
choice.choose()
sound.play(sound.menu.select)
end
if key == "d" or key == "right" then
if choice.next() then
sound.play(sound.menu.pick)
end
end
if key == "a" or key == "left" then
if choice.prev() then
sound.play(sound.menu.pick)
end
end
end
end