yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: DropdownGroup Container yellowfive@57: Container controlled by a dropdown on the top. yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "DropdownGroup", 21 yellowfive@57: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) yellowfive@57: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local assert, pairs, type = assert, pairs, type yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local CreateFrame = CreateFrame yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function SelectedGroup(self, event, value) yellowfive@57: local group = self.parentgroup yellowfive@57: local status = group.status or group.localstatus yellowfive@57: status.selected = value yellowfive@57: self.parentgroup:Fire("OnGroupSelected", value) yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: self.dropdown:SetText("") yellowfive@57: self:SetDropdownWidth(200) yellowfive@57: self:SetTitle("") yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnRelease"] = function(self) yellowfive@57: self.dropdown.list = nil yellowfive@57: self.status = nil yellowfive@57: for k in pairs(self.localstatus) do yellowfive@57: self.localstatus[k] = nil yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetTitle"] = function(self, title) yellowfive@57: self.titletext:SetText(title) yellowfive@57: self.dropdown.frame:ClearAllPoints() yellowfive@57: if title and title ~= "" then yellowfive@57: self.dropdown.frame:SetPoint("TOPRIGHT", -2, 0) yellowfive@57: else yellowfive@57: self.dropdown.frame:SetPoint("TOPLEFT", -1, 0) yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetGroupList"] = function(self,list,order) yellowfive@57: self.dropdown:SetList(list,order) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetStatusTable"] = function(self, status) yellowfive@57: assert(type(status) == "table") yellowfive@57: self.status = status yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetGroup"] = function(self,group) yellowfive@57: self.dropdown:SetValue(group) yellowfive@57: local status = self.status or self.localstatus yellowfive@57: status.selected = group yellowfive@57: self:Fire("OnGroupSelected", group) yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnWidthSet"] = function(self, width) yellowfive@57: local content = self.content yellowfive@57: local contentwidth = width - 26 yellowfive@57: if contentwidth < 0 then yellowfive@57: contentwidth = 0 yellowfive@57: end yellowfive@57: content:SetWidth(contentwidth) yellowfive@57: content.width = contentwidth yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnHeightSet"] = function(self, height) yellowfive@57: local content = self.content yellowfive@57: local contentheight = height - 63 yellowfive@57: if contentheight < 0 then yellowfive@57: contentheight = 0 yellowfive@57: end yellowfive@57: content:SetHeight(contentheight) yellowfive@57: content.height = contentheight yellowfive@57: end, yellowfive@57: yellowfive@57: ["LayoutFinished"] = function(self, width, height) yellowfive@57: self:SetHeight((height or 0) + 63) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetDropdownWidth"] = function(self, width) yellowfive@57: self.dropdown:SetWidth(width) yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local PaneBackdrop = { yellowfive@57: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", yellowfive@57: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", yellowfive@57: tile = true, tileSize = 16, edgeSize = 16, yellowfive@57: insets = { left = 3, right = 3, top = 5, bottom = 3 } yellowfive@57: } yellowfive@57: yellowfive@57: local function Constructor() yellowfive@57: local frame = CreateFrame("Frame") yellowfive@57: frame:SetHeight(100) yellowfive@57: frame:SetWidth(100) yellowfive@57: frame:SetFrameStrata("FULLSCREEN_DIALOG") yellowfive@57: yellowfive@57: local titletext = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") yellowfive@57: titletext:SetPoint("TOPLEFT", 4, -5) yellowfive@57: titletext:SetPoint("TOPRIGHT", -4, -5) yellowfive@57: titletext:SetJustifyH("LEFT") yellowfive@57: titletext:SetHeight(18) yellowfive@57: yellowfive@57: local dropdown = AceGUI:Create("Dropdown") yellowfive@57: dropdown.frame:SetParent(frame) yellowfive@57: dropdown.frame:SetFrameLevel(dropdown.frame:GetFrameLevel() + 2) yellowfive@57: dropdown:SetCallback("OnValueChanged", SelectedGroup) yellowfive@57: dropdown.frame:SetPoint("TOPLEFT", -1, 0) yellowfive@57: dropdown.frame:Show() yellowfive@57: dropdown:SetLabel("") yellowfive@57: yellowfive@57: local border = CreateFrame("Frame", nil, frame) yellowfive@57: border:SetPoint("TOPLEFT", 0, -26) yellowfive@57: border:SetPoint("BOTTOMRIGHT", 0, 3) yellowfive@57: border:SetBackdrop(PaneBackdrop) yellowfive@57: border:SetBackdropColor(0.1,0.1,0.1,0.5) yellowfive@57: border:SetBackdropBorderColor(0.4,0.4,0.4) yellowfive@57: yellowfive@57: --Container Support yellowfive@57: local content = CreateFrame("Frame", nil, border) yellowfive@57: content:SetPoint("TOPLEFT", 10, -10) yellowfive@57: content:SetPoint("BOTTOMRIGHT", -10, 10) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: frame = frame, yellowfive@57: localstatus = {}, yellowfive@57: titletext = titletext, yellowfive@57: dropdown = dropdown, yellowfive@57: border = border, yellowfive@57: content = content, yellowfive@57: type = Type yellowfive@57: } yellowfive@57: for method, func in pairs(methods) do yellowfive@57: widget[method] = func yellowfive@57: end yellowfive@57: dropdown.parentgroup = widget yellowfive@57: yellowfive@57: return AceGUI:RegisterAsContainer(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)