Mercurial > wow > buffalo2
comparison ObjectiveUI.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 |
comparison
equal
deleted
inserted
replaced
6:589de8ea05b9 | 7:5301c68f28d8 |
---|---|
6 local B = select(2,...).frame | 6 local B = select(2,...).frame |
7 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | 7 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') |
8 local print = B.print('Objectives') | 8 local print = B.print('Objectives') |
9 local Tracker, AutoQuest, Quest, Cheevs = mod.Tracker, mod.AutoQuest, mod.Quest, mod.Cheevs | 9 local Tracker, AutoQuest, Quest, Cheevs = mod.Tracker, mod.AutoQuest, mod.Quest, mod.Cheevs |
10 local itemButtonSize, itemButtonSpacing = 36, 1 | 10 local itemButtonSize, itemButtonSpacing = 36, 1 |
11 local tremove, tremovebyval = table.remove, table.removebyval | |
11 | 12 |
12 -------------------------------------------------------------------- | 13 -------------------------------------------------------------------- |
13 --- Tracker-specific widgets and their handlers | 14 --- Tracker-specific widgets and their handlers |
14 -------------------------------------------------------------------- | 15 -------------------------------------------------------------------- |
15 | 16 |
19 Tracker.Report = function(self) | 20 Tracker.Report = function(self) |
20 print('Stats:', self.numWatched,'items tracked,', self.numBlocks,'blocks assigned.') | 21 print('Stats:', self.numWatched,'items tracked,', self.numBlocks,'blocks assigned.') |
21 end | 22 end |
22 | 23 |
23 Tracker.OnMouseUp = function(self, button) | 24 Tracker.OnMouseUp = function(self, button) |
24 | |
25 if self.initialButton == 'LeftButton' then | 25 if self.initialButton == 'LeftButton' then |
26 self:Select() | 26 if self.modChatLink and ChatEdit_GetActiveWindow() then |
27 mod.UpdateWrapper() | 27 self:Link() |
28 if self.modShift then | 28 elseif self.modQuestWatch then |
29 self:Remove() | 29 self:Remove() |
30 else | |
31 self:Select() | |
30 end | 32 end |
31 elseif button == 'RightButton' then | 33 elseif button == 'RightButton' then |
32 self:Open() | 34 self:Open() |
33 end | 35 end |
34 self.initialButton = nil | 36 self.initialButton = nil |
35 self.modShift = nil | 37 self.modChatLink = nil |
38 self.modQuestWatch = nil | |
36 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r ->',self.info.trackingID) | 39 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r ->',self.info.trackingID) |
37 end | 40 end |
38 | 41 |
39 Tracker.OnMouseDown = function(self, button) | 42 Tracker.OnMouseDown = function(self, button) |
40 self.initialButton = button | 43 self.initialButton = button |
41 self.modShift = IsShiftKeyDown() | 44 self.modChatLink = IsModifiedClick("CHATLINK") |
42 if button == 'LeftButton' then | 45 self.modQuestWatch = IsModifiedClick("QUESTWATCHTOGGLE") |
43 self:SetStyle('Active') | 46 self:SetStyle('Active') |
44 end | |
45 print(self.info.title) | 47 print(self.info.title) |
46 end | 48 end |
47 | 49 |
48 ----------------------------- | 50 ----------------------------- |
49 --- AUTO_QUEST | 51 --- AUTO_QUEST |
53 ----------------------------- | 55 ----------------------------- |
54 --- QUEST | 56 --- QUEST |
55 Quest.name = "Quests" | 57 Quest.name = "Quests" |
56 Quest.Select = function(self) | 58 Quest.Select = function(self) |
57 SetSuperTrackedQuestID(self.info.questID) | 59 SetSuperTrackedQuestID(self.info.questID) |
60 mod.UpdateWrapper() | |
61 end | |
62 Quest.Link = function(self) | |
63 local questLink = GetQuestLink(block.questLogIndex); | |
64 if ( questLink ) then | |
65 ChatEdit_InsertLink(questLink); | |
66 end | |
58 end | 67 end |
59 Quest.Open = function(self) | 68 Quest.Open = function(self) |
60 QuestMapFrame_OpenToQuestDetails(self.info.questID) | 69 QuestMapFrame_OpenToQuestDetails(self.info.questID) |
61 end | 70 end |
62 | 71 |
72 | 81 |
73 | 82 |
74 ----------------------------- | 83 ----------------------------- |
75 --- CHEEVS | 84 --- CHEEVS |
76 Cheevs.Select = function(self) | 85 Cheevs.Select = function(self) |
86 end | |
87 Cheevs.Link = function(self) | |
88 local achievementLink = GetAchievementLink(self.info.cheevID); | |
89 if ( achievementLink ) then | |
90 ChatEdit_InsertLink(achievementLink); | |
91 end | |
92 self:SetStyle('CheevNormal') | |
77 end | 93 end |
78 | 94 |
79 Cheevs.Open = function(self) | 95 Cheevs.Open = function(self) |
80 if ( not AchievementFrame ) then | 96 if ( not AchievementFrame ) then |
81 AchievementFrame_LoadUI(); | 97 AchievementFrame_LoadUI(); |
210 end | 226 end |
211 end | 227 end |
212 end | 228 end |
213 | 229 |
214 ----------------------------------------- | 230 ----------------------------------------- |
215 -- Progress slider for achievements, and area objecitves | 231 -- Criteria frames |
216 -- Stored by criteria ID to account for multiple bars in one cheev | 232 |
217 Tracker.SetProgress = function(criteria, info) | 233 --[[ |
218 end | 234 text = description, |
219 | 235 type = type, |
236 finished = completed, | |
237 quantity = quantity, | |
238 requiredQuantity = requiredQuantity, | |
239 characterName = characterName, | |
240 flags = flags, | |
241 assetID = assetID, | |
242 quantityString = quantityString, | |
243 criteriaID = criteriaID, | |
244 ]] | |
245 local newWidgetID = 0 | |
220 mod.WidgetRegistry = {} | 246 mod.WidgetRegistry = {} |
221 local wr = mod.WidgetRegistry | 247 local wr = mod.WidgetRegistry |
222 mod.SetWidget = function(criteria, info) | 248 |
249 --- Get a usable widget for the given achievement criteria set. | |
250 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block | |
251 mod.SetWidget = function(obj, info) | |
252 local widgetType = obj.type | |
223 local widget | 253 local widget |
224 if not wr[criteria.type] then | 254 |
225 print('|cFFFF4400[[WidgetTemplate]]|r', criteria.type) | 255 if not wr[widgetType] or #wr[widgetType].free == 0 then |
226 wr[criteria.type] = { free = {}, used = {}, } | 256 print('VeneerObjectiveCriteria' .. widgetType) |
227 end | 257 widget = CreateFrame('Frame', nil, VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) |
228 if #wr[criteria.type].free == 0 then | 258 end |
229 | 259 local free = wr[widgetType].free |
230 local frameID = #wr[criteria.type].free + #wr[criteria.type].used | 260 local used = wr[widgetType].used |
231 widget = CreateFrame('Frame', 'VeneerCriteria' .. criteria.type .. frameID, VeneerObjectiveWrapper, 'VeneerObjectiveCriteria' .. criteria.type) | 261 |
232 end | 262 widget = tremove(free) |
233 end | 263 local index = #used+1 |
264 used[index] = widget | |
265 wr[widgetType].usedIndex[widget] = index | |
266 widget.info = obj | |
267 widget.parentInfo = info | |
268 mod.InitializeWidget(widget) | |
269 | |
270 return widget | |
271 end | |
272 | |
273 --- Fired by OnLoad() when a new frame is spawned | |
234 mod.RegisterWidget = function(frame) | 274 mod.RegisterWidget = function(frame) |
275 local widgetType = frame.widgetType | |
276 local obj = frame.info | |
277 if not wr[frame.widgetType] then | |
278 print('|cFFFF4400[[WidgetTemplate]]|r', widgetType) | |
279 wr[widgetType] = { lastn = 0, free = {}, used = {}, usedIndex = {}, freeIndex = {} } | |
280 end | |
235 tinsert(wr[frame.widgetType].free, frame) | 281 tinsert(wr[frame.widgetType].free, frame) |
236 end | 282 end |
237 mod.InitializeWidget = function(frame) | 283 mod.InitializeWidget = setmetatable({}, { |
238 | 284 __call = function(t, frame) |
239 end | 285 -- todo: config pull |
286 local maxWidth = 250 | |
287 | |
288 frame:SetWidth(maxWidth) | |
289 mod.UpdateWidget[frame.widgetType](frame) | |
290 frame:SetScript('OnEvent', mod.UpdateWidget[frame.widgetType]) | |
291 if frame.info.isCurrency then | |
292 frame:RegisterEvent('CHAT_MSG_CURRENCY') | |
293 frame:RegisterEvent('CURRENCY_LIST_UPDATE') | |
294 end | |
295 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') | |
296 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') | |
297 frame:RegisterEvent('CRITERIA_UPDATE') | |
298 frame:RegisterEvent('CRITERIA_COMPLETE') | |
299 frame:RegisterEvent('CRITERIA_EARNED') | |
300 | |
301 return t[frame.widgetType](frame) | |
302 end, | |
303 }) | |
304 mod.UpdateWidget = setmetatable({}, { | |
305 __call = function(t, frame) | |
306 if not frame.widgetType then | |
307 error('Invalid widget template, needs .widgetType') | |
308 return | |
309 end | |
310 | |
311 return t[frame.widgetType](frame) | |
312 end | |
313 }) | |
314 | |
240 mod.ReleaseWidget = function(frame) | 315 mod.ReleaseWidget = function(frame) |
241 | 316 local reg = wr[frame.widgetType] |
242 if tContains(wr[frame.widgetType], frame) then | 317 if reg and reg.usedIndex[frame] then |
243 end | 318 tremove(reg.used, reg.usedIndex[frame]) |
244 end | 319 reg.usedIndex[frame] = nil |
320 frame:UnregisterAllEvents() | |
321 tinsert(reg.free, frame) | |
322 end | |
323 end | |
324 | |
325 mod.WidgetParams = { | |
326 ['ProgressBar'] = { | |
327 height = 20, | |
328 caption = {}, | |
329 quantityString = {SetFontObject = _G.VeneerFontNormal} | |
330 } | |
331 } | |
332 | |
333 mod.InitializeWidget.ProgressBar = function(self) | |
334 local params = mod.WidgetParams[self.widgetType] | |
335 self.height = params.height | |
336 self:SetHeight(20) | |
337 self.bg:SetHeight(20) | |
338 self.fg:SetHeight(18) | |
339 self.fg:SetPoint('BOTTOMLEFT', self.bg, 'BOTTOMLEFT', 1, 1) | |
340 self.quantityString:SetFontObject(params.quantityString.SetFontObject) | |
341 self.quantityString:SetText(self.info.quantityString) | |
342 end | |
343 | |
344 mod.UpdateWidget.ProgressBar = function (self) | |
345 local quantity, requiredQuantity = self.info.quantity, self.info.requiredQuantity | |
346 self.fg:SetPoint('TOPLEFT', self, 'TOPLEFT', 0, 0) | |
347 if self.info.finished then | |
348 self.fg:SetWidth(self.bg:GetWidth() - 2) | |
349 elseif quantity == 0 then | |
350 self.fg:Hide() | |
351 else | |
352 self.fg:Show() | |
353 self.fg:SetWidth(self:GetWidth() * (quantity / requiredQuantity)) | |
354 end | |
355 | |
356 end |