Mercurial > wow > buffalo2
comparison ObjectiveWidgets.lua @ 14:ed642234f017
ObjectiveFrame
- implement proper tracker name text
- expanded tracker prototypes to cover "objective lines" formatting and accommodation of widget variables
- implement the progress bars for bonus objectives
ObjectiveStyle
- moved `UpdateWrapperStyle` over and renamed it to fit semantics
- change the formula for block.`height` to measure non-widget content only
- allows widgets to position relative to text
- size FontString `status` to match block.`height`
- full block height is acquired by adding block.`height` and block.`attachmentHeight` which is calculated during objective parsing
ObjectiveWidgets
- use string keys for generated widgets to deal with multiple objectives under the same questID, and maybe dungeon objectives
- wrapper buttons use a common code path
- specialized handlers for wheel scrolling moved over to fit semantics
author | Nenue |
---|---|
date | Mon, 04 Apr 2016 03:16:22 -0400 |
parents | 9455693fc290 |
children | f660f1c1e0aa |
comparison
equal
deleted
inserted
replaced
13:9455693fc290 | 14:ed642234f017 |
---|---|
3 local print = B.print('WidgetFactory') | 3 local print = B.print('WidgetFactory') |
4 local UIParent = UIParent | 4 local UIParent = 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, tinsert, tContains, pairs, setmetatable = tremove, tinsert, tContains, pairs, setmetatable |
8 | |
9 --- frame refs | |
10 local Wrapper = _G.VeneerObjectiveWrapper | |
11 local Scroller = Wrapper.scrollArea | |
12 local CloseButton = Wrapper.CloseButton | |
13 local QuestMapButton = Wrapper.QuestMapButton | |
14 local Scroll = _G.VeneerObjectiveScroll | |
15 | |
16 local panelButtons = { | |
17 CloseButton = { | |
18 closedSwatch = { | |
19 [[Interface\Buttons\UI-Panel-QuestHideButton]], | |
20 [[Interface\Buttons\UI-Panel-QuestHideButton]], | |
21 0, 0.5, 0.5, 1, | |
22 0.5, 1, 0.5, 1, | |
23 }, | |
24 openSwatch = { | |
25 [[Interface\Buttons\UI-Panel-QuestHideButton]], | |
26 [[Interface\Buttons\UI-Panel-QuestHideButton]], | |
27 0.5, 1, 0.5, 1, | |
28 0, 0.5, 0.5, 1, | |
29 }, | |
30 parent = 'VeneerObjectiveWrapper' | |
31 }, | |
32 QuestMapButton = { | |
33 closedSwatch = { | |
34 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], | |
35 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], | |
36 0, 1, 0.5, 1, | |
37 0, 1, 0, 0.5, | |
38 }, | |
39 openSwatch = { | |
40 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], | |
41 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], | |
42 0, 1, 0, 0.5, | |
43 0, 1, 0.5, 1, | |
44 } | |
45 } | |
46 } | |
47 | |
48 local Scroller_OnShow = function() | |
49 Wrapper.watchMoneyReasons = 0; | |
50 mod.UpdateWrapper() | |
51 mod.SetEvents() | |
52 for i, region in ipairs(Wrapper.headerComplex) do | |
53 region:Show() | |
54 end | |
55 end | |
56 | |
57 local Scroller_OnHide = function() | |
58 local self = Wrapper | |
59 Wrapper:UnregisterAllEvents() | |
60 Wrapper:SetScript('OnEvent', nil) | |
61 for i, region in ipairs(Wrapper.headerComplex) do | |
62 region:Hide() | |
63 end | |
64 end | |
65 | |
66 local Scroller_OnMouseWheel = function(self, delta) | |
67 local r = Scroll:GetHeight() - Scroller:GetHeight() | |
68 local s = B.Conf.ObjectiveScroll - delta * floor(r/5+.5) | |
69 local from = self:GetVerticalScroll() | |
70 if s >= r then | |
71 s = r | |
72 elseif s < 1 then | |
73 s = 0 | |
74 end | |
75 self:SetVerticalScroll(s) | |
76 B.Conf.ObjectiveScroll = s | |
77 print('|cFF00FF00OnMouseWheel', 'from = ', from, 'scroll =', s, ' range =', r, 'current =', self:GetVerticalScroll()) | |
78 | |
79 mod.UpdateActionButtons('SCROLLING') | |
80 end | |
81 | |
82 local UpdatePanelButton = function (self, state) | |
83 state = state and B.Conf.FrameState[state] or 1 | |
84 local swatch = (state == 1) and self.openSwatch or self.closedSwatch | |
85 self:SetNormalTexture(swatch[1]) | |
86 self:SetPushedTexture(swatch[2]) | |
87 if #swatch >= 6 then | |
88 self:GetNormalTexture():SetTexCoord(swatch[3], swatch[4], swatch[5], swatch[6]) | |
89 end | |
90 if #swatch == 10 then | |
91 self:GetPushedTexture():SetTexCoord(swatch[7], swatch[8], swatch[9], swatch[10]) | |
92 end | |
93 | |
94 end | |
95 | |
96 local OnClick = {} | |
97 OnClick.CloseButton = function(self) | |
98 Wrapper:Minimize() | |
99 UpdatePanelButton(self, self.parent) | |
100 end | |
101 | |
102 OnClick.QuestMapButton = function() | |
103 ToggleWorldMap() | |
104 end | |
105 | |
106 mod.InitializeWrapperWidgets = function() | |
107 --- tracker scroll | |
108 Scroller:SetScript('OnMouseWheel', Scroller_OnMouseWheel) | |
109 Scroller:SetScript('OnShow', Scroller_OnShow) | |
110 Scroller:SetScript('OnHide', Scroller_OnHide) | |
111 for name, swatch in pairs(panelButtons) do | |
112 local source = swatch and swatch or panelButtons.CloseButton | |
113 local button = Wrapper[name] | |
114 button.parent = swatch.parent | |
115 button.openSwatch = source.openSwatch | |
116 button.closedSwatch = source.closedSwatch | |
117 if OnClick[name] then | |
118 button:SetScript('OnClick', OnClick[name]) | |
119 end | |
120 UpdatePanelButton(button, button.parent) | |
121 end | |
122 end | |
123 | |
8 ---------------------------------------------------------------------------------------- | 124 ---------------------------------------------------------------------------------------- |
9 --- XML and script code lifted from "QuestKing 2" by Barjack, | 125 --- XML and script code lifted from "QuestKing 2" by Barjack, |
10 --- found at http://mods.curse.com/addons/wow/questking | 126 --- found at http://mods.curse.com/addons/wow/questking |
11 ---------------------------------------------------------------------------------------- | 127 ---------------------------------------------------------------------------------------- |
12 local usedButtons = mod.Quest.itemButtons | 128 local usedButtons = mod.Quest.itemButtons |
150 mod.WidgetRegistry = {} | 266 mod.WidgetRegistry = {} |
151 local wr = mod.WidgetRegistry | 267 local wr = mod.WidgetRegistry |
152 | 268 |
153 --- Get a usable widget for the given achievement criteria set. | 269 --- Get a usable widget for the given achievement criteria set. |
154 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block | 270 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block |
155 mod.SetWidget = function(obj, info) | 271 mod.SetWidget = function(line, info, objectiveType, objectiveKey) |
156 local print = B.print('ObjectiveWidgets') | 272 local print = B.print('ObjectiveWidgets') |
157 local widgetType = obj.type | 273 local widgetType = objectiveType |
158 local widget | 274 local widget |
159 if wr[widgetType] and wr[widgetType].used[obj.criteriaID] then | 275 if wr[widgetType] and wr[widgetType].used[objectiveKey] then |
160 widget = wr[widgetType].used[obj.criteriaID] | 276 widget = wr[widgetType].used[objectiveKey] |
161 print('|cFF00FF00Updating ('..obj.criteriaID..')', widget) | 277 print('|cFF00FF00Updating ('..objectiveKey..')', widget) |
162 elseif not wr[widgetType] or #wr[widgetType].free == 0 then | 278 elseif not wr[widgetType] or #wr[widgetType].free == 0 then |
163 widget = CreateFrame('Frame', 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) | 279 widget = CreateFrame('Frame', 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) |
164 | 280 |
165 print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn) | 281 print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn) |
166 else | 282 else |
167 widget = tremove(wr[widgetType].free) | 283 widget = tremove(wr[widgetType].free) |
168 print('|cFFFFFF00Acquiring released widget', widget:GetName()) | 284 print('|cFFFFFF00Acquiring released widget', widget:GetName()) |
169 end | 285 end |
170 | 286 |
171 wr[widgetType].used[obj.criteriaID] = widget | 287 |
172 widget.info = obj | 288 wr[widgetType].used[objectiveKey] = widget |
173 widget.parentInfo = info | 289 widget.line = line |
290 widget.info = info | |
291 widget.key = objectiveKey | |
174 mod.InitializeWidget(widget) | 292 mod.InitializeWidget(widget) |
175 return widget | 293 return widget |
176 end | 294 end |
177 | 295 |
178 --- WidgetTemplate 'OnLoad' | 296 --- WidgetTemplate 'OnLoad' |
193 __call = function(t, frame) | 311 __call = function(t, frame) |
194 -- todo: config pull | 312 -- todo: config pull |
195 local maxWidth = 250 | 313 local maxWidth = 250 |
196 | 314 |
197 frame:SetWidth(maxWidth) | 315 frame:SetWidth(maxWidth) |
198 mod.UpdateWidget[frame.widgetType](frame) | |
199 frame:SetScript('OnEvent', mod.UpdateWidget[frame.widgetType]) | 316 frame:SetScript('OnEvent', mod.UpdateWidget[frame.widgetType]) |
200 if frame.info.isCurrency then | 317 if frame.info.isCurrency then |
201 frame:RegisterEvent('CHAT_MSG_CURRENCY') | 318 frame:RegisterEvent('CHAT_MSG_CURRENCY') |
202 frame:RegisterEvent('CURRENCY_LIST_UPDATE') | 319 frame:RegisterEvent('CURRENCY_LIST_UPDATE') |
203 end | 320 end |
204 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') | 321 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') |
205 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') | 322 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') |
206 frame:RegisterEvent('CRITERIA_UPDATE') | 323 frame:RegisterEvent('CRITERIA_UPDATE') |
207 frame:RegisterEvent('CRITERIA_COMPLETE') | 324 frame:RegisterEvent('CRITERIA_COMPLETE') |
208 frame:RegisterEvent('CRITERIA_EARNED') | 325 frame:RegisterEvent('CRITERIA_EARNED') |
209 | 326 t[frame.widgetType](frame) |
210 return t[frame.widgetType](frame) | 327 mod.UpdateWidget[frame.widgetType](frame) |
211 end, | 328 end, |
212 }) | 329 }) |
213 | 330 |
214 --- WidgetTemplate 'OnEvent' | 331 --- WidgetTemplate 'OnEvent' |
215 mod.UpdateWidget = setmetatable({}, { | 332 mod.UpdateWidget = setmetatable({}, { |
225 | 342 |
226 --- WidgetTemplate 'OnHide' | 343 --- WidgetTemplate 'OnHide' |
227 mod.ReleaseWidget = function(frame) | 344 mod.ReleaseWidget = function(frame) |
228 local print = B.print('ObjectiveWidgets') | 345 local print = B.print('ObjectiveWidgets') |
229 local reg = wr[frame.widgetType] | 346 local reg = wr[frame.widgetType] |
230 if reg and reg.used[frame.info.criteriaID] then | 347 if reg and reg.used[frame.key] then |
231 reg.used[frame.info.criteriaID] = nil | 348 reg.used[frame.key] = nil |
349 frame.line = nil | |
232 frame.info = nil | 350 frame.info = nil |
233 frame.parentInfo = nil | |
234 frame:UnregisterAllEvents() | 351 frame:UnregisterAllEvents() |
235 tinsert(reg.free, frame) | 352 tinsert(reg.free, frame) |
236 print('|cFFBBBBBBreleased from service', frame:GetName()) | 353 print('|cFFBBBBBBreleased from service', frame:GetName()) |
237 end | 354 end |
238 end | 355 end |
239 | 356 |
240 --- RemoveTrackedAchievement post-hook | 357 --- RemoveTrackedAchievement post-hook |
241 mod.CleanWidgets = function() | 358 mod.CleanWidgets = function() |
242 local print = B.print('ObjectiveWidgets') | 359 local print = B.print('ObjectiveWidgets') |
243 local tracked = {GetTrackedAchievements() } | 360 local tracked = {GetTrackedAchievements() } |
361 local tasks = GetTasksTable() | |
244 for type, reg in pairs(mod.WidgetRegistry) do | 362 for type, reg in pairs(mod.WidgetRegistry) do |
245 print('collecting', type) | 363 print('collecting', type) |
246 for criteriaID, frame in pairs(reg.used) do | 364 for key, frame in pairs(reg.used) do |
247 local id = frame.info.cheevID | 365 if frame.info.cheevID then |
248 | 366 local id = frame.info.cheevID |
249 if id and not tContains(tracked, id) then | 367 |
250 | 368 if id and not tContains(tracked, id) then |
251 print(' untracked achievement', id, 'associated with', criteriaID, frame:GetName()) | 369 |
252 frame:Hide() | 370 print(' untracked achievement', id, 'associated with', key, frame:GetName()) |
371 frame:Hide() | |
372 end | |
373 elseif frame.info.questID then | |
374 -- do something for quest task | |
253 end | 375 end |
254 end | 376 end |
255 end | 377 end |
256 end | 378 end |
257 | 379 |
258 | 380 |
259 mod.defaults.WidgetVars = { | 381 |
382 mod.defaults.WidgetStyle = { | |
260 ProgressBar = { | 383 ProgressBar = { |
384 Spacing = 4, | |
261 bg = { | 385 bg = { |
262 Height = 20, | 386 Height = 20, |
263 }, | 387 }, |
264 fg = { | 388 fg = { |
265 Height = 16, | 389 Height = 16, |
266 }, | 390 }, |
267 status = { | 391 status = { |
268 FontObject = _G.VeneerFontNormal | 392 FontObject = _G.VeneerCriteriaFontNormal |
269 } | 393 } |
270 } | 394 } |
271 } | 395 } |
272 mod.InitializeWidget.ProgressBar = function(self) | 396 mod.InitializeWidget.ProgressBar = function(self) |
273 local c = mod.defaults.WidgetVars.ProgressBar | 397 local c = mod.defaults.WidgetStyle.ProgressBar |
274 local params = mod.WidgetParams[self.widgetType] | 398 self.height = c.bg.Height + c.Spacing |
275 self.height = params.height | |
276 self:SetHeight(c.bg.Height) | 399 self:SetHeight(c.bg.Height) |
277 self.bg:SetHeight(c.bg.Height) | 400 self.bg:SetHeight(c.bg.Height) |
278 self.fg:ClearAllPoints() | 401 self.fg:ClearAllPoints() |
279 self.fg:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 2, 2) | 402 self.indent = (c.bg.Height - c.fg.Height) / 2 |
403 self.fg:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', self.indent, self.indent) | |
280 self.fg:SetHeight(c.fg.Height) | 404 self.fg:SetHeight(c.fg.Height) |
281 self.status:SetFontObject(c.status.FontObject) | 405 self.status:SetFontObject(c.status.FontObject) |
282 self.status:SetText(self.info.quantityString) | 406 self.status:SetText(self.info.quantityString) |
283 end | 407 end |
284 | 408 |
285 mod.UpdateWidget.ProgressBar = function (self) | 409 mod.UpdateWidget.ProgressBar = function (self) |
286 local quantity, requiredQuantity = self.info.quantity, self.info.requiredQuantity | 410 local quantity, requiredQuantity = self.line.value, self.line.maxValue |
287 | 411 print('update vals:') |
288 if self.info.finished then | 412 for k,v in pairs(self.line) do |
289 self.fg:SetWidth(self.bg:GetWidth() - 4) | 413 print(k, v) |
414 end | |
415 | |
416 if self.line.format then | |
417 self.status:SetFormattedText(self.line.format, self.line.value, self.line.maxValue) | |
418 end | |
419 | |
420 | |
421 if self.line.finished then | |
422 self.fg:SetWidth(self.bg:GetWidth() - self.indent) | |
290 elseif quantity == 0 then | 423 elseif quantity == 0 then |
291 self.fg:Hide() | 424 self.fg:Hide() |
292 else | 425 else |
293 self.fg:Show() | 426 self.fg:Show() |
294 self.fg:SetWidth((self.bg:GetWidth()-4) * (quantity / requiredQuantity)) | 427 self.fg:SetWidth((self.bg:GetWidth() -self.indent) * (quantity / requiredQuantity)) |
295 end | 428 end |
296 end | 429 end |
297 | 430 |
298 | 431 |
299 mod.InitializeWidget.Hidden = function (self) | 432 mod.InitializeWidget.Hidden = function (self) |