Mercurial > wow > buffalo2
comparison Modules/WorldState.lua @ 89:74e714637d6a
WorldStateProgress fade-in is called for all visibility check falses
| author | Nenue |
|---|---|
| date | Fri, 21 Oct 2016 18:03:35 -0400 |
| parents | b107b4df7eb6 |
| children | 6e2cb847c3c6 |
comparison
equal
deleted
inserted
replaced
| 88:b107b4df7eb6 | 89:74e714637d6a |
|---|---|
| 9 anchorPoint = 'TOP', | 9 anchorPoint = 'TOP', |
| 10 } | 10 } |
| 11 VeneerWorldStateCurrencyMixin = { | 11 VeneerWorldStateCurrencyMixin = { |
| 12 } | 12 } |
| 13 VeneerWorldStateProgressMixin = { | 13 VeneerWorldStateProgressMixin = { |
| 14 keepOpen = true | 14 keepOpen = true, |
| 15 } | 15 } |
| 16 VeneerWorldStateMixin = { | 16 VeneerWorldStateMixin = { |
| 17 maxHeight = 0, | 17 maxHeight = 0, |
| 18 detectedFrames = {}, | 18 detectedFrames = {}, |
| 19 anchorPoint = 'TOP', | 19 anchorPoint = 'TOP', |
| 105 end | 105 end |
| 106 | 106 |
| 107 function VeneerWorldStateMixin:Reanchor(isUpdate) | 107 function VeneerWorldStateMixin:Reanchor(isUpdate) |
| 108 print(' |cFF0088FF'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks') | 108 print(' |cFF0088FF'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks') |
| 109 self.maxHeight = 0 | 109 self.maxHeight = 0 |
| 110 local lastFrame | |
| 110 for i, frame in ipairs(self.modules) do | 111 for i, frame in ipairs(self.modules) do |
| 111 print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) | 112 print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) |
| 112 if frame:IsShown() then | 113 if frame:IsShown() then |
| 113 self.maxHeight = max(self.maxHeight, frame:GetHeight()) | 114 if lastFrame then |
| 115 frame:SetPoint('TOP', lastFrame, 'BOTTOM') | |
| 116 else | |
| 117 frame:SetPoint('TOP', self, 'TOP') | |
| 118 end | |
| 119 | |
| 120 self.maxHeight = self.maxHeight + frame:GetHeight() | |
| 121 lastFrame = frame | |
| 114 end | 122 end |
| 115 end | 123 end |
| 116 if self.maxHeight == 0 then | 124 if self.maxHeight == 0 then |
| 117 print (' hiding because there are no blocks') | 125 print (' hiding because there are no blocks') |
| 118 self:Hide() | 126 self:Hide() |
| 177 print(debugstack(6)) | 185 print(debugstack(6)) |
| 178 | 186 |
| 179 end | 187 end |
| 180 | 188 |
| 181 function VeneerWorldStateCurrencyMixin:OnLoad () | 189 function VeneerWorldStateCurrencyMixin:OnLoad () |
| 182 | |
| 183 self:RegisterEvent("PLAYER_ENTERING_WORLD"); | 190 self:RegisterEvent("PLAYER_ENTERING_WORLD"); |
| 184 self:RegisterEvent("ZONE_CHANGED"); | 191 self:RegisterEvent("ZONE_CHANGED"); |
| 185 self:RegisterEvent("ZONE_CHANGED_INDOORS"); | 192 self:RegisterEvent("ZONE_CHANGED_INDOORS"); |
| 186 self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); | 193 self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); |
| 187 self:RegisterEvent('CURRENCY_DISPLAY_UPDATE') | 194 self:RegisterEvent('CURRENCY_DISPLAY_UPDATE') |
| 188 self:RegisterEvent('CHAT_MSG_CURRENCY') | 195 self:RegisterEvent('CHAT_MSG_CURRENCY') |
| 189 | |
| 190 end | 196 end |
| 191 | 197 |
| 192 function VeneerWorldStateCurrencyMixin:OnEvent (event, arg) | 198 function VeneerWorldStateCurrencyMixin:OnEvent (event, arg) |
| 193 self:Update() | 199 self:Update() |
| 194 end | 200 end |
| 202 | 208 |
| 203 self.Icon:SetTexture(texture) | 209 self.Icon:SetTexture(texture) |
| 204 self.Label:SetFormattedText("%d / %d", earned, totalMax) | 210 self.Label:SetFormattedText("%d / %d", earned, totalMax) |
| 205 self:Show() | 211 self:Show() |
| 206 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) | 212 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) |
| 207 self:SetSize(200,16) | |
| 208 else | 213 else |
| 209 self:Hide() | 214 self:Hide() |
| 210 end | 215 end |
| 211 | 216 |
| 212 | 217 |
| 290 end | 295 end |
| 291 | 296 |
| 292 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | 297 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo |
| 293 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | 298 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank |
| 294 | 299 |
| 295 function VeneerWorldStateProgressMixin:AnimateProgress(progressChange) | 300 |
| 296 | 301 local progressHandlers = { |
| 297 local progressWidth = self:GetWidth() * progressChange | 302 xp = function(self) |
| 298 | 303 local hasNewInfo, showChange = false, false |
| 299 print(' Render change:', progressChange, progressWidth) | |
| 300 self.ProgressAdded:Show() | |
| 301 self.ProgressAdded:ClearAllPoints() | |
| 302 self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0) | |
| 303 self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (progressWidth), 0) | |
| 304 | |
| 305 | |
| 306 self.ProgressFlash.translation:SetOffset(progressWidth, 0) | |
| 307 self.ProgressFlash:Play() | |
| 308 end | |
| 309 | |
| 310 function VeneerWorldStateProgressMixin:Update(isBatchUpdate) | |
| 311 local hasNewInfo = false | |
| 312 local progressChange = false | |
| 313 print(' current mode:', self.mode) | |
| 314 | |
| 315 | |
| 316 if self.mode == 'xp' then | |
| 317 local xp = UnitXP('player') | 304 local xp = UnitXP('player') |
| 318 local xpMax = UnitXPMax('player') | 305 local xpMax = UnitXPMax('player') |
| 319 local bonusXP = GetXPExhaustion() | 306 local bonusXP = GetXPExhaustion() |
| 320 if xp then | 307 if xp then |
| 321 self.progressPercent = xp / xpMax | 308 self.progressPercent = xp / xpMax |
| 322 end | 309 end |
| 323 self.progressText = '|cFFFFCC00' .. UnitLevel('player') .. '|r ' .. xp .. '/' .. xpMax | 310 self.progressText = '|cFFFFCC00' .. UnitLevel('player') .. '|r ' .. xp .. '/' .. xpMax |
| 324 if bonusXP then | 311 if bonusXP then |
| 325 self.ProgressBar:SetColorTexture(0, 0.5,1) | 312 self.progressOverflow = min(1,(bonusXP / xpMax)) |
| 326 self.OverflowBar:Show() | 313 self.OverflowBar:SetColorTexture(0.5, 0.5,0.5, 0.25) |
| 327 self.OverflowBar:ClearAllPoints() | 314 self.OverflowBar:SetPoint('LEFT', self.ProgressBar, 'LEFT') |
| 328 self.OverflowBar:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', 0, 0) | |
| 329 else | 315 else |
| 330 self.ProgressBar:SetColorTexture(0.5,0,1) | 316 self.progressOverflow = nil |
| 331 end | 317 end |
| 332 hasNewInfo = (self.progressAmount ~= xp) | 318 self.ProgressBar:SetColorTexture(0, 0.5,1,1) |
| 333 progressChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax) | 319 self.OverflowAnchor = self.ProgressBar |
| 334 self.progressOverflow = bonusXP or 0 | 320 self.hasNewInfo = (self.progressAmount ~= xp) |
| 321 showChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax) | |
| 322 | |
| 335 self.progressAmount = xp | 323 self.progressAmount = xp |
| 336 self.progressMax = xpMax | 324 self.progressMax = xpMax |
| 337 | 325 return hasNewInfo, showChange |
| 338 elseif self.mode == 'artifact' then | 326 end, |
| 327 artifact = function(self) | |
| 328 local hasNewInfo, showChange = false, false | |
| 339 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() | 329 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() |
| 340 | |
| 341 if itemID then | 330 if itemID then |
| 342 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 | 331 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 |
| 343 print(' API:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost) | 332 print(' API:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost) |
| 344 hasNewInfo = (self.progressAmount ~= totalXP) | 333 hasNewInfo = (self.progressAmount ~= totalXP) |
| 345 progressChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost)) | 334 showChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost)) |
| 346 | 335 |
| 347 if totalXP > nextRankCost then | 336 if totalXP > nextRankCost then |
| 348 self.progressPercent = 1 | 337 self.progressPercent = 1 |
| 349 else | 338 else |
| 350 self.progressPercent = totalXP / nextRankCost | 339 self.progressPercent = totalXP / nextRankCost |
| 353 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost | 342 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost |
| 354 | 343 |
| 355 self.ProgressBar:SetColorTexture(1,0.5,0,1) | 344 self.ProgressBar:SetColorTexture(1,0.5,0,1) |
| 356 self.OverflowBar:Hide() | 345 self.OverflowBar:Hide() |
| 357 | 346 |
| 358 self.progressOverflow = 0 | 347 if totalXP > nextRankCost then |
| 348 self.progressText = self.progressText .. ' Level Up!' | |
| 349 self.progressOverflow = (totalXP - nextRankCost) / nextRankCost | |
| 350 self.OverflowBar:SetPoint('LEFT', self.ProgressBG, 'LEFT') | |
| 351 self.OverflowAnchor = self.OverflawBar | |
| 352 else | |
| 353 self.progressOverflow = nil | |
| 354 self.OverflowAnchor = self.ProgressBar | |
| 355 end | |
| 356 | |
| 359 self.progressAmount = totalXP | 357 self.progressAmount = totalXP |
| 360 self.progressMax = nextRankCost | 358 self.progressMax = nextRankCost |
| 361 else | 359 else |
| 362 self.progressOverflow = 0 | 360 self.progressOverflow = nil |
| 363 self.progressAmount = 0 | 361 self.progressAmount = 0 |
| 364 self.progressMax = 1 | 362 self.progressMax = 1 |
| 365 self.progressText = '' | 363 self.progressText = '' |
| 366 end | 364 end |
| 367 end | 365 return hasNewInfo, showChange |
| 368 | 366 end |
| 369 if self.mode then | 367 } |
| 370 self:SetSize(600,16) | 368 |
| 371 if hasNewInfo then | 369 function VeneerWorldStateProgressMixin:Update(isBatchUpdate) |
| 372 self.timeOut = nil | 370 |
| 373 self.timeLived = 0 | 371 local progressChange = false |
| 374 if self.TransitionFadeOut:IsPlaying() then | 372 print(' current mode:', self.mode) |
| 375 self.TransitionFadeOut:Stop() | 373 if (not self.mode) or (not progressHandlers[self.mode]) then |
| 376 self:SetAlpha(1) | 374 self:HidePanel() |
| 377 end | 375 return |
| 378 if not self:IsVisible() then | 376 end |
| 379 self.TransitionFadeIn:Play() | 377 |
| 380 else | 378 local hasNewInfo, showProgress = progressHandlers[self.mode](self) |
| 381 self:ShowPanel() | 379 self:SetSize(600,16) |
| 382 end | 380 if hasNewInfo then |
| 383 | 381 self.timeOut = nil |
| 384 end | 382 self.timeLived = 0 |
| 385 | 383 end |
| 386 | 384 |
| 387 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'new:', hasNewInfo, 'shown:', self:IsShown()) | 385 if not self:IsVisible() then |
| 388 print(' Metrics:', self:IsVisible(), self:GetWidth(), self.ProgressBG:GetWidth()) | 386 self.TransitionFadeIn:Play() |
| 387 else | |
| 388 self:ShowPanel() | |
| 389 end | |
| 390 | |
| 391 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'new:', hasNewInfo, 'shown:', self:IsShown()) | |
| 392 print(' Metrics:', self:IsVisible(), self:GetWidth(), self.ProgressBG:GetWidth()) | |
| 393 if self.progressPercent > 0 then | |
| 394 self.ProgressBar:Show() | |
| 395 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0) | |
| 396 self.Label:SetText(self.progressText) | |
| 397 | |
| 398 self.ProgressSpark:ClearAllPoints() | |
| 399 if self.progressOverflow then | |
| 400 print(' Overflow:', self.progressOverflow) | |
| 401 self.OverflowBar:Show() | |
| 402 self.OverflowBar:SetWidth(self.progressOverflow * self:GetWidth(), 0) | |
| 403 else | |
| 404 self.OverflowBar:Hide() | |
| 405 end | |
| 406 self.ProgressSpark:SetPoint('CENTER', self.OverflowAnchor, 'RIGHT', 0, 0) | |
| 407 | |
| 408 else | |
| 409 self.ProgressBar:Hide() | |
| 410 end | |
| 411 | |
| 412 if self.progressOverflow and (self.progressOverflow >= self.progressPercent) then | |
| 413 self.OverflowBar:SetDrawLayer('ARTWORK', 1) | |
| 414 self.ProgressBar:SetDrawLayer('ARTWORK', 2) | |
| 415 else | |
| 416 self.OverflowBar:SetDrawLayer('ARTWORK', 2) | |
| 417 self.ProgressBar:SetDrawLayer('ARTWORK', 1) | |
| 418 end | |
| 389 | 419 |
| 390 if progressChange then | 420 if progressChange then |
| 391 self:AnimateProgress(progressChange) | 421 self:AnimateProgress(progressChange) |
| 392 end | |
| 393 | |
| 394 | |
| 395 if self.progressPercent > 0 then | |
| 396 self.ProgressBar:Show() | |
| 397 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0) | |
| 398 self.Label:SetText(self.progressText) | |
| 399 | |
| 400 self.progressLeft = self.progressMax - self.progressAmount | |
| 401 if self.progressOverflow >= self.progressLeft then | |
| 402 | |
| 403 self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0) | |
| 404 else | |
| 405 self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', (self.progressOverflow / self.progressMax) * self:GetWidth(), 0) | |
| 406 end | |
| 407 | |
| 408 else | |
| 409 self.ProgressBar:Hide() | |
| 410 end | |
| 411 else | |
| 412 self:HidePanel() | |
| 413 end | 422 end |
| 414 | 423 |
| 415 self.modeChanged = nil | 424 self.modeChanged = nil |
| 425 end | |
| 426 | |
| 427 | |
| 428 function VeneerWorldStateProgressMixin:AnimateProgress(progressChange) | |
| 429 | |
| 430 | |
| 431 local changeAnchor = (self.progressOverflow and self.OverflowBar) or self.ProgressBar | |
| 432 local progressWidth = self:GetWidth() * min(progressChange, changeAnchor:GetWidth()) | |
| 433 | |
| 434 self.ProgressAdded:Show() | |
| 435 self.ProgressAdded:ClearAllPoints() | |
| 436 self.ProgressAdded:SetPoint('TOPRIGHT', changeAnchor, 'TOPRIGHT', 0, 0) | |
| 437 self.ProgressAdded:SetPoint('BOTTOMLEFT', changeAnchor, 'BOTTOMRIGHT', - (progressWidth), 0) | |
| 438 | |
| 439 print(' Render change:', progressWidth, changeAnchor) | |
| 440 self.ProgressFlash.translation:SetOffset(progressWidth, 0) | |
| 441 self.ProgressFlash:Play() | |
| 416 end | 442 end |
| 417 | 443 |
| 418 function VeneerWorldStateProgressMixin:OnMouseDown(button) | 444 function VeneerWorldStateProgressMixin:OnMouseDown(button) |
| 419 if button == 'RightButton' then | 445 if button == 'RightButton' then |
| 420 if self.keepOpen then | 446 if self.keepOpen then |
| 423 else | 449 else |
| 424 self.keepOpen = true | 450 self.keepOpen = true |
| 425 end | 451 end |
| 426 print('keepOpen =', self.keepOpen) | 452 print('keepOpen =', self.keepOpen) |
| 427 else | 453 else |
| 454 | |
| 428 if self.mode == 'xp' then | 455 if self.mode == 'xp' then |
| 429 self.mode = 'artifact' | 456 self.mode = 'artifact' |
| 430 else | 457 else |
| 431 if not self.canGainXP then | 458 if not self.canGainXP then |
| 432 return | 459 return |
| 433 end | 460 end |
| 434 self.mode = 'xp' | 461 self.mode = 'xp' |
| 435 end | 462 end |
| 463 print('|cFFFF4400Change mode:', self.mode) | |
| 464 | |
| 465 | |
| 436 self:AnimateMode() | 466 self:AnimateMode() |
| 437 end | 467 end |
| 438 | 468 |
| 439 end | 469 end |
| 440 | 470 |
