Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Freebtip by Freebaser
- local F, C = unpack(Aurora)
- local _, ns = ...
- local cfg = {
- font = C.media.font2,
- fontsize = 8,
- outline = "OUTLINEMONOCHROME",
- tex = C.media.backdrop,
- scale = 1,
- point = { "BOTTOMRIGHT", "BOTTOMRIGHT", -100, 224 },
- cursor = false,
- hideTitles = false,
- hideRealm = false,
- backdrop = {
- bgFile = "Interface\\Buttons\\WHITE8x8",
- edgeFile = C.media.backdrop,
- tile = true,
- tileSize = 0,
- edgeSize = 1,
- insets = { left = 1, right = 1, top = 1, bottom = 1 },
- },
- bgcolor = { r=0, g=0, b=0, t=0.5 },
- bdrcolor = { r=0, g=0, b=0},
- gcolor = { r=1, g=0.1, b=0.8 },
- you = "<You>",
- boss = "??",
- colorborderClass = false,
- combathide = false,
- combathideALL = false,
- powerbar = false,
- powerManaOnly = false,
- }
- ns.cfg = cfg
- local colors = {power = {}}
- for power, color in next, PowerBarColor do
- if(type(power) == 'string') then
- colors.power[power] = {color.r, color.g, color.b}
- end
- end
- colors.power['MANA'] = {.31,.45,.63}
- colors.power['RAGE'] = {.69,.31,.31}
- local classification = {
- elite = "+",
- rare = " R",
- rareelite = " R+",
- }
- local numberize = function(val)
- if (val >= 1e6) then
- return ("%.1fm"):format(val / 1e6)
- elseif (val >= 1e3) then
- return ("%.1fk"):format(val / 1e3)
- else
- return ("%d"):format(val)
- end
- end
- local find = string.find
- local format = string.format
- local hex = function(color)
- return format('|cff%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
- end
- local function unitColor(unit)
- local color = { r=1, g=1, b=1 }
- if UnitIsPlayer(unit) then
- local _, class = UnitClass(unit)
- color = RAID_CLASS_COLORS[class]
- return color
- else
- local reaction = UnitReaction(unit, "player")
- if reaction then
- color = FACTION_BAR_COLORS[reaction]
- return color
- end
- end
- return color
- end
- function GameTooltip_UnitColor(unit)
- local color = unitColor(unit)
- return color.r, color.g, color.b
- end
- local function getTarget(unit)
- if UnitIsUnit(unit, "player") then
- return ("|cffff0000%s|r"):format(cfg.you)
- else
- return hex(unitColor(unit))..UnitName(unit).."|r"
- end
- end
- local function UpdatePower()
- return function(self, elapsed)
- self.elapsed = self.elapsed + elapsed
- if self.elapsed < .25 then return end
- local unit = self.unit
- if(unit) then
- local min, max = UnitPower(unit), UnitPowerMax(unit)
- if(max ~= 0) then
- self:SetValue(min)
- local pp = numberize(min).." / "..numberize(max)
- self.text:SetText(pp)
- end
- end
- self.elapsed = 0
- end
- end
- local function HidePower(powerbar)
- if powerbar then
- powerbar:Hide()
- if powerbar.text then
- powerbar.text:SetText(nil)
- end
- end
- end
- local function ShowPowerBar(self, unit, statusbar)
- local powerbar = _G[self:GetName().."FreebTipPowerBar"]
- if not unit then return HidePower(powerbar) end
- local min, max = UnitPower(unit), UnitPowerMax(unit)
- local ptype, ptoken = UnitPowerType(unit)
- if(max == 0 or (cfg.powerManaOnly and ptoken ~= 'MANA')) then
- return HidePower(powerbar)
- end
- if(not powerbar) then
- powerbar = CreateFrame("StatusBar", self:GetName().."FreebTipPowerBar", statusbar)
- powerbar:SetHeight(statusbar:GetHeight())
- powerbar:SetWidth(0)
- powerbar:SetStatusBarTexture(cfg.tex, "OVERLAY")
- powerbar.elapsed = 0
- powerbar:SetScript("OnUpdate", UpdatePower())
- local bg = powerbar:CreateTexture(nil, "BACKGROUND")
- bg:SetAllPoints(powerbar)
- bg:SetTexture(cfg.tex)
- bg:SetVertexColor(0.5, 0.5, 0.5, 0.5)
- end
- powerbar.unit = unit
- powerbar:SetMinMaxValues(0, max)
- powerbar:SetValue(min)
- local pcolor = colors.power[ptoken]
- if(pcolor) then
- powerbar:SetStatusBarColor(pcolor[1], pcolor[2], pcolor[3])
- end
- powerbar:SetPoint("LEFT", statusbar, "LEFT", 0, -(statusbar:GetHeight()) - 5)
- powerbar:SetPoint("RIGHT", self, "RIGHT", -9, 0)
- self:AddLine(" ")
- powerbar:Show()
- if(not powerbar.text) then
- powerbar.text = powerbar:CreateFontString(nil, "OVERLAY")
- powerbar.text:SetPoint("CENTER", powerbar)
- powerbar.text:SetFont(cfg.font, 12, cfg.outline)
- powerbar.text:Show()
- end
- local pp = numberize(min).." / "..numberize(max)
- powerbar.text:SetText(pp)
- end
- GameTooltip:HookScript("OnTooltipSetUnit", function(self)
- local name, unit = self:GetUnit()
- if unit then
- if cfg.combathide and InCombatLockdown() then
- return self:Hide()
- end
- local color = unitColor(unit)
- local ricon = GetRaidTargetIndex(unit)
- if ricon then
- local text = GameTooltipTextLeft1:GetText()
- GameTooltipTextLeft1:SetText(("%s %s"):format(ICON_LIST[ricon].."14|t", text))
- end
- if UnitIsPlayer(unit) then
- self:AppendText((" |cff00cc00%s|r"):format(UnitIsAFK(unit) and CHAT_FLAG_AFK or
- UnitIsDND(unit) and CHAT_FLAG_DND or
- not UnitIsConnected(unit) and "<DC>" or ""))
- if cfg.hideTitles then
- local title = UnitPVPName(unit)
- if title then
- local text = GameTooltipTextLeft1:GetText()
- title = title:gsub(name, "")
- text = text:gsub(title, "")
- if text then GameTooltipTextLeft1:SetText(text) end
- end
- end
- if cfg.hideRealm then
- local _, realm = UnitName(unit)
- if realm then
- local text = GameTooltipTextLeft1:GetText()
- text = text:gsub("- "..realm, "")
- if text then GameTooltipTextLeft1:SetText(text) end
- end
- end
- local unitGuild = GetGuildInfo(unit)
- local text2 = GameTooltipTextLeft2:GetText()
- if unitGuild and text2 and text2:find("^"..unitGuild) then
- GameTooltipTextLeft2:SetTextColor(cfg.gcolor.r, cfg.gcolor.g, cfg.gcolor.b)
- end
- end
- local alive = not UnitIsDeadOrGhost(unit)
- local level = UnitLevel(unit)
- if level then
- local unitClass = UnitIsPlayer(unit) and hex(color)..UnitClass(unit).."|r" or ""
- local creature = not UnitIsPlayer(unit) and UnitCreatureType(unit) or ""
- local diff = GetQuestDifficultyColor(level)
- if level == -1 then
- level = "|cffff0000"..cfg.boss
- end
- local classify = UnitClassification(unit)
- local textLevel = ("%s%s%s|r"):format(hex(diff), tostring(level), classification[classify] or "")
- for i=2, self:NumLines() do
- local tiptext = _G["GameTooltipTextLeft"..i]
- if tiptext:GetText():find(LEVEL) then
- if alive then
- tiptext:SetText(("%s %s%s %s"):format(textLevel, creature, UnitRace(unit) or "", unitClass):trim())
- else
- tiptext:SetText(("%s %s"):format(textLevel, "|cffCCCCCC"..DEAD.."|r"):trim())
- end
- end
- if tiptext:GetText():find(PVP) then
- tiptext:SetText(nil)
- end
- end
- end
- if not alive then
- GameTooltipStatusBar:Hide()
- end
- if UnitExists(unit.."target") then
- local tartext = ("%s: %s"):format(TARGET, getTarget(unit.."target"))
- self:AddLine(tartext)
- end
- GameTooltipStatusBar:SetStatusBarColor(color.r, color.g, color.b)
- else
- for i=2, self:NumLines() do
- local tiptext = _G["GameTooltipTextLeft"..i]
- if tiptext:GetText():find(PVP) then
- tiptext:SetText(nil)
- end
- end
- GameTooltipStatusBar:SetStatusBarColor(0, .9, 0)
- end
- if GameTooltipStatusBar:IsShown() then
- self:AddLine(" ")
- GameTooltipStatusBar:ClearAllPoints()
- GameTooltipStatusBar:SetPoint("LEFT", self:GetName().."TextLeft"..self:NumLines(), "LEFT", 0, -2)
- GameTooltipStatusBar:SetPoint("RIGHT", self, -9, 0)
- if cfg.powerbar then
- ShowPowerBar(self, unit, GameTooltipStatusBar)
- end
- end
- end)
- GameTooltipStatusBar:SetStatusBarTexture(cfg.tex)
- local bg = GameTooltipStatusBar:CreateTexture(nil, "BACKGROUND")
- bg:SetAllPoints(GameTooltipStatusBar)
- bg:SetTexture(cfg.tex)
- bg:SetVertexColor(0,0,0,1)
- bg:SetPoint("TOPLEFT", GameTooltipStatusBar, -1, 1)
- bg:SetPoint("BOTTOMRIGHT", GameTooltipStatusBar, 1, -1)
- GameTooltipStatusBar:SetScript("OnValueChanged", function(self, value)
- if not value then
- return
- end
- local min, max = self:GetMinMaxValues()
- if (value < min) or (value > max) then
- return
- end
- local _, unit = GameTooltip:GetUnit()
- if unit then
- min, max = UnitHealth(unit), UnitHealthMax(unit)
- if not self.text then
- self.text = self:CreateFontString(nil, "OVERLAY")
- self.text:SetPoint("CENTER", GameTooltipStatusBar)
- self.text:SetFont(cfg.font, 8, cfg.outline)
- end
- self.text:Hide()
- local hp = numberize(min).." / "..numberize(max)
- self.text:SetText(hp)
- end
- end)
- hooksecurefunc("GameTooltip_SetDefaultAnchor", function(tooltip, parent)
- local frame = GetMouseFocus()
- if cfg.cursor and frame == WorldFrame then
- tooltip:SetOwner(parent, "ANCHOR_CURSOR")
- else
- tooltip:SetOwner(parent, "ANCHOR_NONE")
- tooltip:SetPoint(cfg.point[1], UIParent, cfg.point[2], cfg.point[3], cfg.point[4])
- end
- tooltip.default = 1
- end)
- local function setBakdrop(frame)
- frame:SetBackdrop(cfg.backdrop)
- frame:SetScale(cfg.scale)
- frame.freebBak = true
- end
- local function style(frame)
- if not frame.freebBak then
- setBakdrop(frame)
- end
- frame:SetBackdropColor(cfg.bgcolor.r, cfg.bgcolor.g, cfg.bgcolor.b, cfg.bgcolor.t)
- frame:SetBackdropBorderColor(cfg.bdrcolor.r, cfg.bdrcolor.g, cfg.bdrcolor.b)
- if cfg.colorborderClass then
- local _, unit = GameTooltip:GetUnit()
- if UnitIsPlayer(unit) then
- frame:SetBackdropBorderColor(GameTooltip_UnitColor(unit))
- end
- end
- if frame.NumLines then
- for index=1, frame:NumLines() do
- if index == 1 then
- _G[frame:GetName()..'TextLeft'..index]:SetFont(cfg.font, cfg.fontsize, cfg.outline)
- else
- _G[frame:GetName()..'TextLeft'..index]:SetFont(cfg.font, cfg.fontsize, cfg.outline)
- end
- _G[frame:GetName()..'TextRight'..index]:SetFont(cfg.font, cfg.fontsize, cfg.outline)
- end
- end
- end
- ns.style = style
- local tooltips = {
- GameTooltip,
- ItemRefTooltip,
- ShoppingTooltip1,
- ShoppingTooltip2,
- ShoppingTooltip3,
- WorldMapTooltip,
- DropDownList1MenuBackdrop,
- DropDownList2MenuBackdrop,
- }
- for i, frame in ipairs(tooltips) do
- frame:SetScript("OnShow", function(frame)
- if(cfg.combathideALL and InCombatLockdown()) then
- return frame:Hide()
- end
- style(frame)
- end)
- end
- local itemrefScripts = {
- "OnTooltipSetItem",
- "OnTooltipSetAchievement",
- "OnTooltipSetQuest",
- "OnTooltipSetSpell",
- }
- for i, script in ipairs(itemrefScripts) do
- ItemRefTooltip:HookScript(script, function(self)
- style(self)
- end)
- end
- local f = CreateFrame"Frame"
- f:SetScript("OnEvent", function(self, event, ...) if ns[event] then return ns[event](ns, event, ...) end end)
- function ns:RegisterEvent(...) for i=1,select("#", ...) do f:RegisterEvent((select(i, ...))) end end
- function ns:UnregisterEvent(...) for i=1,select("#", ...) do f:UnregisterEvent((select(i, ...))) end end
- ns:RegisterEvent"PLAYER_LOGIN"
- function ns:PLAYER_LOGIN()
- for i, frame in ipairs(tooltips) do
- setBakdrop(frame)
- end
- ns:UnregisterEvent"PLAYER_LOGIN"
- end
- local frame = CreateFrame("Frame", "ItemRefTooltipIconFrame", _G["ItemRefTooltip"])
- frame:SetPoint("TOPRIGHT", _G["ItemRefTooltip"], "TOPLEFT", -2, -1)
- frame:SetSize(32, 32)
- local tex = frame:CreateTexture("ItemRefTooltipIcon", "TOOLTIP")
- tex:SetAllPoints(frame)
- F.CreateBG(frame)
- local AddItemIcon = function()
- local frame = _G["ItemRefTooltipIconFrame"]
- frame:Hide()
- local _, link = _G["ItemRefTooltip"]:GetItem()
- local icon = link and GetItemIcon(link)
- if(not icon) then return end
- _G["ItemRefTooltipIcon"]:SetTexture(icon)
- _G["ItemRefTooltipIcon"]:SetTexCoord(.08, .92, .08, .92)
- frame:Show()
- end
- hooksecurefunc("SetItemRef", AddItemIcon)
Add Comment
Please, Sign In to add comment