comparison ObjectiveTracker/Frame.lua @ 35:69d03f8e293e

- separated layout and data logic between Frame.lua and Update.lua - solved disappearing tracker mystery
author Nenue
date Sun, 17 Apr 2016 11:07:48 -0400
parents 9856ebc63fa4
children a487841050be
comparison
equal deleted inserted replaced
34:9856ebc63fa4 35:69d03f8e293e
2 -- @file-author@ 2 -- @file-author@
3 -- @project-revision@ @project-hash@ 3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@ 4 -- @file-revision@ @file-hash@
5 -- Created: 3/30/2016 12:49 AM 5 -- Created: 3/30/2016 12:49 AM
6 local B = select(2,...).frame 6 local B = select(2,...).frame
7 local Module = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
8 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band 8 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove 9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove
10 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent 10 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent
11 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText 11 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText
12 local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent 12 local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent
13 local Default, AutoQuest, Quest, Bonus, Cheevs = Module.DefaultHandler, Module.AutoQuest, Module.Quest, Module.Bonus, Module.Cheevs 13 local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs
14 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame 14 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame
15 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow 15 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow
16 local print = B.print('Tracker') 16 local print = B.print('Layout')
17 local oprint = B.print('Objectives') 17 local oprint = B.print('Objectives')
18 local bprint = B.print('Block') 18 local bprint = B.print('Block')
19 local tprint = B.print('Tracker') 19 local tprint = B.print('Tracker')
20 local lprint = B.print('Line') 20 local lprint = B.print('Layout')
21 local unitLevel = 1 21 local unitLevel = 1
22 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON 22 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON
23 local debug = false 23 local debug = false
24 24
25 --- FRAMES 25 --- FRAMES
26 local Wrapper = _G.VeneerObjectiveWrapper 26 local Wrapper = _G.VeneerObjectiveWrapper
27 local Scroller = Wrapper.scrollArea 27 local Scroller = Wrapper.scrollArea
28 local Scroll = _G.VeneerObjectiveScroll 28 local Scroll = _G.VeneerObjectiveScroll
29 local orderedHandlers = Module.orderedHandlers 29 local orderedHandlers = T.orderedHandlers
30 local orderedNames = Module.orderedNames 30 local orderedNames = T.orderedNames
31 31
32 --- FRAME TEMP VARIABLES 32 --- FRAME TEMP VARIABLES
33 local wrapperWidth, wrapperHeight 33 local wrapperWidth, wrapperHeight
34 local scrollWidth, scrollHeight 34 local scrollWidth, scrollHeight
35 35
61 61
62 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225} 62 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225}
63 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1 63 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1
64 local titleIndent, textIndent,selectionIndent = 2, 5, 50 64 local titleIndent, textIndent,selectionIndent = 2, 5, 50
65 --- END SCHEMA 65 --- END SCHEMA
66 local blockPosition
67
66 --- schema swapper 68 --- schema swapper
67 Module.UpdateSchema = function(layer, newSchema) 69 T.UpdateSchema = function(layer, newSchema)
68 if not (Module.Conf.Schema[layer] and Module.Conf.Schema[layer][newSchema]) then 70 if not (T.Conf.Schema[layer] and T.Conf.Schema[layer][newSchema]) then
69 return 71 return
70 elseif schemaName[layer] == newSchema then 72 elseif schemaName[layer] == newSchema then
71 return 73 return
72 end 74 end
73 lastSchema[layer] = schemaName[layer] 75 lastSchema[layer] = schemaName[layer]
74 schemaName[layer] = newSchema 76 schemaName[layer] = newSchema
75 local c = Module.Conf.Schema[layer][newSchema] 77 local c = T.Conf.Schema[layer][newSchema]
76 78
77 if layer == 'tracker' then 79 if layer == 'tracker' then
78 headerHeight, headerSpacing = c.headerHeight, c.headerSpacing 80 headerHeight, headerSpacing = c.headerHeight, c.headerSpacing
79 headerColor = c.headerColor 81 headerColor = c.headerColor
80 headerbg = c.headerbg 82 headerbg = c.headerbg
97 textColor = c.textColor 99 textColor = c.textColor
98 lineSchema = newSchema 100 lineSchema = newSchema
99 end 101 end
100 print('|cFFFF0088UpdateSchema:|r', layer, lastSchema[layer], '->', newSchema) 102 print('|cFFFF0088UpdateSchema:|r', layer, lastSchema[layer], '->', newSchema)
101 end 103 end
104 -- todo: figure out why objectives go invisible
105 local anchorPoint, anchorFrame
106 local abs, GetTime = math.abs, GetTime
107 Default.AddTracker = function(handler, frame, index)
108 if index == 1 then
109 print('|cFF00FF00### beginning wrapper layout -----------------')
110 anchorPoint, anchorFrame = 'TOP', Scroll
111 wrapperHeight = 0
112 end
113
114 frame.destinationOffset = -wrapperHeight
115 print(frame.destinationOffset, frame.previousOffset)
116 if handler.initialized and (abs(frame.previousOffset - frame.destinationOffset) > 0.9) and frame:IsVisible() then
117 if frame.wasEmpty then
118 frame.previousOffset = -Wrapper:GetHeight()
119 end
120
121 local postFrame, postPoint = anchorFrame, anchorPoint
122 local delta = frame.destinationOffset - frame.previousOffset
123 local _, _, _, _, offset = frame:GetPoint(1)
124 print(' |cFF00FFBBpushing', frame:GetName(), delta, 'pixels, from', frame.previousOffset, '(', offset, ')')
125 frame.SlideIn.translation:SetTarget(frame)
126 frame.SlideIn.translation:SetOffset(0, delta)
127 frame.SlideIn:Play()
128 --for i, b in ipairs(handler.usedBlocks) do
129 --b.SlideIn.translation:SetOffset(0, delta)
130 -- b.SlideIn:Play()
131 --end
132 local start = GetTime()
133 frame.SlideIn:SetScript('OnFinished', function()
134 print(' |cFF00BBFF'..frame:GetName(), 'moved', delta, 'over duration of ', GetTime()-start)
135 frame:SetParent(Scroll)
136 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
137 frame.previousOffset = frame.destinationOffset
138 frame.SlideIn:SetScript('OnFinished', nil)
139 if Wrapper.destinationHeight then
140 Wrapper:SetHeight(Wrapper.destinationHeight)
141 Scroller:SetHeight(Wrapper.destinationHeight)
142 Scroll:SetHeight(Wrapper.destinationHeight)
143 Wrapper.previousHeight = Wrapper.destinationHeight
144 Wrapper.destinationHeight = nil
145 end
146
147 end)
148 else
149 print(' |cFF00BBFFpinning to', anchorFrame:GetName(), anchorPoint, '|rcurrent frame height:', frame.height)
150 print(' |cFFFF0088total height:', wrapperHeight)
151 frame:ClearAllPoints()
152 frame:SetParent(Scroll)
153 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
154 frame.previousOffset = frame.destinationOffset
155 handler.initialized = true
156 end
157
158 frame.title:SetFont(headerFont, headerSize, headerOutline)
159 frame.titlebg:SetHeight(headerHeight)
160 frame.title:SetTextColor(unpack(headerColor))
161
162 if frame.height ~= frame.previousHeight then
163 frame:SetHeight(frame.height)
164 end
165
166 frame:Show()
167 if frame.wasEmpty then
168 frame.headerFade:Play()
169 frame.wasEmpty = nil
170 end
171
172 wrapperHeight = wrapperHeight + frame.height
173 anchorFrame = handler.frame
174 anchorPoint = 'BOTTOM'
175
176 end
102 177
103 Default.AddBlock = function(self, block, blockIndex) 178 Default.AddBlock = function(self, block, blockIndex)
104 local blockIndex = blockIndex or (self.currentBlock + 1) 179 local blockIndex = blockIndex or (self.currentBlock + 1)
105 local print = bprint 180 local print = bprint
106 local tracker = self.frame 181 local tracker = self.frame
107 local info = block.info 182 local info = block.info
108 183
184 block.index = blockIndex
185
109 if blockSchema ~= block.schema then 186 if blockSchema ~= block.schema then
110 print('new schema detected, applicating...') 187 print('new schema detected, applicating...')
111 block.schema = blockSchema 188 block.schema = blockSchema
112 block:SetWidth(Module.Conf.Wrapper.Width) 189 block:SetWidth(T.Conf.Wrapper.Width)
113 block.title:SetSpacing(titleSpacing) 190 block.title:SetSpacing(titleSpacing)
114 block.title:SetPoint('TOP', block, 'TOP', 0, -titleSpacing) 191 block.title:SetPoint('TOP', block, 'TOP', 0, -titleSpacing)
115 block.title:SetPoint('LEFT', block, 'LEFT', titleIndent, 0) 192 block.title:SetPoint('LEFT', block, 'LEFT', titleIndent, 0)
116 block.titlebg:SetTexture(1,1,1,1) 193 block.titlebg:SetTexture(1,1,1,1)
117 block.titlebg:SetGradientAlpha(unpack(titlebg)) 194 block.titlebg:SetGradientAlpha(unpack(titlebg))
137 block.rewardLabel[i]:SetPoint('TOP', tile, 'TOP', 0, 0) 214 block.rewardLabel[i]:SetPoint('TOP', tile, 'TOP', 0, 0)
138 anchor, target, point, x, y = 'TOPRIGHT', tile, 'TOPLEFT', -2, 0 215 anchor, target, point, x, y = 'TOPRIGHT', tile, 'TOPLEFT', -2, 0
139 end 216 end
140 end 217 end
141 218
219
220 local titleHeight = floor(block.title:GetHeight()+.5)
221 local titlebgHeight = titleHeight + titleSpacing*2
222 block.titlebg:SetHeight(titlebgHeight)
223
224 local statusHeight = floor(block.status:GetHeight()+.5)
225 local statusbgHeight = statusHeight + textSpacing*2
226 local attachmentHeight =floor(block.attachmentHeight + .5)
227
228 print(' |cFF0088FFanchor to', self.currentAnchor:GetName())
229 print(' |cFF00FF00attachment:|r', attachmentHeight, '|cFF00FF00title:|r', titlebgHeight, '('.. titleHeight..')')
230 if attachmentHeight > 0 then
231 attachmentHeight = attachmentHeight + textSpacing
232 end
233
234 block.height = titlebgHeight + attachmentHeight
235 block:SetHeight(block.height)
236
142 if block.debug then 237 if block.debug then
143 local func = (B.Conf.GuidesMode == true) and 'Show' or 'Hide' 238 local func = (B.Conf.GuidesMode == true) and 'Show' or 'Hide'
144 for _, region in ipairs(block.debug) do 239 for _, region in ipairs(block.debug) do
145 region[func]() 240 region[func]()
146 end 241 end
147 end 242 end
148 243
149 -- positioned by offset since they tend to swap contents 244 --- Handler vars
150 block.index = blockIndex 245 if blockIndex == 1 then
151 block:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 0, block.offset) 246 tracker.previousHeight = tracker.height
152 block:SetPoint('RIGHT', tracker,'RIGHT', 0, 0) 247 tracker.height = headerHeight
248 blockPosition = -headerHeight
249 tprint(' |cFF88FF00AddBlock:|r new layout: headerHeight =', headerHeight, 'previousHeight =', tracker.previousHeight)
250 else
251 blockPosition = blockPosition
252 tprint(' |cFF8888FFAddBlock:|r advancing: height =', tracker.height)
253 end
153 self.currentBlock = blockIndex 254 self.currentBlock = blockIndex
154 self.currentAnchor = block 255 self.currentAnchor = block
256
257 block:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 0, blockPosition)
258 block:SetPoint('RIGHT', tracker,'RIGHT', 0, 0)
259 self.numBlocks = self.numBlocks + 1
155 print(' |cFFFFFF00'..tracker.height..'|r', '|cFF00FF00'..block:GetName()..'|r', block.height, tracker.height) 260 print(' |cFFFFFF00'..tracker.height..'|r', '|cFF00FF00'..block:GetName()..'|r', block.height, tracker.height)
156 tracker.height = tracker.height + block.height 261 tracker.height = tracker.height + block.height
157 self.actualBlocks = self.actualBlocks + 1 262 blockPosition = blockPosition - block.height
158 end 263 end
159 264
160 --- Used as an iterator of sorts for cascaded tag icon placements (the daily/faction/account icons) 265 --- Used as an iterator of sorts for cascaded tag icon placements (the daily/faction/account icons)
161 Default.AddTag = function (handler, block, tagInfo, tagPoint, tagAnchor, tagRelative) 266 Default.AddTag = function (handler, block, tagInfo, tagPoint, tagAnchor, tagRelative)
162 local print = bprint 267 local print = bprint
180 Default.AddLine = function(handler, block, text, attachment, template) 285 Default.AddLine = function(handler, block, text, attachment, template)
181 local print = lprint 286 local print = lprint
182 local lineIndex = block.currentLine + 1 287 local lineIndex = block.currentLine + 1
183 local line = handler:GetLine(block, lineIndex) 288 local line = handler:GetLine(block, lineIndex)
184 line.index = lineIndex 289 line.index = lineIndex
185 if line.schema ~= template then 290 if template then
186 print(' |cFF00FF00change schema', template) 291 if line.schema ~= template then
187 Module.UpdateSchema('line', template) 292 print(' |cFF00FF00change schema', template)
188 line.status:SetSpacing(textSpacing) 293 T.UpdateSchema('line', template)
189 line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0) 294 line.status:SetSpacing(textSpacing)
190 line.status:SetPoint('RIGHT', line, 'RIGHT', -textIndent, 0) 295 line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
191 line.status:SetTextColor(unpack(textColor)) 296 line.status:SetPoint('RIGHT', line, 'RIGHT',0, 0)
192 line.schema = template 297 line.status:SetTextColor(unpack(textColor))
193 else 298 line.schema = template
194 print(' |cFFFFFF00keep schema', template) 299 else
300 print(' |cFFFFFF00keep schema', line.schema)
301 end
195 end 302 end
196 line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing) 303 line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing)
197 line:Show() 304 line:Show()
198 305
199 306
200 print(' |cFF0088FFAddLine >>|r', block, '::', block.endPoint:GetName(),'"'.. text .. '"', attachment, template) 307 tprint(' |cFF0088FFAddLine|r (|cFF00FFFF'..tostring(line.schema)..'|r):', line:GetName())
201 308
202 309
203 -- fill in the text, then derive pixel-rounded height 310 -- fill in the text, then derive pixel-rounded height
204 line.status:SetText(text) 311 line.status:SetText(text)
205 line.height = floor(line.status:GetStringHeight()+.5) 312 line.height = floor(line.status:GetStringHeight()+.5)
206 313
207 -- For progressbar and timer lines, status text may be used as the title heading 314 -- For progressbar and timer lines, status text may be used as the title heading
208 if attachment then 315 if attachment then
209 print(' |cFFFF0088doing things with a widget', attachment:GetSize()) 316 print(' |cFFFF0088doing things with a widget', attachment:GetSize())
210 line.height = attachment:GetHeight() 317 line.height = attachment:GetHeight()
211 if text then 318 if text then
212 line.height = max(line.height, line.status:GetStringHeight()) 319 line.height = max(line.height, line.status:GetStringHeight())
213 end 320 end
214 if attachment.status:GetText() then 321 if attachment.status:GetText() then
217 attachment:Show() 324 attachment:Show()
218 end 325 end
219 326
220 line:SetHeight(line.height) 327 line:SetHeight(line.height)
221 block.attachmentHeight = block.attachmentHeight + line.height + textSpacing 328 block.attachmentHeight = block.attachmentHeight + line.height + textSpacing
222 print(' |cFF0088FFsetting line #'..lineIndex..' for|r', block.info.title, "\n |cFF0088FFsize:|r", line.height, 329
223 "|cFF0088FFpoint:|r", line:GetPoint(1), "|cFF0088FFwidget:|r", (line.widget and 'Y' or 'N')) 330 local debug_points = ''
331 for i = 1, line:GetNumPoints() do
332 local point, parent, anchor = line:GetPoint(i)
333 debug_points = debug_points .. tostring(parent:GetName()) .. ', ' .. anchor .. ' '
334 end
335
336 print(' |cFF0088FFsetting line #'..lineIndex..' for|r', block.info.title, "\n |cFF0088FFsize:|r", line.height,
337 "|cFF0088FFpoint:|r", debug_points, "|cFF0088FFwidget:|r", (line.widget and 'Y' or 'N'))
224 block.currentLine = lineIndex 338 block.currentLine = lineIndex
225 block.endPoint = line.statusbg -- edge used for the next block 339 block.endPoint = line.statusbg -- edge used for the next block
226 340
227 return lineIndex 341 return lineIndex
228 end 342 end
243 print(' |cFF00FF88created line #'..lineIndex..' from for '..handler.name..' block #'..blockIndex) 357 print(' |cFF00FF88created line #'..lineIndex..' from for '..handler.name..' block #'..blockIndex)
244 lines[lineIndex] = CreateFrame('Frame', 'Vn'..handler.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective') 358 lines[lineIndex] = CreateFrame('Frame', 'Vn'..handler.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective')
245 local line = lines[lineIndex] 359 local line = lines[lineIndex]
246 line.index = lineIndex 360 line.index = lineIndex
247 line.height = 0 361 line.height = 0
362 line.schema = 'default'
248 B.SetConfigLayers(line) 363 B.SetConfigLayers(line)
249 364
250 if debug then 365 if debug then
251 for _, region in ipairs(lines[lineIndex].debug) do 366 for _, region in ipairs(lines[lineIndex].debug) do
252 region:Show() 367 region:Show()
261 376
262 --- Creates or retrieves a complete block frame object 377 --- Creates or retrieves a complete block frame object
263 --- todo: make it use data index to avoid re-coloring every block 378 --- todo: make it use data index to avoid re-coloring every block
264 Default.GetBlock = function(handler, logIndex) 379 Default.GetBlock = function(handler, logIndex)
265 local print = bprint 380 local print = bprint
266 print('|cFFFFFF00getting a block for logID', logIndex ..',', #handler.usedBlocks,'used', #handler.freeBlocks, 'free') 381 print('|cFF0088FFgetting a block for logID', logIndex ..',', #handler.usedBlocks,'used', #handler.freeBlocks, 'free')
267 local block = handler.LogBlock[logIndex] 382 local block = handler.LogBlock[logIndex]
383 local used = handler.usedBlocks
268 384
269 if not block then 385 if not block then
270 if #handler.freeBlocks >= 1 then 386 if #handler.freeBlocks >= 1 then
271 block = tremove(handler.freeBlocks) 387 block = tremove(handler.freeBlocks)
272 print(' assigning from free heap|cFF00FFFF', block:GetName()) 388 tinsert(handler.usedBlocks, block)
389 block.posIndex = #handler.usedBlocks
390 print(' |cFF00FF00 assigning from free heap', block:GetName())
273 else 391 else
274 392
275 local blockIndex = handler.numBlocks + 1 393 local blockIndex = (#handler.usedBlocks + #handler.freeBlocks) + 1
276 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, handler.frame, 'VeneerTrackerBlock') 394 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, handler.frame, 'VeneerTrackerBlock')
395 --block:SetParent()
277 block.lines = {} 396 block.lines = {}
278 block.numLines = 0 397 block.numLines = 0
279 block.currentLine = 0 398 block.currentLine = 0
280 block.attachmentHeight = 0 399 block.attachmentHeight = 0
400 block.offset = 0
281 B.SetConfigLayers(block) 401 B.SetConfigLayers(block)
282 --- methods for event handlers 402 --- methods for event handlers
283 403
284 block.Select = handler.Select 404 block.Select = handler.Select
285 block.Open = handler.Open 405 block.Open = handler.Open
287 block.Link = handler.Link 407 block.Link = handler.Link
288 block.clickZone:SetScript('OnMouseUp', function(self, ...) handler.OnMouseUp(block, ...) end) 408 block.clickZone:SetScript('OnMouseUp', function(self, ...) handler.OnMouseUp(block, ...) end)
289 block.clickZone:SetScript('OnMouseDown', function(self, ...) handler.OnMouseDown(block, ...) end) 409 block.clickZone:SetScript('OnMouseDown', function(self, ...) handler.OnMouseDown(block, ...) end)
290 block:ClearAllPoints() 410 block:ClearAllPoints()
291 block.index = blockIndex 411 block.index = blockIndex
292 handler.numBlocks = max(handler.numBlocks, blockIndex) 412 print(' |cFF00FFBBcreating new|r', block:GetName())
293
294 print(' |cFFFFFF00creating new|r', block:GetName())
295 end 413 end
296 handler.LogBlock[logIndex] = block 414 handler.LogBlock[logIndex] = block
297 tinsert(handler.usedBlocks, block) 415 tinsert(handler.usedBlocks, block)
416 block.posIndex = #handler.usedBlocks
298 else 417 else
299 print(' |cFFFFFF00use existing block|r', block:GetName()) 418 print(' |cFFFFFF00use existing block|r', block:GetName())
419 local found = false
420 for i, entry in ipairs(used) do
421 if entry == block then
422 found = true
423 break
424 end
425 end
426 if not found then
427 tinsert(used, block)
428 block.posIndex = #used
429 end
300 end 430 end
301 return block 431 return block
302 end 432 end
303 433
304 local currentPosition, anchorFrame, anchorPoint 434
305 --- Positioning and stuff 435
306 local tick = 0 436
307 local firstUpdate = true
308 function Module:Update (reason, ...)
309 if not B.Conf.VeneerObjectiveWrapper.enabled then
310 return
311 end
312
313 tick = tick + 1
314 if firstUpdate or not reason then
315 reason = _G.OBJECTIVE_TRACKER_UPDATE_ALL
316 end
317
318 local print = tprint
319 local updateWrapper = 0
320 local hasStuff
321 local insertingStuff
322
323 print(format('|cFFBB0066Update:|r |cFFFF%04X%d|r ', tick, lshift(reason, 4)), reason, ...)
324 currentPosition = 0
325 anchorPoint = 'TOP'
326 anchorFrame = Scroll
327
328 local wrapperHeight = 0
329 for id, handler in pairs(Module.orderedHandlers) do
330 local frame = handler.frame
331
332
333 if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then
334 handler:UpdateTracker(reason, ...)
335 insertingStuff = true
336 else
337 print(' |cFFFF0088'..id..'|r', 'no reason to update')
338 end
339
340 if handler.numWatched >= 1 then
341
342 print(format('|cFF88FFBB%s and(%04X, %04x+%04x) = %04X|r', handler.name, reason, handler.updateReasonModule, handler.updateReasonEvents, band(reason, handler.updateReasonModule + handler.updateReasonEvents)))
343 hasStuff = true
344 currentPosition = currentPosition + 1
345 frame.destinationOffset = -wrapperHeight
346 if (not firstUpdate) and frame.previousOffset ~= wrapperHeight and frame:IsVisible() then
347 print(frame.SlideIn.translation)
348 local postFrame, postPoint = anchorFrame, anchorPoint
349 local delta = frame.destinationOffset - frame.previousOffset
350 local _, _, _, _, offset = frame:GetPoint(1)
351 print(' |cFF00BBFFstart slide for', delta, 'pixels, from', frame.previousOffset, '(', offset, ')')
352 frame.SlideIn.translation:SetTarget(frame)
353 frame.SlideIn.translation:SetOffset(0, delta)
354 frame.SlideIn:Play()
355 for i, b in ipairs(handler.usedBlocks) do
356 b.SlideIn.translation:SetOffset(0, delta)
357 b.SlideIn:Play()
358 end
359 local start = GetTime()
360 frame.SlideIn:SetScript('OnFinished', function()
361 print(' |cFF00BBFFsliding finished:', delta, 'pixels covered; duration:', GetTime()-start)
362 frame:SetParent(Scroll)
363 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
364 frame.previousOffset = frame.destinationOffset
365 frame.SlideIn:SetScript('OnFinished', nil)
366 if Wrapper.destinationHeight then
367 Wrapper:SetHeight(Wrapper.destinationHeight)
368 Scroller:SetHeight(Wrapper.destinationHeight)
369 Scroll:SetHeight(Wrapper.destinationHeight)
370 Wrapper.previousHeight = Wrapper.destinationHeight
371 Wrapper.destinationHeight = nil
372 end
373
374 end)
375 else
376 print(' |cFF00BBFFpinning to', anchorFrame:GetName(), anchorPoint, '|rcurrent frame height:', frame.height)
377 print(' |cFFFF0088total height:', wrapperHeight)
378 frame:SetParent(Scroll)
379 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
380 end
381
382 frame:Show()
383 anchorFrame = handler.frame
384 anchorPoint = 'BOTTOM'
385
386 wrapperHeight = wrapperHeight + frame.height
387 else
388
389 print(' |cFFFF4400GetNumWatched:|r',handler.name, '0')
390 frame:SetPoint('TOP', Scroll, 'TOP', 0, 0)
391 frame.destinationOffset = 0
392 frame.previousOffset = 0
393 handler.frame:Hide()
394 end
395 end
396
397
398 if hasStuff or insertingStuff then
399 print('updating height to', wrapperHeight)
400 if wrapperHeight > Wrapper.previousHeight then
401 Wrapper:SetHeight(wrapperHeight)
402 Scroller:SetHeight(wrapperHeight)
403 Scroll:SetHeight(wrapperHeight)
404 Wrapper.previousHeight = wrapperHeight
405 Wrapper.destinationHeight = wrapperHeight
406 end
407 Scroller:SetVerticalScroll(B.Conf.ObjectiveScroll or 0)
408 print('|cFFFF8800Wrapper:', Wrapper:GetSize())
409 for i = 1, Wrapper:GetNumPoints() do
410 print(' ', Wrapper:GetPoint(i))
411 end
412 print(' |cFF00FFFFScroller:', Scroller:GetSize())
413 for i = 1, Scroller:GetNumPoints() do
414 print(' ', Scroller:GetPoint(i))
415 end
416 print(' |cFF00FFFFScroll:', Scroll:GetSize())
417 for i = 1, Scroll:GetNumPoints() do
418 print(' ', Scroll:GetPoint(i))
419 end
420
421 Wrapper:Show()
422 Scroller:Show()
423 Scroll:Show()
424 end
425 Quest.GetClosest()
426 --Module.UpdateActionButtons(reason)
427 if firstUpdate then
428 firstUpdate = nil
429 end
430 end
431
432 --- Content generator base
433 Default.UpdateTracker = function (handler, reason, id, isNew)
434 local print = tprint
435 local tracker = handler.frame
436 local blockIndex = 0
437 tracker.previousHeight = tracker.height
438 tracker.height = 0
439
440 tracker.title:SetFont(headerFont, headerSize, headerOutline)
441 tracker.titlebg:SetHeight(headerHeight)
442 tracker.title:SetTextColor(unpack(headerColor))
443
444 handler.updateReason = reason
445 handler.numWatched = handler:GetNumWatched()
446 if handler.numWatched >= 1 then
447
448 print(' |cFF00FF88GetNumWatched:|r',handler.name, handler.numWatched, 'of', handler.numAll)
449 end
450
451 handler.currentBlock = 0
452 handler.currentAnchor = tracker.titlebg
453 local blockPosition = -headerHeight
454 for blockIndex = 1, handler.numWatched do
455 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew)
456 if currentBlock then
457 currentBlock.offset = blockPosition
458 handler:AddBlock(currentBlock)
459 blockPosition = blockPosition - currentBlock.height
460 else
461 print(' |cFFFF9900END|r @', blockIndex)
462 break -- done with quest stuff
463 end
464 end
465
466
467 local numBlocks = handler.numBlocks
468 local used = handler.usedBlocks
469 if numBlocks < #used then
470 print(' |cFF0088FFcull the dead: showing|r', numBlocks, '|cFF0088FF out of|r', #used)
471 local free = handler.freeBlocks
472 local remaining = #used
473 for i = #used, 1, -1 do
474 print(' -', 'i='.. i, 'watchIndex='..used[i].info.watchIndex)
475 if used[i].info.watchIndex > numBlocks then
476 print(' clean up dead quest block')
477 local released = tremove(used, i)
478 released:Hide()
479 released:ClearAllPoints()
480 tinsert(free, used[blockIndex])
481 end
482 end
483 end
484
485
486 if handler.currentBlock >= 1 then
487 tracker.height = tracker.height + headerHeight
488 tracker:Show()
489
490 if tracker.wasEmpty then
491 tracker.headerFade:Play()
492 tracker.wasEmpty = nil
493 end
494 if tracker.height ~= tracker.previousHeight then
495 tracker:SetHeight(tracker.height)
496 end
497 print(' |cFFFFFF00', tracker.height, tracker:GetWidth())
498 else
499 tracker:Hide()
500 tracker.wasEmpty = true
501 end
502
503 return tracker.numWatched, tracker.numAll
504 end
505
506
507 --- Updates the selected block frame to display the given info batch
508 -- If `previousBlock` is set, it will attempt to anchor to that
509 -- @param blockNum the ordered block to be updated, not a watchIndex value
510 -- @param info the reference returned by the GetXInfo functions
511 -- REMEMBER: t.info and questData[questID] are the same table
512 Default.UpdateBlock = function (handler, blockIndex, id, added)
513 local print = bprint
514 if not blockIndex then
515 return
516 end
517 local info = handler:GetInfo(blockIndex) -- should match up with whatever the internal watch list has
518 if not info then
519 return
520 end
521 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..blockIndex..'|r|cFF0099FF', info.id ,'|r')
522 local frame = handler.frame
523 local block = handler:GetBlock(info.id)
524
525 if added then
526 -- do something if the block is being assigned a new thing
527 end
528
529 block.handler = handler
530 block.info = info
531
532 info.blockIndex = blockIndex
533 if info.questID then handler.QuestBlock[info.questID] = block end
534 if info.logIndex then handler.LogBlock[info.logIndex] = block end
535 if info.watchIndex then handler.WatchBlock[info.watchIndex] = block end
536 handler.BlockInfo[blockIndex] = info
537 local newSchema = handler:UpdateObjectives(block)
538 if newSchema and newSchema ~= blockSchema then
539 Module.UpdateSchema('block', newSchema)
540 end
541
542 block.title:SetText(info.title)
543 local titleHeight = floor(block.title:GetHeight()+.5)
544 local titlebgHeight = titleHeight + titleSpacing*2
545 block.titlebg:SetHeight(titlebgHeight)
546
547 local statusHeight = floor(block.status:GetHeight()+.5)
548 local statusbgHeight = statusHeight + textSpacing*2
549 local attachmentHeight =floor(block.attachmentHeight + .5)
550
551 print(' |cFF0088FFanchor to', handler.currentAnchor:GetName())
552 print(' |cFF00FF00attachment:|r', attachmentHeight, '|cFF00FF00title:|r', titlebgHeight, '('.. titleHeight..')')
553 if attachmentHeight > 0 then
554 attachmentHeight = attachmentHeight + textSpacing
555 end
556
557 block.height = titlebgHeight + attachmentHeight
558
559 block:SetHeight(block.height)
560
561 print(' |cFFFFFF00height|r:', block.height)
562 print(' |cFF00FFFF)|r -> ', block, block:GetHeight())
563
564 block:Show()
565
566 if info.specialItem and not info.itemButton then
567 print(' - |cFF00FFFFgenerating item button for info set')
568 info.itemButton = Module.SetItemButton(block, info)
569 else
570 --info.itemButton = nil
571 end
572
573 local tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2
574
575 local numCurrency = 0
576 for i, rewardTile in ipairs(block.rewardTile) do
577 if info.rewardInfo and info.rewardInfo[i] then
578 local reward = info.rewardInfo[i]
579 --rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, -2, -2)
580 rewardTile:SetTexture(reward.texture)
581 rewardTile:Show()
582
583 print('updating reward tile #'.. i, reward.type, reward.count, reward.text, reward.texture)
584 if reward.count and reward.count > 1 then
585 block.rewardLabel[i]:SetText(reward.count)
586 block.rewardLabel[i]:Show()
587 end
588
589 rewardTile:ClearAllPoints()
590 rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, x, y)
591 tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', rewardTile, 'TOPLEFT', -2, 0
592 else
593 rewardTile:Hide()
594 block.rewardLabel[i]:Hide()
595 end
596 end
597
598 if info.selected then
599 block.SelectionOverlay:Show()
600 else
601 block.SelectionOverlay:Hide()
602 end
603 -- workaround for scrollchild issue where layers fall out of sync: in this case, it's by 1 vertical pixel
604 --block.highlight:SetPoint('TOPLEFT', block, 'TOPLEFT', 0, 1)
605 --block.lowlight:SetPoint('BOTTOMLEFT', block, 'BOTTOMLEFT', 0, 1)
606
607 if info.tagInfo then
608 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative)
609 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative)
610 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative)
611 end
612
613 if info.statusKey and (Devian and Devian.InWorkspace()) then
614 block.debugText:SetText(info.statusKey)
615 block.debugText:Show()
616 end
617 return block
618 end
619
620
621
622
623 --- Does the main iterations for populating block content.
624 -- Hooked by corresponding handler functions where additional details need to be sorted.
625 Default.UpdateObjectives = function(handler, block, block_schema)
626 local print = lprint
627 local info = block.info
628 print('|cFF00FF00default.objectives', block:GetName())
629 -- reset the starting positions
630 block.endPoint = block.titlebg
631 block.attachmentHeight = 0
632 block.currentLine = 0
633
634 local displayObjectiveHeader = false
635
636 block.attachmentHeight = 0
637 local text, attachment, template
638
639
640 if info.description and #info.description >= 1 then
641 print(' |cFF00FFFF header line:|r', info.description)
642 text = info.description
643 handler:AddLine(block, text, nil)
644 end
645
646 if (info.isComplete or info.numObjectives == 0) and info.completionText then
647 print(' overriding line #1 for completion text:', info.completionText)
648 text = info.completionText
649 handler:AddLine(block, text, nil, 'completed')
650 else
651 if info.objectives then
652 for i, data in ipairs(info.objectives) do
653 local line = handler:GetLine(block)
654 displayObjectiveHeader = true
655 line.height = 0
656 text, attachment, template = handler:UpdateLine(block, line, data)
657 print(' |cFF88FF00#', i, data.type, text, attachment)
658 handler:AddLine(block, text, attachment, template)
659
660 end
661 end
662 end
663
664
665 if block.currentLine < block.numLines then
666 print(' - cull', block.currentLine, block.numLines)
667 for i = block.currentLine + 1, block.numLines do
668 print(' - hide |cFFFF0088'..i..'|r', block.lines[i])
669 block.lines[i]:ClearAllPoints()
670 block.lines[i]:Hide()
671 end
672 end
673
674 if block.currentLine > 0 then
675 block.attachmentHeight = block.attachmentHeight + textSpacing
676 print(' |cFF00FF00attachment:', block.attachmentHeight)
677 end
678 return block_schema
679 end
680
681
682 --- Module-specific display variables
683 -- * height - height of whatever display widget is involved in conveying the task
684 -- * money - boolean that determines listening for money events or not
685 -- * progress - number ranging 0 to 2 indicating none/partial/full completion respectively
686
687
688 Default.UpdateLine = function(handler, block, line, data)
689 if line.finished then
690 line.progress = 2
691 elseif line.quantity > 0 then
692 line.progress = 1
693 else
694 line.progress = 0
695 end
696 return data.text, line.widget, 'normal'
697 end
698 ---------- 437 ----------
699 --- Top level methods 438 --- Top level methods
700 439
701 --- Queue any active item buttons for update for that frame 440
702 local iprint = B.print('ItemButton') 441 T.UpdateBlockAction = function (block, itemButton)
703 Module.UpdateActionButtons = function(updateReason) 442 local print = bprint
704 local print = iprint
705 Scroller.snap_upper = 0
706 Scroller.snap_lower = 0
707 local print = B.print('ItemButton')
708 if updateReason then
709 print = B.print('IB_'..updateReason)
710 end
711
712 local previousItem
713 for questID, itemButton in pairs(Quest.itemButtons) do
714 local info= Module.Quest.Info[questID]
715
716 print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName())
717 local block = Module.Quest.QuestBlock[questID]
718 if block then
719 -- Dispatch the probe
720 if IsQuestWatched(info.logIndex) then
721 itemButton.previousItem = previousItem
722 print(' |cFFFFFF00probing', block:GetName())
723 block:SetScript('OnUpdate', function()
724 if block:GetBottom() and not InCombatLockdown() then
725 print(' '..block:GetName()..' |cFF00FF00probe hit!')
726 Module.UpdateBlockAction(block, itemButton, itemButton.previousItem) -- needs to be previousItem from this scope
727 block:SetScript('OnUpdate', nil)
728
729 end
730 end)
731 previousItem = itemButton
732 else
733 print('hidden block or unwatched quest')
734 itemButton.previousItem = nil
735 itemButton:Hide()
736 end
737 elseif itemButton:IsVisible() then
738 print(' |cFFFF0088hiding unwatched quest button', itemButton:GetName())
739 itemButton.previousItem = nil
740 itemButton:Hide()
741 else
742 print(' |cFFBBBBBBignoring hidden log quest button', itemButton:GetName())
743 end
744 end
745 end
746
747 Module.UpdateBlockAction = function (block, itemButton)
748 local print = iprint
749 print('**|cFF0088FF'..itemButton:GetName(), '|r:Update()') 443 print('**|cFF0088FF'..itemButton:GetName(), '|r:Update()')
750 if itemButton.questID ~= block.info.questID then 444 if itemButton.questID ~= block.info.questID then
751 print('** |cFFFF0088mismatched block assignment', itemButton.questID,'<~>', block.info.questID) 445 print('** |cFFFF0088mismatched block assignment', itemButton.questID,'<~>', block.info.questID)
752 -- something happened between this and last frame, go back and set new probes 446 -- something happened between this and last frame, go back and set new probes
753 return Module.UpdateActionButtons() 447 return T.UpdateActionButtons()
754 end 448 end
755 449
756 local previousItem = itemButton.previousItem 450 local previousItem = itemButton.previousItem
757 local upper_bound = Scroller:GetTop() + Scroller.snap_upper 451 local upper_bound = Scroller:GetTop() + Scroller.snap_upper
758 local lower_bound = Scroller:GetBottom() + Scroller.snap_lower + itemButtonSize 452 local lower_bound = Scroller:GetBottom() + Scroller.snap_lower + itemButtonSize
797 491
798 itemButton:SetPoint(point, anchor, relative, itemButton.x, itemButton.y) 492 itemButton:SetPoint(point, anchor, relative, itemButton.x, itemButton.y)
799 itemButton:Show() 493 itemButton:Show()
800 end 494 end
801 495
802 Module.UpdateItemButtonCooldown = function(button) 496 T.UpdateItemButtonCooldown = function(button)
803 497
804 end 498 end
805 499
806 500 function T:FinishWrapper ()
807 Default.Select = function(handler, block) 501 if wrapperHeight > Wrapper.previousHeight then
808 Module:Update(handler.watchReasonModule) 502 Wrapper:SetHeight(wrapperHeight)
809 end 503 Scroller:SetHeight(wrapperHeight*3)
810 Default.Open = function(handler, block) 504 Scroll:SetHeight(wrapperHeight)
811 Module:Update(handler.watchReasonModule) 505 Wrapper.previousHeight = wrapperHeight
812 end 506 Wrapper.destinationHeight = wrapperHeight
813 Default.Remove = function(handler, block) 507 end
814 Module:Update(handler.watchReasonModule) 508 Scroller:SetVerticalScroll(B.Conf.ObjectiveScroll or 0)
815 end 509 print('|cFF00FF00### end of wrapper layout', Wrapper:GetSize())
816 Default.Report = function(handler, block) 510 print(' |cFF00FF00Scroller:', Scroller:GetSize())
817 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.') 511 print(' |cFF00FF00Scroll:', Scroll:GetSize())
818 end 512 for i = 1, Wrapper:GetNumPoints() do
819 513 print('|cFF00FF00 ', Wrapper:GetPoint(i))
820 Default.OnMouseUp = function(self, button) 514 end
821 print(self.handler.name, self.mainStyle, self.subStyle) 515 for i = 1, Scroller:GetNumPoints() do
822 if button == 'LeftButton' then 516 print('|cFF00FF00 ', Scroller:GetPoint(i))
823 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then 517 end
824 self.Link(self.handler, self) 518 for i = 1, Scroll:GetNumPoints() do
825 elseif IsModifiedClick("QUESTWATCHTOGGLE") then 519 print('|cFF00FF00 ', Scroll:GetPoint(i))
826 self.Remove(self.handler, self) 520 end
827 else 521
828 self.Select(self.handler, self) 522 Wrapper:Show()
829 end 523 Scroller:Show()
830 elseif button == 'RightButton' then 524 Scroll:Show()
831 self.Open(self.handler, self) 525 end
832 end 526
833 self.initialButton = nil
834 self.modChatLink = nil
835 self.modQuestWatch = nil
836 Module:Update(self.handler.updateReasonModule)
837 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r')
838 end
839 Default.OnMouseDown = function(self, button)
840 print(self.info.title)
841 end