Nenue@80: -- Veneer Nenue@84: -- WorldState.lua Nenue@80: -- Created: 10/7/2016 10:55 PM Nenue@80: -- %file-revision% Nenue@80: -- Nenue@80: Nenue@80: VeneerWorldStateCurrencyMixin = {} Nenue@84: VeneerWorldStateProgressMixin = { Nenue@84: keepOpen = true Nenue@84: } Nenue@81: VeneerWorldStateMixin = { Nenue@82: maxHeight = 0, Nenue@81: detectedFrames = {} Nenue@81: } Nenue@80: local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop Nenue@80: Nenue@80: function VeneerWorldStateMixin:Setup() Nenue@80: --DEFAULT_CHAT_FRAME:AddMessage('Loaded') Nenue@84: print('|cFFFFFF00'..self:GetName()..'|r:Setup()') Nenue@81: Nenue@81: self.modules = self.modules or {self:GetChildren()} Nenue@81: for i, frame in ipairs(self.modules) do Nenue@84: print('--'.. frame:GetName()..' exists') Nenue@81: if frame.Setup then Nenue@84: print('--'.. frame:GetName()..':Setup()') Nenue@81: frame:Setup() Nenue@81: end Nenue@82: Nenue@82: frame:SetScript('OnSizeChanged', function() Nenue@82: local h = frame:GetHeight() Nenue@82: if h > self.maxHeight then Nenue@82: self.maxHeight = h Nenue@82: self:SetHeight(h) Nenue@82: print('updating max height:', h) Nenue@82: elseif h < self.maxHeight then Nenue@82: self:UpdateSize() Nenue@82: end Nenue@82: end) Nenue@82: frame:SetScript('OnHide', function() Nenue@82: print('|cFF0088FF'..frame:GetName()..':OnHide()') Nenue@82: self:UpdateSize() Nenue@82: end) Nenue@82: frame:SetScript('OnShow', function() Nenue@82: frame.timeLived = 0 Nenue@82: print('|cFF0088FF'..frame:GetName()..':OnShow()') Nenue@82: self:UpdateSize() Nenue@82: end) Nenue@82: Nenue@82: function frame.ShowPanel(frame) Nenue@82: frame:SetShown(true) Nenue@82: self:Show() Nenue@82: end Nenue@83: function frame.HidePanel(frame) Nenue@83: frame:SetShown(false) Nenue@83: self:UpdateSize() Nenue@83: end Nenue@81: end Nenue@82: self:SetOrderHallUIMods() Nenue@84: self:UnregisterEvent('PLAYER_LOGIN') Nenue@80: end Nenue@80: Nenue@82: function VeneerWorldStateMixin:SetOrderHallUIMods() Nenue@81: if OrderHallCommandBar then Nenue@81: if not self.detectedFrames[OrderHallCommandBar] then Nenue@81: self.detectedFrames[OrderHallCommandBar] = true Nenue@81: hooksecurefunc(OrderHallCommandBar,'Show', function() Nenue@82: self:SetOrderHallUIMods() Nenue@82: end) Nenue@82: hooksecurefunc(OrderHallCommandBar,'Hide', function() Nenue@82: self:SetOrderHallUIMods() Nenue@84: self:UpdateSize() Nenue@81: end) Nenue@81: end Nenue@81: Nenue@81: Nenue@81: OrderHallCommandBar:ClearAllPoints() Nenue@81: OrderHallCommandBar:SetPoint('TOP') Nenue@81: OrderHallCommandBar:SetWidth(600) Nenue@81: OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) Nenue@81: OrderHallCommandBar.WorldMapButton:Hide() Nenue@81: OrderHallCommandBar:EnableMouse(false) Nenue@82: Nenue@82: if OrderHallCommandBar:IsVisible() then Nenue@82: self:SetPoint('TOP', OrderHallCommandBar, 'BOTTOM') Nenue@82: print('anchoring to CommandBar') Nenue@82: else Nenue@82: self:SetPoint('TOP', UIParent, 'TOP') Nenue@82: print('anchoring to UIParent') Nenue@82: end Nenue@84: Nenue@84: self:UnregisterEvent('ADDON_LOADED') Nenue@82: else Nenue@82: self:SetPoint('TOP', UIParent, 'TOP') Nenue@82: print('anchoring to UIParent') Nenue@81: end Nenue@80: end Nenue@84: Nenue@84: Nenue@84: function VeneerWorldStateMixin:OnLoad () Nenue@84: print('|cFFFFFF00'..self:GetName()..'|r!') Nenue@84: self:RegisterEvent('PLAYER_LOGIN') Nenue@84: self:RegisterEvent('ADDON_LOADED') Nenue@84: self:RegisterEvent('ARTIFACT_UPDATE') Nenue@84: self:RegisterEvent('ARTIFACT_XP_UPDATE') Nenue@84: self:RegisterEvent('PLAYER_ENTERING_WORLD') Nenue@84: self:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@84: self:RegisterEvent('PLAYER_REGEN_DISABLED') Nenue@84: end Nenue@84: Nenue@80: function VeneerWorldStateMixin:OnEvent(event, arg) Nenue@80: print(event, arg) Nenue@81: Nenue@84: if event == 'PLAYER_LOGIN' then Nenue@84: if IsLoggedIn() and not self.initialized then Nenue@84: self.initialized = true Nenue@80: self:Setup() Nenue@81: end Nenue@82: elseif event == 'ADDON_LOADED' then Nenue@84: if self.initialized and IsAddOnLoaded('Blizzard_OrderHallUI') then Nenue@82: self:SetOrderHallUIMods() Nenue@82: end Nenue@82: elseif event == 'PLAYER_ENTERING_WORLD' then Nenue@80: self:Update() Nenue@81: elseif event == 'PLAYER_REGEN_ENABLED' then Nenue@83: self:SetShown(true) Nenue@81: elseif event == 'PLAYER_REGEN_DISABLED' then Nenue@83: self:SetShown(false) Nenue@80: end Nenue@80: end Nenue@80: Nenue@80: function VeneerWorldStateMixin:Update() Nenue@82: self.modules = {self:GetChildren()} Nenue@80: print('|cFFFFFF00All:Update()|r') Nenue@82: print(self:GetChildren()) Nenue@82: for i, frame in ipairs(self.modules) do Nenue@82: if frame.Update then Nenue@82: print(' |cFFFF00FF'.. frame:GetName() .. ':Update()') Nenue@82: frame:Update() Nenue@82: end Nenue@82: end Nenue@82: self:SetOrderHallUIMods() Nenue@82: end Nenue@82: Nenue@82: function VeneerWorldStateMixin:UpdateSize() Nenue@82: print('|cFFFFFF00All:UpdateSize()|r') Nenue@82: print(self:GetChildren()) Nenue@82: self.modules = {self:GetChildren()} Nenue@81: self.maxHeight = 0 Nenue@81: for i, frame in ipairs(self.modules) do Nenue@82: print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) Nenue@82: if frame:IsShown() then Nenue@82: self.maxHeight = max(self.maxHeight, frame:GetHeight()) Nenue@80: end Nenue@80: end Nenue@82: if self.maxHeight == 0 then Nenue@82: print ('height zero') Nenue@82: self:Hide() Nenue@82: else Nenue@82: self:Show() Nenue@82: print ('height update:', self.maxHeight) Nenue@82: self:SetHeight(self.maxHeight) Nenue@82: end Nenue@82: Nenue@80: end Nenue@80: Nenue@80: Nenue@80: Nenue@84: function VeneerWorldStateMixin:OnMouseDown() Nenue@80: end Nenue@80: Nenue@80: function VeneerWorldStateCurrencyMixin:OnLoad () Nenue@80: Nenue@84: self:RegisterEvent("PLAYER_ENTERING_WORLD"); Nenue@84: self:RegisterEvent("ZONE_CHANGED"); Nenue@84: self:RegisterEvent("ZONE_CHANGED_INDOORS"); Nenue@84: self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); Nenue@80: self:RegisterEvent('CURRENCY_DISPLAY_UPDATE') Nenue@80: self:RegisterEvent('CHAT_MSG_CURRENCY') Nenue@80: Nenue@80: end Nenue@80: Nenue@80: function VeneerWorldStateCurrencyMixin:OnEvent (event, arg) Nenue@80: self:Update() Nenue@80: end Nenue@80: Nenue@80: Nenue@80: function VeneerWorldStateCurrencyMixin:Update() Nenue@81: Nenue@82: print(' Zone:', GetZoneText()) Nenue@81: if GetZoneText() == 'Suramar' then Nenue@80: local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(1155) Nenue@80: Nenue@80: self.Icon:SetTexture(texture) Nenue@80: self.Label:SetFormattedText("%d / %d", earned, totalMax) Nenue@80: self:Show() Nenue@80: self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) Nenue@82: self:SetSize(200,16) Nenue@80: else Nenue@80: self:Hide() Nenue@80: end Nenue@81: Nenue@82: Nenue@81: end Nenue@81: Nenue@82: function VeneerWorldStateProgressMixin:OnUpdate(sinceLast) Nenue@84: if self.keepOpen then Nenue@84: return Nenue@84: end Nenue@84: Nenue@82: self.timeLived = (self.timeLived or 0) + sinceLast Nenue@82: if self.timeLived >= 3 and not self.TransitionFadeOut:IsPlaying() then Nenue@82: if not self.timeOut then Nenue@82: self.timeOut = true Nenue@84: self.TimedFadeOut:Play() Nenue@82: end Nenue@82: end Nenue@82: end Nenue@82: Nenue@82: Nenue@81: function VeneerWorldStateProgressMixin:OnLoad() Nenue@82: self:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') Nenue@81: Nenue@82: self:RegisterEvent("PLAYER_XP_UPDATE"); Nenue@82: self:RegisterEvent("UPDATE_EXHAUSTION"); Nenue@82: self:RegisterEvent("PLAYER_LEVEL_UP"); Nenue@82: self:RegisterEvent("PLAYER_UPDATE_RESTING"); Nenue@82: Nenue@82: self:RegisterEvent("ARTIFACT_UPDATE"); Nenue@82: self:RegisterEvent("ARTIFACT_XP_UPDATE"); Nenue@82: self:RegisterEvent("ARTIFACT_CLOSE"); Nenue@82: self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE"); Nenue@82: Nenue@82: self.progressPercent = 0 Nenue@82: self.progressAmount = 0 Nenue@82: self.progressMax = 1 Nenue@82: self.progressOverflow = 0 Nenue@84: Nenue@81: end Nenue@81: Nenue@81: function VeneerWorldStateProgressMixin:Setup() Nenue@81: self:UpdateXPGain() Nenue@82: Nenue@82: if self.canGainXP then Nenue@81: self.mode = 'xp' Nenue@81: else Nenue@81: self.mode = 'artifact' Nenue@81: end Nenue@81: print('setup mode:', self.mode) Nenue@81: end Nenue@81: Nenue@82: function VeneerWorldStateProgressMixin:OnEvent(event, ...) Nenue@82: local lastMode = self.mode Nenue@82: if event == 'PLAYER_LEVEL_UP' or event == 'ENABLE_XP_GAIN' or event == 'DISABLE_XP_GAIN' then Nenue@81: self:UpdateXPGain() Nenue@81: elseif event == 'ARTIFACT_XP_UPDATE' or event == 'ARTIFACT_UPDATE' then Nenue@81: self.mode = 'artifact' Nenue@82: Nenue@82: elseif event == 'PLAYER_EQUIPMENT_CHANGED' then Nenue@82: local slot, hasEquip = ... Nenue@82: if slot == 16 then Nenue@82: self.mode = 'artifact' Nenue@82: lastMode = nil Nenue@82: end Nenue@82: elseif event == 'PLAYER_XP_UPDATE' or event == 'PLAYER_LEVEL_UP' then Nenue@82: print('forcing to XP mode') Nenue@81: self.mode = 'xp' Nenue@81: end Nenue@82: self.modeChanged = (lastMode ~= self.mode) Nenue@82: if self.modeChanged and self:IsVisible() then Nenue@82: print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()', event, ...) Nenue@84: self:AnimateMode() Nenue@82: else Nenue@82: print('|cFFFFFF00'..self:GetName()..':Update()', event, ...) Nenue@82: self:Update() Nenue@82: end Nenue@81: end Nenue@81: function VeneerWorldStateProgressMixin:UpdateXPGain() Nenue@82: self.canGainXP = (UnitLevel('player') < GetMaxPlayerLevel()) and (not IsXPUserDisabled()) Nenue@82: if not self.canGainXP then Nenue@81: self.ProgressBar:SetColorTexture(0.75,0.75,0.75) Nenue@81: end Nenue@81: end Nenue@81: Nenue@81: local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo Nenue@81: local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank Nenue@81: function VeneerWorldStateProgressMixin:Update() Nenue@82: local hasNewInfo = false Nenue@82: local progressChange = false Nenue@82: print(' current mode:', self.mode) Nenue@81: Nenue@81: Nenue@81: if self.mode == 'xp' then Nenue@81: local xp = UnitXP('player') Nenue@81: local xpMax = UnitXPMax('player') Nenue@81: local bonusXP = GetXPExhaustion() Nenue@81: if xp then Nenue@81: self.progressPercent = xp / xpMax Nenue@81: end Nenue@84: self.progressText = '|cFFFFCC00' .. UnitLevel('player') .. '|r ' .. xp .. '/' .. xpMax Nenue@82: if bonusXP then Nenue@82: self.ProgressBar:SetColorTexture(0, 0.5,1) Nenue@82: self.OverflowBar:Show() Nenue@82: self.OverflowBar:ClearAllPoints() Nenue@82: self.OverflowBar:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', 0, 0) Nenue@82: else Nenue@82: self.ProgressBar:SetColorTexture(0.5,0,1) Nenue@82: end Nenue@82: hasNewInfo = (self.progressAmount ~= xp) Nenue@83: progressChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax) Nenue@85: self.progressOverflow = bonusXP Nenue@82: self.progressAmount = xp Nenue@82: self.progressMax = xpMax Nenue@85: Nenue@81: elseif self.mode == 'artifact' then Nenue@81: local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() Nenue@82: Nenue@82: if itemID then Nenue@82: local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 Nenue@85: print(' C_AUI:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost) Nenue@82: hasNewInfo = (self.progressAmount ~= totalXP) Nenue@83: progressChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost)) Nenue@82: Nenue@82: if totalXP > nextRankCost then Nenue@82: self.progressPercent = 1 Nenue@85: else Nenue@82: self.progressPercent = totalXP / nextRankCost Nenue@82: end Nenue@82: Nenue@82: self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost Nenue@82: Nenue@82: self.ProgressBar:SetColorTexture(1,0.5,0,1) Nenue@82: self.OverflowBar:Hide() Nenue@82: Nenue@85: self.progressOverflow = 0 Nenue@82: self.progressAmount = totalXP Nenue@82: self.progressMax = nextRankCost Nenue@82: else Nenue@82: self.progressAmount = 0 Nenue@82: self.progressMax = 1 Nenue@82: self.progressText = '' Nenue@82: end Nenue@82: end Nenue@82: Nenue@82: if self.mode then Nenue@82: self:SetSize(600,16) Nenue@82: if hasNewInfo then Nenue@82: self.timeOut = nil Nenue@82: self.timeLived = 0 Nenue@82: if self.TransitionFadeOut:IsPlaying() then Nenue@82: self.TransitionFadeOut:Stop() Nenue@82: self:SetAlpha(1) Nenue@82: end Nenue@82: if not self:IsVisible() then Nenue@82: self.TransitionFadeIn:Play() Nenue@82: else Nenue@82: self:ShowPanel() Nenue@82: end Nenue@82: Nenue@81: end Nenue@81: Nenue@85: print(self:IsVisible()) Nenue@85: print(self:GetWidth()) Nenue@85: print(self.ProgressBG:GetWidth()) Nenue@82: print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'NewInfo:', hasNewInfo, 'IsShown:', self:IsShown()) Nenue@81: Nenue@81: Nenue@82: if progressChange then Nenue@82: print(' Render change:', progressChange) Nenue@82: self.ProgressAdded:Show() Nenue@82: self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (self:GetWidth() * progressChange), 0) Nenue@82: self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0) Nenue@82: self.ProgressFlash:Play() Nenue@81: end Nenue@81: Nenue@82: Nenue@82: if self.progressPercent > 0 then Nenue@82: self.ProgressBar:Show() Nenue@82: self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0) Nenue@84: self.Label:SetText(self.progressText) Nenue@82: Nenue@84: self.progressLeft = self.progressMax - self.progressAmount Nenue@84: if self.progressOverflow >= self.progressLeft then Nenue@84: Nenue@84: self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', (self.progressOverflow / self.progressMax) * self:GetWidth(), 0) Nenue@84: else Nenue@84: self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0) Nenue@84: end Nenue@84: Nenue@82: else Nenue@82: self.ProgressBar:Hide() Nenue@82: end Nenue@81: else Nenue@85: self:HidePanel() Nenue@81: end Nenue@81: Nenue@82: self.modeChanged = nil Nenue@84: end Nenue@84: Nenue@84: function VeneerWorldStateProgressMixin:OnMouseDown(button) Nenue@84: if button == 'RightButton' then Nenue@84: if self.keepOpen then Nenue@84: self.keepOpen = nil Nenue@84: else Nenue@84: self.keepOpen = true Nenue@84: end Nenue@84: print('keepOpen =', self.keepOpen) Nenue@84: else Nenue@84: if self.mode == 'xp' then Nenue@84: self.mode = 'artifact' Nenue@84: else Nenue@85: if not self.canGainXP then Nenue@85: return Nenue@85: end Nenue@84: self.mode = 'xp' Nenue@84: end Nenue@84: self:AnimateMode() Nenue@84: end Nenue@84: Nenue@84: end Nenue@84: Nenue@84: function VeneerWorldStateProgressMixin:AnimateMode() Nenue@84: Nenue@84: self.TransitionFadeIn:Stop() Nenue@84: print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()') Nenue@84: self.modeChanged = true Nenue@84: self.TransitionFadeOut:Play() Nenue@80: end