Go to most recent revision | Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 2 | Blooblahguy-207965 | --[[ Element: Monk Stagger Bar |
2 | Blooblahguy-207965 | ||
3 | Blooblahguy-207965 | Handles updating and visibility of the monk's stagger bar. |
|
4 | Blooblahguy-207965 | ||
5 | Blooblahguy-207965 | Widget |
|
6 | Blooblahguy-207965 | ||
7 | Blooblahguy-207965 | Stagger - A StatusBar |
|
8 | Blooblahguy-207965 | ||
9 | Blooblahguy-207965 | Sub-Widgets |
|
10 | Blooblahguy-207965 | ||
11 | Blooblahguy-207965 | .bg - A Texture that functions as a background. It will inherit the color |
|
12 | Blooblahguy-207965 | of the main StatusBar. |
|
13 | Blooblahguy-207965 | ||
14 | Blooblahguy-207965 | Notes |
|
15 | Blooblahguy-207965 | ||
16 | Blooblahguy-207965 | The default StatusBar texture will be applied if the UI widget doesn't have a |
|
17 | Blooblahguy-207965 | status bar texture or color defined. |
|
18 | Blooblahguy-207965 | ||
19 | Blooblahguy-207965 | In order to override the internal update define the 'OnUpdate' script on the |
|
20 | Blooblahguy-207965 | widget in the layout |
|
21 | Blooblahguy-207965 | ||
22 | Blooblahguy-207965 | Sub-Widgets Options |
|
23 | Blooblahguy-207965 | ||
24 | Blooblahguy-207965 | .multiplier - Defines a multiplier, which is used to tint the background based |
|
25 | Blooblahguy-207965 | on the main widgets R, G and B values. Defaults to 1 if not |
|
26 | Blooblahguy-207965 | present. |
|
27 | Blooblahguy-207965 | ||
28 | Blooblahguy-207965 | Examples |
|
29 | Blooblahguy-207965 | ||
30 | Blooblahguy-207965 | local Stagger = CreateFrame('StatusBar', nil, self) |
|
31 | Blooblahguy-207965 | Stagger:SetSize(120, 20) |
|
32 | Blooblahguy-207965 | Stagger:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, 0) |
|
33 | Blooblahguy-207965 | ||
34 | Blooblahguy-207965 | -- Register with oUF |
|
35 | Blooblahguy-207965 | self.Stagger = Stagger |
|
36 | Blooblahguy-207965 | ||
37 | Blooblahguy-207965 | Hooks |
|
38 | Blooblahguy-207965 | ||
39 | Blooblahguy-207965 | OverrideVisibility(self) - Used to completely override the internal visibility |
|
40 | Blooblahguy-207965 | function. Removing the table key entry will make |
|
41 | Blooblahguy-207965 | the element fall-back to its internal function |
|
42 | Blooblahguy-207965 | again. |
|
43 | Blooblahguy-207965 | Override(self) - Used to completely override the internal |
|
44 | Blooblahguy-207965 | update function. Removing the table key entry will |
|
45 | Blooblahguy-207965 | make the element fall-back to its internal function |
|
46 | Blooblahguy-207965 | again. |
|
47 | Blooblahguy-207965 | ]] |
|
48 | Blooblahguy-207965 | ||
49 | Blooblahguy-207965 | local parent, ns = ... |
|
50 | Blooblahguy-207965 | local oUF = ns.oUF |
|
51 | Blooblahguy-207965 | ||
52 | Blooblahguy-207965 | -- percentages at which the bar should change color |
|
53 | Blooblahguy-207965 | local STAGGER_YELLOW_TRANSITION = STAGGER_YELLOW_TRANSITION |
|
54 | Blooblahguy-207965 | local STAGGER_RED_TRANSITION = STAGGER_RED_TRANSITION |
|
55 | Blooblahguy-207965 | ||
56 | Blooblahguy-207965 | -- table indices of bar colors |
|
57 | Blooblahguy-207965 | local GREEN_INDEX = 1; |
|
58 | Blooblahguy-207965 | local YELLOW_INDEX = 2; |
|
59 | Blooblahguy-207965 | local RED_INDEX = 3; |
|
60 | Blooblahguy-207965 | ||
61 | Blooblahguy-207965 | local STANCE_OF_THE_STURY_OX_ID = 23 |
|
62 | Blooblahguy-207965 | ||
63 | Blooblahguy-207965 | local UnitHealthMax = UnitHealthMax |
|
64 | Blooblahguy-207965 | local UnitStagger = UnitStagger |
|
65 | Blooblahguy-207965 | ||
66 | Blooblahguy-207965 | local _, playerClass = UnitClass("player") |
|
67 | Blooblahguy-207965 | ||
68 | Blooblahguy-207965 | -- TODO: fix color in the power element |
|
69 | Blooblahguy-207965 | oUF.colors.power[BREWMASTER_POWER_BAR_NAME] = { |
|
70 | Blooblahguy-207965 | {0.52, 1.0, 0.52}, |
|
71 | Blooblahguy-207965 | {1.0, 0.98, 0.72}, |
|
72 | Blooblahguy-207965 | {1.0, 0.42, 0.42}, |
|
73 | Blooblahguy-207965 | } |
|
74 | Blooblahguy-207965 | local color |
|
75 | Blooblahguy-207965 | ||
76 | Blooblahguy-207965 | local Update = function(self, event, unit) |
|
77 | Blooblahguy-207965 | if unit and unit ~= self.unit then return end |
|
78 | Blooblahguy-207965 | local element = self.Stagger |
|
79 | Blooblahguy-207965 | ||
80 | Blooblahguy-207965 | if(element.PreUpdate) then |
|
81 | Blooblahguy-207965 | element:PreUpdate() |
|
82 | Blooblahguy-207965 | end |
|
83 | Blooblahguy-207965 | ||
84 | Blooblahguy-207965 | local maxHealth = UnitHealthMax("player") |
|
85 | Blooblahguy-207965 | local stagger = UnitStagger("player") |
|
86 | Blooblahguy-207965 | local staggerPercent = stagger / maxHealth |
|
87 | Blooblahguy-207965 | ||
88 | Blooblahguy-207965 | element:SetMinMaxValues(0, maxHealth) |
|
89 | Blooblahguy-207965 | element:SetValue(stagger) |
|
90 | Blooblahguy-207965 | ||
91 | Blooblahguy-207965 | local rgb |
|
92 | Blooblahguy-207965 | if(staggerPercent >= STAGGER_RED_TRANSITION) then |
|
93 | Blooblahguy-207965 | rgb = color[RED_INDEX] |
|
94 | Blooblahguy-207965 | elseif(staggerPercent > STAGGER_YELLOW_TRANSITION) then |
|
95 | Blooblahguy-207965 | rgb = color[YELLOW_INDEX] |
|
96 | Blooblahguy-207965 | else |
|
97 | Blooblahguy-207965 | rgb = color[GREEN_INDEX] |
|
98 | Blooblahguy-207965 | end |
|
99 | Blooblahguy-207965 | ||
100 | Blooblahguy-207965 | local r, g, b = rgb[1], rgb[2], rgb[3] |
|
101 | Blooblahguy-207965 | element:SetStatusBarColor(r, g, b) |
|
102 | Blooblahguy-207965 | ||
103 | Blooblahguy-207965 | local bg = element.bg |
|
104 | Blooblahguy-207965 | if(bg) then |
|
105 | Blooblahguy-207965 | local mu = bg.multiplier or 1 |
|
106 | Blooblahguy-207965 | bg:SetVertexColor(r * mu, g * mu, b * mu) |
|
107 | Blooblahguy-207965 | end |
|
108 | Blooblahguy-207965 | ||
109 | Blooblahguy-207965 | if(element.PostUpdate) then |
|
110 | Blooblahguy-207965 | element:PostUpdate(maxHealth, stagger, staggerPercent, r, g, b) |
|
111 | Blooblahguy-207965 | end |
|
112 | Blooblahguy-207965 | end |
|
113 | Blooblahguy-207965 | ||
114 | Blooblahguy-207965 | local Path = function(self, ...) |
|
115 | Blooblahguy-207965 | return (self.Stagger.Override or Update)(self, ...) |
|
116 | Blooblahguy-207965 | end |
|
117 | Blooblahguy-207965 | ||
118 | Blooblahguy-207965 | local Visibility = function(self, event, unit) |
|
119 | Blooblahguy-207965 | if(STANCE_OF_THE_STURY_OX_ID ~= GetShapeshiftFormID() or UnitHasVehiclePlayerFrameUI("player")) then |
|
120 | Blooblahguy-207965 | if self.Stagger:IsShown() then |
|
121 | Blooblahguy-207965 | self.Stagger:Hide() |
|
122 | Blooblahguy-207965 | self:UnregisterEvent('UNIT_AURA', Path) |
|
123 | Blooblahguy-207965 | end |
|
124 | Blooblahguy-207965 | elseif not self.Stagger:IsShown() then |
|
125 | Blooblahguy-207965 | self.Stagger:Show() |
|
126 | Blooblahguy-207965 | self:RegisterEvent('UNIT_AURA', Path) |
|
127 | Blooblahguy-207965 | return Path(self, event, unit) |
|
128 | Blooblahguy-207965 | end |
|
129 | Blooblahguy-207965 | end |
|
130 | Blooblahguy-207965 | ||
131 | Blooblahguy-207965 | local VisibilityPath = function(self, ...) |
|
132 | Blooblahguy-207965 | return (self.Stagger.OverrideVisibility or Visibility)(self, ...) |
|
133 | Blooblahguy-207965 | end |
|
134 | Blooblahguy-207965 | ||
135 | Blooblahguy-207965 | local ForceUpdate = function(element) |
|
136 | Blooblahguy-207965 | return VisibilityPath(element.__owner, "ForceUpdate", element.__owner.unit) |
|
137 | Blooblahguy-207965 | end |
|
138 | Blooblahguy-207965 | ||
139 | Blooblahguy-207965 | local Enable = function(self, unit) |
|
140 | Blooblahguy-207965 | if(playerClass ~= "MONK") then return end |
|
141 | Blooblahguy-207965 | ||
142 | Blooblahguy-207965 | local element = self.Stagger |
|
143 | Blooblahguy-207965 | if(element) then |
|
144 | Blooblahguy-207965 | element.__owner = self |
|
145 | Blooblahguy-207965 | element.ForceUpdate = ForceUpdate |
|
146 | Blooblahguy-207965 | element:Hide() |
|
147 | Blooblahguy-207965 | ||
148 | Blooblahguy-207965 | color = self.colors.power[BREWMASTER_POWER_BAR_NAME] |
|
149 | Blooblahguy-207965 | ||
150 | Blooblahguy-207965 | self:RegisterEvent('UNIT_DISPLAYPOWER', VisibilityPath) |
|
151 | Blooblahguy-207965 | self:RegisterEvent('UPDATE_SHAPESHIFT_FORM', VisibilityPath) |
|
152 | Blooblahguy-207965 | ||
153 | Blooblahguy-207965 | if(element:IsObjectType'StatusBar' and not element:GetStatusBarTexture()) then |
|
154 | Blooblahguy-207965 | element:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]] |
|
155 | Blooblahguy-207965 | end |
|
156 | Blooblahguy-207965 | ||
157 | Blooblahguy-207965 | MonkStaggerBar.Show = MonkStaggerBar.Hide |
|
158 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'PLAYER_ENTERING_WORLD' |
|
159 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'PLAYER_SPECIALIZATION_CHANGED' |
|
160 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'UNIT_DISPLAYPOWER' |
|
161 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'UPDATE_VEHICLE_ACTION_BAR' |
|
162 | Blooblahguy-207965 | ||
163 | Blooblahguy-207965 | return true |
|
164 | Blooblahguy-207965 | end |
|
165 | Blooblahguy-207965 | end |
|
166 | Blooblahguy-207965 | ||
167 | Blooblahguy-207965 | local Disable = function(self) |
|
168 | Blooblahguy-207965 | local element = self.Stagger |
|
169 | Blooblahguy-207965 | if(element) then |
|
170 | Blooblahguy-207965 | element:Hide() |
|
171 | Blooblahguy-207965 | self:UnregisterEvent('UNIT_AURA', Path) |
|
172 | Blooblahguy-207965 | self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath) |
|
173 | Blooblahguy-207965 | self:UnregisterEvent('UPDATE_SHAPESHIFT_FORM', VisibilityPath) |
|
174 | Blooblahguy-207965 | ||
175 | Blooblahguy-207965 | MonkStaggerBar.Show = nil |
|
176 | Blooblahguy-207965 | MonkStaggerBar:Show() |
|
177 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'PLAYER_ENTERING_WORLD' |
|
178 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'PLAYER_SPECIALIZATION_CHANGED' |
|
179 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'UNIT_DISPLAYPOWER' |
|
180 | Blooblahguy-207965 | MonkStaggerBar:UnregisterEvent'UPDATE_VEHICLE_ACTION_BAR' |
|
181 | Blooblahguy-207965 | end |
|
182 | Blooblahguy-207965 | end |
|
183 | Blooblahguy-207965 | ||
184 | Blooblahguy-207965 | oUF:AddElement("Stagger", VisibilityPath, Enable, Disable) |