Guest User

TinyTip_friendly

a guest
Jan 24th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.71 KB | None | 0 0
  1. --[[
  2. -- Name: TinyTip
  3. -- Author: Thrae of Maelstrom (aka "Matthew Carras")
  4. -- Release Date: 6-25-06
  5. --
  6. -- Based very losely off AF_Tooltip_Mini
  7. -- Some code from PerfectTooltip by cladhaire
  8. --
  9. -- Thanks to #wowace and #wowi-lounge on Freenode as always for
  10. -- optimization assistance.
  11. --]]
  12.  
  13. local _G = getfenv(0)
  14. local strformat, strfind = string.format, string.find
  15. local tmp,tmp2,tmp3,i
  16.  
  17. local UIParent,GameTooltip = _G.UIParent,_G.GameTooltip
  18. local tooltip = GameTooltip
  19. local fGetAlpha, fSetAlpha, fHide, fShow, fSetBDColor, fGetBDColor, fSetBDBColor, fGetBDBColor, fSetPt, fClearPts, fSetScript, fGetName = UIParent.GetAlpha, UIParent.SetAlpha, UIParent.Show, UIParent.Hide, UIParent.SetBackdropColor, UIParent.GetBackdropColor, UIParent.SetBackdropBorderColor, UIParent.GetBackdropBorderColor, UIParent.SetPoint, UIParent.ClearAllPoints, UIParent.GetScript, UIParent.GetName
  20.  
  21. local gtIsVisible, gtNumLines, gtAddLine, gtAddDoubleLine, gtLine1, gtLine2, gtLine3, gtSetOwner = GameTooltip.IsVisible, GameTooltip.NumLines, GameTooltip.AddLine, GameTooltip.AddDoubleLine, _G.GameTooltipTextLeft1, _G.GameTooltipTextLeft2, _G.GameTooltipTextLeft3, GameTooltip.SetOwner
  22.  
  23. local sbShow = _G.GameTooltipStatusBar.Show
  24.  
  25. local fsGetText, fsSetTextColor, fsGetTextColor, fsSetText, fsIsShown, fsGetWidth, fsHide, fsSetHeight, fsGetHeight = _G.GameTooltipTextLeft1.GetText, _G.GameTooltipTextLeft1.SetTextColor, _G.GameTooltipTextLeft1.GetTextColor, _G.GameTooltipTextLeft1.SetText,  _G.GameTooltipTextLeft1.IsShown, _G.GameTooltipTextLeft1.GetWidth, _G.GameTooltipTextLeft1.Hide, _G.GameTooltipTextLeft1.SetHeight, _G.GameTooltipTextLeft1.GetHeight
  26.  
  27. local EventFrame
  28.  
  29. local SpaceLevel = _G.TinyTipLocale_Level .. " "
  30.  
  31. local acehook = {}
  32. _G.AceLibrary:GetInstance("AceHook-2.0"):embed(acehook)
  33.  
  34. local db
  35. local DBVer = 33
  36.  
  37. --------------------------------------------------------------------
  38. -- Global Functions
  39.  
  40. -- Print out a message, probably to ChatFrame1
  41. local DCFAddMessage = _G.DEFAULT_CHAT_FRAME.AddMessage
  42. function TinyTip_Msg(msg)
  43.     DCFAddMessage(_G.DEFAULT_CHAT_FRAME, "|cFFFFCC00TinyTip:|r " .. msg )
  44. end
  45.  
  46. -- Return ALL possible saved options.
  47. function TinyTip_GetAllOptions()
  48.     return {    ["_profile"]            = "boolean",
  49.                         ["Fade"]                    = "number",
  50.                         ["MAnchor"]             = "string",
  51.                         ["FAnchor"]             = "string",
  52.                         ["MOffX"]                   = "number",
  53.                         ["MOffY"]                   = "number",
  54.                         ["FOffX"]                   = "number",
  55.                         ["FOffY"]                   = "number",
  56.                         ["Scale"]                   = "number",
  57.                         ["HideLevelText"]   = "boolean",
  58.                         ["HideRace"]            = "boolean",
  59.                         ["PvPRank"]             = "boolean",
  60.                         ["PvPIcon"]             = "boolean",
  61.                         ["BGColor"]             = "number",
  62.                         ["Border"]              = "number",
  63.                         ["HideInFrames"]    = "boolean",
  64.                         ["HideGuild"]           = "boolean",
  65.                         ["ReactionText"]    = "boolean",
  66.                         ["Friends"]             = "number",
  67.                         ["LevelGuess"]      = "boolean",
  68.                         ["ToT"]                     = "number",
  69.                         ["ToP"]                     = "number",
  70.                         ["ToR"]                     = "number",
  71.                         ["ExtraTooltip"]    = "number",
  72.                         ["ETAnchor"]            = "string",
  73.                         ["ETOffX"]              = "number",
  74.                         ["ETOffY"]              = "number",
  75.                         ["FormatDisabled"] = "boolean",
  76.                         ["Buffs"]                   = "number",
  77.                         ["Debuffs"]             = "number",
  78.                         ["ManaBar"]             = "boolean",
  79.                         ["Compact"]             = "boolean",
  80.                         ["RTIcon"]              = "boolean",
  81.                         ["AnchorAll"]           = "boolean",
  82.                         ["PvPIconAnchor1"]  = "string",
  83.                         ["PvPIconAnchor2"]  = "string",
  84.                         ["PvPIconOffX"]         = "number",
  85.                         ["PvPIconOffY"]         = "number",
  86.                         ["RTIconAnchor1"]   = "string",
  87.                         ["RTIconAnchor2"]   = "string",
  88.                         ["RTIconOffX"]          = "number",
  89.                         ["RTIconOffY"]          = "number",
  90.                         ["BuffAnchor1"]     = "string",
  91.                         ["BuffAnchor2"]     = "string",
  92.                         ["BuffOffX"]            = "number",
  93.                         ["BuffOffY"]            = "number",
  94.                         ["DebuffAnchor1"]   = "string",
  95.                         ["DebuffAnchor2"]   = "string",
  96.                         ["DebuffOffX"]          = "number",
  97.                         ["DebuffOffY"]          = "number",
  98.                         ["PvPIconScale"]        = "number",
  99.                         ["RTIconScale"]         = "number",
  100.                         ["BuffScale"]               = "number",
  101.                         ["KeyElite"]                = "boolean",
  102.                         ["AlwaysAnchor"]        = "boolean",
  103.                         ["SmoothBorder"]        = "boolean"
  104.                     }
  105. end
  106.  
  107. function TinyTip_LoDRun(addon,sfunc,arg1,arg2,arg3,arg4,arg5,arg6)
  108.     if not _G[ sfunc ] then
  109.         local loaded, reason = _G.LoadAddOn(addon)
  110.         if loaded then
  111.             if _G[ sfunc ] and type( _G[ sfunc] ) == "function" then
  112.                 _G[ sfunc ](arg1,arg2,arg3,arg4,arg5,arg6)
  113.             end
  114.         else
  115.             _G.TinyTip_Msg( addon .. " Addon LoadOnDemand Error - " .. reason )
  116.             return reason
  117.         end
  118.     elseif type( _G[ sfunc] ) == "function" then
  119.             _G[ sfunc ](arg1,arg2,arg3,arg4,arg5,arg6)
  120.     end
  121. end
  122.  
  123. function TinyTip_UpdateProfiles()
  124.     if _G.TinyTipDB["_profile"] then
  125.         if not _G.TinyTipCharDB then
  126.             local k,v
  127.             _G.TinyTipCharDB = {}
  128.             for k,v in db do
  129.                 _G.TinyTipCharDB[k] = v
  130.             end
  131.         end
  132.         db = _G.TinyTipCharDB
  133.     else
  134.         db = _G.TinyTipDB
  135.     end
  136.     if _G.TinyTipAnchor_SetLocals then
  137.         _G.TinyTipAnchor_SetLocals(db,EventFrame)
  138.     end
  139.     if db["PvPIcon"] or db["Buffs"] or db["Debuffs"] then
  140.         _G.TinyTip_LoDRun( "TinyTipExtras", "TinyTipExtras_Init", db, EventFrame)
  141.     end
  142. end
  143.  
  144. -- Destroy the database and reset it with
  145. -- default values.
  146. function TinyTip_DefaultDB()
  147.     local k
  148.     for k,_ in db do
  149.         if k ~= "_v" then
  150.             db[k] = nil
  151.         end
  152.     end
  153. end
  154.  
  155. function TinyTip_GetDB()
  156.     return db
  157. end
  158.  
  159. function TinyTip_SetScale(opt,v)
  160.         if not v then
  161.             if _G.TinyTipExtras_Tooltip then
  162.                 _G.TinyTipExtras_Tooltip:SetScale( 1.0 )
  163.             else
  164.                 GameTooltip:SetScale( 1.0 )
  165.             end
  166.             db["Scale"] = nil
  167.         else
  168.             if _G.TinyTipExtras_Tooltip then
  169.                 _G.TinyTipExtras_Tooltip:SetScale( v )
  170.             else
  171.                 GameTooltip:SetScale( v )
  172.             end
  173.             db["Scale"] = v
  174.         end
  175. end
  176.  
  177. function TinyTip_ResetReferences(_AddLine, _AddDoubleLine, _ettooltip, _tooltip)
  178.     gtAddLine, gtAddDoubleLine = _AddLine, _AddDoubleLine
  179.     EventFrame.tooltip, tooltip = _ettooltip, _tooltip
  180. end
  181.  
  182. -- Get rid of that darn fading effect
  183. function TinyTip_SlimOnUpdate()
  184.     tmp = fGetAlpha(GameTooltip)
  185.     if tmp and tmp < 1 then
  186.         if db["Fade"] ~= 1 or tmp < 0.1 or _G.TinyTipExtras_Tooltip then
  187.             fSetScript(EventFrame, "OnUpdate", nil)
  188.             gtSetOwner(GameTooltip, UIParent, "ANCHOR_CURSOR")
  189.         elseif db["ExtraTooltip"] and _G.TinyTipExtras_Tooltip then
  190.             fSetAlpha(_G.TinyTipExtras_Tooltip, tmp )
  191.         end
  192.     end
  193. end
  194.  
  195. local TooltipCompacted
  196. function TinyTip_UnCompactGameTooltip()
  197.     fClearPts(_G.GameTooltipStatusBar)
  198.     fSetPt(_G.GameTooltipStatusBar, "TOPLEFT", GameTooltip, "BOTTOMLEFT", 2, -1)
  199.     fSetPt(_G.GameTooltipStatusBar, "TOPRIGHT", GameTooltip, "BOTTOMRIGHT", -2, -1)
  200.     fClearPts(gtLine1)
  201.     fSetPt(gtLine1, "TOPLEFT", 10, -10)
  202.     tmp = gtLine1
  203.     for i = 2, 30 do
  204.         tmp2 = _G[ "GameTooltipTextLeft" .. i ]
  205.         fClearPts( tmp2 )
  206.         fSetPt( tmp2, "TOPLEFT", tmp, "BOTTOMLEFT", 0, -2)
  207.         tmp = tmp2
  208.     end
  209.     TooltipCompacted = nil
  210. end
  211.  
  212. --------------------------------------------------------------------
  213. -- Local Functions
  214.  
  215. --[[ Initialize the SavedVariables database.
  216.     * If empty, copies the default table values to it.
  217.     * If mismatched versions, prunes out invalid entries
  218.       and adds new ones.
  219.     * Otherwise just sets the local db.
  220. --]]
  221. local function InitDB()
  222.     local k,v
  223.     if not _G.TinyTipDB then
  224.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB1 )
  225.         _G.TinyTipDB = {}
  226.         db = _G.TinyTipDB
  227.         db["_v"] = DBVer
  228.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB2 )
  229.     elseif _G.TinyTipDB._profile and not _G.TinyTipCharDB then
  230.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB1 )
  231.         _G.TinyTipCharDB = {}
  232.         db = _G.TinyTipCharDB
  233.         db["_v"] = DBVer
  234.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB2 )
  235.     elseif _G.TinyTipDB._v ~= DBVer then
  236.         tmp = _G.TinyTip_GetAllOptions()
  237.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB3 )
  238.         db = _G.TinyTipDB
  239.         for k,_ in db do -- prune
  240.             if not tmp[k] then
  241.                 db[k] = nil
  242.             end
  243.         end
  244.         for k,v in tmp do -- check types
  245.             if type(db[k]) ~= v then
  246.                 db[k] = nil
  247.             end
  248.         end
  249.         if db["MAnchor"] == "CURSOR" then db["MAnchor"] = nil end
  250.         db["_v"] = DBVer
  251.         if db["_profile"] then
  252.             if not _G.TinyTipCharDB then _G.TinyTipCharDB = {} end
  253.             db = _G.TinyTipCharDB
  254.             for k,_ in db do -- prune
  255.                 if not tmp[k] then
  256.                     db[k] = nil
  257.                 end
  258.             end
  259.             for k,v in tmp do -- check types
  260.                 if type(db[k]) ~= v then
  261.                     db[k] = nil
  262.                 end
  263.             end
  264.             if db["MAnchor"] == "CURSOR" then db["MAnchor"] = nil end
  265.         end
  266.         tmp = nil
  267.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB4 )
  268.     elseif _G.TinyTipDB._profile then
  269.         _G.TinyTip_Msg( "Using profile data.")
  270.         _G.TinyTip_Msg( _G.TinyTipLocale_InitDB5 )
  271.         db = _G.TinyTipCharDB
  272.     else
  273.         -- _G.TinyTip_Msg( _G.TinyTipLocale_InitDB5 )
  274.         db = _G.TinyTipDB
  275.     end
  276.  
  277.     -- nil out what we don't need any longer
  278.     _G.TinyTipLocale_InitDB1 = nil
  279.     _G.TinyTipLocale_InitDB2 = nil
  280.     _G.TinyTipLocale_InitDB3 = nil
  281.     _G.TinyTipLocale_InitDB4 = nil
  282.     _G.TinyTipLocale_InitDB5 = nil
  283.  
  284.     -- then finally, nil out the function itself
  285.     InitDB = nil
  286. end
  287.  
  288. -- for Tem
  289. function TinyTip_SmoothBorder(k)
  290.     if k then db[k] = not db[k] end
  291.     if db["SmoothBorder"] then
  292.         GameTooltip:SetBackdrop({
  293.             bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  294.             edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  295.             tile = false,
  296.             tileSize = 6,
  297.             edgeSize = 18,
  298.             insets = {
  299.                     left = 4,
  300.                     right = 4,
  301.                     top = 4,
  302.                     bottom = 4,
  303.                 }
  304.             }  
  305.         )
  306.         fSetBDColor(GameTooltip, 1, 1, 1, 0.8)
  307.         fSetBDBColor(GameTooltip, 0, 0, 0, 1)
  308.     else
  309.         GameTooltip:SetBackdrop({
  310.             bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  311.             edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  312.             tile = true,
  313.             tileSize = 16,
  314.             edgeSize = 16,
  315.             insets = {
  316.                     left = 5,
  317.                     right = 5,
  318.                     top = 5,
  319.                     bottom = 5,
  320.                 }
  321.             }
  322.         )
  323.         fSetBDColor(GameTooltip, 0, 0, 0, 1)
  324.     end
  325. end
  326.  
  327. local function CompactTooltip(tooltip, unit)
  328.     if not TooltipCompacted then
  329.     local lineWidth, largestWidth, fsHHeight, fsHeight, count = 0,0,0,0
  330.     tmp = _G[ fGetName(tooltip) .. "TextLeft1"]
  331.     if tmp and fsIsShown(tmp) then
  332.         count = 1
  333.         _,fsHHeight = tmp:GetFont()
  334.         fClearPts(tmp)
  335.         fSetPt(tmp, "TOPLEFT", 1, 0)
  336.         lineWidth = fsGetWidth(tmp)
  337.         tmp2 = _G[ fGetName(tooltip) .. "TextRight1"]
  338.         if tmp2 and fsIsShown(tmp2) then lineWidth = lineWidth + fsGetWidth(tmp2) + 40 end
  339.         largestWidth = lineWidth
  340.         fClearPts(_G.GameTooltipStatusBar)
  341.         fSetPt(_G.GameTooltipStatusBar, "TOPLEFT", tmp, "BOTTOMLEFT", 0, 0)
  342.         fSetPt(_G.GameTooltipStatusBar, "RIGHT", _G.GameTooltipStatusBar:GetParent(), "RIGHT", 0, 0)
  343.         tmp = _G[ fGetName(tooltip) .. "TextLeft2"]
  344.         if tmp then
  345.             count = 2
  346.             _,fsHeight = tmp:GetFont()
  347.             fClearPts(tmp)
  348.             if db["ManaBar"] and _G.TinyTipExtras_ManaBar:IsShown() then
  349.                 fSetPt(tmp, "TOPLEFT", _G.TinyTipExtras_ManaBar, "BOTTOMLEFT", 0, 0)
  350.                 count = count + 1
  351.             else
  352.                 fSetPt(tmp, "TOPLEFT", _G.GameTooltipStatusBar, "BOTTOMLEFT", 0, 0)
  353.             end
  354.             lineWidth = fsGetWidth(tmp)
  355.             tmp3 = tmp
  356.             tmp2 = _G[ fGetName(tooltip) .. "TextRight2"]
  357.             if tmp2 and fsIsShown(tmp2) then lineWidth = lineWidth + fsGetWidth(tmp2) + 40 end
  358.             if lineWidth > largestWidth then largestWidth = lineWidth end
  359.             tmp = tooltip:NumLines()
  360.             for i = 3,tmp do
  361.                 tmp2 = _G[ fGetName(tooltip) .. "TextLeft" .. i ]
  362.                 if tmp2 and fsIsShown(tmp2) then
  363.                     fClearPts(tmp2)
  364.                     fSetPt(tmp2, "TOPLEFT", tmp3, "BOTTOMLEFT", 0, 0)
  365.                     lineWidth = fsGetWidth(tmp2)
  366.                     count = count + 1
  367.                 end
  368.                 tmp3 = tmp2
  369.                 tmp2 = _G[ fGetName(tooltip) .. "TextRight" .. i ]
  370.                 if tmp2 and fsIsShown(tmp2) then
  371.                     lineWidth = lineWidth + fsGetWidth(tmp2) + 40
  372.                 end
  373.                 if lineWidth > largestWidth then largestWidth = lineWidth end
  374.             end
  375.             tooltip:SetWidth( largestWidth + 5 )
  376.             tooltip:SetHeight( fsHHeight + (fsHeight * (count) ) )
  377.         end
  378.     end
  379.     TooltipCompacted = true
  380. end
  381. end
  382.  
  383. -- Return color format in HEX from Blizzard percentage RGB
  384. -- for the class.
  385. function TinyTip_ColorPlayer(unit)
  386.     _,tmp=_G.UnitClass(unit)
  387.     if tmp and _G.RAID_CLASS_COLORS[tmp] then
  388.         return strformat("%2x%2x%2x", _G.RAID_CLASS_COLORS[tmp].r*255,
  389.                                           _G.RAID_CLASS_COLORS[tmp].g*255,
  390.                                           _G.RAID_CLASS_COLORS[tmp].b*255)
  391.     else
  392.         return "FFFFFF"
  393.     end
  394. end
  395.  
  396. RAID_CLASS_COLORS = {
  397.     ["HUNTER"] = { r = 0.67, g = 0.83, b = 0.45, colorStr = "ffabd473" },
  398.     ["WARLOCK"] = { r = 0.58, g = 0.51, b = 0.79, colorStr = "ff9482c9" },
  399.     ["PRIEST"] = { r = 1.0, g = 1.0, b = 1.0, colorStr = "ffffffff" },
  400.     ["PALADIN"] = { r = 0.96, g = 0.55, b = 0.73, colorStr = "fff58cba" },
  401.     ["MAGE"] = { r = 0.41, g = 0.8, b = 0.94, colorStr = "ff69ccf0" },
  402.     ["ROGUE"] = { r = 1.0, g = 0.96, b = 0.41, colorStr = "fffff569" },
  403.     ["DRUID"] = { r = 1.0, g = 0.49, b = 0.04, colorStr = "ffff7d0a" },
  404.     ["SHAMAN"] = { r = 0.0, g = 0.44, b = 0.87, colorStr = "ff0070de" },
  405.     ["WARRIOR"] = { r = 0.78, g = 0.61, b = 0.43, colorStr = "ffc79c6e" },
  406.     ["DEATHKNIGHT"] = { r = 0.77, g = 0.12 , b = 0.23, colorStr = "ffc41f3b" },
  407.     ["MONK"] = { r = 0.0, g = 1.00 , b = 0.59, colorStr = "ff00ff96" },
  408. };
  409.  
  410. local PvPLine, PvPBeforeLine
  411. local function TooltipFormat(unit)
  412.     if gtIsVisible(GameTooltip) and _G.UnitExists(unit) then
  413.     local treac,cdeadortap,bdead,levelLine
  414.     local bdR,bdG,bdB = 0,0,0
  415.     local tR,tG,tB = 0,0,0
  416.  
  417.     if not db["FormatDisabled"] then
  418.     tmp = gtNumLines(GameTooltip)
  419.     for i = 1,tmp,1 do
  420.         tmp2 = fsGetText(_G[ "GameTooltipTextLeft" .. i ])
  421.         if tmp2 and strfind(tmp2, _G.TinyTipLocale_Level, 1, true) then
  422.             levelLine = _G[ "GameTooltipTextLeft" .. i ]
  423.             break
  424.         end
  425.     end
  426.  
  427.     -- Get Rank, then Set Name (rankName, rankNumber)
  428.     tmp,tmp2 = _G.GetPVPRankInfo(_G.UnitPVPRank(unit), unit)
  429.     tmp3 = _G.UnitIsPlayer(unit)
  430.     if db["PvPIcon"] and _G.TinyTipIcons_ResetPvPIcon then
  431.         _G.TinyTipIcons_ResetPvPIcon(tmp2, tmp3)
  432.     end
  433.     if tmp3 and db["PvPRank"] ~= 1 and tmp2 > 0 then
  434.             if db["PvPRank"] == 2 then
  435.                 fsSetText(gtLine1, tmp .. " " .. (_G.UnitName(unit) or "Unknown" ) )
  436.             elseif db["PvPRank"] == 3 then
  437.                 fsSetText(gtLine1, (_G.UnitName(unit) or "Unknown") .. " [R" .. tmp2 .. "]" )
  438.             else
  439.                 fsSetText(gtLine1, "[R" .. tmp2 .. "] " .. (_G.UnitName(unit) or "Unknown" ) )
  440.             end
  441.     else
  442.             fsSetText(gtLine1, _G.UnitName(unit) or "Unknown" )
  443.     end
  444.  
  445.     -- Reaction coloring
  446.     tmp,tmp2 = _G.UnitPlayerControlled(unit), _G.UnitReaction(unit, "player")
  447.     if _G.UnitIsTapped(unit) and not _G.UnitIsTappedByPlayer(unit) then
  448.         if not db["BGColor"] or db["BGColor"] == 2 then
  449.             bdR,bdG,bdB = 0.54,0.54,0.54
  450.         end
  451.         fsSetTextColor(gtLine1, 0.54,0.54,0.54)
  452.         cdeadortap = "888888"
  453.     elseif ( tmp and _G.UnitCanAttack(unit, "player") ) or
  454.            _G.UnitIsTappedByPlayer(unit) or
  455.            ( not tmp and tmp2 and tmp2 > 0 and tmp2 <= 2 ) then -- hostile
  456.             fsSetTextColor(gtLine1, _G.FACTION_BAR_COLORS[tmp2 or 2].r,
  457.                         _G.FACTION_BAR_COLORS[tmp2 or 2].g,
  458.                         _G.FACTION_BAR_COLORS[tmp2 or 2].b)
  459.             if db["ReactionText"] and tmp2 and tmp2 > 0 then
  460.                 treac = _G["FACTION_STANDING_LABEL" .. tmp2]
  461.             else
  462.                 treac = _G.FACTION_STANDING_LABEL2
  463.             end
  464.            
  465.             if not db["BGColor"] or db["BGColor"] == 2 then
  466.                 if tmp or db["BGColor"] == 2 then
  467.                     if tmp and not _G.UnitCanAttack("player", unit) then
  468.                             bdR,bdG,bdB = 0.5,0.2,0.1
  469.                     else
  470.                         --_,tmp34=_G.UnitClass(unit)
  471.                         --if tmp34 and _G.RAID_CLASS_COLORS[tmp34] then
  472.                             --bdR,bdG,bdB  = _G.RAID_CLASS_COLORS[tmp34].r,_G.RAID_CLASS_COLORS[tmp34].g,_G.RAID_CLASS_COLORS[tmp34].b
  473.                         --else
  474.                             bdR,bdG,bdB = 0.5,0.0,0.0
  475.                         --end
  476.                     end
  477.                 end
  478.             end
  479.     elseif ( tmp and _G.UnitCanAttack("player",unit) ) or
  480.            ( not tmp and tmp2 and tmp2 <= 4 ) then -- neutral
  481.             fsSetTextColor(gtLine1, _G.FACTION_BAR_COLORS[4].r,
  482.                         _G.FACTION_BAR_COLORS[4].g,
  483.                         _G.FACTION_BAR_COLORS[4].b)
  484.             if db["ReactionText"] then treac = _G.FACTION_STANDING_LABEL4 end
  485.             if (tmp and not db["BGColor"]) or db["BGColor"] == 2 then
  486.                 tooltip:SetBackdropColor( 0.5, 0.5, 0.0)
  487.             end
  488.     else -- friendly
  489.         treac = _G.FACTION_STANDING_LABEL5
  490.         if (tmp and not db["BGColor"]) or db["BGColor"] == 2 then
  491.             bdR,bdG,bdB = 0.0, 0.0, 0.5
  492.                 _,tmp33=_G.UnitClass(unit)
  493.                 if tmp33 and _G.RAID_CLASS_COLORS[tmp33] then
  494.                 bdR,bdG,bdB  = _G.RAID_CLASS_COLORS[tmp33].r,_G.RAID_CLASS_COLORS[tmp33].g,_G.RAID_CLASS_COLORS[tmp33].b
  495.                 end
  496.         end
  497.         if _G.UnitIsPVP(unit) then -- friendly, PvP-enabled
  498.             fsSetTextColor(gtLine1, _G.FACTION_BAR_COLORS[6].r,
  499.                                                                         _G.FACTION_BAR_COLORS[6].g,
  500.                                                                         _G.FACTION_BAR_COLORS[6].b)
  501.         else
  502.             fsSetTextColor(gtLine1, (not tmp and _G.FACTION_BAR_COLORS[tmp2 or 5].r) or 0,
  503.                                                                         (not tmp and _G.FACTION_BAR_COLORS[tmp2 or 5].g) or 0.67,
  504.                                                                         (not tmp and _G.FACTION_BAR_COLORS[tmp2 or 5].b) or 1.0)
  505.         end
  506.     end
  507.  
  508.     -- remove PvP line, if it exists
  509.     PvP_Line = nil
  510.     if not db["ReactionText"] and _G.UnitIsPVP(unit) then
  511.         tmp = gtNumLines(GameTooltip)
  512.         for i=3,tmp,1 do
  513.             tmp2 = _G["GameTooltipTextLeft" .. i]
  514.             if tmp2 then
  515.                 tmp3 = fsGetText(tmp2)
  516.                 if tmp3 and strfind(tmp3, _G.PVP_ENABLED, 1, true) then
  517.                     PvPLine = tmp2
  518.                     PvPBeforeLine = _G["GameTooltipTextLeft" .. (i-1)]
  519.                     fsSetText(PvPLine, nil)
  520.                     fClearPts(PvPLine)
  521.                     fSetPt(PvPLine, "TOPLEFT", PvPBeforeLine or gtLine2, "BOTTOMLEFT", 0, 1)
  522.                     fsHide(PvPLine)
  523.                     break
  524.                 end
  525.             end
  526.         end
  527.     end
  528.  
  529.     -- We like to know who our friends are.
  530.     if db["Friends"] ~= 2 and
  531.     _G.UnitIsPlayer(unit) and treac == _G.FACTION_STANDING_LABEL5 then
  532.         local num,name = _G.GetNumFriends(), _G.UnitName(unit)
  533.         for i = 1,num,1 do
  534.             tmp,tmp2 = _G.GetFriendInfo(i)
  535.             if tmp and tmp2 ~= 0 and name and tmp == name then
  536.                 if db["Friends"] == 1 or db["BGColor"] == 1 or db["BGColor"] == 3 then
  537.                     fsSetTextColor(gtLine1, 0.58, 0.0, 0.83)
  538.                 else
  539.                     bdR,bdG,bdB = 0.29, 0.0, 0.42
  540.                 end
  541.                 break
  542.             end
  543.         end
  544.     end
  545.    
  546.     -- Check for a dead unit, but try to leave out Hunter's Feign Death
  547.     if _G.UnitHealth(unit) <= 0 and
  548.     ( not _G.UnitIsPlayer(unit) or _G.UnitIsDeadOrGhost(unit) or _G.UnitIsCorpse(unit) ) then
  549.         if not db["BGColor"] or db["BGColor"] == 2 then
  550.             bdR,bdG,bdB = 0.54, 0.54, 0.54
  551.         end
  552.         fsSetTextColor(gtLine1, 0.54,0.54,0.54)
  553.         cdeadortap = "888888"
  554.         bdead = true
  555.     end
  556.    
  557.     -- set the color of line 2, if it's available
  558.     if levelLine == gtLine3 then
  559.         fsSetTextColor(gtLine2, fsGetTextColor(gtLine1) )
  560.     end
  561.  
  562.     if levelLine then
  563.     local clevel
  564.     local ulevel = _G.UnitLevel(unit)
  565.     tmp2 = ulevel - _G.UnitLevel("player") -- Level difficulty
  566.     if tmp2 and _G.UnitFactionGroup(unit) ~= _G.UnitFactionGroup("player") then
  567.         if tmp2 >= 5 or ulevel == -1 then clevel = "FF0000"
  568.         elseif tmp2 >= 3 then clevel = "FF6600"
  569.         elseif tmp2 >= -2 then clevel = "FFFF00"
  570.         elseif -tmp2 <= _G.GetQuestGreenRange() then clevel = "00FF00"
  571.         else clevel = "888888"
  572.         end    
  573.     end
  574.  
  575.         tmp = (not db["HideLevelText"] and SpaceLevel) or ""
  576.         if ulevel and ulevel >= 1 then
  577.             fsSetText(levelLine, "|cFF" ..
  578.                                                      (cdeadortap or clevel or "FFCC00") ..
  579.                                                      tmp ..
  580.                                                      ulevel ..
  581.                                                      "|r")
  582.         elseif db["LevelGuess"] and ulevel and ulevel == -1 and ulevel < 60 then
  583.             fsSetText(levelLine, "|cFF" ..
  584.                                                      (cdeadortap or clevel or "FFCC00") ..
  585.                                                      tmp .. ">" ..
  586.                                                       (_G.UnitLevel("player") + 10 ) ..
  587.                                                      "|r")
  588.         else
  589.             fsSetText(levelLine, "|cFF" ..
  590.                                                      (cdeadortap or clevel or "FFCC00") ..
  591.                                                      tmp ..
  592.                                                      "??|r")
  593.         end
  594.  
  595.         tmp2 = _G.UnitClassification(unit) -- Elite status
  596.         if tmp2 and tmp2 ~= "normal" then
  597.             if tmp2 == "elite" then
  598.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  599.                                                          ((db["KeyElite"] and "") or " ") ..
  600.                                                          "|cFF" ..
  601.                                                          (cdeadortap or "FFCC00") ..
  602.                                                          ((db["KeyElite"] and "*") or _G.ELITE) ..
  603.                                                          "|r" )
  604.             elseif tmp2 == "worldboss" then
  605.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  606.                                                          ((db["KeyElite"] and "") or " ") ..
  607.                                                          "|cFF" ..
  608.                                                          (cdeadortap or "FF0000") ..
  609.                                                          ((db["KeyElite"] and "**") or _G.BOSS) ..
  610.                                                          "|r" )
  611.             elseif tmp2 == "rare" then
  612.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  613.                                                          ((db["KeyElite"] and "") or " ") ..
  614.                                                          "|cFF" ..
  615.                                                          (cdeadortap or "FF66FF") ..
  616.                                                          ((db["KeyElite"] and "!") or _G.ITEM_QUALITY3_DESC) ..
  617.                                                          "|r" )
  618.             elseif tmp2 == "rareelite" then
  619.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  620.                                                          ((db["KeyElite"] and "") or " ") ..
  621.                                                          "|cFF" ..
  622.                                                          (cdeadortap or "FFAAFF") ..
  623.                                                          ((db["KeyElite"] and "!*") or _G.TinyTipLocale_RareElite) ..
  624.                                                          "|r" )
  625.             else
  626.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  627.                                                          " [|cFF" ..
  628.                                                          (cdeadortap or "FFFFFF") ..
  629.                                                          tmp2 ..
  630.                                                          "|r]" )
  631.             end
  632.         end
  633.  
  634.         -- Class And Race
  635.         if _G.UnitIsPlayer(unit) then
  636.             fsSetText(levelLine,    (fsGetText(levelLine) or "") ..
  637.                                                         " |cFF" ..
  638.                                                         (cdeadortap or "DDEEAA") ..
  639.                                                         (( not db["HideRace"] and (_G.UnitRace(unit) .. " ") ) or "") ..
  640.                                                         "|r|cFF" ..
  641.                                                         (cdeadortap or TinyTip_ColorPlayer(unit)) ..
  642.                                                         (_G.UnitClass(unit) or "" ) ..
  643.                                                         "|r")
  644.         elseif not db["HideRace"] then
  645.             if _G.UnitPlayerControlled(unit) then
  646.             fsSetText(levelLine,    (fsGetText(levelLine) or "") ..
  647.                                                         " |cFF" ..
  648.                                                         (cdeadortap or "DDEEAA") ..
  649.                                                         (_G.UnitCreatureFamily(unit) or "") ..
  650.                                                         "|r")
  651.             else
  652.             fsSetText(levelLine,    (fsGetText(levelLine) or "") ..
  653.                                                         " |cFF" ..
  654.                                                         (cdeadortap or "DDEEAA") ..
  655.                                                         (_G.UnitCreatureType(unit) or "") ..
  656.                                                         "|r")
  657.             end
  658.         end
  659.    
  660.     -- add corpse/tapped line
  661.     if cdeadortap and levelLine then
  662.         fsSetText(levelLine,
  663.                         (fsGetText(levelLine) or "") ..
  664.                         " |cFF888888(" ..
  665.                         ( ( bdead and _G.CORPSE ) or TinyTipLocale_Tapped ) ..
  666.                         ")|r")
  667.     end
  668.  
  669. end
  670. end
  671.  
  672.     if db["ExtraTooltip"] and _G.TinyTipExtras_CopyGameTooltip then
  673.         _G.TinyTipExtras_CopyGameTooltip()
  674.     end
  675.  
  676.     if not bdead then
  677.     -- Add Reaction Text
  678.     if db["ReactionText"] and treac then
  679.         gtAddLine( tooltip, treac, fsGetTextColor(gtLine1) )
  680.     end
  681.  
  682.     -- Add Guild info, if enabled
  683.     tmp2 = _G.GetGuildInfo(unit)
  684.     if not db["HideGuild"] and tmp2 then
  685.         tmp = "<" .. tmp2 .. ">"
  686.         if _G.IsInGuild() and tmp2 == _G.GetGuildInfo("player") and db["Friends"] ~= 2 then
  687.             if not db["Friends"] and not _G.UnitIsUnit(unit, "player") and db["BGColor"] ~= 3 and db["BGColor"] ~= 1 then
  688.                 bdR,bdG,bdB = 0.4, 0.1, 0.5
  689.                 gtAddLine( tooltip, tmp, fsGetTextColor(gtLine1) )
  690.             else
  691.                 gtAddLine( tooltip, tmp, 0.58, 0.0, 0.83)
  692.             end
  693.         else
  694.             gtAddLine( tooltip, tmp, fsGetTextColor(gtLine1) )
  695.         end
  696.     end
  697.  
  698.     if db["RTIcon"] and _G.TinyTipIcons_ResetRTIcon then _G.TinyTipIcons_ResetRTIcon(unit, _G.GetNumRaidMembers()) end
  699.     if db["ToT"] and _G.TinyTipTargets_Mouse then _G.TinyTipTargets_Mouse(unit, db["ToT"]) end
  700.     if db["ToR"] or db["ToP"] then
  701.         tmp,tmp2 = _G.GetNumRaidMembers(), _G.GetNumPartyMembers()
  702.         if db["ToR"] and _G.TinyTipTargets_Raid and tmp and tmp > 0 then _G.TinyTipTargets_Raid(unit, tmp, db["ToR"])
  703.         elseif db["ToP"] and _G.TinyTipTargets_Party and tmp2 and tmp2 > 0 then
  704.             _G.TinyTipTargets_Party(unit, tmp2, db["ToP"])
  705.         end
  706.     end
  707.  
  708.     if db["Buffs"] and _G.TinyTipIcons_ShowBuffs then _G.TinyTipIcons_ShowBuffs(unit) end
  709.     if db["Debuffs"] and _G.TinyTipIcons_ShowDebuffs then _G.TinyTipIcons_ShowDebuffs(unit) end
  710. end
  711.     if (db["Buffs"] or db["Debuffs"]) and _G.TinyTipIcons_HideUnusedTextures then _G.TinyTipIcons_HideUnusedTextures() end
  712.    
  713.     if db["BGColor"] ~= 1 then
  714.         if db["BGColor"] == 3 then
  715.             fSetBDColor(GameTooltip, 0, 0, 0)
  716.         else
  717.             fSetBDColor(GameTooltip, bdR, bdG, bdB )
  718.         end
  719.     end
  720.     if db["Border"] ~= 1 then
  721.         if db["Border"] == 2 then
  722.             fSetBDBColor(GameTooltip, 0,0,0,0)
  723.         else
  724.             local r,g,b = fGetBDColor(GameTooltip)
  725.             r,g,b = r * 1.5, g * 1.5, b * 1.5
  726.             fSetBDBColor(GameTooltip, r,g,b,1)
  727.         end
  728.     end
  729.    
  730.  
  731.     this.skipOnShow = nil
  732.     GameTooltip:Show() -- used to re-size gametooltip
  733.  
  734.     if db["ExtraTooltip"] and _G.TinyTipExtras_Tooltip then
  735.         fSetBDColor(_G.TinyTipExtras_Tooltip, fGetBDColor(GameTooltip) )
  736.         fSetBDBColor( _G.TinyTipExtras_Tooltip, fGetBDBColor(GameTooltip) )
  737.         fSetBDColor(GameTooltip, 0,0,0)
  738.         fSetBDBColor(GameTooltip, 0,0,0,0)
  739.         _G.TinyTipExtras_Tooltip:Show()
  740.     end
  741.     if db["Compact"] then CompactTooltip(EventFrame.tooltip, unit) end
  742. end
  743. end
  744.  
  745. -- arg1=this,arg2=unit
  746. _G.TinyTip_Original_GameTooltip_SetUnit = nil
  747. function TinyTip_SetUnit(this,unit,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  748.     this.skipOnShow = true
  749.     if unit ~= "mouseover" and _G.TinyTip_Original_GameTooltip_SetUnit then
  750.         _G.TinyTip_Original_GameTooltip_SetUnit(this,unit,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  751.     end
  752.     GameTooltip.unit = unit
  753.     if db["HideInFrames"] and unit ~= "mouseover" then
  754.         fSetScript(EventFrame, "OnUpdate", nil)
  755.         fSetAlpha(GameTooltip, 0.01)
  756.         if GameTooltip.owner then
  757.             fClearPts(GameTooltip)
  758.             GameTooltip:SetOwner(GameTooltip.owner, "ANCHOR_NONE")
  759.         end
  760.     else
  761.         if db["ManaBar"] and _G.TinyTipExtras_ManaBar then sbShow(_G.TinyTipExtras_ManaBar) end
  762.         TooltipFormat(unit)
  763.         GameTooltip.unit = unit
  764.         if db["ExtraTooltip"] and _G.TinyTipAnchor_SetDefaultAnchor then
  765.             _G.TinyTipAnchor_SetDefaultAnchor(_G.TinyTipExtras_Tooltip, GameTooltip.owner)
  766.         end
  767.     end
  768.     this.skipOnShow = nil
  769. end
  770.  
  771. _G.TinyTip_Original_GameTooltip_FadeOut = nil
  772. function TinyTip_FadeOut(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  773.     if db["Fade"] == 2 or db["ExtraTooltip"] then
  774.         GameTooltip:Hide()
  775.     elseif _G.TinyTip_Original_GameTooltip_FadeOut then
  776.         _G.TinyTip_Original_GameTooltip_FadeOut(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  777.     end
  778. end
  779.  
  780. local Original_GameTooltip_OnTooltipCleared
  781. function TinyTip_OnTooltipCleared(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  782.     if Original_GameTooltip_OnTooltipCleared then
  783.         Original_GameTooltip_OnTooltipCleared(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  784.     end
  785.     if (db["Compact"] or TooltipCompacted) and not db["ExtraTooltip"] then
  786.         _G.TinyTip_UnCompactGameTooltip()
  787.     elseif PvPLine then
  788.         fClearPts(PvPLine)
  789.         fSetPt(PvPLine, "TOPLEFT", PvPBeforeLine or gtLine2, "BOTTOMLEFT", 0, -2)
  790.         PvPLine,PvPBeforeLine = nil, nil
  791.     end
  792.     GameTooltip.unit = nil
  793.     fSetScript(EventFrame, "OnUpdate", nil)
  794.     _G.GameTooltip_ClearMoney()
  795. end
  796.  
  797. _G.TinyTip_Original_GameTooltip_OnShow = nil
  798. function TinyTip_OnShow(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  799.     if _G.TinyTip_Original_GameTooltip_OnShow and not this.skipOnShow then
  800.         _G.TinyTip_Original_GameTooltip_OnShow(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  801.     end
  802.     if db["AlwaysAnchor"] and not GameTooltip.unit and not _G.UnitExists("mouseover") and not EventFrame:GetScript("OnUpdate") and _G.TinyTipAnchor_AlwaysAnchor then
  803.         fSetScript(EventFrame, "OnUpdate", _G.TinyTipAnchor_AlwaysAnchor)
  804.     end
  805.     if GameTooltip.unit then
  806.         _G.GameTooltip_ClearMoney()
  807.     end
  808. end
  809.  
  810. local function OnEvent()   
  811.     if _G.event == "UPDATE_MOUSEOVER_UNIT" then
  812.         if UnitExists("mouseover") then
  813.             GameTooltip:SetUnit("mouseover")
  814.         end
  815.     elseif _G.event == "PLAYER_ENTERING_WORLD" and db then -- rescale
  816.         _G.TinyTip_SetScale("Scale", db["Scale"] )
  817.         if _G.TinyTipExtras_Init then _G.TinyTipExtras_Init(db) end
  818.     elseif _G.event == "ADDON_LOADED" and _G.arg1 == "TinyTip" then
  819.         InitDB()
  820.         if _G.TinyTipAnchor_SetLocals then
  821.             _G.TinyTipAnchor_SetLocals(db,EventFrame,acehook)
  822.         end
  823.         local ttextraserror = true
  824.         if db["UseAceHook"] or db["PvPIcon"] or db["Buffs"] or db["Debuffs"] or db["ExtraTooltip"] or db["ManaBar"] or db["RTIcon"] then
  825.             ttextraserror = _G.TinyTip_LoDRun( "TinyTipExtras", "TinyTipExtras_Init", db, EventFrame,acehook)
  826.         elseif db["ToT"] or db["ToP"] or db["ToR"] then
  827.             _G.TinyTip_LoDRun( "TinyTipExtras", "TinyTipTargetsExists")
  828.         end
  829.         if not acehook:IsHooked(GameTooltip, "FadeOut") and ( db["Fade"] == 2 or db["ExtraTooltip"] ) then
  830.             acehook:Hook(GameTooltip, "FadeOut", _G.TinyTip_FadeOut)
  831.             _G.TinyTip_Original_GameTooltip_FadeOut = acehook.hooks[GameTooltip]["FadeOut"].orig
  832.         end
  833.         if not acehook:IsHooked(GameTooltip, "OnShow") then
  834.             acehook:HookScript(GameTooltip, "OnShow", _G.TinyTip_OnShow)
  835.             _G.TinyTip_Original_GameTooltip_OnShow = acehook.hooks[GameTooltip]["OnShow"].orig
  836.         end
  837.         if not acehook:IsHooked(GameTooltip, "OnTooltipCleared") then -- most sure-fire way to hide something
  838.             acehook:HookScript(GameTooltip, "OnTooltipCleared", _G.TinyTip_OnTooltipCleared)
  839.             _G.TinyTip_Original_GameTooltip_OnTooltipCleared = acehook.hooks[GameTooltip]["OnTooltipCleared"].orig
  840.         end
  841.  
  842.         _G.TinyTip_SetScale( "Scale", db["Scale"] )
  843.  
  844.         if db["Fade"] == 2 then
  845.             EventFrame:SetScript("OnUpdate", _G.TinyTip_SlimOnUpdate)
  846.         end
  847.  
  848.         TinyTip_SmoothBorder()
  849.  
  850.         EventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  851.         EventFrame:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
  852.         GameTooltip:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")   
  853.     end
  854. end
  855.  
  856. -----------------------------------------------------------------------
  857. -- WoW-Required Functions
  858. --
  859.  
  860. _G.SlashCmdList["TINYTIP"] = function(msg)
  861.     if db then
  862.         _G.TinyTip_LoDRun( "TinyTipOptions", "TinyTipChat_SlashHandler", msg, db)
  863.     end
  864. end
  865.    
  866. -----------------------------------------------------------------------
  867. -- Ready the mod
  868. --
  869. EventFrame = _G.CreateFrame("Frame", "TinyTipEventFrame", GameTooltip)
  870. EventFrame:SetScript("OnEvent", OnEvent)
  871. EventFrame:RegisterEvent("ADDON_LOADED")
  872. EventFrame:Show()
  873. EventFrame.tooltip = GameTooltip
  874.  
  875. -- hook these immediatly
  876. if _G.TinyTipAnchor_Hook then TinyTipAnchor_Hook(acehook) end
  877.  
  878. if not acehook:IsHooked(GameTooltip, "SetUnit") then
  879.     acehook:Hook(GameTooltip, "SetUnit", _G.TinyTip_SetUnit)
  880.     _G.TinyTip_Original_GameTooltip_SetUnit = acehook.hooks[GameTooltip]["SetUnit"].orig
  881. end
Advertisement
Add Comment
Please, Sign In to add comment