summaryrefslogtreecommitdiffhomepage
path: root/config/menus/select.lua
blob: 9ce7201a01397252fb13f9f03261ee381c6da215 (plain)
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
local menu, background = ...

local Button = require "not.Button"
local Selector = require "not.Selector"
local Element = require "not.Element"
local Group = require "not.Group"

local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale()
local bx = width/2-29

local start_Button = Button(menu)

if background == nil or not background:is(require "not.MenuBackground") then
	background = require "not.MenuBackground"(menu)
end

-- TODO: Temporary group for naut selectors. This isn't production code at any means!
local atlas = love.graphics.newImage("assets/portraits.png")
local nauts = require("config.nauts")
local icons = {}
for i=0,#nauts-1 do
	table.insert(icons, love.graphics.newQuad(i*28, 0, 28, 27, 1008, 27))
end

local group = Group(menu)
local
function add (element)
	table.insert(group.children, element)
	return element
end

for i,_ in pairs(Controller.getSets()) do
	add(Selector(nauts, group, menu))
		:setPosition(10+48*(i-1), 10)
		:set("icons_atlas", atlas)
		:set("icons_quads", icons)
end

local
function get ()
	local selection = group:callEach("getSelected")
	for i,naut in ipairs(selection) do
		selection[i] = {naut, Controller.getSets()[i]}
	end
	return selection
end

return {
	background,
	group,
	start_Button
		:setText("Force start")
		:setPosition(bx,134)
		:set("isEnabled", function ()
				return true
			end)
		:set("active", function (self)
				sceneManager:changeScene(World(MAP, get()))
			end)
	,
	Button(menu)
		:setText("Go back")
		:setPosition(bx,150)
		:set("active", function (self)
				self.parent:open("host")
			end)
	,
	Element(menu)
		:setPosition(bx, 101)
		:set("the_final_countdown", 9)
		:set("draw", function (self, scale)
				if self.the_final_countdown ~= 9 then
					local x,y = self:getPosition()
					local countdown = math.max(1, math.ceil(self.the_final_countdown))
					love.graphics.setColor(255, 255, 255, 255)
					love.graphics.setFont(Font)
					love.graphics.print("Autostart in:", (x-16)*scale, (y+10)*scale, 0, scale, scale)
					love.graphics.setFont(Bold)
					love.graphics.printf(countdown, (x+40)*scale, (y)*scale, 36, "center", 0, scale, scale)
				end
			end)
		:set("update", function (self, dt)
				local total = 0
				if total > 1 then
					self.the_final_countdown = self.the_final_countdown - dt
				else
					self.the_final_countdown = 9
				end
				if self.the_final_countdown < 0 then
					start_Button:active()
				end
			end)
	,
}