More menu tweaks;
This commit is contained in:
parent
9ce6285d8c
commit
aa64929f8e
|
@ -18,4 +18,5 @@ return setmetatable({
|
||||||
["svinfo_ip"] = "IP",
|
["svinfo_ip"] = "IP",
|
||||||
["svinfo_port"] = "Port",
|
["svinfo_port"] = "Port",
|
||||||
["refresh_button"] = "Refresh",
|
["refresh_button"] = "Refresh",
|
||||||
|
["cancel_button"] = "Cancel",
|
||||||
}, {__index = function( t, k ) return k end } )
|
}, {__index = function( t, k ) return k end } )
|
|
@ -1,17 +1,39 @@
|
||||||
return {
|
local config = {}
|
||||||
name = "Player Name",
|
|
||||||
pronoun = "they/them/their",
|
local defaultConfig = {
|
||||||
colour = {0.8, 0.4, 0.4, 0.7},
|
plName = "Player Name",
|
||||||
|
plPronoun = "they/them/their",
|
||||||
|
plR = 0.8,
|
||||||
|
plG = 0.4,
|
||||||
|
plB = 0.4,
|
||||||
gamma = 0.5,
|
gamma = 0.5,
|
||||||
keybinds = {
|
keyForward = "w",
|
||||||
forward = "w",
|
keyBack = "s",
|
||||||
back = "s",
|
keyLeft = "a",
|
||||||
left = "a",
|
keyRight = "d",
|
||||||
right = "d",
|
keyChat = "t",
|
||||||
chat = "t",
|
keyLove = "q",
|
||||||
love = "q",
|
keyHate = "e",
|
||||||
hate = "e",
|
|
||||||
},
|
|
||||||
serverIP = "192.168.2.15",
|
serverIP = "192.168.2.15",
|
||||||
serverPort = 51312,
|
serverPort = 51312,
|
||||||
|
logFile = "../logs/log.txt",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function readConfigFile()
|
||||||
|
return dofile( "./cfg.lua" ) or defaultConfig
|
||||||
|
end
|
||||||
|
|
||||||
|
local function dumpConfigFile()
|
||||||
|
print( "Saving Settings." )
|
||||||
|
local cfg = assert(io.open( "./cfg.lua", "w" ))
|
||||||
|
cfg:write( "return {\n " )
|
||||||
|
for k, v in pairs( config ) do
|
||||||
|
cfg:write( k )
|
||||||
|
cfg:write( " = " )
|
||||||
|
cfg:write( tostring( v ) )
|
||||||
|
cfg:write( ",\n" )
|
||||||
|
end
|
||||||
|
cfg:write( "}" )
|
||||||
|
end
|
||||||
|
|
||||||
|
return config
|
|
@ -1,13 +1,38 @@
|
||||||
local scene = assert( require 'client.scene' )
|
local scene = assert( require 'client.scene' )
|
||||||
local lg = assert( love.graphics )
|
local lg = assert( love.graphics )
|
||||||
local server = assert( require 'client.udp' )
|
local server = assert( require 'client.udp' )
|
||||||
|
local button = assert( require 'client.ui.button' )
|
||||||
|
local strings = assert( require 'client.assets.strings.strings' )
|
||||||
local connecting = {}
|
local connecting = {}
|
||||||
|
|
||||||
local time, ip, port
|
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()
|
function connecting.draw()
|
||||||
lg.setColor( 1,1,1,1 )
|
lg.setColor( 1,1,1,1 )
|
||||||
lg.print( ("CONNECTING:\nTIME: %1.1fs\nADDRESS: %s:%d"):format(time, ip, port), 0, 0, 0 )
|
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
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,7 +44,7 @@ function connecting.update(dt)
|
||||||
time = time + dt
|
time = time + dt
|
||||||
|
|
||||||
if time > 5 then
|
if time > 5 then
|
||||||
return scene.loadScene( scene.game )
|
--return scene.loadScene( scene.game )
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -29,7 +54,11 @@ function connecting:onLoad( params )
|
||||||
time = 0
|
time = 0
|
||||||
params = params or { ip = "8.8.8.8", port = 8 }
|
params = params or { ip = "8.8.8.8", port = 8 }
|
||||||
ip, port = params.ip, params.port
|
ip, port = params.ip, params.port
|
||||||
return server.connect( ip, port )
|
return server.isValid( ip, port ) and server.connect( ip, port )
|
||||||
|
end
|
||||||
|
|
||||||
|
function connecting.exit()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.connecting = connecting
|
scene.connecting = connecting
|
||||||
|
|
|
@ -8,12 +8,11 @@ local callbacks = {
|
||||||
keypressed = true,
|
keypressed = true,
|
||||||
update = true,
|
update = true,
|
||||||
resize = true,
|
resize = true,
|
||||||
|
wheelmoved = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local mt = {}
|
local mt = {}
|
||||||
|
|
||||||
print( 'scene', scene )
|
|
||||||
|
|
||||||
function scene.loadScene( scen, params )
|
function scene.loadScene( scen, params )
|
||||||
print( "Loading Scene:", scen.name )
|
print( "Loading Scene:", scen.name )
|
||||||
for k, v in pairs( callbacks ) do
|
for k, v in pairs( callbacks ) do
|
||||||
|
|
|
@ -33,7 +33,7 @@ return {
|
||||||
--Simulate getting server info from the metaserver.
|
--Simulate getting server info from the metaserver.
|
||||||
getTestServers = function()
|
getTestServers = function()
|
||||||
packet.get()
|
packet.get()
|
||||||
for i = 1, r( 1, 13 ) do randserver() end
|
for i = 1, r( 1, 125 ) do randserver() end
|
||||||
return packet.deserialise( packet.get() )
|
return packet.deserialise( packet.get() )
|
||||||
end
|
end
|
||||||
}
|
}
|
|
@ -10,6 +10,13 @@ function udp.receive()
|
||||||
return cxn:receive()
|
return cxn:receive()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function udp.isValid( ip, port )
|
||||||
|
local s, e = socket.udp()
|
||||||
|
if s then s, e = s:setpeername( ip, port ) end
|
||||||
|
if s then return true
|
||||||
|
else return nil, e end --temporary socket, gc it, we just want the error
|
||||||
|
end
|
||||||
|
|
||||||
function udp.connect( ip, port )
|
function udp.connect( ip, port )
|
||||||
assert( cxn:setpeername( ip, port ) )
|
assert( cxn:setpeername( ip, port ) )
|
||||||
return udp.send( packet.get( packet.heartbeat{ tick = 0, hash = 1234 } ) )
|
return udp.send( packet.get( packet.heartbeat{ tick = 0, hash = 1234 } ) )
|
||||||
|
|
|
@ -5,18 +5,15 @@ local button = assert( require 'client.ui.button' )
|
||||||
local packet = assert( require 'shared.packet' )
|
local packet = assert( require 'shared.packet' )
|
||||||
local menu = assert( require 'client.ui.menu' )
|
local menu = assert( require 'client.ui.menu' )
|
||||||
local strings = assert( require 'client.assets.strings.strings' )
|
local strings = assert( require 'client.assets.strings.strings' )
|
||||||
|
local fonts = assert( require 'client.ui.fonts' )
|
||||||
local utf8 = assert( require 'utf8' )
|
local utf8 = assert( require 'utf8' )
|
||||||
|
|
||||||
local browser = {}
|
local browser = {}
|
||||||
|
|
||||||
local test = assert( require 'client.test.browser' )
|
local test = assert( require 'client.test.browser' )
|
||||||
|
|
||||||
|
local font = fonts.font
|
||||||
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 12 )
|
local cw = fonts.font:getWidth( "w" )
|
||||||
local headerFont = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 36 )
|
|
||||||
local midFont = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 24 )
|
|
||||||
|
|
||||||
local cw = font:getWidth( "w" )
|
|
||||||
|
|
||||||
local function joinServerCallback( button )
|
local function joinServerCallback( button )
|
||||||
if button.ip and button.port then
|
if button.ip and button.port then
|
||||||
|
@ -30,8 +27,8 @@ local function tryAdd( text, d, x )
|
||||||
end
|
end
|
||||||
|
|
||||||
local function serverInfoToText( server )
|
local function serverInfoToText( server )
|
||||||
local cw = font:getWidth( "w" )
|
local cw = fonts.font:getWidth( "w" )
|
||||||
local text = lg.newText( font )
|
local text = lg.newText( fonts.font )
|
||||||
tryAdd( text, server.svname, 0 )
|
tryAdd( text, server.svname, 0 )
|
||||||
tryAdd( text, server.map, cw * 16 )
|
tryAdd( text, server.map, cw * 16 )
|
||||||
text:add( tostring( server.ip ), cw * 32 )
|
text:add( tostring( server.ip ), cw * 32 )
|
||||||
|
@ -42,25 +39,14 @@ local function serverInfoToText( server )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local serverButtons = {}
|
|
||||||
local color = { 1, 0.6, 0.6, 0.1 }
|
|
||||||
local headerButtons = {
|
|
||||||
button{ x = cw * 53, color = color, y = 135, text = lg.newText( font, strings.svinfo_capacity ) },
|
|
||||||
button{ x = cw * 50, color = color, y = 135, text = lg.newText( font, strings.svinfo_players ) },
|
|
||||||
button{ x = cw * 44, color = color, y = 135, text = lg.newText( font, strings.svinfo_port ) },
|
|
||||||
button{ x = cw * 32, color = color, y = 135, text = lg.newText( font, strings.svinfo_ip ) },
|
|
||||||
button{ x = cw * 16, color = color, y = 135, text = lg.newText( font, strings.svinfo_map ) },
|
|
||||||
button{ x = cw , color = color, y = 135, text = lg.newText( font, strings.svinfo_name ) },
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
local serverList = menu.new{
|
local serverList = menu.new{
|
||||||
name = "serverList",
|
name = "serverList",
|
||||||
buttons = serverButtons,
|
buttons = {},
|
||||||
fg = lg.newMesh{
|
fg = lg.newMesh{
|
||||||
{ 0.5, 0, 0.5, 0, 0, 0, 0, 0 },
|
{ 0.5, 0, 0.5, 0, 0, 0, 0, 0 },
|
||||||
{ 1, 0, 1, 0, 1, 1, 1, 1 },
|
{ 1, 0, 1, 0, 1, 1, 1, 0.5 },
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1 },
|
{ 1, 1, 1, 1, 1, 1, 1, 0.5 },
|
||||||
{ 0.5, 1, 0.5, 1, 0, 0, 0, 0 },
|
{ 0.5, 1, 0.5, 1, 0, 0, 0, 0 },
|
||||||
},
|
},
|
||||||
bg = lg.newMesh{
|
bg = lg.newMesh{
|
||||||
|
@ -70,25 +56,69 @@ local serverList = menu.new{
|
||||||
{ 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.9 },
|
{ 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.9 },
|
||||||
},
|
},
|
||||||
|
|
||||||
font = font,
|
font = fonts.font,
|
||||||
subScene = true }
|
subScene = true }
|
||||||
serverList.selected = false
|
serverList.selected = false
|
||||||
serverList.x = 25
|
serverList.x = 25
|
||||||
serverList.y = 0
|
serverList.y = 0
|
||||||
serverList.h = 36
|
serverList.h = 36
|
||||||
|
local serverButtons = serverList.buttons
|
||||||
|
local color = { 1, 0.6, 0.6, 0.1 }
|
||||||
|
local ti = textInput.new{
|
||||||
|
width = lg.getWidth(),
|
||||||
|
length = 20,
|
||||||
|
x = cw,
|
||||||
|
y = 35,
|
||||||
|
h = 55,
|
||||||
|
str = strings.ip_button,
|
||||||
|
font = fonts.midFont,
|
||||||
|
}
|
||||||
|
function ti:callback() return self:enterText( browser.joinIPString ) end
|
||||||
|
local headerButtons = {
|
||||||
|
|
||||||
function serverList.refresh( serverInfo )
|
button{
|
||||||
|
callback = function() return serverList.refresh( test.getTestServers() ) end,
|
||||||
|
text = lg.newText( fonts.midFont, strings.refresh_button ) ,
|
||||||
|
color = color,
|
||||||
|
x = cw * 32,
|
||||||
|
y = 75,
|
||||||
|
w = 1400,
|
||||||
|
h = 36
|
||||||
|
},
|
||||||
|
|
||||||
|
button{
|
||||||
|
callback = function() return scene.mainmenu() end,
|
||||||
|
text = lg.newText( fonts.midFont, strings.mainmenu_button ) ,
|
||||||
|
color = color,
|
||||||
|
x = cw,
|
||||||
|
y = 75,
|
||||||
|
w = 1400,
|
||||||
|
},
|
||||||
|
|
||||||
|
ti,
|
||||||
|
|
||||||
|
button{ x = cw * 53, color = color, y = 135, text = lg.newText( font, strings.svinfo_capacity ) },
|
||||||
|
button{ x = cw * 50, color = color, y = 135, text = lg.newText( font, strings.svinfo_players ) },
|
||||||
|
button{ x = cw * 44, color = color, y = 135, text = lg.newText( font, strings.svinfo_port ) },
|
||||||
|
button{ x = cw * 32, color = color, y = 135, text = lg.newText( font, strings.svinfo_ip ) },
|
||||||
|
button{ x = cw * 16, color = color, y = 135, text = lg.newText( font, strings.svinfo_map ) },
|
||||||
|
button{ x = cw , color = color, y = 135, text = lg.newText( font, strings.svinfo_name ) },
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
local n = 1
|
|
||||||
for j, headerButton in ipairs( headerButtons ) do
|
for j, headerButton in ipairs( headerButtons ) do
|
||||||
serverButtons[j] = headerButton
|
serverButtons[j] = headerButton
|
||||||
n = n + 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function serverList.refresh( serverInfo )
|
||||||
|
local n = #headerButtons + 1
|
||||||
|
|
||||||
for i, server in ipairs( serverInfo ) do
|
for i, server in ipairs( serverInfo ) do
|
||||||
local b = serverButtons[n] or button{}
|
local b = serverButtons[n] or button{}
|
||||||
b.space = 0
|
b.space = 0
|
||||||
b.y = 15 + n * 27
|
b.x = cw
|
||||||
|
b.w = lg.getWidth()
|
||||||
|
b.y = 27 * i + 145
|
||||||
b.h = 24
|
b.h = 24
|
||||||
b.color = { 0.3 + 0.1 * (n % 2), 0.3 + 0.1 * (n % 2), 0.8, 0.5 }
|
b.color = { 0.3 + 0.1 * (n % 2), 0.3 + 0.1 * (n % 2), 0.8, 0.5 }
|
||||||
b.callback = joinServerCallback
|
b.callback = joinServerCallback
|
||||||
|
@ -96,28 +126,16 @@ function serverList.refresh( serverInfo )
|
||||||
b.ip = tostring( server.ip )
|
b.ip = tostring( server.ip )
|
||||||
b.port = server.port
|
b.port = server.port
|
||||||
b.text = serverInfoToText( server )
|
b.text = serverInfoToText( server )
|
||||||
|
b.active = ( b.y < lg.getHeight() )
|
||||||
serverButtons[n] = b
|
serverButtons[n] = b
|
||||||
n = n + 1
|
n = n + 1
|
||||||
print( "Button: ", i, b.y )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = #headerButtons + #serverInfo + 1, #headerButtons + #serverButtons do serverButtons[i] = nil end
|
for i = #headerButtons + #serverInfo + 1, #headerButtons + #serverButtons do serverButtons[i] = nil end
|
||||||
|
|
||||||
--for i = #headerButtons, 1, -1 do
|
|
||||||
-- table.insert( serverButtons, 1, headerButtons[i] )
|
|
||||||
--end
|
|
||||||
return serverList:paint()
|
return serverList:paint()
|
||||||
end
|
end
|
||||||
|
|
||||||
local refreshButton = button{
|
|
||||||
callback = serverList.onRefresh,
|
|
||||||
text = lg.newText( midFont, strings.refresh_button ) ,
|
|
||||||
color = { 1, 1, 1, 0.4 },
|
|
||||||
x = 450,
|
|
||||||
y = 75,
|
|
||||||
w = 400,
|
|
||||||
h = 55
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local rs = serverList.resize
|
local rs = serverList.resize
|
||||||
|
@ -136,25 +154,26 @@ do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ti = textInput.new{
|
function serverList.scroll( up )
|
||||||
width = 300,
|
local minY = 170
|
||||||
length = 20,
|
local maxY = lg.getHeight() + 40
|
||||||
x = 150,
|
if up and serverButtons[ #headerButtons + 1 ].y > minY then return end
|
||||||
y = 75,
|
if ( not up ) and serverButtons[ #serverButtons ].y < maxY then return end
|
||||||
str = "8.8.8.8:1234"
|
|
||||||
}
|
up = 10 * ( up and 1 or -1 )
|
||||||
|
for i = #headerButtons + 1, #serverButtons do
|
||||||
|
local sb = serverButtons[i]
|
||||||
|
sb.y = sb.y + up
|
||||||
|
sb.active = ( sb.y > minY ) and ( sb.y < maxY )
|
||||||
|
end
|
||||||
|
return serverList:paint()
|
||||||
|
end
|
||||||
|
|
||||||
browser.selected = false
|
browser.selected = false
|
||||||
|
|
||||||
function browser.draw()
|
function browser.draw()
|
||||||
serverList.draw()
|
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
lg.setFont( headerFont )
|
serverList.draw()
|
||||||
lg.print( strings.server_browser, 15, 15 )
|
|
||||||
lg.setFont( midFont )
|
|
||||||
lg.print( strings.ip_button, 15, 85 )
|
|
||||||
refreshButton:draw()
|
|
||||||
ti:draw()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.update( dt )
|
function browser.update( dt )
|
||||||
|
@ -167,17 +186,19 @@ function browser.onLoad( )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.mousemoved( x, y, dx, dy, istouch )
|
function browser.mousemoved( x, y, dx, dy, istouch )
|
||||||
refreshButton.selected = refreshButton:contains( x, y )
|
|
||||||
return serverList.mousemoved( x, y, dx, dy, istouch )
|
return serverList.mousemoved( x, y, dx, dy, istouch )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function browser.wheelmoved( x, y )
|
||||||
|
if y == 0 then return end
|
||||||
|
return serverList.scroll( ( y > 0 ) )
|
||||||
|
end
|
||||||
|
|
||||||
function browser.resize( x, y )
|
function browser.resize( x, y )
|
||||||
return serverList.resize( x, y )
|
return serverList.resize( x, y )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.mousepressed(x, y, button, istouch, pressed)
|
function browser.mousepressed(x, y, button, istouch, pressed)
|
||||||
if refreshButton.selected and refreshButton:contains( x, y ) then return serverList.refresh( test.getTestServers() ) end
|
|
||||||
if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end
|
|
||||||
return serverList.mousepressed( x, y, button, istouch, pressed )
|
return serverList.mousepressed( x, y, button, istouch, pressed )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -198,9 +219,7 @@ function browser.joinIP( ip, port )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.keypressed( key, code, isRepeat )
|
function browser.keypressed( key, code, isRepeat )
|
||||||
if code == "q" then return serverList.refresh( test.getTestServers() ) end
|
|
||||||
if code == "escape" then return scene.mainmenu() end
|
if code == "escape" then return scene.mainmenu() end
|
||||||
if code == "return" then return ti:enterText( browser.joinIPString ) end
|
|
||||||
return serverList.keypressed( key, code, isRepeat )
|
return serverList.keypressed( key, code, isRepeat )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ function button:new( t )
|
||||||
t.color = t.color or { 0.5, 0.5, 0.5, 0.5 }
|
t.color = t.color or { 0.5, 0.5, 0.5, 0.5 }
|
||||||
t.callback = t.callback or function() print( "Clicked button:", t.text ) end
|
t.callback = t.callback or function() print( "Clicked button:", t.text ) end
|
||||||
t.selected = t.selected or false
|
t.selected = t.selected or false
|
||||||
|
if t.active == nil then t.active = true end
|
||||||
|
|
||||||
button.y = button.y + t.h + button.space
|
button.y = button.y + t.h + button.space
|
||||||
|
|
||||||
|
@ -34,10 +35,11 @@ end
|
||||||
|
|
||||||
function button:contains( x, y )
|
function button:contains( x, y )
|
||||||
local mx, my, Mx, My = self.x, self.y, self.x + self.w, self.y + self.h
|
local mx, my, Mx, My = self.x, self.y, self.x + self.w, self.y + self.h
|
||||||
return (x < Mx and x > mx and y > my and y < My)
|
return self.active and (x < Mx and x > mx and y > my and y < My)
|
||||||
end
|
end
|
||||||
|
|
||||||
function button:draw( )
|
function button:draw( )
|
||||||
|
if not self.active then return end
|
||||||
lg.setColor( self.color )
|
lg.setColor( self.color )
|
||||||
lg.rectangle( "fill", self.x, self.y, self.w, self.h, 10)
|
lg.rectangle( "fill", self.x, self.y, self.w, self.h, 10)
|
||||||
|
|
||||||
|
@ -48,9 +50,9 @@ function button:draw( )
|
||||||
end
|
end
|
||||||
|
|
||||||
lg.setColor( 0, 0, 0, 0.8 )
|
lg.setColor( 0, 0, 0, 0.8 )
|
||||||
lg.draw( self.text, self.x + 15, self.y + 6)
|
lg.draw( self.text, self.x + 15, self.y + self.h / 2 - self.text:getHeight() / 2 )
|
||||||
lg.setColor( 0, 0, 0, 0.2 )
|
lg.setColor( 0, 0, 0, 0.2 )
|
||||||
lg.draw( self.text, self.x + 18, self.y + 8)
|
lg.draw( self.text, self.x + 12, self.y + self.h / 2 - self.text:getHeight() / 2 )-- + self.h / 2 )
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable( button, { __call = button.new } )
|
return setmetatable( button, { __call = button.new } )
|
|
@ -0,0 +1,9 @@
|
||||||
|
--References to font objects.
|
||||||
|
local lgnf = love.graphics.newFont
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
font = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 14 ),
|
||||||
|
midFont = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 24 ),
|
||||||
|
headerFont = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 36 )
|
||||||
|
}
|
|
@ -4,8 +4,7 @@ local scene = assert( require 'client.scene' )
|
||||||
local strings = strings or assert( require 'client.assets.strings.english' )
|
local strings = strings or assert( require 'client.assets.strings.english' )
|
||||||
local button = assert( require 'client.ui.button' )
|
local button = assert( require 'client.ui.button' )
|
||||||
local menu = assert( require 'client.ui.menu' )
|
local menu = assert( require 'client.ui.menu' )
|
||||||
|
local font = assert( require 'client.ui.fonts').headerFont
|
||||||
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
|
|
||||||
|
|
||||||
return menu.new{
|
return menu.new{
|
||||||
name = "mainmenu",
|
name = "mainmenu",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
local love = assert( love )
|
local love = assert( love )
|
||||||
local lg = assert( love.graphics )
|
local lg = assert( love.graphics )
|
||||||
local scene = assert( require 'client.scene' )
|
local scene = assert( require 'client.scene' )
|
||||||
print( 'scene', scene )
|
|
||||||
local menu = {}
|
local menu = {}
|
||||||
|
|
||||||
--Static variables.
|
--Static variables.
|
||||||
|
@ -30,14 +29,13 @@ function menu.new( t )
|
||||||
if t.subScene then setmetatable( t, t )
|
if t.subScene then setmetatable( t, t )
|
||||||
else
|
else
|
||||||
scene[t.name] = t
|
scene[t.name] = t
|
||||||
print( 'scene', scene )
|
|
||||||
end
|
end
|
||||||
getmetatable( t ).__index = menu
|
getmetatable( t ).__index = menu
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu:onLoad()
|
function menu:onLoad()
|
||||||
print( 'loading:', self.name )
|
print( 'Loading Menu:', self.name )
|
||||||
currentMenu = self
|
currentMenu = self
|
||||||
if self.font then lg.setFont( self.font ) end
|
if self.font then lg.setFont( self.font ) end
|
||||||
return menu.resize( lg.getDimensions() )
|
return menu.resize( lg.getDimensions() )
|
||||||
|
@ -112,37 +110,28 @@ function menu.keypressed( key, code, isrepeat )
|
||||||
return button:callback()
|
return button:callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
if code == "down" or code == "tab" or code == "up" then
|
if #buttons > 0 and (code == "down" or code == "tab" or code == "up") then
|
||||||
|
repeat
|
||||||
local sbi = (selectedButtonIdx or 1)
|
local sbi = (selectedButtonIdx or 1)
|
||||||
if buttons[sbi] then buttons[sbi].selected = false end
|
if buttons[sbi] then buttons[sbi].selected = false end
|
||||||
|
|
||||||
--Increment / decrement
|
--Increment / decrement
|
||||||
|
|
||||||
sbi = sbi + ((code == "up") and -1 or 1)
|
sbi = sbi + ((code == "up") and -1 or 1)
|
||||||
if #buttons < 1 then selectedButtonIdx = false; return end
|
if #buttons < 1 then selectedButtonIdx = false; return end
|
||||||
if sbi > #buttons then sbi = 1 end
|
if sbi > #buttons then sbi = 1 end
|
||||||
if sbi < 1 then sbi = #buttons end
|
if sbi < 1 then sbi = #buttons end
|
||||||
|
|
||||||
--Assign
|
|
||||||
print( "Selected button: ", sbi )
|
|
||||||
selectedButtonIdx = sbi
|
selectedButtonIdx = sbi
|
||||||
buttons[selectedButtonIdx].selected = true
|
buttons[selectedButtonIdx].selected = true
|
||||||
|
until buttons[selectedButtonIdx].active --Skip deactivated buttons.
|
||||||
|
print( "Selected button: ", selectedButtonIdx )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return currentMenu:paint()
|
return currentMenu:paint()
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu:randomColour()
|
|
||||||
|
|
||||||
local r = math.random
|
|
||||||
local v = r() * 0.4 + 0.6
|
|
||||||
local fg = self.fg
|
|
||||||
fg:setVertexAttribute( 2, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
|
||||||
fg:setVertexAttribute( 1, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) )
|
|
||||||
fg:setVertexAttribute( 4, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) )
|
|
||||||
fg:setVertexAttribute( 3, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
|
||||||
end
|
|
||||||
|
|
||||||
function menu:paint()
|
function menu:paint()
|
||||||
lg.setCanvas( canvas )
|
lg.setCanvas( canvas )
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ local strings = strings or assert( require 'client.assets.strings.english' )
|
||||||
local button = assert( require 'client.ui.button' )
|
local button = assert( require 'client.ui.button' )
|
||||||
local menu = assert( require 'client.ui.menu' )
|
local menu = assert( require 'client.ui.menu' )
|
||||||
local config = assert( require 'client.config' )
|
local config = assert( require 'client.config' )
|
||||||
|
local font = assert( require 'client.ui.fonts' ).midFont
|
||||||
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 18 )
|
|
||||||
|
|
||||||
local function editSelectedOption( button )
|
local function editSelectedOption( button )
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ local lg = assert( love.graphics )
|
||||||
|
|
||||||
local utf8 = assert( require 'utf8' )
|
local utf8 = assert( require 'utf8' )
|
||||||
local string = assert( string )
|
local string = assert( string )
|
||||||
|
local button = assert( require 'client.ui.button' )
|
||||||
|
|
||||||
local _lt
|
local _lt
|
||||||
local _lkp
|
local _lkp
|
||||||
|
@ -15,7 +16,7 @@ local _callback
|
||||||
local textInput = { }
|
local textInput = { }
|
||||||
local __mt = { __index = textInput }
|
local __mt = { __index = textInput }
|
||||||
|
|
||||||
local font = lg.newFont( 36 )
|
local font = lg.getFont()
|
||||||
|
|
||||||
-- There is only one active text input widget at a time.
|
-- There is only one active text input widget at a time.
|
||||||
-- It takes exclusive control of key input.
|
-- It takes exclusive control of key input.
|
||||||
|
@ -29,12 +30,13 @@ textInput.y = 0
|
||||||
function textInput.new( t )
|
function textInput.new( t )
|
||||||
t = t or {}
|
t = t or {}
|
||||||
t.str = t.str or ""
|
t.str = t.str or ""
|
||||||
t.text = lg.newText( font, t.str )
|
t.text = lg.newText( t.font or font, t.str )
|
||||||
return setmetatable( t, __mt )
|
return setmetatable( t, __mt )
|
||||||
end
|
end
|
||||||
|
|
||||||
function textInput.keypressed(key, code, isRepeat)
|
function textInput.keypressed(key, code, isRepeat)
|
||||||
if activeWidget and textInput[code] then return textInput[code]() end
|
if activeWidget and textInput[code] then textInput[code]() end
|
||||||
|
if _lkp then return _lkp() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function textInput:clear()
|
function textInput:clear()
|
||||||
|
@ -48,11 +50,12 @@ function textInput:contains(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function textInput:draw()
|
function textInput:draw()
|
||||||
local w, h = self.text:getDimensions()
|
local w = self.text:getWidth()
|
||||||
|
local h = (self.font or font):getHeight()
|
||||||
lg.setColor( 1, 1, 1, 0.5 )
|
lg.setColor( 1, 1, 1, 0.5 )
|
||||||
lg.rectangle( "fill", self.x, self.y, w, h )
|
if w > 1 then lg.rectangle( "fill", self.x, self.y, math.max( w, 30 ), h, 15, 15 ) end
|
||||||
if activeWidget == self then lg.rectangle( "fill", self.x, self.y, self.width, font:getHeight(), 5 ) end
|
if self.selected then lg.rectangle( "fill", self.x, self.y, self.width, h, 15, 15 ) end
|
||||||
lg.rectangle( "line", self.x - 3, self.y - 3, self.width + 6, font:getHeight() + 6, 5 )
|
lg.rectangle( "line", self.x - 3, self.y - 3, self.width + 6, h + 6, 15, 15 )
|
||||||
lg.setColor( 0, 0, 0, 1 )
|
lg.setColor( 0, 0, 0, 1 )
|
||||||
lg.draw( self.text, self.x or 0, self.y or 0)
|
lg.draw( self.text, self.x or 0, self.y or 0)
|
||||||
end
|
end
|
||||||
|
@ -64,6 +67,7 @@ end
|
||||||
function textInput.textInput( s )
|
function textInput.textInput( s )
|
||||||
activeWidget.str = activeWidget.str..s
|
activeWidget.str = activeWidget.str..s
|
||||||
activeWidget.text:set( activeWidget.str )
|
activeWidget.text:set( activeWidget.str )
|
||||||
|
if _lkp then return _lkp() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function textInput.backspace( )
|
function textInput.backspace( )
|
||||||
|
@ -83,7 +87,11 @@ function textInput:enterText( callback )
|
||||||
_callback = assert( callback )
|
_callback = assert( callback )
|
||||||
love.textinput = textInput.textInput
|
love.textinput = textInput.textInput
|
||||||
love.keypressed = textInput.keypressed
|
love.keypressed = textInput.keypressed
|
||||||
|
love.mousepressed = nil
|
||||||
|
love.mousemoved = nil
|
||||||
self.oldStr = self.str
|
self.oldStr = self.str
|
||||||
|
self.str = ""
|
||||||
|
self.text:set( self.str )
|
||||||
activeWidget = self
|
activeWidget = self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
--Client starts here!
|
|
||||||
local shared = assert( require 'shared' )
|
local shared = assert( require 'shared' )
|
||||||
local love = assert( love )
|
local love = assert( love )
|
||||||
|
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
print( "Client Started." )
|
||||||
|
assert( require 'client.config' )
|
||||||
|
|
||||||
--Crash unless coconut present and running luajit 2.1
|
--Crash unless coconut present and running luajit 2.1
|
||||||
loadstring( love.data.decode( "string", "base64","G0xKAgrbAQAACgALABY2AAAAOQABADkAAgAnAgMAJwMEADYEAAA5BAEEOQQFBCcGBgA2BwAAOQcHBzkHCAcnCQkAQgcCAEEEAQBBAAICBgAKAFgAAoArAAEAWAEBgCsAAgBMAAIALWQ4MmY3M2RkNjQ1MDcxNDZiNTkwNTMwYjg0NDcwMWZlMmJmYjdjZTkeY2xpZW50L2Fzc2V0cy9jb2NvbnV0LnBuZxFuZXdJbWFnZURhdGEKaW1hZ2UJc2hhMQloYXNoCGhleAtzdHJpbmcLZW5jb2RlCWRhdGEJbG92ZV0BAAUABQAONgAAADMCAQBCAAICDgAAAFgBB4A2AAIANAIAADUDAwA2BAAAPQQEA0IAAwJCAAECMgAAgEwAAgALX19jYWxsAQAAEXNldG1ldGF0YWJsZQAKcGNhbGwA" ))()
|
loadstring( love.data.decode( "string", "base64","G0xKAgrbAQAACgALABY2AAAAOQABADkAAgAnAgMAJwMEADYEAAA5BAEEOQQFBCcGBgA2BwAAOQcHBzkHCAcnCQkAQgcCAEEEAQBBAAICBgAKAFgAAoArAAEAWAEBgCsAAgBMAAIALWQ4MmY3M2RkNjQ1MDcxNDZiNTkwNTMwYjg0NDcwMWZlMmJmYjdjZTkeY2xpZW50L2Fzc2V0cy9jb2NvbnV0LnBuZxFuZXdJbWFnZURhdGEKaW1hZ2UJc2hhMQloYXNoCGhleAtzdHJpbmcLZW5jb2RlCWRhdGEJbG92ZV0BAAUABQAONgAAADMCAQBCAAICDgAAAFgBB4A2AAIANAIAADUDAwA2BAAAPQQEA0IAAwJCAAECMgAAgEwAAgALX19jYWxsAQAAEXNldG1ldGF0YWJsZQAKcGNhbGwA" ))()
|
||||||
|
|
||||||
|
@ -18,3 +20,7 @@ function love.load()
|
||||||
assert( require 'client.connecting' )
|
assert( require 'client.connecting' )
|
||||||
scenes.loadScene( scenes.mainmenu )
|
scenes.loadScene( scenes.mainmenu )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.quit()
|
||||||
|
print( "Client Quit." )
|
||||||
|
end
|
|
@ -25,8 +25,7 @@ local clients = {}
|
||||||
do
|
do
|
||||||
local _print = print
|
local _print = print
|
||||||
function server.Print(...)
|
function server.Print(...)
|
||||||
local time = os.date("!%Y-%m-%d %X")
|
_print( os.date("!%Y-%m-%d %X"), ... )
|
||||||
_print( time, ... )
|
|
||||||
--server.logFile:write( table.concat({ ... }, "\t"), "\n" )
|
--server.logFile:write( table.concat({ ... }, "\t"), "\n" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,10 @@ local shared = {}
|
||||||
|
|
||||||
shared.ip = assert( require 'shared.ipstring' )
|
shared.ip = assert( require 'shared.ipstring' )
|
||||||
shared.packet = assert( require 'shared.packet' )
|
shared.packet = assert( require 'shared.packet' )
|
||||||
|
shared.print = assert( require 'shared.print' )
|
||||||
|
|
||||||
|
--Turn on logging?
|
||||||
|
print = shared.print
|
||||||
|
|
||||||
|
|
||||||
--World state.
|
--World state.
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
local _print = print
|
||||||
|
local log = assert( io.open( ("../logs/log_%04d.txt"):format( os.time() % 1000 ), "a" ))
|
||||||
|
return function( ... )
|
||||||
|
|
||||||
|
log:write( os.date("!%S") )
|
||||||
|
for i, v in ipairs{...} do
|
||||||
|
log:write("\t")
|
||||||
|
log:write(tostring(v))
|
||||||
|
end
|
||||||
|
log:write("\n")
|
||||||
|
|
||||||
|
return _print( ... )
|
||||||
|
end
|
Loading…
Reference in New Issue