Compare commits

..

No commits in common. "ac349ae0fa266e913d39d92810dac66887c7e9ce" and "8b2a9e4b30c87603d6a6f16081d55f1fe866ba7e" have entirely different histories.

5 changed files with 137 additions and 72 deletions

View File

@ -1,8 +1,6 @@
local layout = {}
layout.uiState = {}
layout.uiState.Menu = {}
layout.uiState.GameUI = {}
layout.uiState.MainMenu = {}
layout.uiStateMenu = {}
local fonts = require("shared.fonts")
local utils = require("shared.utils")
@ -52,15 +50,36 @@ end
function layout.cursorSelect(container, x, y, simulate)
x2, y2 = layout.handle(container[1], x, y, simulate)
assert(container.uiSelect)
if not simulate then
table.insert(layout.uiState[container.uiSelect], { identifier = container.identifier, kind=container.kind,
table.insert(layout.uiState, { identifier = container.identifier, kind=container.kind,
x=x, x2=x2, y=y, y2=y2 })
end
return x2, y2
end
function layout.cursorSelectMenu(container, x, y, simulate)
x2, y2 = layout.handle(container[1], x, y, simulate)
if not simulate then
table.insert(layout.uiStateMenu, { identifier = container.identifier, kind=container.kind,
x=x, x2=x2, y=y, y2=y2 })
end
return x2, y2
end
function layout.linewidth(container, x, y, simulate)
assert(container.width, "layout.linewidth (container) no container.width provided!")
if simulate then return layout.handle(container[1], x, y, simulate) end
local oldWidth = love.graphics.getLineWidth()
love.graphics.setLineWidth(container.width)
x, y = layout.handle(container[1], x, y, simulate)
love.graphics.setLineWidth(oldWidth)
return x, y
end
function layout.spacer(container, x, y, simulate)
assert(container.width or container.height, "No arguments for layout.spacer!")
assert(container.width == container.width,
@ -134,7 +153,7 @@ function layout.bwColorPicker(container, x, y, simulate)
local iterationCount = (1.0 / granularity)
maxx = x + pointSize * iterationCount
table.insert(layout.uiState.GameUI, { granularity = granularity, pointSize = pointSize,
table.insert(layout.uiState, { granularity = granularity, pointSize = pointSize,
kind=container.kind,
x=x, x2=maxx, y=y, y2=y + pointSize })
else
@ -177,7 +196,7 @@ function layout.colorPicker(container, x, y, simulate)
local iterationCount = (1.0 / granularity) + 1
maxx = x + pointSize * iterationCount * iterationCount
table.insert(layout.uiState.GameUI, { granularity = granularity, pointSize = pointSize,
table.insert(layout.uiState, { granularity = granularity, pointSize = pointSize,
kind=container.kind,
x=x, x2=maxx, y=y, y2=myy })
else
@ -222,37 +241,23 @@ function layout.rect(container, x, y, simulate)
end
local buttonColors = {
blue = { {50/255, 65/255, 98/255}, {125/255, 151/255, 208/255}, {1, 1, 1}},
pink = { {208/255, 37/255, 134/255}, {241/255, 109/255, 184/255}, {1, 1, 1}},
green = {{30/255,183/255,127/255},{109/255,241/255,193/255}, {1,1,1}},
blueTranslucent = { {50/255, 65/255, 98/255, .7}, {125/255, 151/255, 208/255, .7}, {1, 1, 1, .9}},
pinkTranslucent = { {208/255, 37/255, 134/255, .7}, {241/255, 109/255, 184/255, .7}, {1, 1, 1, .9}},
greenTranslucent = {{30/255,183/255,127/255, .7},{109/255,241/255,193/255, .7}, {1,1,1, .9}},
grayTranslucent = {{.1,.1,.1, .7}, {1,1,1, .7}, {1,1,1, .9}}
}
function layout.button(container, x, y, simulate)
local textObject = love.graphics.newText(fonts.headerFont, container.text)
local uiSelect = layout.uiState[container.uiSelect] or error("layout.button passed invalid uiSelect!" .. container.uiSelect or "no value!")
assert(container.identifier, "layout.button no identifier passed!")
local buttonColor = buttonColors[container.buttonColor or "blue"]
local textObject = love.graphics.newText(fonts.normalFont, container.text)
local width = textObject:getWidth()
local height = textObject:getHeight()
local factor = 1.15
local points = {
x, y,
x + (width *factor), y,
x + (width * factor), y + (height * factor),
x, y + (height * factor),
x, y
}
if not simulate then
utils.color_push()
love.graphics.setColor(buttonColor[1])
love.graphics.rectangle("fill", x, y, width* factor, height* factor,
height* factor/4, height* factor/4)
love.graphics.setColor(buttonColor[2])
love.graphics.rectangle("line", x, y, width* factor, height* factor,
height* factor/4, height* factor/4)
love.graphics.setColor(buttonColor[3])
love.graphics.rectangle("fill", x, y, width* factor, height* factor)
love.graphics.line(points)
love.graphics.draw(textObject, x + width * 0.075 , y + height * 0.075)
utils.color_pop()
end
table.insert(uiSelect, { identifier = container.identifier, kind="button",
x=x, x2=x+(width *factor), y=y, y2=y + (height * factor) })
return x+ (width *factor), y + (height * factor)
end

View File

@ -46,7 +46,7 @@ end
local firstClient = true
function menu.mousepressed(mousex, mousey)
for i, v in ipairs(layout.uiState.MainMenu) do
for i, v in ipairs(layout.uiState) do
if mousex >= v.x and mousex <= v.x2 then
if mousey >= v.y and mousey <= v.y2 then
if v.kind == "localServer" then
@ -90,7 +90,7 @@ function menu.mousepressed(mousex, mousey)
local avatar = love.image.newImageData("textures/player/noriko/liz.png")
local avatarHash = love.data.hash("sha512", avatar:getString())
levelloop.init({ adress = serverEntry.host, port = serverEntry.port }, fullName, avatarHash)
layout.uiState.MainMenu = {}
layout.uiState = {}
end
end
end
@ -99,7 +99,7 @@ end
menu.serverentry = function(id, description, host, port)
return {name = "cursorSelect", kind = "server", identifier = id, uiSelect = "MainMenu",
return {name = "cursorSelect", kind = "server", identifier = id,
{name = "horizontal",
{name = "drawTexture", texture = love.graphics.newImage("textures/menu/serverPlay.png")},
{name = "spacer", width = 10 },
@ -143,8 +143,7 @@ menu.layout = function(message)
{name = "spacer", width = 50},
{name = "vertical",
{name = "spacer", height = 20},
{name = "cursorSelect", kind = "localServer",
identifier = {"::1", "11150"}, uiSelect = "MainMenu",
{name = "cursorSelect", kind = "localServer", identifier = {"::1", "11150"},
{name = "horizontal",
{name = "spacer", width = 10},
{name = "drawTexture",
@ -154,8 +153,7 @@ menu.layout = function(message)
{name = "label", text = "Spin up a local server"},
}
},
{name = "cursorSelect", kind = "localServer",
identifier = {"0.0.0.0", "11150"}, uiSelect = "MainMenu",
{name = "cursorSelect", kind = "localServer", identifier = {"0.0.0.0", "11150"},
{name = "horizontal",
{name = "spacer", width = 10},
{name = "drawTexture",
@ -197,7 +195,7 @@ end
function drawMenu(message)
utils.color_push()
love.graphics.setCanvas(menu.Canvas)
layout.uiState.MainMenu = {}
uiState = {}
love.graphics.clear( )
layout.handle(menu.layout(message), 0, 0)
love.graphics.setCanvas()

View File

@ -90,7 +90,7 @@ function physics.keypressed( key, code, isrepeat)
if isrepeat then return end
if camera.target == 0 then return end
local player = participants[levelloop.clientID]
local player = participants[clientID]
if key == "p" then
player.flying = not player.flying
if player.flying then

View File

@ -215,7 +215,7 @@ function textureEntry(hash)
}
}
else
return {name = "cursorSelect", uiSelect = "GameUI",
return {name = "cursorSelect",
identifier = hash,
kind = "picker",
{name = "drawHash",
@ -287,39 +287,101 @@ end
function ui.menuDrawer(w, h)
return {name = "horizontal",
{name = "vertical",
{name = "button",
{name = "cursorSelectMenu",
identifier = "save",
uiSelect = "Menu",
buttonColor = "greenTranslucent",
text = "Save world"
kind = "button",
{name = "frame",
{name = "copySize",
{name = "rect",
fill = "fill",
color = { r = .1, g = .1, b = .1, .7 }
},
{name = "inset",
width = 10,
height = 4,
{name = "label",
text = "Save world",
font = fonts.normalFont
}
}
}
}
},
{name = "spacer",
height = 10,
height = 20,
},
{name = "button",
{name = "cursorSelectMenu",
identifier = "disconnect",
uiSelect = "Menu",
buttonColor = "pinkTranslucent",
text = "Disconnect"
kind = "button",
{name = "frame",
{name = "copySize",
{name = "rect",
fill = "fill",
color = { r = .1, g = .1, b = .1, .7 }
},
{name = "inset",
width = 10,
height = 4,
{name = "label",
text = "Disconnect",
font = fonts.normalFont
}
}
}
}
},
{name = "spacer",
height = 25,
height = 20,
},
{name = "button",
{name = "cursorSelectMenu",
identifier = "sideBarScaleTwo",
uiSelect = "Menu",
buttonColor = "grayTranslucent",
text = "Ui scale x2"
kind = "button",
{name = "frame",
{name = "copySize",
{name = "rect",
fill = "fill",
color = { r = .1, g = .1, b = .1, .7 }
},
{name = "inset",
width = 10,
height = 4,
{name = "label",
text = "Ui scale x2",
font = fonts.normalFont
}
}
}
}
},
{name = "spacer",
height = 4,
},
{name = "button",
{name = "cursorSelectMenu",
identifier = "sideBarScaleOne",
uiSelect = "Menu",
buttonColor = "grayTranslucent",
text = "Ui scale x1"
kind = "button",
{name = "frame",
{name = "copySize",
{name = "rect",
fill = "fill",
color = { r = .1, g = .1, b = .1, .7 }
},
{name = "inset",
width = 10,
height = 4,
{name = "label",
text = "Ui scale x1",
font = fonts.normalFont
}
}
}
}
},
{name = "cursorSelectMenu",
identifier = "buttonTest",
kind = "button",
{name = "button",
width = 60,
height = 10,
text = "TestKnopf",
}
}
},
{name = "spacer",
width = 80,
@ -335,7 +397,7 @@ end
function ui.draw(w, h)
window.x, window.y = w, h
love.graphics.setCanvas(ui.buffer)
layout.uiState.GameUI = {}
layout.uiState = {}
love.graphics.clear( )
local blockDrawer = ui.blockDrawer(ui.textureTree, w, h)
blockMaxX, blockMaxY = layout.handle(blockDrawer, 0, 0, true)
@ -348,7 +410,7 @@ end
function ui.drawMenu(w, h)
window.x, window.y = w, h
layout.uiState.Menu = {}
layout.uiStateMenu = {}
love.graphics.setCanvas(ui.buffer)
love.graphics.clear()
local menuDrawer = ui.menuDrawer(w, h)
@ -361,7 +423,7 @@ end
function ui.mousepressed(mousex, mousey)
local textures = levelloop.textures
if menuVisible then
for i, v in ipairs(layout.uiState.Menu) do
for i, v in ipairs(layout.uiStateMenu) do
if mousex >= v.x and mousex <= v.x2 and --hit testing
mousey >= v.y and mousey <= v.y2 then
if v.kind == "button" then
@ -386,7 +448,7 @@ function ui.mousepressed(mousex, mousey)
end
end
else
for i, v in ipairs(layout.uiState.GameUI) do
for i, v in ipairs(layout.uiState) do
if mousex >= v.x and mousex <= v.x2 and
mousey >= v.y and mousey <= v.y2 then
if v.kind == "picker" then

View File

@ -14,7 +14,7 @@ function love.load(args)
local host = args[2]
local port = "11150"
if args[3] then port = args[3] end
local serverloop = require("server.main")
print("Starting server! [" .. host .. "] <" .. port .. ">")
serverloop.init({host, port})
@ -24,7 +24,7 @@ function love.load(args)
love.event.quit()
return
end
dofile "lua/gameloop.lua"
dofile "lua/layout.lua"
dofile "lua/ui.lua"
@ -38,17 +38,17 @@ function love.load(args)
end
end
})
PHYSICS_DEBUG = false
NETWORK_DEBUG = true
local host = args[2]
local port = "11150"
if args[3] then port = args[3] end
local avatar = love.image.newImageData("textures/player/nephele/fallback.png")
local avatarHash = love.data.hash("sha512", avatar:getString())
levelloop.init({ adress = host, port = port }, "Fallback player", avatarHash)
levelloop.init({ adress = host, port = port }, "Fallback player", avatarHash)
elseif args[1] == "--help" then
print(" --server [host] <port>")
print(" Start a local server")