@@ -2,7 +2,7 @@ local name = ...
22--- @class DialogKeyNS
33local ns = select (2 , ... )
44
5- local GetMouseFoci = GetMouseFoci or function () return {GetMouseFocus ()} end
5+ local GetMouseFoci = GetMouseFoci or function () return { GetMouseFocus () } end
66local GetFrameMetatable = _G .GetFrameMetatable or function () return getmetatable (CreateFrame (' FRAME' )) end
77
88_G .DialogKeyNS = ns -- expose ourselves to the world :)
@@ -173,32 +173,29 @@ function DialogKey:OnPlayerChoiceHide()
173173 self .playerChoiceButtons = {}
174174end
175175
176- -- Thanks, [github]@mbattersby
177176-- Prefix list of GossipFrame options with 1., 2., 3. etc.
178- function DialogKey :OnGossipFrameUpdate (frame )
179- local dp = frame .GreetingPanel .ScrollBox :GetDataProvider ()
180-
181- if DialogKey .db .numKeysForGossip then
182- local n = 1
183- for _ , item in ipairs (dp .collection ) do
184- local tag
185- if item .buttonType == GOSSIP_BUTTON_TYPE_OPTION then
186- tag = " name"
187- elseif item .buttonType == GOSSIP_BUTTON_TYPE_ACTIVE_QUEST or
188- item .buttonType == GOSSIP_BUTTON_TYPE_AVAILABLE_QUEST then
189- tag = " title"
190- end
191-
192- if tag then
193- local dedup = item .info [tag ]:match (" ^%d+%. (.+)" ) or item .info [tag ]
194- item .info [tag ] = n % 10 .. " . " .. dedup
195- n = n + 1
196- end
197- if n > 10 then break end
177+ --- @param gossipFrame GossipFrame
178+ function DialogKey :OnGossipFrameUpdate (gossipFrame )
179+ if not self .db .numKeysForGossip then return end
180+ local scrollbox = gossipFrame .GreetingPanel .ScrollBox
181+
182+ local n = 1
183+ for _ , frame in scrollbox :EnumerateFrames () do
184+ local data = frame .GetElementData and frame .GetElementData ()
185+ local tag
186+ if data .buttonType == GOSSIP_BUTTON_TYPE_OPTION then
187+ tag = " name"
188+ elseif data .buttonType == GOSSIP_BUTTON_TYPE_ACTIVE_QUEST or data .buttonType == GOSSIP_BUTTON_TYPE_AVAILABLE_QUEST then
189+ tag = " title"
198190 end
191+ if tag then
192+ frame :SetText ((n % 10 ) .. " . " .. data .info [tag ])
193+ frame :SetHeight (frame :GetFontString ():GetHeight () + 2 )
194+ n = n + 1
195+ end
196+ if n > 10 then break end
199197 end
200-
201- frame .GreetingPanel .ScrollBox :SetDataProvider (dp )
198+ scrollbox :OnSizeChanged ()
202199end
203200
204201--- @return StaticPopupTemplate | nil
@@ -390,8 +387,8 @@ function DialogKey:AcquireProxyButton(frame)
390387 proxyButton :SetAttribute (" typerelease" , " click" )
391388 proxyButton :SetAttribute (" clickbutton" , frame )
392389 proxyButton :RegisterForClicks (" AnyUp" , " AnyDown" )
393- proxyButton :SetAttribute (" pressAndHoldAction" , " 1" )
394- proxyButton :HookScript (" OnClick" , function () self :Glow (frame ) end )
390+ proxyButton :SetAttribute (" pressAndHoldAction" , " 1" )
391+ proxyButton :HookScript (" OnClick" , function () self :Glow (frame ) end )
395392 proxyButton .name = proxyName
396393 proxyButton .target = frame
397394 self .proxyFrames [frame ] = proxyButton
453450function DialogKey :HandleKey (key )
454451 if self :ShouldIgnoreInput () then return end
455452
456- local doAction = (key == DialogKey .db .keys [1 ] or key == DialogKey .db .keys [2 ])
453+ local doAction = (key == self .db .keys [1 ] or key == self .db .keys [2 ])
457454 local keynum = doAction and 1 or tonumber (key )
458455 if key == " 0" then
459456 keynum = 10
@@ -465,15 +462,15 @@ function DialogKey:HandleKey(key)
465462 local popupFrame = self :GetFirstVisiblePopup ()
466463 local popupButton = popupFrame and self :GetPopupButton (popupFrame )
467464 if popupButton then
468- DialogKey .frame :SetPropagateKeyboardInput (true )
465+ self .frame :SetPropagateKeyboardInput (true )
469466 self :Glow (popupButton )
470467 return
471468 end
472469
473470 -- Crafting Orders
474471 local craftingOrderFrame = self :GetFirstVisibleCraftingOrderFrame ()
475472 if craftingOrderFrame then
476- DialogKey .frame :SetPropagateKeyboardInput (false )
473+ self .frame :SetPropagateKeyboardInput (false )
477474 self :Glow (craftingOrderFrame )
478475 craftingOrderFrame :Click ()
479476 return
@@ -482,51 +479,51 @@ function DialogKey:HandleKey(key)
482479 -- Custom Frames
483480 local customFrame = self :GetFirstVisibleCustomFrame ()
484481 if customFrame then
485- DialogKey .frame :SetPropagateKeyboardInput (true )
482+ self .frame :SetPropagateKeyboardInput (true )
486483 return
487484 end
488485
489486 -- Auction House
490- if DialogKey .db .postAuctions and AuctionHouseFrame and AuctionHouseFrame :IsVisible () then
487+ if self .db .postAuctions and AuctionHouseFrame and AuctionHouseFrame :IsVisible () then
491488 if AuctionHouseFrame .displayMode == AuctionHouseFrameDisplayMode .CommoditiesSell then
492- DialogKey .frame :SetPropagateKeyboardInput (false )
493- DialogKey :Glow (AuctionHouseFrame .CommoditiesSellFrame .PostButton )
489+ self .frame :SetPropagateKeyboardInput (false )
490+ self :Glow (AuctionHouseFrame .CommoditiesSellFrame .PostButton )
494491 AuctionHouseFrame .CommoditiesSellFrame :PostItem ()
495492 return
496493 elseif AuctionHouseFrame .displayMode == AuctionHouseFrameDisplayMode .ItemSell then
497- DialogKey .frame :SetPropagateKeyboardInput (false )
498- DialogKey :Glow (AuctionHouseFrame .ItemSellFrame .PostButton )
494+ self .frame :SetPropagateKeyboardInput (false )
495+ self :Glow (AuctionHouseFrame .ItemSellFrame .PostButton )
499496 AuctionHouseFrame .ItemSellFrame :PostItem ()
500497 return
501498 end
502499 end
503500
504501 -- Complete Quest
505502 if QuestFrameProgressPanel :IsVisible () then
506- DialogKey .frame :SetPropagateKeyboardInput (false )
507- if not QuestFrameCompleteButton :IsEnabled () and DialogKey .db .ignoreDisabledButtons then
503+ self .frame :SetPropagateKeyboardInput (false )
504+ if not QuestFrameCompleteButton :IsEnabled () and self .db .ignoreDisabledButtons then
508505 -- click "Cencel" button when "Complete" is disabled on progress panel
509- DialogKey :Glow (QuestFrameGoodbyeButton )
506+ self :Glow (QuestFrameGoodbyeButton )
510507 CloseQuest ()
511508 else
512- DialogKey :Glow (QuestFrameCompleteButton )
509+ self :Glow (QuestFrameCompleteButton )
513510 CompleteQuest ()
514511 end
515512 return
516513 -- Accept Quest
517514 elseif QuestFrameDetailPanel :IsVisible () then
518- DialogKey .frame :SetPropagateKeyboardInput (false )
519- DialogKey :Glow (QuestFrameAcceptButton )
515+ self .frame :SetPropagateKeyboardInput (false )
516+ self :Glow (QuestFrameAcceptButton )
520517 AcceptQuest ()
521518 return
522519 -- Take Quest Reward
523520 elseif QuestFrameRewardPanel :IsVisible () then
524- DialogKey .frame :SetPropagateKeyboardInput (false )
525- if DialogKey .itemChoice == - 1 and GetNumQuestChoices () > 1 then
521+ self .frame :SetPropagateKeyboardInput (false )
522+ if self .itemChoice == - 1 and GetNumQuestChoices () > 1 then
526523 QuestChooseRewardError ()
527524 else
528- DialogKey :Glow (QuestFrameCompleteQuestButton )
529- GetQuestReward (DialogKey .itemChoice )
525+ self :Glow (QuestFrameCompleteQuestButton )
526+ GetQuestReward (self .itemChoice )
530527 end
531528 return
532529 end
@@ -536,52 +533,52 @@ function DialogKey:HandleKey(key)
536533 if self .db .handlePlayerChoice and next (self .playerChoiceButtons ) and (doAction or self .db .numKeysForPlayerChoice ) then
537534 local button = self .playerChoiceButtons [keynum ]
538535 if button then
539- DialogKey .frame :SetPropagateKeyboardInput (false )
536+ self .frame :SetPropagateKeyboardInput (false )
540537 self :Glow (button )
541538 button :Click ()
542539 return
543540 end
544541 end
545542
546543 -- GossipFrame
547- if (doAction or DialogKey .db .numKeysForGossip ) and GossipFrame .GreetingPanel :IsVisible () then
548- while keynum and keynum > 0 and keynum <= # DialogKey .frames do
549- choice = DialogKey .frames [keynum ] and DialogKey .frames [keynum ].GetElementData and DialogKey .frames [keynum ].GetElementData ()
544+ if (doAction or self .db .numKeysForGossip ) and GossipFrame .GreetingPanel :IsVisible () then
545+ while keynum and keynum > 0 and keynum <= # self .frames do
546+ local choice = self .frames [keynum ] and self .frames [keynum ].GetElementData and self .frames [keynum ].GetElementData ()
550547 -- Skip grey quest (active but not completed) when pressing DialogKey
551- if doAction and choice and choice .info and choice .info .questID and choice .activeQuestButton and not choice .info .isComplete and DialogKey .db .ignoreDisabledButtons then
548+ if doAction and choice and choice .info and choice .info .questID and choice .activeQuestButton and not choice .info .isComplete and self .db .ignoreDisabledButtons then
552549 keynum = keynum + 1
553550 else
554- DialogKey .frame :SetPropagateKeyboardInput (false )
555- DialogKey :Glow (DialogKey .frames [keynum ])
556- DialogKey .frames [keynum ]:Click ()
551+ self .frame :SetPropagateKeyboardInput (false )
552+ self :Glow (self .frames [keynum ])
553+ self .frames [keynum ]:Click ()
557554 return
558555 end
559556 end
560557 end
561558
562559 -- QuestFrame
563- if (doAction or DialogKey .db .numKeysForGossip ) and QuestFrameGreetingPanel :IsVisible () and DialogKey .frame then
564- while keynum and keynum > 0 and keynum <= # DialogKey .frames do
565- local title , is_complete = GetActiveTitle (keynum )
566- if doAction and not is_complete and DialogKey .frames [keynum ].isActive == 1 and DialogKey .db .ignoreDisabledButtons then
560+ if (doAction or self .db .numKeysForGossip ) and QuestFrameGreetingPanel :IsVisible () and self .frame then
561+ while keynum and keynum > 0 and keynum <= # self .frames do
562+ local _ , is_complete = GetActiveTitle (keynum )
563+ if doAction and not is_complete and self .frames [keynum ].isActive == 1 and self .db .ignoreDisabledButtons then
567564 keynum = keynum + 1
568- if keynum > # DialogKey .frames then
565+ if keynum > # self .frames then
569566 doAction = false
570567 keynum = 1
571568 end
572569 else
573- DialogKey .frame :SetPropagateKeyboardInput (false )
574- DialogKey :Glow (DialogKey .frames [keynum ])
575- DialogKey .frames [keynum ]:Click ()
570+ self .frame :SetPropagateKeyboardInput (false )
571+ self :Glow (self .frames [keynum ])
572+ self .frames [keynum ]:Click ()
576573 return
577574 end
578575 end
579576 end
580577
581578 -- QuestReward Frame (select item)
582- if DialogKey .db .numKeysForQuestRewards and keynum and keynum <= GetNumQuestChoices () and QuestFrameRewardPanel :IsVisible () then
583- DialogKey .frame :SetPropagateKeyboardInput (false )
584- DialogKey .itemChoice = keynum
579+ if self .db .numKeysForQuestRewards and keynum and keynum <= GetNumQuestChoices () and QuestFrameRewardPanel :IsVisible () then
580+ self .frame :SetPropagateKeyboardInput (false )
581+ self .itemChoice = keynum
585582 GetClickFrame (" QuestInfoRewardsFrameQuestInfoItem" .. key ):Click ()
586583 end
587584end
591588function DialogKey :SelectItemReward ()
592589 for i = 1 , GetNumQuestChoices () do
593590 if GetClickFrame (" QuestInfoRewardsFrameQuestInfoItem" .. i ):IsMouseOver () then
594- DialogKey .itemChoice = i
591+ self .itemChoice = i
595592 break
596593 end
597594 end
@@ -602,61 +599,53 @@ end
602599function DialogKey :EnumerateGossips (isGossipFrame )
603600 if not ( QuestFrameGreetingPanel :IsVisible () or GossipFrame .GreetingPanel :IsVisible () ) then return end
604601
605- -- If anyone reading this comment is or knows someone on the WoW UI team, please send them this Addon and
606- -- show them this function and then please ask them to (politely) slap whoever decided that:
607- -- (1) ObjectPool's `activeObjects` *had* to be a dictionary
608- -- (2) :GetChildren() should return an unpacked list of the sub-objects instead of, you know, a Table.
609- -- :)
610- -- FuriousProgrammer
611- local tab = {}
612- DialogKey .frames = {}
602+ self .frames = {}
613603 if isGossipFrame then
614- for _ , v in pairs { GossipFrame .GreetingPanel .ScrollBox .ScrollTarget :GetChildren () } do
615- if v :GetObjectType () == " Button" and v :IsVisible () then
616- table.insert (DialogKey .frames , v )
604+ for _ , child in pairs { GossipFrame .GreetingPanel .ScrollBox .ScrollTarget :GetChildren () } do
605+ if child :GetObjectType () == " Button" and child :IsVisible () then
606+ table.insert (self .frames , child )
617607 end
618608 end
619609 else
620610 if QuestFrameGreetingPanel and QuestFrameGreetingPanel .titleButtonPool then
621611 for tab in QuestFrameGreetingPanel .titleButtonPool :EnumerateActive () do
622612 if tab :GetObjectType () == " Button" then
623- table.insert (DialogKey .frames , tab )
613+ table.insert (self .frames , tab )
624614 end
625615 end
626616 elseif QuestFrameGreetingPanel and not QuestFrameGreetingPanel .titleButtonPool then
627- local children = {QuestGreetingScrollChildFrame :GetChildren ()}
628- for i , c in ipairs (children ) do
629- if c :GetObjectType () == " Button" and c :IsVisible () then
630- table.insert (DialogKey .frames , c )
617+ for _ , child in ipairs ({ QuestGreetingScrollChildFrame :GetChildren () }) do
618+ if child :GetObjectType () == " Button" and child :IsVisible () then
619+ table.insert (self .frames , child )
631620 end
632621 end
633622 else
634623 return
635624 end
636625 end
637626
638- table.sort (DialogKey .frames , function (a ,b )
627+ table.sort (self .frames , function (a ,b )
639628 if a .GetOrderIndex then
640629 return a :GetOrderIndex () < b :GetOrderIndex ()
641630 else
642631 return a :GetTop () > b :GetTop ()
643632 end
644633 end )
645634
646- if DialogKey .db .numKeysForGossip and not isGossipFrame then
647- for i , frame in ipairs (DialogKey .frames ) do
635+ if self .db .numKeysForGossip and not isGossipFrame then
636+ for i , frame in ipairs (self .frames ) do
648637 if i > 10 then break end
649- frame :SetText (i % 10 .. " . " .. frame :GetText ())
638+ frame :SetText (( i % 10 ) .. " . " .. frame :GetText ())
650639
651640 -- Make the button taller if the text inside is wrapped to multiple lines
652- frame :SetHeight (frame :GetFontString ():GetHeight ()+ 2 )
641+ frame :SetHeight (frame :GetFontString ():GetHeight () + 2 )
653642 end
654643 end
655644end
656645
657646-- Glow Functions --
658647function DialogKey :Glow (frame , speedModifier , forceShow )
659- if DialogKey .db .showGlow or forceShow then
648+ if self .db .showGlow or forceShow then
660649 self .glowFrame :SetAllPoints (frame )
661650 self .glowFrame .tex :SetColorTexture (1 ,1 ,0 ,0.5 )
662651 self .glowFrame :Show ()
0 commit comments