65 lines
1.5 KiB
Lua
65 lines
1.5 KiB
Lua
local scene = assert( require 'scene' )
|
|
local lg = assert( love.graphics )
|
|
local server = assert( require 'udp' )
|
|
local button = assert( require 'ui.button' )
|
|
local strings = assert( require 'strings' )
|
|
local connecting = {}
|
|
|
|
local time, ip, port, attempts = 0, 0, 0, 0
|
|
|
|
local cancelButton = button{
|
|
x = lg.getWidth() / 4,
|
|
y = lg.getHeight() / 2,
|
|
w = lg.getWidth() / 2,
|
|
h = 100,
|
|
text = lg.newText( lg.getFont(), strings.cancel_button ),
|
|
}
|
|
|
|
function connecting.mousemoved( x, y )
|
|
cancelButton.selected = cancelButton:contains( x, y )
|
|
end
|
|
|
|
function connecting.mousepressed( x, y )
|
|
if cancelButton:contains( x, y ) then return scene.browser() end
|
|
end
|
|
|
|
function connecting.keypressed( x, y )
|
|
return scene.browser()
|
|
end
|
|
|
|
function connecting.draw()
|
|
lg.setColor( 1,1,1,1 )
|
|
lg.printf( "CONNECTING\nADDRESS\nATTEMPTS",
|
|
15, 15, lg.getWidth() - 30, "left" )
|
|
lg.printf( ("\n%s:%d\n%d"):format( ip, port, attempts ), 15, 15, lg.getWidth() - 30, "right" )
|
|
cancelButton:draw()
|
|
return false
|
|
end
|
|
|
|
function connecting.keypressed(key, code, isrepeat)
|
|
if code == "escape" then return scene.browser() end
|
|
end
|
|
|
|
function connecting.update(dt)
|
|
time = time + dt
|
|
|
|
if time > 5 then
|
|
--return scene.loadScene( scene.game )
|
|
end
|
|
return false
|
|
end
|
|
|
|
function connecting:onLoad( params )
|
|
lg.setCanvas()
|
|
time = 0
|
|
params = params or { ip = "8.8.8.8", port = 8 }
|
|
ip, port = params.ip, params.port
|
|
return server.isValid( ip, port ) and server.connect( ip, port )
|
|
end
|
|
|
|
function connecting.exit()
|
|
|
|
end
|
|
|
|
scene.connecting = connecting
|
|
return connecting |