-
Notifications
You must be signed in to change notification settings - Fork 0
/
listMenu.lua
72 lines (55 loc) · 1.87 KB
/
listMenu.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
local utils = require "utils"
local entity = require "entity"
local love = love
local listMenu = {}
setfenv(1, listMenu)
local function updateMarker (listMenu)
local currentAsset = listMenu.assets[listMenu.menu.option]
listMenu.marker.x = currentAsset.x - listMenu.marker.width - listMenu.markerDistance
listMenu.marker.y = currentAsset.y + (currentAsset.height - listMenu.marker.height) / 2
end
ListMenu = utils.inheritsFrom(entity.Entity, function (self, menu, assets, marker, position, separation, markerDistance)
entity.Entity.__constructor (self)
self.menu = menu
self.assets = assets
self.separation = separation
self.marker = marker
self.position = position
self.markerDistance = markerDistance
local y = self.position.y
for i = 1, #self.assets do
local optionAsset = self.assets[i]
self:addComponent(optionAsset)
optionAsset.x = self.position.x - optionAsset.width / 2
optionAsset.y = y
y = y + optionAsset.height + self.separation
end
self:addComponent(self.marker)
updateMarker (self)
self.select = love.audio.newSource("assets/sound/sfx/menu_accept.ogg")
self.side = love.audio.newSource("assets/sound/sfx/menu_side.ogg")
end)
function ListMenu:update ()
entity.Entity.update (self)
if self.gamepad then
if self.gamepad:buttonJustPressed("dpup") then
self:moveUp()
elseif self.gamepad:buttonJustPressed("dpdown") then
self:moveDown()
elseif self.gamepad:buttonJustPressed("a") then
self.menu:selectOption()
end
end
updateMarker(self)
end
function ListMenu:moveDown ()
self.menu:nextOption()
updateMarker (self)
love.audio.play(self.side)
end
function ListMenu:moveUp ()
self.menu:previousOption()
updateMarker (self)
love.audio.play(self.side)
end
return listMenu