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_Statusbar"
11 local widgetVersion = 11
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 GetContentLine()
31 if next(contentFrameCache) then
32 frame = table.remove(contentFrameCache)
34 frame = CreateFrame("Button", nil, UIParent)
37 frame:SetHighlightTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]], "ADD")
38 frame:SetScript("OnClick", ContentOnClick)
39 local check = frame:CreateTexture("OVERLAY")
42 check:SetPoint("LEFT",frame,"LEFT",1,-1)
43 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
46 local bar = frame:CreateTexture("ARTWORK")
48 bar:SetPoint("LEFT",check,"RIGHT",1,0)
49 bar:SetPoint("RIGHT",frame,"RIGHT",-1,0)
51 local text = frame:CreateFontString(nil,"OVERLAY","GameFontWhite")
53 local font, size = text:GetFont()
54 text:SetFont(font,size,"OUTLINE")
56 text:SetPoint("TOPLEFT", check, "TOPRIGHT", 3, 0)
57 text:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 0)
58 text:SetJustifyH("LEFT")
59 text:SetText("Test Test Test Test Test Test Test")
61 frame.ReturnSelf = ReturnSelf
67 local function OnAcquire(self)
72 local function OnRelease(self)
75 self:SetDisabled(false)
82 self.frame:ClearAllPoints()
86 local function SetValue(self, value) -- Set the value to an item in the List.
88 self:SetText(value or "")
93 local function GetValue(self)
97 local function SetList(self, list) -- Set the list of values for the dropdown (key => value pairs)
98 self.list = list or Media:HashTable("statusbar")
102 local function SetText(self, text) -- Set the text displayed in the box.
103 self.frame.text:SetText(text or "")
104 local statusbar = self.list[text] ~= text and self.list[text] or Media:Fetch('statusbar',text)
105 self.bar:SetTexture(statusbar)
108 local function SetLabel(self, text) -- Set the text for the label.
109 self.frame.label:SetText(text or "")
112 local function AddItem(self, key, value) -- Add an item to the list.
113 self.list = self.list or {}
114 self.list[key] = value
116 local SetItemValue = AddItem -- Set the value of a item in the list. <<same as adding a new item>>
118 local function SetMultiselect(self, flag) end -- Toggle multi-selecting. <<Dummy function to stay inline with the dropdown API>>
119 local function GetMultiselect() return false end-- Query the multi-select flag. <<Dummy function to stay inline with the dropdown API>>
120 local function SetItemDisabled(self, key) end-- Disable one item in the list. <<Dummy function to stay inline with the dropdown API>>
122 local function SetDisabled(self, disabled) -- Disable the widget.
123 self.disabled = disabled
131 local function textSort(a,b)
132 return string.upper(a) < string.upper(b)
135 local sortedlist = {}
136 local function ToggleDrop(this)
137 local self = this.obj
138 if self.dropdown then
139 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
142 AceGUI:SetFocus(self)
143 self.dropdown = AGSMW:GetDropDownFrame()
144 local width = self.frame:GetWidth()
145 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
146 self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
147 for k, v in pairs(self.list) do
148 sortedlist[#sortedlist+1] = k
150 table.sort(sortedlist, textSort)
151 for i, k in ipairs(sortedlist) do
152 local f = GetContentLine()
155 if k == self.value then
159 local statusbar = self.list[k] ~= k and self.list[k] or Media:Fetch('statusbar',k)
160 f.bar:SetTexture(statusbar)
162 f.dropdown = self.dropdown
163 self.dropdown:AddFrame(f)
169 local function ClearFocus(self)
170 if self.dropdown then
171 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
175 local function OnHide(this)
176 local self = this.obj
177 if self.dropdown then
178 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
182 local function Drop_OnEnter(this)
183 this.obj:Fire("OnEnter")
186 local function Drop_OnLeave(this)
187 this.obj:Fire("OnLeave")
190 local function Constructor()
191 local frame = AGSMW:GetBaseFrame()
194 self.type = widgetType
197 frame.dropButton.obj = self
198 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
199 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
200 frame.dropButton:SetScript("OnClick",ToggleDrop)
201 frame:SetScript("OnHide", OnHide)
203 local bar = frame:CreateTexture(nil, "OVERLAY")
204 bar:SetPoint("TOPLEFT", frame,"TOPLEFT",6,-25)
205 bar:SetPoint("BOTTOMRIGHT", frame,"BOTTOMRIGHT", -21, 5)
209 self.alignoffset = 31
211 self.OnRelease = OnRelease
212 self.OnAcquire = OnAcquire
213 self.ClearFocus = ClearFocus
214 self.SetText = SetText
215 self.SetValue = SetValue
216 self.GetValue = GetValue
217 self.SetList = SetList
218 self.SetLabel = SetLabel
219 self.SetDisabled = SetDisabled
220 self.AddItem = AddItem
221 self.SetMultiselect = SetMultiselect
222 self.GetMultiselect = GetMultiselect
223 self.SetItemValue = SetItemValue
224 self.SetItemDisabled = SetItemDisabled
225 self.ToggleDrop = ToggleDrop
227 AceGUI:RegisterAsWidget(self)
231 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)