Mercurial > wow > buffalo2
comparison Modules/OrderHall.lua @ 81:65ec88b30eb8
- OrderHall plugin converted to a general world state cluster. Includes:
- Suramar ancient mana
- Artifact power/XP progress
- OrderHall bar shrinker
author | Nenue |
---|---|
date | Mon, 17 Oct 2016 04:57:32 -0400 |
parents | bb6b532c5d2f |
children | be813a9d99c0 |
comparison
equal
deleted
inserted
replaced
80:bb6b532c5d2f | 81:65ec88b30eb8 |
---|---|
3 -- Created: 10/7/2016 10:55 PM | 3 -- Created: 10/7/2016 10:55 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 -- | 5 -- |
6 | 6 |
7 VeneerWorldStateCurrencyMixin = {} | 7 VeneerWorldStateCurrencyMixin = {} |
8 VeneerWorldStateMixin = {} | 8 VeneerWorldStateProgressMixin = {} |
9 VeneerWorldStateMixin = { | |
10 detectedFrames = {} | |
11 } | |
9 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop | 12 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop |
10 | 13 |
11 function VeneerWorldStateMixin:Setup() | 14 function VeneerWorldStateMixin:Setup() |
12 hooksecurefunc(OrderHallCommandBar,'Show', function() | |
13 self:Refresh() | |
14 end) | |
15 self:Refresh() | 15 self:Refresh() |
16 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') | 16 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') |
17 print('All:Setup()') | |
18 | |
19 self.modules = self.modules or {self:GetChildren()} | |
20 for i, frame in ipairs(self.modules) do | |
21 if frame.Setup then | |
22 frame:Setup() | |
23 end | |
24 end | |
17 end | 25 end |
18 | 26 |
19 function VeneerWorldStateMixin:Refresh() | 27 function VeneerWorldStateMixin:Refresh() |
20 OrderHallCommandBar:ClearAllPoints() | 28 if OrderHallCommandBar then |
21 OrderHallCommandBar:SetPoint('TOP') | 29 if not self.detectedFrames[OrderHallCommandBar] then |
22 OrderHallCommandBar:SetWidth(600) | 30 self.detectedFrames[OrderHallCommandBar] = true |
23 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) | 31 hooksecurefunc(OrderHallCommandBar,'Show', function() |
24 OrderHallCommandBar.WorldMapButton:Hide() | 32 self:Refresh() |
25 OrderHallCommandBar:EnableMouse(false) | 33 end) |
34 end | |
35 | |
36 | |
37 OrderHallCommandBar:ClearAllPoints() | |
38 OrderHallCommandBar:SetPoint('TOP') | |
39 OrderHallCommandBar:SetWidth(600) | |
40 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) | |
41 OrderHallCommandBar.WorldMapButton:Hide() | |
42 OrderHallCommandBar:EnableMouse(false) | |
43 end | |
44 | |
26 end | 45 end |
27 local initialized | 46 local initialized |
28 function VeneerWorldStateMixin:OnEvent(event, arg) | 47 function VeneerWorldStateMixin:OnEvent(event, arg) |
29 print(event, arg) | 48 print(event, arg) |
30 if OrderHallCommandBar and not initialized then | 49 |
31 initialized = true | 50 if event == 'PLAYER_LOGIN' and not initialized then |
51 if IsLoggedIn() then | |
52 initialized = true | |
32 self:Setup() | 53 self:Setup() |
33 self:UnregisterEvent('ADDON_LOADED') | 54 self:UnregisterEvent('PLAYER_LOGIN') |
55 end | |
34 end | 56 end |
35 | 57 |
36 if event == 'PLAYER_ENTERING_WORLD' then | 58 if event == 'PLAYER_ENTERING_WORLD' then |
37 self:Update() | 59 self:Update() |
60 elseif event == 'PLAYER_REGEN_ENABLED' then | |
61 self:Show() | |
62 elseif event == 'PLAYER_REGEN_DISABLED' then | |
63 self:Hide() | |
38 end | 64 end |
39 end | 65 end |
40 | 66 |
41 function VeneerWorldStateMixin:Update() | 67 function VeneerWorldStateMixin:Update() |
42 local frames = {self:GetChildren()} | 68 self.modules = self.modules or {self:GetChildren()} |
43 print('|cFFFFFF00All:Update()|r') | 69 print('|cFFFFFF00All:Update()|r') |
44 for i, frame in ipairs(frames) do | 70 self.maxHeight = 0 |
71 for i, frame in ipairs(self.modules) do | |
45 if frame.Update then | 72 if frame.Update then |
46 print(frame:GetName()) | 73 print(frame:GetName()) |
47 frame:Update() | 74 frame:Update() |
48 end | 75 if frame:IsVisible() then |
49 end | 76 self.maxHeight = max(self.maxHeight, frame.maxHeight) |
77 end | |
78 end | |
79 end | |
80 self:SetHeight(self.maxHeight) | |
50 end | 81 end |
51 | 82 |
52 | 83 |
53 | 84 |
54 function VeneerWorldStateMixin:OnLoad () | 85 function VeneerWorldStateMixin:OnLoad () |
86 self:RegisterEvent('PLAYER_LOGIN') | |
55 self:RegisterEvent('ADDON_LOADED') | 87 self:RegisterEvent('ADDON_LOADED') |
56 self:RegisterEvent('ARTIFACT_UPDATE') | 88 self:RegisterEvent('ARTIFACT_UPDATE') |
57 self:RegisterEvent('ARTIFACT_XP_UPDATE') | 89 self:RegisterEvent('ARTIFACT_XP_UPDATE') |
58 self:RegisterEvent('PLAYER_ENTERING_WORLD') | 90 self:RegisterEvent('PLAYER_ENTERING_WORLD') |
59 | 91 self:RegisterEvent('PLAYER_REGEN_ENABLED') |
92 self:RegisterEvent('PLAYER_REGEN_DISABLED') | |
60 end | 93 end |
61 | 94 |
62 function VeneerWorldStateCurrencyMixin:OnLoad () | 95 function VeneerWorldStateCurrencyMixin:OnLoad () |
63 | 96 |
64 self:RegisterEvent('ZONE_CHANGED') | 97 self:RegisterEvent('ZONE_CHANGED') |
71 self:Update() | 104 self:Update() |
72 end | 105 end |
73 | 106 |
74 | 107 |
75 function VeneerWorldStateCurrencyMixin:Update() | 108 function VeneerWorldStateCurrencyMixin:Update() |
76 local mapID = GetCurrentMapAreaID() | 109 |
77 print('currency refresh: zone =', mapID) | 110 print('currency refresh: zone =', mapID) |
78 if mapID == 1033 then | 111 if GetZoneText() == 'Suramar' then |
79 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(1155) | 112 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(1155) |
80 | 113 |
81 self.Icon:SetTexture(texture) | 114 self.Icon:SetTexture(texture) |
82 self.Label:SetFormattedText("%d / %d", earned, totalMax) | 115 self.Label:SetFormattedText("%d / %d", earned, totalMax) |
83 self:Show() | 116 self:Show() |
84 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) | 117 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) |
85 else | 118 else |
86 self:Hide() | 119 self:Hide() |
87 end | 120 end |
88 end | 121 |
122 self.maxHeight = self:GetHeight() | |
123 end | |
124 | |
125 function VeneerWorldStateProgressMixin:OnLoad() | |
126 self:RegisterEvent('PLAYER_XP_UPDATE') | |
127 self:RegisterEvent('PLAYER_LEVEL_UP') | |
128 self:RegisterEvent('PLAYER_UPDATE_RESTING') | |
129 self:RegisterEvent('ENABLE_XP_GAIN') | |
130 self:RegisterEvent('DISABLE_XP_GAIN') | |
131 self:RegisterEvent('PLAYER_LOGIN') | |
132 self:RegisterEvent('ARTIFACT_UPDATE') | |
133 self:RegisterEvent('ARTIFACT_XP_UPDATE') | |
134 | |
135 end | |
136 | |
137 function VeneerWorldStateProgressMixin:Setup() | |
138 self:UpdateXPGain() | |
139 if UnitLevel('player') < GetMaxPlayerLevel() then | |
140 self.mode = 'xp' | |
141 else | |
142 self.mode = 'artifact' | |
143 end | |
144 print('setup mode:', self.mode) | |
145 self:Update() | |
146 end | |
147 | |
148 function VeneerWorldStateProgressMixin:OnEvent(event) | |
149 if event == 'ENABLE_XP_GAIN' or event == 'DISABLE_XP_GAIN' then | |
150 self:UpdateXPGain() | |
151 elseif event == 'ARTIFACT_XP_UPDATE' or event == 'ARTIFACT_UPDATE' then | |
152 self.mode = 'artifact' | |
153 elseif event == 'PLAYER_XP_UPDATE' or 'PLAYER_LEVEL_UP' then | |
154 self.mode = 'xp' | |
155 end | |
156 | |
157 | |
158 self:Update() | |
159 | |
160 end | |
161 function VeneerWorldStateProgressMixin:UpdateXPGain() | |
162 if IsXPUserDisabled() then | |
163 self.ProgressBar:SetColorTexture(0.75,0.75,0.75) | |
164 self.mode = nil | |
165 else | |
166 self.ProgressBar:SetColorTexture(1,1,1) | |
167 end | |
168 end | |
169 | |
170 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | |
171 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | |
172 function VeneerWorldStateProgressMixin:Update() | |
173 | |
174 if not self.mode then | |
175 if UnitLevel('player') < GetMaxPlayerLevel() then | |
176 self.mode = 'xp' | |
177 else | |
178 self.mode = 'artifact' | |
179 end | |
180 end | |
181 | |
182 | |
183 self.progressPercent = 0 | |
184 self.progressAmount = 0 | |
185 self.progressMax = 1 | |
186 self.progressOverflow = 0 | |
187 if self.mode == 'xp' then | |
188 local xp = UnitXP('player') | |
189 local xpMax = UnitXPMax('player') | |
190 local bonusXP = GetXPExhaustion() | |
191 if xp then | |
192 self.progressPercent = xp / xpMax | |
193 end | |
194 elseif self.mode == 'artifact' then | |
195 | |
196 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() | |
197 if not itemID then | |
198 self:Hide() | |
199 return | |
200 end | |
201 | |
202 local pointsAvailable = 0 | |
203 | |
204 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 | |
205 | |
206 self.progressAmount = totalXP | |
207 self.progressMax = nextRankCost | |
208 if totalXP > nextRankCost then | |
209 self.progressPercent = 1 | |
210 self.progressOverflow = totalXP - nextRankCost | |
211 else | |
212 self.progressPercent = totalXP / nextRankCost | |
213 end | |
214 | |
215 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost | |
216 else | |
217 self:Hide() | |
218 return | |
219 end | |
220 | |
221 print(self.progressPercent, floor(self.ProgressBG:GetWidth()* self.progressPercent)) | |
222 | |
223 if self.progressPercent > 0 then | |
224 self.ProgressBar:Show() | |
225 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self.ProgressBG:GetWidth()* self.progressPercent , 0) | |
226 | |
227 self.Label:SetText(self.progressText) | |
228 else | |
229 self.ProgressBar:Hide() | |
230 end | |
231 | |
232 | |
233 | |
234 self.maxHeight = self:GetHeight() | |
235 end |