Advertisement
Yakumile

NEWQuestiebug

Apr 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.03 KB | None | 0 0
  1. local function log(msg) DEFAULT_CHAT_FRAME:AddMessage(msg) end -- alias for convenience
  2.  
  3. QuestieTracker = CreateFrame("Frame", "QuestieTracker", UIParent, "ActionButtonTemplate")
  4.  
  5. function QuestieTracker:OnEvent() -- functions created in "object:method"-style have an implicit first parameter of "this", which points to object || in 1.12 parsing arguments as ... doesn't work
  6. QuestieTracker[event](QuestieTracker, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) -- route event parameters to Questie:event methods
  7. end
  8.  
  9. QuestieTracker.hasCleared = false
  10. QuestieTracker.lastUpdate = 0;
  11.  
  12. function QuestieTracker_OnUpdate()
  13. --ChatFrame3:Clear();
  14. --for k,v in pairs(QuestieTrackedQuests) do
  15. -- if type(v) == "table" then
  16. -- local nam = "NILLWTF";
  17. -- local extr = " [N]";
  18. -- if v['rend'] then
  19. -- extr = " [Y]";
  20. -- end
  21. -- if QuestieHashMap[k] then
  22. -- nam = QuestieHashMap[k]['name'];
  23. -- end
  24. -- ChatFrame3:AddMessage(k .. ": " .. nam .. extr);
  25. -- end
  26. --end
  27. --ChatFrame4:Clear();
  28. --for k,v in pairs(QuestieHandledQuests) do
  29. -- ChatFrame4:AddMessage(k .. ": " .. QuestieHashMap[k]['name']);
  30. --end
  31. if(EQL3_QuestWatchFrame) then
  32. EQL3_QuestWatchFrame:Hide();
  33. end
  34. if GetTime() - QuestieTracker.lastUpdate >= 1 then
  35. QuestieTracker:fillTrackingFrame()
  36. QuestieTracker.lastUpdate = GetTime()
  37. end
  38. end
  39.  
  40. QuestieTracker:SetScript("OnEvent", QuestieTracker.OnEvent)
  41. QuestieTracker:SetScript("OnUpdate", QuestieTracker_OnUpdate)
  42. QuestieTracker:RegisterEvent("PLAYER_LOGIN")
  43. QuestieTracker:RegisterEvent("ADDON_LOADED")
  44.  
  45.  
  46. local _QuestWatch_Update = QuestWatch_Update;
  47. local _RemoveQuestWatch = RemoveQuestWatch;
  48. local _IsQuestWatched = IsQuestWatched;
  49. local _GetNumQuestWatches = GetNumQuestWatches;
  50. local _AddQuestWatch = AddQuestWatch;
  51. local _GetQuestIndexForWatch = GetQuestIndexForWatch;
  52. local _QuestLogTitleButton_OnClick = QuestLogTitleButton_OnClick;
  53.  
  54.  
  55. -- begin ui code
  56.  
  57. function QuestieTracker:updateTrackingFrameSize()
  58. local lastButton = QuestieTracker.questButtons[QuestieTracker.highestIndex];
  59. --/script DEFAULT_CHAT_FRAME:AddMessage(QuestieTracker.frame:GetTop());
  60. --/script DEFAULT_CHAT_FRAME:AddMessage(QuestieTracker.questButtons[QuestieTracker.highestIndex]:GetTop());
  61. if lastButton == nil then return; end
  62.  
  63. local lbt = lastButton:GetBottom();
  64. local tt = QuestieTracker.frame:GetTop();
  65.  
  66. -- yeah apparently this happens
  67. if tt == nil then tt = 0; end
  68. if lbt == nil then lbt = 0; end
  69. -- wtf wow
  70.  
  71. local totalSize = tt - lbt;
  72. QuestieTracker.frame:SetHeight(totalSize);
  73. end
  74.  
  75. function QuestieTracker:getRGBForObjective_old(objective)
  76. if not (type(objective) == "function") then -- seriously wtf
  77. local lastIndex = findLast(objective, ":");
  78. if not (lastIndex == nil) then -- I seriously CANT shake this habit
  79. local progress = string.sub(objective, lastIndex+2);
  80.  
  81. -- There HAS to be a better way of doing this
  82. local slash = findLast(progress, "/");
  83. local have = tonumber(string.sub(progress, 0, slash-1))
  84. local need = tonumber(string.sub(progress, slash+1))
  85.  
  86. local float = have / need;
  87. local part = float-0.5;
  88. if part < 0 then part = 0; end
  89. part = part * 2;
  90. return 1.0-part, float*2, 0;
  91. end
  92. end
  93. return 0.2, 1, 0.2;
  94. end
  95.  
  96. function QuestieTracker:getRGBForObjective(objective)
  97. if not (type(objective) == "function") then -- seriously wtf
  98. local lastIndex = findLast(objective, ":");
  99. if not (lastIndex == nil) then -- I seriously CANT shake this habit
  100. local progress = string.sub(objective, lastIndex+2);
  101.  
  102. -- There HAS to be a better way of doing this
  103. local slash = findLast(progress, "/");
  104. local have = tonumber(string.sub(progress, 0, slash-1))
  105. local need = tonumber(string.sub(progress, slash+1))
  106.  
  107. local float = have / need;
  108. return 0.8-float/2, 0.8+float/3, 0.8-float/2;
  109. end
  110. end
  111. return 0.3, 1, 0.3;
  112. end
  113.  
  114. function QuestieTracker:clearTrackingFrame()
  115. --[[for i=1, 8 do
  116. getglobal("QuestieTrackerButton"..i):Hide();
  117. for j=1,20 do
  118. getglobal("QuestieTrackerButton"..i.."QuestWatchLine"..j):Hide();
  119. end
  120. end]]--
  121. end
  122.  
  123. QuestieTracker.questButtons = {};
  124.  
  125. function QuestieTracker:createOrGetTrackingButton(index)
  126. if QuestieTracker.questButtons[index] == nil then
  127. local parent;
  128. local parentString; -- fucking wow api
  129. if index == 1 then
  130. parent = QuestieTracker.frame;
  131. else
  132. parent = QuestieTracker.questButtons[index-1]; -- this allows easy dynamic positioning
  133. end
  134.  
  135. --parent = UIParent;
  136. --parent = QuestieTracker.frame;
  137. local btn = CreateFrame("Button", "QuestieTrackerButtonNew"..index, QuestieTracker.frame);
  138. btn.objectives = {};
  139. btn:SetWidth(240);
  140. btn:SetHeight(14);
  141. btn:EnableMouse(true);
  142. btn:SetMovable(true);
  143. btn:SetScript("OnDragStart", QuestieTracker.frame.StartMoving)
  144. btn:SetScript("OnDragStop", QuestieTracker.frame.StopMovingOrSizing)
  145. --btn.clicked = false;
  146. btn:SetScript("OnMouseDown", function()
  147. btn.dragstartx, btn.dragstarty = GetCursorPosition();
  148. QuestieTracker.frame:StartMoving();
  149. end);
  150. btn:SetScript("OnMouseUp", function()
  151. local dragstopx, dragstopy = GetCursorPosition();
  152. if (btn.dragstartx == dragstopx and btn.dragstarty == dragstopy) then
  153. btn:click();
  154. end
  155. QuestieTracker.frame:StopMovingOrSizing();
  156. QuestieTracker.frame:SetUserPlaced(false);
  157. --can't call saveFramePosition because it RANDOMLY THROWS WOW ERRORS (WTF?)
  158. QuestieTracker:saveFramePosition()
  159. --btn.clicked = false;
  160. end);
  161. btn.dragstartx = 0;
  162. btn.dragstarty = 0;
  163. btn:SetScript("OnEnter", function()
  164. QuestieTracker.frame.texture:SetAlpha(0.3);
  165. end);
  166. btn:SetScript("OnLeave", function()
  167. QuestieTracker.frame.texture:SetAlpha(0.0);
  168. end);
  169. btn:RegisterForClicks("RightButtonDown","LeftButtonUp", "LeftClick");
  170. btn.click = function()
  171. SetArrowObjective(btn.hash);
  172. --DEFAULT_CHAT_FRAME:AddMessage("Clicked " .. btn.quest:GetText());
  173. end
  174. btn:SetScript("OnClick", function()
  175. if arg1 == "LeftButton" then
  176. --btn:click();
  177. --btn.clicked = true;
  178. end
  179. end);
  180. --button:SetPoint("CENTER", UIParent, 0, -5);
  181. --button:SetPoint("BOTTOMLEFT", parent, 10, -10);
  182. if index == 1 then
  183. btn:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, 0);
  184. else
  185. btn:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, 0);
  186. end
  187.  
  188. --button.prevoffset = parent.prevoffset + button:GetHeight(); -- there is a way to do this automatically but WOW IS BEING RETARDED AND I'M NOT GIVING UP RAGE RAGE RAGE
  189. local quest = btn:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  190. quest:SetPoint("TOPLEFT", btn, "TOPLEFT", 10, 0)
  191. btn.quest = quest;
  192.  
  193. local level = btn:CreateFontString(nil, "OVERLAY", "GameFontNormal") --/script QuestieTracker.questButtons[3]:SetHeight(20);
  194. level:SetPoint("TOPLEFT", btn, "TOPLEFT", 0, 0)
  195. btn.level = level;
  196.  
  197. QuestieTracker.questButtons[index] = btn;
  198. --button:Show();
  199. --btn.Hide = function() DEFAULT_CHAT_FRAME:AddMessage("Attempt hide!"); end
  200. --table.insert(QuestieTracker.questButtons, btn); -- because of how the code works this will always match index and doing it this way has the benifit of making it sortable
  201. end
  202. return QuestieTracker.questButtons[index];
  203. end
  204.  
  205. QuestieTracker.highestIndex = 0;
  206.  
  207. function QuestieTracker:GetDifficultyColor(level)
  208. if level == nil then return "FFFFFFFF"; end
  209. local levelDiff = level - UnitLevel("player");
  210. if ( levelDiff >= 5 ) then
  211. return "FFFF1A1A";
  212. elseif ( levelDiff >= 3 ) then
  213. return "FFFF8040";
  214. elseif ( levelDiff >= -2 ) then
  215. return "FFFFFF00";
  216. elseif ( -levelDiff <= GetQuestGreenRange() ) then
  217. return "FF40C040";
  218. else
  219. return "FFC0C0C0";
  220. end
  221. end
  222.  
  223. local function RGBToHex(r, g, b)
  224. --r = r <= 255 and r >= 0 and r or 0
  225. --g = g <= 255 and g >= 0 and g or 0
  226. --b = b <= 255 and b >= 0 and b or 0
  227. if r > 255 then r = 255; end
  228. if g > 255 then g = 255; end
  229. if b > 255 then b = 255; end;
  230. return string.format("%02x%02x%02x", r, g, b)
  231. end
  232.  
  233. local function fRGBToHex(r, g, b)
  234. return RGBToHex(r*254, g*254, b*254);
  235. end
  236.  
  237. function QuestieTracker:AddObjectiveToButton(button, objective, index)
  238. local objt;
  239. if button.objectives[index] == nil then
  240. --button:SetHeight(button:GetHeight() + 11);
  241. objt = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  242. else
  243. objt = button.objectives[index];
  244. end
  245. --/script QuestieTracker.questButtons[3]:SetHeight(20);
  246. objt:SetPoint("TOPLEFT", button, "TOPLEFT", 20, -(index * 11+1))
  247.  
  248. local r, g, b = QuestieTracker:getRGBForObjective(objective["desc"]);
  249. local clr = fRGBToHex(r, g, b);
  250. --local clr = "DDDDDD";
  251.  
  252. objt:SetText("|cFF"..clr..objective["desc"].."|r");
  253.  
  254. button.objectives[index] = objt;
  255.  
  256. --btn.objectives
  257.  
  258. end
  259.  
  260. -- TODO move this into Questie: namespace
  261. function QuestieTracker:GetFinisherLocation(typ, name)
  262. local C, Z, X, Y;
  263.  
  264. if typ == "monster" then
  265. local npc = QuestieMonsters[name];
  266. if npc == nil then
  267. npc = QuestieAdditionalStartFinishLookup[name];
  268. if not (npc == nil) then
  269. C, Z, X, Y = npc[1], npc[2], npc[3], npc[4];
  270. else
  271. end
  272. else
  273. local loc = npc['locations'][1];
  274. mapid = loc[1];
  275. x = loc[2];
  276. y = loc[3];
  277. C, Z, X, Y = QuestieZoneIDLookup[mapid][4], QuestieZoneIDLookup[mapid][5], x, y
  278. end
  279. elseif typ == "object" then
  280. local obj = QuestieObjects[name];
  281. if not (obj == nil) then
  282. local loc = obj['locations'][1];
  283. mapid = loc[1];
  284. x = loc[2];
  285. y = loc[3];
  286. C, Z, X, Y = QuestieZoneIDLookup[mapid][4], QuestieZoneIDLookup[mapid][5], x, y
  287. else
  288. local npc = QuestieMonsters[name];
  289. if npc == nil then
  290. npc = QuestieAdditionalStartFinishLookup[name];
  291. if not (npc == nil) then
  292. C, Z, X, Y = npc[1], npc[2], npc[3], npc[4];
  293. else
  294. end
  295. else
  296. local loc = npc['locations'][1];
  297. mapid = loc[1];
  298. x = loc[2];
  299. y = loc[3];
  300. C, Z, X, Y = QuestieZoneIDLookup[mapid][4], QuestieZoneIDLookup[mapid][5], x, y
  301. end
  302. end
  303. end
  304.  
  305. return C, Z, X, Y;
  306. end
  307.  
  308. function QuestieTracker:fillTrackingFrame()
  309. local index = 1;
  310. local sortedByDistance = {};
  311. local distanceControlTable = {};
  312. local C,Z,X,Y = Astrolabe:GetCurrentPlayerPosition() -- continent, zone, x, y
  313.  
  314. local distanceNotes = {};
  315. local objc = 0;
  316. for hash,quest in pairs(QuestieHandledQuests) do
  317. if QuestieTrackedQuests[hash] and QuestieHashMap[hash] then
  318. objc = 0;
  319. if QuestieTrackedQuests[hash]["isComplete"] then
  320.  
  321. else
  322. for name,notes in pairs(quest.objectives.objectives) do
  323. for k,v in pairs(notes) do
  324. if not v.done then
  325. local continent, zone, xNote, yNote = QuestieZoneIDLookup[v.mapid][4], QuestieZoneIDLookup[v.mapid][5], v.x, v.y
  326. local dist, xDelta, yDelta = Astrolabe:ComputeDistance( C, Z, X, Y, continent, zone, xNote, yNote )
  327. local info = {
  328. ["dist"] = dist,
  329. ["hash"] = hash,
  330. ["xDelta"] = xDelta,
  331. ["yDelta"] = yDelta,
  332. ["c"] = continent,
  333. ["z"] = zone,
  334. ["x"] = xNote,
  335. ["y"] = yNote,
  336. }
  337. objc = objc + 1;
  338. table.insert(distanceNotes, info);
  339. end
  340. end
  341. end
  342. end
  343. if objc == 0 then
  344. local continent, zone, xNote, yNote = QuestieTracker:GetFinisherLocation(QuestieHashMap[hash]['finishedType'], QuestieHashMap[hash]['finishedBy']);
  345. if continent and zone and xNote and yNote then
  346. local dist, xDelta, yDelta = Astrolabe:ComputeDistance( C, Z, X, Y, continent, zone, xNote, yNote )
  347. local info = {
  348. ["dist"] = dist,
  349. ["hash"] = hash,
  350. ["xDelta"] = xDelta,
  351. ["yDelta"] = yDelta,
  352. ["c"] = continent,
  353. ["z"] = zone,
  354. ["x"] = xNote,
  355. ["y"] = yNote,
  356. }
  357. table.insert(distanceNotes, info);
  358. end
  359. end
  360. end
  361. end
  362.  
  363.  
  364. sort(distanceNotes, function (a, b)
  365. return (a["dist"] or 0) < (b["dist"] or 0)
  366. end)
  367.  
  368.  
  369. -- not sure what this bit is for
  370. for k,v in pairs(distanceNotes) do
  371. if not distanceControlTable[v["hash"]] then
  372. distanceControlTable[v["hash"]] = true
  373. table.insert(sortedByDistance, v);
  374. end
  375. end
  376. -- but it exists so...
  377.  
  378. for k,v in pairs(QuestieTrackedQuests) do
  379. if type(v) == "table" then v['rend'] = false; end
  380. end
  381.  
  382.  
  383. for i,v in pairs(sortedByDistance) do
  384. local hash = v["hash"];
  385. local quest = QuestieTrackedQuests[hash];
  386. quest['rend'] = true;
  387. local button = QuestieTracker:createOrGetTrackingButton(index);
  388. button.hash = hash;
  389. local colorString = "|c" .. QuestieTracker:GetDifficultyColor(quest["level"]);
  390.  
  391. local titleData = colorString;
  392.  
  393.  
  394. if QuestieConfig['AlwaysShowLevel'] then
  395. titleData = titleData .. "[" .. quest["level"] .. "] " ;
  396. end
  397. titleData = titleData .. quest["questName"];
  398. if QuestieConfig['AlwaysShowDistance'] then
  399. titleData = titleData .. " ("..math.floor(v["dist"]).." Yd)";
  400. end
  401.  
  402. titleData = titleData .. "|r";
  403.  
  404. button.quest:SetText(titleData);
  405. --button.level:SetText(colorString .. "[".. quest["level"] .."]|r");
  406.  
  407. local obj = 1;
  408.  
  409. v["title"] = colorString .. "[" .. quest["level"] .. "] " .. quest["questName"] .. "|r";
  410. quest["arrowPoint"] = v
  411.  
  412. if quest["isComplete"] then
  413. QuestieTracker:AddObjectiveToButton(button, {['desc']="Run to the end"}, obj);
  414. obj = 2;
  415. else
  416. while true do
  417. local beefcake = quest["objective" .. obj];
  418. if beefcake == nil then break; end
  419. QuestieTracker:AddObjectiveToButton(button, beefcake, obj);
  420. obj = obj + 1;
  421. end
  422. end
  423.  
  424. button.currentObjectiveCount = obj - 1;
  425.  
  426. local heightLoss = 0;
  427.  
  428. while true do
  429. if button.objectives[obj] == nil then break; end
  430. button.objectives[obj]:SetText(""); --hecks
  431. heightLoss = heightLoss + 11;
  432. obj = obj + 1;
  433. end
  434.  
  435. --button:SetHeight(button:GetHeight() - heightLoss);
  436. button:SetHeight(14 + (button.currentObjectiveCount * 11));
  437.  
  438. button:Show();
  439.  
  440. index = index + 1;
  441. end
  442.  
  443. QuestieTracker.highestIndex = index - 1;
  444.  
  445. while true do
  446. local d = QuestieTracker.questButtons[index];
  447. if d == nil then break end;
  448. d:Hide();
  449. index = index + 1;
  450. end
  451.  
  452. QuestieTracker:updateTrackingFrameSize();
  453.  
  454. QuestieTracker.frame:Show();
  455.  
  456. end
  457.  
  458. function QuestieTracker:fillTrackingFrame_Old()
  459. local t = GetTime();
  460. QuestieTracker:clearTrackingFrame();
  461. local sortedByDistance = {};
  462. local distanceControlTable = {};
  463. local C,Z,X,Y = Astrolabe:GetCurrentPlayerPosition() -- continent, zone, x, y
  464.  
  465. local distanceNotes = {};
  466.  
  467. -- iterate 3 times
  468. -- first go by through notes in the current zone
  469. -- if quest tracker frame isn't fully filled (index 8), go through other zones
  470. -- as a backup, add quests that don't have any notes by going through QuestieTrackedQuests+Questlog
  471.  
  472. for hash,quest in pairs(QuestieHandledQuests) do
  473. if QuestieTrackedQuests[hash] then
  474. for name,notes in pairs(quest.objectives.objectives) do
  475. for k,v in pairs(notes) do
  476. local continent, zone, xNote, yNote = QuestieZoneIDLookup[v.mapid][4], QuestieZoneIDLookup[v.mapid][5], v.x, v.y
  477. local dist, xDelta, yDelta = Astrolabe:ComputeDistance( C, Z, X, Y, continent, zone, xNote, yNote )
  478. local info = {
  479. ["dist"] = dist,
  480. ["hash"] = hash,
  481. ["xDelta"] = xDelta,
  482. ["yDelta"] = yDelta,
  483. ["c"] = continent,
  484. ["z"] = zone,
  485. ["x"] = xNote,
  486. ["y"] = yNote,
  487. }
  488. table.insert(distanceNotes, info);
  489. end
  490. end
  491. end
  492. end
  493. sort(distanceNotes, function (a, b)
  494. return a["dist"] < b["dist"]
  495. end)
  496.  
  497. for k,v in pairs(distanceNotes) do
  498. if not distanceControlTable[v["hash"]] then
  499. distanceControlTable[v["hash"]] = true
  500. table.insert(sortedByDistance, v);
  501. end
  502. end
  503.  
  504. for i,v in pairs(sortedByDistance) do
  505. local quest = QuestieTrackedQuests[v["hash"]]
  506. local frame = getglobal("QuestieTrackerButton"..i);
  507. if not frame then break end
  508.  
  509. frame:Show();
  510.  
  511. local formatUnits = "yds"
  512. local dist = tonumber(string.format("%.0f" , v["dist"]))
  513.  
  514. -- Arrow data
  515. v["title"] = "[" .. quest["level"] .. "] " .. quest["questName"]
  516. quest["arrowPoint"] = v
  517. frame["hash"] = v["hash"]
  518.  
  519. getglobal("QuestieTrackerButton"..i.."HeaderText"):SetText("[" .. quest["level"] .. "] " .. quest["questName"] .. " (" .. dist .. " " .. formatUnits .. ")");
  520. for j=1,20 do
  521. local objectiveLine = getglobal("QuestieTrackerButton"..i.."QuestWatchLine"..j)
  522. local objectiveTable = quest["objective"..j]
  523. if not objectiveLine or not objectiveTable then break end
  524.  
  525. objectiveLine:SetText(objectiveTable["desc"]);
  526. objectiveLine:SetTextColor(QuestieTracker:getRGBForObjective(objectiveTable["desc"]));
  527. objectiveLine:Show();
  528. end
  529. end
  530.  
  531. QuestieTracker:updateTrackingFrameSize();
  532. --Questie:debug_Print("TrackerFrame filled: Time:", tostring((GetTime()-t)*1000).."ms");
  533. end
  534.  
  535.  
  536.  
  537. function QuestieTracker:createTrackingButtons() -- no longer needed but keeping the method stub
  538.  
  539. end
  540.  
  541. function QuestieTracker:createTrackingFrame()
  542. QuestieTracker.frame = CreateFrame("Frame", "QuestieTrackerFrame", UIParent);
  543. QuestieTracker.frame:SetWidth(250);
  544. QuestieTracker.frame:SetHeight(400);
  545. QuestieTracker.frame:SetPoint(QuestieTrackerVariables["position"]["point"], QuestieTrackerVariables["position"]["relativeTo"], QuestieTrackerVariables["position"]["relativePoint"],
  546. QuestieTrackerVariables["position"]["xOfs"], QuestieTrackerVariables["position"]["yOfs"]);
  547. --QuestieTracker.frame:SetAlpha(0.2)
  548. QuestieTracker.frame.texture = QuestieTracker.frame:CreateTexture(nil, "BACKGROUND");
  549.  
  550. --this.frame.texture:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background");
  551. QuestieTracker.frame.texture:SetTexture(0,0,0); -- black
  552. QuestieTracker.frame.texture:SetAlpha(0.0);
  553. QuestieTracker.frame.texture:SetAllPoints(QuestieTracker.frame);
  554. QuestieTracker.frame:Show();
  555.  
  556. --this.frame:RegisterForDrag("LeftButton");
  557. QuestieTracker.frame:EnableMouse(true);
  558. QuestieTracker.frame:SetMovable(true);
  559. QuestieTracker.frame.prevoffset = 0;
  560. QuestieTracker.frame:SetScript("OnMouseDown", function()
  561. this:StartMoving();
  562. end);
  563. QuestieTracker.frame:SetScript("OnMouseUp", function()
  564. this:StopMovingOrSizing();
  565. this:SetUserPlaced(false);
  566. --can't call saveFramePosition because it RANDOMLY THROWS WOW ERRORS (WTF?)
  567. QuestieTracker:saveFramePosition()
  568. end);
  569. end
  570.  
  571. function QuestLogTitleButton_OnClick(button)
  572. if(EQL3_Player) then -- could also hook EQL3_AddQuestWatch(index) I guess
  573. if ( IsShiftKeyDown() ) then
  574. if not ChatFrameEditBox:IsVisible() then
  575. QuestieTracker:setQuestInfo(this:GetID() + FauxScrollFrame_GetOffset(EQL3_QuestLogListScrollFrame));
  576. end
  577. end
  578. _QuestLogTitleButton_OnClick(button);
  579. EQL3_QuestWatchFrame:Hide();
  580. else
  581. if ( button == "LeftButton" ) then
  582. if ( IsShiftKeyDown() ) then
  583. if(ChatFrameEditBox:IsVisible()) then
  584. ChatFrameEditBox:Insert(this:GetText());
  585. else
  586. -- add/remove quest to/from tracking
  587. QuestieTracker:setQuestInfo(this:GetID() + FauxScrollFrame_GetOffset(QuestLogListScrollFrame));
  588. end
  589. end
  590. QuestLog_SetSelection(this:GetID() + FauxScrollFrame_GetOffset(QuestLogListScrollFrame))
  591. QuestLog_Update();
  592. end
  593. end
  594.  
  595. QuestWatchFrame:Hide()
  596. QuestieTracker:fillTrackingFrame();
  597. end
  598.  
  599.  
  600. function QuestieTracker:saveFramePosition()
  601. local frame = getglobal("QuestieTrackerFrame");
  602. local point, _, relativePoint, xOfs, yOfs = frame:GetPoint();
  603. -- receiving relativeTo causes wow to crash sometimes
  604. -- but the values are ALWAYS TOPLEFT, UIParent, TOPLEFT anyway
  605. QuestieTrackerVariables["position"] = {
  606. ["point"] = point,
  607. ["relativePoint"] = relativePoint,
  608. ["relativeTo"] = "UIParent",
  609. ["yOfs"] = yOfs,
  610. ["xOfs"] = xOfs,
  611. };
  612. end
  613.  
  614. -- end ui code
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630. -- begin logic code
  631.  
  632. local function trim(s)
  633. return string.gsub(s, "^%s*(.-)%s*$", "%1");
  634. end
  635.  
  636. function QuestieTracker:addQuestToTracker(hash, logId, level) -- never used???
  637. local startTime = GetTime()
  638.  
  639. if(type(QuestieTrackedQuests[hash]) ~= "table") then
  640. QuestieTrackedQuests[hash] = {};
  641. end
  642.  
  643. if not logId then
  644. logId = Questie:GetQuestIdFromHash(hash)
  645. end
  646.  
  647. if logId == nil then
  648. Questie:debug_Print("TrackerError! LogId still nil after GetQuestIdFromHash ", hash);
  649. return;
  650. end
  651.  
  652. local startId = GetQuestLogSelection();
  653. SelectQuestLogEntry(logId);
  654. local questName, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(logId);
  655. QuestieTrackedQuests[hash]["questName"] = questName
  656. QuestieTrackedQuests[hash]["level"] = level
  657. QuestieTrackedQuests[hash]["isComplete"] = isComplete
  658. for i=1, GetNumQuestLeaderBoards() do
  659. local desc, type, done = GetQuestLogLeaderBoard(i);
  660. QuestieTrackedQuests[hash]["objective"..i] = {
  661. ["desc"] = desc,
  662. ["type"] = type,
  663. ["done"] = done,
  664. ["notes"] = {},
  665. }
  666. end
  667. -- fallback for running quests
  668. if GetNumQuestLeaderBoards() == 0 then
  669. QuestieTrackedQuests[hash]["objective1"] = {
  670. ["desc"] = "Run to the end",
  671. ["type"] = type,
  672. ["done"] = true,
  673. ["notes"] = {},
  674. }
  675. end
  676. SelectQuestLogEntry(startId);
  677. Questie:debug_Print("Added QuestInfo to Tracker - Time: " .. (GetTime()-startTime)*1000 .. "ms");
  678. QuestieTracker:fillTrackingFrame()
  679. Questie:RedrawNotes();
  680. end
  681.  
  682. function QuestieTracker:updateFrameOnTracker(hash, logId, level)
  683.  
  684. if AUTO_QUEST_WATCH == "1" or type(QuestieTrackedQuests[hash]) == "table" then
  685. QuestieTracker:addQuestToTracker(hash, logId, level);
  686.  
  687. end
  688. if true then return; end
  689.  
  690. local startTime = GetTime()
  691.  
  692.  
  693. if not logId then
  694. logId = Questie:GetQuestIdFromHash(hash)
  695. end
  696.  
  697. if not logId then
  698. Questie:debug_Print("LogId STILL NULL after GetQuestIdFromHash ", hash);
  699. return;
  700. end
  701.  
  702. local startid = GetQuestLogSelection();
  703. SelectQuestLogEntry(logId);
  704. local questName, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(logId);
  705.  
  706. --if not AUTO_QUEST_WATCH == "1" then
  707. -- if not QuestieTrackedQuests[hash] or isHeader then return; end -- skipp isTracked because the hash is already known
  708. --end
  709.  
  710. --if not QuestieTracker:isTracked(logId) then
  711. -- return
  712. --end
  713. if not QuestieTrackedQuests[hash] then
  714. QuestieTrackedQuests[hash] = {};
  715. end
  716.  
  717. QuestieTrackedQuests[hash]["questName"] = questName;
  718. QuestieTrackedQuests[hash]["isComplete"] = isComplete;
  719. QuestieTrackedQuests[hash]["level"] = level;
  720. local uggo = 0;
  721. for i=1, GetNumQuestLeaderBoards() do
  722. local desc, type, done = GetQuestLogLeaderBoard(i);
  723. if not QuestieTrackedQuests[hash]["objective"..i] then
  724. QuestieTrackedQuests[hash]["objective"..i] = {};
  725. end
  726. QuestieTrackedQuests[hash]["objective"..i]["desc"] = desc
  727. QuestieTrackedQuests[hash]["objective"..i]["done"] = done
  728. uggo = i;
  729. end
  730.  
  731. uggo = uggo - 1;
  732.  
  733. while true do
  734. if QuestieTrackedQuests[hash]["objective"..uggo] == nil then break; end;
  735. QuestieTrackedQuests[hash]["objective"..uggo] = nil;
  736. uggo = uggo + 1;
  737. end
  738.  
  739. SelectQuestLogEntry(startid);
  740. QuestieTracker:fillTrackingFrame()
  741. --Questie:debug_Print("TrackerInfo collected - Time: " .. (GetTime()-startTime)*1000 .. "ms");
  742. end
  743.  
  744. function QuestieTracker:removeQuestFromTracker(hash)
  745. --DEFAULT_CHAT_FRAME:AddMessage("REMOVEQUESTFROMTRACKER");
  746. if QuestieTrackedQuests[hash] then
  747. QuestieTrackedQuests[hash] = nil
  748. QuestieTrackedQuests[hash] = false
  749. end
  750. QuestieTracker:fillTrackingFrame()
  751. Questie:RedrawNotes();
  752. end
  753.  
  754.  
  755. function QuestieTracker:findLogIdByName(name)
  756. for i=1,GetNumQuestLogEntries() do
  757. local questName, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(i);
  758. if(name == questName) then
  759. return i;
  760. end
  761. end
  762. end
  763.  
  764. function QuestieTracker:isTracked(quest) -- everything about this function is bad because of GetHashFromName
  765. if quest == nil then return false; end
  766. if(type(quest) == "string") then
  767. local hash = Questie:GetHashFromName(quest)
  768. if(QuestieTrackedQuests[hash] and QuestieTrackedQuests[hash] ~= false) then
  769. return true;
  770. end
  771. else
  772. local questName, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(quest);
  773. local hash = Questie:GetHashFromName(questName)
  774. if(QuestieTrackedQuests[hash] and QuestieTrackedQuests[hash] ~= false) then
  775. return true;
  776. end
  777. end
  778. return false;
  779. end
  780.  
  781. function QuestieTracker:setQuestInfo(id) -- never used???
  782. local questInfo = {};
  783. local questName, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(id);
  784.  
  785. if not isHeader and not isCollapsed then
  786. local hash = Questie:GetHashFromName(questName)
  787.  
  788. if(QuestieTracker:isTracked(questName)) then
  789. QuestieTracker:removeQuestFromTracker(hash);
  790. return;
  791. end
  792. QuestieTracker:addQuestToTracker(hash, id, level);
  793. end
  794. end
  795.  
  796. function QuestieTracker:PLAYER_LOGIN()
  797. QuestieTracker:createTrackingFrame();
  798. --QuestieTracker:createTrackingButtons();
  799. QuestieTracker:RegisterEvent("PLAYER_LOGOUT");
  800.  
  801. QuestieTracker:syncEQL3();
  802. end
  803.  
  804. function QuestieTracker:syncEQL3()
  805. if(EQL3_Player) then
  806. for id=1, GetNumQuestLogEntries() do
  807. local questName, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(id);
  808. if ( not isHeader and EQL3_IsQuestWatched(id) and not QuestieTracker:isTracked(questName) ) then
  809. QuestieTracker:addQuestToTracker(Questie:GetHashFromName(questName), id, level);
  810. elseif( not isHeader and not EQL3_IsQuestWatched(id) and QuestieTracker:isTracked(questName) ) then
  811. QuestieTracker:removeQuestFromTracker(Questie:GetHashFromName(questName));
  812. end
  813. end
  814. end
  815. end
  816.  
  817. function QuestieTracker:ADDON_LOADED()
  818. if not ( QuestieTrackerVariables ) then
  819. QuestieTrackerVariables = {};
  820. QuestieTrackerVariables["position"] = {
  821. point = "CENTER",
  822. relativeTo = "UIParent",
  823. relativePoint = "CENTER",
  824. xOfs = 0,
  825. yOfs = 0,
  826. };
  827. end
  828.  
  829. if not QuestieTrackedQuests then
  830. QuestieTrackedQuests = {}
  831. end
  832.  
  833. -- bye vanilla tracker
  834. QuestWatchFrame:Hide()
  835. QuestWatchFrame.Show = function () end;
  836.  
  837. end
  838.  
  839. -- end logic code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement