Skip to content

Commit c9f3bd9

Browse files
committed
Full rewrite for how gossip frame dialogs are handled, including support for numpad buttons. Should reduce taint issues
1 parent 1db6ace commit c9f3bd9

2 files changed

Lines changed: 80 additions & 35 deletions

File tree

main.lua

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ local defaultPopupBlacklist = { -- If a popup dialog contains one of these strin
1414
AREA_SPIRIT_HEAL = true, -- Prevents cancelling the resurrection
1515
TOO_MANY_LUA_ERRORS = true,
1616
END_BOUND_TRADEABLE = true, EQUIP_BIND_TRADEABLE = true, -- Probably quite reasonable to make the user click on this one
17-
ADDON_ACTION_FORBIDDEN = true, -- Don't disable and reload UI on errors
17+
ADDON_ACTION_FORBIDDEN = true, -- Don't disable and reload UI on errors
1818
CONFIRM_LEAVE_RESTRICTED_CHALLENGE_MODE = true,
1919
WARN_LEAVE_RESTRICTED_CHALLENGE_MODE = true,
2020
}
@@ -69,7 +69,9 @@ function DialogKey:OnInitialize()
6969
self:InitMainProxyFrame()
7070

7171
self:SecureHook("QuestInfoItem_OnClick", "SelectItemReward")
72-
self:SecureHook(GossipFrame, "Update", "OnGossipFrameUpdate")
72+
GossipFrame.GreetingPanel.ScrollBox:RegisterCallback("OnAcquiredFrame", self.OnGossipFrameAcquired, self)
73+
GossipFrame.GreetingPanel.ScrollBox:RegisterCallback("OnReleasedFrame", self.OnGossipFrameReleased, self)
74+
GossipFrame.GreetingPanel.ScrollBox:RegisterCallback(ScrollBoxListMixin.Event.OnDataProviderReassigned, self.OnGossipDataProviderChange, self)
7375

7476
ns:RegisterOptions()
7577

@@ -216,45 +218,93 @@ function DialogKey:OnSpecFrameHide()
216218
self.specButtons = {}
217219
end
218220

219-
--- @param GossipFrame GossipFrame
220-
function DialogKey:OnGossipFrameUpdate(GossipFrame)
221+
function DialogKey:OnGossipDataProviderChange()
222+
self.frames = {}
223+
self.orderedGossipFrames = {}
221224
local scrollbox = GossipFrame.GreetingPanel.ScrollBox
222-
223-
self.frames = {};
224225
local n = 1
225-
for _, frame in scrollbox:EnumerateFrames() do
226-
local data = frame.GetElementData and frame:GetElementData()
226+
for _, elementData in scrollbox:GetDataProvider():Enumerate() do
227227
local tag
228-
if GOSSIP_BUTTON_TYPE_OPTION == data.buttonType then
228+
if GOSSIP_BUTTON_TYPE_OPTION == elementData.buttonType then
229229
tag = "name"
230-
elseif GOSSIP_BUTTON_TYPE_AVAILABLE_QUEST == data.buttonType then
230+
elseif GOSSIP_BUTTON_TYPE_AVAILABLE_QUEST == elementData.buttonType then
231231
tag = "title"
232-
elseif GOSSIP_BUTTON_TYPE_ACTIVE_QUEST == data.buttonType and (data.info.isComplete or not self.db.ignoreInProgressQuests) then
232+
elseif GOSSIP_BUTTON_TYPE_ACTIVE_QUEST == elementData.buttonType and (elementData.info.isComplete or not self.db.ignoreInProgressQuests) then
233233
tag = "title"
234234
end
235235
if tag then
236-
if self.db.numKeysForGossip then
237-
local oldText = data.info[tag]
238-
if data.info.flags and FlagsUtil.IsSet(data.info.flags, Enum.GossipOptionRecFlags.QuestLabelPrepend) then
236+
self.orderedGossipFrames[elementData] = n
237+
if n <= 10 then
238+
local info = elementData.info
239+
local oldText = info[tag]
240+
if info.flags and FlagsUtil.IsSet(info.flags, Enum.GossipOptionRecFlags.QuestLabelPrepend) then
239241
oldText = GOSSIP_QUEST_OPTION_PREPEND:format(oldText);
240242
end
241-
local newText = (n % 10) .. ". " .. (oldText:match("^%d. (.+)$") or oldText)
242-
if self.db.riskyNumKeysForGossip then
243-
data.info[tag] = newText -- this may not be safe, but it looks like the only somewhat reliable way to ensure the scrollbar is enabled when needed
243+
if info.isIgnored then
244+
oldText = IGNORED_QUEST_DISPLAY:format(oldText);
245+
elseif info.isTrivial then
246+
oldText = TRIVIAL_QUEST_DISPLAY:format(oldText);
244247
end
245-
frame:SetText(newText)
246-
frame:SetHeight(frame:GetFontString():GetHeight() + 2)
248+
local newText = (n % 10) .. ". " .. (oldText:match("^%d. (.+)$") or oldText)
249+
250+
elementData.info.DialogKeyNumy_Text = newText
247251
end
248-
self.frames[n] = frame
252+
249253
n = n + 1
250254
end
251-
if n > 10 then break end
255+
256+
local calculatorFrame
257+
if elementData.titleOptionButton then
258+
calculatorFrame = elementData.titleOptionButton
259+
elseif elementData.availableQuestButton then
260+
calculatorFrame = elementData.availableQuestButton
261+
elseif elementData.activeQuestButton then
262+
calculatorFrame = elementData.activeQuestButton
263+
end
264+
if calculatorFrame and not calculatorFrame.DialogKeyNumy_Hooked then
265+
hooksecurefunc(calculatorFrame, 'Setup', function(_, info)
266+
if info.DialogKeyNumy_Text then
267+
calculatorFrame:SetTextAndResize(info.DialogKeyNumy_Text)
268+
end
269+
end)
270+
calculatorFrame.DialogKeyNumy_Hooked = true
271+
end
252272
end
253-
--- @type ScrollBoxListLinearViewMixin
254-
local view = scrollbox:GetView()
255-
view:Layout()
256-
if self.db.riskyNumKeysForGossip then
257-
scrollbox:ScrollIncrease() -- force the scrollbar to show if needed
273+
end
274+
275+
--- @param frame GossipTitleButtonTemplate
276+
--- @param elementData table
277+
function DialogKey:OnGossipFrameAcquired(frame, elementData)
278+
if not self.db.numKeysForGossip then return; end
279+
280+
local n = self.orderedGossipFrames[elementData]
281+
local newText = elementData.info and elementData.info.DialogKeyNumy_Text
282+
283+
if not n or n > 10 or not newText then return end
284+
285+
self.frames[n] = frame
286+
frame:SetTextAndResize(newText)
287+
288+
if not frame.DialogKeyNumy_Text then
289+
--- @param f GossipTitleButtonTemplate
290+
local function onSetText(f, text)
291+
local savedText = f.DialogKeyNumy_Text
292+
if text == savedText or not savedText or savedText == "" then return end
293+
294+
f:SetTextAndResize(savedText)
295+
end
296+
hooksecurefunc(frame, 'SetText', onSetText)
297+
hooksecurefunc(frame, 'SetFormattedText', function(f, format, ...)
298+
local text = format:format(...)
299+
onSetText(f, text)
300+
end)
301+
end
302+
frame.DialogKeyNumy_Text = newText
303+
end
304+
305+
function DialogKey:OnGossipFrameReleased(frame)
306+
if frame.DialogKeyNumy_Text then
307+
frame.DialogKeyNumy_Text = ""
258308
end
259309
end
260310

@@ -455,7 +505,10 @@ function DialogKey:HandleKey(key)
455505
if not InCombatLockdown() then self.frame:SetPropagateKeyboardInput(true) end
456506
local doAction = (key == self.db.keys[1] or key == self.db.keys[2])
457507
local keynum = doAction and 1 or tonumber(key)
458-
if key == "0" then
508+
if key:match("^NUMPAD") then
509+
keynum = tonumber((key:gsub("NUMPAD", "")))
510+
end
511+
if key == "0" or key == "NUMPAD0" then
459512
keynum = 10
460513
end
461514
if not doAction and not keynum then return end

options.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ ns.defaultOptions = {
1818
--- @type table<string, number> # [frameName] = priority
1919
customFrames = {},
2020
numKeysForGossip = true,
21-
riskyNumKeysForGossip = true,
2221
numKeysForQuestRewards = true,
2322
dontClickSummons = true,
2423
dontClickDuels = true,
@@ -259,13 +258,6 @@ function ns:GetOptionsTable()
259258
desc = "Use the number keys (1 -> 0) to select Gossip options or Quests from an NPC dialog window",
260259
descStyle = "inline", width = "full", type = "toggle",
261260
},
262-
riskyNumKeysForGossip = {
263-
order = increment(),
264-
name = wrapName("Number keys for Gossip - Risky"),
265-
disabled = function() return not db.numKeysForGossip end,
266-
desc = "Ensure scrollbar is enabled if the text becomes too long. This may taint objective frame buttons. If you encounter issues, just disable this option.",
267-
descStyle = "inline", width = "full", type = "toggle",
268-
},
269261
numKeysForQuestRewards = {
270262
order = increment(),
271263
name = wrapName("Number keys for Quest Rewards"),

0 commit comments

Comments
 (0)