add scrolling to browser
This commit is contained in:
parent
45effdd048
commit
fd1827b214
85
browser.lua
85
browser.lua
@ -1,5 +1,6 @@
|
||||
local maps
|
||||
local mapIndex = 1
|
||||
local scrollPos = 1
|
||||
local modes = nil
|
||||
local mode = 1
|
||||
|
||||
@ -13,6 +14,7 @@ local function updateMapIndex(n)
|
||||
-- TODO: keep mode while scrolling through levels
|
||||
mode = 1
|
||||
modes = nil
|
||||
scrollPos = 1
|
||||
end
|
||||
|
||||
local function getMap(offset)
|
||||
@ -182,19 +184,20 @@ end
|
||||
|
||||
local function drawFlags(v, x, y, flags)
|
||||
local nx = x * FRACUNIT
|
||||
local ny = y * FRACUNIT + 3 * FRACUNIT
|
||||
local ny = y * FRACUNIT + 2 * FRACUNIT
|
||||
local margin = 4 * FRACUNIT
|
||||
if flags & F_ENCORE then
|
||||
local encp = v.cachePatch("RUBYICON")
|
||||
v.drawScaled(
|
||||
nx, ny,
|
||||
FRACUNIT / 6,
|
||||
nx,
|
||||
ny + 2 * FRACUNIT,
|
||||
FRACUNIT / 5,
|
||||
encp
|
||||
)
|
||||
nx = $ + margin
|
||||
end
|
||||
if flags & F_SPBATK then
|
||||
local scale = FRACUNIT / 4
|
||||
local scale = FRACUNIT / 3
|
||||
local shift = 6 * FRACUNIT
|
||||
nx = $ - shift
|
||||
ny = $ - shift
|
||||
@ -205,12 +208,13 @@ local function drawFlags(v, x, y, flags)
|
||||
end
|
||||
if flags & F_SPBBIG then
|
||||
local growp = v.cachePatch("K_ISGROW")
|
||||
v.drawScaled(nx, ny, scale, growp)
|
||||
v.drawScaled(nx - FRACUNIT / 2, ny, scale, growp)
|
||||
nx = $ + margin
|
||||
end
|
||||
if flags & F_SPBEXP then
|
||||
local invp = v.cachePatch("K_ISINV"..(leveltime / 6 % 6 + 1))
|
||||
v.drawScaled(nx, ny, scale, invp)
|
||||
nx = $ + margin
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -232,26 +236,46 @@ end
|
||||
-- ______________________________________________
|
||||
-- | 3|[O]|InsertNameHere | 01:02:03 | EXB |
|
||||
-- ----------------------------------------------
|
||||
-- defined are widths of each column, x value is calculated below
|
||||
local column = {
|
||||
[0] = 18, -- pos, drawNum is right aligned
|
||||
[1] = 18, -- facerank
|
||||
[2] = 46, -- name
|
||||
[3] = 216, -- time
|
||||
[4] = 270 -- flags
|
||||
[1] = 18, -- facerank, pos, drawNum is right aligned
|
||||
[2] = 170, -- name
|
||||
[3] = 60, -- time
|
||||
[4] = 0 -- flags
|
||||
}
|
||||
local function drawScore(v, i, score)
|
||||
do
|
||||
local w = 32 -- starting offset
|
||||
local t
|
||||
for i = 1, #column do
|
||||
t = column[i]
|
||||
column[i] = w
|
||||
w = $ + t
|
||||
end
|
||||
end
|
||||
|
||||
local colorFlags = {
|
||||
[0] = V_SKYMAP,
|
||||
[1] = 0
|
||||
}
|
||||
local function drawScore(v, i, pos, score)
|
||||
local y = scoresY + i * 18
|
||||
local textFlag = colorFlags[pos%2]
|
||||
|
||||
-- position
|
||||
v.drawNum(column[0], y, i)
|
||||
v.drawNum(column[1], y, pos)
|
||||
|
||||
-- facerank
|
||||
local skin = skins[score["skin"]]
|
||||
local facerank = skin and v.cachePatch(skin.facerank) or v.cachePatch("M_NORANK")
|
||||
|
||||
v.draw(column[1], y, facerank, 0, v.getColormap("sonic", score["color"]))
|
||||
|
||||
-- stats
|
||||
drawStats(v, column[1], y, score["skin"], score["stat"])
|
||||
v.drawString(column[2], y, score["name"], V_ALLOWLOWERCASE)
|
||||
v.drawString(column[3], y, rawget(_G, "TicsToTime")(score["time"]))
|
||||
-- name
|
||||
v.drawString(column[2], y, score["name"], V_ALLOWLOWERCASE | textFlag)
|
||||
-- time
|
||||
v.drawString(column[3], y, rawget(_G, "TicsToTime")(score["time"]), textFlag)
|
||||
-- flags
|
||||
drawFlags(v, column[4], y, score["flags"])
|
||||
end
|
||||
|
||||
@ -292,12 +316,14 @@ local function drawBrowser(v, leaderboard)
|
||||
local scoreTable = gamemode[getMap()]
|
||||
if not scoreTable then return end
|
||||
|
||||
for i, score in ipairs(scoreTable) do
|
||||
if i > 10 then
|
||||
break
|
||||
end
|
||||
drawScore(v, i, score)
|
||||
local scores = #scoreTable
|
||||
scrollPos = max(min(scrollPos, scores - 3), 1)
|
||||
local endi = min(scrollPos + 7, scores)
|
||||
for i = scrollPos, endi do
|
||||
drawScore(v, i - scrollPos + 1, i, scoreTable[i])
|
||||
end
|
||||
v.drawString(0,0,scrollPos)
|
||||
v.drawString(0,10,endi)
|
||||
end
|
||||
rawset(_G, "DrawBrowser", drawBrowser)
|
||||
|
||||
@ -353,22 +379,30 @@ local function controller(player)
|
||||
resetKeyRepeat()
|
||||
end
|
||||
|
||||
local cmd = player.cmd
|
||||
if not keyRepeat then
|
||||
if player.cmd.driftturn > 0 then
|
||||
if cmd.driftturn > 0 then
|
||||
updateMapIndex(-1)
|
||||
updateKeyRepeat()
|
||||
elseif player.cmd.driftturn < 0 then
|
||||
elseif cmd.driftturn < 0 then
|
||||
updateMapIndex(1)
|
||||
updateKeyRepeat()
|
||||
elseif player.cmd.buttons & BT_DRIFT then
|
||||
elseif cmd.buttons & BT_FORWARD then
|
||||
scrollPos = $ - 1
|
||||
updateKeyRepeat()
|
||||
elseif cmd.buttons & BT_BACKWARD then
|
||||
scrollPos = $ + 1
|
||||
updateKeyRepeat()
|
||||
elseif cmd.buttons & BT_DRIFT then
|
||||
if #modes then
|
||||
mode = $ % #modes + 1
|
||||
end
|
||||
scrollPos = 1
|
||||
updateKeyRepeat()
|
||||
elseif player.cmd.buttons & BT_BRAKE then
|
||||
elseif cmd.buttons & BT_BRAKE then
|
||||
S_StartSound(nil, 115)
|
||||
return true
|
||||
elseif player.cmd.buttons & BT_ACCELERATE then
|
||||
elseif cmd.buttons & BT_ACCELERATE then
|
||||
S_StartSound(nil, 143)
|
||||
COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex]))
|
||||
return true
|
||||
@ -383,5 +417,6 @@ local function netvars(net)
|
||||
mapIndex = net($)
|
||||
modes = net($)
|
||||
mode = net($)
|
||||
scrollPos = net($)
|
||||
end
|
||||
addHook("NetVars", netvars)
|
||||
|
Loading…
Reference in New Issue
Block a user