Quantcast

Add Portrait module

Scott Sibley [10-02-10 - 10:00]
Add Portrait module
Filename
.pkgmeta
Modules/Bars/Bars.lua
Modules/Portrait/Portrait.lua
Modules/Portrait/StarTip_Portrait.toc
modules.xml
diff --git a/.pkgmeta b/.pkgmeta
index eb7786c..bc9957f 100644
--- a/.pkgmeta
+++ b/.pkgmeta
@@ -49,7 +49,8 @@ externals:
         url: git://github.com/tekkub/libdatabroker-1-1.git
         tag: v1.1.4
     Libs/LibScriptableDisplay-1.0:
-        url: svn://svn.curseforge.net/wow/starlibs-1-0/mainline/trunk
+        url: svn://svn.curseforge.net/wow/libscriptabledisplay-1-0/mainline/trunk
+
 move-folders:
     StarTip/Modules/Appearance: StarTip_Appearance
     StarTip/Modules/Bars: StarTip_Bars
@@ -60,4 +61,5 @@ move-folders:
     StarTip/Modules/RaidIcon: StarTip_RaidIcon
     StarTip/Modules/Targeting: StarTip_Targeting
     StarTip/Modules/Texts: StarTip_Texts
-    StarTip/Modules/UnitTooltip: StarTip_UnitTooltip
\ No newline at end of file
+    StarTip/Modules/UnitTooltip: StarTip_UnitTooltip
+    StarTip/Modules/Portrait: StarTip_Portrait
\ No newline at end of file
diff --git a/Modules/Bars/Bars.lua b/Modules/Bars/Bars.lua
index 054836e..f90c41b 100644
--- a/Modules/Bars/Bars.lua
+++ b/Modules/Bars/Bars.lua
@@ -1,4 +1,4 @@
-local mod = StarTip:NewModule("Bars", "AceTimer-3.0")
+local mod = StarTip:NewModule("Bars")
 mod.name = "Bars"
 mod.toggled = true
 --mod.childGroup = true
@@ -11,7 +11,6 @@ local RAID_CLASS_COLORS = _G.RAID_CLASS_COLORS
 local UnitSelectionColor = _G.UnitSelectionColor
 local UnitClass = _G.UnitClass
 local self = mod
-local timer
 local LSM = LibStub("LibSharedMedia-3.0")
 local WidgetBar = LibStub("LibScriptableDisplayWidgetBar-1.0")
 local LibCore = LibStub("LibScriptableDisplayCore-1.0")
@@ -406,10 +405,6 @@ function mod:SetSpell()
 end

 function mod:OnHide()
-	if timer then
-		self:CancelTimer(timer)
-		timer = nil
-	end
 	for i, bar in pairs(self.bars) do
 		if not bar.config.alwaysShown then
 			bar:Stop()
diff --git a/Modules/Portrait/Portrait.lua b/Modules/Portrait/Portrait.lua
new file mode 100644
index 0000000..f411412
--- /dev/null
+++ b/Modules/Portrait/Portrait.lua
@@ -0,0 +1,118 @@
+local mod = StarTip:NewModule("Portrait")
+mod.name = "Portrait"
+mod.toggled = true
+local luaTexts = {}
+LibStub("LibScriptableDisplayPluginLuaTexts-1.0"):New(luaTexts)
+local _G = _G
+local GameTooltip = _G.GameTooltip
+local StarTip = _G.StarTip
+local UIParent = _G.UIParent
+local model = CreateFrame("PlayerModel", nil, GameTooltip)
+
+local defaults = {
+	profile = {
+		size = 36,
+		line = 1,
+		animated = true
+	}
+}
+
+local options = {
+	size = {
+		name = "Size",
+		desc = "The texture's width and height",
+		type = "input",
+		pattern = "%d",
+		get = function() return tostring(mod.db.profile.size) end,
+		set = function(info, val)
+			val = tonumber(val)
+			mod.db.profile.size = val
+			mod.texture:SetWidth(val)
+			mod.texture:SetHeight(val)
+			model:SetWidth(val)
+			model:SetHeight(val)
+		end,
+		order = 5
+	},
+	line = {
+		name = "Line",
+		desc = "Which line to place the portrait on",
+		type = "input",
+		pattern = "%d",
+		get = function() return tostring(mod.db.profile.line) end,
+		set = function(info, val)
+			val = tonumber(val)
+			mod.db.profile.line = val
+			mod.text = StarTip.leftLines[val]
+			mod.texture:ClearAllPoints()
+			mod.texture:SetPoint("LEFT", mod.text, "LEFT")
+			model:ClearAllPoints()
+			model:SetPoint("LEFT", mod.text, "LEFT")
+		end,
+		order = 6
+	},
+	animated = {
+		name = "3d Model",
+		desc = "Whether to show the portrait as a 3d model (toggled true) or a 2d model (toggled false)",
+		type = "toggle",
+		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
+		end,
+		order = 7
+	}
+}
+
+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()
+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.texture:ClearAllPoints()
+	self.texture:SetPoint("LEFT", self.text, "LEFT")
+	self.texture:SetWidth(self.db.profile.size)
+	self.texture:SetHeight(self.db.profile.size)
+end
+
+function mod:OnDisable()
+	StarTip:SetOptionsDisabled(options, true)
+	self.texture:ClearAllPoints()
+	self.texture:Hide()
+	model:ClearAllPoints()
+	model:Hide()
+end
+
+function mod:GetOptions()
+	return options
+end
+
+function mod:SetUnit()
+	if not self.text or luaTexts.Race(StarTip.unit) == UNKNOWN then return end
+	SetPortraitTexture(self.texture, StarTip.unit)
+	if self.db.profile.animated then
+		model:SetUnit(StarTip.unit)
+		self.texture:Hide()
+		model:Show()
+		model:SetCamera(0)
+	else
+		self.texture:Show()
+		model:Hide()
+	end
+	self.text:SetFormattedText('|T%s:%d|t %s', self.texture:GetTexture(), self.db.profile.size, self.text:GetText())
+end
+
+function mod:OnHide()
+	model:Hide()
+	self.texture:Hide()
+end
\ No newline at end of file
diff --git a/Modules/Portrait/StarTip_Portrait.toc b/Modules/Portrait/StarTip_Portrait.toc
new file mode 100644
index 0000000..68d2a47
--- /dev/null
+++ b/Modules/Portrait/StarTip_Portrait.toc
@@ -0,0 +1,9 @@
+## Interface: 30300
+## X-Compatible-With: 40000
+## Title: StarTip [Portrait]
+## Notes: Tooltips from outerspace
+## Author: Starlon
+## Version: 1.0
+## OptionalDeps: StarTip
+
+Portrait.lua
\ No newline at end of file
diff --git a/modules.xml b/modules.xml
index 007908c..48e98d2 100644
--- a/modules.xml
+++ b/modules.xml
@@ -12,6 +12,7 @@
 <Script file = "Modules\Bars\Bars.lua"/>
 <Script file = "Modules\Histograms\Histograms.lua"/>
 <Script file = "Modules\UnitTooltip\UnitTooltip.lua"/>
+<Script file = "Modules\Portrait\Portrait.lua"/>
 <Script file = "Modules\Debug\Debug.lua"/>
 <!--@end-debug@-->