John@52: -- no bsk namespace here - we're hooking into AceGUI John@52: John@52: local Type, Version = "SelectorList", 34 John@52: local AceGUI = LibStub and LibStub("AceGUI-3.0",true) John@52: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end John@52: John@52: local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type John@52: local math_min, math_max, floor = math.min, math.max, floor John@52: local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat John@52: John@52: local CreateFrame, UIParent = CreateFrame, UIParent John@52: John@52: local new, del John@52: do John@52: local pool = setmetatable({},{__mode='k'}) John@52: function new() John@52: local t = next(pool) John@52: if t then John@52: pool[t] = nil John@52: return t John@52: else John@52: return {} John@52: end John@52: end John@52: function del(t) John@52: for k in pairs(t) do John@52: t[k] = nil John@52: end John@52: pool[t] = true John@52: end John@52: end John@52: John@52: local DEFAULT_SL_WIDTH = 175 John@52: --local DEFAULT_TREE_SIZABLE = true John@52: John@52: John@52: local function Layout(self) John@52: self:SetHeight(self.numlines * 18 + 20) John@52: John@52: end John@52: John@52: local function CreateButton(widget) John@52: local num = AceGUI:GetNextWidgetNum("TreeGroupButton") John@52: local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), widget.slframe, "OptionsListButtonTemplate") John@52: button.obj = widget John@52: John@52: local icon = button:CreateTexture(nil, "OVERLAY") John@52: icon:SetWidth(14) John@52: icon:SetHeight(14) John@52: button.icon = icon John@52: John@52: button:SetScript("OnClick",Button_OnClick) John@52: button:SetScript("OnDoubleClick", Button_OnDoubleClick) John@52: button:SetScript("OnEnter",Button_OnEnter) John@52: button:SetScript("OnLeave",Button_OnLeave) John@52: John@52: return button John@52: end John@52: John@52: local function UpdateButton(button, line, selected) John@52: local self = button.obj John@52: local frame = self.frame John@52: local text = line.text or "" John@52: local icon = line.icon John@52: local iconCoords = line.iconCoords John@52: local level = line.level or 1 John@52: local value = line.value John@52: local uniquevalue = line.uniquevalue John@52: local disabled = line.disabled John@52: John@52: button.line = line John@52: button.value = value John@52: button.uniquevalue = uniquevalue John@52: if selected then John@52: button:LockHighlight() John@52: button.selected = true John@52: else John@52: button:UnlockHighlight() John@52: button.selected = false John@52: end John@52: local normalTexture = button:GetNormalTexture() John@52: local line = button.line John@52: button.level = level John@52: if ( level == 1 ) then John@52: button:SetNormalFontObject("GameFontNormal") John@52: button:SetHighlightFontObject("GameFontHighlight") John@52: button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2) John@52: else John@52: button:SetNormalFontObject("GameFontHighlightSmall") John@52: button:SetHighlightFontObject("GameFontHighlightSmall") John@52: button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2) John@52: end John@52: John@52: if disabled then John@52: button:EnableMouse(false) John@52: button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE) John@52: else John@52: button.text:SetText(text) John@52: button:EnableMouse(true) John@52: end John@52: John@52: if icon then John@52: button.icon:SetTexture(icon) John@52: button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1) John@52: else John@52: button.icon:SetTexture(nil) John@52: end John@52: John@52: if iconCoords then John@52: button.icon:SetTexCoord(unpack(iconCoords)) John@52: else John@52: button.icon:SetTexCoord(0, 1, 0, 1) John@52: end John@52: end John@52: John@52: John@52: local methods = { John@52: John@52: ["OnAcquire"] = function(self) John@52: self:SetWidth(DEFAULT_SL_WIDTH) John@52: self:SetNumLines() John@52: --self:EnableButtonTooltips(true) John@52: end, John@52: --["SetWidth"] = function(self, width) John@52: -- self.slframe:SetWidth(width) John@52: John@52: -- local status = self.status or self.localstatus John@52: -- status.width = width John@52: -- status.treesizable = resizable John@52: John@52: --end, John@52: ["SetNumLines"] = function(self,value) John@52: if not value or value < 4 then John@52: value = 4 John@52: end John@52: self.numlines = value John@52: Layout(self) John@52: end, John@52: ["SetList"] = function(self, list) John@52: for i,v in ipairs(list) do John@52: self.lines[i] = v John@52: end John@52: self:Refresh() John@52: end, John@52: ["Refresh"] = function(self) John@52: local f = self.slframe John@52: local buttons = self.buttons John@52: local lines = self.lines John@52: John@52: local bnum = 1 John@52: for i=1,self.numlines do John@52: local l = lines[i] John@52: if not l then John@52: break John@52: end John@52: local b = buttons[bnum] John@52: if not b then John@52: b = CreateButton(self) John@52: buttons[bnum] = b John@52: b:SetParent(f) John@52: b:SetFrameLevel(f:GetFrameLevel()+1) John@52: b:ClearAllPoints() John@52: if bnum == 1 then John@52: -- todo: if scroll ... John@52: b:SetPoint("TOPLEFT",0,-10) John@52: b:SetPoint("TOPRIGHT",0,-10) John@52: else John@52: b:SetPoint("TOPRIGHT", buttons[bnum-1], "BOTTOMRIGHT", 0, 0) John@52: b:SetPoint("TOPLEFT", buttons[bnum-1], "BOTTOMLEFT", 0, 0) John@52: end John@52: end John@52: UpdateButton(b, l) John@52: b:Show() John@52: bnum = bnum + 1 John@52: end John@52: end, John@52: } John@52: John@52: John@52: John@52: John@52: John@52: John@52: John@52: John@52: John@52: local PaneBackdrop = { John@52: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", John@52: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", John@52: tile = true, tileSize = 16, edgeSize = 16, John@52: insets = { left = 3, right = 3, top = 5, bottom = 3 } John@52: } John@52: John@52: local function Constructor() John@52: local num = AceGUI:GetNextWidgetNum(Type) John@52: local frame = CreateFrame("Frame", nil, UIParent) John@52: John@52: local slframe = CreateFrame("Frame", nil, frame) John@52: slframe:SetAllPoints() John@52: --slframe:SetPoint("TOPLEFT") John@52: --slframe:SetPoint("BOTTOMLEFT") John@52: --slframe:SetWidth(DEFAULT_SL_WIDTH) John@52: --slframe:SetHeight(DEFAULT_SL_WIDTH) -- todo John@52: slframe:EnableMouseWheel(true) John@52: slframe:SetBackdrop(PaneBackdrop) John@52: slframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5) John@52: slframe:SetBackdropBorderColor(0.4, 0.4, 0.4) John@52: --slframe:SetResizable(true) John@52: --slframe:SetMinResize(100, 1) John@52: --slframe:SetMaxResize(400, 1600) John@52: --slframe:SetScript("OnUpdate", FirstFrameUpdate) John@52: --slframe:SetScript("OnSizeChanged", Tree_OnSizeChanged) John@52: --slframe:SetScript("OnMouseWheel", Tree_OnMouseWheel) John@52: John@52: --local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), slframe, "UIPanelScrollBarTemplate") John@52: --scrollbar:SetScript("OnValueChanged", nil) John@52: --scrollbar:SetPoint("TOPRIGHT", -10, -26) John@52: --scrollbar:SetPoint("BOTTOMRIGHT", -10, 26) John@52: --scrollbar:SetMinMaxValues(0,0) John@52: --scrollbar:SetValueStep(1) John@52: --scrollbar:SetValue(0) John@52: --scrollbar:SetWidth(16) John@52: --scrollbar:SetScript("OnValueChanged", OnScrollValueChanged) John@52: John@52: --local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") John@52: --scrollbg:SetAllPoints(scrollbar) John@52: --scrollbg:SetTexture(0,0,0,0.4) John@52: John@52: --local border = CreateFrame("Frame",nil,frame) John@52: --border:SetPoint("TOPLEFT", slframe, "TOPRIGHT") John@52: --border:SetPoint("BOTTOMRIGHT") John@52: --border:SetBackdrop(PaneBackdrop) John@52: --border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) John@52: --border:SetBackdropBorderColor(0.4, 0.4, 0.4) John@52: John@52: ----Container Support John@52: --local content = CreateFrame("Frame", nil, border) John@52: --content:SetPoint("TOPLEFT", 10, -10) John@52: --content:SetPoint("BOTTOMRIGHT", -10, 10) John@52: John@52: local widget = { John@52: frame = frame, John@52: lines = {}, John@52: --levels = {}, John@52: buttons = {}, John@52: --hasChildren = {}, John@52: localstatus = { John@52: --groups = {}, John@52: scrollvalue = 0 }, John@52: filter = false, John@52: slframe = slframe, John@52: --dragger = dragger, John@52: --scrollbar = scrollbar, John@52: --border = border, John@52: --content = slframe, -- content is for containers John@52: type = Type John@52: } John@52: if methods then John@52: for method, func in pairs(methods) do John@52: widget[method] = func John@52: end John@52: end John@52: slframe.obj = widget John@52: --dragger.obj = widget John@52: --scrollbar.obj = widget John@52: John@52: return AceGUI:RegisterAsWidget(widget) John@52: end John@52: John@52: AceGUI:RegisterWidgetType(Type, Constructor, Version) John@52: John@52: John@52: John@52: