Remember user selections across frame instances
This commit is contained in:
parent
5b36bfdb1b
commit
c27a6cd033
3 changed files with 39 additions and 6 deletions
24
UI.lua
24
UI.lua
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue