Advertisement
gelatine87

Cell Health Bar Direction

Apr 26th, 2025
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.63 KB | Gaming | 0 0
  1. -- Settings
  2. -- Possible values:
  3. --    "LTR"     - Left to Right,
  4. --    "RTL"     - Right to Left,
  5. --    "TTB"    - Top to Bottom,
  6. --    "BTT"    - Bottom to top
  7. local FILL_DIRECTION = "BTT"
  8.  
  9. local ATTENUATE_DEAD_BARS = true
  10.  
  11. local function reanchorOutlets(P, outlet, healthBar)
  12.     P.ClearPoints(outlet)
  13.     P.Point(outlet, "TOPLEFT", healthBar:GetStatusBarTexture(), "TOPRIGHT")
  14.     P.Point(outlet, "BOTTOMLEFT", healthBar:GetStatusBarTexture(), "BOTTOMRIGHT")
  15. end
  16.  
  17. local function reanchorInlets(P, inlet, healthBar)
  18.     P.ClearPoints(inlet)
  19.     P.Point(inlet, "TOPLEFT", healthBar:GetStatusBarTexture())
  20.     P.Point(inlet, "BOTTOMLEFT", healthBar:GetStatusBarTexture())
  21. end
  22.  
  23. local function reanchorVerticalOutlets(P, outlet, healthBar)
  24.     P.ClearPoints(outlet)
  25.     P.Point(outlet, "TOPLEFT", healthBar:GetStatusBarTexture(), "BOTTOMLEFT")
  26.     P.Point(outlet, "TOPRIGHT", healthBar:GetStatusBarTexture(), "BOTTOMRIGHT")
  27. end
  28.  
  29. local function reanchorVerticalInlets(P, inlet, healthBar)
  30.     P.ClearPoints(inlet)
  31.     P.Point(inlet, "TOPLEFT", healthBar:GetStatusBarTexture())
  32.     P.Point(inlet, "TOPRIGHT", healthBar:GetStatusBarTexture())
  33. end
  34.  
  35. local function applyFillDirection()
  36.     Cell.funcs.IterateAllUnitButtons(function(b)
  37.             local P = Cell.pixelPerfectFuncs
  38.             local healthBar = b.widgets.healthBar
  39.             local healthBarLoss = b.widgets.healthBarLoss
  40.            
  41.             if FILL_DIRECTION == "LTR" then
  42.                 healthBar:SetOrientation("HORIZONTAL")
  43.                 healthBar:SetReverseFill(true)
  44.                
  45.                 P.ClearPoints(healthBarLoss)
  46.                 P.Point(healthBarLoss, "TOPLEFT", healthBar:GetStatusBarTexture(), "TOPRIGHT")
  47.                 P.Point(healthBarLoss, "BOTTOMRIGHT", healthBar, "BOTTOMRIGHT")
  48.                
  49.                 reanchorOutlets(P, b.widgets.damageFlashTex, healthBar)
  50.                 reanchorOutlets(P, b.widgets.incomingHeal, healthBar)
  51.                 reanchorOutlets(P, b.widgets.shieldBar, healthBar)
  52.                
  53.                 reanchorInlets(P, b.widgets.shieldBarR, healthBar)
  54.                 reanchorInlets(P, b.widgets.absorbsBar, healthBar)
  55.                
  56.             elseif FILL_DIRECTION == "RTL" then
  57.                 healthBar:SetOrientation("HORIZONTAL")
  58.                 healthBar:SetReverseFill(false)
  59.                
  60.                 P.ClearPoints(healthBarLoss)
  61.                 P.Point(healthBarLoss, "TOPLEFT", healthBar, "TOPLEFT")
  62.                 P.Point(healthBarLoss, "BOTTOMRIGHT", healthBar:GetStatusBarTexture(), "BOTTOMLEFT")
  63.                
  64.                 reanchorOutlets(P, b.widgets.damageFlashTex, healthBar)
  65.                 reanchorOutlets(P, b.widgets.incomingHeal, healthBar)
  66.                 reanchorOutlets(P, b.widgets.shieldBar, healthBar)
  67.                
  68.                 reanchorInlets(P, b.widgets.shieldBarR, healthBar)
  69.                 reanchorInlets(P, b.widgets.absorbsBar, healthBar)
  70.                
  71.             elseif FILL_DIRECTION == "TTB" then
  72.                 healthBar:SetOrientation("VERTICAL")
  73.                 healthBar:SetReverseFill(false)
  74.                
  75.                 P.ClearPoints(healthBarLoss)
  76.                 P.Point(healthBarLoss, "TOPLEFT", healthBar, "TOPLEFT")
  77.                 P.Point(healthBarLoss, "BOTTOMRIGHT", healthBar:GetStatusBarTexture(), "TOPRIGHT")
  78.                
  79.                 reanchorVerticalOutlets(P, b.widgets.damageFlashTex, healthBar)
  80.                 reanchorVerticalOutlets(P, b.widgets.incomingHeal, healthBar)
  81.                 reanchorVerticalOutlets(P, b.widgets.shieldBar, healthBar)
  82.                
  83.                 reanchorVerticalInlets(P, b.widgets.shieldBarR, healthBar)
  84.                 reanchorVerticalInlets(P, b.widgets.absorbsBar, healthBar)
  85.                
  86.             elseif FILL_DIRECTION == "BTT" then
  87.                 healthBar:SetOrientation("VERTICAL")
  88.                 healthBar:SetReverseFill(true)
  89.                
  90.                 P.ClearPoints(healthBarLoss)
  91.                 P.Point(healthBarLoss, "TOPLEFT", healthBar:GetStatusBarTexture(), "BOTTOMLEFT")
  92.                 P.Point(healthBarLoss, "BOTTOMRIGHT", healthBar, "BOTTOMRIGHT")
  93.                
  94.                 reanchorVerticalOutlets(P, b.widgets.damageFlashTex, healthBar)
  95.                 reanchorVerticalOutlets(P, b.widgets.incomingHeal, healthBar)
  96.                 reanchorVerticalOutlets(P, b.widgets.shieldBar, healthBar)
  97.                
  98.                 reanchorVerticalInlets(P, b.widgets.shieldBarR, healthBar)
  99.                 reanchorVerticalInlets(P, b.widgets.absorbsBar, healthBar)
  100.             end
  101.            
  102.             -- Special cases
  103.             local overAbsorbGlow = b.widgets.overAbsorbGlow
  104.             local overShieldGlow = b.widgets.overShieldGlow
  105.             P.ClearPoints(overAbsorbGlow)
  106.             P.ClearPoints(overShieldGlow)
  107.            
  108.             if FILL_DIRECTION == "LEFT_TO_RIGHT" or FILL_DIRECTION == "RIGHT_TO_LEFT" then
  109.                 P.Point(overAbsorbGlow, "TOPRIGHT")
  110.                 P.Point(overAbsorbGlow, "BOTTOMRIGHT")
  111.                 P.Point(overShieldGlow, "TOPLEFT")
  112.                 P.Point(overShieldGlow, "BOTTOMLEFT")
  113.             else
  114.                 P.Point(overAbsorbGlow, "TOP")
  115.                 P.Point(overShieldGlow, "TOP")
  116.             end
  117.     end)
  118. end
  119.  
  120. function hookCell()
  121.     if Cell.__fill_direction_hook_installed then return end
  122.    
  123.     if ATTENUATE_DEAD_BARS then
  124.         local F = Cell.funcs
  125.         local oldGetHealthBarColor = F.GetHealthBarColor
  126.         F.GetHealthBarColor = function(...)
  127.             local colors = {oldGetHealthBarColor(...)}
  128.             if not isDeadOrGhost then
  129.                 return unpack(colors)
  130.             end
  131.             return colors[4], colors[5], colors[6], colors[1], colors[2], colors[3]
  132.         end
  133.        
  134.         Cell.funcs.IterateAllUnitButtons(function(button)
  135.                 local originalSetVertexColor = button.widgets.healthBarLoss.SetVertexColor
  136.                 button.widgets.healthBarLoss.SetVertexColor = function(self, r, g, b, a)
  137.                     local dead = button.states.isDeadOrGhost or button.states.isDead
  138.                     if dead then
  139.                         r, g, b, a = button.widgets.healthBar:GetStatusBarColor()
  140.                     end
  141.                     originalSetVertexColor(self, r, g, b, a)
  142.                 end
  143.         end)
  144.     end
  145.    
  146.     local B = Cell.bFuncs
  147.     hooksecurefunc(B, "SetOrientation", function()
  148.             applyFillDirection()
  149.     end)
  150.    
  151.     applyFillDirection()
  152.     Cell.__fill_direction_hook_installed = true
  153. end
  154.  
  155. hookCell()
  156. Cell.RegisterCallback("AddonLoaded", "FillDirectionHook", hookCell)
Tags: WoW Addons Cell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement