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