Guest User

TinyTip_friendly_hostile

a guest
Jan 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.93 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.                     --_,tmp34=_G.UnitClass(unit)
  469.                         --if tmp34 and _G.RAID_CLASS_COLORS[tmp34] then
  470.                             --bdR,bdG,bdB  = _G.RAID_CLASS_COLORS[tmp34].r,_G.RAID_CLASS_COLORS[tmp34].g,_G.RAID_CLASS_COLORS[tmp34].b
  471.                         --else
  472.                             bdR,bdG,bdB = 0.5,0.2,0.1
  473.                         --end
  474.                     else
  475.                         _,tmp34=_G.UnitClass(unit)
  476.                         if tmp34 and _G.RAID_CLASS_COLORS[tmp34] then
  477.                             bdR,bdG,bdB  = _G.RAID_CLASS_COLORS[tmp34].r,_G.RAID_CLASS_COLORS[tmp34].g,_G.RAID_CLASS_COLORS[tmp34].b
  478.                         else
  479.                             bdR,bdG,bdB = 0.5,0.0,0.0
  480.                         end
  481.                     end
  482.                 end
  483.             end
  484.     elseif ( tmp and _G.UnitCanAttack("player",unit) ) or
  485.            ( not tmp and tmp2 and tmp2 <= 4 ) then -- neutral
  486.             fsSetTextColor(gtLine1, _G.FACTION_BAR_COLORS[4].r,
  487.                         _G.FACTION_BAR_COLORS[4].g,
  488.                         _G.FACTION_BAR_COLORS[4].b)
  489.             if db["ReactionText"] then treac = _G.FACTION_STANDING_LABEL4 end
  490.             if (tmp and not db["BGColor"]) or db["BGColor"] == 2 then
  491.                 tooltip:SetBackdropColor( 0.5, 0.5, 0.0)
  492.             end
  493.     else -- friendly
  494.         treac = _G.FACTION_STANDING_LABEL5
  495.         if (tmp and not db["BGColor"]) or db["BGColor"] == 2 then
  496.             bdR,bdG,bdB = 0.0, 0.0, 0.5
  497.                 _,tmp33=_G.UnitClass(unit)
  498.                 if tmp33 and _G.RAID_CLASS_COLORS[tmp33] then
  499.                 bdR,bdG,bdB  = _G.RAID_CLASS_COLORS[tmp33].r,_G.RAID_CLASS_COLORS[tmp33].g,_G.RAID_CLASS_COLORS[tmp33].b
  500.                 end
  501.         end
  502.         if _G.UnitIsPVP(unit) then -- friendly, PvP-enabled
  503.             fsSetTextColor(gtLine1, _G.FACTION_BAR_COLORS[6].r,
  504.                                                                         _G.FACTION_BAR_COLORS[6].g,
  505.                                                                         _G.FACTION_BAR_COLORS[6].b)
  506.         else
  507.             fsSetTextColor(gtLine1, (not tmp and _G.FACTION_BAR_COLORS[tmp2 or 5].r) or 0,
  508.                                                                         (not tmp and _G.FACTION_BAR_COLORS[tmp2 or 5].g) or 0.67,
  509.                                                                         (not tmp and _G.FACTION_BAR_COLORS[tmp2 or 5].b) or 1.0)
  510.         end
  511.     end
  512.  
  513.     -- remove PvP line, if it exists
  514.     PvP_Line = nil
  515.     if not db["ReactionText"] and _G.UnitIsPVP(unit) then
  516.         tmp = gtNumLines(GameTooltip)
  517.         for i=3,tmp,1 do
  518.             tmp2 = _G["GameTooltipTextLeft" .. i]
  519.             if tmp2 then
  520.                 tmp3 = fsGetText(tmp2)
  521.                 if tmp3 and strfind(tmp3, _G.PVP_ENABLED, 1, true) then
  522.                     PvPLine = tmp2
  523.                     PvPBeforeLine = _G["GameTooltipTextLeft" .. (i-1)]
  524.                     fsSetText(PvPLine, nil)
  525.                     fClearPts(PvPLine)
  526.                     fSetPt(PvPLine, "TOPLEFT", PvPBeforeLine or gtLine2, "BOTTOMLEFT", 0, 1)
  527.                     fsHide(PvPLine)
  528.                     break
  529.                 end
  530.             end
  531.         end
  532.     end
  533.  
  534.     -- We like to know who our friends are.
  535.     if db["Friends"] ~= 2 and
  536.     _G.UnitIsPlayer(unit) and treac == _G.FACTION_STANDING_LABEL5 then
  537.         local num,name = _G.GetNumFriends(), _G.UnitName(unit)
  538.         for i = 1,num,1 do
  539.             tmp,tmp2 = _G.GetFriendInfo(i)
  540.             if tmp and tmp2 ~= 0 and name and tmp == name then
  541.                 if db["Friends"] == 1 or db["BGColor"] == 1 or db["BGColor"] == 3 then
  542.                     fsSetTextColor(gtLine1, 0.58, 0.0, 0.83)
  543.                 else
  544.                     bdR,bdG,bdB = 0.29, 0.0, 0.42
  545.                 end
  546.                 break
  547.             end
  548.         end
  549.     end
  550.    
  551.     -- Check for a dead unit, but try to leave out Hunter's Feign Death
  552.     if _G.UnitHealth(unit) <= 0 and
  553.     ( not _G.UnitIsPlayer(unit) or _G.UnitIsDeadOrGhost(unit) or _G.UnitIsCorpse(unit) ) then
  554.         if not db["BGColor"] or db["BGColor"] == 2 then
  555.             bdR,bdG,bdB = 0.54, 0.54, 0.54
  556.         end
  557.         fsSetTextColor(gtLine1, 0.54,0.54,0.54)
  558.         cdeadortap = "888888"
  559.         bdead = true
  560.     end
  561.    
  562.     -- set the color of line 2, if it's available
  563.     if levelLine == gtLine3 then
  564.         fsSetTextColor(gtLine2, fsGetTextColor(gtLine1) )
  565.     end
  566.  
  567.     if levelLine then
  568.     local clevel
  569.     local ulevel = _G.UnitLevel(unit)
  570.     tmp2 = ulevel - _G.UnitLevel("player") -- Level difficulty
  571.     if tmp2 and _G.UnitFactionGroup(unit) ~= _G.UnitFactionGroup("player") then
  572.         if tmp2 >= 5 or ulevel == -1 then clevel = "FF0000"
  573.         elseif tmp2 >= 3 then clevel = "FF6600"
  574.         elseif tmp2 >= -2 then clevel = "FFFF00"
  575.         elseif -tmp2 <= _G.GetQuestGreenRange() then clevel = "00FF00"
  576.         else clevel = "888888"
  577.         end    
  578.     end
  579.  
  580.         tmp = (not db["HideLevelText"] and SpaceLevel) or ""
  581.         if ulevel and ulevel >= 1 then
  582.             fsSetText(levelLine, "|cFF" ..
  583.                                                      (cdeadortap or clevel or "FFCC00") ..
  584.                                                      tmp ..
  585.                                                      ulevel ..
  586.                                                      "|r")
  587.         elseif db["LevelGuess"] and ulevel and ulevel == -1 and ulevel < 60 then
  588.             fsSetText(levelLine, "|cFF" ..
  589.                                                      (cdeadortap or clevel or "FFCC00") ..
  590.                                                      tmp .. ">" ..
  591.                                                       (_G.UnitLevel("player") + 10 ) ..
  592.                                                      "|r")
  593.         else
  594.             fsSetText(levelLine, "|cFF" ..
  595.                                                      (cdeadortap or clevel or "FFCC00") ..
  596.                                                      tmp ..
  597.                                                      "??|r")
  598.         end
  599.  
  600.         tmp2 = _G.UnitClassification(unit) -- Elite status
  601.         if tmp2 and tmp2 ~= "normal" then
  602.             if tmp2 == "elite" then
  603.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  604.                                                          ((db["KeyElite"] and "") or " ") ..
  605.                                                          "|cFF" ..
  606.                                                          (cdeadortap or "FFCC00") ..
  607.                                                          ((db["KeyElite"] and "*") or _G.ELITE) ..
  608.                                                          "|r" )
  609.             elseif tmp2 == "worldboss" then
  610.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  611.                                                          ((db["KeyElite"] and "") or " ") ..
  612.                                                          "|cFF" ..
  613.                                                          (cdeadortap or "FF0000") ..
  614.                                                          ((db["KeyElite"] and "**") or _G.BOSS) ..
  615.                                                          "|r" )
  616.             elseif tmp2 == "rare" then
  617.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  618.                                                          ((db["KeyElite"] and "") or " ") ..
  619.                                                          "|cFF" ..
  620.                                                          (cdeadortap or "FF66FF") ..
  621.                                                          ((db["KeyElite"] and "!") or _G.ITEM_QUALITY3_DESC) ..
  622.                                                          "|r" )
  623.             elseif tmp2 == "rareelite" then
  624.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  625.                                                          ((db["KeyElite"] and "") or " ") ..
  626.                                                          "|cFF" ..
  627.                                                          (cdeadortap or "FFAAFF") ..
  628.                                                          ((db["KeyElite"] and "!*") or _G.TinyTipLocale_RareElite) ..
  629.                                                          "|r" )
  630.             else
  631.                 fsSetText(levelLine, (fsGetText(levelLine) or "") ..
  632.                                                          " [|cFF" ..
  633.                                                          (cdeadortap or "FFFFFF") ..
  634.                                                          tmp2 ..
  635.                                                          "|r]" )
  636.             end
  637.         end
  638.  
  639.         -- Class And Race
  640.         if _G.UnitIsPlayer(unit) then
  641.             fsSetText(levelLine,    (fsGetText(levelLine) or "") ..
  642.                                                         " |cFF" ..
  643.                                                         (cdeadortap or "DDEEAA") ..
  644.                                                         (( not db["HideRace"] and (_G.UnitRace(unit) .. " ") ) or "") ..
  645.                                                         "|r|cFF" ..
  646.                                                         (cdeadortap or TinyTip_ColorPlayer(unit)) ..
  647.                                                         (_G.UnitClass(unit) or "" ) ..
  648.                                                         "|r")
  649.         elseif not db["HideRace"] then
  650.             if _G.UnitPlayerControlled(unit) then
  651.             fsSetText(levelLine,    (fsGetText(levelLine) or "") ..
  652.                                                         " |cFF" ..
  653.                                                         (cdeadortap or "DDEEAA") ..
  654.                                                         (_G.UnitCreatureFamily(unit) or "") ..
  655.                                                         "|r")
  656.             else
  657.             fsSetText(levelLine,    (fsGetText(levelLine) or "") ..
  658.                                                         " |cFF" ..
  659.                                                         (cdeadortap or "DDEEAA") ..
  660.                                                         (_G.UnitCreatureType(unit) or "") ..
  661.                                                         "|r")
  662.             end
  663.         end
  664.    
  665.     -- add corpse/tapped line
  666.     if cdeadortap and levelLine then
  667.         fsSetText(levelLine,
  668.                         (fsGetText(levelLine) or "") ..
  669.                         " |cFF888888(" ..
  670.                         ( ( bdead and _G.CORPSE ) or TinyTipLocale_Tapped ) ..
  671.                         ")|r")
  672.     end
  673.  
  674. end
  675. end
  676.  
  677.     if db["ExtraTooltip"] and _G.TinyTipExtras_CopyGameTooltip then
  678.         _G.TinyTipExtras_CopyGameTooltip()
  679.     end
  680.  
  681.     if not bdead then
  682.     -- Add Reaction Text
  683.     if db["ReactionText"] and treac then
  684.         gtAddLine( tooltip, treac, fsGetTextColor(gtLine1) )
  685.     end
  686.  
  687.     -- Add Guild info, if enabled
  688.     tmp2 = _G.GetGuildInfo(unit)
  689.     if not db["HideGuild"] and tmp2 then
  690.         tmp = "<" .. tmp2 .. ">"
  691.         if _G.IsInGuild() and tmp2 == _G.GetGuildInfo("player") and db["Friends"] ~= 2 then
  692.             if not db["Friends"] and not _G.UnitIsUnit(unit, "player") and db["BGColor"] ~= 3 and db["BGColor"] ~= 1 then
  693.                 bdR,bdG,bdB = 0.4, 0.1, 0.5
  694.                 gtAddLine( tooltip, tmp, fsGetTextColor(gtLine1) )
  695.             else
  696.                 gtAddLine( tooltip, tmp, 0.58, 0.0, 0.83)
  697.             end
  698.         else
  699.             gtAddLine( tooltip, tmp, fsGetTextColor(gtLine1) )
  700.         end
  701.     end
  702.  
  703.     if db["RTIcon"] and _G.TinyTipIcons_ResetRTIcon then _G.TinyTipIcons_ResetRTIcon(unit, _G.GetNumRaidMembers()) end
  704.     if db["ToT"] and _G.TinyTipTargets_Mouse then _G.TinyTipTargets_Mouse(unit, db["ToT"]) end
  705.     if db["ToR"] or db["ToP"] then
  706.         tmp,tmp2 = _G.GetNumRaidMembers(), _G.GetNumPartyMembers()
  707.         if db["ToR"] and _G.TinyTipTargets_Raid and tmp and tmp > 0 then _G.TinyTipTargets_Raid(unit, tmp, db["ToR"])
  708.         elseif db["ToP"] and _G.TinyTipTargets_Party and tmp2 and tmp2 > 0 then
  709.             _G.TinyTipTargets_Party(unit, tmp2, db["ToP"])
  710.         end
  711.     end
  712.  
  713.     if db["Buffs"] and _G.TinyTipIcons_ShowBuffs then _G.TinyTipIcons_ShowBuffs(unit) end
  714.     if db["Debuffs"] and _G.TinyTipIcons_ShowDebuffs then _G.TinyTipIcons_ShowDebuffs(unit) end
  715. end
  716.     if (db["Buffs"] or db["Debuffs"]) and _G.TinyTipIcons_HideUnusedTextures then _G.TinyTipIcons_HideUnusedTextures() end
  717.    
  718.     if db["BGColor"] ~= 1 then
  719.         if db["BGColor"] == 3 then
  720.             fSetBDColor(GameTooltip, 0, 0, 0)
  721.         else
  722.             fSetBDColor(GameTooltip, bdR, bdG, bdB )
  723.         end
  724.     end
  725.     if db["Border"] ~= 1 then
  726.         if db["Border"] == 2 then
  727.             fSetBDBColor(GameTooltip, 0,0,0,0)
  728.         else
  729.             local r,g,b = fGetBDColor(GameTooltip)
  730.             r,g,b = r * 1.5, g * 1.5, b * 1.5
  731.             fSetBDBColor(GameTooltip, r,g,b,1)
  732.         end
  733.     end
  734.    
  735.  
  736.     this.skipOnShow = nil
  737.     GameTooltip:Show() -- used to re-size gametooltip
  738.  
  739.     if db["ExtraTooltip"] and _G.TinyTipExtras_Tooltip then
  740.         fSetBDColor(_G.TinyTipExtras_Tooltip, fGetBDColor(GameTooltip) )
  741.         fSetBDBColor( _G.TinyTipExtras_Tooltip, fGetBDBColor(GameTooltip) )
  742.         fSetBDColor(GameTooltip, 0,0,0)
  743.         fSetBDBColor(GameTooltip, 0,0,0,0)
  744.         _G.TinyTipExtras_Tooltip:Show()
  745.     end
  746.     if db["Compact"] then CompactTooltip(EventFrame.tooltip, unit) end
  747. end
  748. end
  749.  
  750. -- arg1=this,arg2=unit
  751. _G.TinyTip_Original_GameTooltip_SetUnit = nil
  752. function TinyTip_SetUnit(this,unit,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  753.     this.skipOnShow = true
  754.     if unit ~= "mouseover" and _G.TinyTip_Original_GameTooltip_SetUnit then
  755.         _G.TinyTip_Original_GameTooltip_SetUnit(this,unit,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  756.     end
  757.     GameTooltip.unit = unit
  758.     if db["HideInFrames"] and unit ~= "mouseover" then
  759.         fSetScript(EventFrame, "OnUpdate", nil)
  760.         fSetAlpha(GameTooltip, 0.01)
  761.         if GameTooltip.owner then
  762.             fClearPts(GameTooltip)
  763.             GameTooltip:SetOwner(GameTooltip.owner, "ANCHOR_NONE")
  764.         end
  765.     else
  766.         if db["ManaBar"] and _G.TinyTipExtras_ManaBar then sbShow(_G.TinyTipExtras_ManaBar) end
  767.         TooltipFormat(unit)
  768.         GameTooltip.unit = unit
  769.         if db["ExtraTooltip"] and _G.TinyTipAnchor_SetDefaultAnchor then
  770.             _G.TinyTipAnchor_SetDefaultAnchor(_G.TinyTipExtras_Tooltip, GameTooltip.owner)
  771.         end
  772.     end
  773.     this.skipOnShow = nil
  774. end
  775.  
  776. _G.TinyTip_Original_GameTooltip_FadeOut = nil
  777. function TinyTip_FadeOut(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  778.     if db["Fade"] == 2 or db["ExtraTooltip"] then
  779.         GameTooltip:Hide()
  780.     elseif _G.TinyTip_Original_GameTooltip_FadeOut then
  781.         _G.TinyTip_Original_GameTooltip_FadeOut(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  782.     end
  783. end
  784.  
  785. local Original_GameTooltip_OnTooltipCleared
  786. function TinyTip_OnTooltipCleared(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  787.     if Original_GameTooltip_OnTooltipCleared then
  788.         Original_GameTooltip_OnTooltipCleared(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  789.     end
  790.     if (db["Compact"] or TooltipCompacted) and not db["ExtraTooltip"] then
  791.         _G.TinyTip_UnCompactGameTooltip()
  792.     elseif PvPLine then
  793.         fClearPts(PvPLine)
  794.         fSetPt(PvPLine, "TOPLEFT", PvPBeforeLine or gtLine2, "BOTTOMLEFT", 0, -2)
  795.         PvPLine,PvPBeforeLine = nil, nil
  796.     end
  797.     GameTooltip.unit = nil
  798.     fSetScript(EventFrame, "OnUpdate", nil)
  799.     _G.GameTooltip_ClearMoney()
  800. end
  801.  
  802. _G.TinyTip_Original_GameTooltip_OnShow = nil
  803. function TinyTip_OnShow(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  804.     if _G.TinyTip_Original_GameTooltip_OnShow and not this.skipOnShow then
  805.         _G.TinyTip_Original_GameTooltip_OnShow(this,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  806.     end
  807.     if db["AlwaysAnchor"] and not GameTooltip.unit and not _G.UnitExists("mouseover") and not EventFrame:GetScript("OnUpdate") and _G.TinyTipAnchor_AlwaysAnchor then
  808.         fSetScript(EventFrame, "OnUpdate", _G.TinyTipAnchor_AlwaysAnchor)
  809.     end
  810.     if GameTooltip.unit then
  811.         _G.GameTooltip_ClearMoney()
  812.     end
  813. end
  814.  
  815. local function OnEvent()   
  816.     if _G.event == "UPDATE_MOUSEOVER_UNIT" then
  817.         if UnitExists("mouseover") then
  818.             GameTooltip:SetUnit("mouseover")
  819.         end
  820.     elseif _G.event == "PLAYER_ENTERING_WORLD" and db then -- rescale
  821.         _G.TinyTip_SetScale("Scale", db["Scale"] )
  822.         if _G.TinyTipExtras_Init then _G.TinyTipExtras_Init(db) end
  823.     elseif _G.event == "ADDON_LOADED" and _G.arg1 == "TinyTip" then
  824.         InitDB()
  825.         if _G.TinyTipAnchor_SetLocals then
  826.             _G.TinyTipAnchor_SetLocals(db,EventFrame,acehook)
  827.         end
  828.         local ttextraserror = true
  829.         if db["UseAceHook"] or db["PvPIcon"] or db["Buffs"] or db["Debuffs"] or db["ExtraTooltip"] or db["ManaBar"] or db["RTIcon"] then
  830.             ttextraserror = _G.TinyTip_LoDRun( "TinyTipExtras", "TinyTipExtras_Init", db, EventFrame,acehook)
  831.         elseif db["ToT"] or db["ToP"] or db["ToR"] then
  832.             _G.TinyTip_LoDRun( "TinyTipExtras", "TinyTipTargetsExists")
  833.         end
  834.         if not acehook:IsHooked(GameTooltip, "FadeOut") and ( db["Fade"] == 2 or db["ExtraTooltip"] ) then
  835.             acehook:Hook(GameTooltip, "FadeOut", _G.TinyTip_FadeOut)
  836.             _G.TinyTip_Original_GameTooltip_FadeOut = acehook.hooks[GameTooltip]["FadeOut"].orig
  837.         end
  838.         if not acehook:IsHooked(GameTooltip, "OnShow") then
  839.             acehook:HookScript(GameTooltip, "OnShow", _G.TinyTip_OnShow)
  840.             _G.TinyTip_Original_GameTooltip_OnShow = acehook.hooks[GameTooltip]["OnShow"].orig
  841.         end
  842.         if not acehook:IsHooked(GameTooltip, "OnTooltipCleared") then -- most sure-fire way to hide something
  843.             acehook:HookScript(GameTooltip, "OnTooltipCleared", _G.TinyTip_OnTooltipCleared)
  844.             _G.TinyTip_Original_GameTooltip_OnTooltipCleared = acehook.hooks[GameTooltip]["OnTooltipCleared"].orig
  845.         end
  846.  
  847.         _G.TinyTip_SetScale( "Scale", db["Scale"] )
  848.  
  849.         if db["Fade"] == 2 then
  850.             EventFrame:SetScript("OnUpdate", _G.TinyTip_SlimOnUpdate)
  851.         end
  852.  
  853.         TinyTip_SmoothBorder()
  854.  
  855.         EventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  856.         EventFrame:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
  857.         GameTooltip:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")   
  858.     end
  859. end
  860.  
  861. -----------------------------------------------------------------------
  862. -- WoW-Required Functions
  863. --
  864.  
  865. _G.SlashCmdList["TINYTIP"] = function(msg)
  866.     if db then
  867.         _G.TinyTip_LoDRun( "TinyTipOptions", "TinyTipChat_SlashHandler", msg, db)
  868.     end
  869. end
  870.    
  871. -----------------------------------------------------------------------
  872. -- Ready the mod
  873. --
  874. EventFrame = _G.CreateFrame("Frame", "TinyTipEventFrame", GameTooltip)
  875. EventFrame:SetScript("OnEvent", OnEvent)
  876. EventFrame:RegisterEvent("ADDON_LOADED")
  877. EventFrame:Show()
  878. EventFrame.tooltip = GameTooltip
  879.  
  880. -- hook these immediatly
  881. if _G.TinyTipAnchor_Hook then TinyTipAnchor_Hook(acehook) end
  882.  
  883. if not acehook:IsHooked(GameTooltip, "SetUnit") then
  884.     acehook:Hook(GameTooltip, "SetUnit", _G.TinyTip_SetUnit)
  885.     _G.TinyTip_Original_GameTooltip_SetUnit = acehook.hooks[GameTooltip]["SetUnit"].orig
  886. end
Add Comment
Please, Sign In to add comment