Nenue@35: --- ${PACKAGE_NAME} Nenue@35: -- @file-author@ Nenue@35: -- @project-revision@ @project-hash@ Nenue@35: -- @file-revision@ @file-hash@ Nenue@35: -- Created: 4/17/2016 7:33 AM Nenue@44: --- These are the first layer of methods invoked by event handlers Nenue@44: Nenue@35: local B = select(2,...).frame Nenue@35: local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') Nenue@38: local Devian = Devian Nenue@35: local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band Nenue@35: local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove Nenue@35: local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent Nenue@35: local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText Nenue@35: local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent Nenue@35: local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs Nenue@35: local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame Nenue@35: local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow Nenue@35: local print = B.print('Tracker') Nenue@35: local oprint = B.print('Objectives') Nenue@35: local bprint = B.print('Block') Nenue@35: local tprint = B.print('Tracker') Nenue@35: local lprint = B.print('Line') Nenue@35: local unitLevel = 1 Nenue@35: local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON Nenue@35: local debug = false Nenue@35: Nenue@35: --- FRAMES Nenue@35: local Wrapper = _G.VeneerObjectiveWrapper Nenue@35: local Scroller = Wrapper.scrollArea Nenue@35: local Scroll = _G.VeneerObjectiveScroll Nenue@35: local orderedHandlers = T.orderedHandlers Nenue@35: local orderedNames = T.orderedNames Nenue@35: Nenue@35: Nenue@35: --- Placing the Update functions here since they shouldn't be messing with schema stuff Nenue@35: local currentPosition, anchorFrame, anchorPoint Nenue@35: --- Positioning and stuff Nenue@35: local tick = 0 Nenue@38: local initReason = OBJECTIVE_TRACKER_UPDATE_ALL Nenue@38: local requiresInit Nenue@35: function T:Update (reason, ...) Nenue@35: if not B.Conf.VeneerObjectiveWrapper.enabled then Nenue@35: return Nenue@35: end Nenue@35: tick = tick + 1 Nenue@35: local print = tprint Nenue@35: local hasStuff = false Nenue@35: local insertingStuff = false Nenue@35: Nenue@38: if initReason then Nenue@38: reason = initReason Nenue@38: initReason = nil Nenue@38: elseif not reason then Nenue@38: reason = OBJECTIVE_TRACKER_UPDATE_ALL Nenue@38: end Nenue@45: print(format('|cFFBB0066Update:|r %d |cFFFF%04X%d|r ', tick, lshift(reason, 4)), reason, ...) Nenue@35: currentPosition = 0 Nenue@35: Nenue@35: for id, handler in pairs(T.orderedHandlers) do Nenue@35: local frame = handler.frame Nenue@35: Nenue@38: print('') Nenue@35: if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then Nenue@35: insertingStuff = handler:UpdateTracker(reason, ...) Nenue@35: else Nenue@35: print(' |cFFFF4400Update:|r skipping',handler.name) Nenue@35: end Nenue@35: Nenue@35: if handler.numWatched >= 1 then Nenue@35: hasStuff = true Nenue@35: currentPosition = currentPosition + 1 Nenue@35: Default.AddTracker(handler, frame, currentPosition) Nenue@40: frame.wasEmpty = nil Nenue@35: else Nenue@35: frame.destinationOffset = 0 Nenue@40: if not frame.wasEmpty and not frame.fadeOut:IsPlaying() then Nenue@40: frame.fadeOut:Play() Nenue@40: end Nenue@35: frame.wasEmpty = true Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: -- do these whenever there is content or content is being added Nenue@35: if hasStuff or insertingStuff then Nenue@35: T:FinishWrapper() Nenue@35: end Nenue@35: Quest.GetClosest() Nenue@43: T.UpdateActionButtons(reason) Nenue@35: end Nenue@35: Nenue@35: Default.UpdateTracker = function (handler, reason, id, isNew) Nenue@38: local print = handler.print Nenue@37: local frame = handler.frame Nenue@35: local blockIndex = 0 Nenue@40: print('MODULE:'..handler.name, 'message:', reason, 'id:', id, (isNew and '|cFF88FF88' or '|cFF555555')..'isNew|r') Nenue@35: handler.updateReason = reason Nenue@37: local numWatched, numAll, watchTable = handler:GetNumWatched(id, isNew) Nenue@35: Nenue@37: if numWatched >= 1 then Nenue@37: if watchTable then Nenue@38: print(' WatchList', ' n ID Obj wID Log Blk') Nenue@37: for i, w in ipairs(watchTable) do Nenue@38: 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 ''))) Nenue@37: end Nenue@37: end Nenue@35: end Nenue@35: Nenue@37: handler.numWatched = numWatched Nenue@37: handler.numAll = numAll Nenue@35: handler.numBlocks = 0 Nenue@35: handler.currentBlock = 0 Nenue@37: handler.currentAnchor = frame.titlebg Nenue@37: for blockIndex = 1, numWatched do Nenue@35: local currentBlock = handler:UpdateBlock(blockIndex, id, isNew) Nenue@35: if currentBlock then Nenue@35: handler:AddBlock(currentBlock) Nenue@35: else Nenue@38: print(' |cFF'..handler.internalColor..'finished|r @', blockIndex) Nenue@35: break -- done with quest stuff Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: local numBlocks = handler.numBlocks Nenue@35: local used = handler.usedBlocks Nenue@35: local free = handler.freeBlocks Nenue@38: 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)) Nenue@38: Nenue@37: return numWatched, numAll Nenue@35: end Nenue@35: Nenue@37: Default.UpdateBlock = function (handler, index) Nenue@43: --@debug@ Nenue@43: local print = bprint -- @end-debug@ Nenue@37: if not index then Nenue@35: return Nenue@35: end Nenue@37: local info = handler.WatchList[index] -- should match up with whatever the internal watch list has Nenue@35: if not info then Nenue@35: return Nenue@35: end Nenue@35: local frame = handler.frame Nenue@35: local block = handler:GetBlock(info.id) Nenue@35: Nenue@44: --@debug@ Nenue@44: handler.print('UpdateBlock', '|cFF00FFFF'..index..'|r|cFF0099FF', info.id ,'|r', (block.isAnimating and 'animating' or 'static'))--@end-debug@ Nenue@43: if block.isAnimating then Nenue@43: -- Nothing to do, leave it as is Nenue@43: return block Nenue@43: end Nenue@43: Nenue@35: block.handler = handler Nenue@35: block.info = info Nenue@37: info.blockIndex = index Nenue@43: --@debug@ Nenue@43: local keyInfo--@end-debug@ Nenue@37: if info.id then Nenue@37: handler.InfoBlock[info.id] = block Nenue@43: --@debug@ Nenue@43: keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'InfoBlock[' .. info.id .. '] = *' .. block:GetName():gsub('%D', '') --@end-debug@ Nenue@35: end Nenue@37: if info.logIndex then Nenue@37: handler.LogBlock[info.logIndex] = block Nenue@43: --@debug@ Nenue@43: keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'LogBlock[' .. info.logIndex .. '] = ' .. block:GetName():gsub('%D', '')--@end-debug@ Nenue@37: end Nenue@37: if info.watchIndex then Nenue@37: handler.WatchBlock[info.watchIndex] = block Nenue@43: --@debug@ Nenue@43: keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'WatchBlock[' .. info.watchIndex .. '] = ' .. block:GetName():gsub('%D', '')--@end-debug@ Nenue@37: end Nenue@43: --@debug@ Nenue@43: if keyInfo then print(' assigned', keyInfo) end--@end-debug@ Nenue@37: handler.BlockInfo[index] = info Nenue@38: block.endPoint = block.titlebg Nenue@38: block.attachmentHeight = 0 Nenue@38: block.currentLine = 0 Nenue@40: local attachments, override_schema = handler:UpdateObjectives(block, block.schema) Nenue@35: Nenue@44: Nenue@35: block.title:SetText(info.title) Nenue@35: Nenue@35: if info.specialItem and not info.itemButton then Nenue@43: --@debug@ Nenue@43: print(' - |cFF00FFFFgenerating item button for info set')--@end-debug@ Nenue@35: info.itemButton = T.SetItemButton(block, info) Nenue@35: end Nenue@35: Nenue@35: Nenue@35: if info.selected then Nenue@35: block.SelectionOverlay:Show() Nenue@35: else Nenue@35: block.SelectionOverlay:Hide() Nenue@35: end Nenue@35: Nenue@35: if info.tagInfo then Nenue@44: handler:AddTags(block, info.tagInfo, info.tagCoords) Nenue@35: end Nenue@35: Nenue@44: if override_schema then Nenue@44: block.schema = override_schema Nenue@44: elseif info.schema then Nenue@37: block.schema = info.schema Nenue@37: end Nenue@35: return block Nenue@35: end Nenue@35: Nenue@38: Default.UpdateObjectives = function(handler, block, block_schema, displayObjectives) Nenue@35: local print = lprint Nenue@38: displayObjectives = displayObjectives or true Nenue@38: block_schema = block_schema or block.schema Nenue@35: local info = block.info Nenue@35: print(' |cFF00FF00default.objectives', block:GetName()) Nenue@35: -- reset the starting positions Nenue@35: local text, attachment, template Nenue@40: local numAttachments = 0 Nenue@35: Nenue@38: if info.objectives and displayObjectives then Nenue@38: for i, data in ipairs(info.objectives) do Nenue@38: text, attachment, template = handler:UpdateLine(block, data) Nenue@38: if text or attachment then Nenue@35: local line = handler:GetLine(block) Nenue@35: line.height = 0 Nenue@35: print(' |cFF88FF00#', i, data.type, text, attachment) Nenue@35: handler:AddLine(block, text, attachment, template) Nenue@35: end Nenue@40: if attachment then Nenue@40: numAttachments = numAttachments + 1 Nenue@40: end Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: if block.currentLine < block.numLines then Nenue@35: print(' - cull', block.currentLine, block.numLines) Nenue@35: for i = block.currentLine + 1, block.numLines do Nenue@35: print(' - hide |cFFFF0088'..i..'|r', block.lines[i]) Nenue@35: block.lines[i]:ClearAllPoints() Nenue@35: block.lines[i]:Hide() Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: if block.currentLine > 0 then Nenue@35: block.attachmentHeight = block.attachmentHeight Nenue@35: print(' |cFF00FF00attachment:', block.attachmentHeight) Nenue@35: end Nenue@40: return numAttachments, block_schema Nenue@35: end Nenue@35: Nenue@38: Default.UpdateLine = function(handler, block, data) Nenue@38: return block.info.description, nil, 'default' Nenue@35: end Nenue@35: Nenue@35: Default.Select = function(handler, block) Nenue@35: T:Update() Nenue@35: end Nenue@35: Default.Open = function(handler, block) Nenue@37: T:Update(handler.updateReasonModule) Nenue@35: end Nenue@35: Default.Remove = function(handler, block) Nenue@37: T:Update(handler.updateReasonModule) Nenue@35: end Nenue@35: Default.Report = function(handler, block) Nenue@35: print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.') Nenue@35: end Nenue@35: Nenue@43: function Default:OnMouseUp (button) Nenue@44: print(self.handler.name, button, IsModifiedClick('CHATLINK'), IsModifiedClick("QUESTWATCHTOGGLE")) Nenue@35: if button == 'LeftButton' then Nenue@35: if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then Nenue@35: self.Link(self.handler, self) Nenue@35: elseif IsModifiedClick("QUESTWATCHTOGGLE") then Nenue@35: self.Remove(self.handler, self) Nenue@35: else Nenue@35: self.Select(self.handler, self) Nenue@35: end Nenue@35: elseif button == 'RightButton' then Nenue@35: self.Open(self.handler, self) Nenue@35: end Nenue@35: self.initialButton = nil Nenue@35: self.modChatLink = nil Nenue@35: self.modQuestWatch = nil Nenue@37: --T:Update(self.handler.updateReasonModule) Nenue@35: print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') Nenue@35: end Nenue@43: function Default:OnMouseDown (button) Nenue@44: --print(self.info.title) Nenue@35: end