q3fuba

Wowhead Link Grabber - fixed for 7.1.5 - by q3fuba

Feb 14th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.07 KB | None | 0 0
  1. local tooltipInfo = {}
  2. local customframes;
  3. local wowheadLink, hash
  4. local frame = CreateFrame("Frame")
  5. local gotoLink = ""
  6. local QuestMapFrame_IsQuestWorldQuest = QuestMapFrame_IsQuestWorldQuest or QuestUtils_IsQuestWorldQuest
  7.  
  8. local validfounds = {
  9.     npc = "",
  10.     spell = GetSpellBookItemName,
  11.     achievement = function(id) return select(2,GetAchievementInfo(id)) end,
  12.     quest = function(id)
  13.             for i=1,GetNumQuestLogEntries() do
  14.                     local name,_,_,_,_,_,_,qid = GetQuestLogTitle(i)
  15.                     if id == qid then return name end
  16.             end
  17.             for i=1, NUM_WORLDMAP_TASK_POIS do
  18.                 local POI = _G["WorldMapFrameTaskPOI"..i];
  19.                 if POI.worldQuest and POI.questID then
  20.                     local name = select(4, GetTaskInfo(POI.questID));
  21.                     if POI.questID == id then   return name end
  22.                 end
  23.             end
  24.             if QuestMapFrame_IsQuestWorldQuest(id) then
  25.                 return "World Quest";
  26.             else
  27.                 return "Quest";
  28.             end
  29.     end,
  30.     item = GetItemInfo
  31. }
  32.  
  33. local function clearTooltipInfo(tooltip)
  34.     wipe(tooltipInfo[tooltip])
  35. end
  36.  
  37. local function setTooltipHyperkink(tooltip, hyperlink)
  38.     local ttable = tooltipInfo[tooltip];
  39.     ttable.hl = hyperlink;
  40. end
  41.  
  42. local function setTooltipAura(tooltip, unit, index, filter)
  43.     local ttable = tooltipInfo[tooltip];
  44.     local name,_,_,_,_,_,_,_,_,_,id = UnitAura(unit, index, filter);
  45.     ttable.aura = id
  46.     ttable.name = name
  47. end
  48.  
  49. local function hookTooltip(tooltip)
  50.     tooltipInfo[tooltip] = {}
  51.     hooksecurefunc(tooltip, "SetHyperlink", setTooltipHyperkink)
  52.     hooksecurefunc(tooltip, "SetUnitAura", setTooltipAura)
  53.     tooltip:HookScript("OnTooltipCleared", clearTooltipInfo)
  54. end
  55.  
  56. local function onEvent(frame, event)
  57.     if event == "PLAYER_ENTERING_WORLD" then
  58.         hookTooltip(GameTooltip)
  59.         hookTooltip(ItemRefTooltip)
  60.     end
  61. end
  62.  
  63. local function onUpdate()
  64.     StaticPopup_Show("WOWHEAD_LINK_GRABBER")
  65.     frame:Hide();
  66. end
  67.  
  68. local function found(ftype, id, name)
  69.     local foundAccept = validfounds[ftype];
  70.     if foundAccept then
  71.         name = name or foundAccept;
  72.         if type(name) == 'function' then
  73.             name = name(id);
  74.         end
  75.         name = name or ftype;              
  76.                 local strType;
  77.                 if QuestMapFrame_IsQuestWorldQuest(id) then
  78.                     strType = "World Quest"
  79.                 end
  80.                 strType = strType or ftype;
  81.         --print("Found "..type.." "..id)
  82.         -- Show frame to recieve OnUpdate next frame
  83.         -- So pressed hotkey doesnt erase text field
  84.         gotoLink = wowheadLink .. ftype .. "=" .. id .. hash;
  85.         --StaticPopupDialogs["WOWHEAD_LINK_GRABBER"].text = firstToUpper(ftype) .. ": " .. name .. "\n|cff808080id="..id.."\n|cff00ff00CTRL+C to copy!";
  86.         StaticPopupDialogs["WOWHEAD_LINK_GRABBER"].text = "|cffffff00"..firstToUpper(strType) .. ":\n|r" .. name .. "\n\n|cff00ff00CTRL+C to copy!|r";
  87.         frame:Show();
  88.         return true;
  89.     end
  90. end
  91.  
  92. local function foundplayer(name)
  93.     return true;
  94. end
  95.  
  96. local function getUnitInfo(unit, name)
  97.     if UnitIsPlayer(unit) then
  98.         return foundplayer(name)
  99.     else
  100.         local GUID=UnitGUID(unit)
  101.         local type,_,_,_,_,id = strsplit("-",GUID);
  102.         if type == "Creature" then return found("npc",id,name) end
  103.     end
  104. end
  105.  
  106. local function getFocusInfo()
  107.     local focus = GetMouseFocus()
  108.     local current = focus;
  109.     local focusname;
  110.     --__LASTFRAME = focus;
  111.     while current and not focusname do
  112.         focusname = current:GetName()
  113.         current = current:GetParent()
  114.     end
  115.     if not focusname then return end
  116.     local focuslen = string.len(focusname);
  117.     --print(focusname);
  118.     for name,func in pairs(customframes) do
  119.         local customlen = string.len(name)
  120.         if customlen <= focuslen and name == string.sub(focusname,1,customlen) then
  121.             if func(focus, focusname) then return true end
  122.         end
  123.     end
  124. end
  125.  
  126. local function parseLink(link)
  127.     local linkstart = string.find(link,"|H")
  128.     local _,lastfound,type,id = string.find(link,"(%a+):(%d+):",linkstart and linkstart + 2)
  129.     local _,_,name = string.find(link,"%[([^%[%]]*)%]",lastfound)
  130.     return found(type,id,name)
  131. end
  132.  
  133. local function parseTooltip(tooltip)
  134.     local name, link = tooltip:GetItem()
  135.     if name then return parseLink(link) end
  136.     local name, _, id = tooltip:GetSpell();
  137.     if name then return found("spell",id,name) end
  138.     local name, unit = tooltip:GetUnit()
  139.     if unit then return getUnitInfo(unit, name) end
  140.     local ttdata = tooltipInfo[tooltip];
  141.     if ttdata.hl then return parseLink(ttdata.hl) end
  142.     if ttdata.aura then return found("spell",ttdata.aura,ttdata.name) end
  143. end
  144.  
  145. local function linkGrabberRunInternal()
  146.     return parseTooltip(ItemRefTooltip)
  147.             or parseTooltip(GameTooltip)
  148.             or getFocusInfo()
  149. end
  150.  
  151. linkGrabberRun = function()
  152.     linkGrabberRunInternal()
  153.     --pcall(linkGrabberRunInternal);
  154. end
  155.  
  156. -- Formatting
  157.  
  158. function firstToUpper(str)
  159.     return (str:gsub("^%l", string.upper))
  160. end
  161.  
  162. -- Custom frames mouseover
  163.  
  164. local function AchievmentWidget(widget)
  165.     return found("achievement",widget.id);
  166. end
  167.  
  168. local function AchievmentWidgetParent(widget)
  169.     return AchievmentWidget(widget:GetParent())
  170. end
  171.  
  172. local function QuestWidget(widget)
  173.     if widget.questID then return found("quest",widget.questID) end
  174. end
  175.  
  176. local function WolrdQuestWidget(widget)
  177.     if widget.questID then return found("quest",widget.questID) end
  178. end
  179.  
  180. local function TrackWidget(widget)
  181.     local parent = widget:GetParent()
  182.     local module = parent.module;  
  183.     if module == QUEST_TRACKER_MODULE then
  184.         return found("quest",parent.id)
  185.         elseif module == ACHIEVEMENT_TRACKER_MODULE then
  186.         return found("achievement",parent.id)
  187.     end
  188. end
  189.  
  190. local function TrackWorldQuestWidget(widget)
  191.     local module = widget.module;  
  192.     if module == WORLD_QUEST_TRACKER_MODULE then
  193.             if widget.id then
  194.         return found("quest", widget.id, select(4, GetTaskInfo(widget.id)))
  195.             end
  196.     elseif widget.questID then -- World Quest Tracker support
  197.             if QuestMapFrame_IsQuestWorldQuest(widget.questID) then
  198.                 return found("quest", widget.questID, select(4, GetTaskInfo(widget.questID)))
  199.             end
  200.         end
  201. end
  202.  
  203. local function ArtifactWidget(widget)
  204.     local module = widget.module;  
  205.     if module == WORLD_QUEST_TRACKER_MODULE then
  206.             if widget.id then
  207.         return found("quest", widget.id, select(4, GetTaskInfo(widget.id)))
  208.             end
  209.     elseif widget.questID then -- World Quest Tracker support
  210.             if QuestMapFrame_IsQuestWorldQuest(widget.questID) then
  211.                 return found("quest", widget.questID, select(4, GetTaskInfo(widget.questID)))
  212.             end
  213.         end
  214. end
  215.  
  216. -- local isInArea, isOnMap, numObjectives, taskName, displayAsObjective = GetTaskInfo(questID);
  217.  
  218. customframes = {
  219.     ["AchievementFrameCriteria"] = AchievmentWidgetParent,
  220.     ["AchievementFrameSummaryAchievement"] = AchievmentWidget,
  221.     ["AchievementFrameAchievementsContainerButton"] = AchievmentWidget,
  222.     ["QuestScrollFrame"] = QuestWidget,
  223.     ["ObjectiveTrackerBlocksFrameHeader"] = TrackWidget,
  224.         ["ObjectiveTrackerBlocksFrame"] = TrackWorldQuestWidget,
  225.         ["WorldMapFrameTaskPOI"] = WolrdQuestWidget,
  226.         ["WorldQuestTrackerZonePOIWidget"] = WolrdQuestWidget, -- World Quest Tracker support
  227.         ["WorldQuestTracker_Tracker"] = TrackWorldQuestWidget -- World Quest Tracker support       
  228. }
  229.  
  230. frame:Hide()
  231. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  232. frame:SetScript("OnEvent", onEvent)
  233. frame:SetScript("OnUpdate", onUpdate)
  234.  
  235. local locale = string.sub(GetLocale(),1,2)
  236. if locale ~= "en" then
  237.     wowheadLink = "http://"..locale..".wowhead.com/"
  238.     hash = "#english-comments"
  239. else
  240.     wowheadLink = "http://www.wowhead.com/"
  241.     hash = ""
  242. end
  243.  
  244. BINDING_HEADER_WOWHEADLINK = "Wowhead Link Grabber";
  245. BINDING_NAME_WOWHEADLINKRUN = "Hotkey for displaying wowhead link"
  246.  
  247. StaticPopupDialogs["WOWHEAD_LINK_GRABBER"] = {
  248.     OnShow = function (self, data)
  249.         self.editBox:SetText(gotoLink)
  250.         self.editBox:HighlightText()
  251.     end,
  252.         EditBoxOnEscapePressed = function(self)
  253.             self:GetParent():Hide();
  254.         end,
  255.     button1 = OKAY,
  256.     editBoxWidth = 350,
  257.     hasEditBox=true,
  258.     preferredIndex = 3
  259. }
Advertisement
Add Comment
Please, Sign In to add comment