Nenue@80: -- Veneer Nenue@80: -- OrderHall.lua Nenue@80: -- Created: 10/7/2016 10:55 PM Nenue@80: -- %file-revision% Nenue@80: -- Nenue@80: Nenue@80: VeneerWorldStateCurrencyMixin = {} Nenue@81: VeneerWorldStateProgressMixin = {} Nenue@81: VeneerWorldStateMixin = { 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: self:Refresh() Nenue@80: --DEFAULT_CHAT_FRAME:AddMessage('Loaded') Nenue@81: print('All:Setup()') Nenue@81: Nenue@81: self.modules = self.modules or {self:GetChildren()} Nenue@81: for i, frame in ipairs(self.modules) do Nenue@81: if frame.Setup then Nenue@81: frame:Setup() Nenue@81: end Nenue@81: end Nenue@80: end Nenue@80: Nenue@80: function VeneerWorldStateMixin:Refresh() 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@81: self:Refresh() 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@81: end Nenue@81: Nenue@80: end Nenue@80: local initialized Nenue@80: function VeneerWorldStateMixin:OnEvent(event, arg) Nenue@80: print(event, arg) Nenue@81: Nenue@81: if event == 'PLAYER_LOGIN' and not initialized then Nenue@81: if IsLoggedIn() then Nenue@81: initialized = true Nenue@80: self:Setup() Nenue@81: self:UnregisterEvent('PLAYER_LOGIN') Nenue@81: end Nenue@80: end Nenue@80: Nenue@80: if event == 'PLAYER_ENTERING_WORLD' then Nenue@80: self:Update() Nenue@81: elseif event == 'PLAYER_REGEN_ENABLED' then Nenue@81: self:Show() Nenue@81: elseif event == 'PLAYER_REGEN_DISABLED' then Nenue@81: self:Hide() Nenue@80: end Nenue@80: end Nenue@80: Nenue@80: function VeneerWorldStateMixin:Update() Nenue@81: self.modules = self.modules or {self:GetChildren()} Nenue@80: print('|cFFFFFF00All:Update()|r') Nenue@81: self.maxHeight = 0 Nenue@81: for i, frame in ipairs(self.modules) do Nenue@80: if frame.Update then Nenue@80: print(frame:GetName()) Nenue@80: frame:Update() Nenue@81: if frame:IsVisible() then Nenue@81: self.maxHeight = max(self.maxHeight, frame.maxHeight) Nenue@81: end Nenue@80: end Nenue@80: end Nenue@81: self:SetHeight(self.maxHeight) Nenue@80: end Nenue@80: Nenue@80: Nenue@80: Nenue@80: function VeneerWorldStateMixin:OnLoad () Nenue@81: self:RegisterEvent('PLAYER_LOGIN') Nenue@80: self:RegisterEvent('ADDON_LOADED') Nenue@80: self:RegisterEvent('ARTIFACT_UPDATE') Nenue@80: self:RegisterEvent('ARTIFACT_XP_UPDATE') Nenue@80: self:RegisterEvent('PLAYER_ENTERING_WORLD') Nenue@81: self:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@81: self:RegisterEvent('PLAYER_REGEN_DISABLED') Nenue@80: end Nenue@80: Nenue@80: function VeneerWorldStateCurrencyMixin:OnLoad () Nenue@80: Nenue@80: self:RegisterEvent('ZONE_CHANGED') 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@80: print('currency refresh: zone =', mapID) 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@80: else Nenue@80: self:Hide() Nenue@80: end Nenue@81: Nenue@81: self.maxHeight = self:GetHeight() Nenue@81: end Nenue@81: Nenue@81: function VeneerWorldStateProgressMixin:OnLoad() Nenue@81: self:RegisterEvent('PLAYER_XP_UPDATE') Nenue@81: self:RegisterEvent('PLAYER_LEVEL_UP') Nenue@81: self:RegisterEvent('PLAYER_UPDATE_RESTING') Nenue@81: self:RegisterEvent('ENABLE_XP_GAIN') Nenue@81: self:RegisterEvent('DISABLE_XP_GAIN') Nenue@81: self:RegisterEvent('PLAYER_LOGIN') Nenue@81: self:RegisterEvent('ARTIFACT_UPDATE') Nenue@81: self:RegisterEvent('ARTIFACT_XP_UPDATE') Nenue@81: Nenue@81: end Nenue@81: Nenue@81: function VeneerWorldStateProgressMixin:Setup() Nenue@81: self:UpdateXPGain() Nenue@81: if UnitLevel('player') < GetMaxPlayerLevel() 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: self:Update() Nenue@81: end Nenue@81: Nenue@81: function VeneerWorldStateProgressMixin:OnEvent(event) Nenue@81: if 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@81: elseif event == 'PLAYER_XP_UPDATE' or 'PLAYER_LEVEL_UP' then Nenue@81: self.mode = 'xp' Nenue@81: end Nenue@81: Nenue@81: Nenue@81: self:Update() Nenue@81: Nenue@81: end Nenue@81: function VeneerWorldStateProgressMixin:UpdateXPGain() Nenue@81: if IsXPUserDisabled() then Nenue@81: self.ProgressBar:SetColorTexture(0.75,0.75,0.75) Nenue@81: self.mode = nil Nenue@81: else Nenue@81: self.ProgressBar:SetColorTexture(1,1,1) 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@81: Nenue@81: if not self.mode then Nenue@81: if UnitLevel('player') < GetMaxPlayerLevel() then Nenue@81: self.mode = 'xp' Nenue@81: else Nenue@81: self.mode = 'artifact' Nenue@81: end Nenue@81: end Nenue@81: Nenue@81: Nenue@81: self.progressPercent = 0 Nenue@81: self.progressAmount = 0 Nenue@81: self.progressMax = 1 Nenue@81: self.progressOverflow = 0 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@81: elseif self.mode == 'artifact' then Nenue@81: Nenue@81: local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() Nenue@81: if not itemID then Nenue@81: self:Hide() Nenue@81: return Nenue@81: end Nenue@81: Nenue@81: local pointsAvailable = 0 Nenue@81: Nenue@81: local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 Nenue@81: Nenue@81: self.progressAmount = totalXP Nenue@81: self.progressMax = nextRankCost Nenue@81: if totalXP > nextRankCost then Nenue@81: self.progressPercent = 1 Nenue@81: self.progressOverflow = totalXP - nextRankCost Nenue@81: else Nenue@81: self.progressPercent = totalXP / nextRankCost Nenue@81: end Nenue@81: Nenue@81: self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost Nenue@81: else Nenue@81: self:Hide() Nenue@81: return Nenue@81: end Nenue@81: Nenue@81: print(self.progressPercent, floor(self.ProgressBG:GetWidth()* self.progressPercent)) Nenue@81: Nenue@81: if self.progressPercent > 0 then Nenue@81: self.ProgressBar:Show() Nenue@81: self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self.ProgressBG:GetWidth()* self.progressPercent , 0) Nenue@81: Nenue@81: self.Label:SetText(self.progressText) Nenue@81: else Nenue@81: self.ProgressBar:Hide() Nenue@81: end Nenue@81: Nenue@81: Nenue@81: Nenue@81: self.maxHeight = self:GetHeight() Nenue@80: end