Mercurial > wow > buffalo2
view ObjectiveTracker/XPTracker.lua @ 37:e84d645c8ab8
- revised the tracker update function to build its complete data list up front and use the values as points of comparison for determining possible out of place blocks, which will be iterated over afterward to remove what wasn't re-used
- also entailed revising the exact role of global event handlers and function hooks, limiting their directions of communication so one doesn't end up calling the other multiple or inifinity times
- schema handling polish
author | Nenue |
---|---|
date | Mon, 18 Apr 2016 07:56:23 -0400 |
parents | e837384ac363 |
children |
line wrap: on
line source
--- ${PACKAGE_NAME} -- @file-author@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 4/6/2016 4:44 AM local B = select(2,...).frame local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') local tostring = tostring local UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled = UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled local Wrapper = _G.VeneerObjectiveWrapper local print = B.print('XPTracker') mod.InitializeXPTracker = function() local XPBar = Wrapper.XPBar if UnitLevel('player') == 100 then XPBar:Hide() return end --- xp bar XPBar:SetWidth(mod.Conf.Wrapper.WrapperWidth - Wrapper.CloseButton:GetWidth()) XPBar.statusbg:SetAllPoints(XPBar) XPBar:RegisterEvent('DISABLE_XP_GAIN') XPBar:RegisterEvent('ENABLE_XP_GAIN') XPBar:SetScript('OnEvent', mod.UpdateXP) if not IsXPUserDisabled() then mod.EnableXP(XPBar) else mod.DisableXP(XPBar) end mod.UpdateXP(XPBar) end mod.EnableXP = function(self) self:RegisterEvent('PLAYER_XP_UPDATE') self:RegisterEvent('PLAYER_LEVEL_UP') self:RegisterEvent('PLAYER_UPDATE_RESTING') self.statusbg:SetTexture(0,0,0,.25) self:Show() end mod.DisableXP = function(self) self:UnregisterEvent('PLAYER_XP_UPDATE') self:UnregisterEvent('PLAYER_LEVEL_UP') self:UnregisterEvent('PLAYER_UPDATE_RESTING') self.statusbg:SetTexture(0.5,0.5,0.5,0.5) self:Hide() end mod.UpdateXP = function(self, event) if event == 'DISABLE_XP_GAIN' then mod.DisableXP(self) elseif event == 'ENABLE_XP_GAIN' then mod.EnableXP(self) end if not IsXPUserDisabled() then local xp = UnitXP('player') local xpmax = UnitXPMax('player') local rest = GetXPExhaustion() self.foreground:SetWidth((xp/xpmax) * self:GetWidth()) if rest then self.rested:ClearAllPoints() if xp == 0 then self.rested:SetPoint('TOPLEFT', self, 'TOPLEFT', 0, 0) else self.rested:SetPoint('TOPLEFT', self.fg, 'TOPRIGHT', 0, 0) end if (xp + rest) > xpmax then self.rested:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', 0, 0) else self.rested:SetWidth((rest/xpmax) * self:GetWidth()) end self.rested:SetPoint('BOTTOM', self, 'BOTTOM') self.rested:Show() else self.rested:Hide() end if IsResting() then self.statusbg:SetTexture(.2,.8,.2,.5) else self.statusbg:SetTexture(0,0,0,.25) end self.xpText:SetText(xp .. '/'.. xpmax .. (rest and (' ('..tostring(rest)..')') or '')) end end