Mercurial > wow > buffalo2
comparison ObjectiveTracker/Default.lua @ 44:756e8aeb040b
- Default.lua
- simplified the response to SuperTrackedQuestID changes
- tag icons work again
author | Nenue |
---|---|
date | Mon, 25 Apr 2016 19:37:13 -0400 |
parents | ObjectiveTracker/Update.lua@9480bd904f4c |
children | dd1ae565f559 |
comparison
equal
deleted
inserted
replaced
43:9480bd904f4c | 44:756e8aeb040b |
---|---|
1 --- ${PACKAGE_NAME} | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 4/17/2016 7:33 AM | |
6 --- These are the first layer of methods invoked by event handlers | |
7 | |
8 local B = select(2,...).frame | |
9 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
10 local Devian = Devian | |
11 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band | |
12 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove | |
13 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent | |
14 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText | |
15 local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent | |
16 local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs | |
17 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame | |
18 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow | |
19 local print = B.print('Tracker') | |
20 local oprint = B.print('Objectives') | |
21 local bprint = B.print('Block') | |
22 local tprint = B.print('Tracker') | |
23 local lprint = B.print('Line') | |
24 local unitLevel = 1 | |
25 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON | |
26 local debug = false | |
27 | |
28 --- FRAMES | |
29 local Wrapper = _G.VeneerObjectiveWrapper | |
30 local Scroller = Wrapper.scrollArea | |
31 local Scroll = _G.VeneerObjectiveScroll | |
32 local orderedHandlers = T.orderedHandlers | |
33 local orderedNames = T.orderedNames | |
34 | |
35 | |
36 --- Placing the Update functions here since they shouldn't be messing with schema stuff | |
37 local currentPosition, anchorFrame, anchorPoint | |
38 --- Positioning and stuff | |
39 local tick = 0 | |
40 local initReason = OBJECTIVE_TRACKER_UPDATE_ALL | |
41 local requiresInit | |
42 function T:Update (reason, ...) | |
43 if not B.Conf.VeneerObjectiveWrapper.enabled then | |
44 return | |
45 end | |
46 tick = tick + 1 | |
47 local print = tprint | |
48 local hasStuff = false | |
49 local insertingStuff = false | |
50 | |
51 if initReason then | |
52 reason = initReason | |
53 initReason = nil | |
54 elseif not reason then | |
55 reason = OBJECTIVE_TRACKER_UPDATE_ALL | |
56 end | |
57 print(format('|cFFBB0066Update:|r |cFFFF%04X%d|r ', tick, lshift(reason, 4)), reason, ...) | |
58 currentPosition = 0 | |
59 | |
60 for id, handler in pairs(T.orderedHandlers) do | |
61 local frame = handler.frame | |
62 | |
63 print('') | |
64 if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then | |
65 insertingStuff = handler:UpdateTracker(reason, ...) | |
66 else | |
67 print(' |cFFFF4400Update:|r skipping',handler.name) | |
68 end | |
69 | |
70 if handler.numWatched >= 1 then | |
71 hasStuff = true | |
72 currentPosition = currentPosition + 1 | |
73 Default.AddTracker(handler, frame, currentPosition) | |
74 frame.wasEmpty = nil | |
75 else | |
76 frame.destinationOffset = 0 | |
77 if not frame.wasEmpty and not frame.fadeOut:IsPlaying() then | |
78 frame.fadeOut:Play() | |
79 end | |
80 frame.wasEmpty = true | |
81 end | |
82 end | |
83 | |
84 -- do these whenever there is content or content is being added | |
85 if hasStuff or insertingStuff then | |
86 T:FinishWrapper() | |
87 end | |
88 Quest.GetClosest() | |
89 T.UpdateActionButtons(reason) | |
90 end | |
91 | |
92 Default.UpdateTracker = function (handler, reason, id, isNew) | |
93 local print = handler.print | |
94 local frame = handler.frame | |
95 local blockIndex = 0 | |
96 print('MODULE:'..handler.name, 'message:', reason, 'id:', id, (isNew and '|cFF88FF88' or '|cFF555555')..'isNew|r') | |
97 handler.updateReason = reason | |
98 local numWatched, numAll, watchTable = handler:GetNumWatched(id, isNew) | |
99 | |
100 if numWatched >= 1 then | |
101 if watchTable then | |
102 print(' WatchList', ' n ID Obj wID Log Blk') | |
103 for i, w in ipairs(watchTable) do | |
104 print(' WatchList', format('%2d => %6d %3d %3d %3s %s', i, w.id, w.numObjectives, w.watchIndex, (w.logIndex or ''), (handler.InfoBlock[w.id] and handler.InfoBlock[w.id]:GetName() or ''))) | |
105 end | |
106 end | |
107 end | |
108 | |
109 handler.numWatched = numWatched | |
110 handler.numAll = numAll | |
111 handler.numBlocks = 0 | |
112 handler.currentBlock = 0 | |
113 handler.currentAnchor = frame.titlebg | |
114 for blockIndex = 1, numWatched do | |
115 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew) | |
116 if currentBlock then | |
117 handler:AddBlock(currentBlock) | |
118 else | |
119 print(' |cFF'..handler.internalColor..'finished|r @', blockIndex) | |
120 break -- done with quest stuff | |
121 end | |
122 end | |
123 | |
124 local numBlocks = handler.numBlocks | |
125 local used = handler.usedBlocks | |
126 local free = handler.freeBlocks | |
127 print(format('#### %s ## |cFFFF8800%04X|r --- blocks |cFFFF8800%d|r, (used/free: |cFFFF8800%d|r/|cFFFF8800%d|r)', handler.name, band(reason, handler.updateReasonModule + handler.updateReasonEvents, reason), numBlocks, #used, #free)) | |
128 | |
129 return numWatched, numAll | |
130 end | |
131 | |
132 Default.UpdateBlock = function (handler, index) | |
133 --@debug@ | |
134 local print = bprint -- @end-debug@ | |
135 if not index then | |
136 return | |
137 end | |
138 local info = handler.WatchList[index] -- should match up with whatever the internal watch list has | |
139 if not info then | |
140 return | |
141 end | |
142 local frame = handler.frame | |
143 local block = handler:GetBlock(info.id) | |
144 | |
145 --@debug@ | |
146 handler.print('UpdateBlock', '|cFF00FFFF'..index..'|r|cFF0099FF', info.id ,'|r', (block.isAnimating and 'animating' or 'static'))--@end-debug@ | |
147 if block.isAnimating then | |
148 -- Nothing to do, leave it as is | |
149 return block | |
150 end | |
151 | |
152 block.handler = handler | |
153 block.info = info | |
154 info.blockIndex = index | |
155 --@debug@ | |
156 local keyInfo--@end-debug@ | |
157 if info.id then | |
158 handler.InfoBlock[info.id] = block | |
159 --@debug@ | |
160 keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'InfoBlock[' .. info.id .. '] = *' .. block:GetName():gsub('%D', '') --@end-debug@ | |
161 end | |
162 if info.logIndex then | |
163 handler.LogBlock[info.logIndex] = block | |
164 --@debug@ | |
165 keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'LogBlock[' .. info.logIndex .. '] = ' .. block:GetName():gsub('%D', '')--@end-debug@ | |
166 end | |
167 if info.watchIndex then | |
168 handler.WatchBlock[info.watchIndex] = block | |
169 --@debug@ | |
170 keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'WatchBlock[' .. info.watchIndex .. '] = ' .. block:GetName():gsub('%D', '')--@end-debug@ | |
171 end | |
172 --@debug@ | |
173 if keyInfo then print(' assigned', keyInfo) end--@end-debug@ | |
174 handler.BlockInfo[index] = info | |
175 block.endPoint = block.titlebg | |
176 block.attachmentHeight = 0 | |
177 block.currentLine = 0 | |
178 local attachments, override_schema = handler:UpdateObjectives(block, block.schema) | |
179 | |
180 | |
181 block.title:SetText(info.title) | |
182 | |
183 if info.specialItem and not info.itemButton then | |
184 --@debug@ | |
185 print(' - |cFF00FFFFgenerating item button for info set')--@end-debug@ | |
186 info.itemButton = T.SetItemButton(block, info) | |
187 end | |
188 | |
189 | |
190 if info.selected then | |
191 block.SelectionOverlay:Show() | |
192 else | |
193 block.SelectionOverlay:Hide() | |
194 end | |
195 | |
196 if info.tagInfo then | |
197 handler:AddTags(block, info.tagInfo, info.tagCoords) | |
198 end | |
199 | |
200 if override_schema then | |
201 block.schema = override_schema | |
202 elseif info.schema then | |
203 block.schema = info.schema | |
204 end | |
205 return block | |
206 end | |
207 | |
208 Default.UpdateObjectives = function(handler, block, block_schema, displayObjectives) | |
209 local print = lprint | |
210 displayObjectives = displayObjectives or true | |
211 block_schema = block_schema or block.schema | |
212 local info = block.info | |
213 print(' |cFF00FF00default.objectives', block:GetName()) | |
214 -- reset the starting positions | |
215 local text, attachment, template | |
216 local numAttachments = 0 | |
217 | |
218 if info.objectives and displayObjectives then | |
219 for i, data in ipairs(info.objectives) do | |
220 text, attachment, template = handler:UpdateLine(block, data) | |
221 if text or attachment then | |
222 local line = handler:GetLine(block) | |
223 line.height = 0 | |
224 print(' |cFF88FF00#', i, data.type, text, attachment) | |
225 handler:AddLine(block, text, attachment, template) | |
226 end | |
227 if attachment then | |
228 numAttachments = numAttachments + 1 | |
229 end | |
230 end | |
231 end | |
232 | |
233 if block.currentLine < block.numLines then | |
234 print(' - cull', block.currentLine, block.numLines) | |
235 for i = block.currentLine + 1, block.numLines do | |
236 print(' - hide |cFFFF0088'..i..'|r', block.lines[i]) | |
237 block.lines[i]:ClearAllPoints() | |
238 block.lines[i]:Hide() | |
239 end | |
240 end | |
241 | |
242 if block.currentLine > 0 then | |
243 block.attachmentHeight = block.attachmentHeight | |
244 print(' |cFF00FF00attachment:', block.attachmentHeight) | |
245 end | |
246 return numAttachments, block_schema | |
247 end | |
248 | |
249 Default.UpdateLine = function(handler, block, data) | |
250 return block.info.description, nil, 'default' | |
251 end | |
252 | |
253 Default.Select = function(handler, block) | |
254 T:Update() | |
255 end | |
256 Default.Open = function(handler, block) | |
257 T:Update(handler.updateReasonModule) | |
258 end | |
259 Default.Remove = function(handler, block) | |
260 T:Update(handler.updateReasonModule) | |
261 end | |
262 Default.Report = function(handler, block) | |
263 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.') | |
264 end | |
265 | |
266 function Default:OnMouseUp (button) | |
267 print(self.handler.name, button, IsModifiedClick('CHATLINK'), IsModifiedClick("QUESTWATCHTOGGLE")) | |
268 if button == 'LeftButton' then | |
269 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then | |
270 self.Link(self.handler, self) | |
271 elseif IsModifiedClick("QUESTWATCHTOGGLE") then | |
272 self.Remove(self.handler, self) | |
273 else | |
274 self.Select(self.handler, self) | |
275 end | |
276 elseif button == 'RightButton' then | |
277 self.Open(self.handler, self) | |
278 end | |
279 self.initialButton = nil | |
280 self.modChatLink = nil | |
281 self.modQuestWatch = nil | |
282 --T:Update(self.handler.updateReasonModule) | |
283 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') | |
284 end | |
285 function Default:OnMouseDown (button) | |
286 --print(self.info.title) | |
287 end |