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
|
local menu, background = ...
local Button = require "not.Button"
local Selector = require "not.Selector"
local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale()
local bx = width/2-29
if background == nil or not background:is(require "not.MenuBackground") then
background = require "not.MenuBackground"(menu)
end
-- TODO: loadConfigs and isAvailable are duplicated in menus/select and menus/host.
local
function isAvailable (item)
if item then
if debug then
return true
end
local at = type(item.available)
if at == "boolean" then
return item.available
end
if at == "string" then
return false
end
end
end
local
function loadConfigs (dir, process)
local items, icons = {}, {}
for _,file in pairs(love.filesystem.getDirectoryItems(dir)) do
local path = string.format("%s/%s", dir, file)
if love.filesystem.isFile(path) and file ~= "readme.md" then
local item = love.filesystem.load(path)()
if isAvailable(item) then
if process then
process(item, file, path)
end
table.insert(icons, love.graphics.newImage(item.portrait))
table.insert(items, item)
end
end
end
return items, icons
end
-- TODO: This is temporary solution for generating available maps list and portraits for them to pass to Selector.
local maps, icons = loadConfigs("config/maps", function (map, _, path) map.filename = path end)
local mapSelector = Selector(maps, nil, menu)
return {
background,
mapSelector
:setPosition(width/2-40, 40)
:set("shape", Selector.SHAPE_PANORAMA)
:set("icons", icons)
:set("getText", function (self)
return self:getSelected().name
end)
,
Button(menu)
:setText("Next")
:setPosition(bx,101)
:set("isEnabled", function ()
return mapSelector:getLocked()
end)
:set("active", function (self)
MAP = mapSelector:getSelected()
self.parent:open("select")
end)
,
Button(menu)
:setText("Go back")
:setPosition(bx,117)
:set("active", function (self)
self.parent:open("main")
end)
,
}
|