-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_menu.lua
98 lines (83 loc) · 2.5 KB
/
layer_menu.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
MenuLayer = Layer:extend()
function MenuLayer:new()
MenuLayer.super.new(self)
self.layer_name = "MenuLayer"
self.selected_index = 1
self.items = { "Play" }
self.logo = love.graphics.newImage("gfx/title.png")
end
-- CALLBACKS
-- 195x162
function MenuLayer:draw()
local bgc = constants.dark_bg_color
local em = constants.emphasis_color
local deem = constants.deemphasis_color
local win_w = love.graphics.getWidth()
local win_h = love.graphics.getHeight()
love.graphics.setFont(constants.big_font)
love.graphics.setColor(bgc.r, bgc.g, bgc.b, 1.0)
love.graphics.rectangle('fill', 0, 0, win_w, win_h)
local logo_w, logo_h = self.logo:getPixelDimensions()
logo_w = logo_w * 3
logo_h = logo_h * 3
local logo_x = (win_w - logo_w) / 2
local logo_y = (win_h - logo_h) / 2 - 25
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(self.logo, logo_x, logo_y, 0, 3)
for i = 1, #self.items do
if i == self.selected_index then
love.graphics.setColor(em.r, em.g, em.b, 1.0)
else
love.graphics.setColor(deem.r, deem.g, deem.b, 1.0)
end
local y = logo_y + 50 + i * constants.unit_menu_height_per_item
love.graphics.print(self.items[i], (1280 - 100) / 2, y)
end
end
function MenuLayer:update(dt)
return
end
function MenuLayer:keypressed(key, scancode, isrepeat)
if self.paused == 1 then
return
end
if isrepeat == true then
return
end
if key == layer_manager.controls["Up"] then
self:previous_item()
elseif key == layer_manager.controls["Down"] then
self:next_item()
elseif key == layer_manager.controls["Confirm"] then
self:select_item()
end
end
function MenuLayer:keyreleased(key, scancode)
return
end
-- FUNCTIONALITY
function MenuLayer:previous_item()
local dest = self.selected_index - 1
if dest < 1 then
dest = #self.items
end
self.selected_index = dest
end
function MenuLayer:next_item()
local dest = self.selected_index + 1
if dest > #self.items then
dest = 1
end
self.selected_index = dest
end
function MenuLayer:select_item()
log(lume.format("[{1}] Index {2} selected", { self.layer_name, self.selected_index }))
local destination_layer = null
if self.selected_index == 1 then
destination_layer = NamesLayer()
end
if destination_layer ~= nil then
confirm_sound()
layer_manager:transition(self, destination_layer)
end
end