changeset 54:c8c17286af95

Added power to tooltips (can show item popups) Added interactive and non-interactive modes (ie items are not selectable)
author John@Yosemite-PC
date Sun, 25 Mar 2012 13:08:38 -0400
parents 708d8a423b4c
children 59829ae918eb
files SelectorList.lua
diffstat 1 files changed, 70 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/SelectorList.lua	Sat Mar 24 14:22:01 2012 -0400
+++ b/SelectorList.lua	Sun Mar 25 13:08:38 2012 -0400
@@ -1,9 +1,8 @@
--- no bsk namespace here - we're hooking into AceGUI
-
 local Type, Version = "SelectorList", 34
 local AceGUI = LibStub and LibStub("AceGUI-3.0",true)
 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
 
+local con = LibStub("AceConsole-3.0",true)
 local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type
 local math_min, math_max, floor = math.min, math.max, floor
 local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat
@@ -55,7 +54,44 @@
 	AceGUI:ClearFocus()
 end
 
+local function Button_OnClick(frame)
+	local self = frame.obj
+	local status = self.status or self.localstatus
+	--self:Fire("OnClick", frame.uniquevalue, frame.selected)
+	if status.selected == frame.value then
+	    status.selected = nil
+	else
+	    status.selected = frame.value
+	end
+	self:Refresh()
+	AceGUI:ClearFocus()
+end
 
+local function Button_OnEnter(frame)
+	local self = frame.obj
+	--self:Fire("OnButtonEnter", frame.uniquevalue, frame)
+
+	if self.localstatus.enabletooltips then
+		GameTooltip:SetOwner(frame, "ANCHOR_NONE")
+		GameTooltip:SetPoint("LEFT",frame,"RIGHT")
+		if frame.link then
+		    GameTooltip:SetHyperlink(frame.link)
+		else
+		    GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, 1)
+		end
+
+		GameTooltip:Show()
+	end
+end
+
+local function Button_OnLeave(frame)
+	local self = frame.obj
+	--self:Fire("OnButtonLeave", frame.uniquevalue, frame)
+
+	if self.localstatus.enabletooltips then
+		GameTooltip:Hide()
+	end
+end
 
 local function Layout(self)
     self:SetHeight(self.numlines * 18 + 20)
@@ -88,19 +124,27 @@
 	local iconCoords = line.iconCoords
 	local level = line.level or 1
 	local value = line.value
+	local link = line.link
 	local uniquevalue = line.uniquevalue
 	local disabled = line.disabled
+	local status = self.localstatus
 	
 	button.line = line
 	button.value = value
+	button.link = link
 	button.uniquevalue = uniquevalue
-	if selected then
+	if selected and status.enableInteractive then
 		button:LockHighlight()
 		button.selected = true
 	else
 		button:UnlockHighlight()
 		button.selected = false
 	end
+	if status.enableInteractive then
+	    button:Enable()
+	else
+	    button:Disable()
+	end
 	local normalTexture = button:GetNormalTexture()
 	local line = button.line
 	button.level = level
@@ -116,7 +160,9 @@
 	
 	if disabled then
 		button:EnableMouse(false)
-		button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE)
+		local newText = text
+		newText = newText:gsub("\124c[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F](.*)"..FONT_COLOR_CODE_CLOSE,"%1")
+		button.text:SetText("|cff808080"..newText..FONT_COLOR_CODE_CLOSE)
 	else
 		button.text:SetText(text)
 		button:EnableMouse(true)
@@ -143,16 +189,10 @@
 	["OnAcquire"] = function(self)
 		self:SetWidth(DEFAULT_SL_WIDTH)
 		self:SetNumLines()
-		--self:EnableButtonTooltips(true)
+		self:EnableButtonTooltips(false)
+		self:SetInteractive(true)
 	end,
-	--["SetWidth"] = function(self, width)
-	--    self.slframe:SetWidth(width)
-		
-	--    local status = self.status or self.localstatus
-	--    status.width = width
-	--    status.treesizable = resizable
-		
-	--end,
+
 	["SetNumLines"] = function(self,value)
 	    if not value or value < 4 then
 	        value = 4
@@ -160,15 +200,27 @@
 	    self.numlines = value
 	    Layout(self)
 	end,
+
+	["EnableButtonTooltips"] = function(self, enable)
+		self.localstatus.enabletooltips = enable
+	end,
+
 	["SetList"] = function(self, list)
 	    self.lines = {}
         for i,v in ipairs(list) do
             self.lines[i] = v
         end
+		local status = self.status or self.localstatus
+		status.selected = nil
+		status.scrollvalue = 0
         self:Refresh()
 	end,
 
-	["ShowScroll"] = function(self, show)
+	["SetInteractive"] = function(self, value)
+	    self.localstatus.enableInteractive = value
+	end,
+
+	["ShowScroll"] = function(self, show) -- todo: not a user function. hide.
 		self.showscroll = show
 		if show then
 			self.scrollbar:Show()
@@ -236,7 +288,7 @@
                     b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0)
                 end
             end
-            UpdateButton(b, l)
+            UpdateButton(b, l, status.selected == l.value)
             b:Show()
             bnum = bnum + 1
         end
@@ -292,12 +344,12 @@
 	local widget = {
 		frame        = frame,
 		lines        = {},
-		--levels       = {},
 		buttons      = {},
 		localstatus  = { 
 			--groups = {}, 
-		    scrollvalue = 0 },
-		filter       = false,
+		    enabletooltips= false,
+		    scrollvalue = 0,
+		},
 		slframe      = slframe,
 		scrollbar    = scrollbar,
 		type         = Type