Thread Tools Display Modes
12-17-22, 06:48 AM   #1
xdka
A Kobold Labourer
Join Date: Dec 2022
Posts: 1
(lua) Reduce target debuff max row size

Hello everyone,

I'm currently trying to learn .lua and to mess with my interface but I'm currently blocked with what I want to achieve.

Long story short, I updated the target debuff size with the following code :

Code:
hooksecurefunc("TargetFrame_UpdateDebuffAnchor", function(_, debuff)
    debuff:SetSize(28, 28)
end)
It's working but unfortunately, because of the debuff size, it overlaps on my target frame since too many debuffs are displayed (5). BUT, this issue doesn't appear when my target has an active Target of Target (ToT) because only 4 debuffs are being displayed.

I checked the following resource : tomrus88/BlizzardInterfaceCode

I noticed two things :
  1. two local variables manage the width of rows:
    • local AURA_ROW_WIDTH = 122;
    • local TOT_AURA_ROW_WIDTH = 101;
  2. inside the UpdateAuraFrame there is the following comparison:
    • Code:
      local -- update debuff positions
      maxRowWidth = (haveTargetofTarget and self.auraRows < NUM_TOT_AURA_ROWS and self.TOT_AURA_ROW_WIDTH) or AURA_ROW_WIDTH

My guess is that I need to either:
  1. update the AURA_ROW_WIDTH to be the same size as TOT_AURA_ROW_WIDTH (101)
  2. set haveTargetofTarget to true

Unfortunately, I don't know if this is the right approach or if it's possible to achieve this with hooksecurefunc (ie: by hooking the UpdateAuras function)

If you have any idea or any ways of achieving this, I would be amazing !

Thanks a lot and have a nice week-end
  Reply With Quote
12-18-22, 01:46 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
I had a request to do something similar for someone else and this is what I came up with.

Lua Code:
  1. --  Config Constants
  2. local Aura_Size=24;
  3. local Aura_Spacing=4;
  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 ProcessAuraList; do
  13.     local AuraFrameMap={};
  14.  
  15.     local BuffsOnTop,IsPrimaryAuraType,OtherTypeRowCount;-- Iterator Callback Parameters
  16.     local AuraIndex,FirstAuraFrame;--   Position Tracking
  17.     local LastRowAuraFrame,RowCount;--  "Returns"
  18.     local function ProcessAura(instanceid,aurainfo)
  19.         local auraframe=AuraFrameMap[instanceid];
  20.         if auraframe then
  21.             AuraIndex,FirstAuraFrame=(AuraIndex or 0)+1,FirstAuraFrame or auraframe;
  22.             if AuraIndex>1 then
  23.                 local point,relframe,relpoint,offsetx,offsety=FirstAuraFrame:GetPoint(1);
  24.  
  25.                 local posindex=AuraIndex-1;
  26.                 if not BuffsOnTop and (IsPrimaryAuraType or OtherTypeRowCount<Aura_ShortRows) then
  27. --                  Shorten rows by adding a calculated offset to index
  28.                     posindex=posindex+math.min(math.floor(posindex/Aura_ShortCols),Aura_ShortRows-(IsPrimaryAuraType and 0 or OtherTypeRowCount))*Aura_ShortPadCols;
  29.                 end
  30.  
  31.                 local x,y=posindex%Aura_NormalCols,math.floor(posindex/Aura_NormalCols);
  32.                 auraframe:SetPoint(point,relframe,relpoint
  33.                     ,x*Aura_GridSize+offsetx
  34.                     ,(BuffsOnTop and 1 or -1)*y*Aura_GridSize+offsety
  35.                 );
  36.  
  37.                 if x==0 then RowCount,LastRowAuraFrame=y+1,auraframe; end
  38.             else RowCount,LastRowAuraFrame=1,auraframe; end
  39.  
  40.             auraframe:SetSize(Aura_Size,Aura_Size);
  41.             if auraframe.Border then auraframe.Border:SetSize(Aura_Size+2,Aura_Size+2); end
  42.         end
  43.     end
  44.  
  45.     function ProcessAuraList(self,auralist,isprimary,othersize,template,container)
  46.         local numauras=auralist and auralist:Size() or 0;
  47.         if numauras>0 then
  48.             for auraframe in self.auraPools:GetPool(template):EnumerateActive() do
  49.                 AuraFrameMap[auraframe.auraInstanceID]=auraframe;
  50.             end
  51.  
  52.             AuraIndex,FirstAuraFrame=0,nil;
  53.             BuffsOnTop,IsPrimaryAuraType=self.buffsOnTop,isprimary or othersize<=0;
  54.             OtherTypeRowCount=IsPrimaryAuraType and 0
  55.                 or math.floor(((othersize-1)+math.min(math.floor((othersize-1)/Aura_ShortCols),Aura_ShortRows)*Aura_ShortPadCols)/Aura_NormalCols)+1;
  56.  
  57.             auralist:Iterate(ProcessAura);
  58.             local rowcount=RowCount or 0;-- Cache for now, we're wiping the upvalues during cleanup
  59.  
  60.             if LastRowAuraFrame then
  61.                 if not isprimary or othersize<=0 then self.spellbarAnchor=LastRowAuraFrame; end
  62.                 container:SetPoint(select(3,LastRowAuraFrame:GetPoint(1)),LastRowAuraFrame,0,self.buffsOnTop and Aura_Spacing or -Aura_Spacing);
  63.             end
  64.  
  65. --          Cleanup
  66.             AuraIndex,FirstAuraFrame=nil,nil;
  67.             BuffsOnTop,IsPrimaryAuraType,OtherTypeRowCount=nil,nil,nil;
  68.             RowCount,LastRowAuraFrame=nil,nil;
  69.             table.wipe(AuraFrameMap);
  70.  
  71. --          Return number of rows
  72.             return rowcount;
  73.         else return 0; end
  74.     end
  75. end
  76.  
  77. local function TargetFrame_UpdateAuras(self)
  78.     local containerparent=self.TargetFrameContent.TargetFrameContentContextual;
  79.     local numrows=0;
  80.  
  81.     if UnitIsFriend("player",self.unit) then
  82.         numrows=numrows+ProcessAuraList(self,self.activeBuffs,true,self.activeDebuffs:Size(),"TargetBuffFrameTemplate",containerparent.buffs);
  83.         numrows=numrows+ProcessAuraList(self,self.activeDebuffs,false,self.activeBuffs:Size(),"TargetDebuffFrameTemplate",containerparent.debuffs);
  84.     else
  85.         numrows=numrows+ProcessAuraList(self,self.activeDebuffs,true,self.activeBuffs:Size(),"TargetDebuffFrameTemplate",containerparent.debuffs);
  86.         numrows=numrows+ProcessAuraList(self,self.activeBuffs,false,self.activeDebuffs:Size(),"TargetBuffFrameTemplate",containerparent.buffs);
  87.     end
  88.  
  89.     self.auraRows=numrows;
  90.     if self.spellbar then self.spellbar:AdjustPosition(); end
  91. end
  92.  
  93. hooksecurefunc(TargetFrame,"UpdateAuras",TargetFrame_UpdateAuras);
  94. hooksecurefunc(FocusFrame,"UpdateAuras",TargetFrame_UpdateAuras);

Blizzard's code basically runs an accumulator that adds up the frame size for each individual buff icon in a row. Ones cast by the player are larger than others. When adding an icon would result in a longer row by pixel length than configured, it's pushed to a new row. The first two rows are configured to "dodge" the ToT frame by having a shorter defined width.



At its core, this example does a simple index-to-grid calculation since all the buff icons have a uniform size.

The ToT frame "dodging" is handled by padding the index at the end of the configured rows to skip to a new row. In the end, the first buff retains its anchor while the rest copy it and apply an offset according to the prior calculation.

Two other things that added complexity to this was mapping the buff buttons to their associated entry in the presorted aura lists and carrying over the shortened row rules between the buff/debuff groups.



Looking into how this works. As configured, the ToT frame dodging has the first 2 rows configured with a row count of 4 while the rest are configured for a length of 6. If the ToT frame isn't shown, all rows get the length of 6. If the ToT frame is shown, it takes the zero-based index position, integer divides by 4 (the configured length of the shortened rows), clamps the result by 2 (the configured number of shortened rows), multiplies that by the pad length (configured normal minus short row lengths; 6-4=2), and adds it back into the index position. From there, both routes go through modulo and integer divide operations to convert index to (X,Y) coordinate offsets.
__________________
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

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » (lua) Reduce target debuff max row size

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off