vision/src/client/ui/browser.lua

80 lines
1.9 KiB
Lua

local lg = assert( love.graphics )
local scene = assert( require 'client.scene' )
local textInput = assert( require 'client.ui.textinput' )
local button = assert( require 'client.ui.button' )
local browser = {}
local serverList = {
selected = false,
x = 25,
y = 160,
h = 24,
{ name = "test", ip = "192.168.2.150", port = 51312, players = 1, capacity = 64, map = "testMap" },
{ name = "best", ip = "142.154.3.212", port = 21345, players = 2, capacity = 64, map = "nestMap" },
{ name = "aest", ip = "123.45.67.89", port = 21253, players = 3, capacity = 32, map = "aestMap" },
}
function serverList.draw()
end
function serverList.select()
end
function serverList.up()
serverList.selected = ( serverList.selected or 0 ) - 1
end
function serverList.down()
serverList.selected = ( serverList.selected or 0 ) + 1
end
local ti = textInput.new{
width = 300,
length = 20,
x = 15,
y = 175
}
function browser.draw()
lg.setColor( 1, 1, 1, 1 )
lg.print( "Server Browser", 15, 115 )
ti:draw()
end
function browser.update( dt )
end
function browser.onLoad( )
lg.setColor( 1, 1, 1, 1 )
end
function browser.mousepressed(x, y, button, istouch, pressed)
if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end
end
function browser.joinIPString( s )
--Parse IP address and port from string. If it's valid, join the server.
print( "browser: Attempting to join server", s )
if not s then return end
ti:clear()
local valid, ip, port
if valid then return browser.joinIP( ip, port ) end
end
function browser.joinIP( ip, port )
print( "Joining server:", ip, port )
return scene.game{ serverIP = ip, serverPort = port }
end
function browser.keypressed( key, code, isRepeat )
if code == "escape" then return scene.mainmenu() end
if code == "return" then return ti:enterText( browser.joinIPString ) end
end
scene.browser = browser
return browser