--[[ |
Colored Tooltips by Kharthus |
Simple tooltip addon to set background colors based on targeted unit |
|
v1.2 |
- Updated VARIABLES_LOADED to ADDON_LOADED |
v1.1 |
- Fixed double <guild> tags |
- Added global enable/disable setting |
v1.0 |
- Initial Release |
]] |
|
-- Global Variables |
ColoredTooltips_Config = {}; |
|
local default_config = { |
["ENABLE"] = 1, |
["COLOR"] = 1, |
["GUILD"] = 1, |
["PARTY"] = 1, |
["GUILDLABEL"] = 1, |
["PLAYERLABEL"] = 1, |
["PVPLABEL"] = 1, |
}; |
|
function ColoredTooltips_OnLoad(self) |
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT"); |
self:RegisterEvent("ADDON_LOADED"); |
|
ColoredTooltips_Config = {}; |
|
GameTooltip:HookScript("OnTooltipSetUnit", ColoredTooltips_SetBackground); |
|
tinsert(UISpecialFrames,"ColoredTooltipsOptions"); |
|
-- Set slash command |
SlashCmdList["COLOREDTOOLTIPS"] = function (msg) |
ColoredTooltips_Command(msg); |
end |
SLASH_COLOREDTOOLTIPS1 = "/coloredtooltips"; |
SLASH_COLOREDTOOLTIPS2 = "/colortool"; |
end |
|
function ColoredTooltips_Command(msg) |
ColoredTooltipsOptions:Show(); |
end |
|
function ColoredTooltips_OnEvent(self,event,...) |
local arg1 = ...; |
if (event == "UPDATE_MOUSEOVER_UNIT") then |
ColoredTooltips_SetBackground() |
elseif (event == "ADDON_LOADED" and arg1 == "ColoredTooltips") then |
if( not ColoredTooltips_Config ) then |
ColoredTooltips_Config = {}; |
end |
for k in pairs(default_config) do |
if (ColoredTooltips_Config[k] == nil) then |
ColoredTooltips_Config[k] = default_config[k]; |
end |
end |
end |
end |
|
function ColoredTooltips_SetBackground() |
local __, unit = GameTooltip:GetUnit(); |
|
if(UnitExists(unit) and ColoredTooltips_Config["ENABLE"] == 1) then |
local r, g, b = GameTooltip_UnitColor(unit); |
local changed = false; |
GameTooltipTextLeft1:SetTextColor(1,1,1); |
if (ColoredTooltips_Config["COLOR"] == 1) then |
-- Set tooltip bg to blue for players |
if(r == 1 and g == 1 and b == 1) then |
r = 0; |
g = 0; |
end |
changed = true; |
end |
if (ColoredTooltips_Config["GUILD"] == 1) then |
-- set tooltip bg to a diffrent color for guild members |
local playerGuild = GetGuildInfo("Player"); |
-- if the player is in a guild, and the 'type' is in the same guild |
if (playerGuild and playerGuild ~= "" and GetGuildInfo(unit) == playerGuild) then |
r = 0.4; |
g = 1.0; |
b = 1.0; |
changed = true; |
end |
end |
|
if (ColoredTooltips_Config["PARTY"] == 1) then |
-- set tooltip bg to a diffrent color for party members |
if (UnitInParty(unit) ) then |
r = 0.8; |
g = 0.4; |
b = 1.0; |
changed = true; |
end |
end |
|
if (changed) then |
GameTooltip:SetBackdropColor(r, g, b); |
end |
|
if (ColoredTooltips_Config["GUILDLABEL"] == 1) then |
local guild = GetGuildInfo(unit); |
if (guild) then |
if (GameTooltipTextLeft2:GetText() == guild and GameTooltipTextLeft2:IsVisible()) then |
GameTooltipTextLeft2:Hide(); |
GameTooltip:AddLine(string.format("<%s>", guild)); |
end |
end |
end |
|
if (ColoredTooltips_Config["PLAYERLABEL"] == 1) then |
local originalText = GameTooltipTextLeft2:GetText(); |
if (originalText ~= nil) then |
local newText = string.gsub(originalText, " [(]Player[)]", ""); |
GameTooltipTextLeft2:SetText(newText); |
end |
local originalText = GameTooltipTextLeft3:GetText(); |
if (originalText ~= nil) then |
local newText = string.gsub(originalText, " [(]Player[)]", ""); |
GameTooltipTextLeft3:SetText(newText); |
end |
end |
|
if (ColoredTooltips_Config["PVPLABEL"] == 1) then |
for i = 3, 5 do |
local tooltipTextLeft = _G["GameTooltipTextLeft"..i]; |
local originalText = tooltipTextLeft:GetText(); |
if (originalText ~= nil) then |
local newText = string.gsub(originalText, "PvP", ""); |
if (newText == "") then |
tooltipTextLeft:SetText(nil); |
tooltipTextLeft:Hide(); |
-- removes the right line too, which should provide alignment. |
local tooltipTextRight = _G["GameTooltipTextRight"..i]; |
if ( tooltipTextRight ) then |
tooltipTextRight:SetText(nil); |
tooltipTextRight:Hide(); |
end |
end |
end |
end |
end |
|
ColoredTooltips_MouseOverFixSize(); |
end |
end |
|
-- fix the size and remove blank lines |
-- note that blank lines can still be created by setting the string to "" |
function ColoredTooltips_MouseOverFixSize() |
local tooltipName = "GameTooltip"; |
local lastValid = 0; |
for i = 1, 20 do |
local checkLeftText = _G[tooltipName.."TextLeft"..i]; |
local checkRightText = _G[tooltipName.."TextRight"..i]; |
local width = ColoredTooltips_GetTooltipLineWidth(checkLeftText, checkRightText); |
if (width) then |
lastValid = lastValid + 1; |
if (lastValid ~= i) then |
local moveLeftText = _G[tooltipName.."TextLeft"..lastValid]; |
local moveRightText = _G[tooltipName.."TextRight"..lastValid]; |
if (moveLeftText ~= nil and checkLeftText ~= nil) then |
moveLeftText:SetText(checkLeftText:GetText()); |
moveLeftText:SetTextColor(checkLeftText:GetTextColor()); |
if (checkLeftText:IsVisible()) then |
moveLeftText:Show(); |
end |
checkLeftText:SetText(""); |
checkLeftText:Hide(); |
end |
if (moveRightText ~= nil and checkRightText~=nil) then |
moveRightText:SetText(checkRightText:GetText()); |
moveRightText:SetTextColor(checkRightText:GetTextColor()); |
if (checkRightText:IsVisible()) then |
moveRightText:Show(); |
end |
checkRightText:SetText(""); |
checkRightText:Hide(); |
end |
end |
end |
end |
|
GameTooltip:Show(); |
end |
|
function ColoredTooltips_GetTooltipLineWidth(leftText, rightText) |
if ((not leftText or not leftText:IsVisible()) and (not rightText or not rightText:IsVisible())) then |
return; |
end; |
local result = 0; |
if (leftText and leftText:IsVisible()) then |
result = result + leftText:GetWidth() + 24; |
end |
if (rightText and rightText:IsVisible()) then |
result = result + rightText:GetWidth() + 24; |
end |
if (leftText and leftText:IsVisible() and rightText and rightText:IsVisible()) then |
result = result + 10; |
end; |
|
return result; |
end |
|
function ColoredTooltipsOptions_OnShow() |
ColoredTooltipsOptionsFrameEventFrames = { }; |
ColoredTooltipsOptionsFrameEventFrames [1] = { text = COLORTOOL_CHECK_TEXT1, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT1, ColoredTooltipsVar = "ENABLE"}; |
ColoredTooltipsOptionsFrameEventFrames [2] = { text = COLORTOOL_CHECK_TEXT2, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT2, ColoredTooltipsVar = "COLOR"}; |
ColoredTooltipsOptionsFrameEventFrames [3] = { text = COLORTOOL_CHECK_TEXT3, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT3, ColoredTooltipsVar = "GUILD"}; |
ColoredTooltipsOptionsFrameEventFrames [4] = { text = COLORTOOL_CHECK_TEXT4, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT4, ColoredTooltipsVar = "PARTY"}; |
ColoredTooltipsOptionsFrameEventFrames [5] = { text = COLORTOOL_CHECK_TEXT5, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT5, ColoredTooltipsVar = "GUILDLABEL"}; |
ColoredTooltipsOptionsFrameEventFrames [6] = { text = COLORTOOL_CHECK_TEXT6, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT6, ColoredTooltipsVar = "PLAYERLABEL"}; |
ColoredTooltipsOptionsFrameEventFrames [7] = { text = COLORTOOL_CHECK_TEXT7, tooltipText = COLORTOOL_CHECK_TOOLTIPTEXT7, ColoredTooltipsVar = "PVPLABEL"}; |
|
local button, string, checked; |
|
for key, value in pairs(ColoredTooltipsOptionsFrameEventFrames) do |
local string = getglobal("ColoredTooltipsOptionsFrame_CheckButton"..key.."Text"); |
local button = getglobal("ColoredTooltipsOptionsFrame_CheckButton"..key); |
|
if ( value.ColoredTooltipsVar ) then |
if ( ColoredTooltips_Config[value.ColoredTooltipsVar] == 1 ) then |
checked = 1; |
else |
checked = 0; |
end |
else |
checked = 0; |
end |
button:SetChecked(checked); |
string:SetText(value.text); |
button.tooltipText = value.tooltipText; |
end |
|
end |
|
function ColoredTooltips_OptionsCheckButtonOnClick(self) |
local button; |
|
--loop thru checkbox array to find current one, then update its value |
for key, value in pairs(ColoredTooltipsOptionsFrameEventFrames) do |
if (self:GetName() == "ColoredTooltipsOptionsFrame_CheckButton"..key) then |
button = getglobal("ColoredTooltipsOptionsFrame_CheckButton"..key); |
if ( button:GetChecked() ) then |
value.value = 1; |
else |
value.value = 0; |
end |
if ( ColoredTooltips_Config[value.ColoredTooltipsVar] ) then |
ColoredTooltips_Config[value.ColoredTooltipsVar] = value.value; |
end |
end |
end |
end |
|
function ColoredTooltipsOptions_OnLoad() |
UIPanelWindows["ColoredTooltipsOptions"] = {area = "center", pushable = 0}; |
end |
|
function ColoredTooltipsOptions_OnHide(self) |
|
end |