This commit is contained in:
Not 2022-03-28 13:04:34 +02:00
parent f0703eaafd
commit 9cfb1689b3
1 changed files with 50 additions and 8 deletions

View File

@ -6,6 +6,9 @@ local timeFinished = 0
local disable = true
local prevLap = 0
local splits = {}
local PATCH = {
["FACERANK"]={}
}
-- Read the leaderboard
local f = io.open(FILENAME, "r")
@ -90,14 +93,31 @@ local function ticsToTime(tics)
)
end
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0, 0}
local bodium = {V_YELLOWMAP, V_GRAYMAP, V_BROWNMAP, 0}
local splitColor = {[true]=V_SKYMAP, [false]=V_REDMAP}
local splitSymbol = {[true]="-", [false]="+"}
local showSplit = 0
local function drawScoreboard(v)
local function drawScoreboard(v, player)
if disable then return end
if player != displayplayers[0] then return end
-- PATCH CACHE
if not PATCH["CHILI"] then
PATCH["CHILI"] = {}
for i = 1, 8 do
PATCH["CHILI"][i-1] = v.cachePatch("K_CHILI" + i)
end
end
for skin in skins.iterate do
if PATCH["FACERANK"][skin.name] then
continue
end
PATCH["FACERANK"][skin.name] = v.cachePatch(skin.facerank)
end
local m = lb[tostring(gamemap)]
if m == nil then
return
@ -105,23 +125,45 @@ local function drawScoreboard(v)
for i = 1, #m do
local score = m[i]
local name = score[1]
local skin = skins[score[2]]
if skin == nil then
skin = skins["sonic"]
end
local skinPatch = PATCH["FACERANK"][skin.name]
local patch = v.cachePatch(skin.facerank)
-- | OFFSET | + | PADDING | * |INDEX|
local h = ((200 / 4) + 4) + (patch.height + 4) * (i - 1)
v.draw(4, h, patch, V_HUDTRANS | bodium[i], v.getColormap("sonic", score[3]))
v.drawString(8 + patch.width, h, score[1], V_HUDTRANSHALF | V_ALLOWLOWERCASE)
local h = ((200 / 4) + 4) + (skinPatch.height + 4) * (i - 1)
v.draw(4, h, skinPatch, V_HUDTRANS, v.getColormap("sonic", score[3]))
if player.name == name then
v.draw(4, h, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS)
end
-- Shorten long names
local stralign = "left"
local MAXWIDTH = 70
local px = 6
local py = 0
if v.stringWidth(name) > MAXWIDTH then
stralign = "thin"
py = -1
if v.stringWidth(name, 0, "thin") > MAXWIDTH then
stralign = "small"
py = 2
if v.stringWidth(name, 0, "small") > MAXWIDTH then
name = name:sub(0, 15) + "..."
end
end
end
v.drawString(px + skinPatch.width, h + py, name, V_HUDTRANSHALF | V_ALLOWLOWERCASE, stralign)
-- Draw splits
if showSplit > 0 and score[5][prevLap] != nil then
local split = splits[prevLap] - score[5][prevLap]
v.drawString(8 + patch.width, h + 8, splitSymbol[split < 0] + ticsToTime(abs(split)), V_HUDTRANSHALF | splitColor[split < 0])
v.drawString(px + skinPatch.width, h + 8, splitSymbol[split < 0] + ticsToTime(abs(split)), V_HUDTRANSHALF | splitColor[split < 0])
else
v.drawString(8 + patch.width, h + 8, ticsToTime(score[4]), V_HUDTRANSHALF | bodium[i])
v.drawString(px + skinPatch.width, h + 8, ticsToTime(score[4]), V_HUDTRANSHALF | bodium[min(i, 4)])
end
end
end