Remember user selections across frame instances

This commit is contained in:
Gonçalo Correia 2026-05-11 13:59:44 +01:00
parent 5b36bfdb1b
commit c27a6cd033
3 changed files with 39 additions and 6 deletions

View file

@ -4,6 +4,7 @@
AltSystem = AltSystem or {}
AltSystem.State = {
selectedSkillIndex = 1,
selectedSkillName = nil, -- skill name used to restore selection across sessions
selectedItemIndex = 1, -- 1 = No item
selectedDefenseIndex = 1, -- 1 = Base armor
shieldEnabled = false,
@ -43,6 +44,18 @@ function AltSystem:Init()
if AltSystemDB.petSummonEnabled ~= nil then
AltSystem.State.petSummonEnabled = AltSystemDB.petSummonEnabled
end
if AltSystemDB.shieldEnabled ~= nil then
AltSystem.State.shieldEnabled = AltSystemDB.shieldEnabled
end
if AltSystemDB.selectedItemIndex then
AltSystem.State.selectedItemIndex = AltSystemDB.selectedItemIndex
end
if AltSystemDB.selectedDefenseIndex then
AltSystem.State.selectedDefenseIndex = AltSystemDB.selectedDefenseIndex
end
if AltSystemDB.selectedSkillName then
AltSystem.State.selectedSkillName = AltSystemDB.selectedSkillName
end
-- Register slash command /altsystem
SLASH_ALTSYSTEM1 = "/altsystem"
@ -58,8 +71,15 @@ function AltSystem:Init()
AltSystemDB.announceEnabled = AltSystem.State.announceEnabled
AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex
AltSystemDB.petSummonEnabled = AltSystem.State.petSummonEnabled
AltSystemDB.shieldEnabled = AltSystem.State.shieldEnabled
AltSystemDB.selectedItemIndex = AltSystem.State.selectedItemIndex
AltSystemDB.selectedDefenseIndex = AltSystem.State.selectedDefenseIndex
AltSystemDB.selectedSkillName = AltSystem.State.selectedSkillName
end)
-- Build the main frame now that saved variables are loaded
AltSystem:CreateMainFrame()
print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.")
end

24
UI.lua
View file

@ -90,6 +90,7 @@ function AltSystem:CreateMainFrame()
AltSystem.State.selectedSkillIndex,
function(index)
AltSystem.State.selectedSkillIndex = index
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[index] and AltSystem.Data.Skills[index].name or nil
UpdateSkillWarning(index)
end)
@ -314,13 +315,24 @@ end
function AltSystem:RefreshSkillDropdown()
AltSystem.Data:RefreshSkills()
-- Reset selection to 1 (Base roll) since the skill list may have changed
AltSystem.State.selectedSkillIndex = 1
-- Try to restore the previously selected skill by name; fall back to 1 (Base roll)
local newIndex = 1
local savedName = AltSystem.State.selectedSkillName
if savedName then
for i, skill in ipairs(AltSystem.Data.Skills) do
if skill.name == savedName then
newIndex = i
break
end
end
end
AltSystem.State.selectedSkillIndex = newIndex
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[newIndex] and AltSystem.Data.Skills[newIndex].name or nil
if AltSystem.SetSkillIndex then
AltSystem.SetSkillIndex(1)
AltSystem.SetSkillIndex(newIndex)
end
if AltSystem.UpdateSkillWarning then
AltSystem.UpdateSkillWarning(1)
AltSystem.UpdateSkillWarning(newIndex)
end
-- Rebuild the dropdown menu with the new skill list
@ -333,6 +345,7 @@ function AltSystem:RefreshSkillDropdown()
function(data) return data == AltSystem.State.selectedSkillIndex end,
function(data)
AltSystem.State.selectedSkillIndex = data
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[data] and AltSystem.Data.Skills[data].name or nil
if AltSystem.SetSkillIndex then
AltSystem.SetSkillIndex(data)
end
@ -347,5 +360,4 @@ function AltSystem:RefreshSkillDropdown()
end
end
-- Create the frame on file load so it's ready when Init runs
AltSystem:CreateMainFrame()
-- Frame is created by AltSystem:Init() in Core.lua, after saved variables are loaded

View file

@ -1 +1,2 @@
- The roll window now remembers all user selections (skill, item, armor type, shield, pet, announce and channel) across sessions
- Fixed an issue where the wrong rolls were displayed when in a large enough group