Asa@0: local AceGUI = LibStub("AceGUI-3.0") Asa@0: Asa@0: -- Lua APIs Asa@0: local assert, pairs, type = assert, pairs, type Asa@0: Asa@0: -- WoW APIs Asa@0: local CreateFrame = CreateFrame Asa@0: Asa@0: --[[ Asa@0: Selection Group controls all have an interface to select a group for thier contents Asa@0: None of them will auto size to thier contents, and should usually be used with a scrollframe Asa@0: unless you know that the controls will fit inside Asa@0: ]] Asa@0: Asa@0: -------------------------- Asa@0: -- Dropdown Group -- Asa@0: -------------------------- Asa@0: --[[ Asa@0: Events : Asa@0: OnGroupSelected Asa@0: Asa@0: ]] Asa@0: do Asa@0: local Type = "DropdownGroup" Asa@0: local Version = 13 Asa@0: Asa@0: local function OnAcquire(self) Asa@0: self.dropdown:SetText("") Asa@0: self:SetDropdownWidth(200) Asa@0: self:SetTitle("") Asa@0: end Asa@0: Asa@0: local function OnRelease(self) Asa@0: self.frame:ClearAllPoints() Asa@0: self.frame:Hide() Asa@0: self.dropdown.list = nil Asa@0: self.status = nil Asa@0: for k in pairs(self.localstatus) do Asa@0: self.localstatus[k] = nil Asa@0: end Asa@0: end Asa@0: Asa@0: local PaneBackdrop = { Asa@0: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", Asa@0: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", Asa@0: tile = true, tileSize = 16, edgeSize = 16, Asa@0: insets = { left = 3, right = 3, top = 5, bottom = 3 } Asa@0: } Asa@0: Asa@0: local function SetTitle(self,title) Asa@0: self.titletext:SetText(title) Asa@0: self.dropdown.frame:ClearAllPoints() Asa@0: if title and title ~= "" then Asa@0: self.dropdown.frame:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -2, 0) Asa@0: else Asa@0: self.dropdown.frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", -1, 0) Asa@0: end Asa@0: end Asa@0: Asa@0: Asa@0: local function SelectedGroup(self,event,value) Asa@0: local group = self.parentgroup Asa@0: local status = group.status or group.localstatus Asa@0: status.selected = value Asa@0: self.parentgroup:Fire("OnGroupSelected", value) Asa@0: end Asa@0: Asa@0: local function SetGroupList(self,list) Asa@0: self.dropdown:SetList(list) Asa@0: end Asa@0: Asa@0: -- called to set an external table to store status in Asa@0: local function SetStatusTable(self, status) Asa@0: assert(type(status) == "table") Asa@0: self.status = status Asa@0: end Asa@0: Asa@0: local function SetGroup(self,group) Asa@0: self.dropdown:SetValue(group) Asa@0: local status = self.status or self.localstatus Asa@0: status.selected = group Asa@0: self:Fire("OnGroupSelected", group) Asa@0: end Asa@0: Asa@0: local function OnWidthSet(self, width) Asa@0: local content = self.content Asa@0: local contentwidth = width - 26 Asa@0: if contentwidth < 0 then Asa@0: contentwidth = 0 Asa@0: end Asa@0: content:SetWidth(contentwidth) Asa@0: content.width = contentwidth Asa@0: end Asa@0: Asa@0: Asa@0: local function OnHeightSet(self, height) Asa@0: local content = self.content Asa@0: local contentheight = height - 63 Asa@0: if contentheight < 0 then Asa@0: contentheight = 0 Asa@0: end Asa@0: content:SetHeight(contentheight) Asa@0: content.height = contentheight Asa@0: end Asa@0: Asa@0: local function LayoutFinished(self, width, height) Asa@0: self:SetHeight((height or 0) + 63) Asa@0: end Asa@0: Asa@0: local function SetDropdownWidth(self, width) Asa@0: self.dropdown:SetWidth(width) Asa@0: end Asa@0: Asa@0: local function Constructor() Asa@0: local frame = CreateFrame("Frame") Asa@0: local self = {} Asa@0: self.type = Type Asa@0: Asa@0: self.OnRelease = OnRelease Asa@0: self.OnAcquire = OnAcquire Asa@0: Asa@0: self.SetTitle = SetTitle Asa@0: self.SetGroupList = SetGroupList Asa@0: self.SetGroup = SetGroup Asa@0: self.SetStatusTable = SetStatusTable Asa@0: self.SetDropdownWidth = SetDropdownWidth Asa@0: self.OnWidthSet = OnWidthSet Asa@0: self.OnHeightSet = OnHeightSet Asa@0: self.LayoutFinished = LayoutFinished Asa@0: Asa@0: self.localstatus = {} Asa@0: Asa@0: self.frame = frame Asa@0: frame.obj = self Asa@0: Asa@0: frame:SetHeight(100) Asa@0: frame:SetWidth(100) Asa@0: frame:SetFrameStrata("FULLSCREEN_DIALOG") Asa@0: Asa@0: local titletext = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") Asa@0: titletext:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -5) Asa@0: titletext:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -4, -5) Asa@0: titletext:SetJustifyH("LEFT") Asa@0: titletext:SetHeight(18) Asa@0: self.titletext = titletext Asa@0: Asa@0: local dropdown = AceGUI:Create("Dropdown") Asa@0: self.dropdown = dropdown Asa@0: dropdown.frame:SetParent(frame) Asa@0: dropdown.frame:SetFrameLevel(dropdown.frame:GetFrameLevel() + 2) Asa@0: dropdown.parentgroup = self Asa@0: dropdown:SetCallback("OnValueChanged",SelectedGroup) Asa@0: dropdown.frame:SetPoint("TOPLEFT",frame,"TOPLEFT", -1, 0) Asa@0: dropdown.frame:Show() Asa@0: dropdown:SetLabel("") Asa@0: Asa@0: local border = CreateFrame("Frame",nil,frame) Asa@0: self.border = border Asa@0: border:SetPoint("TOPLEFT",frame,"TOPLEFT",0,-26) Asa@0: border:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,3) Asa@0: Asa@0: border:SetBackdrop(PaneBackdrop) Asa@0: border:SetBackdropColor(0.1,0.1,0.1,0.5) Asa@0: border:SetBackdropBorderColor(0.4,0.4,0.4) Asa@0: Asa@0: --Container Support Asa@0: local content = CreateFrame("Frame",nil,border) Asa@0: self.content = content Asa@0: content.obj = self Asa@0: content:SetPoint("TOPLEFT",border,"TOPLEFT",10,-10) Asa@0: content:SetPoint("BOTTOMRIGHT",border,"BOTTOMRIGHT",-10,10) Asa@0: Asa@0: AceGUI:RegisterAsContainer(self) Asa@0: return self Asa@0: end Asa@0: Asa@0: AceGUI:RegisterWidgetType(Type,Constructor,Version) Asa@0: end