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