WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Best way to detect AdditionalPower's enabled state? (https://www.wowinterface.com/forums/showthread.php?t=56276)

Eungavi 06-11-18 02:41 AM

Best way to detect AdditionalPower's enabled state?
 
So, I'm trying to re-position Auras element based on Additional Power element's enabled state and came out with the following.

Lua Code:
  1. function AdditionalPowerOverride(self, event, unit, powertype)
  2.     if event == "ElementEnable" then
  3.         -- re-position Auras element
  4.     elseif event == "ElementDisable" then
  5.         -- re-position Auras element
  6.     end
  7.  
  8.     if(unit ~= 'player' or (powertype and powertype ~= ADDITIONAL_POWER_BAR_NAME)) then return end
  9.  
  10.     local element = self.AdditionalPower
  11.     --[[ Callback: AdditionalPower:PreUpdate(unit)
  12.     Called before the element has been updated.
  13.  
  14.     * self - the AdditionalPower element
  15.     * unit - the unit for which the update has been triggered (string)
  16.     --]]
  17.     if(element.PreUpdate) then element:PreUpdate(unit) end
  18.  
  19.     local cur = UnitPower('player', ADDITIONAL_POWER_BAR_INDEX)
  20.     local max = UnitPowerMax('player', ADDITIONAL_POWER_BAR_INDEX)
  21.     element:SetMinMaxValues(0, max)
  22.     element:SetValue(cur)
  23.  
  24.     --[[ Override: AdditionalPower:UpdateColor(cur, max)
  25.     Used to completely override the internal function for updating the widget's colors.
  26.  
  27.     * self - the AdditionalPower element
  28.     * cur  - the current value of the player's additional power (number)
  29.     * max  - the maximum value of the player's additional power (number)
  30.     --]]
  31.     element:UpdateColor(cur, max)
  32.  
  33.     --[[ Callback: AdditionalPower:PostUpdate(unit, cur, max)
  34.     Called after the element has been updated.
  35.  
  36.     * self - the AdditionalPower element
  37.     * unit - the unit for which the update has been triggered (string)
  38.     * cur  - the current value of the player's additional power (number)
  39.     * max  - the maximum value of the player's additional power (number)
  40.     --]]
  41.     if(element.PostUpdate) then
  42.         return element:PostUpdate(unit, cur, max)
  43.     end
  44. end
  45.  
  46. function CreateAdditionalPower(self, unit)
  47.     local additionalPower = CreateFrame("StatusBar", "$parentAdditionalPower", self);
  48.     additionalPower:SetSize(self:GetWidth(), 4);
  49.     additionalPower:SetPoint("TOP", self, "BOTTOM", 0, -3);
  50.  
  51.     additionalPower.Override = AdditionalPowerOverride;
  52.  
  53.     self.AdditionalPower = additionalPower;
  54. end

If anyone has a better solution to this, please feel free to advise me.

Thank you!


All times are GMT -6. The time now is 05:25 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI