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
|
||||
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
|
||||
end
|
||||
color_pop()
|
||||
|
@ -128,6 +128,7 @@ function layout.bwColorPicker(container, x, y, simulate)
|
|||
local iterationCount = (1.0 / granularity)
|
||||
maxx = x + pointSize * iterationCount
|
||||
maxy = y + pointSize
|
||||
return maxx, maxy
|
||||
end
|
||||
return maxx, y + pointSize
|
||||
end
|
||||
|
@ -151,7 +152,7 @@ function layout.colorPicker(container, x, y, simulate)
|
|||
for b=0, 1.0, granularity do
|
||||
love.graphics.setColor(r, g, b, 1)
|
||||
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
|
||||
myy = myy + pointSize
|
||||
|
@ -169,6 +170,7 @@ function layout.colorPicker(container, x, y, simulate)
|
|||
local iterationCount = (1.0 / granularity) + 1
|
||||
maxx = x + pointSize * iterationCount * iterationCount
|
||||
maxy = y + pointSize * iterationCount
|
||||
return maxx, maxy
|
||||
end
|
||||
return maxx, myy
|
||||
end
|
||||
|
@ -248,7 +250,40 @@ function layout.horizontal(container, x, y, simulate)
|
|||
if ret.y > bigy then bigy = ret.y end
|
||||
x = ret.x
|
||||
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
|
||||
|
||||
|
||||
|
@ -263,7 +298,7 @@ function layout.copySize(container, x, y, simulate)
|
|||
return bigx, bigy
|
||||
end
|
||||
|
||||
|
||||
|
||||
function layout.vertical(container, x, y, simulate)
|
||||
local bigx = x
|
||||
if not simulate then
|
||||
|
|
71
lua/ui.lua
|
@ -9,8 +9,9 @@ else
|
|||
ui.font = love.graphics.newFont(20)
|
||||
ui.bigFont = love.graphics.newFont(45)
|
||||
end
|
||||
ui.scale = 1
|
||||
|
||||
ui.sidebarScale = 1
|
||||
ui.sidebarWidth = 13 * 16
|
||||
function ui.update_scale(p_scale)
|
||||
scale = p_scale
|
||||
end
|
||||
|
@ -153,11 +154,11 @@ function ui.loadTextures(directory, container)
|
|||
for i, file in pairs(entries) do
|
||||
local path = directory .."/".. file
|
||||
local entry = love.filesystem.getInfo(path)
|
||||
if entry.type == "directory" then
|
||||
if entry.type == "directory" and file ~= ".git" then
|
||||
container[file] = {}
|
||||
container[file] = ui.loadTextures(path, container[file])
|
||||
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 hash = love.data.hash("sha512", imageData:getString())
|
||||
gameloop.textures[hash] = {data = imageData}
|
||||
|
@ -179,17 +180,13 @@ function textureEntry(hash)
|
|||
texture.image = love.graphics.newImage(texture.data)
|
||||
end
|
||||
local width = texture.image:getWidth()
|
||||
local scale = 1
|
||||
if ui.scale == 2 then
|
||||
if width <= 16 then scale = 2 end
|
||||
if width <= 8 then scale = 4 end
|
||||
end
|
||||
local height = texture.image:getHeight()
|
||||
if drawing and drawing.cursorHash and hash == drawing.cursorHash then
|
||||
return{name = "overlayRect",
|
||||
fill = "line",
|
||||
{name = "drawHash",
|
||||
hash = hash,
|
||||
scale = scale
|
||||
scale = ui.sidebarScale
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -198,7 +195,7 @@ function textureEntry(hash)
|
|||
kind = "picker",
|
||||
{name = "drawHash",
|
||||
hash = hash,
|
||||
scale = scale
|
||||
scale = ui.sidebarScale
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -207,52 +204,45 @@ end
|
|||
|
||||
function textureRun(entryTable, width)
|
||||
local textures = gameloop.textures
|
||||
local superEntry = {name = "vertical"}
|
||||
local entries = {name = "horizontal"}
|
||||
local entries = {name = "naiveGrid", width = width - 20}
|
||||
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
|
||||
table.insert(entryTableSorted, {name = iter, entry = entry})
|
||||
end
|
||||
table.sort(entryTableSorted, function(k1, k2) return k1.name < k2.name end)
|
||||
|
||||
for iter, entry in pairs(entryTableSorted) do
|
||||
if #entries > 2 then
|
||||
local NextX, nextY = layout.handle(entries, 0, 0, true)
|
||||
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))
|
||||
if not textures[entry.entry].image then
|
||||
textures[entry.entry].image = love.graphics.newImage(textures[entry.entry].data)
|
||||
end
|
||||
table.insert(entries, textureEntry(entry.entry))
|
||||
end
|
||||
if #entries > 1 then table.insert(superEntry, entries) end
|
||||
if #superEntry > 1 then
|
||||
return superEntry
|
||||
else
|
||||
return entries
|
||||
end
|
||||
return entries
|
||||
end
|
||||
|
||||
|
||||
function ui.blockDrawer(textureTree, w, h, container)
|
||||
if not textureTree then return {name = "label", text = "Loading textures..."} end
|
||||
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",
|
||||
{name = "colorPicker", kind = "colorpicker",
|
||||
granularity = 0.25, pointSize = pointSize},
|
||||
{name = "spacer", height = 5 * ui.scale},
|
||||
{name = "spacer", height = 5 * ui.sidebarScale},
|
||||
{name = "bwColorPicker", kind = "bwColorPicker",
|
||||
pointSize = pointSize}}
|
||||
end
|
||||
local textureTreeSorted = {}
|
||||
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"
|
||||
table.insert(container, {name = "label", text = pack})
|
||||
table.insert(container,
|
||||
|
@ -377,7 +367,7 @@ function ui.draw(w, h)
|
|||
love.graphics.setCanvas(ui.buffer)
|
||||
uiState = {}
|
||||
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)
|
||||
ui.space = width
|
||||
if textEnabled then
|
||||
|
@ -420,18 +410,23 @@ function ui.mousepressed(mousex, mousey)
|
|||
local saturation = math.floor((mousex - v.x) / v.pointSize) / scale
|
||||
drawing.color = {saturation, saturation, saturation, 1}
|
||||
ui.draw(window.x, window.y)
|
||||
return
|
||||
elseif v.kind == "button" then
|
||||
if v.identifier == "disconnect" then
|
||||
gameloop.networkSend(unit("playerLeave"))
|
||||
menu.init()
|
||||
return
|
||||
elseif v.identifier == "increaseUISize" then
|
||||
ui.scale = 2
|
||||
ui.sidebarScale = 2
|
||||
ui.draw(window.x, window.y)
|
||||
return
|
||||
elseif v.identifier == "decreaseUISize" then
|
||||
ui.scale = 1
|
||||
ui.sidebarScale = 1
|
||||
ui.draw(window.x, window.y)
|
||||
return
|
||||
end
|
||||
end
|
||||
return
|
||||
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/
|
||||
Author: andysphinx
|
||||
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 |