remember preferred gamemode
This commit is contained in:
parent
294ef8d40c
commit
127161fe9c
68
browser.lua
68
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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user