WoWInterface SVN bdGrid

[/] [trunk/] [lib/] [oUF/] [elements/] [altpowerbar.lua] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Blooblahguy-207965
--[[ Element: Alternative Power Bar
2 Blooblahguy-207965
 
3 Blooblahguy-207965
 Handles visibility and updating of the alternative power bar.
4 Blooblahguy-207965
 
5 Blooblahguy-207965
 This bar is used to display encounter/quest related power information, such as
6 Blooblahguy-207965
 the number of hour glass uses left on the end boss in End Time.
7 Blooblahguy-207965
 
8 Blooblahguy-207965
 Widget
9 Blooblahguy-207965
 
10 Blooblahguy-207965
 AltPowerBar - A StatusBar to represent alternative power.
11 Blooblahguy-207965
 
12 Blooblahguy-207965
 Options
13 Blooblahguy-207965
 
14 Blooblahguy-207965
 .colorTexture     - Use the vertex color values returned by
15 Blooblahguy-207965
                     UnitAlternatePowerTextureInfo to color the bar.
16 Blooblahguy-207965
 
17 Blooblahguy-207965
 Notes
18 Blooblahguy-207965
 
19 Blooblahguy-207965
 OnEnter and OnLeave handlers to display a tooltip will be set on the widget if
20 Blooblahguy-207965
 it is mouse enabled.
21 Blooblahguy-207965
 
22 Blooblahguy-207965
 Examples
23 Blooblahguy-207965
 
24 Blooblahguy-207965
   -- Position and size
25 Blooblahguy-207965
   local AltPowerBar = CreateFrame('StatusBar', nil, self)
26 Blooblahguy-207965
   AltPowerBar:SetHeight(20)
27 Blooblahguy-207965
   AltPowerBar:SetPoint('BOTTOM')
28 Blooblahguy-207965
   AltPowerBar:SetPoint('LEFT')
29 Blooblahguy-207965
   AltPowerBar:SetPoint('RIGHT')
30 Blooblahguy-207965
 
31 Blooblahguy-207965
   -- Register with oUF
32 Blooblahguy-207965
   self.AltPowerBar = AltPowerBar
33 Blooblahguy-207965
 
34 Blooblahguy-207965
 Callbacks
35 Blooblahguy-207965
]]
36 Blooblahguy-207965
 
37 Blooblahguy-207965
local parent, ns = ...
38 Blooblahguy-207965
local oUF = ns.oUF
39 Blooblahguy-207965
 
40 Blooblahguy-207965
local ALTERNATE_POWER_INDEX = ALTERNATE_POWER_INDEX
41 Blooblahguy-207965
 
42 Blooblahguy-207965
--[[ :UpdateTooltip()
43 Blooblahguy-207965
 
44 Blooblahguy-207965
 The function called when the widget is hovered. Used to populate the tooltip.
45 Blooblahguy-207965
 
46 Blooblahguy-207965
 Arguments
47 Blooblahguy-207965
 
48 Blooblahguy-207965
 self - The AltPowerBar element.
49 Blooblahguy-207965
]]
50 Blooblahguy-207965
local UpdateTooltip = function(self)
51 Blooblahguy-207965
        GameTooltip:SetText(self.powerName, 1, 1, 1)
52 Blooblahguy-207965
        GameTooltip:AddLine(self.powerTooltip, nil, nil, nil, 1)
53 Blooblahguy-207965
        GameTooltip:Show()
54 Blooblahguy-207965
end
55 Blooblahguy-207965
 
56 Blooblahguy-207965
local OnEnter = function(self)
57 Blooblahguy-207965
        if(not self:IsVisible()) then return end
58 Blooblahguy-207965
 
59 Blooblahguy-207965
        GameTooltip_SetDefaultAnchor(GameTooltip, self)
60 Blooblahguy-207965
        self:UpdateTooltip()
61 Blooblahguy-207965
end
62 Blooblahguy-207965
 
63 Blooblahguy-207965
local OnLeave = function()
64 Blooblahguy-207965
        GameTooltip:Hide()
65 Blooblahguy-207965
end
66 Blooblahguy-207965
 
67 Blooblahguy-207965
local UpdatePower = function(self, event, unit, powerType)
68 Blooblahguy-207965
        if(self.unit ~= unit or powerType ~= 'ALTERNATE') then return end
69 Blooblahguy-207965
 
70 Blooblahguy-207965
        local altpowerbar = self.AltPowerBar
71 Blooblahguy-207965
 
72 Blooblahguy-207965
        --[[ :PreUpdate()
73 Blooblahguy-207965
 
74 Blooblahguy-207965
         Called before the element has been updated.
75 Blooblahguy-207965
 
76 Blooblahguy-207965
         Arguments
77 Blooblahguy-207965
 
78 Blooblahguy-207965
         self - The AltPowerBar element.
79 Blooblahguy-207965
         ]]
80 Blooblahguy-207965
        if(altpowerbar.PreUpdate) then
81 Blooblahguy-207965
                altpowerbar:PreUpdate()
82 Blooblahguy-207965
        end
83 Blooblahguy-207965
 
84 Blooblahguy-207965
        local _, r, g, b
85 Blooblahguy-207965
        if(altpowerbar.colorTexture) then
86 Blooblahguy-207965
                _, r, g, b = UnitAlternatePowerTextureInfo(unit, 2)
87 Blooblahguy-207965
        end
88 Blooblahguy-207965
 
89 Blooblahguy-207965
        local cur = UnitPower(unit, ALTERNATE_POWER_INDEX)
90 Blooblahguy-207965
        local max = UnitPowerMax(unit, ALTERNATE_POWER_INDEX)
91 Blooblahguy-207965
 
92 Blooblahguy-207965
        local barType, min, _, _, _, _, _, _, _, powerName, powerTooltip = UnitAlternatePowerInfo(unit)
93 Blooblahguy-207965
        altpowerbar.barType = barType
94 Blooblahguy-207965
        altpowerbar.powerName = powerName
95 Blooblahguy-207965
        altpowerbar.powerTooltip = powerTooltip
96 Blooblahguy-207965
        altpowerbar:SetMinMaxValues(min, max)
97 Blooblahguy-207965
        altpowerbar:SetValue(math.min(math.max(cur, min), max))
98 Blooblahguy-207965
 
99 Blooblahguy-207965
        if(b) then
100 Blooblahguy-207965
                altpowerbar:SetStatusBarColor(r, g, b)
101 Blooblahguy-207965
        end
102 Blooblahguy-207965
 
103 Blooblahguy-207965
        --[[ :PostUpdate(min, cur, max)
104 Blooblahguy-207965
 
105 Blooblahguy-207965
         Called after the element has been updated.
106 Blooblahguy-207965
 
107 Blooblahguy-207965
         Arguments
108 Blooblahguy-207965
 
109 Blooblahguy-207965
         self - The AltPowerBar element.
110 Blooblahguy-207965
         min  - The minimum possible power value for the active type.
111 Blooblahguy-207965
         cur  - The current power value.
112 Blooblahguy-207965
         max  - The maximum possible power value for the active type.
113 Blooblahguy-207965
        ]]
114 Blooblahguy-207965
        if(altpowerbar.PostUpdate) then
115 Blooblahguy-207965
                return altpowerbar:PostUpdate(min, cur, max)
116 Blooblahguy-207965
        end
117 Blooblahguy-207965
end
118 Blooblahguy-207965
 
119 Blooblahguy-207965
 
120 Blooblahguy-207965
--[[ Hooks
121 Blooblahguy-207965
 
122 Blooblahguy-207965
 Override(self) - Used to completely override the internal update function.
123 Blooblahguy-207965
                  Removing the table key entry will make the element fall-back
124 Blooblahguy-207965
                  to its internal function again.
125 Blooblahguy-207965
]]
126 Blooblahguy-207965
local Path = function(self, ...)
127 Blooblahguy-207965
        return (self.AltPowerBar.Override or UpdatePower)(self, ...)
128 Blooblahguy-207965
end
129 Blooblahguy-207965
 
130 Blooblahguy-207965
local ForceUpdate = function(element)
131 Blooblahguy-207965
        return Path(element.__owner, 'ForceUpdate', element.__owner.unit, 'ALTERNATE')
132 Blooblahguy-207965
end
133 Blooblahguy-207965
 
134 Blooblahguy-207965
local Toggler = function(self, event, unit)
135 Blooblahguy-207965
        if(unit ~= self.unit) then return end
136 Blooblahguy-207965
        local altpowerbar = self.AltPowerBar
137 Blooblahguy-207965
 
138 Blooblahguy-207965
        local barType, _, _, _, _, hideFromOthers, showOnRaid = UnitAlternatePowerInfo(unit)
139 Blooblahguy-207965
        if(barType and (showOnRaid and (UnitInParty(unit) or UnitInRaid(unit)) or not hideFromOthers or unit == 'player' or self.realUnit == 'player')) then
140 Blooblahguy-207965
                self:RegisterEvent('UNIT_POWER', Path)
141 Blooblahguy-207965
                self:RegisterEvent('UNIT_MAXPOWER', Path)
142 Blooblahguy-207965
 
143 Blooblahguy-207965
                ForceUpdate(altpowerbar)
144 Blooblahguy-207965
                altpowerbar:Show()
145 Blooblahguy-207965
        else
146 Blooblahguy-207965
                self:UnregisterEvent('UNIT_POWER', Path)
147 Blooblahguy-207965
                self:UnregisterEvent('UNIT_MAXPOWER', Path)
148 Blooblahguy-207965
 
149 Blooblahguy-207965
                altpowerbar:Hide()
150 Blooblahguy-207965
        end
151 Blooblahguy-207965
end
152 Blooblahguy-207965
 
153 Blooblahguy-207965
local Enable = function(self, unit)
154 Blooblahguy-207965
        local altpowerbar = self.AltPowerBar
155 Blooblahguy-207965
        if(altpowerbar) then
156 Blooblahguy-207965
                altpowerbar.__owner = self
157 Blooblahguy-207965
                altpowerbar.ForceUpdate = ForceUpdate
158 Blooblahguy-207965
 
159 Blooblahguy-207965
                self:RegisterEvent('UNIT_POWER_BAR_SHOW', Toggler)
160 Blooblahguy-207965
                self:RegisterEvent('UNIT_POWER_BAR_HIDE', Toggler)
161 Blooblahguy-207965
 
162 Blooblahguy-207965
                altpowerbar:Hide()
163 Blooblahguy-207965
 
164 Blooblahguy-207965
                if(altpowerbar:IsMouseEnabled()) then
165 Blooblahguy-207965
                        if(not altpowerbar:GetScript('OnEnter')) then
166 Blooblahguy-207965
                                altpowerbar:SetScript('OnEnter', OnEnter)
167 Blooblahguy-207965
                        end
168 Blooblahguy-207965
                        altpowerbar:SetScript('OnLeave', OnLeave)
169 Blooblahguy-207965
 
170 Blooblahguy-207965
                        if(not altpowerbar.UpdateTooltip) then
171 Blooblahguy-207965
                                altpowerbar.UpdateTooltip = UpdateTooltip
172 Blooblahguy-207965
                        end
173 Blooblahguy-207965
                end
174 Blooblahguy-207965
 
175 Blooblahguy-207965
                if(unit == 'player') then
176 Blooblahguy-207965
                        PlayerPowerBarAlt:UnregisterEvent'UNIT_POWER_BAR_SHOW'
177 Blooblahguy-207965
                        PlayerPowerBarAlt:UnregisterEvent'UNIT_POWER_BAR_HIDE'
178 Blooblahguy-207965
                        PlayerPowerBarAlt:UnregisterEvent'PLAYER_ENTERING_WORLD'
179 Blooblahguy-207965
                end
180 Blooblahguy-207965
 
181 Blooblahguy-207965
                return true
182 Blooblahguy-207965
        end
183 Blooblahguy-207965
end
184 Blooblahguy-207965
 
185 Blooblahguy-207965
local Disable = function(self, unit)
186 Blooblahguy-207965
        local altpowerbar = self.AltPowerBar
187 Blooblahguy-207965
        if(altpowerbar) then
188 Blooblahguy-207965
                altpowerbar:Hide()
189 Blooblahguy-207965
                self:UnregisterEvent('UNIT_POWER_BAR_SHOW', Toggler)
190 Blooblahguy-207965
                self:UnregisterEvent('UNIT_POWER_BAR_HIDE', Toggler)
191 Blooblahguy-207965
 
192 Blooblahguy-207965
                if(unit == 'player') then
193 Blooblahguy-207965
                        PlayerPowerBarAlt:RegisterEvent'UNIT_POWER_BAR_SHOW'
194 Blooblahguy-207965
                        PlayerPowerBarAlt:RegisterEvent'UNIT_POWER_BAR_HIDE'
195 Blooblahguy-207965
                        PlayerPowerBarAlt:RegisterEvent'PLAYER_ENTERING_WORLD'
196 Blooblahguy-207965
                end
197 Blooblahguy-207965
        end
198 Blooblahguy-207965
end
199 Blooblahguy-207965
 
200 Blooblahguy-207965
oUF:AddElement('AltPowerBar', Toggler, Enable, Disable)