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 = 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 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), "Master")
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 local width = self.frame:GetWidth()
161 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
162 self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
163 for k, v in pairs(self.list) do
164 sortedlist[#sortedlist+1] = k
166 table.sort(sortedlist, textSort)
167 for i, k in ipairs(sortedlist) do
168 local f = GetContentLine()
170 if k == self.value then
174 self.dropdown:AddFrame(f)
180 local function ClearFocus(self)
181 if self.dropdown then
182 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
186 local function OnHide(this)
187 local self = this.obj
188 if self.dropdown then
189 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
193 local function Drop_OnEnter(this)
194 this.obj:Fire("OnEnter")
197 local function Drop_OnLeave(this)
198 this.obj:Fire("OnLeave")
201 local function WidgetPlaySound(this)
202 local self = this.obj
203 local sound = self.frame.text:GetText()
204 PlaySoundFile(self.list[sound] ~= sound and self.list[sound] or Media:Fetch('sound',sound), "Master")
207 local function Constructor()
208 local frame = AGSMW:GetBaseFrame()
211 self.type = widgetType
214 frame.dropButton.obj = self
215 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
216 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
217 frame.dropButton:SetScript("OnClick",ToggleDrop)
218 frame:SetScript("OnHide", OnHide)
221 local soundbutton = CreateFrame("Button", nil, frame)
222 soundbutton:SetWidth(16)
223 soundbutton:SetHeight(16)
224 soundbutton:SetPoint("LEFT",frame.DLeft,"LEFT",26,1)
225 soundbutton:SetScript("OnClick", WidgetPlaySound)
226 soundbutton.obj = self
227 self.soundbutton = soundbutton
228 frame.text:SetPoint("LEFT",soundbutton,"RIGHT",2,0)
231 local speaker = soundbutton:CreateTexture(nil, "BACKGROUND")
232 speaker:SetTexture("Interface\\Common\\VoiceChat-Speaker")
233 speaker:SetAllPoints(soundbutton)
234 self.speaker = speaker
235 local speakeron = soundbutton:CreateTexture(nil, "HIGHLIGHT")
236 speakeron:SetTexture("Interface\\Common\\VoiceChat-On")
237 speakeron:SetAllPoints(soundbutton)
238 self.speakeron = speakeron
240 self.alignoffset = 31
242 self.OnRelease = OnRelease
243 self.OnAcquire = OnAcquire
244 self.ClearFocus = ClearFocus
245 self.SetText = SetText
246 self.SetValue = SetValue
247 self.GetValue = GetValue
248 self.SetList = SetList
249 self.SetLabel = SetLabel
250 self.SetDisabled = SetDisabled
251 self.AddItem = AddItem
252 self.SetMultiselect = SetMultiselect
253 self.GetMultiselect = GetMultiselect
254 self.SetItemValue = SetItemValue
255 self.SetItemDisabled = SetItemDisabled
256 self.ToggleDrop = ToggleDrop
258 AceGUI:RegisterAsWidget(self)
262 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)