Skip to content

Commit adef8ec

Browse files
committed
Preserve initial state when re-opening / resizing
Because changing UI scale values causes the popup to re-open, it would previously overwrite the "initial" values. So changing a setting and then pressing "Cancel" would not actually discard the changes, but save them instead. The `savedState` can now be passed to `OpenOptionsPopup()` in order to have the initial values persist and be restored upon cancellation.
1 parent 26755bd commit adef8ec

1 file changed

Lines changed: 58 additions & 51 deletions

File tree

src/Modules/Main.lua

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,40 @@ function main:ChangeUserPath(newUserPath, ignoreBuild)
814814
self:LoadSettings(ignoreBuild)
815815
self:LoadSharedItems()
816816
end
817-
818-
function main:OpenOptionsPopup()
817+
--- Opens the popup for the "Options" menu
818+
--- @param savedState table|nil optional passing of saved values, in case of reopening `{nodePowerTheme, colorPositive, ...}`
819+
function main:OpenOptionsPopup(savedState)
819820
local controls = { }
821+
822+
-- Check for `savedState` or assign initial values
823+
-- NOTE: update both this and the `controls.cancel` section below, when adding new options
824+
savedState = savedState or {
825+
nodePowerTheme = self.nodePowerTheme,
826+
colorPositive = self.colorPositive,
827+
colorNegative = self.colorNegative,
828+
colorHighlight = self.colorHighlight,
829+
showThousandsSeparators = self.showThousandsSeparators,
830+
thousandsSeparator = self.thousandsSeparator,
831+
decimalSeparator = self.decimalSeparator,
832+
showTitlebarName = self.showTitlebarName,
833+
betaTest = self.betaTest,
834+
edgeSearchHighlight = self.edgeSearchHighlight,
835+
defaultGemQuality = self.defaultGemQuality or 0,
836+
defaultCharLevel = self.defaultCharLevel or 1,
837+
defaultItemAffixQuality = self.defaultItemAffixQuality or 0.5,
838+
showWarnings = self.showWarnings,
839+
slotOnlyTooltips = self.slotOnlyTooltips,
840+
migrateEldritchImplicits = self.migrateEldritchImplicits,
841+
notSupportedModTooltips = self.notSupportedModTooltips,
842+
invertSliderScrollDirection = self.invertSliderScrollDirection,
843+
disableDevAutoSave = self.disableDevAutoSave,
844+
showPublicBuilds = self.showPublicBuilds,
845+
showFlavourText = self.showFlavourText,
846+
showAnimations = self.showAnimations,
847+
showAllItemAffixes = self.showAllItemAffixes,
848+
dpiScaleOverridePercent = self.dpiScaleOverridePercent
849+
}
850+
820851
-- NOTE: Height needs to be adjusted if more menu options are added
821852
local oneColumnHeightReq = 850 -- Min height required to not split menu into two columns
822853
local columnWidth = 600
@@ -897,7 +928,7 @@ function main:OpenOptionsPopup()
897928
SetDPIScaleOverridePercent(value.percent)
898929
self.screenW, self.screenH = GetVirtualScreenSize() -- refresh screen size immediately
899930
self:ClosePopup()
900-
self:OpenOptionsPopup()
931+
self:OpenOptionsPopup(savedState)
901932
end)
902933
controls.dpiScaleOverrideLabel = new("LabelControl", { "RIGHT", controls.dpiScaleOverride, "LEFT" }, { defaultLabelSpacingPx, 0, 0, 16 }, "^7UI scaling override:")
903934
controls.dpiScaleOverride.tooltipText = "Overrides Windows DPI scaling inside Path of Building.\nChoose a percentage between 100% and 250% or revert to the system default."
@@ -1100,30 +1131,6 @@ function main:OpenOptionsPopup()
11001131
controls.showFlavourText.state = self.showFlavourText
11011132
controls.showAnimations.state = self.showAnimations
11021133
controls.showAllItemAffixes.state = self.showAllItemAffixes
1103-
local initialNodePowerTheme = self.nodePowerTheme
1104-
local initialColorPositive = self.colorPositive
1105-
local initialColorNegative = self.colorNegative
1106-
local initialColorHighlight = self.colorHighlight
1107-
local initialThousandsSeparatorDisplay = self.showThousandsSeparators
1108-
local initialTitlebarName = self.showTitlebarName
1109-
local initialThousandsSeparator = self.thousandsSeparator
1110-
local initialDecimalSeparator = self.decimalSeparator
1111-
local initialBetaTest = self.betaTest
1112-
local initialEdgeSearchHighlight = self.edgeSearchHighlight
1113-
local initialDefaultGemQuality = self.defaultGemQuality or 0
1114-
local initialDefaultCharLevel = self.defaultCharLevel or 1
1115-
local initialDefaultItemAffixQuality = self.defaultItemAffixQuality or 0.5
1116-
local initialShowWarnings = self.showWarnings
1117-
local initialSlotOnlyTooltips = self.slotOnlyTooltips
1118-
local initialMigrateEldritchImplicits = self.migrateEldritchImplicits
1119-
local initialNotSupportedModTooltips = self.notSupportedModTooltips
1120-
local initialInvertSliderScrollDirection = self.invertSliderScrollDirection
1121-
local initialDisableDevAutoSave = self.disableDevAutoSave
1122-
local initialShowPublicBuilds = self.showPublicBuilds
1123-
local initialShowFlavourText = self.showFlavourText
1124-
local initialShowAnimations = self.showAnimations
1125-
local initialShowAllItemAffixes = self.showAllItemAffixes
1126-
local initialDpiScaleOverridePercent = self.dpiScaleOverridePercent
11271134

11281135
-- Adjust height in case of two-column layout
11291136
currentY = m_max(leftColumnMaxY, currentY)
@@ -1158,33 +1165,33 @@ function main:OpenOptionsPopup()
11581165
main:SaveSettings()
11591166
end)
11601167
controls.cancel = new("ButtonControl", { "BOTTOM", nil, "BOTTOM" }, {45, -10, 80, 20}, "Cancel", function()
1161-
self.nodePowerTheme = initialNodePowerTheme
1162-
self.colorPositive = initialColorPositive
1168+
self.nodePowerTheme = savedState.nodePowerTheme
1169+
self.colorPositive = savedState.colorPositive
11631170
updateColorCode("POSITIVE", self.colorPositive)
1164-
self.colorNegative = initialColorNegative
1171+
self.colorNegative = savedState.colorNegative
11651172
updateColorCode("NEGATIVE", self.colorNegative)
1166-
self.colorHighlight = initialColorHighlight
1173+
self.colorHighlight = savedState.colorHighlight
11671174
updateColorCode("HIGHLIGHT", self.colorHighlight)
1168-
self.showThousandsSeparators = initialThousandsSeparatorDisplay
1169-
self.thousandsSeparator = initialThousandsSeparator
1170-
self.decimalSeparator = initialDecimalSeparator
1171-
self.showTitlebarName = initialTitlebarName
1172-
self.betaTest = initialBetaTest
1173-
self.edgeSearchHighlight = initialEdgeSearchHighlight
1174-
self.defaultGemQuality = initialDefaultGemQuality
1175-
self.defaultCharLevel = initialDefaultCharLevel
1176-
self.defaultItemAffixQuality = initialDefaultItemAffixQuality
1177-
self.showWarnings = initialShowWarnings
1178-
self.slotOnlyTooltips = initialSlotOnlyTooltips
1179-
self.migrateEldritchImplicits = initialMigrateEldritchImplicits
1180-
self.notSupportedModTooltips = initialNotSupportedModTooltips
1181-
self.invertSliderScrollDirection = initialInvertSliderScrollDirection
1182-
self.disableDevAutoSave = initialDisableDevAutoSave
1183-
self.showPublicBuilds = initialShowPublicBuilds
1184-
self.showFlavourText = initialShowFlavourText
1185-
self.showAnimations = initialShowAnimations
1186-
self.showAllItemAffixes = initialShowAllItemAffixes
1187-
self.dpiScaleOverridePercent = initialDpiScaleOverridePercent
1175+
self.showThousandsSeparators = savedState.chousandsSeparatorDisplay
1176+
self.thousandsSeparator = savedState.thousandsSeparator
1177+
self.decimalSeparator = savedState.decimalSeparator
1178+
self.showTitlebarName = savedState.titlebarName
1179+
self.betaTest = savedState.betaTest
1180+
self.edgeSearchHighlight = savedState.edgeSearchHighlight
1181+
self.defaultGemQuality = savedState.defaultGemQuality
1182+
self.defaultCharLevel = savedState.defaultCharLevel
1183+
self.defaultItemAffixQuality = savedState.defaultItemAffixQuality
1184+
self.showWarnings = savedState.showWarnings
1185+
self.slotOnlyTooltips = savedState.slotOnlyTooltips
1186+
self.migrateEldritchImplicits = savedState.migrateEldritchImplicits
1187+
self.notSupportedModTooltips = savedState.notSupportedModTooltips
1188+
self.invertSliderScrollDirection = savedState.invertSliderScrollDirection
1189+
self.disableDevAutoSave = savedState.disableDevAutoSave
1190+
self.showPublicBuilds = savedState.showPublicBuilds
1191+
self.showFlavourText = savedState.showFlavourText
1192+
self.showAnimations = savedState.showAnimations
1193+
self.showAllItemAffixes = savedState.showAllItemAffixes
1194+
self.dpiScaleOverridePercent = savedState.dpiScaleOverridePercent
11881195
SetDPIScaleOverridePercent(self.dpiScaleOverridePercent)
11891196
main:ClosePopup()
11901197
end)

0 commit comments

Comments
 (0)