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