Skip to content

Commit

Permalink
Fix stack overflow in Squads options panel (#11179)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemigkh authored Aug 1, 2024
1 parent fd54ab1 commit c0b2b16
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions (4a) Squads for VP/UI/SquadsOptions.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
print('This is SquadsOptions.lua')

local SquadsOptions = Modding.OpenUserData( "Squads Options", 1 );

-- Defaults
Expand All @@ -9,14 +11,10 @@ local SquadsEndMovementType = 0;
function OpenSquadsOptions()
UpdateOptionsPanel();
Controls.OptionsPanel:SetHide( false );
-- Controls.SideStack:CalculateSize();
-- Controls.SideStack:ReprocessAnchoring();
end

function CloseSquadsOptions()
Controls.OptionsPanel:SetHide( true );
-- Controls.SideStack:CalculateSize();
-- Controls.SideStack:ReprocessAnchoring();
end

function ToggleSquadsOptions()
Expand All @@ -32,27 +30,23 @@ function UpdateOptionsPanel()
end

function HandleSquadsOptionsButton()
print("Squads Options Button Pressed");
ToggleSquadsOptions()
end
Controls.SquadsOptionsButton:RegisterCallback(Mouse.eLClick, HandleSquadsOptionsButton);

function HandleHighlightSquadUnitsCheckbox()
print("HandleHighlightSquadUnitsCheckbox")
HighlightSquadUnits = not HighlightSquadUnits;
LuaEvents.SQUADS_OPTIONS_CHANGED("HighlightSquadUnits", HighlightSquadUnits)
end
Controls.HighlightSquadUnitsCheckBox:RegisterCheckHandler(HandleHighlightSquadUnitsCheckbox);

function HandleFlagsNumberCheckBox()
print("HandleFlagsNumberCheckBox")
ShowSquadNumberUnderFlag = not ShowSquadNumberUnderFlag;
LuaEvents.SQUADS_OPTIONS_CHANGED("ShowSquadNumberUnderFlag", ShowSquadNumberUnderFlag)
end
Controls.FlagsNumberCheckBox:RegisterCheckHandler(HandleFlagsNumberCheckBox);

function HandleAlertOnArrivalRadioButton()
print("HandleAlertOnArrivalRadioButton")
if SquadsEndMovementType ~= 0 then
SquadsEndMovementType = 0;
LuaEvents.SQUADS_OPTIONS_CHANGED("SquadsEndMovementType", SquadsEndMovementType);
Expand All @@ -61,7 +55,6 @@ end
Controls.AlertOnArrivalRadioButton:RegisterCheckHandler(HandleAlertOnArrivalRadioButton);

function HandleWakeOnUnitArrivalRadioButton()
print("HandleWakeOnUnitArrivalRadioButton")
if SquadsEndMovementType ~= 1 then
SquadsEndMovementType = 1;
LuaEvents.SQUADS_OPTIONS_CHANGED("SquadsEndMovementType", SquadsEndMovementType);
Expand All @@ -70,7 +63,6 @@ end
Controls.WakeOnUnitArrivalRadioButton:RegisterCheckHandler(HandleWakeOnUnitArrivalRadioButton);

function HandleWakeOnSquadArrivalRadioButton()
print("HandleWakeOnSquadArrivalRadioButton")
if SquadsEndMovementType ~= 2 then
SquadsEndMovementType = 2;
LuaEvents.SQUADS_OPTIONS_CHANGED("SquadsEndMovementType", SquadsEndMovementType);
Expand All @@ -80,25 +72,8 @@ Controls.WakeOnSquadArrivalRadioButton:RegisterCheckHandler(HandleWakeOnSquadArr

-- Options Logic
function SquadsOptionChanged(optionKey, newValue)
if optionKey == "HighlightSquadUnits" then
Controls.HighlightSquadUnitsCheckBox:SetCheck(newValue);
print("Setting highlight squad units checkbox to ", newValue);
elseif optionKey == "ShowSquadNumberUnderFlag" then
Controls.FlagsNumberCheckBox:SetCheck(newValue);
print("Setting FlagsNumberCheckBox checkbox to ", newValue);
elseif optionKey == "SquadsEndMovementType" then
print("Setting SquadsEndMovementType to ", newValue);
if newValue == 0 then
Controls.AlertOnArrivalRadioButton:SetCheck(true);
elseif newValue == 1 then
Controls.WakeOnUnitArrivalRadioButton:SetCheck(true);
elseif newValue == 2 then
Controls.WakeOnSquadArrivalRadioButton:SetCheck(true);
end
end
SquadsOptions.SetValue(optionKey, newValue);
end

LuaEvents.SQUADS_OPTIONS_CHANGED.Add(SquadsOptionChanged);

-- Load Saved Options
Expand All @@ -108,15 +83,27 @@ if _hsu ~= nil then
HighlightSquadUnits = _hsu == 1;
end
LuaEvents.SQUADS_OPTIONS_CHANGED("HighlightSquadUnits", HighlightSquadUnits)
Controls.HighlightSquadUnitsCheckBox:SetCheck(HighlightSquadUnits);

local _ssnuf = SquadsOptions.GetValue("ShowSquadNumberUnderFlag");
if _ssnuf ~= nil then
ShowSquadNumberUnderFlag = _ssnuf == 1;
end
LuaEvents.SQUADS_OPTIONS_CHANGED("ShowSquadNumberUnderFlag", ShowSquadNumberUnderFlag)
Controls.FlagsNumberCheckBox:SetCheck(ShowSquadNumberUnderFlag);

local _semt = SquadsOptions.GetValue("SquadsEndMovementType");
if _semt ~= nil then
SquadsEndMovementType = _semt;
end
LuaEvents.SQUADS_OPTIONS_CHANGED("SquadsEndMovementType", SquadsEndMovementType)
LuaEvents.SQUADS_OPTIONS_CHANGED("SquadsEndMovementType", SquadsEndMovementType)
print("loaded the following value for SquadsEndMovementType: ", SquadsEndMovementType);
if SquadsEndMovementType == 0 then
Controls.AlertOnArrivalRadioButton:SetCheck(true);
elseif SquadsEndMovementType == 1 then
Controls.WakeOnUnitArrivalRadioButton:SetCheck(true);
elseif SquadsEndMovementType == 2 then
Controls.WakeOnSquadArrivalRadioButton:SetCheck(true);
end

print('Loaded SquadsOptions.lua')

0 comments on commit c0b2b16

Please sign in to comment.