View Single Post
06-06-23, 04:31 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
This appears to be from the Vanilla Classic client. Wrath Classic adds buff consolidation and Dragon Flight's code was rewritten into mixins. The target client matters as oftentimes the code we're seeking to modify and sometimes even API calls will be different.

That being said, I have a few additional notes. DEBUFF_ACTUAL_DISPLAY is being incremented as DebuffButton_UpdateAnchors() is repeatedly called. For example, it would show zero in the first call, 1 for the second, 2 for the third, and so on. For this reason, you don't have a usable count of how many debuffs you have until after the last call of your function.

Screen doesn't refer to a UI Object. It isn't a magic keyword, Lua just sees it as a variable name. The contents of an undefined variable is nil, which when given as the reference object for :SetPoint() does anchor to the screen. The problem here is if anyone else were to haphazardly store a value into this variable, the result will break your code. It's common practice to anchor to UIParent as that's the root frame of the entire UI and what UI scaling is applied directly to.

UIParent_ManageFramePositions() is called shortly after your function runs, which is susceptible to addon taint. You'll want to avoid directly replacing Blizzard functions unless you're sure protected code doesn't run after your function does. Blizzard provides a way to post-hook functions without spreading taint through hooksecurefunc().



Here's how I would implement your requested change.
Lua Code:
  1. local Step=BUFF_BUTTON_HEIGHT+5;--  Precalculated horizontal step
  2. hooksecurefunc("BuffFrame_Update",function()
  3.     local offset=(DEBUFF_ACTUAL_DISPLAY-1)*Step/2;--    Half the total width added after the first debuff
  4.     for i=1,DEBUFF_ACTUAL_DISPLAY do
  5.         local debuff=_G["DebuffButton"..i];
  6.         if debuff and debuff:IsShown() then--   Sanity check
  7. --          Arrange left-to-right (stock is right-to-left)
  8.             debuff:ClearAllPoints();--  Clear existing anchors (resizing happens when more than one point is defined)
  9.             debuff:SetPoint("CENTER",UIParent,"CENTER",(i-1)*Step-offset,-200);
  10.         end
  11.     end
  12. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote