Skip to content

Commit

Permalink
Merge pull request #727 from jere0500/saveSettings-pull
Browse files Browse the repository at this point in the history
[Feature] System for saving and loading option presets using a local file
  • Loading branch information
AntlerForce authored Nov 8, 2024
2 parents 5541fa3 + 4cbc5bc commit 9934413
Show file tree
Hide file tree
Showing 2 changed files with 869 additions and 1 deletion.
91 changes: 90 additions & 1 deletion LuaMenu/widgets/gui_battle_room_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ local mainWindowFunctions

local showDefaultStartCheckbox = false
local currentStartRects = {}
local startRectValues = {} -- for exporting the raw values

local singleplayerWrapper
local multiplayerWrapper
Expand Down Expand Up @@ -55,6 +56,7 @@ local vote_votingsPattern = "(%d+)/(%d+).-:(%d+)"
local vote_whoCalledPattern = "%* (.*) called a vote for command"
local vote_mapPattern = 'set map (.*)"'

local playerHandler
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Download management
Expand Down Expand Up @@ -1117,12 +1119,37 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
parent = leftInfo,
}
leftOffset = leftOffset + 40
local btnOptionPresets = Button:New {
name = 'btnOptionpresets',
x = 5,
y = leftOffset,
height = 35,
right = 5,
classname = "option_button",
caption = "Option Presets" .. "\b",
objectOverrideFont = config:GetFont(2),
objectOverrideDisabledFont = config:GetFont(1),
hasDisabledFont = true,
tooltip = tooltip,
OnClick = {
function()
if modoptionsLoaded then
WG.OptionpresetsPanel.ShowPresetPanel()
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)
-- preset loading is useless if modification of modoptions not allow
btnOptionPresets.suppressButtonReaction = true
btnOptionPresets: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
Expand All @@ -1138,6 +1165,11 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
btnModoptions:SetEnabled(true)
modoptionsLoaded = true

--enable also btnOptionPresets
btnOptionPresets.suppressButtonReaction = false
btnOptionPresets.tooltip = "Create and Load Presets for gameplay options"
btnOptionPresets:SetEnabled(true)

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

Expand Down Expand Up @@ -1267,6 +1299,8 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
offset = offset + 38
btnModoptions:SetPos(nil, offset)
offset = offset + 40
btnOptionPresets:SetPos(nil, offset)
offset = offset + 40
lblGame:SetPos(nil, offset)
offset = offset + 26
imHaveGame:SetPos(nil, offset)
Expand Down Expand Up @@ -1472,6 +1506,9 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
-- it doesnt even know how big it is right nowhere
-- Spring.Utilities.TraceFullEcho()

-- adding the raw values
startRectValues[allyNo+1]={["left"]=left, ["top"]=top, ["right"]=right, ["bottom"]=bottom}

local minimapPanelMaxSize = math.max(minimapPanel.width,minimapPanel.height) -1
local ox = math.floor(left * minimapPanelMaxSize / 200)
local oy = math.floor(top * minimapPanelMaxSize / 200)
Expand Down Expand Up @@ -1528,6 +1565,9 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
--try to manage clicking on the startbox not changing it.
--TODO: problematic when resizing entire UI :/

-- updating the raw values
startRectValues[tonumber(obj.caption)]={["left"]=l, ["top"]=t, ["right"]=r, ["bottom"]=b}

obj:Invalidate() --doesnt do much
if battleLobby.name == "singleplayer" then
WG.Chobby.Configuration.gameConfig.mapStartBoxes.addBox(l,t,r,b,obj.caption)
Expand Down Expand Up @@ -1573,6 +1613,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
if currentStartRects[allyNo+1] then
currentStartRects[allyNo+1]:Dispose()
currentStartRects[allyNo+1] = nil
startRectValues[allyNo+1] = nil
end
for i,rect in pairs(currentStartRects) do
rect:BringToFront()
Expand Down Expand Up @@ -1841,6 +1882,7 @@ local function SetupPlayerPanel(playerParent, spectatorParent, battle, battleID)
if button == 3 and WG.Chobby.Configuration.lastAddedAiName then
quickAddAi = WG.Chobby.Configuration.lastAddedAiName
end

WG.PopupPreloader.ShowAiListWindow(battleLobby, battle.gameName, teamIndex, quickAddAi)
end,
disallowCustomTeams and teamIndex ~= 0,
Expand Down Expand Up @@ -2119,6 +2161,13 @@ local function SetupPlayerPanel(playerParent, spectatorParent, battle, battleID)
RemovePlayerFromTeam(botName)
end

function externalFunctions.GetTeam(index)
if(index >= emptyTeamIndex)then
OpenNewTeam()
end
return GetTeam(index)
end

return externalFunctions
end

Expand Down Expand Up @@ -2955,7 +3004,7 @@ local function InitializeControls(battleID, oldLobby, topPoportion, setupData)
parent = bottomPanel,
}

local playerHandler = SetupPlayerPanel(playerPanel, spectatorPanel, battle, battleID)
playerHandler = SetupPlayerPanel(playerPanel, spectatorPanel, battle, battleID)


spadsStatusPanel = Control:New{
Expand Down Expand Up @@ -3872,6 +3921,8 @@ function BattleRoomWindow.ShowMultiplayerBattleRoom(battleID)
allyNumber = 0,
sync = (haveMapAndGame and 1) or 2, -- 0 = unknown, 1 = synced, 2 = unsynced
})

WG.OptionpresetsPanel.cloneMPModoptions(true)
end

function BattleRoomWindow.GetSingleplayerControl(setupData)
Expand Down Expand Up @@ -4083,6 +4134,44 @@ function BattleRoomWindow.ClearChatHistory()
end
end


function BattleRoomWindow.GetCurrentStartRects()
return startRectValues
end

function BattleRoomWindow.AddStartRect(allyNo, left, top, right, bottom)
if battleLobby.name == "singleplayer" then
local infoHandler = mainWindowFunctions.GetInfoHandler()
infoHandler.AddStartRect(allyNo, left, top, right, bottom)
else
battleLobby:SayBattle(string.format("!addbox %d %d %d %d %s", left, top, right, bottom, allyNo+1))
end
end

function BattleRoomWindow.RemoveStartRect(allyNo)
if battleLobby.name == "singleplayer" then
local infoHandler = mainWindowFunctions.GetInfoHandler()
infoHandler.RemoveStartRect(allyNo)
end
end


function BattleRoomWindow.SetTeams(numberOfTeams)
if not battleLobby.name == "singleplayer" then
-- command to set the teams
battleLobby:SayBattle(string.format("!nbteams %d", numberOfTeams))
end
end

function BattleRoomWindow.SetStart(allyNo)
local infoHandler = mainWindowFunctions.GetInfoHandler()
infoHandler.RemoveStartRect(allyNo)
end

function BattleRoomWindow.GetPlayerHandler()
return playerHandler
end

local function DelayedInitialize()
local function onConfigurationChange(listener, key, value)
if mainWindowFunctions and key == "canAuthenticateWithSteam" then
Expand Down
Loading

0 comments on commit 9934413

Please sign in to comment.