annotate ObjectiveCore.lua @ 7:5301c68f28d8

TrackerBlock - use IsModifiedClick function to determine appropriate OnClick actions - handle 'CHATLINK' modifier - handle 'TOGGLEQUESTWATCH' modifier TrackerBlockObjectives - use a generic framework to manage frame creation for various criteria tracker types: - ProgressBar when Blizzard flag data indicates so - skip when Blizzard flag data indicates so - DynamicText otherwise - events related to the criteria are registered in the criteria frame, and unregistered when the frame is hidden, either by destruction of its parent or completion
author Nenue
date Fri, 01 Apr 2016 12:27:05 -0400
parents 589de8ea05b9
children 7923243ae972
rev   line source
Nenue@0 1 --- ${PACKAGE_NAME}
Nenue@0 2 -- @file-author@
Nenue@0 3 -- @project-revision@ @project-hash@
Nenue@0 4 -- @file-revision@ @file-hash@
Nenue@0 5 -- Created: 3/26/2016 1:51 AM
Nenue@0 6 local B = select(2,...).frame
Nenue@0 7 local wipe, pairs, ipairs, min, max, unpack = table.wipe, pairs, ipairs, min, max, unpack
Nenue@0 8 local setmetatable, type = setmetatable, type
Nenue@0 9 local GetNumQuestLeaderBoards, GetAchievementNumCriteria, GetQuestLogLeaderBoard, GetAchievementCriteriaInfo = GetNumQuestLeaderBoards, GetAchievementNumCriteria, GetQuestLogLeaderBoard, GetAchievementCriteriaInfo
Nenue@0 10 local GetQuestLogIndexByID, GetSuperTrackedQuestID, SetSuperTrackedQuestID, GetQuestWatchInfo = GetQuestLogIndexByID, GetSuperTrackedQuestID, SetSuperTrackedQuestID, GetQuestWatchInfo
Nenue@0 11 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@0 12 local print = B.print('Objectives')
Nenue@0 13 local ObjectiveTrackerFrame = ObjectiveTrackerFrame
Nenue@0 14
Nenue@0 15 --[[
Nenue@0 16 Full quest info is available if:
Nenue@0 17 - It's in the player quest log, or is available from the Gossip interface
Nenue@0 18 - It's being shared from another player and is acceptible
Nenue@0 19 - It's an auto-quest that is available in the current location
Nenue@0 20 Partial quest info is availabe if:
Nenue@0 21 - It's already completed (i.e. it appears in CompletedQuestInfo()).
Nenue@0 22 - It's an scheduled interval quest (daily, weekly, etc.)
Nenue@0 23 - It's contained in a quest link received from chat
Nenue@0 24 Under any other circumstances, only minimal info can be pulled:
Nenue@0 25 - Its availability to the player
Nenue@0 26 - Its relation with the currently engaged NPC
Nenue@0 27 - Its binary completion status
Nenue@0 28
Nenue@0 29 ]]
Nenue@0 30 --- Global Frames
Nenue@0 31 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@0 32 local Scroller = Wrapper.scrollArea
Nenue@0 33 local Scroll = _G.VeneerObjectiveScroll
Nenue@0 34
Nenue@0 35 --- list used to make things happen
Nenue@0 36 mod.orderedNames = {[1] = 'AutoQuest', [2] = 'Quest', [3] = 'Cheevs'}
Nenue@0 37
Nenue@0 38 --- ipairs() list of handlers for wrapper update
Nenue@0 39 mod.orderedHandlers = {}
Nenue@0 40 mod.orderedTrackers = {}
Nenue@0 41 mod.indexedTrackers = {}
Nenue@0 42 --- pairs() list of handler frames for tracker updates
Nenue@0 43 mod.namedTrackers = {}
Nenue@0 44
Nenue@0 45 --- Handler stubs
Nenue@0 46 mod.AutoQuest = {
Nenue@0 47 name = "AutoQuest"
Nenue@0 48 }
Nenue@0 49 mod.Quest = {
Nenue@0 50 name = "Quest"
Nenue@0 51 }
Nenue@0 52 mod.Cheevs = {
Nenue@0 53 name = "Cheevs"
Nenue@0 54 }
Nenue@0 55
Nenue@0 56
Nenue@0 57 --- Temp values set during updates
Nenue@0 58 local wrapperWidth, wrapperHeight
Nenue@0 59 local scrollWidth, scrollHeight
Nenue@0 60 local previousBlock
Nenue@0 61 local currentBlock
Nenue@0 62
Nenue@0 63 local frame_guide_init = function(self)
Nenue@0 64 self.testU = self.testU or self:CreateTexture('TestU', 'OVERLAY', 'VnTestLine')
Nenue@0 65 self.testB = self.testB or self:CreateTexture('TestB', 'OVERLAY', 'VnTestLine')
Nenue@0 66 self.testL = self.testL or self:CreateTexture('TestL', 'OVERLAY', 'VnTestLine')
Nenue@0 67 self.testR = self.testR or self:CreateTexture('TestR', 'OVERLAY', 'VnTestLine')
Nenue@0 68 end
Nenue@0 69 local frame_guide = function(self, target)
Nenue@0 70 if not target then return end
Nenue@0 71 if target:IsDragging() then return end
Nenue@0 72 local thickness = 1
Nenue@0 73 local midX, midY = target:GetCenter()
Nenue@0 74 local width, height = target:GetWidth() * 1.5, target:GetHeight() * 1.5
Nenue@0 75 --print('frame', target:GetLeft(), target:GetTop(), target:GetRight(), target:GetBottom())
Nenue@0 76 self.testB:ClearAllPoints()
Nenue@0 77 self.testB:SetPoint('TOP', UIParent, 'BOTTOMLEFT', midX, target:GetBottom())
Nenue@0 78 self.testB:SetSize(width,thickness)
Nenue@0 79
Nenue@0 80 self.testU:ClearAllPoints()
Nenue@0 81 self.testU:SetPoint('BOTTOM', UIParent, 'BOTTOMLEFT', midX, target:GetTop())
Nenue@0 82 self.testU:SetSize(width,thickness)
Nenue@0 83
Nenue@0 84 self.testL:ClearAllPoints()
Nenue@0 85 self.testL:SetPoint('RIGHT', UIParent, 'BOTTOMLEFT', target:GetLeft(), midY)
Nenue@0 86 self.testL:SetSize(thickness,height)
Nenue@0 87
Nenue@0 88 self.testR:ClearAllPoints()
Nenue@0 89 self.testR:SetPoint('LEFT', UIParent, 'BOTTOMLEFT', target:GetRight(), midY)
Nenue@0 90 self.testR:SetSize(thickness,height)
Nenue@0 91 end
Nenue@0 92
Nenue@0 93 --- Handler template
Nenue@0 94 local CreateHandler = function (self, name, index)
Nenue@0 95 print(self, name)
Nenue@0 96 local handler = setmetatable({}, {
Nenue@0 97 __tostring = function() return name end,
Nenue@0 98 __call = function (self) mod.UpdateTracker(self) end
Nenue@0 99 })
Nenue@0 100 if type(mod.orderedHandlers[index]) == 'table' then
Nenue@0 101 return mod.orderedHandlers[index]
Nenue@0 102 end
Nenue@0 103
Nenue@0 104 print('take up locals first')
Nenue@0 105 local preset = {}
Nenue@0 106 for k,v in pairs(mod[name]) do
Nenue@0 107 preset[k] = true
Nenue@0 108 if type(v) == 'table' then
Nenue@0 109 handler[k] = {}
Nenue@0 110 else
Nenue@0 111 handler[k] = v
Nenue@0 112 end
Nenue@0 113 end
Nenue@0 114
Nenue@0 115 print('resulting handler contents')
Nenue@0 116 for k, v in pairs(self) do
Nenue@0 117 if not handler[k] then
Nenue@0 118 if type(v) == 'table' then
Nenue@0 119 -- assume all tables to be local data; don't inherit or ref
Nenue@0 120 handler[k] = {}
Nenue@0 121 else
Nenue@0 122 handler[k] = mod.Tracker[k]
Nenue@0 123 end
Nenue@0 124 else
Nenue@0 125 print(name, 'has its own', k)
Nenue@0 126 end
Nenue@0 127 end
Nenue@0 128 print('|cFFFF4400'..tostring(name)..'|r:')
Nenue@0 129 for k, v in pairs(handler) do
Nenue@0 130 print(string.format("%24s %8s %s", (preset[k] and '|cFFFFFFFF' or '|cFFFFFF00') .. k .. '|r', type(v), tostring(v)))
Nenue@0 131 end
Nenue@0 132 mod[name] = handler
Nenue@0 133 mod.orderedHandlers[index] = handler
Nenue@0 134 return true
Nenue@0 135 end
Nenue@0 136
Nenue@0 137 mod.Tracker = setmetatable({}, {
Nenue@0 138 __call = CreateHandler,
Nenue@0 139 __tostring = function() return 'DEFAULT_TRACKING_HANDLER' end
Nenue@0 140 })
Nenue@0 141 local Tracker = mod.Tracker
Nenue@0 142 Tracker.numWatched = 0 --- number of entries being handled
Nenue@0 143 Tracker.numBlocks = 0 --- number of blocks created
Nenue@0 144 Tracker.actualBlocks = 0 --- number of blocks in use
Nenue@0 145
Nenue@0 146 Tracker.freeBlocks = {} --- block heap
Nenue@0 147 Tracker.usedBlocks = {}
Nenue@0 148
Nenue@0 149 Tracker.Watched = {} -- find by watchIndex
Nenue@0 150 Tracker.Info = {} -- find by data ID
Nenue@0 151 Tracker.BlockInfo = {} -- find by block ID
Nenue@0 152 Tracker.LogInfo = {} -- find by log ID (quest log mainly)
Nenue@0 153 Tracker.WatchBlock = {}
Nenue@2 154 Tracker.WatchInfo = {}
Nenue@0 155 Tracker.LogBlock = {}
Nenue@0 156
Nenue@0 157
Nenue@0 158
Nenue@0 159 Tracker.GetBlock = function(handler, blockIndex)
Nenue@0 160 local block = handler.usedBlocks[blockIndex]
Nenue@0 161 if not handler.usedBlocks[blockIndex] then
Nenue@0 162 if #handler.freeBlocks >= 1 then
Nenue@0 163 block = handler.freeBlocks[#handler.freeBlocks]
Nenue@0 164 handler.freeBlocks[#handler.freeBlocks] = nil
Nenue@0 165 else
Nenue@0 166 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, Scroll, 'VeneerTrackerBlock')
Nenue@0 167 block.SetStyle = mod.SetBlockStyle
Nenue@0 168 block:ClearAllPoints() -- making sure the anchors are clear in case they get added for some other template usage
Nenue@0 169 end
Nenue@0 170
Nenue@0 171 handler.usedBlocks[blockIndex] = block
Nenue@0 172 end
Nenue@0 173 return handler.usedBlocks[blockIndex]
Nenue@0 174 end
Nenue@0 175
Nenue@2 176 function mod:OnInitialize()
Nenue@2 177 self.InitializeTrackers()
Nenue@3 178 self.InitializeXPTracker()
Nenue@2 179 mod.SetEvents()
Nenue@0 180 ObjectiveTrackerFrame:UnregisterAllEvents()
Nenue@0 181 ObjectiveTrackerFrame:Hide()
Nenue@0 182 end
Nenue@0 183
Nenue@0 184 --[[
Nenue@0 185 QUESTLINE_UPDATE This event is not yet documented
Nenue@0 186 QUESTTASK_UPDATE This event is not yet documented
Nenue@0 187 QUEST_ACCEPTED Fires when a new quest is added to the player's quest log (which is what happens after a player accepts a quest).
Nenue@0 188 QUEST_ACCEPT_CONFIRM Fires when certain kinds of quests (e.g. NPC escort quests) are started by another member of the player's group
Nenue@0 189 QUEST_AUTOCOMPLETE Fires when a quest is automatically completed (remote handin available)
Nenue@0 190 QUEST_BOSS_EMOTE This event is not yet documented
Nenue@0 191 QUEST_CHOICE_CLOSE This event is not yet documented
Nenue@0 192 QUEST_CHOICE_UPDATE This event is not yet documented
Nenue@0 193 QUEST_COMPLETE Fires when the player is looking at the "Complete" page for a quest, at a questgiver.
Nenue@0 194 QUEST_DETAIL Fires when details of an available quest are presented by a questgiver
Nenue@0 195 QUEST_FINISHED Fires when the player ends interaction with a questgiver or ends a stage of the questgiver dialog
Nenue@0 196 QUEST_GREETING Fires when a questgiver presents a greeting along with a list of active or available quests
Nenue@0 197 QUEST_ITEM_UPDATE Fires when information about items in a questgiver dialog is updated
Nenue@0 198 QUEST_LOG_UPDATE Fires when the game client receives updates relating to the player's quest log (this event is not just related to the quests inside it)
Nenue@0 199 QUEST_POI_UPDATE This event is not yet documented
Nenue@0 200 QUEST_PROGRESS Fires when interacting with a questgiver about an active quest
Nenue@0 201 QUEST_REMOVED This event is not yet documented
Nenue@0 202 QUEST_TURNED_IN Fired when a quest is turned in
Nenue@0 203 QUEST_WATCH_LIST_CHANGED This event is not yet documented
Nenue@0 204 QUEST_WATCH_OBJECTIVES_CHANGED This event is not yet documented
Nenue@0 205 QUEST_WATCH_UPDATE Fires when the player's status regarding a quest's objectives changes, for instance picking up a required object or killing a mob for that quest. All forms of (quest objective) progress changes will trigger this event.]
Nenue@0 206
Nenue@0 207 TRACKED_ACHIEVEMENT_LIST_CHANGED This event is not yet documented
Nenue@0 208 TRACKED_ACHIEVEMENT_UPDATE Fires when the player's progress changes on an achievement marked for watching in the objectives tracker
Nenue@0 209 ]]