Nenue@19: --- ${PACKAGE_NAME} Nenue@19: -- @file-author@ Nenue@19: -- @project-revision@ @project-hash@ Nenue@19: -- @file-revision@ @file-hash@ Nenue@19: -- Created: 4/6/2016 4:44 AM Nenue@19: Nenue@19: local B = select(2,...).frame Nenue@19: local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') Nenue@19: local tostring = tostring Nenue@19: local UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled = UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled Nenue@19: local Wrapper = _G.VeneerObjectiveWrapper Nenue@19: local print = B.print('XPTracker') Nenue@19: Nenue@19: mod.InitializeXPTracker = function() Nenue@19: local XPBar = Wrapper.XPBar Nenue@19: if UnitLevel('player') == 100 then Nenue@19: XPBar:Hide() Nenue@19: return Nenue@19: end Nenue@19: Nenue@19: --- xp bar Nenue@19: XPBar:SetWidth(mod.Conf.Wrapper.WrapperWidth - Wrapper.CloseButton:GetWidth()) Nenue@19: XPBar.statusbg:SetAllPoints(XPBar) Nenue@19: XPBar:RegisterEvent('DISABLE_XP_GAIN') Nenue@19: XPBar:RegisterEvent('ENABLE_XP_GAIN') Nenue@19: XPBar:SetScript('OnEvent', mod.UpdateXP) Nenue@19: Nenue@19: if not IsXPUserDisabled() then Nenue@19: mod.EnableXP(XPBar) Nenue@19: else Nenue@19: mod.DisableXP(XPBar) Nenue@19: end Nenue@19: Nenue@19: mod.UpdateXP(XPBar) Nenue@19: end Nenue@19: Nenue@19: mod.EnableXP = function(self) Nenue@19: self:RegisterEvent('PLAYER_XP_UPDATE') Nenue@19: self:RegisterEvent('PLAYER_LEVEL_UP') Nenue@19: self:RegisterEvent('PLAYER_UPDATE_RESTING') Nenue@19: self.statusbg:SetTexture(0,0,0,.25) Nenue@19: self:Show() Nenue@19: end Nenue@19: Nenue@19: mod.DisableXP = function(self) Nenue@19: self:UnregisterEvent('PLAYER_XP_UPDATE') Nenue@19: self:UnregisterEvent('PLAYER_LEVEL_UP') Nenue@19: self:UnregisterEvent('PLAYER_UPDATE_RESTING') Nenue@19: self.statusbg:SetTexture(0.5,0.5,0.5,0.5) Nenue@19: self:Hide() Nenue@19: end Nenue@19: Nenue@19: mod.UpdateXP = function(self, event) Nenue@19: if event == 'DISABLE_XP_GAIN' then Nenue@19: mod.DisableXP(self) Nenue@19: elseif event == 'ENABLE_XP_GAIN' then Nenue@19: mod.EnableXP(self) Nenue@19: end Nenue@19: Nenue@19: if not IsXPUserDisabled() then Nenue@19: Nenue@19: local xp = UnitXP('player') Nenue@19: local xpmax = UnitXPMax('player') Nenue@19: local rest = GetXPExhaustion() Nenue@19: self.foreground:SetWidth((xp/xpmax) * self:GetWidth()) Nenue@19: if rest then Nenue@19: self.rested:ClearAllPoints() Nenue@19: if xp == 0 then Nenue@19: self.rested:SetPoint('TOPLEFT', self, 'TOPLEFT', 0, 0) Nenue@19: else Nenue@19: self.rested:SetPoint('TOPLEFT', self.fg, 'TOPRIGHT', 0, 0) Nenue@19: end Nenue@19: Nenue@19: if (xp + rest) > xpmax then Nenue@19: self.rested:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', 0, 0) Nenue@19: else Nenue@19: self.rested:SetWidth((rest/xpmax) * self:GetWidth()) Nenue@19: end Nenue@19: self.rested:SetPoint('BOTTOM', self, 'BOTTOM') Nenue@19: self.rested:Show() Nenue@19: else Nenue@19: self.rested:Hide() Nenue@19: end Nenue@19: Nenue@19: if IsResting() then Nenue@19: self.statusbg:SetTexture(.2,.8,.2,.5) Nenue@19: else Nenue@19: self.statusbg:SetTexture(0,0,0,.25) Nenue@19: end Nenue@19: self.xpText:SetText(xp .. '/'.. xpmax .. (rest and (' ('..tostring(rest)..')') or '')) Nenue@19: end Nenue@19: end