Remember user selections across frame instances
This commit is contained in:
parent
5b36bfdb1b
commit
c27a6cd033
3 changed files with 39 additions and 6 deletions
20
Core.lua
20
Core.lua
|
|
@ -4,6 +4,7 @@
|
||||||
AltSystem = AltSystem or {}
|
AltSystem = AltSystem or {}
|
||||||
AltSystem.State = {
|
AltSystem.State = {
|
||||||
selectedSkillIndex = 1,
|
selectedSkillIndex = 1,
|
||||||
|
selectedSkillName = nil, -- skill name used to restore selection across sessions
|
||||||
selectedItemIndex = 1, -- 1 = No item
|
selectedItemIndex = 1, -- 1 = No item
|
||||||
selectedDefenseIndex = 1, -- 1 = Base armor
|
selectedDefenseIndex = 1, -- 1 = Base armor
|
||||||
shieldEnabled = false,
|
shieldEnabled = false,
|
||||||
|
|
@ -43,6 +44,18 @@ function AltSystem:Init()
|
||||||
if AltSystemDB.petSummonEnabled ~= nil then
|
if AltSystemDB.petSummonEnabled ~= nil then
|
||||||
AltSystem.State.petSummonEnabled = AltSystemDB.petSummonEnabled
|
AltSystem.State.petSummonEnabled = AltSystemDB.petSummonEnabled
|
||||||
end
|
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
|
-- Register slash command /altsystem
|
||||||
SLASH_ALTSYSTEM1 = "/altsystem"
|
SLASH_ALTSYSTEM1 = "/altsystem"
|
||||||
|
|
@ -58,8 +71,15 @@ function AltSystem:Init()
|
||||||
AltSystemDB.announceEnabled = AltSystem.State.announceEnabled
|
AltSystemDB.announceEnabled = AltSystem.State.announceEnabled
|
||||||
AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex
|
AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex
|
||||||
AltSystemDB.petSummonEnabled = AltSystem.State.petSummonEnabled
|
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)
|
end)
|
||||||
|
|
||||||
|
-- Build the main frame now that saved variables are loaded
|
||||||
|
AltSystem:CreateMainFrame()
|
||||||
|
|
||||||
print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.")
|
print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
24
UI.lua
24
UI.lua
|
|
@ -90,6 +90,7 @@ function AltSystem:CreateMainFrame()
|
||||||
AltSystem.State.selectedSkillIndex,
|
AltSystem.State.selectedSkillIndex,
|
||||||
function(index)
|
function(index)
|
||||||
AltSystem.State.selectedSkillIndex = index
|
AltSystem.State.selectedSkillIndex = index
|
||||||
|
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[index] and AltSystem.Data.Skills[index].name or nil
|
||||||
UpdateSkillWarning(index)
|
UpdateSkillWarning(index)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -314,13 +315,24 @@ end
|
||||||
function AltSystem:RefreshSkillDropdown()
|
function AltSystem:RefreshSkillDropdown()
|
||||||
AltSystem.Data:RefreshSkills()
|
AltSystem.Data:RefreshSkills()
|
||||||
|
|
||||||
-- Reset selection to 1 (Base roll) since the skill list may have changed
|
-- Try to restore the previously selected skill by name; fall back to 1 (Base roll)
|
||||||
AltSystem.State.selectedSkillIndex = 1
|
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
|
if AltSystem.SetSkillIndex then
|
||||||
AltSystem.SetSkillIndex(1)
|
AltSystem.SetSkillIndex(newIndex)
|
||||||
end
|
end
|
||||||
if AltSystem.UpdateSkillWarning then
|
if AltSystem.UpdateSkillWarning then
|
||||||
AltSystem.UpdateSkillWarning(1)
|
AltSystem.UpdateSkillWarning(newIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Rebuild the dropdown menu with the new skill list
|
-- 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) return data == AltSystem.State.selectedSkillIndex end,
|
||||||
function(data)
|
function(data)
|
||||||
AltSystem.State.selectedSkillIndex = data
|
AltSystem.State.selectedSkillIndex = data
|
||||||
|
AltSystem.State.selectedSkillName = AltSystem.Data.Skills[data] and AltSystem.Data.Skills[data].name or nil
|
||||||
if AltSystem.SetSkillIndex then
|
if AltSystem.SetSkillIndex then
|
||||||
AltSystem.SetSkillIndex(data)
|
AltSystem.SetSkillIndex(data)
|
||||||
end
|
end
|
||||||
|
|
@ -347,5 +360,4 @@ function AltSystem:RefreshSkillDropdown()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create the frame on file load so it's ready when Init runs
|
-- Frame is created by AltSystem:Init() in Core.lua, after saved variables are loaded
|
||||||
AltSystem:CreateMainFrame()
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
- Fixed an issue where the wrong rolls were displayed when in a large enough group
|
||||||
Loading…
Add table
Add a link
Reference in a new issue