love-loader/skins/psp.lua

200 lines
4.8 KiB
Lua

return function(ll)
-- New UI from Sony PSP
local sel = 1
local psel
local cx, cy, cw, ch, cg
local css, rcss = 2, 0
local f, bf
ll.cfg.pcht = ll.cfg.pcht or 60 * 10
local pikchv, pikcha = 0, 0
local pikchao = math.floor(1 / ll.cfg.pcht * 2 * 255 + 0.5)
local logger = ''
local chc = '<>><m><'
os.setlocale('', 'time')
function resize()
r = math.min(W, H) / 30
cg = H / 64
cw = W / 5
ch = (H - cg) / 6
cx = W / 10
cy = -H / 2
f = love.graphics.setNewFont(math.min(W, H) / 30)
bf = love.graphics.newFont(math.min(W, H) / 20)
ll.kbInit('v', H / 2 - ch, H / 2 + ch + cg, 0, cx + cw * 2)
end
local sdir
local function update(dt)
local ty = H / 2 - (ch + cg) * sel
cy = cy + (ty - cy) * 5 * dt
css = css + (2 - css) * 15 * dt
rcss = 2 - css + 1
local sdi = ll.kbGet()
if sdi ~= sdir then
if sdi
then rcss = css
css = 1
psel = sel
logger = logger .. sdi
if logger == chc then
resize()
ll.devtools()
end
end
sdir = sdi
if sdi == '<'
then sel = sel - 1
elseif sdi == '>'
then sel = sel + 1
elseif sdi == 'o' and ll.games[sel]
then ll.mount(ll.games[sel])
end
if sel < 1 then sel = #ll.games end
if sel > #ll.games then sel = 1 end
end
pikchv = pikchv + dt
if pikchv >= ll.cfg.pcht / 100 then
pikchv, pikcha = 0, 0
for _, v in pairs(ll.games) do
if v.dat.scr then
v.scrprv = v.scrcur
v.scrcur = v.scrcur + 1
if v.scrcur > #v.dat.scr
then v.scrcur = 1
end
end
end
else pikcha = math.min(255, pikcha + pikchao * 100 * dt)
end
end
local function scrCard(gme, x, y, w, h, a)
if not gme.dat.scr then return end
love.graphics.setColor(255, 255, 255, a / COLDIV)
local p, n = gme.dat.scr[gme.scrprv], gme.dat.scr[gme.scrcur]
love.graphics.draw(p, x, y, 0, w / p:getWidth(), h / p:getHeight())
love.graphics.setColor(255, 255, 255, math.min(a, pikcha) / COLDIV)
love.graphics.draw(n, x, y, 0, w / n:getWidth(), h / n:getHeight())
love.graphics.setColor(0, 0, 0, 150 / COLDIV)
love.graphics.rectangle('fill', x, y, w, h)
end
local function roundRect(m, x, y, w, h, r)
if w < 1 or h < 1 then return end
love.graphics.rectangle(m, x, y, w, h, r)
if m == 'fill'
then roundRect('line', x, y, w, h, r)
end
end
local function draw()
love.graphics.setColor(0 / COLDIV, 50 / COLDIV, 75 / COLDIV)
love.graphics.rectangle('fill', 0, 0, W, H)
if ll.games[sel] then
local cur = ll.games[sel]
scrCard(cur, 0, 0, W, H, (css - 1) * 255)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(bf)
love.graphics.printf(cur.desc, cx + cw * 2, cx, W - (cx + cw * 2))
else love.graphics.setColor(255, 255, 255, 255)
sel = #ll.games
end
love.graphics.setFont(f)
-- battery indicators
love.graphics.setColor(255, 255, 255)
love.graphics.push()
love.graphics.translate(W - r * 1.5, r)
love.graphics.setLineWidth(r / 8)
local pst, pper = love.system.getPowerInfo()
if pst ~= 'nobattery' then
pper = pper or 0
if pst == 'charging'
then pper = os.time() % 5 / 4 * 100
end
roundRect('line', -r * 2.2, 0, r * 2, r * 1.2, r / 4)
roundRect('fill', -r / 6, r * 0.3, r / 4, r / 2, r / 16)
roundRect('fill', -r * 1.95, r * 0.3, r * 1.5 * pper / 100, r * 0.6, r / 16)
love.graphics.translate(-r * 2.8, 0)
end
local time = os.date('%X'):gsub('^(%d+.+%d+).+%d+', '%1')
local w = f:getWidth(time)
love.graphics.print(time, -w, -2)
love.graphics.pop()
local oy = 0
for k, v in pairs(ll.games) do
local x, w, h, g = cx, cw, ch, cg
if k == sel then
x = cx / css
w = cw * css
h = ch * css
g = cg * 3
oy = oy + cg * css
elseif k == psel then
x = cx / rcss
w = cw * rcss
h = ch * rcss
oy = oy + cg * rcss
end
love.graphics.stencil(function()
love.graphics.rectangle('fill', x, cy + oy, w, h, r)
end)
love.graphics.setStencilTest('greater', 0)
love.graphics.setColor(50 / COLDIV, 50 / COLDIV, 50 / COLDIV, 100 / COLDIV)
love.graphics.rectangle('fill', x, cy + oy, w, h)
love.graphics.setColor(255, 255, 255, 255)
scrCard(v, x, cy + oy, w, h, 255)
love.graphics.setColor(255, 255, 255, 255)
local th = f:getHeight(v.name)
love.graphics.print(v.name, x + cg, cy + oy + h - th - cg)
love.graphics.setStencilTest()
love.graphics.rectangle('line', x, cy + oy, w, h, r)
oy = oy + h + g
end
if #ll.games == 0 then
love.graphics.print('No games', cx, cy - ch)
love.graphics.setFont(bf)
love.graphics.print('Add some to the library', cx, cy)
end
end
local function addGame(file, cont, x, y)
local msg, id = ll.addGame(file, cont)
love.graphics.print(msg, x, y)
if id then
sel = id
end
end
return {
update = update,
draw = draw,
addGame = addGame,
}
end