GeodesicDragon

GuildTooltip.lua

Jun 11th, 2021
674
3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Localisation
  2. local AddonName, AddonTable = ...
  3. local L = AddonTable.Localize
  4. local AddonTitle = select(2, GetAddOnInfo(AddonName))
  5. local PlainAddonTitle = AddonTitle:gsub("|c........", ""):gsub("|r", "")
  6.  
  7. -- Create frame and register events
  8. local GTWelcome = CreateFrame("Frame")
  9. GTWelcome:RegisterEvent("ADDON_LOADED")
  10. GTWelcome:RegisterEvent("PLAYER_TARGET_CHANGED")
  11.  
  12. local function GTEventHandler(self, event, arg1) -- Call this function when a registered event occurs
  13.  
  14. if event == "ADDON_LOADED" and arg1 == "GuildTooltip" then
  15.     if GTConfig == nil or GTConfig == "" then -- Create default settings if they don't exist already
  16.         GTConfig = {
  17.             ["Colour"] = "ENABLED",
  18.             ["HealthBar"] = "ENABLED",
  19.             ["Titles"] = "ENABLED",
  20.             ["Realms"] = "ENABLED",
  21.             ["GuildRank"] = "DISABLED",
  22.             ["FontSize"] = "12"
  23.         }
  24.     end
  25.    
  26.     -- Add new settings if the user updated from a previous version of the addon that didn't have them
  27.     if GTConfig.HealthBar == nil then GTConfig.HealthBar = 'ENABLED' end
  28.     if GTConfig.Titles == nil then GTConfig.Titles = 'ENABLED' end
  29.     if GTConfig.Realms == nil then GTConfig.Realms = 'ENABLED' end
  30.     if GTConfig.GuildRank == nil then GTConfig.GuildRank = 'DISABLED' end
  31.     if GTConfig.FontSize == nil then GTConfig.FontSize = '12' end
  32. elseif event == "PLAYER_TARGET_CHANGED" then
  33.     -- Compatibility with ShadowedUnitFrames addon
  34.     if IsAddOnLoaded("ShadowedUnitFrames") == true then
  35.         SUFUnittarget:SetScript("OnEnter", function(self)
  36.             if UnitIsPlayer("target") and not UnitIsUnit("target", "player") then
  37.                 GameTooltip:Show()
  38.                 CreateGTTooltip("target")
  39.             end
  40.         end)
  41.        
  42.         SUFUnittarget:SetScript("OnLeave", function(self)
  43.             if GTConfig.HealthBar == "ENABLED" then
  44.                 GameTooltipStatusBar:Hide()
  45.             elseif GTConfig.HealthBar == "DISABLED" then
  46.                 GameTooltipStatusBar:Hide()
  47.             end
  48.    
  49.             GameTooltipHeaderText:SetFont("Fonts\\FRIZQT__.ttf", 14)
  50.         end)
  51.     end
  52. end
  53.  
  54. end
  55.  
  56. GTWelcome:SetScript("OnEvent", GTEventHandler)
  57.  
  58. -- Game Tooltip
  59.  
  60. GameTooltip:HookScript("OnTooltipSetUnit", function(self)
  61.     if UnitIsPlayer("mouseover") and not UnitIsUnit("mouseover", "player") then
  62.         CreateGTTooltip("mouseover") -- Call the tooltip creation function using the 'mouseover' argument
  63.     end
  64. end)
  65.  
  66. GameTooltip:HookScript("OnTooltipCleared", function(self)
  67.     if GTConfig.HealthBar == "ENABLED" then
  68.         GameTooltipStatusBar:Hide()
  69.     elseif GTConfig.HealthBar == "DISABLED" then
  70.         GameTooltipStatusBar:Hide()
  71.     end
  72.    
  73.     GameTooltipHeaderText:SetFont("Fonts\\FRIZQT__.ttf", 14)
  74. end)
  75.  
  76. GameTooltip:HookScript("OnLeave", function(self)
  77.     GameTooltip:Show()
  78. end)
  79.  
  80. -- Target Frame
  81.  
  82. TargetFrame:HookScript("OnEnter", function(self)
  83.     if UnitIsPlayer("target") and not UnitIsUnit("target", "player") then
  84.         CreateGTTooltip("target") -- Call the tooltip creation function using the 'target' argument
  85.     end
  86. end)
  87.  
  88. TargetFrame:HookScript("OnLeave", function(self)
  89.     -- Reset font size to (what I hope is) the default
  90.     if GTConfig.HealthBar == "ENABLED" then
  91.         GameTooltipStatusBar:Hide()
  92.     elseif GTConfig.HealthBar == "DISABLED" then
  93.         GameTooltipStatusBar:Hide()
  94.     end
  95.    
  96.     GameTooltipHeaderText:SetFont("Fonts\\FRIZQT__.ttf", 14)
  97.     GameTooltip:Show()
  98. end)
  99.  
  100. -- Party/Raid Frames
  101. -- I doubt this will ever happen, as I can't get it working no matter what I try.
  102.  
  103. -- Tooltip Creation
  104.  
  105. function CreateGTTooltip(person)
  106.  
  107.     GameTooltip:ClearLines() -- Clear tooltip so we can repopulate it.
  108.  
  109.     GameTooltipHeaderText:SetFont("Fonts\\FRIZQT__.ttf", tonumber(GTConfig.FontSize)) -- Set text size to that determined by the user in addon settings
  110.     local guildName, guildRankName, guildRankIndex = GetGuildInfo(person);
  111.     local playerlevel = UnitLevel(person)
  112.     local race = UnitRace(person)
  113.     local localizedClass, englishClass, classIndex = UnitClass(person)
  114.     local myRealm = GetRealmName("player")
  115.            
  116.     local theirname, theirRealm = UnitName(person)
  117.     local name
  118.    
  119.     if theirRealm ~= nil then
  120.         if GTConfig.Realms == "DISABLED" then -- Show or hide the player's realm (used in battlegrounds)
  121.             if GTConfig.Titles == "ENABLED" then
  122.                 name = UnitPVPName(person) -- Show or hide the player's PvP rank
  123.             elseif GTConfig.Titles == "DISABLED" then
  124.                 name = UnitName(person)
  125.             end
  126.         elseif GTConfig.Realms == "ENABLED" then
  127.             if GTConfig.Titles == "ENABLED" then
  128.                 name = UnitPVPName(person) .. "-" .. theirRealm
  129.             elseif GTConfig.Titles == "DISABLED" then
  130.                 name = UnitName(person) .. "-" .. theirRealm
  131.             end
  132.         end
  133.     elseif theirRealm == myRealm or theirRealm == nil then
  134.         if GTConfig.Titles == "ENABLED" then
  135.             name = UnitPVPName(person)
  136.         elseif GTConfig.Titles == "DISABLED" then
  137.             name = UnitName(person)
  138.         end
  139.     end
  140.    
  141.     if playerlevel == -1 then playerlevel = "??" end -- If the player is skulled, show 'Level ??' instead of 'Level -1' in their tooltip
  142.    
  143.     if GTConfig.Colour == "ENABLED" then -- If this setting is enabled, the players name is shown using their class colour, and their guild (if applicable) is shown in the default guild chat green       
  144.         if guildName == nil then
  145.             GameTooltip:AddLine("|c" .. RAID_CLASS_COLORS[englishClass].colorStr .. name .. "|r")
  146.             GameTooltip:AddLine(LEVEL .. " " .. playerlevel .. " " .. race .. " |c" .. RAID_CLASS_COLORS[englishClass].colorStr .. localizedClass .. "|r", 1, 1, 1, true)
  147.         elseif guildName ~= nil then
  148.             if GTConfig.GuildRank == "ENABLED" then
  149.                 GameTooltip:AddLine("|c" .. RAID_CLASS_COLORS[englishClass].colorStr .. name .. "|r\n|cFF40FB40" .. guildRankName .. " of " .. guildName .. "|r")
  150.                 GameTooltip:AddLine(LEVEL .. " " .. playerlevel .. " " .. race .. " |c" .. RAID_CLASS_COLORS[englishClass].colorStr .. localizedClass .. "|r", 1, 1, 1, true)
  151.             elseif GTConfig.GuildRank == "DISABLED" then
  152.                 GameTooltip:AddLine("|c" .. RAID_CLASS_COLORS[englishClass].colorStr .. name .. "|r\n|cFF40FB40" .. guildName .. "|r")
  153.                 GameTooltip:AddLine(LEVEL .. " " .. playerlevel .. " " .. race .. " |c" .. RAID_CLASS_COLORS[englishClass].colorStr .. localizedClass .. "|r", 1, 1, 1, true)
  154.             end
  155.         end
  156.     elseif GTConfig.Colour == "DISABLED" then -- If this setting is disabled, show everything without colour
  157.         if guildName == nil then
  158.             GameTooltip:AddLine(name)
  159.             GameTooltip:AddLine(LEVEL .. " " .. playerlevel .. " " .. race .. " " .. localizedClass, 1, 1, 1, true)
  160.         elseif guildName ~= nil then
  161.             if GTConfig.GuildRank == "ENABLED" then
  162.                 GameTooltip:AddLine(name .. "\n" .. guildRankName .. " of " .. guildName)
  163.                 GameTooltip:AddLine(LEVEL .. " " .. playerlevel .. " " .. race .. " " .. localizedClass, 1, 1, 1, true)
  164.             elseif GTConfig.GuildRank == "DISABLED" then
  165.                 GameTooltip:AddLine(name .. "\n" .. guildName)
  166.                 GameTooltip:AddLine(LEVEL .. " " .. playerlevel .. " " .. race .. " " .. localizedClass, 1, 1, 1, true)
  167.             end
  168.         end
  169.     end    
  170.        
  171.     if GTConfig.HealthBar == "ENABLED" then -- Show or hide the health bar under the tooltip
  172.         GameTooltipStatusBar:Show()
  173.     elseif GTConfig.HealthBar == "DISABLED" then
  174.         GameTooltipStatusBar:Hide()
  175.     end
  176.    
  177.     GameTooltip:Show() -- Show the tooltip
  178.  
  179. end
RAW Paste Data