From b6e6e82bd6596601b6950bddc835b553b6ec5d20 Mon Sep 17 00:00:00 2001 From: Not Date: Mon, 29 Aug 2022 06:08:53 +0200 Subject: [PATCH 01/23] add levelselector --- browser.lua | 337 ++++++++++++++++++++++++++++++++++++++++++++++++ leaderboard.lua | 27 +++- 2 files changed, 362 insertions(+), 2 deletions(-) create mode 100644 browser.lua diff --git a/browser.lua b/browser.lua new file mode 100644 index 0000000..8c9d8d2 --- /dev/null +++ b/browser.lua @@ -0,0 +1,337 @@ +local maps +local mapIndex = 1 +local modes = nil +local mode = 1 + +local function mapIndexOffset(n) + return (mapIndex + n + #maps - 1) % #maps + 1 +end + +local function updateMapIndex(n) + mapIndex = mapIndexOffset(n) + + -- TODO: keep mode while scrolling through levels + mode = 1 + modes = nil +end + +local function getMap(offset) + return maps[mapIndexOffset(offset or 0)] +end + +local scalar = 2 +local hlfScrnWdth = 320 / 2 +local mappY = 26 +local ttlY = mappY + FixedMul(30, FRACUNIT / scalar) +local scoresY = ttlY + 16 + +local function drawMapPatch(v, offset) + local scale = FRACUNIT / (abs(offset) + scalar) + local mapName = G_BuildMapName(getMap(offset)) + local mapp = v.cachePatch(mapName.."P") + + local scaledWidth = FixedMul(mapp.width, scale) + local scaledHeight = FixedMul(mapp.height, scale) + + v.drawScaled( + (hlfScrnWdth + offset * scaledWidth - scaledWidth / 2) * FRACUNIT, + (mappY - scaledHeight / 2) * FRACUNIT, + scale, + mapp + ) +end + +local colors = { + [0] = 0, + [1] = 215 +} +local function drawMapBorder(v) + local mapWidth = FixedMul(160, FRACUNIT / scalar) + local mapHeight = FixedMul(100, FRACUNIT / scalar) + v.drawFill( + hlfScrnWdth - mapWidth / 2 - 1, + mappY - mapHeight / 2 -1, + mapWidth + 2, + mapHeight + 2, + colors[leveltime / 4 % 2] + ) +end + +local function zoneAct(map) + local z = "" + if map.zonttl != "" then + z = " " + map.zonttl + elseif not(map.levelflags & LF_NOZONE) then + z = " Zone" + end + if map.actnum != "" then + z = $ + " " + map.actnum + end + + return z +end + +local function drawMapStrings(v) + local map = mapheaderinfo[getMap()] + local titleWidth = v.stringWidth(map.lvlttl) + + -- title + v.drawString( + hlfScrnWdth, + ttlY, + map.lvlttl, + V_SKYMAP, + "center" + ) + + -- zone/act + local zone = zoneAct(map) + local zoneWidth = v.stringWidth(zone) + v.drawString( + hlfScrnWdth + titleWidth / 2, + ttlY + 8, + zone, + V_SKYMAP, + "right" + ) + + -- subtitle + v.drawString( + hlfScrnWdth + titleWidth / 2 - zoneWidth, + ttlY + 8, + map.subttl, + V_MAGENTAMAP, + "small-right" + ) +end + +local F_SPBATK = 0x1 +local F_SPBJUS = 0x2 +local F_SPBBIG = 0x4 +local F_SPBEXP = 0x8 + +local function drawGamemode(v) + local m = modes[mode] or 0 + + local modeX = 20 + local modeY = scoresY + local scale = FRACUNIT / 2 + + if m == 0 then + local clockp = v.cachePatch("K_LAPE02") + v.drawScaled( + modeX * FRACUNIT, + modeY * FRACUNIT, + scale, + clockp + ) + + v.drawString( + modeX, + modeY, + "Time Attack!" + ) + elseif m & F_SPBATK then + local scaledHalf = FixedMul(50 * FRACUNIT, scale) / 2 + local xoff = 0 + if m & F_SPBBIG then + xoff = $ + scaledHalf + end + if m & F_SPBEXP then + xoff = $ + scaledHalf + end + + if m & F_SPBBIG then + local growp = v.cachePatch("K_ITGROW") + v.drawScaled( + modeX * FRACUNIT - scaledHalf + xoff, + modeY * FRACUNIT - scaledHalf, + scale, + growp + ) + + xoff = $ - scaledHalf + end + + if m & F_SPBEXP then + local invp = v.cachePatch("K_ITINV"..(leveltime / 6 % 7 + 1)) + v.drawScaled( + modeX * FRACUNIT - scaledHalf + xoff, + modeY * FRACUNIT - scaledHalf, + scale, + invp + ) + end + + local spbp = v.cachePatch("K_ITSPB") + v.drawScaled( + modeX * FRACUNIT - scaledHalf, + modeY * FRACUNIT - scaledHalf, + scale, + spbp + ) + + v.drawString( + modeX, + modeY, + "SPB Attack!" + ) + end +end + +-- draw in columns +-- pos, facerank, name, time, flags +-- ______________________________________________ +-- | 3|[O]|InsertNameHere | 01:02:03 | EXB | +-- ---------------------------------------------- +local column = { + [0] = 18, -- pos, drawNum is right aligned + [1] = 18, -- facerank + [2] = 46, -- name + [3] = 216, -- time + [4] = 250 -- flags +} +local function drawScore(v, i, score) + local y = scoresY + i * 18 + + -- position + v.drawNum(column[0], y, i) + + 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"])) + v.drawString(column[2], y, score["name"], V_ALLOWLOWERCASE) + v.drawString(column[3], y, rawget(_G, "TicsToTime")(score["time"])) +end + +local function drawBrowser(v, leaderboard) + -- set available modes for this map + -- TODO: set this elsewhere + if modes == nil then + modes = {} + for mode, scoreTable in pairs(leaderboard) do + if scoreTable[getMap()] then + table.insert(modes, mode) + end + end + table.sort(modes) + end + + v.fadeScreen(0xFF00, 16) + + -- previous, next maps + for i = 5, 1, -1 do + drawMapPatch(v, -i) + drawMapPatch(v, i) + end + + -- draw map border + drawMapBorder(v) + + -- current map + drawMapPatch(v, 0) + drawMapStrings(v) + drawGamemode(v) + + if not modes then return end + + local gamemode = leaderboard[modes[mode]] + if not gamemode then return end + + 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) + end +end +rawset(_G, "DrawBrowser", drawBrowser) + +local function initBrowser(leaderboard) + -- set mapIndex to current map + for i, m in ipairs(maps) do + if m == gamemap then + mapIndex = i + break + end + end + + modes = nil + mode = 1 +end +rawset(_G, "InitBrowser", initBrowser) + +-- initialize maps with racemaps only +local function loadMaps() + maps = {} + for i = 0, #mapheaderinfo do + local map = mapheaderinfo[i] + if map and map.typeoflevel & TOL_RACE then + table.insert(maps, i) + end + end +end +addHook("MapLoad", loadMaps) + +local repeatCount = 0 +local keyRepeat = 0 + +local function updateKeyRepeat() + S_StartSound(nil, 143) + if repeatCount < 1 then + keyRepeat = TICRATE / 4 + else + keyRepeat = TICRATE / 15 + end + repeatCount = $ + 1 +end + +local function resetKeyRepeat() + keyRepeat = 0 + repeatCount = 0 +end + +-- return value indicates we want to exit the browser +local function controller(player) + keyRepeat = max(0, $ - 1) + + if not (player.cmd.driftturn or player.cmd.buttons) then + resetKeyRepeat() + end + + if not keyRepeat then + if player.cmd.driftturn > 0 then + updateMapIndex(-1) + updateKeyRepeat() + elseif player.cmd.driftturn < 0 then + updateMapIndex(1) + updateKeyRepeat() + elseif player.cmd.buttons & BT_DRIFT then + if #modes then + mode = $ % #modes + 1 + end + updateKeyRepeat() + elseif player.cmd.buttons & BT_BRAKE then + S_StartSound(nil, 115) + return true + elseif player.cmd.buttons & BT_ACCELERATE then + S_StartSound(nil, 143) + COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex])) + return true + end + end +end +rawset(_G, "BrowserController", controller) + + +local function netvars(net) + maps = net($) + mapIndex = net($) + modes = net($) + mode = net($) +end +addHook("NetVars", netvars) diff --git a/leaderboard.lua b/leaderboard.lua index 87b8696..cd49c1a 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -33,7 +33,7 @@ local RedFlash = { local StatTrack = false local UNCLAIMED = "Unclaimed Record" -local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore records" +local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore records levelselect" local FILENAME = "leaderboard.txt" -- Retry / changelevel map @@ -68,6 +68,7 @@ local DS_DEFAULT = 0x0 local DS_SCROLL = 0x1 local DS_AUTO = 0x2 local DS_SCRLTO = 0x4 +local DS_BROWSER = 0x8 local drawState = DS_DEFAULT @@ -396,6 +397,18 @@ local function exitlevel(player, ...) end COM_AddCommand("exit", exitlevel) +local function browser(player) + if not doyoudare(player) then return end + + if not rawget(_G, "DrawBrowser") then + print("Browser is not loaded") + return + end + rawget(_G, "InitBrowser")() + drawState = DS_BROWSER +end +COM_AddCommand("levelselect", browser) + local function zoneAct(map) local z = "" if map.zonttl != "" then @@ -835,6 +848,7 @@ function ticsToTime(tics, pure) G_TicsToCentiseconds(tics) ) end +rawset(_G, "TicsToTime", ticsToTime) -- Item patches have the amazing property of being displaced 12x 13y pixels local iXoffset = 13 * FRACUNIT @@ -1116,11 +1130,16 @@ local function drawScrollTo(v, player, scoreTable, gui) drawScroll(v, player, scoreTable, gui) end +local function drawBrowser(v, player) + rawget(_G, "DrawBrowser")(v, lb) +end + local stateFunctions = { [DS_DEFAULT] = drawDefault, [DS_SCROLL] = drawScroll, [DS_AUTO] = drawAuto, - [DS_SCRLTO] = drawScrollTo + [DS_SCRLTO] = drawScrollTo, + [DS_BROWSER] = drawBrowser } -- Draw mode and return pos + 1 if success @@ -1457,6 +1476,10 @@ local function think() scrollAcc = 0 end end + elseif drawState == DS_BROWSER then + if rawget(_G, "BrowserController")(p) then + drawState = DS_DEFAULT + end end if p.lives == 0 then -- 2.45.2 From 554e329194de88326273fa820eb19deae3362d67 Mon Sep 17 00:00:00 2001 From: Not Date: Mon, 29 Aug 2022 16:19:02 +0200 Subject: [PATCH 02/23] delay intermission while browsing --- leaderboard.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/leaderboard.lua b/leaderboard.lua index cd49c1a..5e13e98 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -1480,6 +1480,11 @@ local function think() if rawget(_G, "BrowserController")(p) then drawState = DS_DEFAULT end + + -- prevent intermission while browsing + if p.exiting then + p.exiting = $ + 1 + end end if p.lives == 0 then -- 2.45.2 From 45cefc786ed7610776041bcab3b0c7793d293362 Mon Sep 17 00:00:00 2001 From: Not Date: Tue, 30 Aug 2022 20:47:50 +0200 Subject: [PATCH 03/23] disable spba if browser is open --- leaderboard.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 5e13e98..2920a71 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -1485,9 +1485,14 @@ local function think() if p.exiting then p.exiting = $ + 1 end - end - if p.lives == 0 then + -- disable spba hud + if server.SPBAdone then + server.SPBArunning = false + p.pflags = $ & !(PF_TIMEOVER) + p.exiting = 100 + end + elseif p.lives == 0 then drawState = DS_SCROLL end -- 2.45.2 From 45effdd048eb17a6978e22ac7b7d28a25684f2a7 Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 00:41:05 +0200 Subject: [PATCH 04/23] draw flags --- browser.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/browser.lua b/browser.lua index 8c9d8d2..237b95c 100644 --- a/browser.lua +++ b/browser.lua @@ -109,6 +109,7 @@ local F_SPBATK = 0x1 local F_SPBJUS = 0x2 local F_SPBBIG = 0x4 local F_SPBEXP = 0x8 +local F_ENCORE = 0x80 local function drawGamemode(v) local m = modes[mode] or 0 @@ -179,6 +180,53 @@ local function drawGamemode(v) end end +local function drawFlags(v, x, y, flags) + local nx = x * FRACUNIT + local ny = y * FRACUNIT + 3 * FRACUNIT + local margin = 4 * FRACUNIT + if flags & F_ENCORE then + local encp = v.cachePatch("RUBYICON") + v.drawScaled( + nx, ny, + FRACUNIT / 6, + encp + ) + nx = $ + margin + end + if flags & F_SPBATK then + local scale = FRACUNIT / 4 + local shift = 6 * FRACUNIT + nx = $ - shift + ny = $ - shift + if flags & F_SPBJUS then + local hyup = v.cachePatch("K_ISHYUD") + v.drawScaled(nx, ny, scale, hyup) + nx = $ + margin + end + if flags & F_SPBBIG then + local growp = v.cachePatch("K_ISGROW") + v.drawScaled(nx, 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) + end + end +end + +local function drawStats(v, x, y, skin, stats) + local s = skins[skin] + if not (s + and s.kartspeed == stats["speed"] + and s.kartweight == stats["weight"] + ) + and stats then + v.drawString(x-2, y-2, stats["speed"], V_ALLOWLOWERCASE, "thin") + v.drawString(x + 13, y + 9, stats["weight"], V_ALLOWLOWERCASE, "thin") + end +end + -- draw in columns -- pos, facerank, name, time, flags -- ______________________________________________ @@ -189,7 +237,7 @@ local column = { [1] = 18, -- facerank [2] = 46, -- name [3] = 216, -- time - [4] = 250 -- flags + [4] = 270 -- flags } local function drawScore(v, i, score) local y = scoresY + i * 18 @@ -201,8 +249,10 @@ local function drawScore(v, i, score) 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"])) + 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"])) + drawFlags(v, column[4], y, score["flags"]) end local function drawBrowser(v, leaderboard) -- 2.45.2 From fd1827b2149e9298f1253bfdee48f48697bafd6c Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 02:18:21 +0200 Subject: [PATCH 05/23] add scrolling to browser --- browser.lua | 85 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/browser.lua b/browser.lua index 237b95c..795ab51 100644 --- a/browser.lua +++ b/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) -- 2.45.2 From 294ef8d40c7c155f924a5ea141b365765ba067db Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 02:51:55 +0200 Subject: [PATCH 06/23] use BLANKLVL --- browser.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/browser.lua b/browser.lua index 795ab51..dde802e 100644 --- a/browser.lua +++ b/browser.lua @@ -30,7 +30,8 @@ local scoresY = ttlY + 16 local function drawMapPatch(v, offset) local scale = FRACUNIT / (abs(offset) + scalar) local mapName = G_BuildMapName(getMap(offset)) - local mapp = v.cachePatch(mapName.."P") + local patchName = mapName.."P" + local mapp = v.patchExists(patchName) and v.cachePatch(patchName) or v.cachePatch("BLANKLVL") local scaledWidth = FixedMul(mapp.width, scale) local scaledHeight = FixedMul(mapp.height, scale) @@ -322,8 +323,6 @@ local function drawBrowser(v, leaderboard) 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) -- 2.45.2 From 127161fe9c4c68585059359156af05c45698222b Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 04:33:14 +0200 Subject: [PATCH 07/23] remember preferred gamemode --- browser.lua | 68 +++++++++++++++++++++++++++++-------------------- leaderboard.lua | 2 +- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/browser.lua b/browser.lua index dde802e..5ee7ccd 100644 --- a/browser.lua +++ b/browser.lua @@ -1,26 +1,46 @@ +local leaderboard = nil local maps local mapIndex = 1 local scrollPos = 1 local modes = nil local mode = 1 +local prefMode = nil local function mapIndexOffset(n) return (mapIndex + n + #maps - 1) % #maps + 1 end -local function updateMapIndex(n) - mapIndex = mapIndexOffset(n) - - -- TODO: keep mode while scrolling through levels - mode = 1 - modes = nil - scrollPos = 1 -end - local function getMap(offset) return maps[mapIndexOffset(offset or 0)] end +local function updateModes() + -- set available modes for this map + modes = {} + for mode, scoreTable in pairs(leaderboard) do + if scoreTable[getMap()] then + table.insert(modes, mode) + end + end + table.sort(modes) + + mode = 1 + -- select pref mode + for i, m in ipairs(modes) do + if m == prefMode then + mode = i + break + end + end +end + +local function updateMapIndex(n) + mapIndex = mapIndexOffset(n) + scrollPos = 1 + + updateModes() +end + local scalar = 2 local hlfScrnWdth = 320 / 2 local mappY = 26 @@ -280,18 +300,8 @@ local function drawScore(v, i, pos, score) drawFlags(v, column[4], y, score["flags"]) end -local function drawBrowser(v, leaderboard) - -- set available modes for this map - -- TODO: set this elsewhere - if modes == nil then - modes = {} - for mode, scoreTable in pairs(leaderboard) do - if scoreTable[getMap()] then - table.insert(modes, mode) - end - end - table.sort(modes) - end +local function drawBrowser(v) + if not leaderboard then return end v.fadeScreen(0xFF00, 16) @@ -326,7 +336,9 @@ local function drawBrowser(v, leaderboard) end rawset(_G, "DrawBrowser", drawBrowser) -local function initBrowser(leaderboard) +local function initBrowser(lb) + leaderboard = lb + -- set mapIndex to current map for i, m in ipairs(maps) do if m == gamemap then @@ -335,8 +347,7 @@ local function initBrowser(leaderboard) end end - modes = nil - mode = 1 + updateModes() end rawset(_G, "InitBrowser", initBrowser) @@ -393,10 +404,11 @@ local function controller(player) scrollPos = $ + 1 updateKeyRepeat() elseif cmd.buttons & BT_DRIFT then - if #modes then - mode = $ % #modes + 1 - end scrollPos = 1 + if modes then + mode = $ % #modes + 1 + prefMode = modes[mode] + end updateKeyRepeat() elseif cmd.buttons & BT_BRAKE then S_StartSound(nil, 115) @@ -416,6 +428,8 @@ local function netvars(net) mapIndex = net($) modes = net($) mode = net($) + prefMode = net($) scrollPos = net($) + leaderboard = net($) end addHook("NetVars", netvars) diff --git a/leaderboard.lua b/leaderboard.lua index 2920a71..f316f79 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -404,7 +404,7 @@ local function browser(player) print("Browser is not loaded") return end - rawget(_G, "InitBrowser")() + rawget(_G, "InitBrowser")(lb) drawState = DS_BROWSER end COM_AddCommand("levelselect", browser) -- 2.45.2 From 7642dfaf981d68566a7081633cd653e93ef629f3 Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 04:36:31 +0200 Subject: [PATCH 08/23] reset prefMode, scrollPos on init --- browser.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/browser.lua b/browser.lua index 5ee7ccd..9cd17b7 100644 --- a/browser.lua +++ b/browser.lua @@ -347,6 +347,8 @@ local function initBrowser(lb) end end + prefMode = nil + scrollPos = 1 updateModes() end rawset(_G, "InitBrowser", initBrowser) -- 2.45.2 From 003dd98ce31dec67cdac43e5cec250902790fe9e Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 04:44:43 +0200 Subject: [PATCH 09/23] rawget once --- leaderboard.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index f316f79..6fccf13 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -397,17 +397,25 @@ local function exitlevel(player, ...) end COM_AddCommand("exit", exitlevel) -local function browser(player) +local DrawBrowser +local BrowserController +local function initBrowser(player) if not doyoudare(player) then return end - if not rawget(_G, "DrawBrowser") then - print("Browser is not loaded") - return + if not DrawBrowser then + DrawBrowser = rawget(_G, "DrawBrowser") + if not DrawBrowser then + print("Browser is not loaded") + return + end + + BrowserController = rawget(_G, "BrowserController") end + rawget(_G, "InitBrowser")(lb) drawState = DS_BROWSER end -COM_AddCommand("levelselect", browser) +COM_AddCommand("levelselect", initBrowser) local function zoneAct(map) local z = "" @@ -1131,7 +1139,7 @@ local function drawScrollTo(v, player, scoreTable, gui) end local function drawBrowser(v, player) - rawget(_G, "DrawBrowser")(v, lb) + DrawBrowser(v, lb) end local stateFunctions = { @@ -1477,7 +1485,7 @@ local function think() end end elseif drawState == DS_BROWSER then - if rawget(_G, "BrowserController")(p) then + if BrowserController(p) then drawState = DS_DEFAULT end -- 2.45.2 From ec12485c434d724d10f053ebcb3df82d19d93bea Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 04:45:15 +0200 Subject: [PATCH 10/23] actually, don't reset modePref on init --- browser.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/browser.lua b/browser.lua index 9cd17b7..21e39e3 100644 --- a/browser.lua +++ b/browser.lua @@ -347,7 +347,6 @@ local function initBrowser(lb) end end - prefMode = nil scrollPos = 1 updateModes() end -- 2.45.2 From 407d65b44dffe693a93cd5c12affbb5fefe55ac3 Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 18:49:47 +0200 Subject: [PATCH 11/23] reject browser in battle --- leaderboard.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/leaderboard.lua b/leaderboard.lua index 6fccf13..1f91836 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -402,6 +402,11 @@ local BrowserController local function initBrowser(player) if not doyoudare(player) then return end + -- TODO: allow in battle + if mapheaderinfo[gamemap].typeoflevel & TOL_MATCH then + CONS_Printf(player, "Please exit battle first") + return + end if not DrawBrowser then DrawBrowser = rawget(_G, "DrawBrowser") if not DrawBrowser then -- 2.45.2 From 6afb884e5901fd0541c3bd3bfe6d41e1f4929234 Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 19:25:40 +0200 Subject: [PATCH 12/23] fix uninitialized variables, add browser timeout --- leaderboard.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 1f91836..cbb3f45 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -55,6 +55,7 @@ local clearcheats = false local START_TIME = 6 * TICRATE + (3 * TICRATE / 4) + 1 local AFK_TIMEOUT = TICRATE * 5 +local AFK_BROWSER = TICRATE * 15 local AFK_BALANCE = TICRATE * 60 local AFK_BALANCE_WARN = AFK_BALANCE - TICRATE * 10 local PREVENT_JOIN_TIME = START_TIME + TICRATE * 5 @@ -407,18 +408,16 @@ local function initBrowser(player) CONS_Printf(player, "Please exit battle first") return end - if not DrawBrowser then - DrawBrowser = rawget(_G, "DrawBrowser") - if not DrawBrowser then - print("Browser is not loaded") - return - end - BrowserController = rawget(_G, "BrowserController") + if not rawget(_G, "DrawBrowser") then + print("Browser is not loaded") + return end rawget(_G, "InitBrowser")(lb) drawState = DS_BROWSER + + player.afkTime = leveltime end COM_AddCommand("levelselect", initBrowser) @@ -1144,6 +1143,9 @@ local function drawScrollTo(v, player, scoreTable, gui) end local function drawBrowser(v, player) + if not DrawBrowser then + DrawBrowser = rawget(_G, "DrawBrowser") + end DrawBrowser(v, lb) end @@ -1364,7 +1366,7 @@ local function think() if not singleplayer() then for p in players.iterate do if p.valid and not p.spectator and not p.exiting and p.lives > 0 then - if p.cmd.buttons then + if p.cmd.buttons or p.cmd.driftturn then p.afkTime = leveltime end @@ -1490,6 +1492,9 @@ local function think() end end elseif drawState == DS_BROWSER then + if not BrowserController then + BrowserController = rawget(_G, "BrowserController") + end if BrowserController(p) then drawState = DS_DEFAULT end @@ -1505,11 +1510,17 @@ local function think() p.pflags = $ & !(PF_TIMEOVER) p.exiting = 100 end + + -- prevent softlocking the server + if p.afkTime + AFK_BROWSER < leveltime then + drawState = DS_DEFAULT + S_StartSound(nil, 100) + end elseif p.lives == 0 then drawState = DS_SCROLL end - if p.cmd.buttons then + if p.cmd.buttons or p.cmd.driftturn then p.afkTime = leveltime end -- 2.45.2 From 416563928242d44a2ab37bbdbede9f774b8ebe18 Mon Sep 17 00:00:00 2001 From: Not Date: Thu, 1 Sep 2022 16:57:01 +0200 Subject: [PATCH 13/23] export functions --- browser.lua | 26 +++++++++----------------- leaderboard.lua | 1 + 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/browser.lua b/browser.lua index 21e39e3..1e50969 100644 --- a/browser.lua +++ b/browser.lua @@ -6,6 +6,10 @@ local modes = nil local mode = 1 local prefMode = nil +-- imported funcs +local ZoneAct +local TicsToTime + local function mapIndexOffset(n) return (mapIndex + n + #maps - 1) % #maps + 1 end @@ -80,20 +84,6 @@ local function drawMapBorder(v) ) end -local function zoneAct(map) - local z = "" - if map.zonttl != "" then - z = " " + map.zonttl - elseif not(map.levelflags & LF_NOZONE) then - z = " Zone" - end - if map.actnum != "" then - z = $ + " " + map.actnum - end - - return z -end - local function drawMapStrings(v) local map = mapheaderinfo[getMap()] local titleWidth = v.stringWidth(map.lvlttl) @@ -108,7 +98,7 @@ local function drawMapStrings(v) ) -- zone/act - local zone = zoneAct(map) + local zone = ZoneAct(map) local zoneWidth = v.stringWidth(zone) v.drawString( hlfScrnWdth + titleWidth / 2, @@ -295,7 +285,7 @@ local function drawScore(v, i, pos, score) -- name v.drawString(column[2], y, score["name"], V_ALLOWLOWERCASE | textFlag) -- time - v.drawString(column[3], y, rawget(_G, "TicsToTime")(score["time"]), textFlag) + v.drawString(column[3], y, TicsToTime(score["time"]), textFlag) -- flags drawFlags(v, column[4], y, score["flags"]) end @@ -303,6 +293,9 @@ end local function drawBrowser(v) if not leaderboard then return end + TicsToTime = $ or rawget(_G, "TicsToTime") + ZoneAct = $ or rawget(_G, "ZoneAct") + v.fadeScreen(0xFF00, 16) -- previous, next maps @@ -423,7 +416,6 @@ local function controller(player) end rawset(_G, "BrowserController", controller) - local function netvars(net) maps = net($) mapIndex = net($) diff --git a/leaderboard.lua b/leaderboard.lua index cbb3f45..af2f7df 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -434,6 +434,7 @@ local function zoneAct(map) return z end +rawset(_G, "ZoneAct", zoneAct) local function findMap(player, ...) local search = ... -- 2.45.2 From d7dc3336ddbb2e369d5870594e5a8d391c88cfdd Mon Sep 17 00:00:00 2001 From: Not Date: Fri, 2 Sep 2022 22:49:00 +0200 Subject: [PATCH 14/23] fix modulo by zero --- browser.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser.lua b/browser.lua index 1e50969..3138c13 100644 --- a/browser.lua +++ b/browser.lua @@ -399,7 +399,7 @@ local function controller(player) updateKeyRepeat() elseif cmd.buttons & BT_DRIFT then scrollPos = 1 - if modes then + if modes and #modes then mode = $ % #modes + 1 prefMode = modes[mode] end -- 2.45.2 From e453290419bd657f4c36009a8ba1ff77378028f9 Mon Sep 17 00:00:00 2001 From: Not Date: Fri, 2 Sep 2022 23:03:09 +0200 Subject: [PATCH 15/23] lb_common.lua --- browser.lua | 11 +++++----- lb_common.lua | 26 ++++++++++++++++++++++++ leaderboard.lua | 54 ++++++++++++------------------------------------- 3 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 lb_common.lua diff --git a/browser.lua b/browser.lua index 3138c13..8854f13 100644 --- a/browser.lua +++ b/browser.lua @@ -6,9 +6,11 @@ local modes = nil local mode = 1 local prefMode = nil --- imported funcs -local ZoneAct -local TicsToTime +-- Imported functions ------- +-- lb_common.lua +local ZoneAct = lb_ZoneAct +local TicsToTime = lb_TicsToTime +----------------------------- local function mapIndexOffset(n) return (mapIndex + n + #maps - 1) % #maps + 1 @@ -293,9 +295,6 @@ end local function drawBrowser(v) if not leaderboard then return end - TicsToTime = $ or rawget(_G, "TicsToTime") - ZoneAct = $ or rawget(_G, "ZoneAct") - v.fadeScreen(0xFF00, 16) -- previous, next maps diff --git a/lb_common.lua b/lb_common.lua new file mode 100644 index 0000000..ac7f479 --- /dev/null +++ b/lb_common.lua @@ -0,0 +1,26 @@ +rawset(_G, "lb_TicsToTime", function(tics, pure) + if tics == 0 and pure then + return "-:--:--" + end + + return string.format( + "%d:%02d:%02d", + G_TicsToMinutes(tics, true), + G_TicsToSeconds(tics), + G_TicsToCentiseconds(tics) + ) +end) + +rawset(_G, "lb_ZoneAct", function(map) + local z = "" + if map.zonttl != "" then + z = " " + map.zonttl + elseif not(map.levelflags & LF_NOZONE) then + z = " Zone" + end + if map.actnum != "" then + z = $ + " " + map.actnum + end + + return z +end) diff --git a/leaderboard.lua b/leaderboard.lua index af2f7df..d4d9f64 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -87,9 +87,18 @@ local clamp local scroll_to -local ticsToTime - local allowJoin + +-- Imported functions -- + +-- lb_common.lua +local ticsToTime = lb_TicsToTime +local zoneAct = lb_ZoneAct + +-- browser.lua +local InitBrowser = InitBrowser +local DrawBrowser = DrawBrowser +local BrowserController = BrowserController --------------- -- cvars @@ -398,8 +407,6 @@ local function exitlevel(player, ...) end COM_AddCommand("exit", exitlevel) -local DrawBrowser -local BrowserController local function initBrowser(player) if not doyoudare(player) then return end @@ -409,33 +416,18 @@ local function initBrowser(player) return end - if not rawget(_G, "DrawBrowser") then + if not InitBrowser then print("Browser is not loaded") return end - rawget(_G, "InitBrowser")(lb) + InitBrowser(lb) drawState = DS_BROWSER player.afkTime = leveltime end COM_AddCommand("levelselect", initBrowser) -local function zoneAct(map) - local z = "" - if map.zonttl != "" then - z = " " + map.zonttl - elseif not(map.levelflags & LF_NOZONE) then - z = " Zone" - end - if map.actnum != "" then - z = $ + " " + map.actnum - end - - return z -end -rawset(_G, "ZoneAct", zoneAct) - local function findMap(player, ...) local search = ... @@ -849,20 +841,6 @@ addHook("MapLoad", function() end ) -function ticsToTime(tics, pure) - if tics == 0 and pure then - return "-:--:--" - end - - return string.format( - "%d:%02d:%02d", - G_TicsToMinutes(tics, true), - G_TicsToSeconds(tics), - G_TicsToCentiseconds(tics) - ) -end -rawset(_G, "TicsToTime", ticsToTime) - -- Item patches have the amazing property of being displaced 12x 13y pixels local iXoffset = 13 * FRACUNIT local iYoffset = 12 * FRACUNIT @@ -1144,9 +1122,6 @@ local function drawScrollTo(v, player, scoreTable, gui) end local function drawBrowser(v, player) - if not DrawBrowser then - DrawBrowser = rawget(_G, "DrawBrowser") - end DrawBrowser(v, lb) end @@ -1493,9 +1468,6 @@ local function think() end end elseif drawState == DS_BROWSER then - if not BrowserController then - BrowserController = rawget(_G, "BrowserController") - end if BrowserController(p) then drawState = DS_DEFAULT end -- 2.45.2 From 2c11b1e0fc126480d1e3c4eeba01d950cf856fe8 Mon Sep 17 00:00:00 2001 From: Not Date: Fri, 2 Sep 2022 23:53:42 +0200 Subject: [PATCH 16/23] draw hell --- browser.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/browser.lua b/browser.lua index 8854f13..85a3025 100644 --- a/browser.lua +++ b/browser.lua @@ -118,6 +118,17 @@ local function drawMapStrings(v) V_MAGENTAMAP, "small-right" ) + + -- hell + if map.menuflags & LF2_HIDEINMENU then + v.drawString( + 300, + ttlY + 16, + "HELL", + V_REDMAP, + "right" + ) + end end local F_SPBATK = 0x1 -- 2.45.2 From 1f9c00202e5e42ad4296aab49682e4fb07c66c2f Mon Sep 17 00:00:00 2001 From: Not Date: Sat, 3 Sep 2022 00:12:57 +0200 Subject: [PATCH 17/23] group hell maps together --- browser.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/browser.lua b/browser.lua index 85a3025..937b69e 100644 --- a/browser.lua +++ b/browser.lua @@ -358,12 +358,22 @@ rawset(_G, "InitBrowser", initBrowser) -- initialize maps with racemaps only local function loadMaps() maps = {} + local hell = {} for i = 0, #mapheaderinfo do local map = mapheaderinfo[i] if map and map.typeoflevel & TOL_RACE then - table.insert(maps, i) + if map.menuflags & LF2_HIDEINMENU then + table.insert(hell, i) + else + table.insert(maps, i) + end end end + + -- append hell maps + for _, map in ipairs(hell) do + table.insert(maps, map) + end end addHook("MapLoad", loadMaps) -- 2.45.2 From c497581539617892af774e00457cf2838e25c297 Mon Sep 17 00:00:00 2001 From: Not Date: Sun, 4 Sep 2022 05:33:06 +0200 Subject: [PATCH 18/23] invert map selection direction --- browser.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser.lua b/browser.lua index 937b69e..3a68496 100644 --- a/browser.lua +++ b/browser.lua @@ -406,10 +406,10 @@ local function controller(player) local cmd = player.cmd if not keyRepeat then if cmd.driftturn > 0 then - updateMapIndex(-1) + updateMapIndex(1) updateKeyRepeat() elseif cmd.driftturn < 0 then - updateMapIndex(1) + updateMapIndex(-1) updateKeyRepeat() elseif cmd.buttons & BT_FORWARD then scrollPos = $ - 1 -- 2.45.2 From 2f5db0f3c73d81a12921b3f2d5d9a8320017631c Mon Sep 17 00:00:00 2001 From: Not Date: Sun, 4 Sep 2022 05:45:08 +0200 Subject: [PATCH 19/23] nevermind --- browser.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser.lua b/browser.lua index 3a68496..937b69e 100644 --- a/browser.lua +++ b/browser.lua @@ -406,10 +406,10 @@ local function controller(player) local cmd = player.cmd if not keyRepeat then if cmd.driftturn > 0 then - updateMapIndex(1) + updateMapIndex(-1) updateKeyRepeat() elseif cmd.driftturn < 0 then - updateMapIndex(-1) + updateMapIndex(1) updateKeyRepeat() elseif cmd.buttons & BT_FORWARD then scrollPos = $ - 1 -- 2.45.2 From f21bc7d97cb6ec46104134d37145aa4a464aebcf Mon Sep 17 00:00:00 2001 From: Not Date: Sun, 4 Sep 2022 17:23:32 +0200 Subject: [PATCH 20/23] flip left/right in encore --- browser.lua | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/browser.lua b/browser.lua index 937b69e..03695f5 100644 --- a/browser.lua +++ b/browser.lua @@ -395,6 +395,7 @@ local function resetKeyRepeat() repeatCount = 0 end +local ValidButtons = BT_ACCELERATE | BT_BRAKE | BT_FORWARD | BT_BACKWARD | BT_DRIFT -- return value indicates we want to exit the browser local function controller(player) keyRepeat = max(0, $ - 1) @@ -405,32 +406,36 @@ local function controller(player) local cmd = player.cmd if not keyRepeat then - if cmd.driftturn > 0 then - updateMapIndex(-1) - updateKeyRepeat() - elseif cmd.driftturn < 0 then - updateMapIndex(1) - updateKeyRepeat() + if not (cmd.buttons & ValidButtons or cmd.driftturn) then + return + end + + updateKeyRepeat() + + if cmd.buttons & BT_BRAKE then + S_StartSound(nil, 115) + return true + elseif cmd.buttons & BT_ACCELERATE then + COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex])) + return true + elseif cmd.driftturn then + local dir = cmd.driftturn > 0 and -1 or 1 + + if encoremode then + updateMapIndex(-dir) + else + updateMapIndex(dir) + end elseif cmd.buttons & BT_FORWARD then scrollPos = $ - 1 - updateKeyRepeat() elseif cmd.buttons & BT_BACKWARD then scrollPos = $ + 1 - updateKeyRepeat() elseif cmd.buttons & BT_DRIFT then scrollPos = 1 if modes and #modes then mode = $ % #modes + 1 prefMode = modes[mode] end - updateKeyRepeat() - elseif cmd.buttons & BT_BRAKE then - S_StartSound(nil, 115) - return true - elseif cmd.buttons & BT_ACCELERATE then - S_StartSound(nil, 143) - COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex])) - return true end end end -- 2.45.2 From 5fe7a6966a79bfb2d6f7119fca8c1485dd996ff8 Mon Sep 17 00:00:00 2001 From: Not Date: Sun, 4 Sep 2022 18:00:02 +0200 Subject: [PATCH 21/23] toggle encore with item button --- browser.lua | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/browser.lua b/browser.lua index 03695f5..9235916 100644 --- a/browser.lua +++ b/browser.lua @@ -12,6 +12,8 @@ local ZoneAct = lb_ZoneAct local TicsToTime = lb_TicsToTime ----------------------------- +local cv_kartencore + local function mapIndexOffset(n) return (mapIndex + n + #maps - 1) % #maps + 1 end @@ -53,6 +55,7 @@ local mappY = 26 local ttlY = mappY + FixedMul(30, FRACUNIT / scalar) local scoresY = ttlY + 16 +local sin = sin local function drawMapPatch(v, offset) local scale = FRACUNIT / (abs(offset) + scalar) local mapName = G_BuildMapName(getMap(offset)) @@ -68,6 +71,26 @@ local function drawMapPatch(v, offset) scale, mapp ) + +end + +local function drawEncore(v) + if not cv_kartencore then + cv_kartencore = CV_FindVar("kartencore") + end + + if not cv_kartencore.value then + return + end + + local rubyp = v.cachePatch("RUBYICON") + local bob = sin(leveltime * ANG10) * 2 + v.drawScaled( + hlfScrnWdth * FRACUNIT, + mappY * FRACUNIT + bob, + FRACUNIT, + rubyp + ) end local colors = { @@ -319,6 +342,7 @@ local function drawBrowser(v) -- current map drawMapPatch(v, 0) + drawEncore(v) drawMapStrings(v) drawGamemode(v) @@ -395,7 +419,8 @@ local function resetKeyRepeat() repeatCount = 0 end -local ValidButtons = BT_ACCELERATE | BT_BRAKE | BT_FORWARD | BT_BACKWARD | BT_DRIFT +local ValidButtons = BT_ACCELERATE | BT_BRAKE | BT_FORWARD | BT_BACKWARD | BT_DRIFT | BT_ATTACK + -- return value indicates we want to exit the browser local function controller(player) keyRepeat = max(0, $ - 1) @@ -418,6 +443,8 @@ local function controller(player) elseif cmd.buttons & BT_ACCELERATE then COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex])) return true + elseif cmd.buttons & BT_ATTACK then + COM_BufInsertText(player, "encore") elseif cmd.driftturn then local dir = cmd.driftturn > 0 and -1 or 1 -- 2.45.2 From f0cb05156457cf863fa3d0b6d32f0e8c3edd8be5 Mon Sep 17 00:00:00 2001 From: Not Date: Sun, 4 Sep 2022 18:32:41 +0200 Subject: [PATCH 22/23] speed up invinc icons --- browser.lua | 4 ++-- leaderboard.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/browser.lua b/browser.lua index 9235916..bffd404 100644 --- a/browser.lua +++ b/browser.lua @@ -204,7 +204,7 @@ local function drawGamemode(v) end if m & F_SPBEXP then - local invp = v.cachePatch("K_ITINV"..(leveltime / 6 % 7 + 1)) + local invp = v.cachePatch("K_ITINV"..(leveltime / 3 % 7 + 1)) v.drawScaled( modeX * FRACUNIT - scaledHalf + xoff, modeY * FRACUNIT - scaledHalf, @@ -259,7 +259,7 @@ local function drawFlags(v, x, y, flags) nx = $ + margin end if flags & F_SPBEXP then - local invp = v.cachePatch("K_ISINV"..(leveltime / 6 % 6 + 1)) + local invp = v.cachePatch("K_ISINV"..(leveltime / 3 % 6 + 1)) v.drawScaled(nx, ny, scale, invp) nx = $ + margin end diff --git a/leaderboard.lua b/leaderboard.lua index d4d9f64..b54e5dc 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -863,7 +863,7 @@ local modePatches = { local function modePatch(flag) if flag == F_SPBEXP then - return PATCH[modePatches[flag]][(leveltime / 4) % 6] + return PATCH[modePatches[flag]][(leveltime / 3) % 6] end return PATCH[modePatches[flag]] end -- 2.45.2 From dbf020e32009a5976aa7a655f4c8e962aebfd452 Mon Sep 17 00:00:00 2001 From: Not Date: Tue, 6 Sep 2022 09:52:51 +0200 Subject: [PATCH 23/23] highlight current player --- browser.lua | 13 ++++++++++--- leaderboard.lua | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/browser.lua b/browser.lua index bffd404..538dd02 100644 --- a/browser.lua +++ b/browser.lua @@ -304,7 +304,7 @@ local colorFlags = { [0] = V_SKYMAP, [1] = 0 } -local function drawScore(v, i, pos, score) +local function drawScore(v, i, pos, score, highlight) local y = scoresY + i * 18 local textFlag = colorFlags[pos%2] @@ -316,6 +316,13 @@ local function drawScore(v, i, pos, score) 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"])) + -- chili + if highlight then + local chilip = v.cachePatch("K_CHILI"..leveltime/4%8+1) + v.draw(column[1], y, chilip) + textFlag = V_YELLOWMAP + end + -- stats drawStats(v, column[1], y, score["skin"], score["stat"]) -- name @@ -326,7 +333,7 @@ local function drawScore(v, i, pos, score) drawFlags(v, column[4], y, score["flags"]) end -local function drawBrowser(v) +local function drawBrowser(v, player) if not leaderboard then return end v.fadeScreen(0xFF00, 16) @@ -358,7 +365,7 @@ local function drawBrowser(v) 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]) + drawScore(v, i - scrollPos + 1, i, scoreTable[i], scoreTable[i].name == player.name) end end rawset(_G, "DrawBrowser", drawBrowser) diff --git a/leaderboard.lua b/leaderboard.lua index b54e5dc..cdb4a78 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -1122,7 +1122,7 @@ local function drawScrollTo(v, player, scoreTable, gui) end local function drawBrowser(v, player) - DrawBrowser(v, lb) + DrawBrowser(v, player) end local stateFunctions = { -- 2.45.2