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@35: local B = select(2,...).frame Nenue@35: local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') 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@35: local firstUpdate = true Nenue@35: function T:Update (reason, ...) Nenue@35: if not B.Conf.VeneerObjectiveWrapper.enabled then Nenue@35: return Nenue@35: end Nenue@35: Nenue@35: tick = tick + 1 Nenue@35: if firstUpdate or not reason then Nenue@35: reason = _G.OBJECTIVE_TRACKER_UPDATE_ALL Nenue@35: end Nenue@35: Nenue@35: local print = tprint Nenue@35: local hasStuff = false Nenue@35: local insertingStuff = false Nenue@35: Nenue@35: print(format('|cFFBB0066Update:|r |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@35: 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@35: Nenue@35: else Nenue@35: frame:ClearAllPoints() Nenue@35: frame:SetPoint('BOTTOM', Scroll, 'BOTTOM', 0, 0) Nenue@35: frame.destinationOffset = 0 Nenue@35: frame:Hide() 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@35: --T.UpdateActionButtons(reason) Nenue@35: if firstUpdate then Nenue@35: firstUpdate = nil Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: Default.UpdateTracker = function (handler, reason, id, isNew) Nenue@35: local print = tprint Nenue@37: local frame = handler.frame Nenue@35: local blockIndex = 0 Nenue@35: Nenue@37: print(format(' |cFFFF8800UpdateTracker|r(%s): %s', handler.name, reason)) 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@37: print('|cFF00FF00 n ID Obj wID Log Blk') Nenue@37: for i, w in ipairs(watchTable) do Nenue@37: print(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@35: print(' |cFFFF9900finished|r @', blockIndex) Nenue@35: break -- done with quest stuff Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: Nenue@35: local numBlocks = handler.numBlocks Nenue@35: local used = handler.usedBlocks Nenue@35: local free = handler.freeBlocks Nenue@37: 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@37: return numWatched, numAll Nenue@35: end Nenue@35: Nenue@37: Default.UpdateBlock = function (handler, index) Nenue@35: local print = bprint 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@37: print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..index..'|r|cFF0099FF', info.id ,'|r') Nenue@35: local frame = handler.frame Nenue@35: local block = handler:GetBlock(info.id) Nenue@35: Nenue@35: block.handler = handler Nenue@35: block.info = info Nenue@35: Nenue@37: info.blockIndex = index Nenue@37: if info.id then Nenue@37: print(' storing id', info.id, 'for', block:GetName()) Nenue@37: handler.InfoBlock[info.id] = block Nenue@35: end Nenue@37: if info.logIndex then Nenue@37: print(' storing logIndex', info.logIndex, 'for', block:GetName()) Nenue@37: handler.LogBlock[info.logIndex] = block Nenue@37: end Nenue@37: if info.watchIndex then Nenue@37: print(' storing watchIndex', info.watchIndex, 'for', block:GetName()) Nenue@37: handler.WatchBlock[info.watchIndex] = block Nenue@37: end Nenue@37: handler.BlockInfo[index] = info Nenue@37: handler:UpdateObjectives(block) Nenue@35: Nenue@35: block.title:SetText(info.title) Nenue@35: Nenue@35: print(' |cFFFFFF00height|r:', block.height) Nenue@35: print(' |cFF00FFFF)|r -> ', block, block:GetHeight()) Nenue@35: Nenue@35: block:Show() Nenue@35: Nenue@35: if info.specialItem and not info.itemButton then Nenue@35: print(' - |cFF00FFFFgenerating item button for info set') Nenue@35: info.itemButton = T.SetItemButton(block, info) Nenue@35: else Nenue@35: --info.itemButton = nil Nenue@35: end Nenue@35: Nenue@35: local tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2 Nenue@35: Nenue@35: local numCurrency = 0 Nenue@35: for i, rewardTile in ipairs(block.rewardTile) do Nenue@35: if info.rewardInfo and info.rewardInfo[i] then Nenue@35: local reward = info.rewardInfo[i] Nenue@35: --rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, -2, -2) Nenue@35: rewardTile:SetTexture(reward.texture) Nenue@35: rewardTile:Show() Nenue@35: Nenue@35: print('updating reward tile #'.. i, reward.type, reward.count, reward.text, reward.texture) Nenue@35: if reward.count and reward.count > 1 then Nenue@35: block.rewardLabel[i]:SetText(reward.count) Nenue@35: block.rewardLabel[i]:Show() Nenue@35: end Nenue@35: Nenue@35: rewardTile:ClearAllPoints() Nenue@35: rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, x, y) Nenue@35: tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', rewardTile, 'TOPLEFT', -2, 0 Nenue@35: else Nenue@35: rewardTile:Hide() Nenue@35: block.rewardLabel[i]:Hide() Nenue@35: end Nenue@35: end 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@35: tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative) Nenue@35: tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative) Nenue@35: tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative) Nenue@35: end Nenue@35: Nenue@37: if info.schema then Nenue@37: block.schema = info.schema Nenue@37: end Nenue@37: Nenue@35: if info.statusKey and (Devian and Devian.InWorkspace()) then Nenue@37: block.debugText:SetText(tostring(info.statusKey) .. ' ' .. tostring(block.posIndex) .. ' '.. tostring(info.logIndex)) Nenue@35: block.debugText:Show() Nenue@35: end Nenue@35: return block Nenue@35: end Nenue@35: Nenue@37: Default.UpdateObjectives = function(handler, block) Nenue@35: local print = lprint Nenue@37: local block_schema = block.schema Nenue@35: local info = block.info Nenue@35: print(' |cFF00FF00default.objectives', block:GetName()) Nenue@35: -- reset the starting positions Nenue@35: block.endPoint = block.titlebg Nenue@35: block.attachmentHeight = 0 Nenue@35: block.currentLine = 0 Nenue@35: Nenue@35: local displayObjectiveHeader = false Nenue@35: Nenue@35: block.attachmentHeight = 0 Nenue@35: local text, attachment, template Nenue@35: Nenue@35: Nenue@35: if info.description and #info.description >= 1 then Nenue@35: print(' |cFF00FFFF header line:|r', info.description) Nenue@35: text = info.description Nenue@35: handler:AddLine(block, text, nil) Nenue@35: end Nenue@35: Nenue@35: if (info.isComplete or info.numObjectives == 0) and info.completionText then Nenue@35: print(' overriding line #1 for completion text:', info.completionText) Nenue@35: text = info.completionText Nenue@35: handler:AddLine(block, text, nil, 'completed') Nenue@35: else Nenue@35: if info.objectives then Nenue@35: for i, data in ipairs(info.objectives) do Nenue@35: local line = handler:GetLine(block) Nenue@35: displayObjectiveHeader = true Nenue@35: line.height = 0 Nenue@35: text, attachment, template = handler:UpdateLine(block, line, data) Nenue@35: print(' |cFF88FF00#', i, data.type, text, attachment) Nenue@35: handler:AddLine(block, text, attachment, template) Nenue@35: Nenue@35: 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@35: return block_schema Nenue@35: end Nenue@35: Nenue@35: Default.UpdateLine = function(handler, block, line, data) Nenue@35: return data.text, line.widget, 'normal' 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@35: Default.OnMouseUp = function(self, button) Nenue@35: print(self.handler.name, self.mainStyle, self.subStyle) 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@35: Default.OnMouseDown = function(self, button) Nenue@35: print(self.info.title) Nenue@35: end