Mercurial > wow > buffalo2
comparison XPTracker.lua @ 19:605e8f0e46db
ObjectiveCore / Style / Events / Frame
- polishing the execution path for better performance
- make use of the Blizzard_ObjectiveTracker bitfield values to ensure compatibility in possible secure hooks
- avoid full updates when possible (using said bitfield values to indicate targeted sections)
- extreme streamlining of event handling layout: specific reason updates are invoked from API hooks; broader updates are invoked by when the event listener catches something vague like 'QUEST_LOG_UPDATE'
author | Nenue |
---|---|
date | Wed, 06 Apr 2016 07:38:35 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
18:d1812fb10ae6 | 19:605e8f0e46db |
---|---|
1 --- ${PACKAGE_NAME} | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 4/6/2016 4:44 AM | |
6 | |
7 local B = select(2,...).frame | |
8 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
9 local tostring = tostring | |
10 local UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled = UnitLevel, IsResting, UnitXP, UnitXPMax, GetXPExhaustion, IsXPUserDisabled | |
11 local Wrapper = _G.VeneerObjectiveWrapper | |
12 local print = B.print('XPTracker') | |
13 | |
14 mod.InitializeXPTracker = function() | |
15 local XPBar = Wrapper.XPBar | |
16 if UnitLevel('player') == 100 then | |
17 XPBar:Hide() | |
18 return | |
19 end | |
20 | |
21 --- xp bar | |
22 XPBar:SetWidth(mod.Conf.Wrapper.WrapperWidth - Wrapper.CloseButton:GetWidth()) | |
23 XPBar.statusbg:SetAllPoints(XPBar) | |
24 XPBar:RegisterEvent('DISABLE_XP_GAIN') | |
25 XPBar:RegisterEvent('ENABLE_XP_GAIN') | |
26 XPBar:SetScript('OnEvent', mod.UpdateXP) | |
27 | |
28 if not IsXPUserDisabled() then | |
29 mod.EnableXP(XPBar) | |
30 else | |
31 mod.DisableXP(XPBar) | |
32 end | |
33 | |
34 mod.UpdateXP(XPBar) | |
35 end | |
36 | |
37 mod.EnableXP = function(self) | |
38 self:RegisterEvent('PLAYER_XP_UPDATE') | |
39 self:RegisterEvent('PLAYER_LEVEL_UP') | |
40 self:RegisterEvent('PLAYER_UPDATE_RESTING') | |
41 self.statusbg:SetTexture(0,0,0,.25) | |
42 self:Show() | |
43 end | |
44 | |
45 mod.DisableXP = function(self) | |
46 self:UnregisterEvent('PLAYER_XP_UPDATE') | |
47 self:UnregisterEvent('PLAYER_LEVEL_UP') | |
48 self:UnregisterEvent('PLAYER_UPDATE_RESTING') | |
49 self.statusbg:SetTexture(0.5,0.5,0.5,0.5) | |
50 self:Hide() | |
51 end | |
52 | |
53 mod.UpdateXP = function(self, event) | |
54 if event == 'DISABLE_XP_GAIN' then | |
55 mod.DisableXP(self) | |
56 elseif event == 'ENABLE_XP_GAIN' then | |
57 mod.EnableXP(self) | |
58 end | |
59 | |
60 if not IsXPUserDisabled() then | |
61 | |
62 local xp = UnitXP('player') | |
63 local xpmax = UnitXPMax('player') | |
64 local rest = GetXPExhaustion() | |
65 self.foreground:SetWidth((xp/xpmax) * self:GetWidth()) | |
66 if rest then | |
67 self.rested:ClearAllPoints() | |
68 if xp == 0 then | |
69 self.rested:SetPoint('TOPLEFT', self, 'TOPLEFT', 0, 0) | |
70 else | |
71 self.rested:SetPoint('TOPLEFT', self.fg, 'TOPRIGHT', 0, 0) | |
72 end | |
73 | |
74 if (xp + rest) > xpmax then | |
75 self.rested:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', 0, 0) | |
76 else | |
77 self.rested:SetWidth((rest/xpmax) * self:GetWidth()) | |
78 end | |
79 self.rested:SetPoint('BOTTOM', self, 'BOTTOM') | |
80 self.rested:Show() | |
81 else | |
82 self.rested:Hide() | |
83 end | |
84 | |
85 if IsResting() then | |
86 self.statusbg:SetTexture(.2,.8,.2,.5) | |
87 else | |
88 self.statusbg:SetTexture(0,0,0,.25) | |
89 end | |
90 self.xpText:SetText(xp .. '/'.. xpmax .. (rest and (' ('..tostring(rest)..')') or '')) | |
91 end | |
92 end |