comparison SelectorList.lua @ 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 9b1588bd4398
comparison
equal deleted inserted replaced
53:708d8a423b4c 54:c8c17286af95
1 -- no bsk namespace here - we're hooking into AceGUI
2
3 local Type, Version = "SelectorList", 34 1 local Type, Version = "SelectorList", 34
4 local AceGUI = LibStub and LibStub("AceGUI-3.0",true) 2 local AceGUI = LibStub and LibStub("AceGUI-3.0",true)
5 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end 3 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
6 4
5 local con = LibStub("AceConsole-3.0",true)
7 local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type 6 local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type
8 local math_min, math_max, floor = math.min, math.max, floor 7 local math_min, math_max, floor = math.min, math.max, floor
9 local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat 8 local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat
10 9
11 local CreateFrame, UIParent = CreateFrame, UIParent 10 local CreateFrame, UIParent = CreateFrame, UIParent
53 status.scrollvalue = value 52 status.scrollvalue = value
54 self:Refresh() 53 self:Refresh()
55 AceGUI:ClearFocus() 54 AceGUI:ClearFocus()
56 end 55 end
57 56
58 57 local function Button_OnClick(frame)
58 local self = frame.obj
59 local status = self.status or self.localstatus
60 --self:Fire("OnClick", frame.uniquevalue, frame.selected)
61 if status.selected == frame.value then
62 status.selected = nil
63 else
64 status.selected = frame.value
65 end
66 self:Refresh()
67 AceGUI:ClearFocus()
68 end
69
70 local function Button_OnEnter(frame)
71 local self = frame.obj
72 --self:Fire("OnButtonEnter", frame.uniquevalue, frame)
73
74 if self.localstatus.enabletooltips then
75 GameTooltip:SetOwner(frame, "ANCHOR_NONE")
76 GameTooltip:SetPoint("LEFT",frame,"RIGHT")
77 if frame.link then
78 GameTooltip:SetHyperlink(frame.link)
79 else
80 GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, 1)
81 end
82
83 GameTooltip:Show()
84 end
85 end
86
87 local function Button_OnLeave(frame)
88 local self = frame.obj
89 --self:Fire("OnButtonLeave", frame.uniquevalue, frame)
90
91 if self.localstatus.enabletooltips then
92 GameTooltip:Hide()
93 end
94 end
59 95
60 local function Layout(self) 96 local function Layout(self)
61 self:SetHeight(self.numlines * 18 + 20) 97 self:SetHeight(self.numlines * 18 + 20)
62 98
63 end 99 end
86 local text = line.text or "" 122 local text = line.text or ""
87 local icon = line.icon 123 local icon = line.icon
88 local iconCoords = line.iconCoords 124 local iconCoords = line.iconCoords
89 local level = line.level or 1 125 local level = line.level or 1
90 local value = line.value 126 local value = line.value
127 local link = line.link
91 local uniquevalue = line.uniquevalue 128 local uniquevalue = line.uniquevalue
92 local disabled = line.disabled 129 local disabled = line.disabled
130 local status = self.localstatus
93 131
94 button.line = line 132 button.line = line
95 button.value = value 133 button.value = value
134 button.link = link
96 button.uniquevalue = uniquevalue 135 button.uniquevalue = uniquevalue
97 if selected then 136 if selected and status.enableInteractive then
98 button:LockHighlight() 137 button:LockHighlight()
99 button.selected = true 138 button.selected = true
100 else 139 else
101 button:UnlockHighlight() 140 button:UnlockHighlight()
102 button.selected = false 141 button.selected = false
142 end
143 if status.enableInteractive then
144 button:Enable()
145 else
146 button:Disable()
103 end 147 end
104 local normalTexture = button:GetNormalTexture() 148 local normalTexture = button:GetNormalTexture()
105 local line = button.line 149 local line = button.line
106 button.level = level 150 button.level = level
107 if ( level == 1 ) then 151 if ( level == 1 ) then
114 button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2) 158 button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2)
115 end 159 end
116 160
117 if disabled then 161 if disabled then
118 button:EnableMouse(false) 162 button:EnableMouse(false)
119 button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE) 163 local newText = text
164 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")
165 button.text:SetText("|cff808080"..newText..FONT_COLOR_CODE_CLOSE)
120 else 166 else
121 button.text:SetText(text) 167 button.text:SetText(text)
122 button:EnableMouse(true) 168 button:EnableMouse(true)
123 end 169 end
124 170
141 local methods = { 187 local methods = {
142 188
143 ["OnAcquire"] = function(self) 189 ["OnAcquire"] = function(self)
144 self:SetWidth(DEFAULT_SL_WIDTH) 190 self:SetWidth(DEFAULT_SL_WIDTH)
145 self:SetNumLines() 191 self:SetNumLines()
146 --self:EnableButtonTooltips(true) 192 self:EnableButtonTooltips(false)
147 end, 193 self:SetInteractive(true)
148 --["SetWidth"] = function(self, width) 194 end,
149 -- self.slframe:SetWidth(width) 195
150
151 -- local status = self.status or self.localstatus
152 -- status.width = width
153 -- status.treesizable = resizable
154
155 --end,
156 ["SetNumLines"] = function(self,value) 196 ["SetNumLines"] = function(self,value)
157 if not value or value < 4 then 197 if not value or value < 4 then
158 value = 4 198 value = 4
159 end 199 end
160 self.numlines = value 200 self.numlines = value
161 Layout(self) 201 Layout(self)
162 end, 202 end,
203
204 ["EnableButtonTooltips"] = function(self, enable)
205 self.localstatus.enabletooltips = enable
206 end,
207
163 ["SetList"] = function(self, list) 208 ["SetList"] = function(self, list)
164 self.lines = {} 209 self.lines = {}
165 for i,v in ipairs(list) do 210 for i,v in ipairs(list) do
166 self.lines[i] = v 211 self.lines[i] = v
167 end 212 end
213 local status = self.status or self.localstatus
214 status.selected = nil
215 status.scrollvalue = 0
168 self:Refresh() 216 self:Refresh()
169 end, 217 end,
170 218
171 ["ShowScroll"] = function(self, show) 219 ["SetInteractive"] = function(self, value)
220 self.localstatus.enableInteractive = value
221 end,
222
223 ["ShowScroll"] = function(self, show) -- todo: not a user function. hide.
172 self.showscroll = show 224 self.showscroll = show
173 if show then 225 if show then
174 self.scrollbar:Show() 226 self.scrollbar:Show()
175 if self.buttons[1] then 227 if self.buttons[1] then
176 self.buttons[1]:SetPoint("TOPRIGHT", self.slframe,"TOPRIGHT",-22,-10) 228 self.buttons[1]:SetPoint("TOPRIGHT", self.slframe,"TOPRIGHT",-22,-10)
234 else 286 else
235 b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0) 287 b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0)
236 b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0) 288 b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0)
237 end 289 end
238 end 290 end
239 UpdateButton(b, l) 291 UpdateButton(b, l, status.selected == l.value)
240 b:Show() 292 b:Show()
241 bnum = bnum + 1 293 bnum = bnum + 1
242 end 294 end
243 end, 295 end,
244 } 296 }
290 scrollbg:SetTexture(0,0,0,0.4) 342 scrollbg:SetTexture(0,0,0,0.4)
291 343
292 local widget = { 344 local widget = {
293 frame = frame, 345 frame = frame,
294 lines = {}, 346 lines = {},
295 --levels = {},
296 buttons = {}, 347 buttons = {},
297 localstatus = { 348 localstatus = {
298 --groups = {}, 349 --groups = {},
299 scrollvalue = 0 }, 350 enabletooltips= false,
300 filter = false, 351 scrollvalue = 0,
352 },
301 slframe = slframe, 353 slframe = slframe,
302 scrollbar = scrollbar, 354 scrollbar = scrollbar,
303 type = Type 355 type = Type
304 } 356 }
305 if methods then 357 if methods then