129 lines
3.6 KiB
Lua
129 lines
3.6 KiB
Lua
menu = {}
|
|
menu.serverlist = {
|
|
{description = "A localhost server [ipv4]", host = "127.0.0.1", port = "11150"},
|
|
{description = "A localhost server [ipv6]", host = "::1", port = "11150"}
|
|
}
|
|
|
|
local altPressed, enterPressed = false, false
|
|
function menu.keyreleased(key, _)
|
|
if key == "lalt" then
|
|
altPressed = false
|
|
end
|
|
if key == "return" then
|
|
enterPressed = false
|
|
end
|
|
end
|
|
|
|
|
|
function menu.keypressed(key, _)
|
|
if key == "return" then enterPressed = true end
|
|
if key == "lalt" then altPressed = true end
|
|
if key == "f11" or (altPressed and key == "return") or (enterPressed and key == "lalt") then
|
|
fullscreen = not fullscreen
|
|
love.window.setFullscreen(fullscreen, "desktop")
|
|
end
|
|
end
|
|
|
|
|
|
function menu.update(dt)
|
|
love.timer.sleep((1/60) -dt)
|
|
end
|
|
|
|
|
|
function menu.resize()
|
|
menu.width, menu.height = love.window.getMode()
|
|
menu.Canvas = love.graphics.newCanvas(width, height)
|
|
love.graphics.setCanvas(menu.Canvas)
|
|
love.graphics.clear()
|
|
drawMenu(w, h)
|
|
love.graphics.setCanvas()
|
|
end
|
|
|
|
|
|
function menu.mousepressed(mousex, mousey)
|
|
local textures = gameloop.textures
|
|
for i, v in ipairs(uiState) do
|
|
if mousex >= v.x and mousex <= v.x2 then
|
|
if mousey >= v.y and mousey <= v.y2 then
|
|
if v.kind == "server" then
|
|
local names = { "Herbert", "Thorben", "Martin", "Heinrich", "Dietrich", "Markus", "Florian", "Helmut", "Willhelm", "Fritz", "Gustav", "Konrad", "Berta", "Charlotte", "Hildegard", "Lieselotte", "Gudrun", "Giesela", "Margarete", "Antonia", "Friederike", "Clotilde", "Marlies", "Hedwig" }
|
|
local lastNames = { "Müller", "Schmidt", "Meier", "Bauer", "Werner", "Schumacher", "Bergmann", "Eisenhauer", "Heisenberg" }
|
|
local fullName = names[love.math.random(1, #names)] .. " " .. lastNames[love.math.random(1, #lastNames)]
|
|
local serverID = v.identifier
|
|
local serverEntry = menu.serverlist[serverID]
|
|
gameloop.init({ adress = serverEntry.host, port = serverEntry.port }, fullName)
|
|
uiState = {}
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
menu.serverentry = function(id, description, host, port)
|
|
return {name = "horizontal",
|
|
{name = "label", text = description },
|
|
{name = "spacer", width = 20 },
|
|
{name = "label", text = "[".. host .."]"},
|
|
{name = "label", text = ":".. port },
|
|
{name = "spacer", width = 25 },
|
|
{name = "cursorSelect", kind = "server", identifier = id,
|
|
{name = "drawTexture", texture = love.graphics.newImage("textures/menu/serverPlay.png")}}}
|
|
end
|
|
|
|
menu.layoutServerList = function()
|
|
local list = {name = "vertical"}
|
|
for i, v in ipairs(menu.serverlist) do
|
|
table.insert(list, menu.serverentry(i, v.description, v.host, v.port))
|
|
end
|
|
return list
|
|
end
|
|
|
|
|
|
menu.layout = {name ="vertical",
|
|
{name = "spacer", height = 20},
|
|
{name = "horizontal",
|
|
{name = "spacer", width = 20},
|
|
{name = "drawTexture", texture = love.graphics.newImage("ressources/Poppy.png")},
|
|
{name = "label", text = "Welcome to poppy!"},
|
|
},
|
|
{name = "horizontal",
|
|
{name = "spacer", width = 60},
|
|
{name = "vertical",
|
|
{name = "spacer", height = 60},
|
|
{name = "label", text = "Pick a server to join!"},
|
|
{name = "spacer", height = 20},
|
|
menu.layoutServerList()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function drawMenu()
|
|
color_push()
|
|
love.graphics.setCanvas(menu.Canvas)
|
|
uiState = {}
|
|
love.graphics.clear( )
|
|
layout.handle(menu.layout, 0, 0)
|
|
love.graphics.setCanvas()
|
|
color_pop()
|
|
end
|
|
|
|
|
|
function menu.draw(w, h)
|
|
love.graphics.draw(menu.Canvas)
|
|
end
|
|
|
|
|
|
function menu.init()
|
|
menu.width, menu.height = love.window.getMode()
|
|
menu.Canvas = love.graphics.newCanvas(menu.width, menu.height)
|
|
drawMenu()
|
|
love.draw = menu.draw
|
|
love.keyreleased = menu.keyreleased
|
|
love.keypressed = menu.keypressed
|
|
love.mousepressed = menu.mousepressed
|
|
end
|
|
|
|
return menu
|