ExperimentalGear/scripts/gameplay/banner.lua

133 lines
3.6 KiB
Lua

local bannerBaseImage = gfx.CreateSkinImage("gameplay/banner/base.png", 0)
local UsBottom = gfx.CreateSkinImage("result/multi_4p/base.png",0)
local UsTop = gfx.CreateSkinImage("result/multi_4p/top.png",0)
local pos = {
gfx.CreateSkinImage("result/multi_4p/pos/1.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/2.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/3.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/4.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/5.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/6.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/7.png", 0),
gfx.CreateSkinImage("result/multi_4p/pos/8.png", 0),
}
local desw = 1080
local desh = 1920
local BANNER_W = 1080;
local BANNER_H = 368;
local drawScoreboard = function (users, currentUserId)
if (users == nil) then
return
end
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(32)
gfx.LoadSkinFont("Digital-Serial-Bold.ttf")
for i, u in ipairs(users) do
if (u.id == currentUserId) then
gfx.FillColor(128,192,255);
else
gfx.FillColor(255,255,255);
end
isLandscape = desw < desh;
local posUPWidth, posUPHeight = gfx.ImageSize(UsBottom)
numberx = posUPWidth;
if not isLandscape then
local posUPWidth, posUPHeight = gfx.ImageSize(UsBottom)
local y = 16;
gfx.BeginPath()
gfx.ImageRect(numberx, y,posUPWidth/1.75,posUPHeight/1.75,UsBottom,1,0)
local posDWWidth, posDWHeight = gfx.ImageSize(UsTop)
gfx.BeginPath()
gfx.ImageRect(numberx, y,posDWWidth/1.75,posDWHeight/1.75,UsTop,1,0)
local posWidth, posHeight = gfx.ImageSize(pos[i])
gfx.BeginPath()
gfx.ImageRect(numberx+110, y+16,posWidth/2,posHeight/2,pos[i],1,0)
gfx.BeginPath()
gfx.FontSize(26)
gfx.Text(u.name, numberx, y)
elseif isLandscape then
local x = 16;
local basey = 510;
local y = basey + i*28;
gfx.FontSize(26)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.Text(string.format("%04d", math.floor(u.score/10000)), x, y)
local lastFourDigits = ((u.score / 10000) - math.floor(u.score / 10000))*10000
gfx.FontSize(22)
gfx.Text(string.format("%04d", math.floor(lastFourDigits)), x+58, y+1)
gfx.FontSize(26)
gfx.Text(u.name, x+155, y)
gfx.BeginPath()
local posWidth, posHeight = gfx.ImageSize(pos[i])
gfx.BeginPath()
gfx.ImageRect(x+100, y-20,posWidth/2.5,posHeight/2.5,pos[i],1,0)
end
numberx = numberx+numberx
end
end
local render = function (deltaTime, users, currentUserId)
local resx, resy = game.GetResolution();
local scale = resx / desw
gfx.Scale(scale, scale)
drawScoreboard(users, currentUserId); -- TODO: for now
-- hide if landscape
if (resx > resy) then
return
end
-- Get the banner downscaled in whatever resolution it is, while maintaining the aspect ratio
local tw,th = gfx.ImageSize(bannerBaseImage);
BANNER_H = th * (1080/tw);
gfx.BeginPath();
gfx.ImageRect(
0,
0,
BANNER_W,
BANNER_H,
bannerBaseImage,
1,
0
);
drawScoreboard(users, currentUserId); -- TODO: for now
gfx.ResetTransform()
end
return {
render=render
}