Thread Tools Display Modes
02-03-11, 03:07 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
UnitPowerAlt

I gathered some information on the UnitPowerAlt stuff.

Code:
  --default Blizzard PlayerPowerBarAlt
  PlayerPowerBarAlt:Hide()

  --Event handling
  frame:RegisterEvent("UNIT_POWER")
  frame:RegisterEvent("UNIT_POWER_BAR_SHOW")
  frame:RegisterEvent("UNIT_POWER_BAR_HIDE")
  
  --WoW API Functions
  UnitAlternatePowerInfo("player")
  UnitAlternatePowerTextureInfo(...)
  UnitPower("player", ALTERNATE_POWER_INDEX)
  UnitPowerMax("player", ALTERNATE_POWER_INDEX)
Currently only two powerbars of that type are known.

PlayerPowerAlt for Atramedes and Cho'gall.

Onyxia Bossframe on Nefarian encounter has a alternative powerbar aswell. No clue about the name though.

Creating an player power alternative statusbar on its own in form of a statusbar should be quite simple.

Just create the statusbar make it 0/100, hook the events and check for UnitAlternatePowerInfo(). If that is true get the percentage value of UnitPower(alt_index) to UnitPowerMax(alt_index) and apply that value to the statusbar.

Does anyone have information on the onyxia bossframe altpowerbar?

I just checked ShadowedUnitFrames. There is already some kind of element for that.
Code:
local AltPower = {}
ShadowUF:RegisterModule(AltPower, "altPowerBar", ShadowUF.L["Alt. Power bar"], true)

local ALTERNATE_POWER_INDEX = ALTERNATE_POWER_INDEX

function AltPower:OnEnable(frame)
	frame.altPowerBar = frame.altPowerBar or ShadowUF.Units:CreateBar(frame)

	frame:RegisterUnitEvent("UNIT_POWER", self, "Update")
	frame:RegisterUnitEvent("UNIT_MAXPOWER", self, "Update")
	frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", self, "UpdateVisibility")
	frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", self, "UpdateVisibility")

	frame:RegisterUpdateFunc(self, "UpdateVisibility")
end

function AltPower:OnLayoutApplied(frame)
	if( frame.visibility.altPowerBar ) then
		local color = ShadowUF.db.profile.powerColors.ALTERNATE
		frame.altPowerBar:SetStatusBarColor(color.r, color.g, color.b, ShadowUF.db.profile.bars.alpha)
	end
end

function AltPower:OnDisable(frame)
	frame:UnregisterAll(self)
end

function AltPower:UpdateVisibility(frame)
	local barType, minPower, _, _, _, hideFromOthers = UnitAlternatePowerInfo(frame.unit)
	local visible = barType and (frame.unit == "player" or not hideFromOthers)
	ShadowUF.Layout:SetBarVisibility(frame, "altPowerBar", visible)
	AltPower:Update(frame, nil, nil, "ALTERNATE")
end

function AltPower:Update(frame, event, unit, type)
	if( type ~= "ALTERNATE" ) then return end
	local cur = UnitPower(frame.unit, ALTERNATE_POWER_INDEX)
	local max = UnitPowerMax(frame.unit, ALTERNATE_POWER_INDEX)
	local barType, min = UnitAlternatePowerInfo(frame.unit)
	frame.altPowerBar.currentPower = cur
	frame.altPowerBar:SetMinMaxValues(min or 0, max or 0)
	frame.altPowerBar:SetValue(cur or 0)
end
Player bar
Code:
	if( ShadowUF.db.profile.hidden.playerAltPower ) then
		PlayerPowerBarAlt:UnregisterEvent("UNIT_POWER_BAR_SHOW")
		PlayerPowerBarAlt:UnregisterEvent("UNIT_POWER_BAR_HIDE")
		PlayerPowerBarAlt:UnregisterEvent("PLAYER_ENTERING_WORLD")
		PlayerPowerBarAlt:Hide()
	end
The Onyxia alternative power bar is bound to the bossframe. It is gone once you spawn bossframes via oUF. Which is good since you only have to spawn the powerbar alt for bossframes without having to deactivate a specific frame like for player.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 02-03-11 at 03:32 AM.
  Reply With Quote
02-03-11, 06:06 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
oUF has supported the alt power bar since late December. I haven't pushed a release yet as I've had some stuff I wanted to test and change.

Hopefully I'll get my last batch of testing done and can push a release this week.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
02-03-11, 06:29 AM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
There is an AltPowerBar when one does the quests associated with Iso'Rath (starting with Devoured) in Twilight Highland. In case you need this for testing.
  Reply With Quote
02-03-11, 06:31 AM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Thanks, but the AltPowerBar has already been tested and verified working (unless I missed something). It's the unit swapping in raids for vehicles that still require some minor testing.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
02-07-11, 05:22 PM   #5
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
I created a little power bar that fits my unit frames and UI, but feel free to modify it to your own needs.

This should cover all the known bosses/quests that use the alt power bar as well as it's function and value.

(Add under shared stuff)

*EDIT*
Oh, and tested and works! :P

lua Code:
  1. -- alt power bar
  2.     local AltPowerBar = CreateFrame("StatusBar", nil, self)
  3.     AltPowerBar:SetWidth(cfg.widthF)
  4.     AltPowerBar:SetHeight(17)
  5.     AltPowerBar:SetStatusBarTexture(settings.texture)
  6.     AltPowerBar:SetStatusBarColor(1,0,0)
  7.     AltPowerBar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 226)
  8.     AltPowerBar.bd = SetBD(AltPowerBar, backdrop, {0.17, 0.17, 0.17, 1})
  9.    
  10.     AltPowerBar.type = AltPowerBar:CreateFontString(nil, "OVERLAY")
  11.     AltPowerBar.type:SetFontObject(cfg.Font)
  12.     AltPowerBar.type:SetText("")
  13.     AltPowerBar.type:SetPoint("LEFT",4,0)
  14.        
  15.     AltPowerBar.value = AltPowerBar:CreateFontString(nil, "OVERLAY")
  16.     AltPowerBar.value:SetFontObject(cfg.Font)
  17.     AltPowerBar.value:SetJustifyH("RIGHT")
  18.     AltPowerBar.value:SetPoint("RIGHT",-2,0)
  19.     AltPowerBar.value:SetText("")
  20.    
  21.     AltPowerBar:RegisterEvent("UNIT_POWER")
  22.     --AltPowerBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  23.     AltPowerBar:SetScript("OnEvent", function(self,event,...)
  24.         alternatePower = UnitPower("player", ALTERNATE_POWER_INDEX)
  25.         ZoneName = GetRealZoneText()
  26.         subZoneName = GetSubZoneText()
  27.        
  28.         if alternatePower >= 0 then
  29.             AltPowerBar.value:SetText(alternatePower)
  30.         else
  31.             AltPowerBar.value:SetText(0)
  32.         end
  33.        
  34.         if ZoneName == "Twilight Highlands" then -- Iso'Rath Quest (Maw of Madness)
  35.             AltPowerBar:SetStatusBarColor(0.5,0.8,0.3)
  36.             AltPowerBar.type:SetText("DIGESTION")
  37.         elseif ZoneName == "The Bastion of Twilight" then -- Cho'Gall
  38.             AltPowerBar:SetStatusBarColor(0.5,0,1)
  39.             AltPowerBar.type:SetText("CORRUPTION")
  40.         elseif ZoneName == "Blackwing Descent" then -- Atramedes and Nefarion
  41.             if subZoneName == "The Athenaeum" then
  42.                 AltPowerBar:SetStatusBarColor(0,0.5,1)
  43.                 AltPowerBar.type:SetText("SOUNDLVL")
  44.             else --elseif subZoneName == "Vault of the Shadowflame" --Onyxia Rage
  45.                 AltPowerBar:SetStatusBarColor(0,0.5,1)
  46.                 AltPowerBar.type:SetText("ONYRAGE")
  47.             end
  48.         end
  49.     end)
__________________


Last edited by sacrife : 02-07-11 at 06:35 PM.
  Reply With Quote
02-08-11, 02:33 AM   #6
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Onyxia's bar is hooked to the bossframe1 or 2 afaik.
So UnitPower("player", ALTERNATE_POWER_INDEX) will fail for that.

Basically I would spawn the powerbar for bossframes and for player. But you could even spawn it in raids to see the powertype of other players afaik.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 02-08-11 at 02:37 AM.
  Reply With Quote
02-08-11, 02:52 AM   #7
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
I tested it for onyxia and it worked fine. Atleast for the 5 seconds I was alive So I have no need to create one additional linked to the boss frames.

However, spawning a bar for each raid member is an interesting idea. Not entirely sure where to put it though.
Maybe a small bar below the normal mana/energy/etc bar on the raid frames.

Will have to test it in todays raid. One question though, with my current code being put in shared what will happen in a raid with 10 members?
Maybe I should add a check for if unit == player or raid%d and only then draw/size/etc the frames?
__________________


Last edited by sacrife : 02-08-11 at 02:57 AM.
  Reply With Quote
02-08-11, 06:27 AM   #8
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Is there any reason behind you rolling your own solution, instead of using the internal one?

Your current code is hard-coded for player however.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
02-08-11, 06:31 AM   #9
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
The reason is I'm a noob and don't know how to use your built in function to do what I did above with the least amount of code. Also I'm not sure if you have the feature for changing color/info for each type of bar depending on your location etc.
And also atm I know it is limited to finding the number for the player power, but shouldnt bars spawn for every frame when I have it under shared but every frame would have the player power number?
__________________

  Reply With Quote
02-08-11, 12:41 PM   #10
Freebaser
A Molten Kobold Bandit
 
Freebaser's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 135
You can use PostUpate. The bar color and power name can be gathered from blizzard functions.

some drycode

lua Code:
  1. local PostUpdateAltPower = function(altpower, min, cur, max)
  2.     local self = altpower.__owner
  3.  
  4.     local tPath, r, g, b = UnitAlternatePowerTextureInfo(self.unit, 2) -- 2 is statusbar index
  5.     if(r) then
  6.         altpower:SetStatusBarColor(r, g, b)
  7.     end
  8.  
  9.     local powerName = select(10, UnitAlternatePowerInfo(self.unit))
  10.     if(powerName) then
  11.         altpower.text:SetText(powerName)
  12.     end
  13. end
  Reply With Quote
02-08-11, 01:30 PM   #11
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
Originally Posted by Freebaser View Post
You can use PostUpate. The bar color and power name can be gathered from blizzard functions.

some drycode

lua Code:
  1. local PostUpdateAltPower = function(altpower, min, cur, max)
  2.     local self = altpower.__owner
  3.  
  4.     local tPath, r, g, b = UnitAlternatePowerTextureInfo(self.unit, 2) -- 2 is statusbar index
  5.     if(r) then
  6.         altpower:SetStatusBarColor(r, g, b)
  7.     end
  8.  
  9.     local powerName = select(10, UnitAlternatePowerInfo(self.unit))
  10.     if(powerName) then
  11.         altpower.text:SetText(powerName)
  12.     end
  13. end
What code would I have to add under player or raid then?

self.altpower:SetWidth/pos/height/Show/etc?
__________________

  Reply With Quote
02-08-11, 02:16 PM   #12
Freebaser
A Molten Kobold Bandit
 
Freebaser's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 135
Remove the event stuff from you previous code and add

Code:
self.AltPowerBar = AltPowerBar
self.AltPowerBar.PostUpdate = PostUpdateAltPower
Use PostUpdate to add the power text value or create a tag for it.
  Reply With Quote
02-19-11, 02:14 PM   #13
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Sacrife, why don't you add a tooltip for it as in the standart interface instead of displaying powerName on the bar itself?

lua Code:
  1. self.AltPowerBar.Tooltip = function(self)
  2.     local powerName = select(10, UnitAlternatePowerInfo(self.__owner.unit))
  3.     local powerTooltip = select(11, UnitAlternatePowerInfo(self.__owner.unit))
  4.        
  5.     GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT", 0, 5)
  6.     GameTooltip:AddLine(powerName)
  7.     GameTooltip:AddLine("\n"..powerTooltip, nil, nil, nil, true)
  8.     GameTooltip:Show()
  9. end
  10.    
  11. self.AltPowerBar:EnableMouse()
  12. self.AltPowerBar:HookScript("OnLeave", GameTooltip_Hide)
  13. self.AltPowerBar:HookScript("OnEnter", self.AltPowerBar.Tooltip)
  Reply With Quote
02-19-11, 03:03 PM   #14
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
As a sidenote:
I'd try to implement the altpower thing via oUF and it seems to fail on that fun quest where you have to defend your farm against zombies (Flower vs. Zombies Q line next to Tarrens Mill). It didn't show up at all.
I'm pretty sure I didn't do it wrong. Since, I also tried to copy and paste oUF_Lily's implementation, after trying it on my own.

I ended up with scaling blizzards bar down and making it moveable, keeping the art etc., instead.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
02-20-11, 01:24 PM   #15
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
I did some testing on Zombies vs Plants and thats what I got

All the altPower infos are reported for player and not for vehicle
/run print(UnitAlternatePowerInfo("player")) -- returns the normal bunch of values
/run print(UnitPower("player", ALTERNATE_POWER_INDEX)) -- returns 0
/run print(UnitPowerMax("player", ALTERNATE_POWER_INDEX)) -- returns 4

The three above return nothing, 0, 0 respectevely when I use vehicle as unit.

Thus in oUF/elements/altpowerbar.lua Toggler would be called when unit == "vehicle" and self.unit == "vehicle" and will fail as UnitPowerMax(unit, ALTERNATE_POWER_INDEX) would return 0. UpdatePower fails then because powerType for unit vehicle is always ENERGY.

I then commented out in Toggler
Code:
if(unit ~= self.unit) then return end
and changed in UpdatePower
Code:
if(self.unit ~= unit or powerType ~= 'ALTERNATE') then return end
to
Code:
if(powerType ~= 'ALTERNATE') then return end
Toggler calls then UpdatePower on every UNIT_POWER for all units (initially failing to show the altpowerbar as min and max are both 0 because at UNIT_POWER_BAR_SHOW it gets unit == "pet" and unit == "vehicle"). After some zombies die, the altpowerbar changes to 25% for unit == "player" and self.unit == "vehicle". It fails again to show the bar because of
Code:
local cur = UnitPower(unit, ALTERNATE_POWER_INDEX)
local max = UnitPowerMax(self.unit, ALTERNATE_POWER_INDEX)
in UpdatePower. Changing this to local max = UnitPowerMax(unit, ALTERNATE_POWER_INDEX) updates and shows the powerbar.

I hope this helps somehow.
  Reply With Quote
02-20-11, 01:44 PM   #16
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
On Cho'gall I got 2 bars on top of eachother, which was really annoying. How do I solve that?

Never mind, it was just every raid's bar stacked on each other.
__________________


Last edited by sacrife : 02-20-11 at 02:10 PM.
  Reply With Quote
02-20-11, 03:32 PM   #17
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Originally Posted by Rainrider View Post
I did some testing on Zombies vs Plants and thats what I got

All the altPower infos are reported for player and not for vehicle
/run print(UnitAlternatePowerInfo("player")) -- returns the normal bunch of values
/run print(UnitPower("player", ALTERNATE_POWER_INDEX)) -- returns 0
/run print(UnitPowerMax("player", ALTERNATE_POWER_INDEX)) -- returns 4

The three above return nothing, 0, 0 respectevely when I use vehicle as unit.

Thus in oUF/elements/altpowerbar.lua Toggler would be called when unit == "vehicle" and self.unit == "vehicle" and will fail as UnitPowerMax(unit, ALTERNATE_POWER_INDEX) would return 0. UpdatePower fails then because powerType for unit vehicle is always ENERGY.

I then commented out in Toggler
Code:
if(unit ~= self.unit) then return end
and changed in UpdatePower
Code:
if(self.unit ~= unit or powerType ~= 'ALTERNATE') then return end
to
Code:
if(powerType ~= 'ALTERNATE') then return end
Toggler calls then UpdatePower on every UNIT_POWER for all units (initially failing to show the altpowerbar as min and max are both 0 because at UNIT_POWER_BAR_SHOW it gets unit == "pet" and unit == "vehicle"). After some zombies die, the altpowerbar changes to 25% for unit == "player" and self.unit == "vehicle". It fails again to show the bar because of
Code:
local cur = UnitPower(unit, ALTERNATE_POWER_INDEX)
local max = UnitPowerMax(self.unit, ALTERNATE_POWER_INDEX)
in UpdatePower. Changing this to local max = UnitPowerMax(unit, ALTERNATE_POWER_INDEX) updates and shows the powerbar.

I hope this helps somehow.
Thanks for further investigation. Someone should open a ticket over at github. *cough*
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
02-20-11, 04:28 PM   #18
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Ticket opened at https://github.com/haste/oUF/issues/73
  Reply With Quote
03-16-11, 01:25 AM   #19
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
If I understand haste correctly spawning an AltPowerBar for the pet unit should do it? Gonna test that later. My AltPowerBar is nearly finished.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
03-16-11, 12:45 PM   #20
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Tested. haste is correct. Create a powerbar for player and pets and you will be fine.



If you hack the default element you will destroy it.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » UnitPowerAlt


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