Advertisement
Namestaken

BetterTooltips BfA Update

Aug 5th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.99 KB | None | 0 0
  1. --------------------------------------------------------------------------
  2. -- BetterTooltips.lua
  3. --------------------------------------------------------------------------
  4. --[[Author: Maldarius of Arathor
  5.  
  6. Usage:  Auto-loads on login
  7.         /btt -- root slash command
  8.         /btt combat -- toggle hide/show of tooltip info while in combat
  9.         /btt help -- display in-game help in chat box
  10.  
  11. Change Log:
  12.     v2.3.1 Current Official Release
  13.         - Fixed a bug that prevented the Character Tooltip from updating properly
  14.         - Beginning prep for the coming expansion: Legion
  15.  
  16.     v2.3
  17.         - Updated for Warlord of Draenor patch 6.2.3
  18.         - Added automatic Valor Point tracking to the WoD currency section
  19.  
  20.     v2.2.2
  21.         - Verified no API or UI changes were made in WoD 6.2.2 that would affect BetterTooltips
  22.         - Enjoy flying in Draenor!
  23.    
  24.     v2.2.1
  25.         - Corrected a spacing & layout issue on the Spellbook Tooltip
  26.  
  27.     v2.2
  28.         - Updated the Character Tooltip with a WoD-specific currency
  29.           section that automatically populates with your Warlords of
  30.           Draenor currency (Apexis Crystals, Oil, Garrison Resources,
  31.           etc.)
  32.         - Moved the three "tracked" currencies in their own section in the
  33.           Character Tooltip
  34.         - Updated Spellbook Tooltip to include a breakout of
  35.           native profession skill + bonuses
  36.         - Added conditional coloring to the Spellbook Tooltip
  37.         - Updated the included Ace library packages
  38.         - Changed some of the coding to be a bit more effecient
  39.         - Still chasing the best solution for that pesky guild roster
  40.           updating bug (you sometimes have to mouseover twice to get an
  41.           updated roster if someone has very recently logged in)
  42.           NOTE: If you have expertise in this area and can help me out
  43.           with a fix, reach out to me via CurseForge
  44.           http://www.curseforge.com/projects/44177/
  45.  
  46.     v2.1
  47.         - Changed the slash command help text
  48.         - Changed coloring & formatting of all the chat box text messages
  49.         - Changed the folder name inside the addon package
  50.         - Added Change Log to the main lua file (this file)
  51.     v2.0.2
  52.         - Implemented another quick code fix because it was late when I
  53.           packaged the first TWO times...
  54.     v2.0.1
  55.         - Implemented a quick code fix because it was late when I packaged
  56.           the first time... and mistakes happen
  57.     v2.0
  58.         - Second major release version
  59.         - Added a slash command framework - [/btt]
  60.         - Added a slash command to hide the tooltip info during combat,
  61.           if desired. Use [/btt combat] to toggle the feature
  62.         - Updated function hooks to reflect any changes since 5.4 that
  63.           may affect tooltip rendering and information
  64.         - Added conditional formatting and spacing to tooltips
  65.         - Updated the Social Tooltip to better reflect the state of
  66.           Battle.net and WoW friends
  67.         - Updated the Guild Tooltip to update more frequently
  68.         - Added a "Remote Guildies" section to the Guild Tooltip to track
  69.           Mobile Armory App users
  70.     v1.7b
  71.         - Internal beta (withheld)
  72.         - Function prototyping and code testing
  73.     v1.6
  74.         - Updated the onLoad chat notice function
  75.         - Updated change log for consistency
  76.         - Removed DragonHide feature
  77.     v1.5
  78.         - Revived project on Curse - Look for version 2.0 coming July 2015!
  79.         - Updated TOC for patch 6.2
  80.     v1.4
  81.         - Updated TOC for patch 5.1 (two previous versions skipped due to
  82.           development problems)
  83.     v1.3b
  84.         - Internal beta (withheld)
  85.         - Function prototyping and code testing
  86.     v1.2b
  87.         - Internal beta (withheld)
  88.         - Function prototyping and code testing
  89.     v1.1
  90.         - Patched the Guild Tooltip code that was causing an error to be
  91.           thrown when a character was not in a guild and/or had not chosen
  92.           a faction (i.e., Pandarens)
  93.     v1.0
  94.         - First official release
  95.         - Added a MainMenuBar prep function that hides those pesky dragons
  96.     v0.4b
  97.         - Minor bug fixes
  98.     v0.3b
  99.         - Corrected error in .toc versioning
  100.     v0.2b
  101.         - Removed Mac OS-X folders and .DS_Store files
  102.     v0.1b
  103.         - Inital Public Beta Release
  104.  
  105. ]]--
  106.  
  107. BetterTooltips = LibStub("AceAddon-3.0"):NewAddon("BetterTooltips", "AceHook-3.0");
  108.  
  109. -- GLOBAL VARIABLES
  110. bttConfigCombat = false;
  111.  
  112. -- LOCAL FUNCTIONS AND HOOKS
  113. local function eventHandler(self, event, ...)
  114.     if ( event == "PLAYER_ENTERING_WORLD" ) then
  115.         self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  116.         DEFAULT_CHAT_FRAME:AddMessage(string.format("|cff00ffffBetterTooltips v2.3 for WoD:|r Successfully loaded"))
  117.     end
  118. end
  119.  
  120. local frame = CreateFrame("Frame")
  121. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  122. frame:SetScript("OnEvent", eventHandler)
  123.  
  124. local function levelcolor(level)
  125.     if level then
  126.         local color = GetQuestDifficultyColor(level)
  127.         return string.format("%02x%02x%02x", color.r*255, color.g*255, color.b*255)
  128.     end
  129. end
  130.  
  131. local colors = {}
  132. for class,color in pairs(RAID_CLASS_COLORS)
  133.     do colors[class] = string.format("%02x%02x%02x", color.r*255, color.g*255, color.b*255);
  134. end
  135.  
  136. function BetterTooltips:OnInitialize()
  137.     -- do nothing
  138. end
  139.  
  140. function BetterTooltips:OnEnable()
  141.     self:SecureHookScript(QuickJoinToastButton, "OnEnter", "OnMouseOverFriends");
  142.     self:SecureHookScript(CharacterMicroButton, "OnEnter", "OnMouseOverCharacter");
  143.     self:SecureHookScript(SpellbookMicroButton, "OnEnter", "OnMouseOverSpellbook");
  144.     self:SecureHookScript(GuildMicroButton, "OnEnter", "OnMouseOverGuild");
  145.     --self:SecureHookScript(MainMenuBarBackpackButton, "OnEnter", "OnMouseOverBackpack");
  146. end
  147.  
  148. function BetterTooltips:OnDisable()
  149.     self:UnHookAll();
  150. end
  151.  
  152. -- SOCIAL TOOLTIP
  153. function BetterTooltips:OnMouseOverFriends()
  154.     if ((UnitAffectingCombat("player")) and (bttConfigCombat)) then
  155.         -- Do Nothing
  156.     else
  157.         local numBNet, numBNetOnline = BNGetNumFriends();
  158.         local numFriends, numFriendsOnline = GetNumFriends();
  159.         local fcolor = "ffffff";
  160.         GameTooltip:AddLine(" ");
  161.        
  162.         -- Battle.net Friends
  163.         if numBNetOnline > 0 then
  164.             fcolor = "00ff00";
  165.             if numBNetOnline == 1 then
  166.                 GameTooltip:AddLine("|cff"..fcolor.."1 Battle.net Friend Online|r");
  167.             else
  168.                 GameTooltip:AddLine("|cff"..fcolor..string.format("%d Battle.net Friends Online", numBNetOnline).."|r");
  169.             end
  170.         else
  171.             GameTooltip:AddLine("|cff"..fcolor.."No Battle.net Friends Online|r");
  172.         end
  173.         for i = 1, numBNet, 1 do
  174.             local presenceID, realName, toonName, toonID, client, isOnline = BNGetFriendInfo(i);
  175.             if isOnline then
  176.                 local zone = client;
  177.                 if client == "WoW" then
  178.                     local _, _, _, zoneName = BNGetToonInfo(presenceID);
  179.                     zone = zoneName;
  180.                 end
  181.                 --GameTooltip:AddLine("|cff00fbf6"..toonName.." ("..zone..") ["..realName.."]|r");
  182.                 GameTooltip:AddLine("|cff00fbf6"..toonName.." ["..realName.."]|r");
  183.             end
  184.         end
  185.        
  186.         -- Spacer Line
  187.         if (numFriendsOnline > 0) or (numBNetOnline > 0) then
  188.             GameTooltip:AddLine(" ");
  189.         end
  190.        
  191.         -- Regular Friends
  192.         if numFriendsOnline > 0 then
  193.             fcolor = "00ff00";
  194.             if numFriendsOnline == 1 then
  195.                 GameTooltip:AddLine("|cff"..fcolor.."1 WoW Friend Online|r");
  196.             else
  197.                 GameTooltip:AddLine("|cff"..fcolor..string.format("%d WoW Friends Online", numFriendsOnline).."|r");
  198.             end
  199.         else
  200.             fcolor = "ffffff";
  201.             GameTooltip:AddLine("|cff"..fcolor.."No WoW Friends Online|r");
  202.         end
  203.         for i = 1, numFriends, 1 do
  204.             local name, level, class, area, connected, status, note = GetFriendInfo(i);
  205.             if connected then
  206.                     GameTooltip:AddDoubleLine(("|cff"..levelcolor(level)..string.format("%2d", level).."|r".."   "..string.format("|cff%s%s", colors[class:gsub(" ", ""):upper()] or "ffffff", name).."|r"),(area));
  207.             end
  208.         end
  209.        
  210.         GameTooltip:Show();
  211.     end
  212. end
  213.  
  214. local function trackCurrency()
  215.     local toTrack = {   "Apexis Crystal",
  216.                         "Garrison Resources",
  217.                         "Oil",
  218.                         "Valor",
  219.                         "Artifact Fragment",
  220.                         "Dingy Iron Coin",
  221.                         "Seal of Tempered Fate",
  222.                         "Seal of Inevitable Fate",
  223.                         "Curious Coin",
  224.                         "Coins of Air",
  225.                         "Legionfall War Supplies",
  226.                         "Order Resources",
  227.                         "Sightless Eye",
  228.                         "Timewarped Badge",
  229.                         "Lesser Charm of Good Fortune"
  230.                     }
  231.    
  232.     return toTrack
  233. end
  234.  
  235. local function trackableCurrency(checkCurrency)
  236.     for _,currency in ipairs(trackCurrency()) do
  237.         if checkCurrency == currency then
  238.             return true
  239.         end
  240.     end
  241.    
  242.     return false
  243. end
  244.  
  245. -- CHARACTER INFO TOOLTIP
  246. function BetterTooltips:OnMouseOverCharacter()
  247.     if ((UnitAffectingCombat("player")) and (bttConfigCombat)) then
  248.         -- Do Nothing
  249.     else
  250.         --Durability
  251.         local itemSlots = {
  252.         "HeadSlot",
  253.         "ShoulderSlot",
  254.         "ChestSlot",
  255.         "WristSlot",
  256.         "HandsSlot",
  257.         "WaistSlot",
  258.         "LegsSlot",
  259.         "FeetSlot",
  260.         "MainHandSlot",
  261.         "SecondaryHandSlot",
  262.         }
  263.         if not GetNumSubgroupMembers then
  264.             tinsert(itemSlots, "RangedSlot")
  265.         end
  266.         local durability, maximum = 0, 0
  267.         for i=1, #itemSlots do
  268.             local slotId = GetInventorySlotInfo(itemSlots[i])
  269.             local d, m = GetInventoryItemDurability(slotId)
  270.             durability = durability + (d or 0)
  271.             maximum = maximum + (m or 0)
  272.         end
  273.         local duraLast = durability / maximum * 100;
  274.         local duraColor = "ffffff";
  275.         if duraLast > 74 then duraColor = "00ff00"
  276.             elseif duraLast > 59 then duraColor = "9acd32"
  277.             elseif duraLast > 39 then duraColor = "ffff00"
  278.             elseif duraLast > 19 then duraColor = "ffa500"
  279.             elseif duraLast > 9 then duraColor = "ff4500"
  280.             else duraColor = "ff0000"
  281.         end
  282.         GameTooltip:AddDoubleLine(("Durability: "),(("|T%s:0|t"):format("Interface\\Icons\\Trade_BlackSmithing").."  |cff"..duraColor..("%.0f%%"):format(duraLast).."|r"));
  283.         GameTooltip:AddLine(" ");
  284.         --Money
  285.         local money = GetCoinTextureString(GetMoney("player"))
  286.         GameTooltip:AddDoubleLine(("Money: "),("|cffffffff"..money.."|r"))
  287.         --Currency
  288.         local numCurTypes = GetCurrencyListSize()
  289.         local warlordsCount = 0;
  290.         for i = 1, numCurTypes, 1 do
  291.             local name, isHeader, isExpanded, isUnused, isWatched, count, icon = GetCurrencyListInfo(i);
  292.            
  293.             if count == nil then
  294.                 GameTooltip:AddLine(" ");
  295.                 GameTooltip:AddLine(name);
  296.             elseif count > 0 then
  297.                 --if trackableCurrency(name) then
  298.                     GameTooltip:AddDoubleLine("|cffffffff"..name.."|r","|cffffffff"..("%d%s|T%s:0|t"):format(count,"  ",icon).."|r");
  299.                 --end
  300.             end
  301.         end
  302.        
  303.         --[[
  304.         local watchCount = 0;
  305.         for i = 1, numCurTypes, 1 do
  306.             local name, isHeader, isExpanded, isUnused, isWatched, count, icon = GetCurrencyListInfo(i);
  307.             if (isWatched and name ~= "Apexis Crystal" and name ~= "Garrison Resources" and name ~= "Oil" and name ~= "Valor" and name ~= "Artifact Fragment" and name ~= "Dingy Iron Coin" and name ~= "Seal of Tempered Fate" and name ~= "Seal of Inevitable Fate") then
  308.                 if watchCount == 0 then
  309.                     GameTooltip:AddLine(" ");
  310.                     GameTooltip:AddLine("Tracked Currency:");
  311.                 end
  312.                 GameTooltip:AddDoubleLine("|cffffffff"..name.."|r","|cffffffff"..("%d%s|T%s:0|t"):format(count,"  ",icon).."|r");
  313.                 watchCount = watchCount + 1
  314.             end
  315.         end
  316.         --]]
  317.         GameTooltip:Show();
  318.     end
  319. end
  320.  
  321. -- SPELLBOOK & ABILITIES TOOLTIP
  322. local function AddSkillToTooltip(skillid, fallback)
  323.     if (not skillid) then
  324.         return GameTooltip:AddDoubleLine(fallback, "See Trainer!");
  325.     else
  326.         local name, icon, skillLevel, maxSkillLevel, numSpells, spellOffset, skillLine, skillModifier  = GetProfessionInfo(skillid);
  327.        
  328.         if (skillLevel < maxSkillLevel) then
  329.             if (skillModifier ~= 0) then
  330.                 skillLevel = "|cff00ff00"..("%d"):format(skillLevel + skillModifier).."|r (|cffeeeeee"..("%d"):format(skillLevel).."+|r|cff00ff00"..("%d"):format(skillModifier).."|r)";
  331.             else
  332.                 skillLevel = "|cffeeeeee"..("%d"):format(skillLevel).."|r";
  333.             end
  334.         else
  335.             skillLevel = ("%d"):format(skillLevel);
  336.         end
  337.         GameTooltip:AddDoubleLine(("|cffffffff"..("|T%s:0|t%s"):format(icon, "  "..name).."|r"),(skillLevel..("/%d"):format(maxSkillLevel)));
  338.     end
  339. end
  340.  
  341. function BetterTooltips:OnMouseOverSpellbook()
  342.     if (UnitAffectingCombat("player") and bttConfigCombat) then
  343.         -- Do Nothing
  344.     else
  345.         local prof1, prof2, arch, fish, cook, firstAid = GetProfessions();
  346.         GameTooltip:AddLine(" ");  
  347.         GameTooltip:AddLine("Professions");
  348.         AddSkillToTooltip(prof1, PROFESSIONS_FIRST_PROFESSION);
  349.         AddSkillToTooltip(prof2, PROFESSIONS_SECOND_PROFESSION);
  350.         AddSkillToTooltip(arch, PROFESSIONS_ARCHAEOLOGY);
  351.         AddSkillToTooltip(fish, PROFESSIONS_FISHING);
  352.         AddSkillToTooltip(cook, PROFESSIONS_COOKING);
  353.         AddSkillToTooltip(firstAid, PROFESSIONS_FIRST_AID);
  354.         GameTooltip:Show();
  355.     end
  356. end
  357.  
  358. -- GUILD TOOLTIP
  359. function BetterTooltips:OnMouseOverGuild()
  360.     if (UnitAffectingCombat("player") and bttConfigCombat) then
  361.         -- Do Nothing
  362.     else
  363.         if IsInGuild() then
  364.             GuildRoster();
  365.             local guildName, guildRankName, guildRankIndex = GetGuildInfo("player");
  366.             local numGuildMembers, numOnline = GetNumGuildMembers();
  367.             local sMsg = "";
  368.             local spacer = true;
  369.             if (numOnline) == 1 then
  370.                 sMsg = "1 Guildie Online";
  371.             else
  372.                 sMsg = string.format("%0d Guildies Online", numOnline);
  373.             end
  374.             GameTooltip:AddLine("|cffffffff"..guildName.." - |r".."|cff00ff00"..sMsg.."|r");
  375.  
  376.             for i = 1, numOnline, 1 do
  377.                 local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile = GetGuildRosterInfo(i);
  378.                 if online then
  379.                     if (level < 100) then
  380.                         GameTooltip:AddDoubleLine(("|cff"..levelcolor(level).."  "..string.format("%2d", level).."|r".."   "..string.format("|cff%s%s", colors[classFileName] or "ffffff", name).."|r"),(zone));
  381.                     else
  382.                         GameTooltip:AddDoubleLine(("|cff"..levelcolor(level)..string.format("%2d", level).."|r".."   "..string.format("|cff%s%s", colors[classFileName] or "ffffff", name).."|r"),(zone));
  383.                     end
  384.                 end
  385.             end
  386.            
  387.             for i = 1, numGuildMembers, 1 do
  388.                 local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile = GetGuildRosterInfo(i);
  389.                 if isMobile then
  390.                     if (spacer) then
  391.                         GameTooltip:AddLine(" ");
  392.                         GameTooltip:AddLine("Remote Guildies (Mobile Armory App)");
  393.                         spacer = false;
  394.                     end
  395.                     if (level < 100) then
  396.                         GameTooltip:AddLine(("|cff"..levelcolor(level).."  "..string.format("%2d", level).."|r".."   "..string.format("|cff%s%s", colors[classFileName] or "ffffff", name).."|r"));
  397.                     else
  398.                         GameTooltip:AddLine(("|cff"..levelcolor(level)..string.format("%2d", level).."|r".."   "..string.format("|cff%s%s", colors[classFileName] or "ffffff", name).."|r"));
  399.                     end
  400.                 end
  401.             end
  402.            
  403.         else
  404.             GameTooltip:AddLine("You are not currently in a guild.");
  405.             GameTooltip:AddLine(" ");
  406.             GameTooltip:AddLine("Once you join a guild, information about your guild mates who are logged on will appear in this tooltip.");
  407.         end
  408.         GameTooltip:Show();
  409.     end
  410. end
  411.  
  412. --[[ BACKPACK INFO TOOLTIP (REAGENT COUNTER BASED ON PROFESSIONS)
  413. function BetterTooltips:OnMouseOverBackpack()
  414.     if ((UnitAffectingCombat("player")) and (bttConfigCombat)) then
  415.         -- Do Nothing
  416.     else
  417.         --Currency
  418.         GameTooltip:AddLine(" ");
  419.         GameTooltip:AddLine("Currency:");
  420.         local numCurTypes = GetCurrencyListSize()
  421.         for i = 1, numCurTypes, 1 do
  422.             local name, isHeader, isExpanded, isUnused, isWatched, count, icon = GetCurrencyListInfo(i);
  423.             if (isHeader and not isUnused and name ~= "Dungeon and Raid") then
  424.                 if (i > 1) then
  425.                     GameTooltip:AddLine(" ");
  426.                 end
  427.                 GameTooltip:AddLine(name);
  428.             elseif (not isHeader and not isUnused and count > 0) then
  429.                 GameTooltip:AddDoubleLine("|cffffffff"..name.."|r","|cffffffff"..("%d%s|T%s:0|t"):format(count,"  ",icon).."|r");
  430.             end
  431.         end
  432.  
  433.         GameTooltip:Show();
  434.     end
  435. end]]
  436.  
  437. --[[ WORLD/FRAME UNIT TOOLTIP (AVERAGE ITEM LEVEL)
  438. function BetterTooltips:OnMouseOverBackpack()
  439.     if ((UnitAffectingCombat("player")) and (bttConfigCombat)) then
  440.         -- Do Nothing
  441.     else
  442.         --Currency
  443.         GameTooltip:AddLine(" ");
  444.         GameTooltip:AddLine("Currency:");
  445.         local numCurTypes = GetCurrencyListSize()
  446.         for i = 1, numCurTypes, 1 do
  447.             local name, isHeader, isExpanded, isUnused, isWatched, count, icon = GetCurrencyListInfo(i);
  448.             if (isHeader and not isUnused and name ~= "Dungeon and Raid") then
  449.                 if (i > 1) then
  450.                     GameTooltip:AddLine(" ");
  451.                 end
  452.                 GameTooltip:AddLine(name);
  453.             elseif (not isHeader and not isUnused and count > 0) then
  454.                 GameTooltip:AddDoubleLine("|cffffffff"..name.."|r","|cffffffff"..("%d%s|T%s:0|t"):format(count,"  ",icon).."|r");
  455.             end
  456.         end
  457.  
  458.         GameTooltip:Show();
  459.     end
  460. end]]
  461.  
  462.  
  463. -- SLASH COMMANDS
  464. SLASH_BTTCONFIG1 = "/btt";
  465. function SlashCmdList.BTTCONFIG(arg)
  466.    
  467.     -- Combat Visibility Toggle
  468.     if (arg == "combat") then
  469.         -- Toggle and echo current setting
  470.         bttConfigCombat = (bttConfigCombat == false);
  471.         if (bttConfigCombat) then
  472.             DEFAULT_CHAT_FRAME:AddMessage("|cffddaa11BetterTooltips will be hidden during combat|r");
  473.         else
  474.             DEFAULT_CHAT_FRAME:AddMessage("|cffddaa11BetterTooltips will show both in and out of combat|r");
  475.         end
  476.     else
  477.         -- Print help
  478.         DEFAULT_CHAT_FRAME:AddMessage("|cffddaa11BetterTooltips v2.0.3 -- |cffffffffCommand Help:|r");
  479.         DEFAULT_CHAT_FRAME:AddMessage("|cffeeee00/btt combat|r".."|cff4de6cc -- Toggle hide/show BetterTooltips during combat|r");
  480.         DEFAULT_CHAT_FRAME:AddMessage("|cffeeee00/btt help|r".."|cff4de6cc -- Display this help menu|r");
  481.         DEFAULT_CHAT_FRAME:AddMessage("|cffddaa11More to come... send in feature/command requests!|r");
  482.     end
  483. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement