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