View Single Post
10-22-22, 09:38 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
This is what I've come up with. I ended up rewriting it from scratch while using the newer version's position calculation as it was cleaner and I had already made it configurable.

Lua Code:
  1. --  Config Constants
  2. local Aura_Size=21;
  3. local Aura_Spacing=2;
  4. local Aura_ShortCols=4;--   Buffs per short row
  5. local Aura_ShortRows=2;--   Number of shortened rows
  6. local Aura_NormalCols=6;--  Buffs per remaining rows
  7.  
  8. --  Calculated Constants
  9. local Aura_ShortPadCols=Aura_NormalCols-Aura_ShortCols;
  10. local Aura_GridSize=Aura_Size+Aura_Spacing;
  11.  
  12. local function ReanchorAuras(self,auratype,container,prevrows)
  13.     prevrows=prevrows or 0;
  14.     local nameformat=("%s%s%%d"):format(self:GetName(),auratype);
  15.  
  16.     local point,relframe,relpoint,offsetx,offsety;
  17.     local rowcount,lastrowanchor=prevrows,nil;
  18.     for i=1,math.huge do--  Trick into running an infinite counter loop
  19.         local auraframe=_G[nameformat:format(i)];
  20.         if not (auraframe and auraframe:IsShown()) then return rowcount,lastrowanchor; end--    We're done, return here
  21.  
  22.         if i>1 then
  23.             local posindex=i-1; if not self.buffsOnTop and prevrows<Aura_ShortRows then
  24.                 posindex=posindex+math.min(math.floor(posindex/Aura_ShortCols),Aura_ShortRows-prevrows)*Aura_ShortPadCols;
  25.             end
  26.  
  27.             local x,y=posindex%Aura_NormalCols,math.floor(posindex/Aura_NormalCols);
  28.             auraframe:SetPoint(point,relframe,relpoint
  29.                 ,x*Aura_GridSize+offsetx
  30.                 ,(self.buffsOnTop and 1 or -1)*y*Aura_GridSize+offsety
  31.             );
  32.  
  33.             if x==0 then
  34.                 rowcount,lastrowanchor=prevrows+y+1,auraframe;
  35.                 container:SetPoint(relpoint,auraframe,relpoint,0,self.buffsOnTop and 1 or -1);
  36.             end
  37.         else point,relframe,relpoint,offsetx,offsety=auraframe:GetPoint(1); end
  38.  
  39. --      Note: DebuffType border scales with size, but Stealable border doesn't
  40.         auraframe:SetSize(Aura_Size,Aura_Size);
  41.         local stealborder=_G[nameformat:format(i).."Stealable"]; if stealborder then
  42.             local size=math.floor(Aura_Size*8/7);
  43.             stealborder:SetSize(size,size);
  44.         end
  45.     end
  46. end
  47.  
  48. hooksecurefunc("TargetFrame_UpdateAuras",function(self)
  49.     local rowcount,anchor1,anchor2=0,nil,nil;
  50.  
  51.     if UnitIsFriend("player",self.unit) then
  52.         rowcount,anchor1=ReanchorAuras(self,"Buff",self.buffs,rowcount);
  53.         rowcount,anchor2=ReanchorAuras(self,"Debuff",self.debuffs,rowcount);
  54.     else
  55.         rowcount,anchor1=ReanchorAuras(self,"Debuff",self.debuffs,rowcount);
  56.         rowcount,anchor2=ReanchorAuras(self,"Buff",self.buffs,rowcount);
  57.     end
  58.  
  59.     self.auraRows=rowcount;
  60.     self.spellbarAnchor=anchor1 or anchor2;
  61. 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