2023-09-04 18:20:02 +00:00
|
|
|
local lg = assert( love.graphics )
|
2023-09-04 18:31:47 +00:00
|
|
|
local scene = assert( require 'client.scene' )
|
2023-09-07 01:03:22 +00:00
|
|
|
local textInput = assert( require 'client.ui.textinput' )
|
|
|
|
local button = assert( require 'client.ui.button' )
|
2023-09-04 18:20:02 +00:00
|
|
|
local browser = {}
|
|
|
|
|
2023-09-11 22:44:36 +00:00
|
|
|
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
|
|
|
|
|
2023-09-07 01:03:22 +00:00
|
|
|
local ti = textInput.new{
|
|
|
|
width = 300,
|
|
|
|
length = 20,
|
|
|
|
x = 15,
|
2023-09-11 22:44:36 +00:00
|
|
|
y = 175
|
2023-09-07 01:03:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-04 18:20:02 +00:00
|
|
|
function browser.draw()
|
2023-09-07 01:03:22 +00:00
|
|
|
lg.setColor( 1, 1, 1, 1 )
|
|
|
|
lg.print( "Server Browser", 15, 115 )
|
|
|
|
ti:draw()
|
2023-09-04 18:20:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function browser.update( dt )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function browser.onLoad( )
|
|
|
|
lg.setColor( 1, 1, 1, 1 )
|
|
|
|
end
|
|
|
|
|
2023-09-07 01:03:22 +00:00
|
|
|
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.
|
2023-09-11 22:44:36 +00:00
|
|
|
print( "browser: Attempting to join server", s )
|
2023-09-07 01:03:22 +00:00
|
|
|
if not s then return end
|
|
|
|
ti:clear()
|
|
|
|
local valid, ip, port
|
2023-09-05 00:40:07 +00:00
|
|
|
|
2023-09-07 01:03:22 +00:00
|
|
|
if valid then return browser.joinIP( ip, port ) end
|
|
|
|
end
|
|
|
|
|
|
|
|
function browser.joinIP( ip, port )
|
2023-09-11 22:44:36 +00:00
|
|
|
print( "Joining server:", ip, port )
|
2023-09-07 01:03:22 +00:00
|
|
|
return scene.game{ serverIP = ip, serverPort = port }
|
2023-09-05 00:40:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function browser.keypressed( key, code, isRepeat )
|
|
|
|
if code == "escape" then return scene.mainmenu() end
|
2023-09-07 01:03:22 +00:00
|
|
|
if code == "return" then return ti:enterText( browser.joinIPString ) end
|
2023-09-05 00:40:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
scene.browser = browser
|
|
|
|
return browser
|