vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 -- Sea.wow.questLog
3 -- Basic Quest Log Functions
4 --
5 -- $LastChangedBy: Miravlix $
6 -- $Rev: 3231 $
7 -- $Date: 2006-03-26 00:30:16 -0600 (Sun, 26 Mar 2006) $
8 --]]
9  
10 Sea.wow.questLog = {
11 -- Quest Log Max
12 QUESTLOG_MAX = 20;
13  
14 -- Protection Data
15 ProtectionData = {};
16  
17 --
18 -- storeCollapsedQuests
19 --
20 -- Stores the currently collapsed quests and returns them
21 --
22 -- Returns:
23 -- (table quests)
24 -- quests - a list containing the title of the collapsed quests
25 --
26 storeCollapsedQuests = function ()
27 local collapsed = {};
28 for i=1, Sea.wow.questLog.QUESTLOG_MAX do
29 local title, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(i);
30 if ( isCollapsed ) then
31 table.insert(collapsed, title);
32 end
33 end
34  
35 return collapsed;
36 end;
37  
38 --
39 -- collapseStoredQuests (collapseTitles)
40 -- Collapses all quests whose titles are in the list
41 --
42 -- Args:
43 -- (table collapseTitles)
44 -- collapseTitles - the titles which will be collapsed
45 --
46 -- Returns:
47 -- nil
48 --
49 collapseStoredQuests = function (collapseThese)
50 for i=1, Sea.wow.questLog.QUESTLOG_MAX do
51 local title, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(i);
52 if ( Sea.list.isInList(collapseThese, title) ) then
53 CollapseQuestHeader(i);
54 end
55 end
56 end;
57  
58  
59 --
60 -- protectQuestLog()
61 -- Preserves the quest log state.
62 -- Don't forget to call unprotectQuestLog()
63 -- after modifying the log.
64 --
65 -- This will return false if someone else
66 -- has protected the quest log and
67 -- not unprotected it yet.
68 --
69 -- Args:
70 -- none
71 -- Returns:
72 -- true - the log was protected
73 -- false - someone else is modifying the log now
74 --
75 protectQuestLog = function ()
76 if ( Sea.wow.questLog.ProtectionData.protected ) then
77 return nil;
78 end
79  
80 -- Store the protected state
81 Sea.wow.questLog.ProtectionData.protected = true;
82  
83 -- Store the event
84 Sea.wow.questLog.ProtectionData.ql_OnEvent = QuestLog_OnEvent;
85 QuestLog_OnEvent = function() end;
86  
87 -- Store the collapsed
88 Sea.wow.questLog.ProtectionData.collapsed = Sea.wow.questLog.storeCollapsedQuests();
89  
90 -- Store the selection
91 Sea.wow.questLog.ProtectionData.savedID = GetQuestLogSelection();
92  
93 -- Store the scroll bar position
94 Sea.wow.questLog.ProtectionData.savedScrollBar = FauxScrollFrame_GetOffset(QuestLogListScrollFrame);
95 Sea.wow.questLog.ProtectionData.savedValue = QuestLogListScrollFrameScrollBar:GetValue()
96  
97 return true;
98 end;
99  
100 --
101 -- unprotectQuestLog()
102 -- Restores the state of the quest log.
103 -- Useful if you're going to mess with the
104 -- quest log in order to get info out, and
105 -- don't want the user to notice.
106 --
107 -- Args:
108 -- none
109 -- Returns:
110 -- nil
111 --
112 unprotectQuestLog = function ()
113 -- Collapse again
114 Sea.wow.questLog.collapseStoredQuests(Sea.wow.questLog.ProtectionData.collapsed);
115  
116 -- Restore the scroll bar position
117 FauxScrollFrame_SetOffset(QuestLogListScrollFrame,Sea.wow.questLog.ProtectionData.savedScrollBar)
118 QuestLogListScrollFrameScrollBar:SetValue( Sea.wow.questLog.ProtectionData.savedValue )
119  
120 -- Restore the selection
121 SelectQuestLogEntry(Sea.wow.questLog.ProtectionData.savedID);
122  
123 -- Restore the event
124 QuestLog_OnEvent = Sea.wow.questLog.ProtectionData.ql_OnEvent;
125 Sea.wow.questLog.ProtectionData.ql_OnEvent = nil;
126  
127 -- Unprotect
128 Sea.wow.questLog.ProtectionData.protected = false;
129 end;
130  
131 --
132 -- getPlayerQuestTree()
133 -- Returns a formatted table containing all of
134 -- the quests the player currently has.
135 --
136 -- Returns:
137 --
138 -- questTree - list of zones
139 -- {
140 -- ["zone name"] - list of quests
141 -- {
142 -- {
143 -- flatid - (string) id when fully expanded
144 -- title - (string) quest title
145 -- level - (number) quest level
146 -- tag - (string) Elite or Raid
147 -- complete - (boolean) is quest completed
148 -- }
149 -- }
150 -- }
151 --
152 getPlayerQuestTree = function()
153 if ( not Sea.wow.questLog.protectQuestLog() ) then
154 return nil;
155 end
156  
157 -- Expand everything
158 ExpandQuestHeader(0);
159  
160 -- Build our quest list
161 local numEntries, numQuests = GetNumQuestLogEntries();
162  
163 local questList = {};
164 local activeTable = nil;
165  
166 for i=1, Sea.wow.questLog.QUESTLOG_MAX + numEntries, 1 do
167 local questIndex = i;
168 if ( questIndex <= numEntries ) then
169 local title, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questIndex);
170 local color;
171 if ( title ) then
172 if ( isHeader ) then
173 questList[title] = {};
174 activeTable = questList[title];
175 else
176 if ( activeTable == nil ) then
177 activeTable = questList;
178 end
179  
180 local entry = {};
181 entry.id = i;
182 entry.flatid = i;
183 entry.title = title;
184 entry.level = level;
185 entry.tag = questTag;
186 entry.complete = isComplete;
187  
188 table.insert(activeTable, entry);
189 end
190 end
191 end
192 end
193  
194 -- Unprotect
195 Sea.wow.questLog.unprotectQuestLog();
196  
197 return questList;
198  
199 end;
200  
201 --
202 -- getPlayerQuestTreeFlat()
203 -- Returns a flat table containing all of
204 -- the quests the player currently has.
205 --
206 -- Returns:
207 --
208 -- questTree - table of quests, the key in this table equals id
209 -- {
210 -- {
211 -- id - (string) id when fully expanded
212 -- title - (string) quest title
213 -- level - (number) quest level
214 -- tag - (string) Elite or Raid
215 -- complete - (boolean) is quest completed
216 -- zone - (string) collapsable header name
217 -- }
218 -- }
219 --
220 getPlayerQuestTreeFlat = function()
221 if ( not Sea.wow.questLog.protectQuestLog() ) then
222 return nil;
223 end
224  
225 -- Expand everything
226 ExpandQuestHeader(0);
227  
228 -- Build our quest list
229 local numEntries = GetNumQuestLogEntries();
230  
231 local questList = {};
232 local currentZone;
233  
234 for questIndex=1, numEntries, 1 do
235 local title, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questIndex);
236 if ( title ) then
237 if ( isHeader ) then
238 currentZone = title;
239 else
240 local entry =
241 {
242 id = questIndex;
243 title = title;
244 level = level;
245 tag = questTag;
246 complete = isComplete;
247 zone = currentZone
248 };
249  
250 questList[questIndex] = entry;
251 end
252 end
253 end
254  
255 -- Unprotect
256 Sea.wow.questLog.unprotectQuestLog();
257  
258 return questList;
259 end;
260  
261 --
262 --
263 -- convertPlayerQuestTreeFromFlatToNormal()
264 -- Converts output of getPlayerQuestTreeFlat to format of
265 -- output of getPlayerQuestTree. It's shallow copy: doesn't
266 -- copy actual quest entries, just reference them.
267 --
268 -- Args:
269 -- tree - table of quests as returned by getPlayerQuestTreeFlat
270 --
271 -- Returns:
272 --
273 -- See getPlayerQuestTree.
274 --
275 convertPlayerQuestTreeFromFlatToNormal = function(tree)
276 if not tree then
277 return;
278 end
279 local currentZone;
280 local result = {};
281 for k,v in tree do
282 if v.zone ~= currentZone then
283 currentZone = v.zone;
284  
285 if result[currentZone] == nil then -- Only Zap when NIL!
286 result[currentZone] = {};
287 end
288 end
289 v.flatid = v.id;
290 table.insert(result[currentZone], v);
291 end
292 return result;
293 end;
294  
295 --
296 -- getPlayerQuestData ( number id )
297 --
298 -- Returns a formatted table containing the quest's information
299 -- If you specify its id when the table is flat.
300 --
301 -- Args:
302 -- id - flattened (expanded) id of the quest
303 --
304 -- Returns:
305 -- questData - (table)
306 -- {
307 -- id - flattened id (number)
308 -- title - quest title (string)
309 -- level - quest level (number)
310 -- tag - quest tag (string)
311 -- failed - (boolean)
312 -- pushable - (boolean)
313 -- timer - (number)
314 -- description - full description text (string)
315 -- objective - objective text (string)
316 -- objectives - objective status (table)
317 -- {
318 -- text - description (string)
319 -- questType - monster, reputation or item (string)
320 -- finished - (boolean)
321 -- info - status information (table)
322 -- {
323 -- name - monster/item/faction name
324 -- done - number - number obtained or killed
325 -- - string - faction achieved
326 -- total - number - amount needed
327 -- - string - faction required
328 -- }
329 -- }
330 -- choices - choices of items (table)
331 -- {
332 -- name - item name
333 -- texture - item texture
334 -- numItems - count of items (number)
335 -- quality - item quality (number)
336 -- isUsable - (boolean)
337 -- info - link information (table)
338 -- {
339 -- color - color string (string)
340 -- link - item link (string)
341 -- linkname - [Item of Power] (string)
342 -- }
343 -- }
344 -- rewards - items always recieved (table)
345 -- {
346 -- name - item name
347 -- texture - item texture
348 -- numItems - count of items (number)
349 -- quality - item quality (number)
350 -- isUsable - (boolean)
351 -- info - link information (table)
352 -- {
353 -- color - color string (string)
354 -- link - item link (string)
355 -- linkname - [Item of Power] (string)
356 -- }
357 -- }
358 -- spellReward - the spell given to you after the quest (table)
359 -- {
360 -- name - spell name (string)
361 -- texture - spell texture (string)
362 -- }
363 -- }
364 --
365 getPlayerQuestData = function ( id )
366 if ( not Sea.wow.questLog.protectQuestLog() ) then
367 return false;
368 end
369  
370 if ( not id ) then
371 -- Unprotect
372 Sea.wow.questLog.unprotectQuestLog();
373 return nil;
374 end
375  
376 local questInfo = {};
377  
378 -- Expand everything
379 ExpandQuestHeader(0);
380  
381 -- Select it
382 SelectQuestLogEntry(id);
383  
384 questInfo.id = id;
385 questInfo.title, questInfo.level, questInfo.tag = GetQuestLogTitle(id);
386 questInfo.failed = IsCurrentQuestFailed();
387 questInfo.description, questInfo.objective = GetQuestLogQuestText();
388 questInfo.pushable = GetQuestLogPushable();
389 questInfo.timer = GetQuestLogTimeLeft();
390  
391 questInfo.objectives = {};
392  
393 for i=1, GetNumQuestLeaderBoards(), 1 do
394 local item = {};
395  
396 item.text, item.questType, item.finished = GetQuestLogLeaderBoard(i);
397  
398 if ( item.questType == "item" ) then
399 local realGlobal = QUEST_ITEMS_NEEDED;
400 QUEST_ITEMS_NEEDED = "%s:%d:%d";
401 local info = Sea.string.split(GetQuestLogLeaderBoard(i),":");
402 QUEST_ITEMS_NEEDED = realGlobal;
403  
404 item.info = {};
405 item.info.name = info[1];
406 item.info.done = tonumber(info[2]);
407 item.info.total = tonumber(info[3]);
408 elseif ( item.questType == "monster" ) then
409 local realGlobal = QUEST_MONSTERS_KILLED;
410 QUEST_MONSTERS_KILLED = "%s:%d:%d";
411 local info = Sea.string.split(GetQuestLogLeaderBoard(i),":");
412 QUEST_MONSTERS_KILLED = realGlobal;
413  
414 item.info = {};
415 item.info.name = info[1];
416 item.info.done = tonumber(info[2]);
417 item.info.total = tonumber(info[3]);
418 elseif ( item.questType == "reputation" ) then
419 local realGlobal = QUEST_FACTION_NEEDED;
420 QUEST_FACTION_NEEDED = "%s:%s:%s";
421 local info = Sea.string.split(GetQuestLogLeaderBoard(i),":");
422 QUEST_FACTION_NEEDED = realGlobal;
423  
424 item.info = {};
425 item.info.name = info[1];
426 item.info.done = info[2];
427 item.info.total = info[3];
428 end
429 table.insert(questInfo.objectives, item);
430 end
431  
432 if ( GetQuestLogRequiredMoney() > 0 ) then
433 questInfo.requiredMoney = GetQuestLogRequiredMoney();
434 end
435 questInfo.rewardMoney = GetQuestLogRewardMoney();
436  
437 questInfo.rewards = {};
438 questInfo.choices = {};
439  
440 for i=1, GetNumQuestLogChoices(), 1 do
441 local item = {};
442 item.name, item.texture, item.numItems, item.quality, item.isUsable = GetQuestLogChoiceInfo(i);
443  
444 local info = GetQuestLogItemLink("choice", i );
445 if ( info ) then
446 item.info = {};
447 item.info.color = string.gsub(info, "|c(.*)|H(.*)|h(.*)|h|r.*", "%1");
448 item.info.link = string.gsub(info, "|c(.*)|H(.*)|h(.*)|h|r.*", "%2");
449 item.info.linkname = string.gsub(info, "|c(.*)|H(.*)|h(.*)|h|r.*", "%3");
450 end
451 table.insert(questInfo.choices, item);
452 end
453 for i=1, GetNumQuestLogRewards(), 1 do
454 local item = {};
455 item.name, item.texture, item.numItems, item.quality, item.isUsable = GetQuestLogRewardInfo(i);
456  
457 local info = GetQuestLogItemLink("reward", i );
458 if ( info ) then
459 item.info = {};
460 item.info.color = string.gsub(info, "|c(.*)|H(.*)|h(.*)|h|r.*", "%1");
461 item.info.link = string.gsub(info, "|c(.*)|H(.*)|h(.*)|h|r.*", "%2");
462 item.info.linkname = string.gsub(info, "|c(.*)|H(.*)|h(.*)|h|r.*", "%3");
463 end
464  
465 table.insert(questInfo.rewards, item);
466 end
467  
468 if ( GetRewardSpell() ) then
469 questInfo.spellReward={};
470 questInfo.spellReward.texture, questInfo.spellReward.name = GetQuestLogRewardSpell();
471 end
472  
473 -- Unprotect
474 Sea.wow.questLog.unprotectQuestLog();
475  
476 return questInfo;
477 end;
478 };