Compare commits
4 Commits
e3e516fee4
...
fb0c3357dc
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | fb0c3357dc | |
Pascal Abresch | 4835007941 | |
Pascal Abresch | 926448965c | |
Pascal Abresch | 522e6f6026 |
|
@ -114,7 +114,7 @@ function layout.bwColorPicker(container, x, y, simulate)
|
||||||
|
|
||||||
for c=0, 1.0, granularity do
|
for c=0, 1.0, granularity do
|
||||||
love.graphics.setColor(c, c, c, 1)
|
love.graphics.setColor(c, c, c, 1)
|
||||||
love.graphics.points(myx+(pointSize/2), y +(pointSize/2) +.5)
|
love.graphics.points(myx+(pointSize/2), y +(pointSize/2))
|
||||||
myx = myx + pointSize
|
myx = myx + pointSize
|
||||||
end
|
end
|
||||||
color_pop()
|
color_pop()
|
||||||
|
@ -128,6 +128,7 @@ function layout.bwColorPicker(container, x, y, simulate)
|
||||||
local iterationCount = (1.0 / granularity)
|
local iterationCount = (1.0 / granularity)
|
||||||
maxx = x + pointSize * iterationCount
|
maxx = x + pointSize * iterationCount
|
||||||
maxy = y + pointSize
|
maxy = y + pointSize
|
||||||
|
return maxx, maxy
|
||||||
end
|
end
|
||||||
return maxx, y + pointSize
|
return maxx, y + pointSize
|
||||||
end
|
end
|
||||||
|
@ -151,7 +152,7 @@ function layout.colorPicker(container, x, y, simulate)
|
||||||
for b=0, 1.0, granularity do
|
for b=0, 1.0, granularity do
|
||||||
love.graphics.setColor(r, g, b, 1)
|
love.graphics.setColor(r, g, b, 1)
|
||||||
myx=myx+pointSize
|
myx=myx+pointSize
|
||||||
love.graphics.points(myx-(pointSize/2) -.5, myy +(pointSize/2) +.5)
|
love.graphics.points(myx-(pointSize/2) -.5, myy +(pointSize/2))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
myy = myy + pointSize
|
myy = myy + pointSize
|
||||||
|
@ -169,6 +170,7 @@ function layout.colorPicker(container, x, y, simulate)
|
||||||
local iterationCount = (1.0 / granularity) + 1
|
local iterationCount = (1.0 / granularity) + 1
|
||||||
maxx = x + pointSize * iterationCount * iterationCount
|
maxx = x + pointSize * iterationCount * iterationCount
|
||||||
maxy = y + pointSize * iterationCount
|
maxy = y + pointSize * iterationCount
|
||||||
|
return maxx, maxy
|
||||||
end
|
end
|
||||||
return maxx, myy
|
return maxx, myy
|
||||||
end
|
end
|
||||||
|
@ -248,7 +250,40 @@ function layout.horizontal(container, x, y, simulate)
|
||||||
if ret.y > bigy then bigy = ret.y end
|
if ret.y > bigy then bigy = ret.y end
|
||||||
x = ret.x
|
x = ret.x
|
||||||
end
|
end
|
||||||
return x,bigy
|
return x, bigy
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function layout.naiveGrid(container, startX, startY, simulate)
|
||||||
|
-- This is naiveGrid and not grid because the splitting alghorythm splits
|
||||||
|
-- *after* the threshold is reached, thus individual lines can be quite a bit longer
|
||||||
|
-- depending on the passed content.
|
||||||
|
-- todo: rewrite this with a (possibly) more expensive grid function that
|
||||||
|
-- simulates everything before doing it
|
||||||
|
local maxX, maxY = startX, startY
|
||||||
|
local workX, workY = startX, startY -- The current "pointer" for where to draw
|
||||||
|
local retX, retY = startX, startY -- the values returned by the newly drawn shape
|
||||||
|
local width = container.width
|
||||||
|
if not simulate then
|
||||||
|
assert(container[1], "naiveGrid called without arguments!")
|
||||||
|
else
|
||||||
|
if not container[1] then return startX, startY end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i, v in ipairs(container) do
|
||||||
|
retX, retY = layout.handle(v, workX, workY, simulate)
|
||||||
|
if retY > maxY then maxY = retY end
|
||||||
|
|
||||||
|
if retX > startX + width then
|
||||||
|
workY = maxY
|
||||||
|
workX = startX
|
||||||
|
if retX > maxX then maxX = retX end
|
||||||
|
else
|
||||||
|
workX = retX
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return maxX, maxY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,7 +298,7 @@ function layout.copySize(container, x, y, simulate)
|
||||||
return bigx, bigy
|
return bigx, bigy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function layout.vertical(container, x, y, simulate)
|
function layout.vertical(container, x, y, simulate)
|
||||||
local bigx = x
|
local bigx = x
|
||||||
if not simulate then
|
if not simulate then
|
||||||
|
|
71
lua/ui.lua
|
@ -9,8 +9,9 @@ else
|
||||||
ui.font = love.graphics.newFont(20)
|
ui.font = love.graphics.newFont(20)
|
||||||
ui.bigFont = love.graphics.newFont(45)
|
ui.bigFont = love.graphics.newFont(45)
|
||||||
end
|
end
|
||||||
ui.scale = 1
|
|
||||||
|
|
||||||
|
ui.sidebarScale = 1
|
||||||
|
ui.sidebarWidth = 13 * 16
|
||||||
function ui.update_scale(p_scale)
|
function ui.update_scale(p_scale)
|
||||||
scale = p_scale
|
scale = p_scale
|
||||||
end
|
end
|
||||||
|
@ -153,11 +154,11 @@ function ui.loadTextures(directory, container)
|
||||||
for i, file in pairs(entries) do
|
for i, file in pairs(entries) do
|
||||||
local path = directory .."/".. file
|
local path = directory .."/".. file
|
||||||
local entry = love.filesystem.getInfo(path)
|
local entry = love.filesystem.getInfo(path)
|
||||||
if entry.type == "directory" then
|
if entry.type == "directory" and file ~= ".git" then
|
||||||
container[file] = {}
|
container[file] = {}
|
||||||
container[file] = ui.loadTextures(path, container[file])
|
container[file] = ui.loadTextures(path, container[file])
|
||||||
elseif entry.type == "file" or entry.type == "symlink" then
|
elseif entry.type == "file" or entry.type == "symlink" then
|
||||||
if file ~= "license.txt" then
|
if file ~= "license.txt" and file ~= "Readme.md" then
|
||||||
local imageData = love.image.newImageData(path)
|
local imageData = love.image.newImageData(path)
|
||||||
local hash = love.data.hash("sha512", imageData:getString())
|
local hash = love.data.hash("sha512", imageData:getString())
|
||||||
gameloop.textures[hash] = {data = imageData}
|
gameloop.textures[hash] = {data = imageData}
|
||||||
|
@ -179,17 +180,13 @@ function textureEntry(hash)
|
||||||
texture.image = love.graphics.newImage(texture.data)
|
texture.image = love.graphics.newImage(texture.data)
|
||||||
end
|
end
|
||||||
local width = texture.image:getWidth()
|
local width = texture.image:getWidth()
|
||||||
local scale = 1
|
local height = texture.image:getHeight()
|
||||||
if ui.scale == 2 then
|
|
||||||
if width <= 16 then scale = 2 end
|
|
||||||
if width <= 8 then scale = 4 end
|
|
||||||
end
|
|
||||||
if drawing and drawing.cursorHash and hash == drawing.cursorHash then
|
if drawing and drawing.cursorHash and hash == drawing.cursorHash then
|
||||||
return{name = "overlayRect",
|
return{name = "overlayRect",
|
||||||
fill = "line",
|
fill = "line",
|
||||||
{name = "drawHash",
|
{name = "drawHash",
|
||||||
hash = hash,
|
hash = hash,
|
||||||
scale = scale
|
scale = ui.sidebarScale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -198,7 +195,7 @@ function textureEntry(hash)
|
||||||
kind = "picker",
|
kind = "picker",
|
||||||
{name = "drawHash",
|
{name = "drawHash",
|
||||||
hash = hash,
|
hash = hash,
|
||||||
scale = scale
|
scale = ui.sidebarScale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -207,52 +204,45 @@ end
|
||||||
|
|
||||||
function textureRun(entryTable, width)
|
function textureRun(entryTable, width)
|
||||||
local textures = gameloop.textures
|
local textures = gameloop.textures
|
||||||
local superEntry = {name = "vertical"}
|
local entries = {name = "naiveGrid", width = width - 20}
|
||||||
local entries = {name = "horizontal"}
|
|
||||||
local entryTableSorted = {}
|
local entryTableSorted = {}
|
||||||
|
|
||||||
|
-- Sort the entries alphapetically (or well, probably more... "byte compared") :)
|
||||||
|
-- This implies that in <author>/<packname>/<fileName> the fileName controls where
|
||||||
|
-- the texture lands in the block drawer, smaller lands further left.
|
||||||
for iter, entry in pairs(entryTable) do
|
for iter, entry in pairs(entryTable) do
|
||||||
table.insert(entryTableSorted, {name = iter, entry = entry})
|
table.insert(entryTableSorted, {name = iter, entry = entry})
|
||||||
end
|
end
|
||||||
table.sort(entryTableSorted, function(k1, k2) return k1.name < k2.name end)
|
table.sort(entryTableSorted, function(k1, k2) return k1.name < k2.name end)
|
||||||
|
|
||||||
for iter, entry in pairs(entryTableSorted) do
|
for iter, entry in pairs(entryTableSorted) do
|
||||||
if #entries > 2 then
|
if not textures[entry.entry].image then
|
||||||
local NextX, nextY = layout.handle(entries, 0, 0, true)
|
textures[entry.entry].image = love.graphics.newImage(textures[entry.entry].data)
|
||||||
if not textures[entry.entry] then textures[entry.entry] = {} end
|
|
||||||
if not textures[entry.entry].image then
|
|
||||||
textures[entry.entry].image = love.graphics.newImage(textures[entry.entry].data)
|
|
||||||
end
|
|
||||||
if textures[entry.entry].image:getWidth() + NextX < width then
|
|
||||||
table.insert(entries, textureEntry(entry.entry))
|
|
||||||
else
|
|
||||||
table.insert(superEntry, entries)
|
|
||||||
entries = {name = "horizontal"}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
table.insert(entries, textureEntry(entry.entry))
|
|
||||||
end
|
end
|
||||||
|
table.insert(entries, textureEntry(entry.entry))
|
||||||
end
|
end
|
||||||
if #entries > 1 then table.insert(superEntry, entries) end
|
return entries
|
||||||
if #superEntry > 1 then
|
|
||||||
return superEntry
|
|
||||||
else
|
|
||||||
return entries
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function ui.blockDrawer(textureTree, w, h, container)
|
function ui.blockDrawer(textureTree, w, h, container)
|
||||||
if not textureTree then return {name = "label", text = "Loading textures..."} end
|
if not textureTree then return {name = "label", text = "Loading textures..."} end
|
||||||
local pointSize = 8
|
local pointSize = 8
|
||||||
if ui.scale == 2 then pointSize = 16 end
|
if ui.sidebarScale == 2 then pointSize = 16 end
|
||||||
if not container then container = {name="vertical",
|
if not container then container = {name="vertical",
|
||||||
{name = "colorPicker", kind = "colorpicker",
|
{name = "colorPicker", kind = "colorpicker",
|
||||||
granularity = 0.25, pointSize = pointSize},
|
granularity = 0.25, pointSize = pointSize},
|
||||||
{name = "spacer", height = 5 * ui.scale},
|
{name = "spacer", height = 5 * ui.sidebarScale},
|
||||||
{name = "bwColorPicker", kind = "bwColorPicker",
|
{name = "bwColorPicker", kind = "bwColorPicker",
|
||||||
pointSize = pointSize}}
|
pointSize = pointSize}}
|
||||||
end
|
end
|
||||||
|
local textureTreeSorted = {}
|
||||||
for author, tree in pairs(textureTree) do
|
for author, tree in pairs(textureTree) do
|
||||||
for pack, subTree in pairs(tree) do
|
table.insert(textureTreeSorted, {author = author, tree = tree})
|
||||||
|
end
|
||||||
|
table.sort(textureTreeSorted, function(k1, k2) return k1.author < k2.author end)
|
||||||
|
for author, tree in pairs(textureTreeSorted) do
|
||||||
|
for pack, subTree in pairs(tree.tree) do
|
||||||
container.name = "vertical"
|
container.name = "vertical"
|
||||||
table.insert(container, {name = "label", text = pack})
|
table.insert(container, {name = "label", text = pack})
|
||||||
table.insert(container,
|
table.insert(container,
|
||||||
|
@ -377,7 +367,7 @@ function ui.draw(w, h)
|
||||||
love.graphics.setCanvas(ui.buffer)
|
love.graphics.setCanvas(ui.buffer)
|
||||||
uiState = {}
|
uiState = {}
|
||||||
love.graphics.clear( )
|
love.graphics.clear( )
|
||||||
local sidebar, width = ui.tabDrawer(ui.textureTree, w, h)
|
local sidebar, width = ui.tabDrawer(ui.textureTree, ui.sidebarWidth * ui.sidebarScale, h)
|
||||||
layout.handle(sidebar, window.x -width, 0)
|
layout.handle(sidebar, window.x -width, 0)
|
||||||
ui.space = width
|
ui.space = width
|
||||||
if textEnabled then
|
if textEnabled then
|
||||||
|
@ -420,18 +410,23 @@ function ui.mousepressed(mousex, mousey)
|
||||||
local saturation = math.floor((mousex - v.x) / v.pointSize) / scale
|
local saturation = math.floor((mousex - v.x) / v.pointSize) / scale
|
||||||
drawing.color = {saturation, saturation, saturation, 1}
|
drawing.color = {saturation, saturation, saturation, 1}
|
||||||
ui.draw(window.x, window.y)
|
ui.draw(window.x, window.y)
|
||||||
|
return
|
||||||
elseif v.kind == "button" then
|
elseif v.kind == "button" then
|
||||||
if v.identifier == "disconnect" then
|
if v.identifier == "disconnect" then
|
||||||
gameloop.networkSend(unit("playerLeave"))
|
gameloop.networkSend(unit("playerLeave"))
|
||||||
menu.init()
|
menu.init()
|
||||||
|
return
|
||||||
elseif v.identifier == "increaseUISize" then
|
elseif v.identifier == "increaseUISize" then
|
||||||
ui.scale = 2
|
ui.sidebarScale = 2
|
||||||
ui.draw(window.x, window.y)
|
ui.draw(window.x, window.y)
|
||||||
|
return
|
||||||
elseif v.identifier == "decreaseUISize" then
|
elseif v.identifier == "decreaseUISize" then
|
||||||
ui.scale = 1
|
ui.sidebarScale = 1
|
||||||
ui.draw(window.x, window.y)
|
ui.draw(window.x, window.y)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Before Width: | Height: | Size: 129 B After Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 258 B After Width: | Height: | Size: 258 B |
Before Width: | Height: | Size: 413 B After Width: | Height: | Size: 413 B |
Before Width: | Height: | Size: 714 B After Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 722 B After Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 731 B After Width: | Height: | Size: 731 B |
Before Width: | Height: | Size: 714 B After Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 602 B |
|
@ -1,3 +1,7 @@
|
||||||
andysphinx/
|
andysphinx/
|
||||||
Author: andysphinx
|
Author: andysphinx
|
||||||
License: CC0
|
License: CC0
|
||||||
|
|
||||||
|
nephele/
|
||||||
|
Author: nephele
|
||||||
|
License : CC0
|
||||||
|
|
After Width: | Height: | Size: 404 B |
Before Width: | Height: | Size: 271 B After Width: | Height: | Size: 271 B |
Before Width: | Height: | Size: 688 B After Width: | Height: | Size: 688 B |