annotate ObjectiveCore.lua @ 15:f660f1c1e0aa

Objective Widgets - determine completion by fractional value
author Nenue
date Mon, 04 Apr 2016 03:41:28 -0400
parents ed642234f017
children 880828018bf4
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@14 7 local pairs, setmetatable, type, tostring = pairs, setmetatable, type, tostring
Nenue@14 8 local format = string.format
Nenue@14 9 local M = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@0 10 local print = B.print('Objectives')
Nenue@0 11 local ObjectiveTrackerFrame = ObjectiveTrackerFrame
Nenue@0 12
Nenue@0 13 --[[
Nenue@0 14 Full quest info is available if:
Nenue@0 15 - It's in the player quest log, or is available from the Gossip interface
Nenue@0 16 - It's being shared from another player and is acceptible
Nenue@0 17 - It's an auto-quest that is available in the current location
Nenue@0 18 Partial quest info is availabe if:
Nenue@0 19 - It's already completed (i.e. it appears in CompletedQuestInfo()).
Nenue@0 20 - It's an scheduled interval quest (daily, weekly, etc.)
Nenue@0 21 - It's contained in a quest link received from chat
Nenue@0 22 Under any other circumstances, only minimal info can be pulled:
Nenue@0 23 - Its availability to the player
Nenue@0 24 - Its relation with the currently engaged NPC
Nenue@0 25 - Its binary completion status
Nenue@0 26
Nenue@0 27 ]]
Nenue@0 28 --- Global Frames
Nenue@0 29 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@0 30 local Scroller = Wrapper.scrollArea
Nenue@0 31 local Scroll = _G.VeneerObjectiveScroll
Nenue@0 32
Nenue@10 33 --- Baseline defaults
Nenue@14 34 M.defaults = {
Nenue@10 35
Nenue@10 36 }
Nenue@10 37
Nenue@0 38 --- list used to make things happen
Nenue@14 39 M.orderedNames = {'Bonus', 'AutoQuest', 'Quest', 'Cheevs'}
Nenue@0 40
Nenue@0 41 --- ipairs() list of handlers for wrapper update
Nenue@14 42 M.orderedHandlers = {}
Nenue@14 43 M.orderedTrackers = {}
Nenue@14 44 M.indexedTrackers = {}
Nenue@0 45 --- pairs() list of handler frames for tracker updates
Nenue@14 46 M.namedTrackers = {}
Nenue@0 47
Nenue@0 48 --- Handler stubs
Nenue@14 49 M.AutoQuest = {
Nenue@14 50 name = "AutoQuest",
Nenue@14 51 displayName = "Local Quests",
Nenue@0 52 }
Nenue@14 53 M.Quest = {
Nenue@14 54 name = "Quest",
Nenue@14 55 displayName = "Quests",
Nenue@0 56 }
Nenue@14 57 M.Cheevs = {
Nenue@14 58 name = "Cheevs",
Nenue@14 59 displayName = "Achievements",
Nenue@14 60 }
Nenue@14 61 M.Bonus = {
Nenue@14 62 name = "Bonus",
Nenue@14 63 displayName = "Bonus Objectives",
Nenue@0 64 }
Nenue@0 65
Nenue@0 66
Nenue@0 67 --- Temp values set during updates
Nenue@0 68 local wrapperWidth, wrapperHeight
Nenue@0 69 local scrollWidth, scrollHeight
Nenue@0 70 local previousBlock
Nenue@0 71 local currentBlock
Nenue@0 72
Nenue@0 73 local frame_guide_init = function(self)
Nenue@0 74 self.testU = self.testU or self:CreateTexture('TestU', 'OVERLAY', 'VnTestLine')
Nenue@0 75 self.testB = self.testB or self:CreateTexture('TestB', 'OVERLAY', 'VnTestLine')
Nenue@0 76 self.testL = self.testL or self:CreateTexture('TestL', 'OVERLAY', 'VnTestLine')
Nenue@0 77 self.testR = self.testR or self:CreateTexture('TestR', 'OVERLAY', 'VnTestLine')
Nenue@0 78 end
Nenue@0 79 local frame_guide = function(self, target)
Nenue@0 80 if not target then return end
Nenue@0 81 if target:IsDragging() then return end
Nenue@0 82 local thickness = 1
Nenue@0 83 local midX, midY = target:GetCenter()
Nenue@0 84 local width, height = target:GetWidth() * 1.5, target:GetHeight() * 1.5
Nenue@0 85 --print('frame', target:GetLeft(), target:GetTop(), target:GetRight(), target:GetBottom())
Nenue@0 86 self.testB:ClearAllPoints()
Nenue@0 87 self.testB:SetPoint('TOP', UIParent, 'BOTTOMLEFT', midX, target:GetBottom())
Nenue@0 88 self.testB:SetSize(width,thickness)
Nenue@0 89
Nenue@0 90 self.testU:ClearAllPoints()
Nenue@0 91 self.testU:SetPoint('BOTTOM', UIParent, 'BOTTOMLEFT', midX, target:GetTop())
Nenue@0 92 self.testU:SetSize(width,thickness)
Nenue@0 93
Nenue@0 94 self.testL:ClearAllPoints()
Nenue@0 95 self.testL:SetPoint('RIGHT', UIParent, 'BOTTOMLEFT', target:GetLeft(), midY)
Nenue@0 96 self.testL:SetSize(thickness,height)
Nenue@0 97
Nenue@0 98 self.testR:ClearAllPoints()
Nenue@0 99 self.testR:SetPoint('LEFT', UIParent, 'BOTTOMLEFT', target:GetRight(), midY)
Nenue@0 100 self.testR:SetSize(thickness,height)
Nenue@0 101 end
Nenue@0 102
Nenue@0 103 --- Handler template
Nenue@0 104 local CreateHandler = function (self, name, index)
Nenue@0 105 print(self, name)
Nenue@0 106 local handler = setmetatable({}, {
Nenue@0 107 __tostring = function() return name end,
Nenue@14 108 __call = function (self) M.UpdateTracker(self) end
Nenue@0 109 })
Nenue@14 110 if type(M.orderedHandlers[index]) == 'table' then
Nenue@14 111 return M.orderedHandlers[index]
Nenue@0 112 end
Nenue@0 113
Nenue@0 114 print('take up locals first')
Nenue@0 115 local preset = {}
Nenue@14 116 for k,v in pairs(M[name]) do
Nenue@0 117 preset[k] = true
Nenue@0 118 if type(v) == 'table' then
Nenue@0 119 handler[k] = {}
Nenue@0 120 else
Nenue@0 121 handler[k] = v
Nenue@0 122 end
Nenue@0 123 end
Nenue@0 124
Nenue@0 125 print('resulting handler contents')
Nenue@0 126 for k, v in pairs(self) do
Nenue@0 127 if not handler[k] then
Nenue@0 128 if type(v) == 'table' then
Nenue@0 129 -- assume all tables to be local data; don't inherit or ref
Nenue@0 130 handler[k] = {}
Nenue@0 131 else
Nenue@14 132 handler[k] = M.Tracker[k]
Nenue@0 133 end
Nenue@0 134 else
Nenue@0 135 print(name, 'has its own', k)
Nenue@0 136 end
Nenue@0 137 end
Nenue@0 138 print('|cFFFF4400'..tostring(name)..'|r:')
Nenue@0 139 for k, v in pairs(handler) do
Nenue@0 140 print(string.format("%24s %8s %s", (preset[k] and '|cFFFFFFFF' or '|cFFFFFF00') .. k .. '|r', type(v), tostring(v)))
Nenue@0 141 end
Nenue@14 142 M[name] = handler
Nenue@14 143 M.orderedHandlers[index] = handler
Nenue@0 144 return true
Nenue@0 145 end
Nenue@0 146
Nenue@14 147 M.Tracker = setmetatable({}, {
Nenue@0 148 __call = CreateHandler,
Nenue@0 149 __tostring = function() return 'DEFAULT_TRACKING_HANDLER' end
Nenue@0 150 })
Nenue@14 151 local Tracker = M.Tracker
Nenue@0 152 Tracker.numWatched = 0 --- number of entries being handled
Nenue@0 153 Tracker.numBlocks = 0 --- number of blocks created
Nenue@0 154 Tracker.actualBlocks = 0 --- number of blocks in use
Nenue@0 155
Nenue@0 156 Tracker.freeBlocks = {} --- block heap
Nenue@0 157 Tracker.usedBlocks = {}
Nenue@0 158
Nenue@0 159 Tracker.Watched = {} -- find by watchIndex
Nenue@0 160 Tracker.Info = {} -- find by data ID
Nenue@0 161 Tracker.BlockInfo = {} -- find by block ID
Nenue@0 162 Tracker.LogInfo = {} -- find by log ID (quest log mainly)
Nenue@2 163 Tracker.WatchInfo = {}
Nenue@0 164 Tracker.LogBlock = {}
Nenue@8 165 Tracker.WatchBlock = {}
Nenue@0 166
Nenue@0 167
Nenue@0 168
Nenue@0 169 Tracker.GetBlock = function(handler, blockIndex)
Nenue@0 170 local block = handler.usedBlocks[blockIndex]
Nenue@0 171 if not handler.usedBlocks[blockIndex] then
Nenue@0 172 if #handler.freeBlocks >= 1 then
Nenue@0 173 block = handler.freeBlocks[#handler.freeBlocks]
Nenue@0 174 handler.freeBlocks[#handler.freeBlocks] = nil
Nenue@0 175 else
Nenue@0 176 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, Scroll, 'VeneerTrackerBlock')
Nenue@14 177 block.SetStyle = M.SetBlockStyle
Nenue@14 178 block.Select = handler.Select
Nenue@14 179 block.Open = handler.Open
Nenue@14 180 block.Remove = handler.Remove
Nenue@14 181 block.Link = handler.Link
Nenue@14 182 block:SetScript('OnMouseUp', handler.OnMouseUp)
Nenue@14 183 block:SetScript('OnMouseDown', handler.OnMouseDown)
Nenue@14 184 block:ClearAllPoints()
Nenue@0 185 end
Nenue@0 186
Nenue@0 187 handler.usedBlocks[blockIndex] = block
Nenue@0 188 end
Nenue@0 189 return handler.usedBlocks[blockIndex]
Nenue@0 190 end
Nenue@0 191
Nenue@14 192 function M:OnInitialize()
Nenue@14 193 self.InitializeWrapper()
Nenue@3 194 self.InitializeXPTracker()
Nenue@14 195 M.SetEvents()
Nenue@0 196 ObjectiveTrackerFrame:UnregisterAllEvents()
Nenue@0 197 ObjectiveTrackerFrame:Hide()
Nenue@13 198
Nenue@0 199 end
Nenue@0 200
Nenue@0 201 --[[
Nenue@0 202 QUESTLINE_UPDATE This event is not yet documented
Nenue@0 203 QUESTTASK_UPDATE This event is not yet documented
Nenue@0 204 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 205 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 206 QUEST_AUTOCOMPLETE Fires when a quest is automatically completed (remote handin available)
Nenue@0 207 QUEST_BOSS_EMOTE This event is not yet documented
Nenue@0 208 QUEST_CHOICE_CLOSE This event is not yet documented
Nenue@0 209 QUEST_CHOICE_UPDATE This event is not yet documented
Nenue@0 210 QUEST_COMPLETE Fires when the player is looking at the "Complete" page for a quest, at a questgiver.
Nenue@0 211 QUEST_DETAIL Fires when details of an available quest are presented by a questgiver
Nenue@0 212 QUEST_FINISHED Fires when the player ends interaction with a questgiver or ends a stage of the questgiver dialog
Nenue@0 213 QUEST_GREETING Fires when a questgiver presents a greeting along with a list of active or available quests
Nenue@0 214 QUEST_ITEM_UPDATE Fires when information about items in a questgiver dialog is updated
Nenue@0 215 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 216 QUEST_POI_UPDATE This event is not yet documented
Nenue@0 217 QUEST_PROGRESS Fires when interacting with a questgiver about an active quest
Nenue@0 218 QUEST_REMOVED This event is not yet documented
Nenue@0 219 QUEST_TURNED_IN Fired when a quest is turned in
Nenue@0 220 QUEST_WATCH_LIST_CHANGED This event is not yet documented
Nenue@0 221 QUEST_WATCH_OBJECTIVES_CHANGED This event is not yet documented
Nenue@0 222 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 223
Nenue@0 224 TRACKED_ACHIEVEMENT_LIST_CHANGED This event is not yet documented
Nenue@0 225 TRACKED_ACHIEVEMENT_UPDATE Fires when the player's progress changes on an achievement marked for watching in the objectives tracker
Nenue@0 226 ]]