Mercurial > wow > buffalo2
comparison Modules/OrderHall.lua @ 82:be813a9d99c0
- order of operations regarding frame visibility checking
- interaction with WorldPlan OrderHall module
- fancy shmancy transition fades resulting from above
author | Nenue |
---|---|
date | Mon, 17 Oct 2016 13:00:26 -0400 |
parents | 65ec88b30eb8 |
children | 4ec4fd89fced |
comparison
equal
deleted
inserted
replaced
81:65ec88b30eb8 | 82:be813a9d99c0 |
---|---|
5 -- | 5 -- |
6 | 6 |
7 VeneerWorldStateCurrencyMixin = {} | 7 VeneerWorldStateCurrencyMixin = {} |
8 VeneerWorldStateProgressMixin = {} | 8 VeneerWorldStateProgressMixin = {} |
9 VeneerWorldStateMixin = { | 9 VeneerWorldStateMixin = { |
10 maxHeight = 0, | |
10 detectedFrames = {} | 11 detectedFrames = {} |
11 } | 12 } |
12 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop | 13 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop |
13 | 14 |
14 function VeneerWorldStateMixin:Setup() | 15 function VeneerWorldStateMixin:Setup() |
15 self:Refresh() | |
16 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') | 16 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') |
17 print('All:Setup()') | 17 print('All:Setup()') |
18 | 18 |
19 self.modules = self.modules or {self:GetChildren()} | 19 self.modules = self.modules or {self:GetChildren()} |
20 for i, frame in ipairs(self.modules) do | 20 for i, frame in ipairs(self.modules) do |
21 if frame.Setup then | 21 if frame.Setup then |
22 frame:Setup() | 22 frame:Setup() |
23 end | 23 end |
24 end | 24 |
25 end | 25 frame:SetScript('OnSizeChanged', function() |
26 | 26 local h = frame:GetHeight() |
27 function VeneerWorldStateMixin:Refresh() | 27 if h > self.maxHeight then |
28 self.maxHeight = h | |
29 self:SetHeight(h) | |
30 print('updating max height:', h) | |
31 elseif h < self.maxHeight then | |
32 self:UpdateSize() | |
33 end | |
34 end) | |
35 frame:SetScript('OnHide', function() | |
36 print('|cFF0088FF'..frame:GetName()..':OnHide()') | |
37 self:UpdateSize() | |
38 end) | |
39 frame:SetScript('OnShow', function() | |
40 frame.timeLived = 0 | |
41 print('|cFF0088FF'..frame:GetName()..':OnShow()') | |
42 self:UpdateSize() | |
43 end) | |
44 | |
45 function frame.ShowPanel(frame) | |
46 frame:SetShown(true) | |
47 self:Show() | |
48 end | |
49 end | |
50 self:SetOrderHallUIMods() | |
51 end | |
52 | |
53 function VeneerWorldStateMixin:SetOrderHallUIMods() | |
28 if OrderHallCommandBar then | 54 if OrderHallCommandBar then |
29 if not self.detectedFrames[OrderHallCommandBar] then | 55 if not self.detectedFrames[OrderHallCommandBar] then |
30 self.detectedFrames[OrderHallCommandBar] = true | 56 self.detectedFrames[OrderHallCommandBar] = true |
31 hooksecurefunc(OrderHallCommandBar,'Show', function() | 57 hooksecurefunc(OrderHallCommandBar,'Show', function() |
32 self:Refresh() | 58 self:SetOrderHallUIMods() |
59 end) | |
60 hooksecurefunc(OrderHallCommandBar,'Hide', function() | |
61 self:SetOrderHallUIMods() | |
33 end) | 62 end) |
34 end | 63 end |
35 | 64 |
36 | 65 |
37 OrderHallCommandBar:ClearAllPoints() | 66 OrderHallCommandBar:ClearAllPoints() |
38 OrderHallCommandBar:SetPoint('TOP') | 67 OrderHallCommandBar:SetPoint('TOP') |
39 OrderHallCommandBar:SetWidth(600) | 68 OrderHallCommandBar:SetWidth(600) |
40 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) | 69 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) |
41 OrderHallCommandBar.WorldMapButton:Hide() | 70 OrderHallCommandBar.WorldMapButton:Hide() |
42 OrderHallCommandBar:EnableMouse(false) | 71 OrderHallCommandBar:EnableMouse(false) |
43 end | 72 |
44 | 73 if OrderHallCommandBar:IsVisible() then |
74 self:SetPoint('TOP', OrderHallCommandBar, 'BOTTOM') | |
75 print('anchoring to CommandBar') | |
76 else | |
77 self:SetPoint('TOP', UIParent, 'TOP') | |
78 print('anchoring to UIParent') | |
79 end | |
80 else | |
81 self:SetPoint('TOP', UIParent, 'TOP') | |
82 print('anchoring to UIParent') | |
83 end | |
45 end | 84 end |
46 local initialized | 85 local initialized |
47 function VeneerWorldStateMixin:OnEvent(event, arg) | 86 function VeneerWorldStateMixin:OnEvent(event, arg) |
48 print(event, arg) | 87 print(event, arg) |
49 | 88 |
51 if IsLoggedIn() then | 90 if IsLoggedIn() then |
52 initialized = true | 91 initialized = true |
53 self:Setup() | 92 self:Setup() |
54 self:UnregisterEvent('PLAYER_LOGIN') | 93 self:UnregisterEvent('PLAYER_LOGIN') |
55 end | 94 end |
56 end | 95 elseif event == 'ADDON_LOADED' then |
57 | 96 if initialized and IsAddOnLoaded('Blizzard_OrderHallUI') then |
58 if event == 'PLAYER_ENTERING_WORLD' then | 97 self:SetOrderHallUIMods() |
98 end | |
99 elseif event == 'PLAYER_ENTERING_WORLD' then | |
59 self:Update() | 100 self:Update() |
60 elseif event == 'PLAYER_REGEN_ENABLED' then | 101 elseif event == 'PLAYER_REGEN_ENABLED' then |
61 self:Show() | 102 self:Show() |
62 elseif event == 'PLAYER_REGEN_DISABLED' then | 103 elseif event == 'PLAYER_REGEN_DISABLED' then |
63 self:Hide() | 104 self:Hide() |
64 end | 105 end |
65 end | 106 end |
66 | 107 |
67 function VeneerWorldStateMixin:Update() | 108 function VeneerWorldStateMixin:Update() |
68 self.modules = self.modules or {self:GetChildren()} | 109 self.modules = {self:GetChildren()} |
69 print('|cFFFFFF00All:Update()|r') | 110 print('|cFFFFFF00All:Update()|r') |
111 print(self:GetChildren()) | |
112 for i, frame in ipairs(self.modules) do | |
113 if frame.Update then | |
114 print(' |cFFFF00FF'.. frame:GetName() .. ':Update()') | |
115 frame:Update() | |
116 end | |
117 end | |
118 self:SetOrderHallUIMods() | |
119 end | |
120 | |
121 function VeneerWorldStateMixin:UpdateSize() | |
122 print('|cFFFFFF00All:UpdateSize()|r') | |
123 print(self:GetChildren()) | |
124 self.modules = {self:GetChildren()} | |
70 self.maxHeight = 0 | 125 self.maxHeight = 0 |
71 for i, frame in ipairs(self.modules) do | 126 for i, frame in ipairs(self.modules) do |
72 if frame.Update then | 127 print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) |
73 print(frame:GetName()) | 128 if frame:IsShown() then |
74 frame:Update() | 129 self.maxHeight = max(self.maxHeight, frame:GetHeight()) |
75 if frame:IsVisible() then | 130 end |
76 self.maxHeight = max(self.maxHeight, frame.maxHeight) | 131 end |
77 end | 132 if self.maxHeight == 0 then |
78 end | 133 print ('height zero') |
79 end | 134 self:Hide() |
80 self:SetHeight(self.maxHeight) | 135 else |
136 self:Show() | |
137 print ('height update:', self.maxHeight) | |
138 self:SetHeight(self.maxHeight) | |
139 end | |
140 | |
81 end | 141 end |
82 | 142 |
83 | 143 |
84 | 144 |
85 function VeneerWorldStateMixin:OnLoad () | 145 function VeneerWorldStateMixin:OnLoad () |
105 end | 165 end |
106 | 166 |
107 | 167 |
108 function VeneerWorldStateCurrencyMixin:Update() | 168 function VeneerWorldStateCurrencyMixin:Update() |
109 | 169 |
110 print('currency refresh: zone =', mapID) | 170 print(' Zone:', GetZoneText()) |
111 if GetZoneText() == 'Suramar' then | 171 if GetZoneText() == 'Suramar' then |
112 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(1155) | 172 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(1155) |
113 | 173 |
114 self.Icon:SetTexture(texture) | 174 self.Icon:SetTexture(texture) |
115 self.Label:SetFormattedText("%d / %d", earned, totalMax) | 175 self.Label:SetFormattedText("%d / %d", earned, totalMax) |
116 self:Show() | 176 self:Show() |
117 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) | 177 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) |
178 self:SetSize(200,16) | |
118 else | 179 else |
119 self:Hide() | 180 self:Hide() |
120 end | 181 end |
121 | 182 |
122 self.maxHeight = self:GetHeight() | 183 |
123 end | 184 end |
185 | |
186 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast) | |
187 self.timeLived = (self.timeLived or 0) + sinceLast | |
188 if self.timeLived >= 3 and not self.TransitionFadeOut:IsPlaying() then | |
189 if not self.timeOut then | |
190 self.timeOut = true | |
191 self.TransitionFadeOut:Play() | |
192 end | |
193 end | |
194 end | |
195 | |
124 | 196 |
125 function VeneerWorldStateProgressMixin:OnLoad() | 197 function VeneerWorldStateProgressMixin:OnLoad() |
126 self:RegisterEvent('PLAYER_XP_UPDATE') | 198 self:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') |
127 self:RegisterEvent('PLAYER_LEVEL_UP') | 199 |
128 self:RegisterEvent('PLAYER_UPDATE_RESTING') | 200 self:RegisterEvent("PLAYER_XP_UPDATE"); |
129 self:RegisterEvent('ENABLE_XP_GAIN') | 201 self:RegisterEvent("UPDATE_EXHAUSTION"); |
130 self:RegisterEvent('DISABLE_XP_GAIN') | 202 self:RegisterEvent("PLAYER_LEVEL_UP"); |
131 self:RegisterEvent('PLAYER_LOGIN') | 203 self:RegisterEvent("PLAYER_UPDATE_RESTING"); |
132 self:RegisterEvent('ARTIFACT_UPDATE') | 204 |
133 self:RegisterEvent('ARTIFACT_XP_UPDATE') | 205 self:RegisterEvent("ARTIFACT_UPDATE"); |
134 | 206 self:RegisterEvent("ARTIFACT_XP_UPDATE"); |
135 end | 207 self:RegisterEvent("ARTIFACT_CLOSE"); |
136 | 208 self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE"); |
137 function VeneerWorldStateProgressMixin:Setup() | |
138 self:UpdateXPGain() | |
139 if UnitLevel('player') < GetMaxPlayerLevel() then | |
140 self.mode = 'xp' | |
141 else | |
142 self.mode = 'artifact' | |
143 end | |
144 print('setup mode:', self.mode) | |
145 self:Update() | |
146 end | |
147 | |
148 function VeneerWorldStateProgressMixin:OnEvent(event) | |
149 if event == 'ENABLE_XP_GAIN' or event == 'DISABLE_XP_GAIN' then | |
150 self:UpdateXPGain() | |
151 elseif event == 'ARTIFACT_XP_UPDATE' or event == 'ARTIFACT_UPDATE' then | |
152 self.mode = 'artifact' | |
153 elseif event == 'PLAYER_XP_UPDATE' or 'PLAYER_LEVEL_UP' then | |
154 self.mode = 'xp' | |
155 end | |
156 | |
157 | |
158 self:Update() | |
159 | |
160 end | |
161 function VeneerWorldStateProgressMixin:UpdateXPGain() | |
162 if IsXPUserDisabled() then | |
163 self.ProgressBar:SetColorTexture(0.75,0.75,0.75) | |
164 self.mode = nil | |
165 else | |
166 self.ProgressBar:SetColorTexture(1,1,1) | |
167 end | |
168 end | |
169 | |
170 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | |
171 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | |
172 function VeneerWorldStateProgressMixin:Update() | |
173 | |
174 if not self.mode then | |
175 if UnitLevel('player') < GetMaxPlayerLevel() then | |
176 self.mode = 'xp' | |
177 else | |
178 self.mode = 'artifact' | |
179 end | |
180 end | |
181 | |
182 | 209 |
183 self.progressPercent = 0 | 210 self.progressPercent = 0 |
184 self.progressAmount = 0 | 211 self.progressAmount = 0 |
185 self.progressMax = 1 | 212 self.progressMax = 1 |
186 self.progressOverflow = 0 | 213 self.progressOverflow = 0 |
214 end | |
215 | |
216 function VeneerWorldStateProgressMixin:Setup() | |
217 self:UpdateXPGain() | |
218 | |
219 if self.canGainXP then | |
220 self.mode = 'xp' | |
221 else | |
222 self.mode = 'artifact' | |
223 end | |
224 print('setup mode:', self.mode) | |
225 end | |
226 | |
227 function VeneerWorldStateProgressMixin:OnEvent(event, ...) | |
228 local lastMode = self.mode | |
229 if event == 'PLAYER_LEVEL_UP' or event == 'ENABLE_XP_GAIN' or event == 'DISABLE_XP_GAIN' then | |
230 self:UpdateXPGain() | |
231 elseif event == 'ARTIFACT_XP_UPDATE' or event == 'ARTIFACT_UPDATE' then | |
232 self.mode = 'artifact' | |
233 | |
234 elseif event == 'PLAYER_EQUIPMENT_CHANGED' then | |
235 local slot, hasEquip = ... | |
236 if slot == 16 then | |
237 self.mode = 'artifact' | |
238 lastMode = nil | |
239 end | |
240 elseif event == 'PLAYER_XP_UPDATE' or event == 'PLAYER_LEVEL_UP' then | |
241 print('forcing to XP mode') | |
242 self.mode = 'xp' | |
243 end | |
244 self.modeChanged = (lastMode ~= self.mode) | |
245 if self.modeChanged and self:IsVisible() then | |
246 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()', event, ...) | |
247 self.TransitionFadeIn:Stop() | |
248 self.TransitionFadeOut:Play() | |
249 else | |
250 print('|cFFFFFF00'..self:GetName()..':Update()', event, ...) | |
251 self:Update() | |
252 end | |
253 end | |
254 function VeneerWorldStateProgressMixin:UpdateXPGain() | |
255 self.canGainXP = (UnitLevel('player') < GetMaxPlayerLevel()) and (not IsXPUserDisabled()) | |
256 if not self.canGainXP then | |
257 self.ProgressBar:SetColorTexture(0.75,0.75,0.75) | |
258 end | |
259 end | |
260 | |
261 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | |
262 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | |
263 function VeneerWorldStateProgressMixin:Update() | |
264 local hasNewInfo = false | |
265 local progressChange = false | |
266 print(' current mode:', self.mode) | |
267 | |
268 | |
187 if self.mode == 'xp' then | 269 if self.mode == 'xp' then |
188 local xp = UnitXP('player') | 270 local xp = UnitXP('player') |
189 local xpMax = UnitXPMax('player') | 271 local xpMax = UnitXPMax('player') |
190 local bonusXP = GetXPExhaustion() | 272 local bonusXP = GetXPExhaustion() |
191 if xp then | 273 if xp then |
192 self.progressPercent = xp / xpMax | 274 self.progressPercent = xp / xpMax |
193 end | 275 end |
276 | |
277 self.progressText = 'Level ' .. UnitLevel('player') .. ': ' .. xp .. '/' .. xpMax | |
278 | |
279 if bonusXP then | |
280 self.ProgressBar:SetColorTexture(0, 0.5,1) | |
281 self.OverflowBar:Show() | |
282 self.OverflowBar:ClearAllPoints() | |
283 self.OverflowBar:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', 0, 0) | |
284 print(bonusXP, (xpMax - xp)) | |
285 if bonusXP < (xpMax - xp) then | |
286 | |
287 self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', (bonusXP / xpMax) * self:GetWidth(), 0) | |
288 else | |
289 self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0) | |
290 end | |
291 else | |
292 self.OverflowBar:Hide() | |
293 self.ProgressBar:SetColorTexture(0.5,0,1) | |
294 end | |
295 hasNewInfo = (self.progressAmount ~= xp) | |
296 | |
297 progressChange = (hasNewInfo and not self.modeChanged) and (xp - self.progressAmount) / self:GetWidth() | |
298 | |
299 | |
300 self.progressAmount = xp | |
301 self.progressMax = xpMax | |
194 elseif self.mode == 'artifact' then | 302 elseif self.mode == 'artifact' then |
195 | 303 |
196 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() | 304 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() |
197 if not itemID then | 305 print(' C_AUI:', itemID, altItemID, name, icon, totalXP, pointsSpent) |
198 self:Hide() | 306 |
199 return | 307 if itemID then |
200 end | 308 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 |
201 | 309 hasNewInfo = (self.progressAmount ~= totalXP) |
202 local pointsAvailable = 0 | 310 progressChange = (hasNewInfo and not self.modeChanged) and (totalXP - self.progressAmount) / self:GetWidth() |
203 | 311 |
204 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 | 312 if totalXP > nextRankCost then |
205 | 313 self.progressPercent = 1 |
206 self.progressAmount = totalXP | 314 self.progressOverflow = totalXP - nextRankCost |
207 self.progressMax = nextRankCost | 315 else |
208 if totalXP > nextRankCost then | 316 self.progressPercent = totalXP / nextRankCost |
209 self.progressPercent = 1 | 317 end |
210 self.progressOverflow = totalXP - nextRankCost | 318 |
319 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost | |
320 | |
321 self.ProgressBar:SetColorTexture(1,0.5,0,1) | |
322 self.OverflowBar:Hide() | |
323 | |
324 | |
325 self.progressAmount = totalXP | |
326 self.progressMax = nextRankCost | |
211 else | 327 else |
212 self.progressPercent = totalXP / nextRankCost | 328 self.progressAmount = 0 |
213 end | 329 self.progressMax = 1 |
214 | 330 self.progressText = '' |
215 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost | 331 end |
332 end | |
333 | |
334 if self.mode then | |
335 self:SetSize(600,16) | |
336 if hasNewInfo then | |
337 self.timeOut = nil | |
338 self.timeLived = 0 | |
339 if self.TransitionFadeOut:IsPlaying() then | |
340 self.TransitionFadeOut:Stop() | |
341 self:SetAlpha(1) | |
342 end | |
343 if not self:IsVisible() then | |
344 self.TransitionFadeIn:Play() | |
345 else | |
346 self:ShowPanel() | |
347 end | |
348 | |
349 end | |
350 | |
351 print(self.ProgressBG:GetWidth()) | |
352 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'NewInfo:', hasNewInfo, 'IsShown:', self:IsShown()) | |
353 | |
354 | |
355 if progressChange then | |
356 print(' Render change:', progressChange) | |
357 self.ProgressAdded:Show() | |
358 self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (self:GetWidth() * progressChange), 0) | |
359 self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0) | |
360 self.ProgressFlash:Play() | |
361 end | |
362 | |
363 | |
364 if self.progressPercent > 0 then | |
365 self.ProgressBar:Show() | |
366 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0) | |
367 | |
368 self.Label:SetText(self.progressText) | |
369 else | |
370 self.ProgressBar:Hide() | |
371 end | |
216 else | 372 else |
217 self:Hide() | 373 self:Hide() |
218 return | 374 end |
219 end | 375 |
220 | 376 self.modeChanged = nil |
221 print(self.progressPercent, floor(self.ProgressBG:GetWidth()* self.progressPercent)) | 377 end |
222 | |
223 if self.progressPercent > 0 then | |
224 self.ProgressBar:Show() | |
225 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self.ProgressBG:GetWidth()* self.progressPercent , 0) | |
226 | |
227 self.Label:SetText(self.progressText) | |
228 else | |
229 self.ProgressBar:Hide() | |
230 end | |
231 | |
232 | |
233 | |
234 self.maxHeight = self:GetHeight() | |
235 end |