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 = 10
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)
48 local check = frame:CreateTexture("OVERLAY")
51 check:SetPoint("LEFT",frame,"LEFT",1,-1)
52 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
56 local text = frame:CreateFontString(nil,"OVERLAY","GameFontWhite")
57 local font, size = text:GetFont()
58 text:SetFont(font,size,"OUTLINE")
60 text:SetPoint("LEFT", check, "RIGHT", 1, 0)
61 text:SetPoint("RIGHT", frame, "RIGHT", -2, 0)
62 text:SetJustifyH("LEFT")
63 text:SetText("Test Test Test Test Test Test Test")
66 frame.ReturnSelf = ReturnSelf
72 local function OnAcquire(self)
77 local function OnRelease(self)
80 self:SetDisabled(false)
87 self.frame:ClearAllPoints()
91 local function SetValue(self, value) -- Set the value to an item in the List.
93 self:SetText(value or "")
98 local function GetValue(self)
102 local function SetList(self, list) -- Set the list of values for the dropdown (key => value pairs)
103 self.list = list or Media:HashTable("background")
107 local function SetText(self, text) -- Set the text displayed in the box.
108 self.frame.text:SetText(text or "")
109 local background = self.list[text] ~= text and self.list[text] or Media:Fetch('background',text)
111 self.frame.displayButton:SetBackdrop({bgFile = background,
112 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
114 insets = { left = 4, right = 4, top = 4, bottom = 4 }})
117 local function SetLabel(self, text) -- Set the text for the label.
118 self.frame.label:SetText(text or "")
121 local function AddItem(self, key, value) -- Add an item to the list.
122 self.list = self.list or {}
123 self.list[key] = value
125 local SetItemValue = AddItem -- Set the value of a item in the list. <<same as adding a new item>>
127 local function SetMultiselect(self, flag) end -- Toggle multi-selecting. <<Dummy function to stay inline with the dropdown API>>
128 local function GetMultiselect() return false end-- Query the multi-select flag. <<Dummy function to stay inline with the dropdown API>>
129 local function SetItemDisabled(self, key) end-- Disable one item in the list. <<Dummy function to stay inline with the dropdown API>>
131 local function SetDisabled(self, disabled) -- Disable the widget.
132 self.disabled = disabled
135 self.frame.displayButton:SetBackdropColor(.2,.2,.2,1)
138 self.frame.displayButton:SetBackdropColor(1,1,1,1)
142 local function textSort(a,b)
143 return string.upper(a) < string.upper(b)
146 local sortedlist = {}
147 local function ToggleDrop(this)
148 local self = this.obj
149 if self.dropdown then
150 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
153 AceGUI:SetFocus(self)
154 self.dropdown = AGSMW:GetDropDownFrame()
155 local width = self.frame:GetWidth()
156 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
157 self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
158 for k, v in pairs(self.list) do
159 sortedlist[#sortedlist+1] = k
161 table.sort(sortedlist, textSort)
162 for i, k in ipairs(sortedlist) do
163 local f = GetContentLine()
166 if k == self.value then
170 f.dropdown = self.dropdown
171 self.dropdown:AddFrame(f)
177 local function ClearFocus(self)
178 if self.dropdown then
179 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
183 local function OnHide(this)
184 local self = this.obj
185 if self.dropdown then
186 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
190 local function Drop_OnEnter(this)
191 this.obj:Fire("OnEnter")
194 local function Drop_OnLeave(this)
195 this.obj:Fire("OnLeave")
198 local function Constructor()
199 local frame = AGSMW:GetBaseFrameWithWindow()
202 self.type = widgetType
205 frame.dropButton.obj = self
206 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
207 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
208 frame.dropButton:SetScript("OnClick",ToggleDrop)
209 frame:SetScript("OnHide", OnHide)
211 self.alignoffset = 31
213 self.OnRelease = OnRelease
214 self.OnAcquire = OnAcquire
215 self.ClearFocus = ClearFocus
216 self.SetText = SetText
217 self.SetValue = SetValue
218 self.GetValue = GetValue
219 self.SetList = SetList
220 self.SetLabel = SetLabel
221 self.SetDisabled = SetDisabled
222 self.AddItem = AddItem
223 self.SetMultiselect = SetMultiselect
224 self.GetMultiselect = GetMultiselect
225 self.SetItemValue = SetItemValue
226 self.SetItemDisabled = SetItemDisabled
227 self.ToggleDrop = ToggleDrop
229 AceGUI:RegisterAsWidget(self)
233 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)