Mercurial > wow > buffalo2
comparison ObjectiveTracker/Update.lua @ 35:69d03f8e293e
- separated layout and data logic between Frame.lua and Update.lua
- solved disappearing tracker mystery
| author | Nenue |
|---|---|
| date | Sun, 17 Apr 2016 11:07:48 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 34:9856ebc63fa4 | 35:69d03f8e293e |
|---|---|
| 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 local B = select(2,...).frame | |
| 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
| 8 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band | |
| 9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove | |
| 10 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent | |
| 11 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText | |
| 12 local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent | |
| 13 local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs | |
| 14 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame | |
| 15 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow | |
| 16 local print = B.print('Tracker') | |
| 17 local oprint = B.print('Objectives') | |
| 18 local bprint = B.print('Block') | |
| 19 local tprint = B.print('Tracker') | |
| 20 local lprint = B.print('Line') | |
| 21 local unitLevel = 1 | |
| 22 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON | |
| 23 local debug = false | |
| 24 | |
| 25 --- FRAMES | |
| 26 local Wrapper = _G.VeneerObjectiveWrapper | |
| 27 local Scroller = Wrapper.scrollArea | |
| 28 local Scroll = _G.VeneerObjectiveScroll | |
| 29 local orderedHandlers = T.orderedHandlers | |
| 30 local orderedNames = T.orderedNames | |
| 31 | |
| 32 | |
| 33 --- Placing the Update functions here since they shouldn't be messing with schema stuff | |
| 34 local currentPosition, anchorFrame, anchorPoint | |
| 35 --- Positioning and stuff | |
| 36 local tick = 0 | |
| 37 local firstUpdate = true | |
| 38 function T:Update (reason, ...) | |
| 39 if not B.Conf.VeneerObjectiveWrapper.enabled then | |
| 40 return | |
| 41 end | |
| 42 | |
| 43 tick = tick + 1 | |
| 44 if firstUpdate or not reason then | |
| 45 reason = _G.OBJECTIVE_TRACKER_UPDATE_ALL | |
| 46 end | |
| 47 | |
| 48 local print = tprint | |
| 49 local hasStuff = false | |
| 50 local insertingStuff = false | |
| 51 | |
| 52 print(format('|cFFBB0066Update:|r |cFFFF%04X%d|r ', tick, lshift(reason, 4)), reason, ...) | |
| 53 currentPosition = 0 | |
| 54 | |
| 55 for id, handler in pairs(T.orderedHandlers) do | |
| 56 local frame = handler.frame | |
| 57 | |
| 58 | |
| 59 if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then | |
| 60 insertingStuff = handler:UpdateTracker(reason, ...) | |
| 61 else | |
| 62 print(' |cFFFF4400Update:|r skipping',handler.name) | |
| 63 end | |
| 64 | |
| 65 if handler.numWatched >= 1 then | |
| 66 hasStuff = true | |
| 67 currentPosition = currentPosition + 1 | |
| 68 Default.AddTracker(handler, frame, currentPosition) | |
| 69 | |
| 70 else | |
| 71 frame:ClearAllPoints() | |
| 72 frame:SetPoint('BOTTOM', Scroll, 'BOTTOM', 0, 0) | |
| 73 frame.destinationOffset = 0 | |
| 74 frame:Hide() | |
| 75 frame.wasEmpty = true | |
| 76 end | |
| 77 end | |
| 78 | |
| 79 -- do these whenever there is content or content is being added | |
| 80 if hasStuff or insertingStuff then | |
| 81 T:FinishWrapper() | |
| 82 end | |
| 83 Quest.GetClosest() | |
| 84 --T.UpdateActionButtons(reason) | |
| 85 if firstUpdate then | |
| 86 firstUpdate = nil | |
| 87 end | |
| 88 end | |
| 89 | |
| 90 Default.UpdateTracker = function (handler, reason, id, isNew) | |
| 91 local print = tprint | |
| 92 local tracker = handler.frame | |
| 93 local blockIndex = 0 | |
| 94 | |
| 95 handler.updateReason = reason | |
| 96 handler.numWatched = handler:GetNumWatched() | |
| 97 if handler.numWatched >= 1 then | |
| 98 | |
| 99 print(' |cFF00FF88GetNumWatched:|r',handler.name, handler.numWatched, 'of', handler.numAll) | |
| 100 end | |
| 101 | |
| 102 handler.numBlocks = 0 | |
| 103 handler.currentBlock = 0 | |
| 104 handler.currentAnchor = tracker.titlebg | |
| 105 for blockIndex = 1, handler.numWatched do | |
| 106 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew) | |
| 107 if currentBlock then | |
| 108 handler:AddBlock(currentBlock) | |
| 109 else | |
| 110 print(' |cFFFF9900finished|r @', blockIndex) | |
| 111 break -- done with quest stuff | |
| 112 end | |
| 113 end | |
| 114 | |
| 115 | |
| 116 local numBlocks = handler.numBlocks | |
| 117 local used = handler.usedBlocks | |
| 118 local free = handler.freeBlocks | |
| 119 print(format(' |cFFFF8800UpdateTracker|r(%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)) | |
| 120 return tracker.numWatched, tracker.numAll | |
| 121 end | |
| 122 | |
| 123 Default.UpdateBlock = function (handler, blockIndex, id, added) | |
| 124 local print = bprint | |
| 125 if not blockIndex then | |
| 126 return | |
| 127 end | |
| 128 local info = handler:GetInfo(blockIndex) -- should match up with whatever the internal watch list has | |
| 129 if not info then | |
| 130 return | |
| 131 end | |
| 132 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..blockIndex..'|r|cFF0099FF', info.id ,'|r') | |
| 133 local frame = handler.frame | |
| 134 local block = handler:GetBlock(info.id) | |
| 135 | |
| 136 if added then | |
| 137 -- do something if the block is being assigned a new thing | |
| 138 end | |
| 139 | |
| 140 block.handler = handler | |
| 141 block.info = info | |
| 142 | |
| 143 info.blockIndex = blockIndex | |
| 144 if info.questID then handler.QuestBlock[info.questID] = block end | |
| 145 if info.logIndex then handler.LogBlock[info.logIndex] = block end | |
| 146 if info.watchIndex then handler.WatchBlock[info.watchIndex] = block end | |
| 147 handler.BlockInfo[blockIndex] = info | |
| 148 local newSchema = handler:UpdateObjectives(block) | |
| 149 if newSchema and newSchema ~= blockSchema then | |
| 150 T.UpdateSchema('block', newSchema) | |
| 151 end | |
| 152 | |
| 153 block.title:SetText(info.title) | |
| 154 | |
| 155 print(' |cFFFFFF00height|r:', block.height) | |
| 156 print(' |cFF00FFFF)|r -> ', block, block:GetHeight()) | |
| 157 | |
| 158 block:Show() | |
| 159 | |
| 160 if info.specialItem and not info.itemButton then | |
| 161 print(' - |cFF00FFFFgenerating item button for info set') | |
| 162 info.itemButton = T.SetItemButton(block, info) | |
| 163 else | |
| 164 --info.itemButton = nil | |
| 165 end | |
| 166 | |
| 167 local tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2 | |
| 168 | |
| 169 local numCurrency = 0 | |
| 170 for i, rewardTile in ipairs(block.rewardTile) do | |
| 171 if info.rewardInfo and info.rewardInfo[i] then | |
| 172 local reward = info.rewardInfo[i] | |
| 173 --rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, -2, -2) | |
| 174 rewardTile:SetTexture(reward.texture) | |
| 175 rewardTile:Show() | |
| 176 | |
| 177 print('updating reward tile #'.. i, reward.type, reward.count, reward.text, reward.texture) | |
| 178 if reward.count and reward.count > 1 then | |
| 179 block.rewardLabel[i]:SetText(reward.count) | |
| 180 block.rewardLabel[i]:Show() | |
| 181 end | |
| 182 | |
| 183 rewardTile:ClearAllPoints() | |
| 184 rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, x, y) | |
| 185 tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', rewardTile, 'TOPLEFT', -2, 0 | |
| 186 else | |
| 187 rewardTile:Hide() | |
| 188 block.rewardLabel[i]:Hide() | |
| 189 end | |
| 190 end | |
| 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.statusKey and (Devian and Devian.InWorkspace()) then | |
| 205 block.debugText:SetText(info.statusKey) | |
| 206 block.debugText:Show() | |
| 207 end | |
| 208 return block | |
| 209 end | |
| 210 | |
| 211 Default.UpdateObjectives = function(handler, block, block_schema) | |
| 212 local print = lprint | |
| 213 local info = block.info | |
| 214 print(' |cFF00FF00default.objectives', block:GetName()) | |
| 215 -- reset the starting positions | |
| 216 block.endPoint = block.titlebg | |
| 217 block.attachmentHeight = 0 | |
| 218 block.currentLine = 0 | |
| 219 | |
| 220 local displayObjectiveHeader = false | |
| 221 | |
| 222 block.attachmentHeight = 0 | |
| 223 local text, attachment, template | |
| 224 | |
| 225 | |
| 226 if info.description and #info.description >= 1 then | |
| 227 print(' |cFF00FFFF header line:|r', info.description) | |
| 228 text = info.description | |
| 229 handler:AddLine(block, text, nil) | |
| 230 end | |
| 231 | |
| 232 if (info.isComplete or info.numObjectives == 0) and info.completionText then | |
| 233 print(' overriding line #1 for completion text:', info.completionText) | |
| 234 text = info.completionText | |
| 235 handler:AddLine(block, text, nil, 'completed') | |
| 236 else | |
| 237 if info.objectives then | |
| 238 for i, data in ipairs(info.objectives) do | |
| 239 local line = handler:GetLine(block) | |
| 240 displayObjectiveHeader = true | |
| 241 line.height = 0 | |
| 242 text, attachment, template = handler:UpdateLine(block, line, data) | |
| 243 print(' |cFF88FF00#', i, data.type, text, attachment) | |
| 244 handler:AddLine(block, text, attachment, template) | |
| 245 | |
| 246 end | |
| 247 end | |
| 248 end | |
| 249 | |
| 250 | |
| 251 if block.currentLine < block.numLines then | |
| 252 print(' - cull', block.currentLine, block.numLines) | |
| 253 for i = block.currentLine + 1, block.numLines do | |
| 254 print(' - hide |cFFFF0088'..i..'|r', block.lines[i]) | |
| 255 block.lines[i]:ClearAllPoints() | |
| 256 block.lines[i]:Hide() | |
| 257 end | |
| 258 end | |
| 259 | |
| 260 if block.currentLine > 0 then | |
| 261 block.attachmentHeight = block.attachmentHeight | |
| 262 print(' |cFF00FF00attachment:', block.attachmentHeight) | |
| 263 end | |
| 264 return block_schema | |
| 265 end | |
| 266 | |
| 267 Default.UpdateLine = function(handler, block, line, data) | |
| 268 if line.finished then | |
| 269 line.progress = 2 | |
| 270 elseif line.quantity > 0 then | |
| 271 line.progress = 1 | |
| 272 else | |
| 273 line.progress = 0 | |
| 274 end | |
| 275 return data.text, line.widget, 'normal' | |
| 276 end | |
| 277 | |
| 278 Default.Select = function(handler, block) | |
| 279 T:Update() | |
| 280 end | |
| 281 Default.Open = function(handler, block) | |
| 282 T:Update(handler.watchReasonModule) | |
| 283 end | |
| 284 Default.Remove = function(handler, block) | |
| 285 T:Update(handler.watchReasonModule) | |
| 286 end | |
| 287 Default.Report = function(handler, block) | |
| 288 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.') | |
| 289 end | |
| 290 | |
| 291 Default.OnMouseUp = function(self, button) | |
| 292 print(self.handler.name, self.mainStyle, self.subStyle) | |
| 293 if button == 'LeftButton' then | |
| 294 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then | |
| 295 self.Link(self.handler, self) | |
| 296 elseif IsModifiedClick("QUESTWATCHTOGGLE") then | |
| 297 self.Remove(self.handler, self) | |
| 298 else | |
| 299 self.Select(self.handler, self) | |
| 300 end | |
| 301 elseif button == 'RightButton' then | |
| 302 self.Open(self.handler, self) | |
| 303 end | |
| 304 self.initialButton = nil | |
| 305 self.modChatLink = nil | |
| 306 self.modQuestWatch = nil | |
| 307 T:Update(self.handler.updateReasonModule) | |
| 308 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') | |
| 309 end | |
| 310 Default.OnMouseDown = function(self, button) | |
| 311 print(self.info.title) | |
| 312 end |
