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_Sound"
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 ContentSpeakerOnClick(this, button)
30 local self = this.frame.obj
31 local sound = this.frame.text:GetText()
32 PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound))
35 local function GetContentLine()
37 if next(contentFrameCache) then
38 frame = table.remove(contentFrameCache)
40 frame = CreateFrame("Button", nil, UIParent)
43 frame:SetHighlightTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]], "ADD")
44 frame:SetScript("OnClick", ContentOnClick)
45 local check = frame:CreateTexture("OVERLAY")
48 check:SetPoint("LEFT",frame,"LEFT",1,-1)
49 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
53 local soundbutton = CreateFrame("Button", nil, frame)
54 soundbutton:SetWidth(16)
55 soundbutton:SetHeight(16)
56 soundbutton:SetPoint("RIGHT",frame,"RIGHT",-1,0)
57 soundbutton.frame = frame
58 soundbutton:SetScript("OnClick", ContentSpeakerOnClick)
59 frame.soundbutton = soundbutton
61 local speaker = soundbutton:CreateTexture(nil, "BACKGROUND")
62 speaker:SetTexture("Interface\\Common\\VoiceChat-Speaker")
63 speaker:SetAllPoints(soundbutton)
64 frame.speaker = speaker
65 local speakeron = soundbutton:CreateTexture(nil, "HIGHLIGHT")
66 speakeron:SetTexture("Interface\\Common\\VoiceChat-On")
67 speakeron:SetAllPoints(soundbutton)
68 frame.speakeron = speakeron
70 local text = frame:CreateFontString(nil,"OVERLAY","GameFontWhite")
71 text:SetPoint("LEFT", check, "RIGHT", 1, 0)
72 text:SetPoint("RIGHT", soundbutton, "LEFT", -2, 0)
73 text:SetJustifyH("LEFT")
74 text:SetText("Test Test Test Test Test Test Test")
76 frame.ReturnSelf = ReturnSelf
82 local function OnAcquire(self)
87 local function OnRelease(self)
90 self:SetDisabled(false)
97 self.frame:ClearAllPoints()
101 local function SetValue(self, value) -- Set the value to an item in the List.
103 self:SetText(value or "")
108 local function GetValue(self)
112 local function SetList(self, list) -- Set the list of values for the dropdown (key => value pairs)
113 self.list = list or Media:HashTable("sound")
116 local function SetText(self, text) -- Set the text displayed in the box.
117 self.frame.text:SetText(text or "")
120 local function SetLabel(self, text) -- Set the text for the label.
121 self.frame.label:SetText(text or "")
124 local function AddItem(self, key, value) -- Add an item to the list.
125 self.list = self.list or {}
126 self.list[key] = value
128 local SetItemValue = AddItem -- Set the value of a item in the list. <<same as adding a new item>>
130 local function SetMultiselect(self, flag) end -- Toggle multi-selecting. <<Dummy function to stay inline with the dropdown API>>
131 local function GetMultiselect() return false end-- Query the multi-select flag. <<Dummy function to stay inline with the dropdown API>>
132 local function SetItemDisabled(self, key) end-- Disable one item in the list. <<Dummy function to stay inline with the dropdown API>>
134 local function SetDisabled(self, disabled) -- Disable the widget.
135 self.disabled = disabled
138 self.speaker:SetDesaturated(true)
139 self.speakeron:SetDesaturated(true)
142 self.speaker:SetDesaturated(false)
143 self.speakeron:SetDesaturated(false)
147 local function textSort(a,b)
148 return string.upper(a) < string.upper(b)
151 local sortedlist = {}
152 local function ToggleDrop(this)
153 local self = this.obj
154 if self.dropdown then
155 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
158 AceGUI:SetFocus(self)
159 self.dropdown = AGSMW:GetDropDownFrame()
160 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
161 for k, v in pairs(self.list) do
162 sortedlist[#sortedlist+1] = k
164 table.sort(sortedlist, textSort)
165 for i, k in ipairs(sortedlist) do
166 local f = GetContentLine()
168 if k == self.value then
172 self.dropdown:AddFrame(f)
178 local function ClearFocus(self)
179 if self.dropdown then
180 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
184 local function OnHide(this)
185 local self = this.obj
186 if self.dropdown then
187 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
191 local function Drop_OnEnter(this)
192 this.obj:Fire("OnEnter")
195 local function Drop_OnLeave(this)
196 this.obj:Fire("OnLeave")
199 local function WidgetPlaySound(this)
200 local self = this.obj
201 local sound = self.frame.text:GetText()
202 PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound))
205 local function Constructor()
206 local frame = AGSMW:GetBaseFrame()
209 self.type = widgetType
212 frame.dropButton.obj = self
213 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
214 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
215 frame.dropButton:SetScript("OnClick",ToggleDrop)
216 frame:SetScript("OnHide", OnHide)
219 local soundbutton = CreateFrame("Button", nil, frame)
220 soundbutton:SetWidth(16)
221 soundbutton:SetHeight(16)
222 soundbutton:SetPoint("LEFT",frame.DLeft,"LEFT",26,1)
223 soundbutton:SetScript("OnClick", WidgetPlaySound)
224 soundbutton.obj = self
225 self.soundbutton = soundbutton
226 frame.text:SetPoint("LEFT",soundbutton,"RIGHT",2,0)
229 local speaker = soundbutton:CreateTexture(nil, "BACKGROUND")
230 speaker:SetTexture("Interface\\Common\\VoiceChat-Speaker")
231 speaker:SetAllPoints(soundbutton)
232 self.speaker = speaker
233 local speakeron = soundbutton:CreateTexture(nil, "HIGHLIGHT")
234 speakeron:SetTexture("Interface\\Common\\VoiceChat-On")
235 speakeron:SetAllPoints(soundbutton)
236 self.speakeron = speakeron
238 self.alignoffset = 31
240 self.OnRelease = OnRelease
241 self.OnAcquire = OnAcquire
242 self.ClearFocus = ClearFocus
243 self.SetText = SetText
244 self.SetValue = SetValue
245 self.GetValue = GetValue
246 self.SetList = SetList
247 self.SetLabel = SetLabel
248 self.SetDisabled = SetDisabled
249 self.AddItem = AddItem
250 self.SetMultiselect = SetMultiselect
251 self.GetMultiselect = GetMultiselect
252 self.SetItemValue = SetItemValue
253 self.SetItemDisabled = SetItemDisabled
254 self.ToggleDrop = ToggleDrop
256 AceGUI:RegisterAsWidget(self)
260 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)