Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.10 KB | None | 0 0
  1. -- Freebtip by Freebaser
  2.  
  3. local F, C = unpack(Aurora)
  4.  
  5. local _, ns = ...
  6.  
  7. local cfg = {
  8.     font = C.media.font2,
  9.     fontsize = 8,
  10.     outline = "OUTLINEMONOCHROME",
  11.     tex = C.media.backdrop,
  12.  
  13.     scale = 1,
  14.     point = { "BOTTOMRIGHT", "BOTTOMRIGHT", -100, 224 },
  15.     cursor = false,
  16.  
  17.     hideTitles = false,
  18.     hideRealm = false,
  19.  
  20.     backdrop = {
  21.         bgFile = "Interface\\Buttons\\WHITE8x8",
  22.         edgeFile = C.media.backdrop,
  23.         tile = true,
  24.         tileSize = 0,
  25.         edgeSize = 1,
  26.         insets = { left = 1, right = 1, top = 1, bottom = 1 },
  27.     },
  28.     bgcolor = { r=0, g=0, b=0, t=0.5 },
  29.     bdrcolor = { r=0, g=0, b=0},
  30.     gcolor = { r=1, g=0.1, b=0.8 },
  31.  
  32.     you = "<You>",
  33.     boss = "??",
  34.     colorborderClass = false,
  35.     combathide = false,
  36.     combathideALL = false,
  37.  
  38.     powerbar = false,
  39.     powerManaOnly = false,
  40. }
  41. ns.cfg = cfg
  42.  
  43. local colors = {power = {}}
  44. for power, color in next, PowerBarColor do
  45.     if(type(power) == 'string') then
  46.         colors.power[power] = {color.r, color.g, color.b}
  47.     end
  48. end
  49.  
  50. colors.power['MANA'] = {.31,.45,.63}
  51. colors.power['RAGE'] = {.69,.31,.31}
  52.  
  53. local classification = {
  54.     elite = "+",
  55.     rare = " R",
  56.     rareelite = " R+",
  57. }
  58.  
  59. local numberize = function(val)
  60.     if (val >= 1e6) then
  61.         return ("%.1fm"):format(val / 1e6)
  62.     elseif (val >= 1e3) then
  63.         return ("%.1fk"):format(val / 1e3)
  64.     else
  65.         return ("%d"):format(val)
  66.     end
  67. end
  68.  
  69. local find = string.find
  70. local format = string.format
  71. local hex = function(color)
  72.     return format('|cff%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
  73. end
  74.  
  75. local function unitColor(unit)
  76.     local color = { r=1, g=1, b=1 }
  77.     if UnitIsPlayer(unit) then
  78.         local _, class = UnitClass(unit)
  79.         color = RAID_CLASS_COLORS[class]
  80.         return color
  81.     else
  82.         local reaction = UnitReaction(unit, "player")
  83.         if reaction then
  84.             color = FACTION_BAR_COLORS[reaction]
  85.             return color
  86.         end
  87.     end
  88.     return color
  89. end
  90.  
  91. function GameTooltip_UnitColor(unit)
  92.     local color = unitColor(unit)
  93.     return color.r, color.g, color.b
  94. end
  95.  
  96. local function getTarget(unit)
  97.     if UnitIsUnit(unit, "player") then
  98.         return ("|cffff0000%s|r"):format(cfg.you)
  99.     else
  100.         return hex(unitColor(unit))..UnitName(unit).."|r"
  101.     end
  102. end
  103.  
  104. local function UpdatePower()
  105.     return function(self, elapsed)
  106.         self.elapsed = self.elapsed + elapsed
  107.         if self.elapsed < .25 then return end
  108.  
  109.         local unit = self.unit
  110.         if(unit) then
  111.             local min, max = UnitPower(unit), UnitPowerMax(unit)
  112.             if(max ~= 0) then
  113.                 self:SetValue(min)
  114.  
  115.                 local pp = numberize(min).." / "..numberize(max)
  116.                 self.text:SetText(pp)
  117.             end
  118.         end
  119.        
  120.         self.elapsed = 0
  121.     end
  122. end
  123.  
  124. local function HidePower(powerbar)
  125.     if powerbar then
  126.         powerbar:Hide()
  127.  
  128.         if powerbar.text then
  129.             powerbar.text:SetText(nil)
  130.         end
  131.     end
  132. end
  133.  
  134. local function ShowPowerBar(self, unit, statusbar)
  135.     local powerbar = _G[self:GetName().."FreebTipPowerBar"]
  136.     if not unit then return HidePower(powerbar) end
  137.  
  138.     local min, max = UnitPower(unit), UnitPowerMax(unit)
  139.     local ptype, ptoken = UnitPowerType(unit)
  140.  
  141.     if(max == 0 or (cfg.powerManaOnly and ptoken ~= 'MANA')) then
  142.         return HidePower(powerbar)
  143.     end
  144.  
  145.     if(not powerbar) then
  146.         powerbar = CreateFrame("StatusBar", self:GetName().."FreebTipPowerBar", statusbar)
  147.         powerbar:SetHeight(statusbar:GetHeight())
  148.         powerbar:SetWidth(0)
  149.         powerbar:SetStatusBarTexture(cfg.tex, "OVERLAY")
  150.         powerbar.elapsed = 0
  151.         powerbar:SetScript("OnUpdate", UpdatePower())
  152.  
  153.         local bg = powerbar:CreateTexture(nil, "BACKGROUND")
  154.         bg:SetAllPoints(powerbar)
  155.         bg:SetTexture(cfg.tex)
  156.         bg:SetVertexColor(0.5, 0.5, 0.5, 0.5)
  157.     end
  158.     powerbar.unit = unit
  159.  
  160.     powerbar:SetMinMaxValues(0, max)
  161.     powerbar:SetValue(min)
  162.  
  163.     local pcolor = colors.power[ptoken]
  164.     if(pcolor) then
  165.         powerbar:SetStatusBarColor(pcolor[1], pcolor[2], pcolor[3])
  166.     end
  167.  
  168.     powerbar:SetPoint("LEFT", statusbar, "LEFT", 0, -(statusbar:GetHeight()) - 5)
  169.     powerbar:SetPoint("RIGHT", self, "RIGHT", -9, 0)
  170.  
  171.     self:AddLine(" ")
  172.     powerbar:Show()
  173.  
  174.     if(not powerbar.text) then
  175.         powerbar.text = powerbar:CreateFontString(nil, "OVERLAY")
  176.         powerbar.text:SetPoint("CENTER", powerbar)
  177.         powerbar.text:SetFont(cfg.font, 12, cfg.outline)
  178.         powerbar.text:Show()
  179.     end
  180.  
  181.     local pp = numberize(min).." / "..numberize(max)
  182.     powerbar.text:SetText(pp)
  183. end
  184.  
  185. GameTooltip:HookScript("OnTooltipSetUnit", function(self)
  186.     local name, unit = self:GetUnit()
  187.  
  188.     if unit then
  189.         if cfg.combathide and InCombatLockdown() then
  190.             return self:Hide()
  191.         end
  192.  
  193.         local color = unitColor(unit)
  194.         local ricon = GetRaidTargetIndex(unit)
  195.  
  196.         if ricon then
  197.             local text = GameTooltipTextLeft1:GetText()
  198.             GameTooltipTextLeft1:SetText(("%s %s"):format(ICON_LIST[ricon].."14|t", text))
  199.         end
  200.  
  201.         if UnitIsPlayer(unit) then
  202.             self:AppendText((" |cff00cc00%s|r"):format(UnitIsAFK(unit) and CHAT_FLAG_AFK or
  203.             UnitIsDND(unit) and CHAT_FLAG_DND or
  204.             not UnitIsConnected(unit) and "<DC>" or ""))
  205.  
  206.             if cfg.hideTitles then
  207.                 local title = UnitPVPName(unit)
  208.                 if title then
  209.                     local text = GameTooltipTextLeft1:GetText()
  210.                     title = title:gsub(name, "")
  211.                     text = text:gsub(title, "")
  212.                     if text then GameTooltipTextLeft1:SetText(text) end
  213.                 end
  214.             end
  215.  
  216.             if cfg.hideRealm then
  217.                 local _, realm = UnitName(unit)
  218.                 if realm then
  219.                     local text = GameTooltipTextLeft1:GetText()
  220.                     text = text:gsub("- "..realm, "")
  221.                     if text then GameTooltipTextLeft1:SetText(text) end
  222.                 end
  223.             end
  224.  
  225.             local unitGuild = GetGuildInfo(unit)
  226.             local text2 = GameTooltipTextLeft2:GetText()
  227.             if unitGuild and text2 and text2:find("^"..unitGuild) then 
  228.                 GameTooltipTextLeft2:SetTextColor(cfg.gcolor.r, cfg.gcolor.g, cfg.gcolor.b)
  229.             end
  230.         end
  231.  
  232.  
  233.         local alive = not UnitIsDeadOrGhost(unit)
  234.         local level = UnitLevel(unit)
  235.  
  236.         if level then
  237.             local unitClass = UnitIsPlayer(unit) and hex(color)..UnitClass(unit).."|r" or ""
  238.             local creature = not UnitIsPlayer(unit) and UnitCreatureType(unit) or ""
  239.             local diff = GetQuestDifficultyColor(level)
  240.  
  241.             if level == -1 then
  242.                 level = "|cffff0000"..cfg.boss
  243.             end
  244.  
  245.             local classify = UnitClassification(unit)
  246.             local textLevel = ("%s%s%s|r"):format(hex(diff), tostring(level), classification[classify] or "")
  247.  
  248.             for i=2, self:NumLines() do
  249.                 local tiptext = _G["GameTooltipTextLeft"..i]
  250.                 if tiptext:GetText():find(LEVEL) then
  251.                     if alive then
  252.                         tiptext:SetText(("%s %s%s %s"):format(textLevel, creature, UnitRace(unit) or "", unitClass):trim())
  253.                     else
  254.                         tiptext:SetText(("%s %s"):format(textLevel, "|cffCCCCCC"..DEAD.."|r"):trim())
  255.                     end
  256.                 end
  257.  
  258.                 if tiptext:GetText():find(PVP) then
  259.                     tiptext:SetText(nil)
  260.                 end
  261.             end
  262.         end
  263.  
  264.         if not alive then
  265.             GameTooltipStatusBar:Hide()
  266.         end
  267.  
  268.         if UnitExists(unit.."target") then
  269.             local tartext = ("%s: %s"):format(TARGET, getTarget(unit.."target"))
  270.             self:AddLine(tartext)
  271.         end
  272.  
  273.         GameTooltipStatusBar:SetStatusBarColor(color.r, color.g, color.b)
  274.     else
  275.         for i=2, self:NumLines() do
  276.             local tiptext = _G["GameTooltipTextLeft"..i]
  277.  
  278.             if tiptext:GetText():find(PVP) then
  279.                 tiptext:SetText(nil)
  280.             end
  281.         end
  282.  
  283.         GameTooltipStatusBar:SetStatusBarColor(0, .9, 0)
  284.     end
  285.  
  286.     if GameTooltipStatusBar:IsShown() then
  287.         self:AddLine(" ")
  288.         GameTooltipStatusBar:ClearAllPoints()
  289.         GameTooltipStatusBar:SetPoint("LEFT", self:GetName().."TextLeft"..self:NumLines(), "LEFT", 0, -2)
  290.         GameTooltipStatusBar:SetPoint("RIGHT", self, -9, 0)
  291.  
  292.         if cfg.powerbar then
  293.             ShowPowerBar(self, unit, GameTooltipStatusBar)
  294.         end
  295.     end
  296. end)
  297.  
  298. GameTooltipStatusBar:SetStatusBarTexture(cfg.tex)
  299. local bg = GameTooltipStatusBar:CreateTexture(nil, "BACKGROUND")
  300. bg:SetAllPoints(GameTooltipStatusBar)
  301. bg:SetTexture(cfg.tex)
  302. bg:SetVertexColor(0,0,0,1)
  303. bg:SetPoint("TOPLEFT", GameTooltipStatusBar, -1, 1)
  304. bg:SetPoint("BOTTOMRIGHT", GameTooltipStatusBar, 1, -1)
  305.  
  306. GameTooltipStatusBar:SetScript("OnValueChanged", function(self, value)
  307.     if not value then
  308.         return
  309.     end
  310.     local min, max = self:GetMinMaxValues()
  311.     if (value < min) or (value > max) then
  312.         return
  313.     end
  314.     local _, unit = GameTooltip:GetUnit()
  315.     if unit then
  316.         min, max = UnitHealth(unit), UnitHealthMax(unit)
  317.         if not self.text then
  318.             self.text = self:CreateFontString(nil, "OVERLAY")
  319.             self.text:SetPoint("CENTER", GameTooltipStatusBar)
  320.             self.text:SetFont(cfg.font, 8, cfg.outline)
  321.         end
  322.         self.text:Hide()
  323.         local hp = numberize(min).." / "..numberize(max)
  324.         self.text:SetText(hp)
  325.     end
  326. end)
  327.  
  328. hooksecurefunc("GameTooltip_SetDefaultAnchor", function(tooltip, parent)
  329.     local frame = GetMouseFocus()
  330.     if cfg.cursor and frame == WorldFrame then
  331.         tooltip:SetOwner(parent, "ANCHOR_CURSOR")
  332.     else
  333.         tooltip:SetOwner(parent, "ANCHOR_NONE")
  334.         tooltip:SetPoint(cfg.point[1], UIParent, cfg.point[2], cfg.point[3], cfg.point[4])
  335.     end
  336.     tooltip.default = 1
  337. end)
  338.  
  339. local function setBakdrop(frame)
  340.     frame:SetBackdrop(cfg.backdrop)
  341.     frame:SetScale(cfg.scale)
  342.  
  343.     frame.freebBak = true
  344. end
  345.  
  346. local function style(frame)
  347.     if not frame.freebBak then
  348.         setBakdrop(frame)
  349.     end
  350.  
  351.     frame:SetBackdropColor(cfg.bgcolor.r, cfg.bgcolor.g, cfg.bgcolor.b, cfg.bgcolor.t)
  352.     frame:SetBackdropBorderColor(cfg.bdrcolor.r, cfg.bdrcolor.g, cfg.bdrcolor.b)
  353.  
  354.  
  355.     if cfg.colorborderClass then
  356.         local _, unit = GameTooltip:GetUnit()
  357.         if UnitIsPlayer(unit) then
  358.             frame:SetBackdropBorderColor(GameTooltip_UnitColor(unit))
  359.         end
  360.     end
  361.  
  362.     if frame.NumLines then
  363.         for index=1, frame:NumLines() do
  364.             if index == 1 then
  365.                 _G[frame:GetName()..'TextLeft'..index]:SetFont(cfg.font, cfg.fontsize, cfg.outline)
  366.             else
  367.                 _G[frame:GetName()..'TextLeft'..index]:SetFont(cfg.font, cfg.fontsize, cfg.outline)
  368.             end
  369.             _G[frame:GetName()..'TextRight'..index]:SetFont(cfg.font, cfg.fontsize, cfg.outline)
  370.         end
  371.     end
  372. end
  373. ns.style = style
  374.  
  375. local tooltips = {
  376.     GameTooltip,
  377.     ItemRefTooltip,
  378.     ShoppingTooltip1,
  379.     ShoppingTooltip2,
  380.     ShoppingTooltip3,
  381.     WorldMapTooltip,
  382.     DropDownList1MenuBackdrop,
  383.     DropDownList2MenuBackdrop,
  384. }
  385.  
  386. for i, frame in ipairs(tooltips) do
  387.     frame:SetScript("OnShow", function(frame)
  388.         if(cfg.combathideALL and InCombatLockdown()) then
  389.             return frame:Hide()
  390.         end
  391.  
  392.         style(frame)
  393.     end)
  394. end
  395.  
  396. local itemrefScripts = {
  397.     "OnTooltipSetItem",
  398.     "OnTooltipSetAchievement",
  399.     "OnTooltipSetQuest",
  400.     "OnTooltipSetSpell",
  401. }
  402.  
  403. for i, script in ipairs(itemrefScripts) do
  404.     ItemRefTooltip:HookScript(script, function(self)
  405.         style(self)
  406.     end)
  407. end
  408.  
  409. local f = CreateFrame"Frame"
  410. f:SetScript("OnEvent", function(self, event, ...) if ns[event] then return ns[event](ns, event, ...) end end)
  411. function ns:RegisterEvent(...) for i=1,select("#", ...) do f:RegisterEvent((select(i, ...))) end end
  412. function ns:UnregisterEvent(...) for i=1,select("#", ...) do f:UnregisterEvent((select(i, ...))) end end
  413.  
  414. ns:RegisterEvent"PLAYER_LOGIN"
  415. function ns:PLAYER_LOGIN()
  416.     for i, frame in ipairs(tooltips) do
  417.         setBakdrop(frame)
  418.     end
  419.  
  420.     ns:UnregisterEvent"PLAYER_LOGIN"
  421. end
  422.  
  423. local frame = CreateFrame("Frame", "ItemRefTooltipIconFrame", _G["ItemRefTooltip"])
  424. frame:SetPoint("TOPRIGHT", _G["ItemRefTooltip"], "TOPLEFT", -2, -1)
  425. frame:SetSize(32, 32)
  426.  
  427. local tex = frame:CreateTexture("ItemRefTooltipIcon", "TOOLTIP")
  428. tex:SetAllPoints(frame)
  429.  
  430. F.CreateBG(frame)
  431.            
  432. local AddItemIcon = function()
  433.     local frame = _G["ItemRefTooltipIconFrame"]
  434.     frame:Hide()
  435.  
  436.     local _, link = _G["ItemRefTooltip"]:GetItem()
  437.     local icon = link and GetItemIcon(link)
  438.     if(not icon) then return end
  439.  
  440.     _G["ItemRefTooltipIcon"]:SetTexture(icon)
  441.     _G["ItemRefTooltipIcon"]:SetTexCoord(.08, .92, .08, .92)
  442.     frame:Show()
  443. end
  444.  
  445. hooksecurefunc("SetItemRef", AddItemIcon)
Add Comment
Please, Sign In to add comment