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