Compare commits

...

2 Commits

Author SHA1 Message Date
Pascal Abresch ac349ae0fa simplify ui code a bit, finish new buttons 2022-12-18 11:33:15 +01:00
Pascal Abresch 87248d5139 fix flying 2022-12-18 11:32:37 +01:00
5 changed files with 72 additions and 137 deletions

View File

@ -1,6 +1,8 @@
local layout = {}
layout.uiState = {}
layout.uiStateMenu = {}
layout.uiState.Menu = {}
layout.uiState.GameUI = {}
layout.uiState.MainMenu = {}
local fonts = require("shared.fonts")
local utils = require("shared.utils")
@ -50,36 +52,15 @@ 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, { identifier = container.identifier, kind=container.kind,
table.insert(layout.uiState[container.uiSelect], { 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,
@ -153,7 +134,7 @@ function layout.bwColorPicker(container, x, y, simulate)
local iterationCount = (1.0 / granularity)
maxx = x + pointSize * iterationCount
table.insert(layout.uiState, { granularity = granularity, pointSize = pointSize,
table.insert(layout.uiState.GameUI, { granularity = granularity, pointSize = pointSize,
kind=container.kind,
x=x, x2=maxx, y=y, y2=y + pointSize })
else
@ -196,7 +177,7 @@ function layout.colorPicker(container, x, y, simulate)
local iterationCount = (1.0 / granularity) + 1
maxx = x + pointSize * iterationCount * iterationCount
table.insert(layout.uiState, { granularity = granularity, pointSize = pointSize,
table.insert(layout.uiState.GameUI, { granularity = granularity, pointSize = pointSize,
kind=container.kind,
x=x, x2=maxx, y=y, y2=myy })
else
@ -241,23 +222,37 @@ 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.normalFont, container.text)
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 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
love.graphics.rectangle("fill", x, y, width* factor, height* factor)
love.graphics.line(points)
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.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) do
for i, v in ipairs(layout.uiState.MainMenu) 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 = {}
layout.uiState.MainMenu = {}
end
end
end
@ -99,7 +99,7 @@ end
menu.serverentry = function(id, description, host, port)
return {name = "cursorSelect", kind = "server", identifier = id,
return {name = "cursorSelect", kind = "server", identifier = id, uiSelect = "MainMenu",
{name = "horizontal",
{name = "drawTexture", texture = love.graphics.newImage("textures/menu/serverPlay.png")},
{name = "spacer", width = 10 },
@ -143,7 +143,8 @@ menu.layout = function(message)
{name = "spacer", width = 50},
{name = "vertical",
{name = "spacer", height = 20},
{name = "cursorSelect", kind = "localServer", identifier = {"::1", "11150"},
{name = "cursorSelect", kind = "localServer",
identifier = {"::1", "11150"}, uiSelect = "MainMenu",
{name = "horizontal",
{name = "spacer", width = 10},
{name = "drawTexture",
@ -153,7 +154,8 @@ menu.layout = function(message)
{name = "label", text = "Spin up a local server"},
}
},
{name = "cursorSelect", kind = "localServer", identifier = {"0.0.0.0", "11150"},
{name = "cursorSelect", kind = "localServer",
identifier = {"0.0.0.0", "11150"}, uiSelect = "MainMenu",
{name = "horizontal",
{name = "spacer", width = 10},
{name = "drawTexture",
@ -195,7 +197,7 @@ end
function drawMenu(message)
utils.color_push()
love.graphics.setCanvas(menu.Canvas)
uiState = {}
layout.uiState.MainMenu = {}
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[clientID]
local player = participants[levelloop.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",
return {name = "cursorSelect", uiSelect = "GameUI",
identifier = hash,
kind = "picker",
{name = "drawHash",
@ -287,101 +287,39 @@ end
function ui.menuDrawer(w, h)
return {name = "horizontal",
{name = "vertical",
{name = "cursorSelectMenu",
{name = "button",
identifier = "save",
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
}
}
}
}
uiSelect = "Menu",
buttonColor = "greenTranslucent",
text = "Save world"
},
{name = "spacer",
height = 20,
height = 10,
},
{name = "cursorSelectMenu",
{name = "button",
identifier = "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
}
}
}
}
uiSelect = "Menu",
buttonColor = "pinkTranslucent",
text = "Disconnect"
},
{name = "spacer",
height = 20,
height = 25,
},
{name = "cursorSelectMenu",
{name = "button",
identifier = "sideBarScaleTwo",
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
}
}
}
}
uiSelect = "Menu",
buttonColor = "grayTranslucent",
text = "Ui scale x2"
},
{name = "cursorSelectMenu",
{name = "spacer",
height = 4,
},
{name = "button",
identifier = "sideBarScaleOne",
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
}
}
}
}
uiSelect = "Menu",
buttonColor = "grayTranslucent",
text = "Ui scale x1"
},
{name = "cursorSelectMenu",
identifier = "buttonTest",
kind = "button",
{name = "button",
width = 60,
height = 10,
text = "TestKnopf",
}
}
},
{name = "spacer",
width = 80,
@ -397,7 +335,7 @@ end
function ui.draw(w, h)
window.x, window.y = w, h
love.graphics.setCanvas(ui.buffer)
layout.uiState = {}
layout.uiState.GameUI = {}
love.graphics.clear( )
local blockDrawer = ui.blockDrawer(ui.textureTree, w, h)
blockMaxX, blockMaxY = layout.handle(blockDrawer, 0, 0, true)
@ -410,7 +348,7 @@ end
function ui.drawMenu(w, h)
window.x, window.y = w, h
layout.uiStateMenu = {}
layout.uiState.Menu = {}
love.graphics.setCanvas(ui.buffer)
love.graphics.clear()
local menuDrawer = ui.menuDrawer(w, h)
@ -423,7 +361,7 @@ end
function ui.mousepressed(mousex, mousey)
local textures = levelloop.textures
if menuVisible then
for i, v in ipairs(layout.uiStateMenu) do
for i, v in ipairs(layout.uiState.Menu) 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
@ -448,7 +386,7 @@ function ui.mousepressed(mousex, mousey)
end
end
else
for i, v in ipairs(layout.uiState) do
for i, v in ipairs(layout.uiState.GameUI) 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")