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