Tercio@51: --[[ $Id: AceGUIWidget-DropDown.lua 1167 2017-08-29 22:08:48Z funkydude $ ]]-- Tercio@23: local AceGUI = LibStub("AceGUI-3.0") Tercio@23: Tercio@23: -- Lua APIs Tercio@23: local min, max, floor = math.min, math.max, math.floor Tercio@23: local select, pairs, ipairs, type = select, pairs, ipairs, type Tercio@23: local tsort = table.sort Tercio@23: Tercio@23: -- WoW APIs Tercio@23: local PlaySound = PlaySound Tercio@23: local UIParent, CreateFrame = UIParent, CreateFrame Tercio@23: local _G = _G Tercio@23: Tercio@23: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded Tercio@23: -- List them here for Mikk's FindGlobals script Tercio@23: -- GLOBALS: CLOSE Tercio@23: Tercio@23: local function fixlevels(parent,...) Tercio@23: local i = 1 Tercio@23: local child = select(i, ...) Tercio@23: while child do Tercio@23: child:SetFrameLevel(parent:GetFrameLevel()+1) Tercio@23: fixlevels(child, child:GetChildren()) Tercio@23: i = i + 1 Tercio@23: child = select(i, ...) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: local function fixstrata(strata, parent, ...) Tercio@23: local i = 1 Tercio@23: local child = select(i, ...) Tercio@23: parent:SetFrameStrata(strata) Tercio@23: while child do Tercio@23: fixstrata(strata, child, child:GetChildren()) Tercio@23: i = i + 1 Tercio@23: child = select(i, ...) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: do Tercio@23: local widgetType = "Dropdown-Pullout" Tercio@23: local widgetVersion = 3 Tercio@23: Tercio@23: --[[ Static data ]]-- Tercio@23: Tercio@23: local backdrop = { Tercio@23: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", Tercio@23: edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", Tercio@23: edgeSize = 32, Tercio@23: tileSize = 32, Tercio@23: tile = true, Tercio@23: insets = { left = 11, right = 12, top = 12, bottom = 11 }, Tercio@23: } Tercio@23: local sliderBackdrop = { Tercio@23: bgFile = "Interface\\Buttons\\UI-SliderBar-Background", Tercio@23: edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", Tercio@23: tile = true, tileSize = 8, edgeSize = 8, Tercio@23: insets = { left = 3, right = 3, top = 3, bottom = 3 } Tercio@23: } Tercio@23: Tercio@23: local defaultWidth = 200 Tercio@23: local defaultMaxHeight = 600 Tercio@23: Tercio@23: --[[ UI Event Handlers ]]-- Tercio@23: Tercio@23: -- HACK: This should be no part of the pullout, but there Tercio@23: -- is no other 'clean' way to response to any item-OnEnter Tercio@23: -- Used to close Submenus when an other item is entered Tercio@23: local function OnEnter(item) Tercio@23: local self = item.pullout Tercio@23: for k, v in ipairs(self.items) do Tercio@23: if v.CloseMenu and v ~= item then Tercio@23: v:CloseMenu() Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- See the note in Constructor() for each scroll related function Tercio@23: local function OnMouseWheel(this, value) Tercio@23: this.obj:MoveScroll(value) Tercio@23: end Tercio@23: Tercio@23: local function OnScrollValueChanged(this, value) Tercio@23: this.obj:SetScroll(value) Tercio@23: end Tercio@23: Tercio@23: local function OnSizeChanged(this) Tercio@23: this.obj:FixScroll() Tercio@23: end Tercio@23: Tercio@23: --[[ Exported methods ]]-- Tercio@23: Tercio@23: -- exported Tercio@23: local function SetScroll(self, value) Tercio@23: local status = self.scrollStatus Tercio@23: local frame, child = self.scrollFrame, self.itemFrame Tercio@23: local height, viewheight = frame:GetHeight(), child:GetHeight() Tercio@23: Tercio@23: local offset Tercio@23: if height > viewheight then Tercio@23: offset = 0 Tercio@23: else Tercio@23: offset = floor((viewheight - height) / 1000 * value) Tercio@23: end Tercio@23: child:ClearAllPoints() Tercio@23: child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset) Tercio@23: child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", self.slider:IsShown() and -12 or 0, offset) Tercio@23: status.offset = offset Tercio@23: status.scrollvalue = value Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function MoveScroll(self, value) Tercio@23: local status = self.scrollStatus Tercio@23: local frame, child = self.scrollFrame, self.itemFrame Tercio@23: local height, viewheight = frame:GetHeight(), child:GetHeight() Tercio@23: Tercio@23: if height > viewheight then Tercio@23: self.slider:Hide() Tercio@23: else Tercio@23: self.slider:Show() Tercio@23: local diff = height - viewheight Tercio@23: local delta = 1 Tercio@23: if value < 0 then Tercio@23: delta = -1 Tercio@23: end Tercio@23: self.slider:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000)) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function FixScroll(self) Tercio@23: local status = self.scrollStatus Tercio@23: local frame, child = self.scrollFrame, self.itemFrame Tercio@23: local height, viewheight = frame:GetHeight(), child:GetHeight() Tercio@23: local offset = status.offset or 0 Tercio@23: Tercio@23: if viewheight < height then Tercio@23: self.slider:Hide() Tercio@23: child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, offset) Tercio@23: self.slider:SetValue(0) Tercio@23: else Tercio@23: self.slider:Show() Tercio@23: local value = (offset / (viewheight - height) * 1000) Tercio@23: if value > 1000 then value = 1000 end Tercio@23: self.slider:SetValue(value) Tercio@23: self:SetScroll(value) Tercio@23: if value < 1000 then Tercio@23: child:ClearAllPoints() Tercio@23: child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset) Tercio@23: child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -12, offset) Tercio@23: status.offset = offset Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported, AceGUI callback Tercio@23: local function OnAcquire(self) Tercio@23: self.frame:SetParent(UIParent) Tercio@23: --self.itemFrame:SetToplevel(true) Tercio@23: end Tercio@23: Tercio@23: -- exported, AceGUI callback Tercio@23: local function OnRelease(self) Tercio@23: self:Clear() Tercio@23: self.frame:ClearAllPoints() Tercio@23: self.frame:Hide() Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function AddItem(self, item) Tercio@23: self.items[#self.items + 1] = item Tercio@23: Tercio@23: local h = #self.items * 16 Tercio@23: self.itemFrame:SetHeight(h) Tercio@23: self.frame:SetHeight(min(h + 34, self.maxHeight)) -- +34: 20 for scrollFrame placement (10 offset) and +14 for item placement Tercio@23: Tercio@23: item.frame:SetPoint("LEFT", self.itemFrame, "LEFT") Tercio@23: item.frame:SetPoint("RIGHT", self.itemFrame, "RIGHT") Tercio@23: Tercio@23: item:SetPullout(self) Tercio@23: item:SetOnEnter(OnEnter) Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function Open(self, point, relFrame, relPoint, x, y) Tercio@23: local items = self.items Tercio@23: local frame = self.frame Tercio@23: local itemFrame = self.itemFrame Tercio@23: Tercio@23: frame:SetPoint(point, relFrame, relPoint, x, y) Tercio@23: Tercio@23: Tercio@23: local height = 8 Tercio@23: for i, item in pairs(items) do Tercio@23: if i == 1 then Tercio@23: item:SetPoint("TOP", itemFrame, "TOP", 0, -2) Tercio@23: else Tercio@23: item:SetPoint("TOP", items[i-1].frame, "BOTTOM", 0, 1) Tercio@23: end Tercio@23: Tercio@23: item:Show() Tercio@23: Tercio@23: height = height + 16 Tercio@23: end Tercio@23: itemFrame:SetHeight(height) Tercio@23: fixstrata("TOOLTIP", frame, frame:GetChildren()) Tercio@23: frame:Show() Tercio@23: self:Fire("OnOpen") Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function Close(self) Tercio@23: self.frame:Hide() Tercio@23: self:Fire("OnClose") Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function Clear(self) Tercio@23: local items = self.items Tercio@23: for i, item in pairs(items) do Tercio@23: AceGUI:Release(item) Tercio@23: items[i] = nil Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function IterateItems(self) Tercio@23: return ipairs(self.items) Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetHideOnLeave(self, val) Tercio@23: self.hideOnLeave = val Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetMaxHeight(self, height) Tercio@23: self.maxHeight = height or defaultMaxHeight Tercio@23: if self.frame:GetHeight() > height then Tercio@23: self.frame:SetHeight(height) Tercio@23: elseif (self.itemFrame:GetHeight() + 34) < height then Tercio@23: self.frame:SetHeight(self.itemFrame:GetHeight() + 34) -- see :AddItem Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function GetRightBorderWidth(self) Tercio@23: return 6 + (self.slider:IsShown() and 12 or 0) Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function GetLeftBorderWidth(self) Tercio@23: return 6 Tercio@23: end Tercio@23: Tercio@23: --[[ Constructor ]]-- Tercio@23: Tercio@23: local function Constructor() Tercio@23: local count = AceGUI:GetNextWidgetNum(widgetType) Tercio@23: local frame = CreateFrame("Frame", "AceGUI30Pullout"..count, UIParent) Tercio@23: local self = {} Tercio@23: self.count = count Tercio@23: self.type = widgetType Tercio@23: self.frame = frame Tercio@23: frame.obj = self Tercio@23: Tercio@23: self.OnAcquire = OnAcquire Tercio@23: self.OnRelease = OnRelease Tercio@23: Tercio@23: self.AddItem = AddItem Tercio@23: self.Open = Open Tercio@23: self.Close = Close Tercio@23: self.Clear = Clear Tercio@23: self.IterateItems = IterateItems Tercio@23: self.SetHideOnLeave = SetHideOnLeave Tercio@23: Tercio@23: self.SetScroll = SetScroll Tercio@23: self.MoveScroll = MoveScroll Tercio@23: self.FixScroll = FixScroll Tercio@23: Tercio@23: self.SetMaxHeight = SetMaxHeight Tercio@23: self.GetRightBorderWidth = GetRightBorderWidth Tercio@23: self.GetLeftBorderWidth = GetLeftBorderWidth Tercio@23: Tercio@23: self.items = {} Tercio@23: Tercio@23: self.scrollStatus = { Tercio@23: scrollvalue = 0, Tercio@23: } Tercio@23: Tercio@23: self.maxHeight = defaultMaxHeight Tercio@23: Tercio@23: frame:SetBackdrop(backdrop) Tercio@23: frame:SetBackdropColor(0, 0, 0) Tercio@23: frame:SetFrameStrata("FULLSCREEN_DIALOG") Tercio@23: frame:SetClampedToScreen(true) Tercio@23: frame:SetWidth(defaultWidth) Tercio@23: frame:SetHeight(self.maxHeight) Tercio@23: --frame:SetToplevel(true) Tercio@23: Tercio@23: -- NOTE: The whole scroll frame code is copied from the AceGUI-3.0 widget ScrollFrame Tercio@23: local scrollFrame = CreateFrame("ScrollFrame", nil, frame) Tercio@23: local itemFrame = CreateFrame("Frame", nil, scrollFrame) Tercio@23: Tercio@23: self.scrollFrame = scrollFrame Tercio@23: self.itemFrame = itemFrame Tercio@23: Tercio@23: scrollFrame.obj = self Tercio@23: itemFrame.obj = self Tercio@23: Tercio@23: local slider = CreateFrame("Slider", "AceGUI30PulloutScrollbar"..count, scrollFrame) Tercio@23: slider:SetOrientation("VERTICAL") Tercio@23: slider:SetHitRectInsets(0, 0, -10, 0) Tercio@23: slider:SetBackdrop(sliderBackdrop) Tercio@23: slider:SetWidth(8) Tercio@23: slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Vertical") Tercio@23: slider:SetFrameStrata("FULLSCREEN_DIALOG") Tercio@23: self.slider = slider Tercio@23: slider.obj = self Tercio@23: Tercio@23: scrollFrame:SetScrollChild(itemFrame) Tercio@23: scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -12) Tercio@23: scrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -6, 12) Tercio@23: scrollFrame:EnableMouseWheel(true) Tercio@23: scrollFrame:SetScript("OnMouseWheel", OnMouseWheel) Tercio@23: scrollFrame:SetScript("OnSizeChanged", OnSizeChanged) Tercio@23: scrollFrame:SetToplevel(true) Tercio@23: scrollFrame:SetFrameStrata("FULLSCREEN_DIALOG") Tercio@23: Tercio@23: itemFrame:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, 0) Tercio@23: itemFrame:SetPoint("TOPRIGHT", scrollFrame, "TOPRIGHT", -12, 0) Tercio@23: itemFrame:SetHeight(400) Tercio@23: itemFrame:SetToplevel(true) Tercio@23: itemFrame:SetFrameStrata("FULLSCREEN_DIALOG") Tercio@23: Tercio@23: slider:SetPoint("TOPLEFT", scrollFrame, "TOPRIGHT", -16, 0) Tercio@23: slider:SetPoint("BOTTOMLEFT", scrollFrame, "BOTTOMRIGHT", -16, 0) Tercio@23: slider:SetScript("OnValueChanged", OnScrollValueChanged) Tercio@23: slider:SetMinMaxValues(0, 1000) Tercio@23: slider:SetValueStep(1) Tercio@23: slider:SetValue(0) Tercio@23: Tercio@23: scrollFrame:Show() Tercio@23: itemFrame:Show() Tercio@23: slider:Hide() Tercio@23: Tercio@23: self:FixScroll() Tercio@23: Tercio@23: AceGUI:RegisterAsWidget(self) Tercio@23: return self Tercio@23: end Tercio@23: Tercio@23: AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) Tercio@23: end Tercio@23: Tercio@23: do Tercio@23: local widgetType = "Dropdown" Tercio@51: local widgetVersion = 31 Tercio@23: Tercio@23: --[[ Static data ]]-- Tercio@23: Tercio@23: --[[ UI event handler ]]-- Tercio@23: Tercio@23: local function Control_OnEnter(this) Tercio@23: this.obj.button:LockHighlight() Tercio@23: this.obj:Fire("OnEnter") Tercio@23: end Tercio@23: Tercio@23: local function Control_OnLeave(this) Tercio@23: this.obj.button:UnlockHighlight() Tercio@23: this.obj:Fire("OnLeave") Tercio@23: end Tercio@23: Tercio@23: local function Dropdown_OnHide(this) Tercio@23: local self = this.obj Tercio@23: if self.open then Tercio@23: self.pullout:Close() Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: local function Dropdown_TogglePullout(this) Tercio@23: local self = this.obj Tercio@51: PlaySound(856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON Tercio@23: if self.open then Tercio@23: self.open = nil Tercio@23: self.pullout:Close() Tercio@23: AceGUI:ClearFocus() Tercio@23: else Tercio@23: self.open = true Tercio@23: self.pullout:SetWidth(self.pulloutWidth or self.frame:GetWidth()) Tercio@23: self.pullout:Open("TOPLEFT", self.frame, "BOTTOMLEFT", 0, self.label:IsShown() and -2 or 0) Tercio@23: AceGUI:SetFocus(self) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: local function OnPulloutOpen(this) Tercio@23: local self = this.userdata.obj Tercio@23: local value = self.value Tercio@23: Tercio@23: if not self.multiselect then Tercio@23: for i, item in this:IterateItems() do Tercio@23: item:SetValue(item.userdata.value == value) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: self.open = true Tercio@23: self:Fire("OnOpened") Tercio@23: end Tercio@23: Tercio@23: local function OnPulloutClose(this) Tercio@23: local self = this.userdata.obj Tercio@23: self.open = nil Tercio@23: self:Fire("OnClosed") Tercio@23: end Tercio@23: Tercio@23: local function ShowMultiText(self) Tercio@23: local text Tercio@23: for i, widget in self.pullout:IterateItems() do Tercio@23: if widget.type == "Dropdown-Item-Toggle" then Tercio@23: if widget:GetValue() then Tercio@23: if text then Tercio@23: text = text..", "..widget:GetText() Tercio@23: else Tercio@23: text = widget:GetText() Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: self:SetText(text) Tercio@23: end Tercio@23: Tercio@23: local function OnItemValueChanged(this, event, checked) Tercio@23: local self = this.userdata.obj Tercio@23: Tercio@23: if self.multiselect then Tercio@23: self:Fire("OnValueChanged", this.userdata.value, checked) Tercio@23: ShowMultiText(self) Tercio@23: else Tercio@23: if checked then Tercio@23: self:SetValue(this.userdata.value) Tercio@23: self:Fire("OnValueChanged", this.userdata.value) Tercio@23: else Tercio@23: this:SetValue(true) Tercio@23: end Tercio@23: if self.open then Tercio@23: self.pullout:Close() Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: --[[ Exported methods ]]-- Tercio@23: Tercio@23: -- exported, AceGUI callback Tercio@23: local function OnAcquire(self) Tercio@23: local pullout = AceGUI:Create("Dropdown-Pullout") Tercio@23: self.pullout = pullout Tercio@23: pullout.userdata.obj = self Tercio@23: pullout:SetCallback("OnClose", OnPulloutClose) Tercio@23: pullout:SetCallback("OnOpen", OnPulloutOpen) Tercio@23: self.pullout.frame:SetFrameLevel(self.frame:GetFrameLevel() + 1) Tercio@23: fixlevels(self.pullout.frame, self.pullout.frame:GetChildren()) Tercio@23: Tercio@23: self:SetHeight(44) Tercio@23: self:SetWidth(200) Tercio@23: self:SetLabel() Tercio@23: self:SetPulloutWidth(nil) Tercio@23: end Tercio@23: Tercio@23: -- exported, AceGUI callback Tercio@23: local function OnRelease(self) Tercio@23: if self.open then Tercio@23: self.pullout:Close() Tercio@23: end Tercio@23: AceGUI:Release(self.pullout) Tercio@23: self.pullout = nil Tercio@23: Tercio@23: self:SetText("") Tercio@23: self:SetDisabled(false) Tercio@23: self:SetMultiselect(false) Tercio@23: Tercio@23: self.value = nil Tercio@23: self.list = nil Tercio@23: self.open = nil Tercio@23: self.hasClose = nil Tercio@23: Tercio@23: self.frame:ClearAllPoints() Tercio@23: self.frame:Hide() Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetDisabled(self, disabled) Tercio@23: self.disabled = disabled Tercio@23: if disabled then Tercio@23: self.text:SetTextColor(0.5,0.5,0.5) Tercio@23: self.button:Disable() Tercio@23: self.button_cover:Disable() Tercio@23: self.label:SetTextColor(0.5,0.5,0.5) Tercio@23: else Tercio@23: self.button:Enable() Tercio@23: self.button_cover:Enable() Tercio@23: self.label:SetTextColor(1,.82,0) Tercio@23: self.text:SetTextColor(1,1,1) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function ClearFocus(self) Tercio@23: if self.open then Tercio@23: self.pullout:Close() Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetText(self, text) Tercio@23: self.text:SetText(text or "") Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetLabel(self, text) Tercio@23: if text and text ~= "" then Tercio@23: self.label:SetText(text) Tercio@23: self.label:Show() Tercio@23: self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,-14) Tercio@23: self:SetHeight(40) Tercio@23: self.alignoffset = 26 Tercio@23: else Tercio@23: self.label:SetText("") Tercio@23: self.label:Hide() Tercio@23: self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,0) Tercio@23: self:SetHeight(26) Tercio@23: self.alignoffset = 12 Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetValue(self, value) Tercio@23: if self.list then Tercio@23: self:SetText(self.list[value] or "") Tercio@23: end Tercio@23: self.value = value Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function GetValue(self) Tercio@23: return self.value Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetItemValue(self, item, value) Tercio@23: if not self.multiselect then return end Tercio@23: for i, widget in self.pullout:IterateItems() do Tercio@23: if widget.userdata.value == item then Tercio@23: if widget.SetValue then Tercio@23: widget:SetValue(value) Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: ShowMultiText(self) Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetItemDisabled(self, item, disabled) Tercio@23: for i, widget in self.pullout:IterateItems() do Tercio@23: if widget.userdata.value == item then Tercio@23: widget:SetDisabled(disabled) Tercio@23: end Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: local function AddListItem(self, value, text, itemType) Tercio@23: if not itemType then itemType = "Dropdown-Item-Toggle" end Tercio@23: local exists = AceGUI:GetWidgetVersion(itemType) Tercio@23: if not exists then error(("The given item type, %q, does not exist within AceGUI-3.0"):format(tostring(itemType)), 2) end Tercio@23: Tercio@23: local item = AceGUI:Create(itemType) Tercio@23: item:SetText(text) Tercio@23: item.userdata.obj = self Tercio@23: item.userdata.value = value Tercio@23: item:SetCallback("OnValueChanged", OnItemValueChanged) Tercio@23: self.pullout:AddItem(item) Tercio@23: end Tercio@23: Tercio@23: local function AddCloseButton(self) Tercio@23: if not self.hasClose then Tercio@23: local close = AceGUI:Create("Dropdown-Item-Execute") Tercio@23: close:SetText(CLOSE) Tercio@23: self.pullout:AddItem(close) Tercio@23: self.hasClose = true Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local sortlist = {} Tercio@23: local function SetList(self, list, order, itemType) Tercio@23: self.list = list Tercio@23: self.pullout:Clear() Tercio@23: self.hasClose = nil Tercio@23: if not list then return end Tercio@23: Tercio@23: if type(order) ~= "table" then Tercio@23: for v in pairs(list) do Tercio@23: sortlist[#sortlist + 1] = v Tercio@23: end Tercio@23: tsort(sortlist) Tercio@23: Tercio@23: for i, key in ipairs(sortlist) do Tercio@23: AddListItem(self, key, list[key], itemType) Tercio@23: sortlist[i] = nil Tercio@23: end Tercio@23: else Tercio@23: for i, key in ipairs(order) do Tercio@23: AddListItem(self, key, list[key], itemType) Tercio@23: end Tercio@23: end Tercio@23: if self.multiselect then Tercio@23: ShowMultiText(self) Tercio@23: AddCloseButton(self) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function AddItem(self, value, text, itemType) Tercio@23: if self.list then Tercio@23: self.list[value] = text Tercio@23: AddListItem(self, value, text, itemType) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function SetMultiselect(self, multi) Tercio@23: self.multiselect = multi Tercio@23: if multi then Tercio@23: ShowMultiText(self) Tercio@23: AddCloseButton(self) Tercio@23: end Tercio@23: end Tercio@23: Tercio@23: -- exported Tercio@23: local function GetMultiselect(self) Tercio@23: return self.multiselect Tercio@23: end Tercio@23: Tercio@23: local function SetPulloutWidth(self, width) Tercio@23: self.pulloutWidth = width Tercio@23: end Tercio@23: Tercio@23: --[[ Constructor ]]-- Tercio@23: Tercio@23: local function Constructor() Tercio@23: local count = AceGUI:GetNextWidgetNum(widgetType) Tercio@23: local frame = CreateFrame("Frame", nil, UIParent) Tercio@23: local dropdown = CreateFrame("Frame", "AceGUI30DropDown"..count, frame, "UIDropDownMenuTemplate") Tercio@23: Tercio@23: local self = {} Tercio@23: self.type = widgetType Tercio@23: self.frame = frame Tercio@23: self.dropdown = dropdown Tercio@23: self.count = count Tercio@23: frame.obj = self Tercio@23: dropdown.obj = self Tercio@23: Tercio@23: self.OnRelease = OnRelease Tercio@23: self.OnAcquire = OnAcquire Tercio@23: Tercio@23: self.ClearFocus = ClearFocus Tercio@23: Tercio@23: self.SetText = SetText Tercio@23: self.SetValue = SetValue Tercio@23: self.GetValue = GetValue Tercio@23: self.SetList = SetList Tercio@23: self.SetLabel = SetLabel Tercio@23: self.SetDisabled = SetDisabled Tercio@23: self.AddItem = AddItem Tercio@23: self.SetMultiselect = SetMultiselect Tercio@23: self.GetMultiselect = GetMultiselect Tercio@23: self.SetItemValue = SetItemValue Tercio@23: self.SetItemDisabled = SetItemDisabled Tercio@23: self.SetPulloutWidth = SetPulloutWidth Tercio@23: Tercio@23: self.alignoffset = 26 Tercio@23: Tercio@23: frame:SetScript("OnHide",Dropdown_OnHide) Tercio@23: Tercio@23: dropdown:ClearAllPoints() Tercio@23: dropdown:SetPoint("TOPLEFT",frame,"TOPLEFT",-15,0) Tercio@23: dropdown:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",17,0) Tercio@23: dropdown:SetScript("OnHide", nil) Tercio@23: Tercio@23: local left = _G[dropdown:GetName() .. "Left"] Tercio@23: local middle = _G[dropdown:GetName() .. "Middle"] Tercio@23: local right = _G[dropdown:GetName() .. "Right"] Tercio@23: Tercio@23: middle:ClearAllPoints() Tercio@23: right:ClearAllPoints() Tercio@23: Tercio@23: middle:SetPoint("LEFT", left, "RIGHT", 0, 0) Tercio@23: middle:SetPoint("RIGHT", right, "LEFT", 0, 0) Tercio@23: right:SetPoint("TOPRIGHT", dropdown, "TOPRIGHT", 0, 17) Tercio@23: Tercio@23: local button = _G[dropdown:GetName() .. "Button"] Tercio@23: self.button = button Tercio@23: button.obj = self Tercio@23: button:SetScript("OnEnter",Control_OnEnter) Tercio@23: button:SetScript("OnLeave",Control_OnLeave) Tercio@23: button:SetScript("OnClick",Dropdown_TogglePullout) Tercio@23: Tercio@23: local button_cover = CreateFrame("BUTTON",nil,self.frame) Tercio@23: self.button_cover = button_cover Tercio@23: button_cover.obj = self Tercio@23: button_cover:SetPoint("TOPLEFT",self.frame,"BOTTOMLEFT",0,25) Tercio@23: button_cover:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT") Tercio@23: button_cover:SetScript("OnEnter",Control_OnEnter) Tercio@23: button_cover:SetScript("OnLeave",Control_OnLeave) Tercio@23: button_cover:SetScript("OnClick",Dropdown_TogglePullout) Tercio@23: Tercio@23: local text = _G[dropdown:GetName() .. "Text"] Tercio@23: self.text = text Tercio@23: text.obj = self Tercio@23: text:ClearAllPoints() Tercio@23: text:SetPoint("RIGHT", right, "RIGHT" ,-43, 2) Tercio@23: text:SetPoint("LEFT", left, "LEFT", 25, 2) Tercio@23: Tercio@23: local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") Tercio@23: label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) Tercio@23: label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0) Tercio@23: label:SetJustifyH("LEFT") Tercio@23: label:SetHeight(18) Tercio@23: label:Hide() Tercio@23: self.label = label Tercio@23: Tercio@23: AceGUI:RegisterAsWidget(self) Tercio@23: return self Tercio@23: end Tercio@23: Tercio@23: AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) Tercio@23: end