Quantcast

Hook GameTooltip:FadeOut

Scott Sibley [10-03-10 - 09:52]
Hook GameTooltip:FadeOut
Introduce Icons module
Filename
.pkgmeta
Modules/Icons/Icons.lua
Modules/Icons/Icons_Portrait.toc
Modules/Portrait/Portrait.lua
StarTip.lua
modules.xml
diff --git a/.pkgmeta b/.pkgmeta
index bc9957f..7ee0693 100644
--- a/.pkgmeta
+++ b/.pkgmeta
@@ -62,4 +62,5 @@ move-folders:
     StarTip/Modules/Targeting: StarTip_Targeting
     StarTip/Modules/Texts: StarTip_Texts
     StarTip/Modules/UnitTooltip: StarTip_UnitTooltip
-    StarTip/Modules/Portrait: StarTip_Portrait
\ No newline at end of file
+    StarTip/Modules/Portrait: StarTip_Portrait
+    StarTip/Modules/Icons: StarTip_Icons
\ No newline at end of file
diff --git a/Modules/Icons/Icons.lua b/Modules/Icons/Icons.lua
new file mode 100644
index 0000000..4504f83
--- /dev/null
+++ b/Modules/Icons/Icons.lua
@@ -0,0 +1,325 @@
+local mod = StarTip:NewModule("Icons")
+mod.name = "Icons"
+mod.toggled = true
+local LibBuffer = LibStub("LibScriptableDisplayBuffer-1.0")
+local LibCore = LibStub("LibScriptableDisplayCore-1.0")
+local LibTimer = LibStub("LibScriptableDisplayTimer-1.0")
+local PluginUtils = LibStub("LibScriptableDisplayPluginUtils-1.0")
+local WidgetIcon = LibStub("LibScriptableDisplayWidgetIcon-1.0")
+local _G = _G
+local GameTooltip = _G.GameTooltip
+local StarTip = _G.StarTip
+local UIParent = _G.UIParent
+local textures = {[1] = "Interface\\Addons\\StarTip\\Media\\white.blp", [0] = "Interface\\Addons\\StarTip\\Media\\blank.tga"}
+local environment = {}
+local update
+
+local options = {
+}
+
+local foo = 200
+local defaults = {
+	profile = {
+		cols = 1,
+		rows = 1,
+		yres = 8,
+		xres = 7,
+		size = 12,
+		update = 0,
+		icons = {
+			[1] = {
+				["bitmap"] = {
+					["row1"] = ".....|.....|.....",
+					["row2"] = ".....|.....|.***.",
+					["row3"] = ".....|.***.|*...*",
+					["row4"] = "..*..|.*.*.|*...*",
+					["row5"] = ".....|.***.|*...*",
+					["row6"] = ".....|.....|.***.",
+					["row7"] = ".....|.....|.....",
+					["row8"] = ".....|.....|....."
+				},
+				["speed"] = foo,
+			},
+			[2] = {
+				["bitmap"] = {
+					["row1"] = ".....|.....|.....|.....|.....|.....|.....|.....",
+					["row2"] = ".....|....*|...*.|..*..|.*...|*....|.....|.....",
+					["row3"] = ".....|....*|...*.|..*..|.*...|*....|.....|.....",
+					["row4"] = ".....|....*|...**|..**.|.**..|**...|*....|.....",
+					["row5"] = ".....|....*|...**|..**.|.**..|**...|*....|.....",
+					["row6"] = ".....|....*|...*.|..*.*|.*.*.|*.*..|.*...|*....",
+					["row7"] = "*****|*****|****.|***..|**..*|*..**|..***|.****",
+					["row8"] = ".....|.....|.....|.....|.....|.....|.....|....."
+				},
+				["speed"] = foo,
+			},
+			[3] = {
+				["bitmap"] = {
+					["row1"] = ".....|.....|.....|.....|.....|.....",
+					["row2"] = ".*.*.|.....|.*.*.|.....|.....|.....",
+					["row3"] = "*****|.*.*.|*****|.*.*.|.*.*.|.*.*.",
+					["row4"] = "*****|.***.|*****|.***.|.***.|.***.",
+					["row5"] = ".***.|.***.|.***.|.***.|.***.|.***.",
+					["row6"] = ".***.|..*..|.***.|..*..|..*..|..*..",
+					["row7"] = "..*..|.....|..*..|.....|.....|.....",
+					["row8"] = ".....|.....|.....|.....|.....|....."
+				},
+				["speed"] = foo,
+			},
+			[4] = {
+				enabled = false,
+				["bitmap"] = {
+					["row1"] = ".....|.....",
+					["row2"] = ".*.*.|.*.*.",
+					["row3"] = "*****|*.*.*",
+					["row4"] = "*****|*...*",
+					["row5"] = ".***.|.*.*.",
+					["row6"] = ".***.|.*.*.",
+					["row7"] = "..*..|..*..",
+					["row8"] = ".....|....."
+				},
+				["speed"] = foo,
+			},
+			[5] = {
+				["bitmap"] = {
+					["row1"] = ".....|.....|.....|.....|..*..|.....|.....|.....",
+					["row2"] = ".....|.....|.....|..*..|.*.*.|..*..|.....|.....",
+					["row3"] = ".....|.....|..*..|.*.*.|*...*|.*.*.|..*..|.....",
+					["row4"] = ".....|..*..|.*.*.|*...*|.....|*...*|.*.*.|..*..",
+					["row5"] = ".....|.....|..*..|.*.*.|*...*|.*.*.|..*..|.....",
+					["row6"] = ".....|.....|.....|..*..|.*.*.|..*..|.....|.....",
+					["row7"] = ".....|.....|.....|.....|..*..|.....|.....|.....",
+					["row8"] = ".....|.....|.....|.....|.....|.....|.....|....."
+				},
+				["speed"] = foo,
+			},
+			[6] = {
+				["bitmap"] = {
+					["row1"] = "...*.|.....|.....|.*...|....*|..*..|.....|*....",
+					["row2"] = "*....|...*.|.....|.....|.*...|....*|..*..|.....",
+					["row3"] = ".....|*....|...*.|.....|.....|.*...|....*|..*..",
+					["row4"] = "..*..|.....|*....|...*.|.....|.....|.*...|....*",
+					["row5"] = "....*|..*..|.....|*....|...*.|.....|.....|.*...",
+					["row6"] = ".*...|....*|..*..|.....|*....|...*.|.....|.....",
+					["row7"] = ".....|.*...|....*|..*..|.....|*....|...*.|.....",
+					["row8"] = ".....|.....|.*...|....*|..*..|.....|*....|...*."
+				},
+				["speed"] = foo,
+			},
+			[7] = {
+				["bitmap"] = {
+					["row1"] = ".....|.....|.....|.....|.....|.....",
+					["row2"] = ".....|.....|.....|.....|.....|.....",
+					["row3"] = ".....|.....|.....|.....|.....|.....",
+					["row4"] = "**...|.**..|..**.|...**|....*|.....",
+					["row5"] = "*****|*****|*****|*****|*****|*****",
+					["row6"] = "...**|..**.|.**..|**...|*....|.....",
+					["row7"] = ".....|.....|.....|.....|.....|.....",
+					["row8"] = ".....|.....|.....|.....|.....|....."
+				},
+				["speed"] = foo,
+			},
+			[8] = {
+				["bitmap"] = {
+					["row1"] = ".....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|",
+					["row2"] = ".***.|.*+*.|.*++.|.*++.|.*++.|.*++.|.*++.|.*++.|.*++.|.*++.|.*++.|.*++.|.+++.|.+*+.|.+**.|.+**.|.+**.|.+**.|.+**.|.+**.|.+**.|.+**.|.+**.|.+**.|",
+					["row3"] = "*****|**+**|**++*|**+++|**++.|**++.|**+++|**+++|**+++|**+++|**+++|+++++|+++++|++*++|++**+|++***|++**.|++**.|++***|++***|++***|++***|++***|*****|",
+					["row4"] = "*****|**+**|**+**|**+**|**+++|**+++|**+++|**+++|**+++|**+++|+++++|+++++|+++++|++*++|++*++|++*++|++***|++***|++***|++***|++***|++***|*****|*****|",
+					["row5"] = "*****|*****|*****|*****|*****|***++|***++|**+++|*++++|+++++|+++++|+++++|+++++|+++++|+++++|+++++|+++++|+++**|+++**|++***|+****|*****|*****|*****|",
+					["row6"] = ".***.|.***.|.***.|.***.|.***.|.***.|.**+.|.*++.|.+++.|.+++.|.+++.|.+++.|.+++.|.+++.|.+++.|.+++.|.+++.|.+++.|.++*.|.+**.|.***.|.***.|.***.|.***.|",
+					["row7"] = ".....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|",
+					["row8"] = ".....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|.....|"
+				},
+				["speed"] = foo,
+			},
+			[9] = {
+				enabled = true,
+				["bitmap"] = {
+					["row1"] = "..**.|.**..|**...|*....|.....|.....|.....|.....|....*|...**",
+					["row2"] = ".*..*|*..*.|..*..|.*...|*....|.....|.....|....*|...*.|..*..",
+					["row3"] = "*....|....*|...*.|..*..|.*...|*....|....*|...*.|..*..|.*...",
+					["row4"] = "*....|....*|...*.|..*..|.*...|*....|....*|...*.|..*..|.*...",
+					["row5"] = "*....|....*|...*.|..*..|.*...|*....|....*|...*.|..*..|.*...",
+					["row6"] = ".....|.....|....*|...*.|..*..|.*..*|*..*.|..*..|.*...|*....",
+					["row7"] = ".....|.....|.....|....*|...**|..**.|.**..|**...|*....|.....",
+					["row8"] = ".....|.....|.....|.....|.....|.....|.....|.....|.....|....."
+				},
+				["speed"] = foo,
+			},
+		}
+	}
+}
+
+function mod:OnInitialize()
+	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
+	StarTip:SetOptionsDisabled(options, true)
+
+	self.core = LibCore:New(mod, environment, "StarTip.Icons", {["StarTip.Icons"] = {}}, nil, StarTip.db.profile.errorLevel)
+	self.core.lcd = {LCOLS=1, LROWS=1, XRES=7, YRES=8, specialChars = {}}
+
+	self.buffer = LibBuffer:New("Icons", self.core.lcd.LCOLS * self.core.lcd.LROWS, 0, StarTip.db.profile.errorLevel)
+
+	if self.db.profile.update > 0 then
+		self.timer = LibTimer:New("Icons", 100, true, update)
+	end
+end
+
+local function copy(tbl)
+	local newTbl = {}
+	for k, v in pairs(tbl) do
+		if type(v) == "table" then
+			v = copy(v)
+		end
+		newTbl[k] = v
+	end
+	return newTbl
+end
+
+local draw
+local function createIcons()
+	if type(mod.icons) ~= "table" then mod.icons = {} end
+
+	for k, icon in pairs(mod.db.profile.icons) do
+		if icon.enabled then
+			local icon = WidgetIcon:New(mod.core, "icon", copy(icon), icon.row or 0, icon.col or 0, icon.layer or 0, StarTip.db.profile.errorLevel, draw)
+			icon:SetupChars()
+			tinsert(mod.icons, icon)
+		end
+	end
+end
+
+function mod:OnEnable()
+	StarTip:SetOptionsDisabled(options, false)
+	createIcons()
+	-- no need to start the timer
+end
+
+function mod:OnDisable()
+	StarTip:SetOptionsDisabled(options, true)
+	if self.timer then
+		self.timer:Stop()
+	end
+end
+
+function mod:GetOptionsbleh()
+	for i, icon in ipairs(self.db.profile.icons) do
+		options.icons.args["Icon"..i] = {
+			enabled = {
+				name = "Enabled",
+				type = "toggle",
+				get = function() return icon.enabled end,
+				set = function(info, val) icon.enabled = val end,
+				order = 1
+			},
+			speed = {
+				name = "Speed",
+				type = "input",
+				pattern = "%d",
+				get = function() return icon.speed end,
+				set = function(info, val) icon.speed = val end,
+				order = 2
+			},
+			bitmap = {
+				name = "Bitmap",
+				type = "input",
+				multiline = true,
+				width = "full",
+				get = function() return icon.bitmap end,
+				set = function(info, val) icon.bitmap = val end,
+				order = 3
+			}
+		}
+	end
+	return options
+end
+
+function mod:ClearIcons()
+	for k, widget in pairs(mod.icons) do
+		widget:Del()
+	end
+	wipe(mod.icons)
+end
+
+function draw(widget)
+	local lcd = widget.visitor.lcd
+
+	local row = widget.row
+	local col = widget.col
+	local layer = widget.layer
+	local n = row * lcd.LCOLS + col
+
+	local icon = widget.icon
+
+
+	local chr = lcd.specialChars[widget.start + widget.index]
+
+	for y = 0 , lcd.YRES - 1 do
+		local mask = bit.lshift(1, lcd.XRES)
+		for x = 0, lcd.XRES - 1 do
+			mask = bit.rshift(mask, 1)
+			if bit.band(chr[y + 1], mask) == 0 then
+				mod.buffer.buffer[(row * lcd.YRES + y) * lcd.LCOLS * lcd.XRES + col * lcd.XRES + x] = 1
+			else
+				mod.buffer.buffer[(row * lcd.YRES + y) * lcd.LCOLS * lcd.XRES + col * lcd.XRES + x] = 0
+			end
+		end
+	end
+
+	update()
+end
+
+local first = true
+function update()
+
+			local str = ""
+			local size = mod.core.lcd.LCOLS * mod.core.lcd.XRES * (strlen(format("|T%s:%d|t", textures[1], mod.db.profile.size or 10)))
+			--[[for row = 0, mod.core.lcd.LROWS - 1 do
+				for y = 0, mod.core.lcd.YRES - 1 do
+					if StarTip.leftLines[row * mod.core.lcd.YRES + y] then
+						local text = StarTip.leftLines[row * mod.core.lcd.YRES + y]:GetText() or ""
+						if text then
+							text = string.sub(text, size)
+						end
+						StarTip.leftLines[row * mod.core.lcd.YRES + y]:SetText(text)
+					end
+				end
+			end]]
+			for row = 0, mod.core.lcd.LROWS - 1 do
+				for col = 0, mod.core.lcd.LCOLS - 1 do
+					for r = 0, mod.core.lcd.YRES - 1 do
+						for c = 0, mod.core.lcd.XRES - 1 do
+
+							local color = mod.buffer.buffer[(row * mod.core.lcd.YRES + r) * mod.core.lcd.LCOLS * mod.core.lcd.XRES + col * mod.core.lcd.XRES + c]
+							str = str .. format('|T%s:%d|t', textures[color] or "", mod.db.profile.size or 10)
+						end
+						if StarTip.leftLines[r + row + 2] then
+							StarTip.leftLines[r + row + 2]:SetText(str)
+							str = ""
+						end
+					end
+				end
+			end
+			if UnitExists(StarTip.unit) then
+				GameTooltip:Show()
+			end
+			first = false
+end
+
+function mod:SetUnit()
+	first = true
+	for k, icon in pairs(self.icons or {}) do
+		icon:Start()
+	end
+	if self.timer then
+		self.timer:Start()
+	end
+end
+
+function mod:OnHide()
+	for k, icon in pairs(self.icons or {}) do
+		icon:Stop()
+	end
+	if self.timer then
+		self.timer:Stop()
+	end
+end
diff --git a/Modules/Icons/Icons_Portrait.toc b/Modules/Icons/Icons_Portrait.toc
new file mode 100644
index 0000000..48f96be
--- /dev/null
+++ b/Modules/Icons/Icons_Portrait.toc
@@ -0,0 +1,9 @@
+## Interface: 30300
+## X-Compatible-With: 40000
+## Title: StarTip [Icons]
+## Notes: Tooltips from outerspace
+## Author: Starlon
+## Version: 1.0
+## OptionalDeps: StarTip
+
+Icons.lua
\ No newline at end of file
diff --git a/Modules/Portrait/Portrait.lua b/Modules/Portrait/Portrait.lua
index fa484f7..289b3f4 100644
--- a/Modules/Portrait/Portrait.lua
+++ b/Modules/Portrait/Portrait.lua
@@ -7,7 +7,6 @@ local _G = _G
 local GameTooltip = _G.GameTooltip
 local StarTip = _G.StarTip
 local UIParent = _G.UIParent
-local model = CreateFrame("PlayerModel", nil, GameTooltip)

 local defaults = {
 	profile = {
@@ -58,7 +57,7 @@ local options = {
 		get = function() return mod.db.profile.animated end,
 		set = function(info, val)
 			mod.db.profile.animated = val
-			if val then model:Show() else model:Hide() end
+			if val then mod.model:Show() else mod.model:Hide() end
 		end,
 		order = 7
 	}
@@ -69,15 +68,16 @@ function mod:OnInitialize()
 	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)

-	model:ClearAllPoints()
-	model:SetPoint("LEFT", self.text, "LEFT")
-	model:SetWidth(self.db.profile.size)
-	model:SetHeight(self.db.profile.size)
+	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.texture:ClearAllPoints()
 	self.texture:SetPoint("LEFT", self.text, "LEFT")
@@ -89,8 +89,8 @@ function mod:OnDisable()
 	StarTip:SetOptionsDisabled(options, true)
 	self.texture:ClearAllPoints()
 	self.texture:Hide()
-	model:ClearAllPoints()
-	model:Hide()
+	self.model:ClearAllPoints()
+	self.model:Hide()
 end

 function mod:GetOptions()
@@ -103,24 +103,24 @@ function mod:SetUnit()
 	SetPortraitTexture(self.texture, StarTip.unit)

 	if not self.texture:GetTexture() then
-		model:Hide()
+		self.model:Hide()
 		self.texture:Hide()
 		return
 	end

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

 function mod:OnHide()
-	model:Hide()
+	self.model:Hide()
 	self.texture:Hide()
 end
\ No newline at end of file
diff --git a/StarTip.lua b/StarTip.lua
index 41e6894..1dc2eba 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -513,6 +513,7 @@ function StarTip:OnEnable()
 	self:SecureHook(GameTooltip, "Show", self.GameTooltipShow)
 	self:SecureHook(GameTooltip, "AddDoubleLine", self.GameTooltipAddLine)
 	self:SecureHook(GameTooltip, "AddLine", self.GameTooltipAddLine)
+	self:SecureHook(GameTooltip, "FadeOut", self.GameTooltipFade)

 	for k,v in self:IterateModules() do
 		if (self.db.profile.modules[k]  == nil and not v.defaultOff) or self.db.profile.modules[k] then
@@ -540,6 +541,7 @@ function StarTip:OnDisable()
 	self:Unhook(GameTooltip, "OnHide")
 	self:Unhook(GameTooltip, "OnShow")
 	self:Unhook(GameTooltip, "Show")
+	self:Unhook(GameTooltip, "FadeOut")
 	self:UnregisterEvent("MODIFIER_STATE_CHANGED")
 	for k,v in self:IterateModules() do
 		if (self.db.profile.modules[k]  == nil and not v.defaultOff) or self.db.profile.modules[k] then
@@ -794,16 +796,22 @@ function StarTip:GameTooltipShow(...)
 	if not show then GameTooltip:Hide() end
 end

-function StarTip:OnTooltipShow(this, ...)
-	if not self.justShow then
-		for k, v in self:IterateModules() do
-			if v.OnShow and v:IsEnabled() then v:OnShow(this, ...) end
+function StarTip.OnTooltipShow(...)
+	if not StarTip.justShow then
+		for k, v in StarTip:IterateModules() do
+			if v.OnShow and v:IsEnabled() then v:OnShow(...) end
 		end
 	end

-	self.justShow = false
+	StarTip.justShow = false

-	return self.hooks[GameTooltip].OnShow(this, ...)
+	return StarTip.hooks[GameTooltip].OnShow(...)
+end
+
+function StarTip.GameTooltipFade(...)
+	for k, v in StarTip:IterateModules() do
+		if v.OnFadeOut and v:IsEnabled() then v:OnFadeOut(...) end
+	end
 end

 function StarTip:GetLSMIndexByName(category, name)
diff --git a/modules.xml b/modules.xml
index 48e98d2..25e8a93 100644
--- a/modules.xml
+++ b/modules.xml
@@ -13,6 +13,7 @@
 <Script file = "Modules\Histograms\Histograms.lua"/>
 <Script file = "Modules\UnitTooltip\UnitTooltip.lua"/>
 <Script file = "Modules\Portrait\Portrait.lua"/>
+<Script file = "Modules\Icons\Icons.lua"/>
 <Script file = "Modules\Debug\Debug.lua"/>
 <!--@end-debug@-->