Mercurial > wow > buffalo2
comparison ObjectiveTracker/Update.lua @ 43:9480bd904f4c
- file name organizing
| author | Nenue |
|---|---|
| date | Mon, 25 Apr 2016 13:51:58 -0400 |
| parents | ObjectiveTracker/DefaultTracker.lua@03ed70f846de |
| children |
comparison
equal
deleted
inserted
replaced
| 42:c73051785f19 | 43:9480bd904f4c |
|---|---|
| 1 --- ${PACKAGE_NAME} | |
| 2 -- @file-author@ | |
| 3 -- @project-revision@ @project-hash@ | |
| 4 -- @file-revision@ @file-hash@ | |
| 5 -- Created: 4/17/2016 7:33 AM | |
| 6 --- Baseline update work | |
| 7 local B = select(2,...).frame | |
| 8 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
| 9 local Devian = Devian | |
| 10 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band | |
| 11 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove | |
| 12 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent | |
| 13 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText | |
| 14 local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent | |
| 15 local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs | |
| 16 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame | |
| 17 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow | |
| 18 local print = B.print('Tracker') | |
| 19 local oprint = B.print('Objectives') | |
| 20 local bprint = B.print('Block') | |
| 21 local tprint = B.print('Tracker') | |
| 22 local lprint = B.print('Line') | |
| 23 local unitLevel = 1 | |
| 24 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON | |
| 25 local debug = false | |
| 26 | |
| 27 --- FRAMES | |
| 28 local Wrapper = _G.VeneerObjectiveWrapper | |
| 29 local Scroller = Wrapper.scrollArea | |
| 30 local Scroll = _G.VeneerObjectiveScroll | |
| 31 local orderedHandlers = T.orderedHandlers | |
| 32 local orderedNames = T.orderedNames | |
| 33 | |
| 34 | |
| 35 --- Placing the Update functions here since they shouldn't be messing with schema stuff | |
| 36 local currentPosition, anchorFrame, anchorPoint | |
| 37 --- Positioning and stuff | |
| 38 local tick = 0 | |
| 39 local initReason = OBJECTIVE_TRACKER_UPDATE_ALL | |
| 40 local requiresInit | |
| 41 function T:Update (reason, ...) | |
| 42 if not B.Conf.VeneerObjectiveWrapper.enabled then | |
| 43 return | |
| 44 end | |
| 45 tick = tick + 1 | |
| 46 local print = tprint | |
| 47 local hasStuff = false | |
| 48 local insertingStuff = false | |
| 49 | |
| 50 if initReason then | |
| 51 reason = initReason | |
| 52 initReason = nil | |
| 53 elseif not reason then | |
| 54 reason = OBJECTIVE_TRACKER_UPDATE_ALL | |
| 55 end | |
| 56 print(format('|cFFBB0066Update:|r |cFFFF%04X%d|r ', tick, lshift(reason, 4)), reason, ...) | |
| 57 currentPosition = 0 | |
| 58 | |
| 59 for id, handler in pairs(T.orderedHandlers) do | |
| 60 local frame = handler.frame | |
| 61 | |
| 62 print('') | |
| 63 if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then | |
| 64 insertingStuff = handler:UpdateTracker(reason, ...) | |
| 65 else | |
| 66 print(' |cFFFF4400Update:|r skipping',handler.name) | |
| 67 end | |
| 68 | |
| 69 if handler.numWatched >= 1 then | |
| 70 hasStuff = true | |
| 71 currentPosition = currentPosition + 1 | |
| 72 Default.AddTracker(handler, frame, currentPosition) | |
| 73 frame.wasEmpty = nil | |
| 74 else | |
| 75 frame.destinationOffset = 0 | |
| 76 if not frame.wasEmpty and not frame.fadeOut:IsPlaying() then | |
| 77 frame.fadeOut:Play() | |
| 78 end | |
| 79 frame.wasEmpty = true | |
| 80 end | |
| 81 end | |
| 82 | |
| 83 -- do these whenever there is content or content is being added | |
| 84 if hasStuff or insertingStuff then | |
| 85 T:FinishWrapper() | |
| 86 end | |
| 87 Quest.GetClosest() | |
| 88 T.UpdateActionButtons(reason) | |
| 89 end | |
| 90 | |
| 91 Default.UpdateTracker = function (handler, reason, id, isNew) | |
| 92 local print = handler.print | |
| 93 local frame = handler.frame | |
| 94 local blockIndex = 0 | |
| 95 print('MODULE:'..handler.name, 'message:', reason, 'id:', id, (isNew and '|cFF88FF88' or '|cFF555555')..'isNew|r') | |
| 96 handler.updateReason = reason | |
| 97 local numWatched, numAll, watchTable = handler:GetNumWatched(id, isNew) | |
| 98 | |
| 99 if numWatched >= 1 then | |
| 100 if watchTable then | |
| 101 print(' WatchList', ' n ID Obj wID Log Blk') | |
| 102 for i, w in ipairs(watchTable) do | |
| 103 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 ''))) | |
| 104 end | |
| 105 end | |
| 106 end | |
| 107 | |
| 108 handler.numWatched = numWatched | |
| 109 handler.numAll = numAll | |
| 110 handler.numBlocks = 0 | |
| 111 handler.currentBlock = 0 | |
| 112 handler.currentAnchor = frame.titlebg | |
| 113 for blockIndex = 1, numWatched do | |
| 114 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew) | |
| 115 if currentBlock then | |
| 116 handler:AddBlock(currentBlock) | |
| 117 else | |
| 118 print(' |cFF'..handler.internalColor..'finished|r @', blockIndex) | |
| 119 break -- done with quest stuff | |
| 120 end | |
| 121 end | |
| 122 | |
| 123 local numBlocks = handler.numBlocks | |
| 124 local used = handler.usedBlocks | |
| 125 local free = handler.freeBlocks | |
| 126 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)) | |
| 127 | |
| 128 return numWatched, numAll | |
| 129 end | |
| 130 | |
| 131 Default.UpdateBlock = function (handler, index) | |
| 132 --@debug@ | |
| 133 local print = bprint -- @end-debug@ | |
| 134 if not index then | |
| 135 return | |
| 136 end | |
| 137 local info = handler.WatchList[index] -- should match up with whatever the internal watch list has | |
| 138 if not info then | |
| 139 return | |
| 140 end | |
| 141 --@debug@ | |
| 142 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..index..'|r|cFF0099FF', info.id ,'|r')--@end-debug@ | |
| 143 local frame = handler.frame | |
| 144 local block = handler:GetBlock(info.id) | |
| 145 | |
| 146 if block.isAnimating then | |
| 147 -- Nothing to do, leave it as is | |
| 148 return block | |
| 149 end | |
| 150 | |
| 151 block.handler = handler | |
| 152 block.info = info | |
| 153 info.blockIndex = index | |
| 154 --@debug@ | |
| 155 local keyInfo--@end-debug@ | |
| 156 if info.id then | |
| 157 handler.InfoBlock[info.id] = block | |
| 158 --@debug@ | |
| 159 keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'InfoBlock[' .. info.id .. '] = *' .. block:GetName():gsub('%D', '') --@end-debug@ | |
| 160 end | |
| 161 if info.logIndex then | |
| 162 handler.LogBlock[info.logIndex] = block | |
| 163 --@debug@ | |
| 164 keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'LogBlock[' .. info.logIndex .. '] = ' .. block:GetName():gsub('%D', '')--@end-debug@ | |
| 165 end | |
| 166 if info.watchIndex then | |
| 167 handler.WatchBlock[info.watchIndex] = block | |
| 168 --@debug@ | |
| 169 keyInfo = (keyInfo and (keyInfo..', ') or '') .. 'WatchBlock[' .. info.watchIndex .. '] = ' .. block:GetName():gsub('%D', '')--@end-debug@ | |
| 170 end | |
| 171 --@debug@ | |
| 172 if keyInfo then print(' assigned', keyInfo) end--@end-debug@ | |
| 173 handler.BlockInfo[index] = info | |
| 174 block.endPoint = block.titlebg | |
| 175 block.attachmentHeight = 0 | |
| 176 block.currentLine = 0 | |
| 177 local attachments, override_schema = handler:UpdateObjectives(block, block.schema) | |
| 178 | |
| 179 block.title:SetText(info.title) | |
| 180 | |
| 181 if info.specialItem and not info.itemButton then | |
| 182 --@debug@ | |
| 183 print(' - |cFF00FFFFgenerating item button for info set')--@end-debug@ | |
| 184 info.itemButton = T.SetItemButton(block, info) | |
| 185 else | |
| 186 --info.itemButton = nil | |
| 187 end | |
| 188 | |
| 189 local tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2 | |
| 190 | |
| 191 | |
| 192 if info.selected then | |
| 193 block.SelectionOverlay:Show() | |
| 194 else | |
| 195 block.SelectionOverlay:Hide() | |
| 196 end | |
| 197 | |
| 198 if info.tagInfo then | |
| 199 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative) | |
| 200 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative) | |
| 201 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative) | |
| 202 end | |
| 203 | |
| 204 if info.schema then | |
| 205 block.schema = info.schema | |
| 206 end | |
| 207 return block | |
| 208 end | |
| 209 | |
| 210 Default.UpdateObjectives = function(handler, block, block_schema, displayObjectives) | |
| 211 local print = lprint | |
| 212 displayObjectives = displayObjectives or true | |
| 213 block_schema = block_schema or block.schema | |
| 214 local info = block.info | |
| 215 print(' |cFF00FF00default.objectives', block:GetName()) | |
| 216 -- reset the starting positions | |
| 217 local text, attachment, template | |
| 218 local numAttachments = 0 | |
| 219 | |
| 220 if info.objectives and displayObjectives then | |
| 221 for i, data in ipairs(info.objectives) do | |
| 222 text, attachment, template = handler:UpdateLine(block, data) | |
| 223 if text or attachment then | |
| 224 local line = handler:GetLine(block) | |
| 225 line.height = 0 | |
| 226 print(' |cFF88FF00#', i, data.type, text, attachment) | |
| 227 handler:AddLine(block, text, attachment, template) | |
| 228 end | |
| 229 if attachment then | |
| 230 numAttachments = numAttachments + 1 | |
| 231 end | |
| 232 end | |
| 233 end | |
| 234 | |
| 235 if block.currentLine < block.numLines then | |
| 236 print(' - cull', block.currentLine, block.numLines) | |
| 237 for i = block.currentLine + 1, block.numLines do | |
| 238 print(' - hide |cFFFF0088'..i..'|r', block.lines[i]) | |
| 239 block.lines[i]:ClearAllPoints() | |
| 240 block.lines[i]:Hide() | |
| 241 end | |
| 242 end | |
| 243 | |
| 244 if block.currentLine > 0 then | |
| 245 block.attachmentHeight = block.attachmentHeight | |
| 246 print(' |cFF00FF00attachment:', block.attachmentHeight) | |
| 247 end | |
| 248 return numAttachments, block_schema | |
| 249 end | |
| 250 | |
| 251 Default.UpdateLine = function(handler, block, data) | |
| 252 return block.info.description, nil, 'default' | |
| 253 end | |
| 254 | |
| 255 Default.Select = function(handler, block) | |
| 256 T:Update() | |
| 257 end | |
| 258 Default.Open = function(handler, block) | |
| 259 T:Update(handler.updateReasonModule) | |
| 260 end | |
| 261 Default.Remove = function(handler, block) | |
| 262 T:Update(handler.updateReasonModule) | |
| 263 end | |
| 264 Default.Report = function(handler, block) | |
| 265 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.') | |
| 266 end | |
| 267 | |
| 268 function Default:OnMouseUp (button) | |
| 269 print(self.handler.name, self.mainStyle, self.subStyle) | |
| 270 if button == 'LeftButton' then | |
| 271 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then | |
| 272 self.Link(self.handler, self) | |
| 273 elseif IsModifiedClick("QUESTWATCHTOGGLE") then | |
| 274 self.Remove(self.handler, self) | |
| 275 else | |
| 276 self.Select(self.handler, self) | |
| 277 end | |
| 278 elseif button == 'RightButton' then | |
| 279 self.Open(self.handler, self) | |
| 280 end | |
| 281 self.initialButton = nil | |
| 282 self.modChatLink = nil | |
| 283 self.modQuestWatch = nil | |
| 284 --T:Update(self.handler.updateReasonModule) | |
| 285 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') | |
| 286 end | |
| 287 function Default:OnMouseDown (button) | |
| 288 print(self.info.title) | |
| 289 end |
