ExperimentalGear/scripts/gameplay/banner.lua

72 lines
1.6 KiB
Lua
Raw Normal View History

local bannerBaseImage = gfx.CreateSkinImage("gameplay/banner/base.png", 0)
local BANNER_W = 1080;
local BANNER_H = 368;
2021-11-27 21:49:32 +01:00
local drawScoreboard = function (users, currentUserId)
if (users == nil) then
return
end
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(32)
local x = 16;
2021-11-27 21:49:32 +01:00
local basey = 510;
gfx.LoadSkinFont("Digital-Serial-Bold.ttf")
for i, u in ipairs(users) do
2021-11-27 21:49:32 +01:00
local y = basey + i*28;
if (u.id == currentUserId) then
gfx.FillColor(128,192,255);
else
gfx.FillColor(255,255,255);
end
gfx.FontSize(26)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
2021-11-27 22:30:44 +01:00
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)
2021-11-27 22:30:44 +01:00
gfx.Text(string.format("%04d", math.floor(lastFourDigits)), x+58, y+1)
gfx.FontSize(26)
gfx.Text('#' .. i .. ' ' .. u.name, x+120, y)
end
end
2021-11-27 21:49:32 +01:00
local render = function (deltaTime, users, currentUserId)
2021-11-25 18:49:50 +01:00
local resx, resy = game.GetResolution();
2021-11-27 22:30:44 +01:00
drawScoreboard(users, currentUserId); -- TODO: for now
-- hide if landscape
2021-11-25 18:49:50 +01:00
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
);
end
return {
render=render
}