Mercurial > wow > buffalo2
comparison ObjectiveTracker/ObjectiveWidgets.lua @ 24:66b927b46776
Refine the XML data logic, and sort out some EnableMouse inconsistencies.
author | Nenue |
---|---|
date | Mon, 11 Apr 2016 09:07:40 -0400 |
parents | e837384ac363 |
children |
comparison
equal
deleted
inserted
replaced
23:e837384ac363 | 24:66b927b46776 |
---|---|
1 local B = select(2,...).frame | 1 local B = select(2,...).frame |
2 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | 2 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') |
3 local print = B.print('WidgetFactory') | 3 local print = B.print('WidgetFactory') |
4 local UIParent = UIParent | 4 local _G, UIParent = _G, UIParent |
5 local GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown = GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown | 5 local GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown = GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown |
6 local CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll = CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll | 6 local CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll = CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll |
7 local tremove, tinsert, tContains, pairs, setmetatable = tremove, tinsert, tContains, pairs, setmetatable | 7 local tremove, tContains, pairs, ipairs, setmetatable, floor = tremove, tContains, pairs, ipairs, setmetatable, floor |
8 | 8 local SetItemButtonTexture, SetItemButtonCount = SetItemButtonTexture, SetItemButtonCount |
9 local ToggleWorldMap, GetTrackedAchievements, GetTasksTable = ToggleWorldMap, GetTrackedAchievements, GetTasksTable | |
10 -- GLOBALS: Veneer_QuestObjectiveItem_UpdateCooldown, Veneer_QuestObjectiveItem_OnUpdate | |
9 --- frame refs | 11 --- frame refs |
10 local Wrapper = _G.VeneerObjectiveWrapper | 12 local Wrapper = _G.VeneerObjectiveWrapper |
11 local Scroller = Wrapper.scrollArea | 13 local Scroller = Wrapper.scrollArea |
12 local CloseButton = Wrapper.CloseButton | 14 local CloseButton = Wrapper.CloseButton |
13 local QuestMapButton = Wrapper.QuestMapButton | 15 local QuestMapButton = Wrapper.QuestMapButton |
14 local Scroll = _G.VeneerObjectiveScroll | 16 local Scroll = _G.VeneerObjectiveScroll |
15 | 17 local usedButtons = T.Quest.itemButtons |
16 local panelButtons = { | 18 local freeButtons = T.Quest.freeButtons |
19 | |
20 T.buttons = { | |
17 CloseButton = { | 21 CloseButton = { |
18 closedSwatch = { | 22 closedSwatch = { |
19 [[Interface\Buttons\UI-Panel-QuestHideButton]], | 23 [[Interface\Buttons\UI-Panel-QuestHideButton]], |
20 [[Interface\Buttons\UI-Panel-QuestHideButton]], | 24 [[Interface\Buttons\UI-Panel-QuestHideButton]], |
21 0, 0.5, 0.5, 1, | 25 0, 0.5, 0.5, 1, |
45 } | 49 } |
46 } | 50 } |
47 | 51 |
48 local Scroller_OnShow = function() | 52 local Scroller_OnShow = function() |
49 Wrapper.watchMoneyReasons = 0; | 53 Wrapper.watchMoneyReasons = 0; |
50 --mod:Update() | 54 --T:Update() |
51 --mod:OnInitialize() | 55 --T:OnInitialize() |
52 for i, region in ipairs(Wrapper.headerComplex) do | 56 for i, region in ipairs(Wrapper.headerComplex) do |
53 region:Show() | 57 region:Show() |
54 end | 58 end |
55 end | 59 end |
56 | 60 |
75 end | 79 end |
76 self:SetVerticalScroll(s) | 80 self:SetVerticalScroll(s) |
77 B.Conf.ObjectiveScroll = s | 81 B.Conf.ObjectiveScroll = s |
78 print('|cFF00FF00OnMouseWheel', 'from = ', from, 'scroll =', s, ' range =', r, 'current =', self:GetVerticalScroll()) | 82 print('|cFF00FF00OnMouseWheel', 'from = ', from, 'scroll =', s, ' range =', r, 'current =', self:GetVerticalScroll()) |
79 | 83 |
80 mod.UpdateActionButtons('SCROLLING') | 84 T.UpdateActionButtons('SCROLLING') |
81 end | 85 end |
82 | 86 |
83 local UpdatePanelButton = function (self, state) | 87 local UpdatePanelButton = function (self, state) |
84 state = state and B.Conf.FrameState[state] or 1 | 88 state = state or true |
85 local swatch = (state == 1) and self.openSwatch or self.closedSwatch | 89 local swatch = (state == true) and self.openSwatch or self.closedSwatch |
90 print((state ~= true) and 'closedSwatch' or 'openSwatch') | |
86 self:SetNormalTexture(swatch[1]) | 91 self:SetNormalTexture(swatch[1]) |
87 self:SetPushedTexture(swatch[2]) | 92 self:SetPushedTexture(swatch[2]) |
88 if #swatch >= 6 then | 93 if #swatch >= 6 then |
89 self:GetNormalTexture():SetTexCoord(swatch[3], swatch[4], swatch[5], swatch[6]) | 94 self:GetNormalTexture():SetTexCoord(swatch[3], swatch[4], swatch[5], swatch[6]) |
90 end | 95 end |
94 | 99 |
95 end | 100 end |
96 | 101 |
97 local OnClick = {} | 102 local OnClick = {} |
98 OnClick.CloseButton = function(self) | 103 OnClick.CloseButton = function(self) |
99 Wrapper:Minimize() | 104 T:SetEnabled() |
100 UpdatePanelButton(self, self.parent) | 105 UpdatePanelButton(self, T.Conf.enabled) |
101 end | 106 end |
102 | 107 |
103 OnClick.QuestMapButton = function() | 108 OnClick.QuestMapButton = function() |
104 ToggleWorldMap() | 109 ToggleWorldMap() |
105 end | 110 end |
106 | 111 |
107 | 112 |
108 mod.InitializeWidgets = function() | 113 T.InitializeWidgets = function() |
114 local panelButtons = T.buttons | |
109 --- tracker scroll | 115 --- tracker scroll |
110 Scroller:SetScript('OnMouseWheel', Scroller_OnMouseWheel) | 116 Scroller:SetScript('OnMouseWheel', Scroller_OnMouseWheel) |
111 Scroller:SetScript('OnShow', Scroller_OnShow) | 117 Scroller:SetScript('OnShow', Scroller_OnShow) |
112 Scroller:SetScript('OnHide', Scroller_OnHide) | 118 Scroller:SetScript('OnHide', Scroller_OnHide) |
113 for name, swatch in pairs(panelButtons) do | 119 for name, swatch in pairs(panelButtons) do |
117 button.openSwatch = source.openSwatch | 123 button.openSwatch = source.openSwatch |
118 button.closedSwatch = source.closedSwatch | 124 button.closedSwatch = source.closedSwatch |
119 if OnClick[name] then | 125 if OnClick[name] then |
120 button:SetScript('OnClick', OnClick[name]) | 126 button:SetScript('OnClick', OnClick[name]) |
121 end | 127 end |
122 UpdatePanelButton(button, button.parent) | 128 UpdatePanelButton(button, T.Conf.enabled) |
123 end | 129 end |
124 end | 130 end |
125 | 131 |
126 ---------------------------------------------------------------------------------------- | 132 ---------------------------------------------------------------------------------------- |
127 --- XML and script code lifted from "QuestKing 2" by Barjack, | 133 --- modified version of the itemButton initializer used by Barjack's 'QuestKing 2' addon, |
128 --- found at http://mods.curse.com/addons/wow/questking | 134 --- url: http://mods.curse.com/addons/wow/questking |
129 ---------------------------------------------------------------------------------------- | 135 ---------------------------------------------------------------------------------------- |
130 local usedButtons = mod.Quest.itemButtons | 136 T.SetItemButton = function(block, info) |
131 local freeButtons = mod.Quest.freeButtons | |
132 mod.SetItemButton = function(block, info) | |
133 local itemInfo = info.specialItem | 137 local itemInfo = info.specialItem |
134 if not itemInfo then | 138 if not itemInfo then |
135 return | 139 return |
136 end | 140 end |
137 | |
138 --- Quest.GetInfo().specialItem :: {link = link, charges = charges, icon = icon, start = start, duration = duration, enable = enable} | |
139 | |
140 | 141 |
141 local itemButton | 142 local itemButton |
142 if not info.itemButton then | 143 if not info.itemButton then |
143 if #freeButtons >= 1 then | 144 if #freeButtons >= 1 then |
144 print(' |cFF00FFFFfound a free button') | 145 print(' |cFF00FFFFfound a free button') |
147 if itemButton.block then | 148 if itemButton.block then |
148 itemButton.block.itemButton = nil | 149 itemButton.block.itemButton = nil |
149 itemButton.block = nil | 150 itemButton.block = nil |
150 end | 151 end |
151 else | 152 else |
152 local buttonIndex = mod.Quest.numButtons + #freeButtons + 1 | 153 local buttonIndex = T.Quest.numButtons + #freeButtons + 1 |
153 itemButton = CreateFrame('Button', 'VeneerQuestItemButton' .. buttonIndex, UIParent, 'VeneerItemButtonTemplate') | 154 itemButton = CreateFrame('Button', 'VeneerQuestItemButton' .. buttonIndex, UIParent, 'VeneerItemButtonTemplate') |
154 itemButton.buttonIndex = buttonIndex | 155 itemButton.buttonIndex = buttonIndex |
155 itemButton:SetSize(36, 36) | 156 itemButton:SetSize(36, 36) |
156 itemButton:GetNormalTexture():SetSize(36 * (5/3), 36 * (5/3)) | 157 itemButton:GetNormalTexture():SetSize(36 * (5/3), 36 * (5/3)) |
157 print(' |cFFFF4400starting new button', itemButton:GetName()) | 158 print(' |cFFFF4400starting new button', itemButton:GetName()) |
158 end | 159 end |
159 mod.Quest.numButtons = mod.Quest.numButtons + 1 | 160 T.Quest.numButtons = T.Quest.numButtons + 1 |
160 else | 161 else |
161 itemButton = info.itemButton | 162 itemButton = info.itemButton |
162 print(' |cFF00FF00found assigned button', itemButton:GetName()) | 163 print(' |cFF00FF00found assigned button', itemButton:GetName()) |
163 | 164 |
164 end | 165 end |
186 Veneer_QuestObjectiveItem_UpdateCooldown(itemButton); | 187 Veneer_QuestObjectiveItem_UpdateCooldown(itemButton); |
187 | 188 |
188 return itemButton | 189 return itemButton |
189 end | 190 end |
190 --- Clear an itemButton from the given block | 191 --- Clear an itemButton from the given block |
191 mod.FreeItemButtons = function(block) | 192 T.FreeItemButtons = function(block) |
192 | 193 |
193 if block.itemButton then | 194 if block.itemButton then |
194 local itemButton = block.itemButton | 195 local itemButton = block.itemButton |
195 if itemButton.questID ~= block.info.questID then | 196 if itemButton.questID ~= block.info.questID then |
196 block.itemButton = nil | 197 block.itemButton = nil |
197 itemButton.block = mod.Quest.InfoBlock[itemButton.questID] | 198 itemButton.block = T.Quest.InfoBlock[itemButton.questID] |
198 else | 199 else |
199 itemButton.block = nil | 200 itemButton.block = nil |
200 itemButton:Hide() | 201 itemButton:Hide() |
201 | 202 |
202 usedButtons[itemButton.questID] = nil | 203 usedButtons[itemButton.questID] = nil |
203 freeButtons[#freeButtons + 1] = itemButton | 204 freeButtons[#freeButtons + 1] = itemButton |
204 mod.Quest.numButtons = mod.Quest.numButtons - 1 | 205 T.Quest.numButtons = T.Quest.numButtons - 1 |
205 print('|cFFFF0088released', itemButton:GetName(),'and', block:GetName()) | 206 print('|cFFFF0088released', itemButton:GetName(),'and', block:GetName()) |
206 end | 207 end |
207 end | 208 end |
208 end | 209 end |
209 | 210 |
213 if (rangeTimer) then | 214 if (rangeTimer) then |
214 rangeTimer = rangeTimer - elapsed | 215 rangeTimer = rangeTimer - elapsed |
215 if (rangeTimer <= 0) then | 216 if (rangeTimer <= 0) then |
216 local link, item, charges, showItemWhenComplete = GetQuestLogSpecialItemInfo(self.questLogIndex) | 217 local link, item, charges, showItemWhenComplete = GetQuestLogSpecialItemInfo(self.questLogIndex) |
217 if ((not charges) or (charges ~= self.charges)) then | 218 if ((not charges) or (charges ~= self.charges)) then |
218 mod:Update() | 219 T:Update() |
219 return | 220 return |
220 end | 221 end |
221 | 222 |
222 local count = self.HotKey | 223 local count = self.HotKey |
223 local valid = IsQuestLogSpecialItemInRange(self.questLogIndex) | 224 local valid = IsQuestLogSpecialItemInRange(self.questLogIndex) |
263 assetID = assetID, | 264 assetID = assetID, |
264 quantityString = quantityString, | 265 quantityString = quantityString, |
265 criteriaID = criteriaID, | 266 criteriaID = criteriaID, |
266 ]] | 267 ]] |
267 local newWidgetID = 0 | 268 local newWidgetID = 0 |
268 mod.WidgetRegistry = {} | 269 T.WidgetRegistry = {} |
269 local wr = mod.WidgetRegistry | 270 local wr = T.WidgetRegistry |
270 | 271 |
271 --- Get a usable widget for the given achievement criteria set. | 272 --- Get a usable widget for the given achievement criteria set. |
272 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block | 273 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block |
273 mod.SetWidget = function(line, data, objectiveType, objectiveKey) | 274 T.SetWidget = function(line, data, objectiveType, objectiveKey) |
274 local print = B.print('ObjectiveWidgets') | 275 local print = B.print('ObjectiveWidgets') |
275 local widgetType = objectiveType | 276 local widgetType = objectiveType |
276 local widget | 277 local widget |
277 if wr[widgetType] and wr[widgetType].used[objectiveKey] then | 278 if wr[widgetType] and wr[widgetType].used[objectiveKey] then |
278 widget = wr[widgetType].used[objectiveKey] | 279 widget = wr[widgetType].used[objectiveKey] |
289 | 290 |
290 wr[widgetType].used[objectiveKey] = widget | 291 wr[widgetType].used[objectiveKey] = widget |
291 widget.line = line | 292 widget.line = line |
292 widget.objective = data | 293 widget.objective = data |
293 widget.key = objectiveKey | 294 widget.key = objectiveKey |
294 mod.InitializeWidget(widget) | 295 T.InitializeWidget(widget) |
295 return widget | 296 return widget |
296 end | 297 end |
297 | 298 |
298 --- WidgetTemplate 'OnLoad' | 299 --- WidgetTemplate 'OnLoad' |
299 mod.RegisterWidget = function(frame) | 300 T.RegisterWidget = function(frame) |
300 local print = B.print('ObjectiveWidgets') | 301 local print = B.print('ObjectiveWidgets') |
301 local widgetType = frame.widgetType | 302 local widgetType = frame.widgetType |
302 if not wr[frame.widgetType] then | 303 if not wr[frame.widgetType] then |
303 print('|cFFFF4400[[WidgetTemplate]]|r', widgetType) | 304 print('|cFFFF4400[[WidgetTemplate]]|r', widgetType) |
304 wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} } | 305 wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} } |
307 wr[widgetType].lastn = wr[widgetType].lastn + 1 | 308 wr[widgetType].lastn = wr[widgetType].lastn + 1 |
308 end | 309 end |
309 end | 310 end |
310 | 311 |
311 --- WidgetTemplate 'OnShow' | 312 --- WidgetTemplate 'OnShow' |
312 mod.InitializeWidget = setmetatable({}, { | 313 T.InitializeWidget = setmetatable({}, { |
313 __call = function(t, frame) | 314 __call = function(t, frame) |
314 -- todo: config pull | 315 -- todo: config pull |
315 | 316 |
316 frame:SetWidth(mod.Conf.Wrapper.Width - mod.Conf.Style.Format.status.Indent * 2) | 317 frame:SetWidth(T.Conf.Wrapper.Width - T.Conf.Style.Format.status.Indent * 2) |
317 frame:SetScript('OnEvent', mod.UpdateWidget[frame.widgetType]) | 318 frame:SetScript('OnEvent', T.UpdateWidget[frame.widgetType]) |
318 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') | 319 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') |
319 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') | 320 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') |
320 frame:RegisterEvent('CRITERIA_UPDATE') | 321 frame:RegisterEvent('CRITERIA_UPDATE') |
321 frame:RegisterEvent('CRITERIA_COMPLETE') | 322 frame:RegisterEvent('CRITERIA_COMPLETE') |
322 frame:RegisterEvent('CRITERIA_EARNED') | 323 frame:RegisterEvent('CRITERIA_EARNED') |
323 t[frame.widgetType](frame) | 324 t[frame.widgetType](frame) |
324 mod.UpdateWidget[frame.widgetType](frame) | 325 T.UpdateWidget[frame.widgetType](frame) |
325 end, | 326 end, |
326 }) | 327 }) |
327 | 328 |
328 --- WidgetTemplate 'OnEvent' | 329 --- WidgetTemplate 'OnEvent' |
329 mod.UpdateWidget = setmetatable({}, { | 330 T.UpdateWidget = setmetatable({}, { |
330 __call = function(t, frame) | 331 __call = function(t, frame) |
331 if not frame.widgetType then | 332 if not frame.widgetType then |
332 error('Invalid widget template, needs .widgetType') | 333 error('Invalid widget template, needs .widgetType') |
333 return | 334 return |
334 end | 335 end |
336 return t[frame.widgetType](frame) | 337 return t[frame.widgetType](frame) |
337 end | 338 end |
338 }) | 339 }) |
339 | 340 |
340 --- WidgetTemplate 'OnHide' | 341 --- WidgetTemplate 'OnHide' |
341 mod.ReleaseWidget = function(frame) | 342 T.ReleaseWidget = function(frame) |
342 --[[ | 343 --[[ |
343 local print = B.print('ObjectiveWidgets') | 344 local print = B.print('ObjectiveWidgets') |
344 local reg = wr[frame.widgetType] | 345 local reg = wr[frame.widgetType] |
345 if reg and reg.used[frame.key] then | 346 if reg and reg.used[frame.key] then |
346 reg.used[frame.key] = nil | 347 reg.used[frame.key] = nil |
352 end | 353 end |
353 ]] | 354 ]] |
354 end | 355 end |
355 | 356 |
356 --- RemoveTrackedAchievement post-hook | 357 --- RemoveTrackedAchievement post-hook |
357 mod.CleanWidgets = function() | 358 T.CleanWidgets = function() |
358 local print = B.print('ObjectiveWidgets') | 359 local print = B.print('ObjectiveWidgets') |
359 local tracked = {GetTrackedAchievements() } | 360 local tracked = {GetTrackedAchievements() } |
360 local tasks = GetTasksTable() | 361 local tasks = GetTasksTable() |
361 for type, reg in pairs(mod.WidgetRegistry) do | 362 for type, reg in pairs(T.WidgetRegistry) do |
362 print('collecting', type) | 363 print('collecting', type) |
363 for key, frame in pairs(reg.used) do | 364 for key, frame in pairs(reg.used) do |
364 if frame.objective.cheevID then | 365 if frame.objective.cheevID then |
365 local id = frame.objective.cheevID | 366 local id = frame.objective.cheevID |
366 | 367 |
376 end | 377 end |
377 end | 378 end |
378 | 379 |
379 | 380 |
380 | 381 |
381 mod.defaults.WidgetStyle = { | 382 T.defaults.WidgetStyle = { |
382 | 383 |
383 } | 384 } |
384 | 385 |
385 local progressHeight = 16 | 386 local progressHeight = 16 |
386 local progressBorder = 1 | 387 local progressBorder = 1 |
387 local progressIndent = 3 | 388 local progressIndent = 3 |
388 local progressFont = _G.VeneerCriteriaFontNormal | 389 local progressFont = _G.VeneerCriteriaFontNormal |
389 | 390 |
390 | 391 |
391 mod.InitializeWidget.ProgressBar = function(self) | 392 T.InitializeWidget.ProgressBar = function(self) |
392 local c = mod.Conf.Wrapper | 393 local c = T.Conf.Wrapper |
393 self.height = progressHeight + c.TextSpacing | 394 self.height = progressHeight + c.TextSpacing |
394 self.width = c.Width - c.TextSpacing | 395 self.width = c.Width - c.TextSpacing |
395 self.indent = progressIndent | 396 self.indent = progressIndent |
396 | 397 |
397 self:SetHeight(progressHeight) | 398 self:SetHeight(progressHeight) |
402 self.fg:SetHeight(progressHeight - progressBorder * 2) | 403 self.fg:SetHeight(progressHeight - progressBorder * 2) |
403 self.status:SetFontObject(progressFont) | 404 self.status:SetFontObject(progressFont) |
404 self.status:SetText(self.objective.quantityString) | 405 self.status:SetText(self.objective.quantityString) |
405 end | 406 end |
406 | 407 |
407 mod.UpdateWidget.ProgressBar = function (self) | 408 T.UpdateWidget.ProgressBar = function (self) |
408 local quantity, requiredQuantity = self.objective.value, self.objective.maxValue | 409 local quantity, requiredQuantity = self.objective.value, self.objective.maxValue |
409 print('update vals:') | 410 print('update vals:') |
410 for k,v in pairs(self.line) do | 411 for k,v in pairs(self.line) do |
411 print(k, v) | 412 print(k, v) |
412 end | 413 end |
429 self.fg:Hide() | 430 self.fg:Hide() |
430 end | 431 end |
431 end | 432 end |
432 | 433 |
433 | 434 |
434 mod.InitializeWidget.Hidden = function (self) | 435 T.InitializeWidget.Hidden = function (self) |
435 self.height = 0 | 436 self.height = 0 |
436 end | 437 end |
437 mod.UpdateWidget.Hidden = function (self) | 438 T.UpdateWidget.Hidden = function (self) |
438 self.height= 0 | 439 self.height= 0 |
439 end | 440 end |