Compare commits
2 Commits
dc6cdf123e
...
4a7be75dfa
Author | SHA1 | Date |
---|---|---|
wan-may | 4a7be75dfa | |
wan-may | e6b9e7aa13 |
25
build.sh
25
build.sh
|
@ -1,10 +1,33 @@
|
||||||
|
#get locations of scripts, libraries, engine
|
||||||
SRC_DIR="src"
|
SRC_DIR="src"
|
||||||
|
LIB_DIR="lib"
|
||||||
LOVE_DIR="../../love"
|
LOVE_DIR="../../love"
|
||||||
BUILD_DIR="build"
|
BUILD_DIR="build"
|
||||||
|
|
||||||
|
#build LuaJIT for target platform
|
||||||
|
|
||||||
|
|
||||||
|
#build LuaSocket shared library for target platform
|
||||||
|
|
||||||
|
|
||||||
|
#get appropriate copy of love
|
||||||
|
|
||||||
|
|
||||||
|
#zip client scripts into .love file
|
||||||
cp -r $SRC_DIR/ $BUILD_DIR/
|
cp -r $SRC_DIR/ $BUILD_DIR/
|
||||||
cd $BUILD_DIR/
|
cd $BUILD_DIR/
|
||||||
zip -9 -r vision.love
|
zip -9 -r vision.love
|
||||||
|
|
||||||
|
#zip .love file with LOVE and dependencies (and license!)
|
||||||
|
|
||||||
|
|
||||||
|
#zip server scripts with LuaJIT and dependencies
|
||||||
|
|
||||||
|
|
||||||
|
#zip metaserver with LuaJIT and dependencies
|
||||||
|
|
||||||
|
|
||||||
|
#WINDOWS: make fused client executable
|
||||||
cat ../../love/love.exe vision.love > vision.exe
|
cat ../../love/love.exe vision.love > vision.exe
|
||||||
|
|
||||||
|
#LINUX: get official LOVE AppImage
|
|
@ -8,4 +8,13 @@ return setmetatable({
|
||||||
["option_pron"] = "Player Pronouns",
|
["option_pron"] = "Player Pronouns",
|
||||||
["option_tint"] = "Player Colour",
|
["option_tint"] = "Player Colour",
|
||||||
["option_keybinds"] = "Edit Keybindings",
|
["option_keybinds"] = "Edit Keybindings",
|
||||||
|
["utf8_error"] = "??? what is this",
|
||||||
|
["server_browser"] = "Server Browser",
|
||||||
|
["ip_button"] = "Enter IP:",
|
||||||
|
["svinfo_name"] = "Server Name",
|
||||||
|
["svinfo_map"] = "Current Map",
|
||||||
|
["svinfo_players"] = "In",
|
||||||
|
["svinfo_capacity"] = "Max",
|
||||||
|
["svinfo_ip"] = "IP",
|
||||||
|
["svinfo_port"] = "Port",
|
||||||
}, {__index = function( t, k ) return k end } )
|
}, {__index = function( t, k ) return k end } )
|
|
@ -0,0 +1,3 @@
|
||||||
|
--TODO: check config option for current language, dynamically change it?
|
||||||
|
local utf8 = assert( require 'utf8' )
|
||||||
|
return require 'client.assets.strings.english'
|
|
@ -11,7 +11,7 @@ return {
|
||||||
chat = "t",
|
chat = "t",
|
||||||
love = "q",
|
love = "q",
|
||||||
hate = "e",
|
hate = "e",
|
||||||
}
|
},
|
||||||
serverIP = "192.168.2.15",
|
serverIP = "192.168.2.15",
|
||||||
serverPort = 51312,
|
serverPort = 51312,
|
||||||
}
|
}
|
|
@ -3,13 +3,18 @@ local lg = assert( love.graphics )
|
||||||
local server = assert( require 'client.udp' )
|
local server = assert( require 'client.udp' )
|
||||||
local connecting = {}
|
local connecting = {}
|
||||||
|
|
||||||
local time, ip, port = 0
|
local time, ip, port
|
||||||
|
|
||||||
function connecting.draw()
|
function connecting.draw()
|
||||||
lg.print( "Connecting to server:\t"..time, 0, 0, 0 )
|
lg.setColor( 1,1,1,1 )
|
||||||
|
lg.print( ("CONNECTING:\nTIME: %1.1fs\nADDRESS: %s:%d"):format(time, ip, port), 0, 0, 0 )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function connecting.keypressed(key, code, isrepeat)
|
||||||
|
if code == "escape" then return scene.browser() end
|
||||||
|
end
|
||||||
|
|
||||||
function connecting.update(dt)
|
function connecting.update(dt)
|
||||||
time = time + dt
|
time = time + dt
|
||||||
|
|
||||||
|
@ -20,8 +25,12 @@ function connecting.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function connecting:onLoad( params )
|
function connecting:onLoad( params )
|
||||||
params = params or { ip = "127.0.0.0", port = 8 }
|
lg.setCanvas()
|
||||||
local ip, port = params.ip, params.port
|
time = 0
|
||||||
|
print( "connecting:", params, self.ip, self.port )
|
||||||
|
for k, v in pairs( self ) do print( k,v ) end
|
||||||
|
params = params or { ip = "8.8.8.8", port = 8 }
|
||||||
|
ip, port = params.ip, params.port
|
||||||
return server.connect( ip, port )
|
return server.connect( ip, port )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ function game.disconnect( )
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.onLoad( params )
|
function game.onLoad( params )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.keypressed( key, code, isRepeat )
|
function game.keypressed( key, code, isRepeat )
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
local packet = assert( require 'shared.packet' )
|
||||||
|
local ipString = assert( require 'shared.ipstring' )
|
||||||
|
local utf8 = assert( require 'utf8' )
|
||||||
|
local r = math.random
|
||||||
|
local rand = function() return r( 1, 255 ) end
|
||||||
|
local rs = function()
|
||||||
|
local t = {}
|
||||||
|
for i = 1, r( 0, 64 ) do t[i] = rand() end
|
||||||
|
return string.char( unpack( t ) )
|
||||||
|
end
|
||||||
|
local rutf8 = function()
|
||||||
|
local t = {}
|
||||||
|
for i = 1, r( 0, 64 ) do t[i] = r( 30, 1234 ) end
|
||||||
|
|
||||||
|
local s = utf8.char( unpack( t ) )
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
local randserver = function()
|
||||||
|
local str = rutf8
|
||||||
|
return packet.serverInfo{
|
||||||
|
players = rand(),
|
||||||
|
capacity = rand(),
|
||||||
|
ip = ipString.new{ rand(), rand(), rand(), rand() },
|
||||||
|
port = r( 1, 65535 ),
|
||||||
|
version = 25,
|
||||||
|
svname = str(),
|
||||||
|
map = str(),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
--Simulate getting server info from the metaserver.
|
||||||
|
getTestServers = function()
|
||||||
|
packet.get()
|
||||||
|
for i = 1, r( 1, 128 ) do randserver() end
|
||||||
|
return packet.deserialise( packet.get() )
|
||||||
|
end
|
||||||
|
}
|
|
@ -3,94 +3,84 @@ local scene = assert( require 'client.scene' )
|
||||||
local textInput = assert( require 'client.ui.textinput' )
|
local textInput = assert( require 'client.ui.textinput' )
|
||||||
local button = assert( require 'client.ui.button' )
|
local button = assert( require 'client.ui.button' )
|
||||||
local packet = assert( require 'shared.packet' )
|
local packet = assert( require 'shared.packet' )
|
||||||
local ipString = assert( require 'shared.ipstring' )
|
local menu = assert( require 'client.ui.menu' )
|
||||||
|
local strings = assert( require 'client.assets.strings.strings' )
|
||||||
|
local utf8 = assert( require 'utf8' )
|
||||||
|
local gs = function( d )
|
||||||
|
local s = packet.getString( d )
|
||||||
|
local valid, trip = utf8.len( s )
|
||||||
|
return valid and s or --Regurgitate name.
|
||||||
|
( trip > 1 ) and s:sub( 1, trip - 1 ) or --Attempt truncation to initial valid utf8 sequence.
|
||||||
|
strings.utf8_error --Return fallback string indicating garbled mess.
|
||||||
|
end
|
||||||
local browser = {}
|
local browser = {}
|
||||||
|
|
||||||
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 20 )
|
local test = assert( require 'client.test.browser' )
|
||||||
|
|
||||||
local function populateTestServers()
|
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 12 )
|
||||||
packet.get()
|
local headerFont = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 36 )
|
||||||
packet.serverInfo{
|
local midFont = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 24 )
|
||||||
players = 24,
|
|
||||||
capacity = 255,
|
local function joinServerCallback( button )
|
||||||
ip = ipString.new{ 123, 456, 789, 101 },
|
if button.ip and button.port then
|
||||||
port = 51312,
|
return browser.joinIP( button.ip, button.port )
|
||||||
version = 25,
|
end
|
||||||
svname = "test server",
|
|
||||||
map = "testMap_01",
|
|
||||||
}
|
|
||||||
packet.serverInfo{
|
|
||||||
players = 24,
|
|
||||||
capacity = 255,
|
|
||||||
ip = ipString.new{ 123, 456, 789, 101 },
|
|
||||||
port = 51312,
|
|
||||||
version = 25,
|
|
||||||
svname = "test server",
|
|
||||||
map = "testMap_02",
|
|
||||||
}
|
|
||||||
packet.serverInfo{
|
|
||||||
players = 24,
|
|
||||||
capacity = 255,
|
|
||||||
ip = ipString.new{ 150, 645, 151, 67 },
|
|
||||||
port = 51312,
|
|
||||||
version = 25,
|
|
||||||
svname = "test server",
|
|
||||||
map = "testMap_03",
|
|
||||||
}
|
|
||||||
packet.serverInfo{
|
|
||||||
players = 24,
|
|
||||||
capacity = 255,
|
|
||||||
ip = ipString.new{ 123, 456, 789, 101 },
|
|
||||||
port = 51312,
|
|
||||||
version = 25,
|
|
||||||
svname = "test server",
|
|
||||||
map = "testMap_01",
|
|
||||||
}
|
|
||||||
return packet.deserialise( packet.get() )
|
|
||||||
end
|
end
|
||||||
local serverList = {}
|
|
||||||
serverList.servers = populateTestServers()
|
local serverButtons = test.getTestServers()
|
||||||
serverList.offsets = {
|
do
|
||||||
15,
|
local cw = font:getWidth( "w" )
|
||||||
50,
|
|
||||||
150,
|
|
||||||
100,
|
local headerText = lg.newText( font )
|
||||||
100,
|
headerText:add( strings.svinfo_name, 0 )
|
||||||
50,
|
headerText:add( strings.svinfo_map, cw * 16 )
|
||||||
50
|
headerText:add( strings.svinfo_ip, cw * 32 )
|
||||||
|
headerText:add( strings.svinfo_port, cw * ( 32 + 12 ) )
|
||||||
|
headerText:add( strings.svinfo_players, cw * ( 32 + 12 + 6 ) )
|
||||||
|
headerText:add( strings.svinfo_capacity, cw * ( 32 + 12 + 9 ) )
|
||||||
|
local headerButton = button{
|
||||||
|
space = 15, y = 135, text = headerText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, server in ipairs( serverButtons ) do
|
||||||
|
local text = lg.newText( font )
|
||||||
|
text:add( gs( server.svname ), 0 )
|
||||||
|
text:add( gs( server.map ), cw * 16 )
|
||||||
|
text:add( tostring( server.ip ), cw * 32 )
|
||||||
|
text:add( server.port, cw * ( 32 + 12 ) )
|
||||||
|
text:add( server.players, cw * ( 32 + 12 + 6 ) )
|
||||||
|
text:add( server.capacity, cw * ( 32 + 12 + 9 ) )
|
||||||
|
|
||||||
|
serverButtons[i] = button{ space = 0,
|
||||||
|
ip = tostring( server.ip ),
|
||||||
|
port = server.port,
|
||||||
|
text = text,
|
||||||
|
callback = joinServerCallback,
|
||||||
|
color = { 0.3 + 0.1 * (i % 2), 0.3 + 0.1 * (i % 2), 0.8, 0.5 }}
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert( serverButtons, 1, headerButton )
|
||||||
|
|
||||||
|
end
|
||||||
|
local serverList = menu.new{
|
||||||
|
name = "serverList",
|
||||||
|
buttons = serverButtons,
|
||||||
|
fg = nil,
|
||||||
|
bg = lg.newMesh{
|
||||||
|
{ 0, 0, 0, 0, 0.4, 0.05, 0.0, 0.1 },
|
||||||
|
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
||||||
|
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
||||||
|
{ 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.1 },
|
||||||
|
},
|
||||||
|
|
||||||
|
font = font,
|
||||||
|
subScene = true }
|
||||||
serverList.selected = false
|
serverList.selected = false
|
||||||
serverList.x = 25
|
serverList.x = 25
|
||||||
serverList.y = 220
|
serverList.y = 0
|
||||||
serverList.h = 36
|
serverList.h = 36
|
||||||
|
|
||||||
function serverList.draw()
|
|
||||||
local gs = packet.getString
|
|
||||||
local x, y, h = serverList.x, serverList.y, serverList.h
|
|
||||||
local oldFont = lg.getFont()
|
|
||||||
lg.setFont( font )
|
|
||||||
for i, svInfo in ipairs( serverList.servers ) do
|
|
||||||
lg.setColor( 0.7, 0.7, 0.7, 0.7 )
|
|
||||||
lg.rectangle( "fill", x, y, 800, h, 5, 5 )
|
|
||||||
|
|
||||||
x = x + 15
|
|
||||||
y = y + 9
|
|
||||||
lg.setColor( 0, 0, 0, 0.7 )
|
|
||||||
lg.print( svInfo.version, x, y )
|
|
||||||
lg.print( gs( svInfo.svname ), 50 + x, y )
|
|
||||||
lg.print( tostring( svInfo.ip ), 200 + x, y )
|
|
||||||
lg.print( svInfo.port, 300 + x, y )
|
|
||||||
lg.print( svInfo.players, 400 + x, y )
|
|
||||||
lg.print( svInfo.capacity, 450 + x, y )
|
|
||||||
lg.print( gs( svInfo.map ), 500 + x, y )
|
|
||||||
y = y - 12
|
|
||||||
x = x - 15
|
|
||||||
y = y + h + 5
|
|
||||||
end
|
|
||||||
lg.setFont( oldFont )
|
|
||||||
end
|
|
||||||
|
|
||||||
function serverList.select()
|
function serverList.select()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -106,15 +96,21 @@ end
|
||||||
local ti = textInput.new{
|
local ti = textInput.new{
|
||||||
width = 300,
|
width = 300,
|
||||||
length = 20,
|
length = 20,
|
||||||
x = 15,
|
x = 150,
|
||||||
y = 175
|
y = 75,
|
||||||
|
str = "8.8.8.8:1234"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browser.selected = false
|
||||||
|
|
||||||
function browser.draw()
|
function browser.draw()
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
|
||||||
lg.print( "Server Browser", 15, 115 )
|
|
||||||
ti:draw()
|
|
||||||
serverList.draw()
|
serverList.draw()
|
||||||
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
|
lg.setFont( headerFont )
|
||||||
|
lg.print( strings.server_browser, 15, 15 )
|
||||||
|
lg.setFont( midFont )
|
||||||
|
lg.print( strings.ip_button, 15, 85 )
|
||||||
|
ti:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.update( dt )
|
function browser.update( dt )
|
||||||
|
@ -122,31 +118,43 @@ function browser.update( dt )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.onLoad( )
|
function browser.onLoad( )
|
||||||
|
serverList:onLoad()
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function browser.mousemoved( x, y, dx, dy, istouch )
|
||||||
|
return serverList.mousemoved( x, y, dx, dy, istouch )
|
||||||
|
end
|
||||||
|
|
||||||
|
function browser.resize( x, y )
|
||||||
|
return serverList.resize( x, y )
|
||||||
|
end
|
||||||
|
|
||||||
function browser.mousepressed(x, y, button, istouch, pressed)
|
function browser.mousepressed(x, y, button, istouch, pressed)
|
||||||
if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end
|
if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end
|
||||||
|
return serverList.mousepressed( x, y, button, istouch, pressed )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.joinIPString( s )
|
function browser.joinIPString( s )
|
||||||
--Parse IP address and port from string. If it's valid, join the server.
|
--Parse IP address and port from string. If it's valid, join the server.
|
||||||
print( "browser: Attempting to join server", s )
|
print( "browser: entered IP and port", s )
|
||||||
if not s then return end
|
if not s then return end
|
||||||
ti:clear()
|
ti:clear()
|
||||||
local valid, ip, port
|
local ip, port = s:match '(%d+%.%d+%.%d+%.%d+)', s:match ':(%d+)'
|
||||||
|
print( "browser:", "ip:", ip, port )
|
||||||
|
|
||||||
if valid then return browser.joinIP( ip, port ) end
|
if ip and port then return browser.joinIP( ip, port ) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.joinIP( ip, port )
|
function browser.joinIP( ip, port )
|
||||||
print( "Joining server:", ip, port )
|
print( "Joining server:", ip, port )
|
||||||
return scene.game{ serverIP = ip, serverPort = port }
|
return scene.loadScene( scene.connecting, { ip = ip, port = port } )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.keypressed( key, code, isRepeat )
|
function browser.keypressed( key, code, isRepeat )
|
||||||
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
|
if code == "return" then return ti:enterText( browser.joinIPString ) end
|
||||||
|
return serverList.keypressed( key, code, isRepeat )
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.browser = browser
|
scene.browser = browser
|
||||||
|
|
|
@ -16,12 +16,13 @@ function button:new( t )
|
||||||
if t.h then button.h = t.h end
|
if t.h then button.h = t.h end
|
||||||
if t.w then button.w = t.w end
|
if t.w then button.w = t.w end
|
||||||
if t.x then button.x = t.x end
|
if t.x then button.x = t.x end
|
||||||
|
if t.space then button.space = t.space end
|
||||||
|
|
||||||
t.x = t.x or button.x
|
t.x = t.x or button.x
|
||||||
t.y = t.y or button.y
|
t.y = t.y or button.y
|
||||||
t.w = t.w or button.w
|
t.w = t.w or button.w
|
||||||
t.h = t.h or button.h
|
t.h = t.h or button.h
|
||||||
t.text = t.text or ""
|
t.text = t.text or lg.newText( lg.getFont(), "button" )
|
||||||
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
|
||||||
|
@ -47,9 +48,9 @@ function button:draw( )
|
||||||
end
|
end
|
||||||
|
|
||||||
lg.setColor( 0, 0, 0, 0.8 )
|
lg.setColor( 0, 0, 0, 0.8 )
|
||||||
lg.print( self.text, self.x + 15, self.y + 6)
|
lg.draw( self.text, self.x + 15, self.y + 6)
|
||||||
lg.setColor( 0, 0, 0, 0.2 )
|
lg.setColor( 0, 0, 0, 0.2 )
|
||||||
lg.print( self.text, self.x + 18, self.y + 8)
|
lg.draw( self.text, self.x + 18, self.y + 8)
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable( button, { __call = button.new } )
|
return setmetatable( button, { __call = button.new } )
|
|
@ -5,47 +5,49 @@ 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' )
|
||||||
|
|
||||||
return menu.new(
|
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
|
||||||
"mainmenu",
|
|
||||||
|
|
||||||
{
|
return menu.new{
|
||||||
|
name = "mainmenu",
|
||||||
|
|
||||||
|
buttons = {
|
||||||
|
|
||||||
button{
|
button{
|
||||||
x = 15, w = lg.getWidth(), y = 115, h = 72,
|
x = 15, w = lg.getWidth(), y = 115, h = 72, space = 15,
|
||||||
text = strings.newgame_button,
|
text = lg.newText( font, strings.newgame_button ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.9 },
|
color = { 0.6, 0.6, 0.6, 0.9 },
|
||||||
callback = function() return scene.connecting() end },
|
callback = function() return scene.connecting{ip = "127.0.0.0", port = 8} end },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
text = strings.join_button,
|
text = lg.newText( font, strings.join_button ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.9 },
|
color = { 0.6, 0.6, 0.6, 0.9 },
|
||||||
callback = function() return scene.browser() end },
|
callback = function() return scene.browser() end },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
text = strings.option_button,
|
text = lg.newText( font, strings.option_button ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.9 },
|
color = { 0.6, 0.6, 0.6, 0.9 },
|
||||||
callback = function() return scene.options() end },
|
callback = function() return scene.options() end },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
text = strings.quit_button,
|
text = lg.newText( font, strings.quit_button ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.9 },
|
color = { 0.6, 0.6, 0.6, 0.9 },
|
||||||
callback = love.event.quit },
|
callback = love.event.quit },
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
lg.newMesh{
|
fg = lg.newMesh{
|
||||||
{ 0, 0, 0, 0, 0.4, 0.1, 0.05, 0.0 },
|
{ 0, 0, 0, 0, 0.4, 0.1, 0.05, 0.0 },
|
||||||
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
||||||
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
||||||
{ 0, 1, 0, 1, 0.4, 0.1, 0.03, 0.0 },
|
{ 0, 1, 0, 1, 0.4, 0.1, 0.03, 0.0 },
|
||||||
},
|
},
|
||||||
|
|
||||||
lg.newMesh{
|
bg = lg.newMesh{
|
||||||
{ 0, 0, 0, 0, 0.4, 0.05, 0.0, 0.1 },
|
{ 0, 0, 0, 0, 0.4, 0.05, 0.0, 0.1 },
|
||||||
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
||||||
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
||||||
{ 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.1 },
|
{ 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.1 },
|
||||||
},
|
},
|
||||||
|
|
||||||
lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
|
font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
|
||||||
)
|
}
|
|
@ -10,10 +10,16 @@ local canvas
|
||||||
local wWidth, wHeight
|
local wWidth, wHeight
|
||||||
local currentMenu
|
local currentMenu
|
||||||
|
|
||||||
function menu.new( name, buttons, fg, bg, font )
|
function menu.getSelectedButton()
|
||||||
local t = { buttons = buttons, fg = fg, bg = bg, font = font or lg.getFont() }
|
return currentMenu.buttons[selectedButtonIdx]
|
||||||
scene[name] = t
|
end
|
||||||
|
|
||||||
|
function menu.new( t )
|
||||||
|
if t.subScene then setmetatable( t, t )
|
||||||
|
else
|
||||||
|
scene[t.name] = t
|
||||||
print( 'scene', scene )
|
print( 'scene', scene )
|
||||||
|
end
|
||||||
getmetatable( t ).__index = menu
|
getmetatable( t ).__index = menu
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
@ -21,7 +27,7 @@ end
|
||||||
function menu:onLoad()
|
function menu:onLoad()
|
||||||
print( 'loading:', self.name )
|
print( 'loading:', self.name )
|
||||||
currentMenu = self
|
currentMenu = self
|
||||||
lg.setFont( self.font )
|
if self.font then lg.setFont( self.font ) end
|
||||||
return menu.resize( lg.getDimensions() )
|
return menu.resize( lg.getDimensions() )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -117,7 +123,9 @@ function menu:paint()
|
||||||
|
|
||||||
--bg
|
--bg
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
|
if self.bg then
|
||||||
lg.draw( self.bg, 0, 0, 0, wWidth, wHeight )
|
lg.draw( self.bg, 0, 0, 0, wWidth, wHeight )
|
||||||
|
end
|
||||||
|
|
||||||
--buttons
|
--buttons
|
||||||
for i = #self.buttons, 1, -1 do self.buttons[i]:draw( ) end
|
for i = #self.buttons, 1, -1 do self.buttons[i]:draw( ) end
|
||||||
|
@ -127,12 +135,14 @@ function menu:paint()
|
||||||
local r = math.random
|
local r = math.random
|
||||||
local v = r() * 0.4 + 0.6
|
local v = r() * 0.4 + 0.6
|
||||||
|
|
||||||
|
if self.fg then
|
||||||
local fg = self.fg
|
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( 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( 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( 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 )
|
fg:setVertexAttribute( 3, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
||||||
lg.draw( fg, 0, 0, 0, wWidth, wHeight )
|
lg.draw( fg, 0, 0, 0, wWidth, wHeight )
|
||||||
|
end
|
||||||
lg.setCanvas()
|
lg.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,45 +5,47 @@ 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' )
|
||||||
|
|
||||||
return menu.new(
|
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 18 )
|
||||||
"options",
|
|
||||||
|
|
||||||
{
|
return menu.new{
|
||||||
|
name = "options",
|
||||||
|
|
||||||
|
buttons = {
|
||||||
|
|
||||||
button{
|
button{
|
||||||
x = 15, y = 115, w = 800, h = 30,
|
x = 15, y = 115, w = 800, h = 30, space = 8,
|
||||||
text = strings.mainmenu_button,
|
text = lg.newText( font, strings.mainmenu_button ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.8 },
|
color = { 0.6, 0.6, 0.6, 0.8 },
|
||||||
callback = function() return scene.mainmenu() end },
|
callback = function() return scene.mainmenu() end },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
option = 'name',
|
option = 'name',
|
||||||
text = strings.option_name,
|
text = lg.newText( font, strings.option_name ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.8 },
|
color = { 0.6, 0.6, 0.6, 0.8 },
|
||||||
callback = menu.textOption },
|
callback = menu.textOption },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
option = 'pronoun',
|
option = 'pronoun',
|
||||||
text = strings.option_pron,
|
text = lg.newText( font, strings.option_pron ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.8 },
|
color = { 0.6, 0.6, 0.6, 0.8 },
|
||||||
callback = menu.textOption },
|
callback = menu.textOption },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
option = 'colour',
|
option = 'colour',
|
||||||
text = strings.option_tint,
|
text = lg.newText( font, strings.option_tint ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.8 },
|
color = { 0.6, 0.6, 0.6, 0.8 },
|
||||||
callback = menu.colourOption },
|
callback = menu.colourOption },
|
||||||
|
|
||||||
|
|
||||||
button{
|
button{
|
||||||
option = 'keybinds',
|
option = 'keybinds',
|
||||||
text = strings.option_keybinds,
|
text = lg.newText( font, strings.option_keybinds ),
|
||||||
color = { 0.6, 0.6, 0.6, 0.8 },
|
color = { 0.6, 0.6, 0.6, 0.8 },
|
||||||
callback = menu.editKeybinds,
|
callback = menu.editKeybinds,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
lg.newMesh{
|
fg = lg.newMesh{
|
||||||
{ 0, 0, 0, 0, 0.4, 0.1, 0.05, 0.0 },
|
{ 0, 0, 0, 0, 0.4, 0.1, 0.05, 0.0 },
|
||||||
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
||||||
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
||||||
|
@ -51,12 +53,11 @@ return menu.new(
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
lg.newMesh{
|
bg = lg.newMesh{
|
||||||
{ 0, 0, 0, 0, 1, 1, 1, 0.01 },
|
{ 0, 0, 0, 0, 1, 1, 1, 0.01 },
|
||||||
{ 1, 0, 1, 0, 1, 1, 1, 0.1 },
|
{ 1, 0, 1, 0, 1, 1, 1, 0.1 },
|
||||||
{ 1, 1, 1, 1, 0, 0, 0, 0.1 },
|
{ 1, 1, 1, 1, 0, 0, 0, 0.1 },
|
||||||
{ 0, 1, 0, 1, 0, 0, 0, 0.01 },
|
{ 0, 1, 0, 1, 0, 0, 0, 0.01 },
|
||||||
},
|
}
|
||||||
|
|
||||||
lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 18 )
|
}
|
||||||
)
|
|
|
@ -28,8 +28,8 @@ textInput.y = 0
|
||||||
|
|
||||||
function textInput.new( t )
|
function textInput.new( t )
|
||||||
t = t or {}
|
t = t or {}
|
||||||
t.text = lg.newText( font, "")
|
t.str = t.str or ""
|
||||||
t.str = ""
|
t.text = lg.newText( font, t.str )
|
||||||
return setmetatable( t, __mt )
|
return setmetatable( t, __mt )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ function server.Start()
|
||||||
udp:settimeout(0)
|
udp:settimeout(0)
|
||||||
server.SetIP( socket.dns.toip(socket.dns.gethostname()), 51312 )
|
server.SetIP( socket.dns.toip(socket.dns.gethostname()), 51312 )
|
||||||
assert( udp:setsockname( tostring( svInfo.ip ), svInfo.port ))
|
assert( udp:setsockname( tostring( svInfo.ip ), svInfo.port ))
|
||||||
server.StartLocalClient()
|
|
||||||
print( socket.gettime(), "Start." )
|
print( socket.gettime(), "Start." )
|
||||||
repeat
|
repeat
|
||||||
server.Parse( udp:receivefrom() )
|
server.Parse( udp:receivefrom() )
|
||||||
|
|
|
@ -127,6 +127,12 @@ function packet.getString( member )
|
||||||
return ffi.string( member, ffi.sizeof( member ) )
|
return ffi.string( member, ffi.sizeof( member ) )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Slow!
|
||||||
|
function packet.luaString( member )
|
||||||
|
local s = packet.getString( member )
|
||||||
|
return s:sub( 1, ( s:find( "\0" ) or s:len() ) - 1 )
|
||||||
|
end
|
||||||
|
|
||||||
local writeBuffer = buffer.new( 1024 )
|
local writeBuffer = buffer.new( 1024 )
|
||||||
function packet.add( struct, data )
|
function packet.add( struct, data )
|
||||||
local str = ffi.new( struct.ct, data or 0 )
|
local str = ffi.new( struct.ct, data or 0 )
|
||||||
|
|
Loading…
Reference in New Issue