Quantcast

fix tooltip

Ou Junhui [01-20-22 - 15:58]
fix tooltip
Filename
rMinimap/core.lua
rTooltip/core.lua
diff --git a/rMinimap/core.lua b/rMinimap/core.lua
index c4a8e38..a0e6da8 100644
--- a/rMinimap/core.lua
+++ b/rMinimap/core.lua
@@ -202,7 +202,7 @@ Hide(Minimap)

 --drag frame
 rLib:CreateDragFrame(MinimapCluster, L.dragFrames, -2, true)
-rLib:CreateDragFrame(QuestWatchFrame, L.dragFrames, -2, true)
+-- rLib:CreateDragFrame(QuestWatchFrame, L.dragFrames, -2, true)

 --create slash commands
 rLib:CreateSlashCmd(L.addonName, L.addonShortcut, L.dragFrames, L.addonColor)
diff --git a/rTooltip/core.lua b/rTooltip/core.lua
index 851ca95..23e0d79 100644
--- a/rTooltip/core.lua
+++ b/rTooltip/core.lua
@@ -14,6 +14,7 @@ local GameTooltip, GameTooltipStatusBar = GameTooltip, GameTooltipStatusBar
 local GameTooltipTextRight1, GameTooltipTextRight2, GameTooltipTextRight3, GameTooltipTextRight4, GameTooltipTextRight5, GameTooltipTextRight6, GameTooltipTextRight7, GameTooltipTextRight8 = GameTooltipTextRight1, GameTooltipTextRight2, GameTooltipTextRight3, GameTooltipTextRight4, GameTooltipTextRight5, GameTooltipTextRight6, GameTooltipTextRight7, GameTooltipTextRight8
 local GameTooltipTextLeft1, GameTooltipTextLeft2, GameTooltipTextLeft3, GameTooltipTextLeft4, GameTooltipTextLeft5, GameTooltipTextLeft6, GameTooltipTextLeft7, GameTooltipTextLeft8 = GameTooltipTextLeft1, GameTooltipTextLeft2, GameTooltipTextLeft3, GameTooltipTextLeft4, GameTooltipTextLeft5, GameTooltipTextLeft6, GameTooltipTextLeft7, GameTooltipTextLeft8
 local classColorHex, factionColorHex = {}, {}
+local Hider = CreateFrame("Frame", nil, UIParent) Hider:Hide()

 -----------------------------
 -- Config
@@ -162,6 +163,28 @@ local function OnTooltipSetUnit(self)
   end
 end

+local function SetItemBorderColor(tooltip)
+	local link = select(2, tooltip:GetItem())
+	local r, g, b
+	local backdrop = tooltip.Backdrop
+
+	if backdrop then
+		if link then
+			local quality = select(3, GetItemInfo(link))
+
+			if quality then
+				r, g, b = GetItemQualityColor(quality)
+			else
+				r, g, b = unpack(cfg.backdrop.borderColor)
+			end
+
+			backdrop:SetBackdropBorderColor(r, g, b)
+		else
+			backdrop:SetBackdropBorderColor(unpack(cfg.backdrop.borderColor))
+		end
+	end
+end
+
 local function OnTooltipSetItem(self)
   local _, link = self:GetItem()

@@ -173,11 +196,42 @@ local function OnTooltipSetItem(self)
     self:AddLine(" ")
     self:AddDoubleLine(id, text)
   end
+
+  SetItemBorderColor(self)
+end
+
+local function Kill(self)
+	if (self.UnregisterAllEvents) then
+		self:UnregisterAllEvents()
+		self:SetParent(Hider)
+	else
+		self.Show = self.Hide
+	end
+
+	self:Hide()
+end
+
+local function StripTextures(self, Kill)
+	for i = 1, self:GetNumRegions() do
+		local Region = select(i, self:GetRegions())
+		if (Region and Region:GetObjectType() == "Texture") then
+			if (Kill and type(Kill) == "boolean") then
+				Region:Kill()
+			elseif (Region:GetDrawLayer() == Kill) then
+				Region:SetTexture(nil)
+			elseif (Kill and type(Kill) == "string" and Region:GetTexture() ~= Kill) then
+				Region:SetTexture(nil)
+			else
+				Region:SetTexture(nil)
+			end
+		end
+	end
 end

-local function SetBackdropStyle(self,style)
+local function SetBackdropStyle(self, style)
   if self.TopOverlay then self.TopOverlay:Hide() end
   if self.BottomOverlay then self.BottomOverlay:Hide() end
+  StripTextures(self)
   self:SetBackdrop(cfg.backdrop)
   self:SetBackdropColor(unpack(cfg.backdrop.bgColor))
   local _, itemLink = self:GetItem()
@@ -198,6 +252,18 @@ local function SetBackdropStyle(self,style)
   end
 end

+local function CreateBackdrop(self)
+	if self.Backdrop then return end
+
+	self.Backdrop = CreateFrame("Frame", nil, self, "BackdropTemplate")
+	self.Backdrop:SetAllPoints()
+	self.Backdrop:SetFrameLevel(self:GetFrameLevel())
+
+	self.Backdrop:SetBackdrop(cfg.backdrop)
+	self.Backdrop:SetBackdropColor(unpack(cfg.backdrop.bgColor))
+	self.Backdrop:SetBackdropBorderColor(unpack(cfg.backdrop.borderColor))
+end
+
 local function SetStatusBarColor(self,r,g,b)
   if not cfg.barColor then return end
   if r == cfg.barColor.r and g == cfg.barColor.g and b == cfg.barColor.b then return end
@@ -215,6 +281,81 @@ local function SetDefaultAnchor(self,parent)
   end
 end

+local function ResetBorderColor(self)
+	if self ~= GameTooltip then
+		return
+	end
+
+	if self.Backdrop then
+		self.Backdrop:SetBackdropBorderColor(unpack(cfg.backdrop.borderColor))
+	end
+end
+
+local function SetUnitBorderColor(self)
+	local unit = self
+	local r, g, b
+	local GameTooltip = GameTooltip
+
+	local reaction = unit and UnitReaction(unit, "player")
+	local player = unit and UnitIsPlayer(unit)
+	local friend = unit and UnitIsFriend("player", unit)
+
+	if player and friend then
+		local class = select(2, UnitClass(unit))
+		local color = RAID_CLASS_COLORS[class]
+
+		r, g, b = color.r, color.g, color.b
+
+		GameTooltip.Backdrop:SetBackdropBorderColor(r, g, b)
+	elseif reaction then
+		local color = FACTION_BAR_COLORS[reaction]
+
+		r, g, b = color.r, color.g, color.b
+
+		GameTooltip.Backdrop:SetBackdropBorderColor(r, g, b)
+	end
+end
+
+local function SetCompareItemBorderColor(anchorFrame)
+	for i = 1, 2 do
+		local shoptip = _G["ShoppingTooltip"..i]
+
+		if shoptip:IsShown() then
+			local frameLevel = GameTooltip:GetFrameLevel()
+			local item = shoptip:GetItem()
+
+			if frameLevel == shoptip:GetFrameLevel() then
+				shoptip:SetFrameLevel(i + 1)
+			end
+
+			if item then
+				local quality = select(3, GetItemInfo(item))
+
+				if quality then
+					local r, g, b = GetItemQualityColor(quality)
+
+					shoptip.Backdrop:SetBackdropBorderColor(r, g, b, cfg.backdrop.itemBorderColorAlpha)
+				else
+					shoptip.Backdrop:SetBackdropBorderColor(unpack(cfg.backdrop.borderColor))
+				end
+			end
+		end
+	end
+end
+
+local function SkinTooltip(self)
+	if self:IsForbidden() then
+		return
+	end
+
+	if (not self.isSkinned) then
+		StripTextures(self)
+		CreateBackdrop(self)
+
+		self.isSkinned = true
+	end
+end
+
 -----------------------------
 -- Init
 -----------------------------
@@ -247,8 +388,8 @@ Tooltip_Small:SetShadowColor(0,0,0,0.75)

 --gametooltip statusbar
 GameTooltipStatusBar:ClearAllPoints()
-GameTooltipStatusBar:SetPoint("LEFT",5,0)
-GameTooltipStatusBar:SetPoint("RIGHT",-5,0)
+GameTooltipStatusBar:SetPoint("LEFT",3,0)
+GameTooltipStatusBar:SetPoint("RIGHT",-3,0)
 GameTooltipStatusBar:SetPoint("TOP",0,-2.5)
 GameTooltipStatusBar:SetHeight(4)
 --gametooltip statusbar bg
@@ -262,25 +403,35 @@ hooksecurefunc(GameTooltipStatusBar, "SetStatusBarColor", SetStatusBarColor)
 --GameTooltip_SetDefaultAnchor()
 if cfg.pos then hooksecurefunc("GameTooltip_SetDefaultAnchor", SetDefaultAnchor) end
 --GameTooltip_SetBackdropStyle
-hooksecurefunc("GameTooltip_SetBackdropStyle", SetBackdropStyle)
+-- hooksecurefunc("GameTooltip_SetBackdropStyle", SetBackdropStyle)
 --SharedTooltip_SetBackdropStyle
-hooksecurefunc("SharedTooltip_SetBackdropStyle", SetBackdropStyle)
+-- hooksecurefunc("SharedTooltip_SetBackdropStyle", SetBackdropStyle)
+
+-- hooksecurefunc("GameTooltip_UnitColor", SetUnitBorderColor)
+hooksecurefunc("GameTooltip_ShowCompareItem", SetCompareItemBorderColor)
+hooksecurefunc("GameTooltip_ClearMoney", ResetBorderColor)

 --OnTooltipSetUnit
 GameTooltip:HookScript("OnTooltipSetUnit", OnTooltipSetUnit)
 --OnTooltipSetItem
 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)

---loop over tooltips
+-- loop over tooltips
 local tooltips = { GameTooltip,ShoppingTooltip1,ShoppingTooltip2,ItemRefTooltip,ItemRefShoppingTooltip1,ItemRefShoppingTooltip2,WorldMapTooltip,
 WorldMapCompareTooltip1,WorldMapCompareTooltip2,SmallTextTooltip,EmbeddedItemTooltip }
 for i, tooltip in next, tooltips do
   tooltip:SetScale(cfg.scale)
-  if tooltip:HasScript("OnTooltipCleared") then
-    tooltip:HookScript("OnTooltipCleared", SetBackdropStyle)
-  end
+  -- if tooltip:HasScript("OnTooltipCleared") then
+  --   tooltip:HookScript("OnTooltipCleared", SetBackdropStyle)
+  -- end
 end

+SkinTooltip(GameTooltip)
+SkinTooltip(ItemRefTooltip)
+SkinTooltip(EmbeddedItemTooltip)
+SkinTooltip(ShoppingTooltip1)
+SkinTooltip(ShoppingTooltip2)
+
 --loop over menues
 local menues = {
   DropDownList1MenuBackdrop,