annotate ObjectiveTracker/ExperienceBar.lua @ 49:16465f3fd919

- remove UpdateAnchorAnchors and use hardlink for the one frame that this applied to
author Nenue
date Fri, 29 Apr 2016 10:50:27 -0400
parents c33c17dd97e7
children 07ef62fe201f
rev   line source
Nenue@28 1 --- ${PACKAGE_NAME}
Nenue@28 2 -- @file-author@
Nenue@28 3 -- @project-revision@ @project-hash@
Nenue@28 4 -- @file-revision@ @file-hash@
Nenue@28 5 -- Created: 4/6/2016 4:44 AM
Nenue@28 6
Nenue@28 7 local B = select(2,...).frame
Nenue@28 8 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@28 9 local tostring = tostring
Nenue@28 10 local UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled = UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled
Nenue@28 11 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@28 12 local print = B.print('XPTracker')
Nenue@28 13
Nenue@28 14 mod.InitializeXPTracker = function()
Nenue@28 15 local XPBar = Wrapper.XPBar
Nenue@28 16 if UnitLevel('player') == 100 then
Nenue@28 17 XPBar:Hide()
Nenue@28 18 return
Nenue@28 19 end
Nenue@28 20
Nenue@28 21 --- xp bar
Nenue@28 22 XPBar:SetWidth(mod.Conf.Wrapper.WrapperWidth - Wrapper.CloseButton:GetWidth())
Nenue@28 23 XPBar.statusbg:SetAllPoints(XPBar)
Nenue@28 24 XPBar:RegisterEvent('DISABLE_XP_GAIN')
Nenue@28 25 XPBar:RegisterEvent('ENABLE_XP_GAIN')
Nenue@28 26 XPBar:SetScript('OnEvent', mod.UpdateXP)
Nenue@28 27
Nenue@28 28 if not IsXPUserDisabled() then
Nenue@28 29 mod.EnableXP(XPBar)
Nenue@28 30 else
Nenue@28 31 mod.DisableXP(XPBar)
Nenue@28 32 end
Nenue@28 33
Nenue@28 34 mod.UpdateXP(XPBar)
Nenue@28 35 end
Nenue@28 36
Nenue@28 37 mod.EnableXP = function(self)
Nenue@28 38 self:RegisterEvent('PLAYER_XP_UPDATE')
Nenue@28 39 self:RegisterEvent('PLAYER_LEVEL_UP')
Nenue@28 40 self:RegisterEvent('PLAYER_UPDATE_RESTING')
Nenue@28 41 self.statusbg:SetTexture(0,0,0,.25)
Nenue@28 42 self:Show()
Nenue@28 43 end
Nenue@28 44
Nenue@28 45 mod.DisableXP = function(self)
Nenue@28 46 self:UnregisterEvent('PLAYER_XP_UPDATE')
Nenue@28 47 self:UnregisterEvent('PLAYER_LEVEL_UP')
Nenue@28 48 self:UnregisterEvent('PLAYER_UPDATE_RESTING')
Nenue@28 49 self.statusbg:SetTexture(0.5,0.5,0.5,0.5)
Nenue@28 50 self:Hide()
Nenue@28 51 end
Nenue@28 52
Nenue@28 53 mod.UpdateXP = function(self, event)
Nenue@28 54 if event == 'DISABLE_XP_GAIN' then
Nenue@28 55 mod.DisableXP(self)
Nenue@28 56 elseif event == 'ENABLE_XP_GAIN' then
Nenue@28 57 mod.EnableXP(self)
Nenue@28 58 end
Nenue@28 59
Nenue@28 60 if not IsXPUserDisabled() then
Nenue@28 61
Nenue@28 62 local xp = UnitXP('player')
Nenue@28 63 local xpmax = UnitXPMax('player')
Nenue@28 64 local rest = GetXPExhaustion()
Nenue@28 65 self.foreground:SetWidth((xp/xpmax) * self:GetWidth())
Nenue@28 66 if rest then
Nenue@28 67 self.rested:ClearAllPoints()
Nenue@28 68 if xp == 0 then
Nenue@28 69 self.rested:SetPoint('TOPLEFT', self, 'TOPLEFT', 0, 0)
Nenue@28 70 else
Nenue@28 71 self.rested:SetPoint('TOPLEFT', self.fg, 'TOPRIGHT', 0, 0)
Nenue@28 72 end
Nenue@28 73
Nenue@28 74 if (xp + rest) > xpmax then
Nenue@28 75 self.rested:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', 0, 0)
Nenue@28 76 else
Nenue@28 77 self.rested:SetWidth((rest/xpmax) * self:GetWidth())
Nenue@28 78 end
Nenue@28 79 self.rested:SetPoint('BOTTOM', self, 'BOTTOM')
Nenue@28 80 self.rested:Show()
Nenue@28 81 else
Nenue@28 82 self.rested:Hide()
Nenue@28 83 end
Nenue@28 84
Nenue@28 85 if IsResting() then
Nenue@28 86 self.statusbg:SetTexture(.2,.8,.2,.5)
Nenue@28 87 else
Nenue@28 88 self.statusbg:SetTexture(0,0,0,.25)
Nenue@28 89 end
Nenue@28 90 self.xpText:SetText(xp .. '/'.. xpmax .. (rest and (' ('..tostring(rest)..')') or ''))
Nenue@28 91 end
Nenue@28 92 end