Skip to content

Commit bc2a587

Browse files
committed
Custom Watchlist frames are now sortable, frames higher on the list will always be clicked first when multiple frames are visible
1 parent aa95d63 commit bc2a587

File tree

2 files changed

+492
-267
lines changed

2 files changed

+492
-267
lines changed

main.lua

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ DialogKey.activeOverrideBindings = {}
4949
function DialogKey:OnInitialize()
5050
DialogKeyNumyDB = DialogKeyNumyDB or {}
5151
self.db = DialogKeyNumyDB
52-
for k, v in pairs(ns.defaultOptions) do
53-
if self.db[k] == nil then self.db[k] = v end
54-
end
52+
ns:InitDB(self)
5553

5654
self:InitGlowFrame()
5755

@@ -66,10 +64,7 @@ function DialogKey:OnInitialize()
6664
self:SecureHook("QuestInfoItem_OnClick", "SelectItemReward")
6765
self:SecureHook(GossipFrame, "Update", "OnGossipFrameUpdate")
6866

69-
-- interfaceOptions defined in `options.lua`
70-
local configPanelName = 'DialogKey - Numy Edition'
71-
LibStub("AceConfig-3.0"):RegisterOptionsTable(configPanelName, ns.interfaceOptions)
72-
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(configPanelName)
67+
ns:RegisterOptions()
7368

7469
_G.SLASH_DIALOGKEY1 = '/dialogkey'
7570
_G.SLASH_DIALOGKEY2 = '/dkey'
@@ -81,7 +76,7 @@ function DialogKey:OnInitialize()
8176
elseif func == 'remove' then
8277
self:RemoveFrame(args)
8378
else
84-
Settings.OpenToCategory(configPanelName)
79+
Settings.OpenToCategory(ns.configPanelName)
8580
end
8681
end
8782
end
@@ -225,7 +220,7 @@ end
225220

226221
--- @return Button|nil
227222
function DialogKey:GetFirstVisibleCustomFrame()
228-
for frameName, _ in pairs(self.db.customFrames) do
223+
for _, frameName in ipairs(ns.orderedCustomFrames) do
229224
local frame = self:GetFrameByName(frameName)
230225
if frame and frame:IsVisible() and frame:IsObjectType('Button') and self:GuardDisabled(frame) then
231226
return frame ---@diagnostic disable-line: return-type-mismatch
@@ -553,6 +548,9 @@ function DialogKey:EnumerateGossips(isGossipFrame)
553548
end
554549

555550
-- Glow Functions --
551+
--- @param frame Frame
552+
--- @param speedModifier number # increasing this number will speed up the fade out of the glow
553+
--- @param forceShow boolean # if true, the glow will be shown regardless of the showGlow setting
556554
function DialogKey:Glow(frame, speedModifier, forceShow)
557555
if self.db.showGlow or forceShow then
558556
self.glowFrame:SetAllPoints(frame)
@@ -590,7 +588,12 @@ function DialogKey:AddFrame(frameName)
590588
return
591589
end
592590

593-
self.db.customFrames[frameName] = true
591+
if self.db.customFrames[frameName] then
592+
self:print("Frame is already on the watchlist:", frameName)
593+
self:Glow(frame, 0.25, true)
594+
return
595+
end
596+
ns:AddToWatchlist(frameName)
594597
self:Glow(frame, 0.25, true)
595598
self:print("Added frame:", frameName, ". Remove it again with /dialogkey remove; or in the options UI.")
596599
end
@@ -607,14 +610,20 @@ function DialogKey:RemoveFrame(frameName)
607610
self:print("No clickable frame found under your mouse. Try /fstack and find the name of the frame, and remove it manually with /dialogkey remove <frameName>")
608611
return
609612
end
613+
local index = self.db.customFrames[frameName]
614+
if not index then
615+
self:print("The clickable frame under your mouse isn't on the custom watchlist:", frameName)
616+
self:Glow(frame, 0.25, true)
617+
return
618+
end
610619

611-
self.db.customFrames[frameName] = nil
620+
ns:RemoveFromWatchlist(frameName)
612621
self:Glow(frame, 0.25, true)
613622
self:print("Removed frame:", frameName)
614623
end
615624

616625
--- Returns the first clickable frame that has mouse focus
617-
--- @return ScriptRegion?, string? # The frame under the cursor, and its name; or nil
626+
--- @return Frame?, string? # The frame under the cursor, and its name; or nil
618627
function DialogKey:GetFrameUnderCursor()
619628
for _, frame in ipairs(GetMouseFoci()) do
620629
if

0 commit comments

Comments
 (0)