You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TurnIn.lua 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. --[[
  2. Turn-In Mod
  3. version 2.3
  4. Authored by Ian Friedman
  5. Sabindeus of Terenas (Alliance)
  6. The repeatable quest turn in automating machine.
  7. Thanks to Arcanemagus of Hyjal for extra bug fixes and coding input
  8. ]]
  9. TI_VersionString = "2.0";
  10. local TI_slashtable;
  11. TI_gossipclosed = false;
  12. TI_LoadedNPCIndex = 0;
  13. TI_activenumber = 1;
  14. TI_availnumber = 1;
  15. TI_specnum = 0;
  16. TI_gossipopts = {};
  17. TI_TempNPCList = {};
  18. TI_TempNPCListMaxSize = 5;
  19. TI_NPCInQuestion = nil;
  20. local TI_GossipDefaults = {
  21. availquest ="Available Quests",
  22. activequest = "Active Quests",
  23. gossip = "Gossip",
  24. vendor = "Vendor",
  25. taxi = "Taxi",
  26. trainer = "Trainer",
  27. battlemaster = "Battlemaster",
  28. binder = "Hearthstone Binder",
  29. healer = "Spirit Healer",
  30. banker = "Bank"
  31. };
  32. local TI_DefaultStatus = {
  33. state = false,
  34. version = TI_VersionString,
  35. options = {},
  36. debugstate = false,
  37. usedefault=true,
  38. autoadd=false
  39. };
  40. local TI_events = {
  41. "GOSSIP_SHOW",
  42. "GOSSIP_CLOSED",
  43. "QUEST_DETAIL",
  44. "QUEST_COMPLETE",
  45. "QUEST_PROGRESS",
  46. "QUEST_GREETING",
  47. "QUEST_FINISHED"
  48. };
  49. local TI_GossipIconNameToId = {
  50. ["activequesticon"] = 132048,
  51. ["availablequesticon"] = 132049,
  52. ["banker"] = 132050,
  53. ["battlemaster"] = 132051,
  54. ["binder"] = 132052,
  55. ["gossip"] = 132053,
  56. ["healer"] = 132054,
  57. ["petition"] = 132055,
  58. ["tabard"] = 132056,
  59. ["taxi"] = 132057,
  60. ["trainer"] = 132058,
  61. ["unlearn"] = 132059,
  62. ["vendor"] = 132060,
  63. ["incompletequest"] = 365195,
  64. ["dailyquest"] = 368364,
  65. ["dailyactivequest"] = 368577,
  66. ["auctioneer"] = 528409,
  67. ["activelegendaryquest"] = 646979,
  68. ["availablelegendaryquest"] = 646980,
  69. ["chatbubble"] = 1019848,
  70. ["workorder"] = 1130518,
  71. ["transmogrify"] = 1673939,
  72. ["campaignactivequest"] = 3532316,
  73. ["campaignavailablequest"] = 3532317,
  74. ["campaignincompletequest"] = 3532318,
  75. ["campaigngossipicons"] = 3595324,
  76. }
  77. local function TI_InvertDictionary(input)
  78. local s={}
  79. for k,v in pairs(input) do
  80. s[v]=k
  81. end
  82. return s
  83. end
  84. local TI_GossipIconIdToName = TI_InvertDictionary(TI_GossipIconNameToId)
  85. local function TI_TranslateIconToType(iconId)
  86. return TI_GossipIconIdToName[iconId]
  87. end
  88. TI_TempNPCList = {};
  89. function TI_message(...)
  90. local x = {...};
  91. for k,v in pairs(x) do
  92. DEFAULT_CHAT_FRAME:AddMessage(tostring(v));
  93. end
  94. end
  95. function TI_debug(...)
  96. if(TI_status.debugstate) then
  97. C_AddOns.LoadAddOn("Blizzard_DebugTools")
  98. local x = {...};
  99. for k,v in pairs(x) do
  100. if type(v) == "table" and DevTools_Dump then
  101. DevTools_Dump(v)
  102. else
  103. DEFAULT_CHAT_FRAME:AddMessage(tostring(v));
  104. end
  105. end
  106. end
  107. end
  108. function TI_OnLoad()
  109. SlashCmdList["TI"]=TI_SlashCmdHandler;
  110. SLASH_TI1="/turnin";
  111. SLASH_TI2="/ti";
  112. tinsert(UISpecialFrames,"TI_OptionsFrame");
  113. TI_message("Turn In loaded");
  114. TI_slashtable = {};
  115. TI_gossipopts = {};
  116. TI_gossipclosed = false;
  117. TurnIn:RegisterEvent("VARIABLES_LOADED");
  118. TI_activenumber = 1;
  119. TI_availnumber = 1;
  120. TI_specnum = 0;
  121. StaticPopupDialogs["TI_NPCINQUESTION"] = {
  122. text = "The NPC %s is already in your NPC Database. Do you wish to replace his gossip options with the current ones? (Note: This will overwrite your settings for this NPC.)",
  123. button1 = "Yes",
  124. button2 = "No",
  125. OnAccept = function()
  126. TI_AddNPCToList(TI_NPCInQuestion.list, TI_NPCInQuestion.name, true);
  127. end,
  128. timeout=0,
  129. whileDead = 1,
  130. hideOnEscape = 1
  131. };
  132. end
  133. function TI_VarInit()
  134. if(not TI_status or TI_status.version ~= TI_VersionString) then
  135. TI_status = TI_copyTable(TI_DefaultStatus);
  136. TI_OptionsInit();
  137. end
  138. if(not TI_status.options or #TI_status.options == 0) then
  139. TI_OptionsInit();
  140. end
  141. if(not TI_NPCDB) then
  142. TI_NPCDB = {};
  143. end
  144. if(not TI_NPCIndex) then
  145. TI_NPCIndexGenerate();
  146. end
  147. TI_PopulateOptions("vars loaded");
  148. end
  149. function TI_OptionsInit()
  150. TI_status.options = {};
  151. for k,v in pairs(TI_GossipDefaults) do
  152. local temp = {};
  153. temp.name = v;
  154. temp.type = k;
  155. temp.state = false;
  156. table.insert(TI_status.options, temp);
  157. end
  158. end
  159. function TI_NPCIndexGenerate()
  160. TI_NPCIndex = {};
  161. for k,v in pairs(TI_NPCDB) do
  162. table.insert(TI_NPCIndex, k);
  163. end
  164. table.sort(TI_NPCIndex);
  165. end
  166. function TI_LoadEvents()
  167. for k,v in pairs(TI_events) do
  168. TurnIn:RegisterEvent(v);
  169. end
  170. end
  171. function TI_ResetPointers()
  172. TI_debug("resetting pointers")
  173. TI_activenumber = 1;
  174. TI_availnumber = 1;
  175. TI_specnum = 0;
  176. end
  177. function TI_UnloadEvents()
  178. for k,v in pairs(TI_events) do
  179. TurnIn:UnregisterEvent(v);
  180. end
  181. end
  182. function TI_Switch(state)
  183. if(state=="on") then
  184. TI_status.state = true;
  185. TI_LoadEvents();
  186. TI_message("Turn In On");
  187. elseif(state=="off") then
  188. TI_ResetPointers();
  189. TI_status.state = false;
  190. TI_UnloadEvents();
  191. TI_message("Turn In Off");
  192. elseif(state=="toggle") then
  193. if(TI_status.state) then
  194. TI_Switch("off");
  195. else
  196. TI_Switch("on");
  197. end
  198. end
  199. TI_StatusIndicatorUpdate();
  200. end
  201. function TI_SlashCmdHandler(cmd)
  202. cmdlist = {strsplit(" ", cmd)};
  203. local commands = {
  204. on = function ()
  205. TI_Switch("on");
  206. end,
  207. off = function ()
  208. TI_Switch("off");
  209. end,
  210. toggle = function ()
  211. TI_Switch("toggle");
  212. end,
  213. status = function ()
  214. if(TI_status.state) then
  215. TI_message("Turn In On");
  216. else
  217. TI_message("Turn In Off");
  218. end
  219. end,
  220. window = function ()
  221. TI_OptionsFrame:Show();
  222. end,
  223. config = function ()
  224. TI_OptionsFrame:Show();
  225. end,
  226. recent = function ()
  227. TI_TempNPCListWindow:Show();
  228. end,
  229. debug = function ()
  230. if(TI_status.debugstate) then
  231. TI_status.debugstate = false;
  232. TI_message("debug mode off");
  233. else
  234. TI_status.debugstate = true;
  235. TI_message("debug mode on");
  236. end
  237. end
  238. };
  239. if(commands[cmdlist[1]]) then
  240. commands[cmdlist[1]](cmdlist[2], cmdlist[3], cmdlist[4]);
  241. else
  242. TI_message("Turn In 2.1 Help", "--------------", "/ti on - turns Turn In on", "/ti off - turns Turn In off", "/ti toggle - toggles Turn In on or off", "/ti window - shows the options window", "/ti recent - shows the recently visited NPCs");
  243. end
  244. end
  245. function TI_IsNPCOn(npcname, type)
  246. local opton = false;
  247. if(type ~= nil) then
  248. for k,v in pairs(TI_status.options) do
  249. if(v.type == type and v.state == true) then
  250. opton = true;
  251. end
  252. end
  253. else
  254. opton = true;
  255. end
  256. if(TI_NPCDB[npcname] == nil and TI_status.usedefault == true and opton == true) then
  257. TI_debug("case 1");
  258. return true;
  259. elseif(TI_NPCDB[npcname] ~= nil and TI_NPCDB[npcname].state) then
  260. TI_debug("case 2");
  261. return true;
  262. elseif(TI_NPCDB[npcname] ~= nil and TI_status.usedefault == true and not TI_NPCDB[npcname].state and opton == true) then
  263. TI_debug("case 4");
  264. return true;
  265. else
  266. TI_debug("case 3");
  267. return false;
  268. end
  269. end
  270. function TI_OnEvent(self, event, ...)
  271. if(event == "VARIABLES_LOADED") then
  272. TI_VarInit();
  273. if(TI_status.state) then
  274. TI_LoadEvents();
  275. end
  276. end
  277. if(TI_status.state and not IsShiftKeyDown()) then
  278. if(event == "QUEST_GREETING") then
  279. TI_debug("Quest Greeting");
  280. TI_lastquestframe = "greeting";
  281. if(QuestFrame:IsVisible()) then
  282. if(TI_gossipclosed) then
  283. TI_debug("resetting pointers");
  284. TI_gossipclosed = false;
  285. TI_ResetPointers();
  286. end
  287. TI_HandleGossipWindow("q");
  288. end
  289. end
  290. if(event == "GOSSIP_SHOW") then
  291. TI_debug("Gossip Show");
  292. if(GossipFrame:IsVisible()) then
  293. if(TI_gossipclosed) then
  294. TI_debug("resetting pointers");
  295. TI_gossipclosed = false;
  296. TI_ResetPointers();
  297. end
  298. TI_HandleGossipWindow("g");
  299. end
  300. end
  301. if(event == "GOSSIP_CLOSED") then
  302. TI_debug("Gossip Closed");
  303. if(not GossipFrame:IsVisible()) then
  304. TI_gossipclosed = true;
  305. end;
  306. end
  307. if(event == "QUEST_COMPLETE") then
  308. TI_debug("Quest Complete");
  309. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  310. if(not (GetNumQuestChoices() > 1)) then
  311. GetQuestReward(1);
  312. end
  313. end
  314. TI_ResetPointers();
  315. end
  316. if(event == "QUEST_PROGRESS") then
  317. TI_debug("Quest Progress");
  318. TI_gossipclosed = false;
  319. TI_lastquestframe = "progress";
  320. TI_HandleQuestProgress();
  321. end
  322. if(event == "QUEST_DETAIL") then
  323. TI_debug("Quest Detail");
  324. TI_gossipclosed = false;
  325. if(TI_IsNPCOn(UnitName("npc"), "availquest")) then
  326. TI_HandleAcceptQuest();
  327. end
  328. TI_ResetPointers();
  329. end
  330. if(event == "QUEST_FINISHED") then
  331. TI_debug("Quest Finished");
  332. if(not QuestFrame:IsVisible() and TI_lastquestframe == "greeting") then
  333. TI_debug("looks like the quest frame closed, resetting pointers on next open");
  334. TI_gossipclosed = true;
  335. end
  336. end
  337. end
  338. end
  339. function TI_HandleAcceptQuest()
  340. --QuestInfoFadingFrame_OnUpdate(QuestInfoFadingFrame, 1); -- does not exist anymore in 6.0
  341. QuestDetailAcceptButton_OnClick();
  342. end
  343. function TI_HandleQuestProgress()
  344. local questname = GetTitleText();
  345. local npcname = UnitName("npc");
  346. if(QuestFrame:IsVisible()) then
  347. if(TI_NPCDB[npcname]) then
  348. local thisnpc = TI_NPCDB[npcname];
  349. if(thisnpc.state) then
  350. for i,current in ipairs(thisnpc) do
  351. if(current.name == questname and current.state) then
  352. TI_CompleteQuest();
  353. end
  354. end
  355. else
  356. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  357. TI_CompleteQuest();
  358. end
  359. end
  360. else
  361. if(TI_IsNPCOn(UnitName("npc"), "activequest")) then
  362. TI_CompleteQuest();
  363. end
  364. end
  365. end
  366. end
  367. function TI_CompleteQuest()
  368. if(IsQuestCompletable()) then
  369. TI_debug("quest is completable, completeing");
  370. CompleteQuest();
  371. TI_ResetPointers();
  372. else
  373. TI_debug("quest is not completable, declining");
  374. TI_availnumber = TI_availnumber + 1;
  375. QuestDetailDeclineButton_OnClick();
  376. end
  377. end
  378. function TI_GetQuests(type)
  379. local numQuests = (getglobal("GetNum"..type.."Quests"))();
  380. local qfn = getglobal("Get"..type.."Title");
  381. local ret = {};
  382. local i=1;
  383. for i=1,numQuests do
  384. local qname, isComplete = qfn(i);
  385. ret[i] = {name=qname, questID=i, isComplete=isComplete};
  386. end
  387. return ret;
  388. end
  389. function TI_HandleGossipWindow(gorq)
  390. local SAcQ;
  391. local SAvQ;
  392. local AvailableQuests;
  393. local ActiveQuests;
  394. local GossipOptions;
  395. TI_debug(gorq);
  396. if(gorq == "g") then
  397. AvailableQuests = TI_FunctionList.g.tabulateAvailable(TI_FunctionList.g.getavailquests());
  398. ActiveQuests = TI_FunctionList.g.tabulateActive(TI_FunctionList.g.getactivequests());
  399. GossipOptions = TI_FunctionList.g.tabulateOptions(TI_FunctionList.g.getoptions());
  400. SAcQ = TI_FunctionList.g.activequest;
  401. SAvQ = TI_FunctionList.g.availquest;
  402. elseif(gorq == "q") then
  403. AvailableQuests = TI_GetQuests("Available");
  404. ActiveQuests = TI_GetQuests("Active");
  405. GossipOptions = {};
  406. SAcQ=TI_FunctionList.q.activequest;
  407. SAvQ=TI_FunctionList.q.availquest;
  408. end
  409. local ListEntry = {};
  410. for i,v in ipairs(AvailableQuests) do
  411. local x={};
  412. x.name = v.name;
  413. x.gorq = gorq;
  414. x.args = i;
  415. x.type = "availquest";
  416. x.icon = v.icon;
  417. x.state = false;
  418. table.insert(ListEntry, x);
  419. end
  420. for i,v in ipairs(ActiveQuests) do
  421. local x={};
  422. x.name = v.name;
  423. x.gorq = gorq;
  424. x.args = i;
  425. x.type = "activequest";
  426. x.icon = v.icon;
  427. x.state = false;
  428. table.insert(ListEntry, x);
  429. end
  430. for i,v in ipairs(GossipOptions) do
  431. local x={};
  432. x.name = v.name;
  433. x.gorq = gorq;
  434. if x.orderIndex then
  435. x.args = v.orderIndex;
  436. else
  437. x.args = i;
  438. end
  439. x.type = v.type;
  440. x.icon = v.icon;
  441. x.state = false;
  442. table.insert(ListEntry, x);
  443. end
  444. ListEntry.state = false;
  445. local TotalOptions = #AvailableQuests+#ActiveQuests+#GossipOptions;
  446. if(TotalOptions < 1) then
  447. return;
  448. end
  449. local npcname = UnitName("npc");
  450. TI_AddNPCToTempList(npcname, ListEntry);
  451. if(TI_status.autoadd and (not TI_NPCDB[npcname])) then
  452. TI_debug("autoadd on, adding this NPC", TI_status.autoadd, TI_NPCDB[npcname]);
  453. TI_AddNPCToList(ListEntry, npcname);
  454. end
  455. -- If a NPC is in the Database but a new dialog option has appeared (new daily/completed quest) then add it to the DB
  456. if (TI_NPCDB[npcname]) then
  457. for k1, v1 in ipairs(ListEntry) do
  458. local found = false;
  459. for k2, v2 in ipairs(TI_NPCDB[npcname]) do
  460. if (v2.type == v1.type and v2.name == v1.name) then
  461. found = true;
  462. end
  463. end
  464. if (not found) then
  465. table.insert(TI_NPCDB[npcname], v1)
  466. TI_PopulateOptions("npclist updated");
  467. end
  468. end
  469. end
  470. if(TI_availnumber > TotalOptions or TI_activenumber > TotalOptions) then
  471. TI_debug("Out of available/active quests, giving up ");
  472. TI_ResetPointers();
  473. return;
  474. end
  475. TI_debug(npcname);
  476. if(TI_NPCDB[npcname]) then
  477. local thisnpc = TI_NPCDB[npcname];
  478. if(thisnpc.state) then
  479. TI_debug("npc is active, using his options");
  480. for i1,current in ipairs(thisnpc) do
  481. if (current.state == true) then
  482. TI_debug("Current Quest: "..current.name);
  483. if (TI_specnum == 0 or i1 > TI_specnum) then
  484. TI_specnum = i1;
  485. if (current.type == "availquest") then
  486. for i2,v2 in ipairs(AvailableQuests) do
  487. if (v2.name == current.name) then
  488. TI_debug(i1.."-Available Match Found: "..current.name);
  489. SAvQ(v2.questID);
  490. return;
  491. end
  492. end
  493. elseif (current.type == "activequest") then
  494. for i2,v2 in ipairs(ActiveQuests) do
  495. if (v2.name == current.name) then
  496. TI_debug(i1.."-Active Match Found: "..current.name..", "..current.type);
  497. SAcQ(v2.questID);
  498. return;
  499. end
  500. end
  501. else
  502. for i2,v2 in ipairs(GossipOptions) do
  503. if (v2.name == current.name) then
  504. TI_debug(i1.."-Gossip Match Found: "..current.name..", "..current.type);
  505. if(v2.args) then
  506. TI_FunctionList.g.gossip(v2.args);
  507. else
  508. TI_FunctionList.g.gossip(i2);
  509. end
  510. return;
  511. end
  512. end
  513. end
  514. end
  515. end
  516. end
  517. return;
  518. else
  519. TI_debug("npc in list, but not active");
  520. end
  521. else
  522. TI_debug("npc not in list");
  523. end
  524. if(TI_status.usedefault == false) then
  525. TI_debug("npc not in list, default set to off, returning.");
  526. return;
  527. end;
  528. TI_debug("using default config");
  529. for i,current in ipairs(TI_status.options) do
  530. if(current.state) then
  531. if(current.type == "availquest" and #AvailableQuests > 0 and TI_availnumber <= #AvailableQuests) then
  532. SAvQ(AvailableQuests[TI_availnumber].questID);
  533. TI_debug("Selecting Available Quest ".. TI_availnumber);
  534. return;
  535. elseif(current.type == "activequest" and #ActiveQuests > 0 and TI_activenumber <= #ActiveQuests) then
  536. while TI_activenumber <= #ActiveQuests do
  537. if ActiveQuests[TI_activenumber].isComplete then
  538. TI_debug("Selecting Active Quest ".. TI_activenumber .. " " .. ActiveQuests[TI_activenumber].name );
  539. SAcQ(ActiveQuests[TI_activenumber].questID);
  540. TI_ResetPointers();
  541. return;
  542. else
  543. TI_debug("Active Quest ".. TI_activenumber .. " " .. ActiveQuests[TI_activenumber].name .. " is not complete")
  544. TI_activenumber = TI_activenumber + 1;
  545. end
  546. end
  547. elseif(#GossipOptions > 0) then
  548. for j,val in ipairs(GossipOptions) do
  549. if(val.type == current.type) then
  550. TI_ResetPointers();
  551. TI_debug("Selecting Gossip Option "..j)
  552. TI_FunctionList.g.gossip(val.args);
  553. return;
  554. end
  555. end
  556. end
  557. end
  558. end
  559. end
  560. function TI_AddNPCToList(OptList, npcname, confirminquestion)
  561. if (npcname == nil) then
  562. npcname = UnitName("npc");
  563. end
  564. if(#OptList > 0) then
  565. if(TI_NPCDB[npcname] == nil) then
  566. TI_NPCDB[npcname] = TI_copyTable(OptList);
  567. table.insert(TI_NPCIndex, npcname);
  568. table.sort(TI_NPCIndex);
  569. TI_PopulateOptions("npclist updated");
  570. elseif(confirminquestion == true) then
  571. TI_NPCDB[npcname] = TI_copyTable(OptList);
  572. TI_PopulateOptions("npclist updated");
  573. else
  574. TI_NPCInQuestion = {name=npcname, list=OptList};
  575. StaticPopup_Show("TI_NPCINQUESTION", npcname);
  576. end
  577. end
  578. end
  579. function TI_AddNPCToTempList(name, list)
  580. local temp = {};
  581. temp.name = name;
  582. temp.list = list;
  583. local subZone = GetSubZoneText();
  584. local realZone = GetRealZoneText();
  585. if(subZone == "") then
  586. temp.location = realZone;
  587. else
  588. temp.location = subZone .. ", " .. realZone;
  589. end
  590. table.insert(TI_TempNPCList, 1, temp);
  591. if(#TI_TempNPCList > TI_TempNPCListMaxSize) then
  592. table.remove(TI_TempNPCList, TI_TempNPCListMaxSize);
  593. end
  594. TI_TempNPCListUpdate();
  595. end
  596. function TI_DeleteTempNPCIndex(index)
  597. table.remove(TI_TempNPCList, index);
  598. TI_TempNPCListUpdate();
  599. end
  600. function TI_AddTempNPCIndex(index)
  601. TI_AddNPCToList(TI_TempNPCList[index].list, TI_TempNPCList[index].name);
  602. end
  603. function TI_DeleteNPC(index)
  604. local name = TI_NPCIndex[index];
  605. table.remove(TI_NPCIndex, index);
  606. TI_NPCDB[name] = nil;
  607. end
  608. function TI_StripDescriptors(...)
  609. local x = {};
  610. local arg = {...};
  611. for i=1, #arg, 2 do
  612. table.insert(x,arg[i]);
  613. end
  614. return x;
  615. end
  616. function TI_TabulateGossipQuestUIInfo(gquis)
  617. local x = {};
  618. for i,gqui in ipairs(gquis) do
  619. local temp = {};
  620. temp.name = gqui.title;
  621. temp.icon = QuestUtil.GetQuestIconOffer(
  622. gqui.isLegendary,
  623. gqui.frequency,
  624. gqui.isRepeatable,
  625. false,
  626. false
  627. );
  628. temp.questID = gqui.questID;
  629. temp.isComplete = gqui.isComplete;
  630. table.insert(x, temp);
  631. end
  632. return x;
  633. end
  634. function TI_TabulateGossipUIInfo(guis)
  635. local x = {};
  636. table.sort(guis, GossipOptionSort);
  637. for i,gui in ipairs(guis) do
  638. local temp = {};
  639. temp.name = gui.name;
  640. local gossipType = TI_TranslateIconToType(gui.icon)
  641. if gossipType == "chatbubble" then
  642. gossipType = "gossip"
  643. end
  644. temp.type = gossipType;
  645. temp.icon = gui.icon;
  646. temp.gossipOptionID = gui.gossipOptionID
  647. temp.orderIndex = gui.orderIndex
  648. temp.args = gui.orderIndex
  649. table.insert(x, temp);
  650. end
  651. return x;
  652. end
  653. function TI_TabulateGossipAvailableQuests_Classic(gquis)
  654. local x = {};
  655. for i,gqui in ipairs(gquis) do
  656. local temp = {};
  657. temp.name = gqui.title;
  658. if ( gqui.repeatable ) then
  659. temp.icon = "Interface\\GossipFrame\\DailyQuestIcon";
  660. elseif ( gqui.isLegendary ) then
  661. temp.icon = "Interface\\GossipFrame\\AvailableLegendaryQuestIcon";
  662. else
  663. temp.icon = "Interface\\GossipFrame\\AvailableQuestIcon";
  664. end
  665. temp.questID = gqui.questID;
  666. temp.isComplete = gqui.isComplete;
  667. table.insert(x, temp);
  668. end
  669. return x;
  670. end
  671. function TI_TabulateGossipActiveQuests_Classic(gquis)
  672. local x = {};
  673. for i,gqui in ipairs(gquis) do
  674. local temp = {};
  675. temp.name = gqui.title;
  676. if ( gqui.repeatable ) then
  677. temp.icon = "Interface\\GossipFrame\\DailyQuestIcon";
  678. elseif ( gqui.isLegendary ) then
  679. temp.icon = "Interface\\GossipFrame\\AvailableLegendaryQuestIcon";
  680. else
  681. temp.icon = "Interface\\GossipFrame\\AvailableQuestIcon";
  682. end
  683. temp.questID = gqui.questID;
  684. temp.isComplete = gqui.isComplete;
  685. table.insert(x, temp);
  686. end
  687. return x;
  688. end
  689. TI_FunctionList = {}
  690. function TI_SetupFunctions()
  691. TI_FunctionList = {
  692. g = {
  693. availquest = C_GossipInfo.SelectAvailableQuest,
  694. activequest = C_GossipInfo.SelectActiveQuest,
  695. gossip = C_GossipInfo.SelectOptionByIndex,
  696. getavailquests = C_GossipInfo.GetAvailableQuests,
  697. getactivequests = C_GossipInfo.GetActiveQuests,
  698. getoptions = C_GossipInfo.GetOptions,
  699. tabulateOptions = TI_TabulateGossipUIInfo,
  700. },
  701. q = {
  702. activequest = SelectActiveQuest,
  703. availquest = SelectAvailableQuest,
  704. }
  705. }
  706. if QuestUtil.GetQuestIconOffer then
  707. TI_FunctionList.g.tabulateAvailable = TI_TabulateGossipQuestUIInfo
  708. TI_FunctionList.g.tabulateActive = TI_TabulateGossipQuestUIInfo
  709. else
  710. TI_FunctionList.g.tabulateAvailable = TI_TabulateGossipAvailableQuests_Classic
  711. TI_FunctionList.g.tabulateActive = TI_TabulateGossipActiveQuests_Classic
  712. end
  713. end
  714. TI_SetupFunctions()
  715. function TI_copyTable( src )
  716. local copy = {}
  717. for k1,v1 in pairs(src) do
  718. if ( type(v1) == "table" ) then
  719. copy[k1]=TI_copyTable(v1)
  720. else
  721. copy[k1]=v1
  722. end
  723. end
  724. return copy
  725. end
  726. function toggle(arg)
  727. if(arg) then
  728. return false;
  729. else
  730. return true;
  731. end
  732. end