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-07 01:03:22 +00:00
|
|
|
local ti = textInput.new{
|
|
|
|
width = 300,
|
|
|
|
length = 20,
|
|
|
|
x = 15,
|
|
|
|
y = 165
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
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 )
|
|
|
|
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
|