Skip to content

Commit

Permalink
Merge pull request #633 from robertthepie/moreModoptionsPanelFixes
Browse files Browse the repository at this point in the history
Disable Adv Options Button when no modoptions present
  • Loading branch information
AntlerForce authored Apr 6, 2024
2 parents d25eeed + 51ef573 commit 19e9a02
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 20 deletions.
54 changes: 39 additions & 15 deletions LuaMenu/widgets/gui_battle_room_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1155,26 +1155,16 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs

-- modoptions
WG.ModoptionsPanel.LoadModoptions(battle.gameName, battleLobby)
-- if load modoptions failed there may be modoptions from the previous game
local modoptions = WG.ModoptionsPanel.ReturnModoptions()


-- this is a kludge so that we can override default values for some specific ModOptions in singleplayer games
if modoptions then
for i = 1, #modoptions do
local data = modoptions[i]
-- default teamffa_start_boxes_shuffle to "off" for singleplayer games
-- teamffa_start_boxes_shuffle defaults to "on" for multiplayer games since it is desirable to hide start location
-- however in singleplayer it is a common scenario to play a pseudo-TeamFFA game against multiple AIs, and in this
-- case players typically do not want to be booted off their specifically chosen start box
if data.key == "teamffa_start_boxes_shuffle" then
data.def = not (battleLobby.name == "singleplayer")
end
end
end

local tooltip = modoptions
and "Configure custom gameplay options"
or "Error: Could not retrieve modoptions, your game files may be corrupted or the lobby may be invalid"
--or "Error: Could not retrieve modoptions, your game files may be corrupted or the lobby may be invalid"
or "Game Update may still be downloading"
local modoptionsLoaded = modoptions
local btnModoptions = Button:New {
name = 'btnModoptions',
x = 5,
Expand All @@ -1184,16 +1174,50 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
classname = "option_button",
caption = "Adv Options" .. "\b",
objectOverrideFont = config:GetFont(2),
objectOverrideDisabledFont = config:GetFont(1),
hasDisabledFont = true,
tooltip = tooltip,
OnClick = {
function()
WG.ModoptionsPanel.ShowModoptions()
if modoptionsLoaded then
WG.ModoptionsPanel.ShowModoptions()
end
end
},
parent = leftInfo,
}
leftOffset = leftOffset + 40

-- gray out the button if we don't have a modoptions panel to show
if not modoptions then
-- cosmetics when disabled
btnModoptions.suppressButtonReaction = true
btnModoptions:SetEnabled(false)
end

-- the modoptions panel needing a refresh is independant on if we have a modoptions panel from a diffrent version to fall back onto
if not VFS.HasArchive(battle.gameName) then
-- Listener function to re-enable the button
local function gameArchiveReady(k,v)
if VFS.HasArchive(battle.gameName) then
WG.ModoptionsPanel.LoadModoptions(battle.gameName, battleLobby)

-- cosmetics for re-enabling
btnModoptions.suppressButtonReaction = false
btnModoptions.tooltip = "Configure custom gameplay options"
btnModoptions:SetEnabled(true)
modoptionsLoaded = true

local modoptionspanelExternalFunctions = WG.ModoptionsPanel.GetModoptionsControl()
modoptionspanelExternalFunctions:Update()

WG.DownloadHandler.RemoveListener("DownloadFinished", gameArchiveReady)
end
end

WG.DownloadHandler.AddListener("DownloadFinished", gameArchiveReady)
end


local lblGame = Label:New {
name = 'lblGame',
Expand Down
44 changes: 39 additions & 5 deletions LuaMenu/widgets/gui_modoptions_panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,14 @@ local function InitializeModoptionsDisplay()
return value
end

local panelModoptions

local function OnSetModOptions(listener, modopts)
if not modopts then
return
end
local text = ""
local empty = true
modoptions = modopts
for key, value in pairs(modoptions) do
panelModoptions = modopts or panelModoptions or {}
if not modoptions then return end
for key, value in pairs(panelModoptions) do
if modoptionDefaults[key] == nil or modoptionDefaults[key] ~= value or key == "ranked_game" then
local option = getModOptionByKey(key)
local name = option.name and option.name or key
Expand Down Expand Up @@ -677,6 +677,40 @@ function ModoptionsPanel.LoadModoptions(gameName, newBattleLobby)
end
end

-- adjust the modoptions for singleplayer/multiplayer
if modoptions then
-- singleplayer adjustments
if battleLobby.name == "singleplayer" then
for i = 1, #modoptions do
local data = modoptions[i]
if data.key == "teamffa_start_boxes_shuffle" then
data.def = false
end

if data.visible == "mp" then
data.hidden = true
end
if data.spdef then
data.def = data.spdef
end
end
-- multiplayer adjustments
else
for i = 1, #modoptions do
local data = modoptions[i]

if data.visible == "sp" then
data.hidden = true
end
if data.mpdef then
data.def = data.mpdef
end
end
end
end



modoptionDefaults = {}
if not modoptions then
return
Expand Down

0 comments on commit 19e9a02

Please sign in to comment.