Quantcast

Update UnitTooltip, Appearance, and Portrait modules for LibQTip migration.

Scott Sibley [07-04-11 - 00:25]
Update UnitTooltip, Appearance, and Portrait modules for LibQTip migration.
Filename
Modules/Appearance/Appearance.lua
Modules/Portrait/Portrait.lua
Modules/UnitTooltip/UnitTooltip.lua
diff --git a/Modules/Appearance/Appearance.lua b/Modules/Appearance/Appearance.lua
index 418506a..aa6d046 100644
--- a/Modules/Appearance/Appearance.lua
+++ b/Modules/Appearance/Appearance.lua
@@ -3,7 +3,6 @@ mod.name = "Appearance"
 mod.noToggle = true
 local _G = _G
 local StarTip = _G.StarTip
-local GameTooltip = _G.GameTooltip
 local ShoppingTooltip1 = _G.ShoppingTooltip1
 local ShoppingTooltip2 = _G.ShoppingTooltip2
 local self = mod
@@ -407,7 +406,7 @@ function mod:OnDisable()
 	self:SetBackdrop(true)
 	self:SetBackdropColor(true)
 	StarTip:SetOptionsDisabled(options, true)
-	GameTooltip:SetClampRectInsets(0, 0, 0, 0)
+	StarTip.tooltipMain:SetClampRectInsets(0, 0, 0, 0)
 end

 function mod:GetOptions()
@@ -415,8 +414,8 @@ function mod:GetOptions()
 end

 function mod:SetUnit()
-	self.origBackdrop = self.origBackdrop or GameTooltip:GetBackdrop()
-	self.origBackdropColor = self.origBackdropColor or {GameTooltip:GetBackdropColor()}
+	self.origBackdrop = self.origBackdrop or _G["StarTipQTipMain"]:GetBackdrop()
+	self.origBackdropColor = self.origBackdropColor or {_G["StarTipQTipMain"]:GetBackdropColor()}
 	self:SetBackdropColor()
 end

@@ -430,12 +429,12 @@ end

 function mod:SetScale(reset)
 	if reset then
-		GameTooltip:SetScale(1)
+		_G["StarTipQTipMain"]:SetScale(1)
 		ShoppingTooltip1:SetScale(1)
 		ShoppingTooltip2:SetScale(1)

 	else
-		GameTooltip:SetScale(self.db.profile.scale)
+		_G["StarTipQTipMain"]:SetScale(self.db.profile.scale)
 		ShoppingTooltip1:SetScale(self.db.profile.scale)
 		ShoppingTooltip2:SetScale(self.db.profile.scale)

@@ -481,11 +480,11 @@ end
 local tmp, tmp2 = {}, {}
 function mod:SetBackdrop()
 	if reset then
-		GameTooltip:SetBackdrop(self.origBackdrop)
+		_G["StarTipQTipMain"]:SetBackdrop(self.origBackdrop)
 		ShoppingTooltip1:SetBackdrop(self.origBackdrop)
 		ShoppingTooltip2:SetBackdrop(self.origBackdrop)
 	else
-		local bd = GameTooltip:GetBackdrop()
+		local bd = _G["StarTipQTipMain"]:GetBackdrop()
 		local changed = false
 		local bgFile = LSM:Fetch('background', self.db.profile.background)
 		local edgeFile = LSM:Fetch('border', self.db.profile.edgeFile)
@@ -504,7 +503,7 @@ function mod:SetBackdrop()
 			tmp2.right = self.db.profile.paddingRight
 			tmp2.top = self.db.profile.paddingTop
 			tmp2.bottom = self.db.profile.paddingBottom
-			GameTooltip:SetBackdrop(tmp)
+			_G["StarTipQTipMain"]:SetBackdrop(tmp)
 			ShoppingTooltip1:SetBackdrop(tmp)
 			ShoppingTooltip2:SetBackdrop(tmp)
 		end
@@ -514,11 +513,11 @@ end
 function mod:SetBackdropColor(reset)
 	if reset then
 		if self.origBackdropColor then
-			GameTooltip:SetBackdropColor(unpack(self.origBackdropColor))
+			_G["StarTipQTipMain"]:SetBackdropColor(unpack(self.origBackdropColor))
 			ShoppingTooltip1:SetBackdropColor(unpack(self.origBackdropColor))
 			ShoppingTooltip2:SetBackdropColor(unpack(self.origBackdropColor))
 		else
-			GameTooltip:SetBackdropColor(0,0,0,1)
+			_G["StarTipQTipMain"]:SetBackdropColor(0,0,0,1)
 			ShoppingTooltip1:SetBackdropColor(0,0,0,1)
 			ShoppingTooltip2:SetBackdropColor(0,0,0,1)
 		end
@@ -567,7 +566,7 @@ function mod:SetBackdropColor(reset)
 		else
 			kind = 'other'
 		end
-		GameTooltip:SetBackdropColor(unpack(self.db.profile.bgColor[kind]))
+		_G["StarTipQTipMain"]:SetBackdropColor(unpack(self.db.profile.bgColor[kind]))
 		if kind == 'other' then
 			ShoppingTooltip1:SetBackdropColor(unpack(self.db.profile.bgColor[kind]))
 			ShoppingTooltip2:SetBackdropColor(unpack(self.db.profile.bgColor[kind]))
diff --git a/Modules/Portrait/Portrait.lua b/Modules/Portrait/Portrait.lua
index 37e14ad..f58bcbb 100644
--- a/Modules/Portrait/Portrait.lua
+++ b/Modules/Portrait/Portrait.lua
@@ -12,7 +12,10 @@ local L = StarTip.L
 local defaults = {
 	profile = {
 		size = 36,
-		line = 1,
+		tooltipMain = true,
+		tooltipUnit = false,
+		tooltipItem = true,
+		tooltipSpell = true,
 		animated = false
 	}
 }
@@ -44,29 +47,78 @@ local options = {
 			if val then mod.model:Show() else mod.model:Hide() end
 		end,
 		order = 7
+	},
+	tooltipMain = {
+		name = L["Tooltip Main"],
+		desc = L["Whether to show a portrait on the main QTip tooltip."],
+		type = "toggle",
+		get = function() return mod.db.profile.tooltipMain end,
+		set = function(info, val)
+			mod.db.profile.tooltipMain = val
+		end,
+		order = 8
+	},
+	tooltipUnit = {
+		name = L["Default Unit Tooltip"],
+		desc = L["Whether to show a portrait on the default unit tooltip."],
+		type = "toggle",
+		get = function() return mod.db.profile.tooltipUnit end,
+		set = function(info, val)
+			mod.db.profile.tooltipUnit = val
+		end,
+		order = 9
+	},
+	tooltipItem = {
+		name = L["Item Tooltip"],
+		desc = L["Whether to show a portrait on the item tooltip."],
+		type = "toggle",
+		get = function() return mod.db.profile.tooltipItem end,
+		set = function(info, val) mod.db.profile.tooltipItem = val end,
+		order = 10,
+	},
+	tooltipSpell = {
+		name = L["Spell Tooltip"],
+		desc = L["Whether to show a portrait on the spell tooltip."],
+		type = "toggle",
+		get = function() return mod.db.profile.tooltipSpell end,
+		set = function(info, val) mod.db.profile.tooltipSpell = val end,
+		order = 11
 	}
 }

 function mod:OnInitialize()
 	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
 	StarTip:SetOptionsDisabled(options, true)
-	self.text = StarTip.leftLines[self.db.profile.line]
-	self.texture = GameTooltip:CreateTexture()
-	self.model = CreateFrame("PlayerModel", nil, GameTooltip)
 end

 function mod:OnEnable()
 	StarTip:SetOptionsDisabled(options, false)
-
+
+	self.text = StarTip.leftLines[self.db.profile.line]
+	self.texture = GameTooltip:CreateTexture()
+	self.texture2 = StarTip.tooltipMain:CreateTexture()
+	self.model = CreateFrame("PlayerModel", nil, GameTooltip)
+	self.model2 = CreateFrame("PlayerModel", nil, StarTip.tooltipMain)
+
 	self.model:ClearAllPoints()
 	self.model:SetPoint("LEFT", self.text, "LEFT")
 	self.model:SetWidth(self.db.profile.size)
 	self.model:SetHeight(self.db.profile.size)
+
+	self.model2:ClearAllPoints()
+	self.model2:SetPoint("TOPLEFT", StarTip.tooltipMain, "TOPLEFT", 12, -12)
+	self.model2:SetWidth(self.db.profile.size)
+	self.model2:SetHeight(self.db.profile.size)

 	self.texture:ClearAllPoints()
 	self.texture:SetPoint("LEFT", self.text, "LEFT")
 	self.texture:SetWidth(self.db.profile.size)
 	self.texture:SetHeight(self.db.profile.size)
+
+	self.texture2:ClearAllPoints()
+	self.texture2:SetPoint("TOPLEFT", StarTip.tooltipMain, "TOPLEFT", 12, -12)
+	self.texture2:SetWidth(self.db.profile.size)
+	self.texture2:SetHeight(self.db.profile.size)
 end

 function mod:OnDisable()
@@ -82,31 +134,50 @@ function mod:GetOptions()
 end

 function mod:SetUnit()
-	if not self.text or not self.texture then return end

 	SetPortraitTexture(self.texture, StarTip.unit or "mouseover")
-
+	SetPortraitTexture(self.texture2, StarTip.unit or "mouseover")
+
 	if not self.texture:GetTexture() then
 		self.model:Hide()
+		self.model2:Hide()
 		self.texture:Hide()
+		self.texture2:Hide()
 		return
 	end

 	if self.db.profile.animated then
-		self.model:SetUnit(StarTip.unit)
+		self.model:SetUnit(StarTip.unit or "mouseover")
+		self.model2:SetUnit(StarTip.unit or "mouseover")
 		self.texture:Hide()
+		self.texture2:Hide()
 		self.model:Show()
 		self.model:SetCamera(0)
+		self.model2:Show()
+		self.model2:SetCamera(0)
 	else
 		self.texture:Show()
+		self.texture2:Show()
 		self.model:Hide()
+		self.model2:Hide()
+	end
+	if not self.db.profile.tooltipMain then
+		self.texture2:Hide()
+		self.model2:Hide()
+	end
+	if not self.db.profile.tooltipUnit then
+		self.texture:Hide()
+		self.model:Hide()
+	else
+		if self.text then
+			self.text:SetFormattedText('|T%s:%d|t %s', "", self.db.profile.size, self.text:GetText() or "") -- we only need a blank space for the texture
+		end
 	end
-	self.text:SetFormattedText('|T%s:%d|t %s', "", self.db.profile.size, self.text:GetText() or "") -- we only need a blank space for the texture
 end

 local lasttxt = ""
 function mod:SetItem()
-	if not self.text then return end
+	if not self.text or not self.db.profile.tooltipItem then return end

 	local txt = self.text:GetText()
 	if txt == lasttxt then return end
@@ -121,7 +192,7 @@ function mod:SetItem()
 end

 function mod:SetSpell()
-	if not self.text then return end
+	if not self.text or not self.db.profile.tooltipSpell then return end

 	local txt = self.text:GetText()
 	if txt == lasttxt then return end
@@ -137,4 +208,4 @@ end
 function mod:OnHide()
 	self.model:Hide()
 	self.texture:Hide()
-end
\ No newline at end of file
+end
diff --git a/Modules/UnitTooltip/UnitTooltip.lua b/Modules/UnitTooltip/UnitTooltip.lua
index 9678e15..2de1d60 100644
--- a/Modules/UnitTooltip/UnitTooltip.lua
+++ b/Modules/UnitTooltip/UnitTooltip.lua
@@ -95,7 +95,15 @@ local offline = Offline(unit)
 if offline then
     afk = " " .. Angle(offline)
 end
-return Colorize((Name(unit, true) or Name(unit)) .. afk , r, g, b)
+local port = StarTip:GetModule("Portrait")
+local texture  = ""
+if port and port.texture then
+	texture = port.texture:GetTexture()
+end
+if texture ~= "" then
+	texture = Texture("", port.db.profile.size) .. " "
+end
+return texture .. Colorize((Name(unit, true) or Name(unit)) .. afk , r, g, b)
 ]],
         right = nil,
         bold = true,
@@ -905,6 +913,14 @@ do
             end
 ]]
         end
+	for cell in StarTip.tooltipMain:GetDefaultProvider():IterateCells() do
+		local y, x = cell:GetPosition()
+		if y == 1 and x == 1 then
+			cell.fontString.isHeader = true
+		else
+			cell.fontString.isHeader = false
+		end
+	end
         table.wipe(widgetsToDraw)
         if UnitExists(StarTip.unit) then
             --GameTooltip:Show()