Mercurial > wow > buffalo2
comparison ObjectiveUI.lua @ 13:9455693fc290
Init
- recall XML display state on reload
ObjectiveFrame
- quest coloring by relative level
- quest coloring by daily/weekly/complete status
- remember starting scroll value between reload
- limit anchor points to edges for regions affected by style attributes
ObjectiveInfo
- AutoQuest outline definitions
- Pull Quest title and tag data in addition to WatchInfo
ObjectiveStyle
- ensure consistent style table
- hardcode certain attributes for sanity
XML
- ensure consistent naming conventions for heading and content elements
- ensure hardcore anchors are based on edges
- expansion of file structure to deal with complexities of dynamic widgets and style caching
ObjectiveUI
- determine primary style by block handler when restoring original style
- moved framescript to 'ObjectiveWidgets' lua
author | Nenue |
---|---|
date | Sat, 02 Apr 2016 17:46:52 -0400 |
parents | 8238cddaddb1 |
children | ed642234f017 |
comparison
equal
deleted
inserted
replaced
12:8238cddaddb1 | 13:9455693fc290 |
---|---|
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 local tremove, tremovebyval = table.remove, table.removebyval |
12 | 12 |
13 -------------------------------------------------------------------- | 13 -------------------------------------------------------------------- |
14 --- Tracker-specific widgets and their handlers | 14 --- Functions responsible for: |
15 --- - UI interactions that propagate to the BlizzardUI (sending RemoveQuestWatch() on remove quest action) | |
16 --- - | |
15 -------------------------------------------------------------------- | 17 -------------------------------------------------------------------- |
16 | 18 |
17 Tracker.Select = function(self) end | 19 Tracker.Select = function(self) end |
18 Tracker.Open = function(self) end | 20 Tracker.Open = function(self) end |
19 Tracker.Remove = function(self) end | 21 Tracker.Remove = function(self) end |
23 | 25 |
24 Tracker.OnMouseUp = function(self, button) | 26 Tracker.OnMouseUp = function(self, button) |
25 if button == 'LeftButton' then | 27 if button == 'LeftButton' then |
26 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then | 28 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then |
27 self:Link() | 29 self:Link() |
30 self:SetStyle('TrackerBlock', self.info.type, 'Normal') | |
28 elseif IsModifiedClick("QUESTWATCHTOGGLE") then | 31 elseif IsModifiedClick("QUESTWATCHTOGGLE") then |
29 self:Remove() | 32 self:Remove() |
30 else | 33 else |
31 self:Select() | 34 self:Select() |
32 end | 35 end |
33 elseif button == 'RightButton' then | 36 elseif button == 'RightButton' then |
34 self:Open() | 37 self:Open() |
38 self:SetStyle('TrackerBlock', self.info.type, 'Normal') | |
35 end | 39 end |
36 self.initialButton = nil | 40 self.initialButton = nil |
37 self.modChatLink = nil | 41 self.modChatLink = nil |
38 self.modQuestWatch = nil | 42 self.modQuestWatch = nil |
39 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') | 43 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') |
40 end | 44 end |
41 | 45 |
42 Tracker.OnMouseDown = function(self, button) | 46 Tracker.OnMouseDown = function(self, button) |
43 self:SetStyle('TrackeBlock','MouseDown') | 47 self:SetStyle('TrackerBlock', 'MouseDown') |
44 print(IsModifiedClick("CHATLINK"), IsModifiedClick("QUESTWATCHTOGGLE")) | 48 print(IsModifiedClick("CHATLINK"), IsModifiedClick("QUESTWATCHTOGGLE")) |
45 print(self.info.title) | 49 print(self.info.title) |
46 end | 50 end |
47 | 51 |
48 ----------------------------- | |
49 --- AUTO_QUEST | |
50 AutoQuest.name = "Remote Quests" | |
51 AutoQuest.GetNumWatched = GetNumAutoQuestPopUps | |
52 | |
53 ----------------------------- | |
54 --- QUEST | |
55 Quest.name = "Quests" | |
56 Quest.Select = function(self) | 52 Quest.Select = function(self) |
57 SetSuperTrackedQuestID(self.info.questID) | 53 SetSuperTrackedQuestID(self.info.questID) |
58 mod.UpdateWrapper() | 54 mod.UpdateWrapper() |
59 end | 55 end |
60 Quest.Link = function(self) | 56 Quest.Link = function(self) |
74 | 70 |
75 | 71 |
76 ----------------------------- | 72 ----------------------------- |
77 --- CHEEVS | 73 --- CHEEVS |
78 Cheevs.Select = function(self) | 74 Cheevs.Select = function(self) |
75 self:SetStyle('TrackerBlock', self.info.type, 'Normal') | |
79 end | 76 end |
80 Cheevs.Remove = function(self) | 77 Cheevs.Remove = function(self) |
81 RemoveTrackedAchievement(self.info.cheevID) | 78 RemoveTrackedAchievement(self.info.cheevID) |
82 end | 79 end |
83 Cheevs.OnMouseUp = function(self, button) | 80 Cheevs.OnMouseUp = function(self, button) |
84 Tracker.OnMouseUp(self, button) | 81 Tracker.OnMouseUp(self, button) |
85 self:SetStyle('TrackerBlock', 'Cheev', 'CheevNormal') | |
86 end | 82 end |
87 Cheevs.Link = function(self) | 83 Cheevs.Link = function(self) |
88 local achievementLink = GetAchievementLink(self.info.cheevID); | 84 local achievementLink = GetAchievementLink(self.info.cheevID); |
89 if ( achievementLink ) then | 85 if ( achievementLink ) then |
90 ChatEdit_InsertLink(achievementLink); | 86 ChatEdit_InsertLink(achievementLink); |
99 AchievementFrame_ToggleAchievementFrame(); | 95 AchievementFrame_ToggleAchievementFrame(); |
100 end | 96 end |
101 AchievementFrame_SelectAchievement(self.info.cheevID); | 97 AchievementFrame_SelectAchievement(self.info.cheevID); |
102 end | 98 end |
103 | 99 |
104 ---------------------------------------------------------------------------------------- | |
105 --- frame template and scripts lifted from "QuestKing 2" by Barjack | |
106 --- url: http://mods.curse.com/addons/wow/questking | |
107 ---------------------------------------------------------------------------------------- | |
108 local usedButtons = mod.Quest.itemButtons | |
109 local freeButtons = mod.Quest.freeButtons | |
110 mod.SetItemButton = function(block, info) | |
111 local itemInfo = info.specialItem | |
112 if not itemInfo then | |
113 return | |
114 end | |
115 --- .specialItem :: {link = link, charges = charges, icon = icon, start = start, duration = duration, enable = enable} | |
116 | |
117 | |
118 local itemButton | |
119 if not info.itemButton then | |
120 if #freeButtons >= 1 then | |
121 print(' |cFF00FFFFfound a free button') | |
122 itemButton = freeButtons[#freeButtons] | |
123 freeButtons[#freeButtons] = nil | |
124 if itemButton.block then | |
125 itemButton.block.itemButton = nil | |
126 itemButton.block = nil | |
127 end | |
128 else | |
129 local buttonIndex = mod.Quest.numButtons + #freeButtons + 1 | |
130 itemButton = CreateFrame('Button', 'VeneerQuestItemButton' .. buttonIndex, UIParent, 'VeneerItemButtonTemplate') | |
131 itemButton.buttonIndex = buttonIndex | |
132 itemButton:SetSize(itemButtonSize, itemButtonSize) | |
133 itemButton:GetNormalTexture():SetSize(itemButtonSize * (5/3), itemButtonSize * (5/3)) | |
134 print(' |cFFFF4400starting new button', itemButton:GetName()) | |
135 end | |
136 mod.Quest.numButtons = mod.Quest.numButtons + 1 | |
137 else | |
138 itemButton = info.itemButton | |
139 print(' |cFF00FF00found assigned button', itemButton:GetName()) | |
140 | |
141 end | |
142 -- set values | |
143 | |
144 info.itemButton = itemButton | |
145 usedButtons[info.questID] = itemButton | |
146 print(' |cFF8800FFassigning|r', itemButton:GetName(), 'to quest|cFF00FF00', info.questID, '|rat|cFFFFFF00', block:GetName(),'|r') | |
147 | |
148 for k,v in pairs(usedButtons) do | |
149 print('|cFFFF44DD'..k..'|r', v:GetName()) | |
150 end | |
151 | |
152 itemButton:SetAttribute("type", "item") | |
153 itemButton:SetAttribute("item", itemInfo.link) | |
154 | |
155 itemButton.questID = info.questID | |
156 itemButton.questLogIndex = info.questLogIndex | |
157 itemButton.charges = itemInfo.charges | |
158 itemButton.rangeTimer = -1 | |
159 itemButton.block = block | |
160 | |
161 SetItemButtonTexture(itemButton, itemInfo.icon) | |
162 SetItemButtonCount(itemButton, itemInfo.charges) | |
163 Veneer_QuestObjectiveItem_UpdateCooldown(itemButton); | |
164 | |
165 return itemButton | |
166 end | |
167 --- Clear an itemButton from the given block | |
168 mod.FreeItemButtons = function(block) | |
169 | |
170 if block.itemButton then | |
171 local itemButton = block.itemButton | |
172 if itemButton.questID ~= block.info.questID then | |
173 block.itemButton = nil | |
174 itemButton.block = mod.Quest.InfoBlock[itemButton.questID] | |
175 else | |
176 itemButton.block = nil | |
177 itemButton:Hide() | |
178 | |
179 usedButtons[itemButton.questID] = nil | |
180 freeButtons[#freeButtons + 1] = itemButton | |
181 mod.Quest.numButtons = mod.Quest.numButtons - 1 | |
182 print('|cFFFF0088released', itemButton:GetName(),'and', block:GetName()) | |
183 end | |
184 end | |
185 end | |
186 | |
187 function Veneer_QuestObjectiveItem_OnUpdate (self, elapsed) | |
188 -- Handle range indicator | |
189 local rangeTimer = self.rangeTimer | |
190 if (rangeTimer) then | |
191 rangeTimer = rangeTimer - elapsed | |
192 if (rangeTimer <= 0) then | |
193 local link, item, charges, showItemWhenComplete = GetQuestLogSpecialItemInfo(self.questLogIndex) | |
194 if ((not charges) or (charges ~= self.charges)) then | |
195 mod.UpdateWrapper() | |
196 return | |
197 end | |
198 | |
199 local count = self.HotKey | |
200 local valid = IsQuestLogSpecialItemInRange(self.questLogIndex) | |
201 if (valid == 0) then | |
202 count:Show() | |
203 count:SetVertexColor(1.0, 0.1, 0.1) | |
204 elseif (valid == 1) then | |
205 count:Show() | |
206 count:SetVertexColor(0.6, 0.6, 0.6) | |
207 else | |
208 count:Hide() | |
209 end | |
210 rangeTimer = TOOLTIP_UPDATE_TIME | |
211 end | |
212 | |
213 self.rangeTimer = rangeTimer | |
214 end | |
215 end | |
216 | |
217 function Veneer_QuestObjectiveItem_UpdateCooldown (itemButton) | |
218 local start, duration, enable = GetQuestLogSpecialItemCooldown(itemButton.questLogIndex) | |
219 if (start) then | |
220 CooldownFrame_SetTimer(itemButton.Cooldown, start, duration, enable) | |
221 if (duration > 0 and enable == 0) then | |
222 SetItemButtonTextureVertexColor(itemButton, 0.4, 0.4, 0.4) | |
223 else | |
224 SetItemButtonTextureVertexColor(itemButton, 1, 1, 1) | |
225 end | |
226 end | |
227 end | |
228 | |
229 ----------------------------------------- | |
230 -- Criteria frames | |
231 | |
232 --[[ | |
233 text = description, | |
234 type = type, | |
235 finished = completed, | |
236 quantity = quantity, | |
237 requiredQuantity = requiredQuantity, | |
238 characterName = characterName, | |
239 flags = flags, | |
240 assetID = assetID, | |
241 quantityString = quantityString, | |
242 criteriaID = criteriaID, | |
243 ]] | |
244 local newWidgetID = 0 | |
245 mod.WidgetRegistry = {} | |
246 local wr = mod.WidgetRegistry | |
247 | |
248 --- Get a usable widget for the given achievement criteria set. | |
249 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block | |
250 mod.SetWidget = function(obj, info) | |
251 local print = B.print('ObjectiveWidgets') | |
252 local widgetType = obj.type | |
253 local widget | |
254 if wr[widgetType] and wr[widgetType].used[obj.criteriaID] then | |
255 widget = wr[widgetType].used[obj.criteriaID] | |
256 print('|cFF00FF00Updating ('..obj.criteriaID..')', widget) | |
257 elseif not wr[widgetType] or #wr[widgetType].free == 0 then | |
258 widget = CreateFrame('Frame', 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) | |
259 | |
260 print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn) | |
261 else | |
262 widget = tremove(wr[widgetType].free) | |
263 print('|cFFFFFF00Acquiring released widget', widget:GetName()) | |
264 end | |
265 | |
266 wr[widgetType].used[obj.criteriaID] = widget | |
267 widget.info = obj | |
268 widget.parentInfo = info | |
269 mod.InitializeWidget(widget) | |
270 return widget | |
271 end | |
272 | |
273 --- WidgetTemplate 'OnLoad' | |
274 mod.RegisterWidget = function(frame) | |
275 local print = B.print('ObjectiveWidgets') | |
276 local widgetType = frame.widgetType | |
277 if not wr[frame.widgetType] then | |
278 print('|cFFFF4400[[WidgetTemplate]]|r', widgetType) | |
279 wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} } | |
280 else | |
281 print('|cFF0088FF+ [[WidgetTemplate]]r', widgetType, wr[widgetType].lastn) | |
282 wr[widgetType].lastn = wr[widgetType].lastn + 1 | |
283 end | |
284 end | |
285 | |
286 --- WidgetTemplate 'OnShow' | |
287 mod.InitializeWidget = setmetatable({}, { | |
288 __call = function(t, frame) | |
289 -- todo: config pull | |
290 local maxWidth = 250 | |
291 | |
292 frame:SetWidth(maxWidth) | |
293 mod.UpdateWidget[frame.widgetType](frame) | |
294 frame:SetScript('OnEvent', mod.UpdateWidget[frame.widgetType]) | |
295 if frame.info.isCurrency then | |
296 frame:RegisterEvent('CHAT_MSG_CURRENCY') | |
297 frame:RegisterEvent('CURRENCY_LIST_UPDATE') | |
298 end | |
299 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') | |
300 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') | |
301 frame:RegisterEvent('CRITERIA_UPDATE') | |
302 frame:RegisterEvent('CRITERIA_COMPLETE') | |
303 frame:RegisterEvent('CRITERIA_EARNED') | |
304 | |
305 return t[frame.widgetType](frame) | |
306 end, | |
307 }) | |
308 | |
309 --- WidgetTemplate 'OnEvent' | |
310 mod.UpdateWidget = setmetatable({}, { | |
311 __call = function(t, frame) | |
312 if not frame.widgetType then | |
313 error('Invalid widget template, needs .widgetType') | |
314 return | |
315 end | |
316 | |
317 return t[frame.widgetType](frame) | |
318 end | |
319 }) | |
320 | |
321 --- WidgetTemplate 'OnHide' | |
322 mod.ReleaseWidget = function(frame) | |
323 local print = B.print('ObjectiveWidgets') | |
324 local reg = wr[frame.widgetType] | |
325 if reg and reg.used[frame.info.criteriaID] then | |
326 reg.used[frame.info.criteriaID] = nil | |
327 frame.info = nil | |
328 frame.parentInfo = nil | |
329 frame:UnregisterAllEvents() | |
330 tinsert(reg.free, frame) | |
331 print('|cFFBBBBBBreleased from service', frame:GetName()) | |
332 end | |
333 end | |
334 | |
335 --- RemoveTrackedAchievement post-hook | |
336 mod.CleanWidgets = function() | |
337 local print = B.print('ObjectiveWidgets') | |
338 local tracked = {GetTrackedAchievements() } | |
339 for type, reg in pairs(mod.WidgetRegistry) do | |
340 print('collecting', type) | |
341 for criteriaID, frame in pairs(reg.used) do | |
342 local id = frame.info.cheevID | |
343 | |
344 if id and not tContains(tracked, id) then | |
345 | |
346 print(' untracked achievement', id, 'associated with', criteriaID, frame:GetName()) | |
347 frame:Hide() | |
348 end | |
349 end | |
350 end | |
351 end | |
352 | |
353 mod.WidgetParams = { | |
354 ['ProgressBar'] = { | |
355 height = 20, | |
356 caption = {}, | |
357 quantityString = {SetFontObject = _G.VeneerFontNormal} | |
358 } | |
359 } | |
360 | |
361 mod.InitializeWidget.ProgressBar = function(self) | |
362 local print = B.print('ObjectiveWidgets') | |
363 local params = mod.WidgetParams[self.widgetType] | |
364 self.height = params.height | |
365 self:SetHeight(20) | |
366 self.bg:SetHeight(20) | |
367 self.fg:ClearAllPoints() | |
368 self.fg:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 2, 2) | |
369 self.fg:SetHeight(16) | |
370 self.quantityString:SetFontObject(params.quantityString.SetFontObject) | |
371 self.quantityString:SetText(self.info.quantityString) | |
372 end | |
373 | |
374 mod.UpdateWidget.ProgressBar = function (self) | |
375 local print = B.print('ObjectiveWidgets') | |
376 local quantity, requiredQuantity = self.info.quantity, self.info.requiredQuantity | |
377 | |
378 if self.info.finished then | |
379 self.fg:SetWidth(self.bg:GetWidth() - 4) | |
380 elseif quantity == 0 then | |
381 self.fg:Hide() | |
382 else | |
383 self.fg:Show() | |
384 self.fg:SetWidth((self.bg:GetWidth()-4) * (quantity / requiredQuantity)) | |
385 end | |
386 end | |
387 | |
388 | |
389 mod.InitializeWidget.Hidden = function (self) | |
390 self.height = 0 | |
391 end | |
392 mod.UpdateWidget.Hidden = function (self) | |
393 self.height= 0 | |
394 end |