1 -- Widget is based on the AceGUIWidget-DropDown.lua supplied with AceGUI-3.0
2 -- Widget created by Yssaril
4 local AceGUI = LibStub("AceGUI-3.0")
5 local Media = LibStub("LibSharedMedia-3.0")
7 local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
10 local widgetType = "LSM30_Background"
11 local widgetVersion = 9
13 local contentFrameCache = {}
14 local function ReturnSelf(self)
18 table.insert(contentFrameCache, self)
21 local function ContentOnClick(this, button)
23 self:Fire("OnValueChanged", this.text:GetText())
25 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
29 local function ContentOnEnter(this, button)
31 local text = this.text:GetText()
32 local background = self.list[text] ~= text and self.list[text] or Media:Fetch('background',text)
33 self.dropdown.bgTex:SetTexture(background)
36 local function GetContentLine()
38 if next(contentFrameCache) then
39 frame = table.remove(contentFrameCache)
41 frame = CreateFrame("Button", nil, UIParent)
44 frame:SetHighlightTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]], "ADD")
45 frame:SetScript("OnClick", ContentOnClick)
46 frame:SetScript("OnEnter", ContentOnEnter)
47 local check = frame:CreateTexture("OVERLAY")
50 check:SetPoint("LEFT",frame,"LEFT",1,-1)
51 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
54 local text = frame:CreateFontString(nil,"OVERLAY","GameFontWhite")
56 local font, size = text:GetFont()
57 text:SetFont(font,size,"OUTLINE")
59 text:SetPoint("LEFT", check, "RIGHT", 1, 0)
60 text:SetPoint("RIGHT", frame, "RIGHT", -2, 0)
61 text:SetJustifyH("LEFT")
62 text:SetText("Test Test Test Test Test Test Test")
64 frame.ReturnSelf = ReturnSelf
70 local function OnAcquire(self)
75 local function OnRelease(self)
78 self:SetDisabled(false)
85 self.frame:ClearAllPoints()
89 local function SetValue(self, value) -- Set the value to an item in the List.
91 self:SetText(value or "")
96 local function GetValue(self)
100 local function SetList(self, list) -- Set the list of values for the dropdown (key => value pairs)
101 self.list = list or Media:HashTable("background")
105 local function SetText(self, text) -- Set the text displayed in the box.
106 self.frame.text:SetText(text or "")
107 local background = self.list[text] ~= text and self.list[text] or Media:Fetch('background',text)
109 self.frame.displayButton:SetBackdrop({bgFile = background,
110 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
112 insets = { left = 4, right = 4, top = 4, bottom = 4 }})
115 local function SetLabel(self, text) -- Set the text for the label.
116 self.frame.label:SetText(text or "")
119 local function AddItem(self, key, value) -- Add an item to the list.
120 self.list = self.list or {}
121 self.list[key] = value
123 local SetItemValue = AddItem -- Set the value of a item in the list. <<same as adding a new item>>
125 local function SetMultiselect(self, flag) end -- Toggle multi-selecting. <<Dummy function to stay inline with the dropdown API>>
126 local function GetMultiselect() return false end-- Query the multi-select flag. <<Dummy function to stay inline with the dropdown API>>
127 local function SetItemDisabled(self, key) end-- Disable one item in the list. <<Dummy function to stay inline with the dropdown API>>
129 local function SetDisabled(self, disabled) -- Disable the widget.
130 self.disabled = disabled
133 self.frame.displayButton:SetBackdropColor(.2,.2,.2,1)
136 self.frame.displayButton:SetBackdropColor(1,1,1,1)
140 local function textSort(a,b)
141 return string.upper(a) < string.upper(b)
144 local sortedlist = {}
145 local function ToggleDrop(this)
146 local self = this.obj
147 if self.dropdown then
148 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
151 AceGUI:SetFocus(self)
152 self.dropdown = AGSMW:GetDropDownFrame()
153 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
154 for k, v in pairs(self.list) do
155 sortedlist[#sortedlist+1] = k
157 table.sort(sortedlist, textSort)
158 for i, k in ipairs(sortedlist) do
159 local f = GetContentLine()
162 if k == self.value then
166 f.dropdown = self.dropdown
167 self.dropdown:AddFrame(f)
173 local function ClearFocus(self)
174 if self.dropdown then
175 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
179 local function OnHide(this)
180 local self = this.obj
181 if self.dropdown then
182 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
186 local function Drop_OnEnter(this)
187 this.obj:Fire("OnEnter")
190 local function Drop_OnLeave(this)
191 this.obj:Fire("OnLeave")
194 local function Constructor()
195 local frame = AGSMW:GetBaseFrameWithWindow()
198 self.type = widgetType
201 frame.dropButton.obj = self
202 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
203 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
204 frame.dropButton:SetScript("OnClick",ToggleDrop)
205 frame:SetScript("OnHide", OnHide)
207 self.alignoffset = 31
209 self.OnRelease = OnRelease
210 self.OnAcquire = OnAcquire
211 self.ClearFocus = ClearFocus
212 self.SetText = SetText
213 self.SetValue = SetValue
214 self.GetValue = GetValue
215 self.SetList = SetList
216 self.SetLabel = SetLabel
217 self.SetDisabled = SetDisabled
218 self.AddItem = AddItem
219 self.SetMultiselect = SetMultiselect
220 self.GetMultiselect = GetMultiselect
221 self.SetItemValue = SetItemValue
222 self.SetItemDisabled = SetItemDisabled
223 self.ToggleDrop = ToggleDrop
225 AceGUI:RegisterAsWidget(self)
229 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)