Thread Tools Display Modes
06-11-18, 02:41 AM   #1
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
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!

Last edited by Eungavi : 06-11-18 at 03:16 AM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Best way to detect AdditionalPower's enabled state?

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