1553757 - Refactor updateIndicators
[wowui.git] / libs / AceGUI-3.0-SharedMediaWidgets / prototypes.lua
1 -- Widget created by Yssaril
2 --[===[@debug@
3 local DataVersion = 9001 -- dev version always overwrites everything else :)
4 --@end-debug@]===]
5 --@non-debug@
6 local DataVersion = 37
7 --@end-non-debug@
8 local AGSMW = LibStub:NewLibrary("AceGUISharedMediaWidgets-1.0", DataVersion)
9
10 if not AGSMW then
11   return        -- already loaded and no upgrade necessary
12 end
13
14 LoadAddOn("LibSharedMedia-3.0")
15 local AceGUI = LibStub("AceGUI-3.0")
16 local Media = LibStub("LibSharedMedia-3.0")
17
18 AGSMW = AGSMW or {}
19
20 AceGUIWidgetLSMlists = {
21         ['font'] = Media:HashTable("font"),
22         ['sound'] = Media:HashTable("sound"),
23         ['statusbar'] = Media:HashTable("statusbar"),
24         ['border'] = Media:HashTable("border"),
25         ['background'] = Media:HashTable("background"),
26 }
27
28 do
29         local function disable(frame)
30                 frame.label:SetTextColor(.5,.5,.5)
31                 frame.text:SetTextColor(.5,.5,.5)
32                 frame.dropButton:Disable()
33                 if frame.displayButtonFont then
34                         frame.displayButtonFont:SetTextColor(.5,.5,.5)
35                         frame.displayButton:Disable()
36                 end
37         end
38
39         local function enable(frame)
40                 frame.label:SetTextColor(1,.82,0)
41                 frame.text:SetTextColor(1,1,1)
42                 frame.dropButton:Enable()
43                 if frame.displayButtonFont then
44                         frame.displayButtonFont:SetTextColor(1,1,1)
45                         frame.displayButton:Enable()
46                 end
47         end
48
49         local displayButtonBackdrop = {
50                 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
51                 tile = true, tileSize = 16, edgeSize = 16,
52                 insets = { left = 4, right = 4, top = 4, bottom = 4 },
53         }
54
55         -- create or retrieve BaseFrame
56         function AGSMW:GetBaseFrame()
57                 local frame = CreateFrame("Frame", nil, UIParent)
58                 frame:SetHeight(44)
59                 frame:SetWidth(200)
60                 frame:SetPoint("CENTER", UIParent, "CENTER")
61
62                 local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
63                         label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
64                         label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0)
65                         label:SetJustifyH("LEFT")
66                         label:SetHeight(18)
67                         label:SetText("")
68                 frame.label = label
69
70                 local DLeft = frame:CreateTexture(nil, "ARTWORK")
71                         DLeft:SetWidth(25)
72                         DLeft:SetHeight(64)
73                         DLeft:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", -17, -21)
74                         DLeft:SetTexture([[Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame]])
75                         DLeft:SetTexCoord(0, 0.1953125, 0, 1)
76                 frame.DLeft = DLeft
77                 local DRight = frame:CreateTexture(nil, "ARTWORK")
78                         DRight:SetWidth(25)
79                         DRight:SetHeight(64)
80                         DRight:SetPoint("TOP", DLeft, "TOP")
81                         DRight:SetPoint("RIGHT", frame, "RIGHT", 17, 0)
82                         DRight:SetTexture([[Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame]])
83                         DRight:SetTexCoord(0.8046875, 1, 0, 1)
84                 frame.DRight = DRight
85                 local DMiddle = frame:CreateTexture(nil, "ARTWORK")
86                         DMiddle:SetHeight(64)
87                         DMiddle:SetPoint("TOP", DLeft, "TOP")
88                         DMiddle:SetPoint("LEFT", DLeft, "RIGHT")
89                         DMiddle:SetPoint("RIGHT", DRight, "LEFT")
90                         DMiddle:SetTexture([[Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame]])
91                         DMiddle:SetTexCoord(0.1953125, 0.8046875, 0, 1)
92                 frame.DMiddle = DMiddle
93
94                 local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlightSmall")
95                         text:SetPoint("RIGHT",DRight,"RIGHT",-43,1)
96                         text:SetPoint("LEFT",DLeft,"LEFT",26,1)
97                         text:SetJustifyH("RIGHT")
98                         text:SetHeight(18)
99                         text:SetText("")
100                 frame.text = text
101
102                 local dropButton = CreateFrame("Button", nil, frame)
103                         dropButton:SetWidth(24)
104                         dropButton:SetHeight(24)
105                         dropButton:SetPoint("TOPRIGHT", DRight, "TOPRIGHT", -16, -18)
106                         dropButton:SetNormalTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Up]])
107                         dropButton:SetPushedTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Down]])
108                         dropButton:SetDisabledTexture([[Interface\ChatFrame\UI-ChatIcon-ScrollDown-Disabled]])
109                         dropButton:SetHighlightTexture([[Interface\Buttons\UI-Common-MouseHilight]], "ADD")
110                 frame.dropButton = dropButton
111
112                 frame.Disable = disable
113                 frame.Enable = enable
114                 return frame
115         end
116
117         function AGSMW:GetBaseFrameWithWindow()
118                 local frame = self:GetBaseFrame()
119
120                 local displayButton = CreateFrame("Button", nil, frame)
121                         displayButton:SetHeight(42)
122                         displayButton:SetWidth(42)
123                         displayButton:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -2)
124                         displayButton:SetBackdrop(displayButtonBackdrop)
125                         displayButton:SetBackdropBorderColor(.5, .5, .5)
126                 frame.displayButton = displayButton
127
128                 frame.label:SetPoint("TOPLEFT",displayButton,"TOPRIGHT",1,2)
129
130                 frame.DLeft:SetPoint("BOTTOMLEFT", displayButton, "BOTTOMRIGHT", -17, -20)
131
132                 return frame
133         end
134
135 end
136
137 do
138
139         local sliderBackdrop = {
140                 ["bgFile"] = [[Interface\Buttons\UI-SliderBar-Background]],
141                 ["edgeFile"] = [[Interface\Buttons\UI-SliderBar-Border]],
142                 ["tile"] = true,
143                 ["edgeSize"] = 8,
144                 ["tileSize"] = 8,
145                 ["insets"] = {
146                         ["left"] = 3,
147                         ["right"] = 3,
148                         ["top"] = 3,
149                         ["bottom"] = 3,
150                 },
151         }
152         local frameBackdrop = {
153                 bgFile=[[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
154                 edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]],
155                 tile = true, tileSize = 32, edgeSize = 32,
156                 insets = { left = 11, right = 12, top = 12, bottom = 9 },
157         }
158
159         local function OnMouseWheel(self, dir)
160                 self.slider:SetValue(self.slider:GetValue()+(15*dir*-1))
161         end
162
163         local function AddFrame(self, frame)
164                 frame:SetParent(self.contentframe)
165                 local strata = self:GetFrameStrata()
166                 frame:SetFrameStrata(strata)
167                 local level =  self:GetFrameLevel() + 100
168                 frame:SetFrameLevel(level)
169                 if next(self.contentRepo) then
170                         frame:SetPoint("TOPLEFT", self.contentRepo[#self.contentRepo], "BOTTOMLEFT", 0, 0)
171                         frame:SetPoint("RIGHT", self.contentframe, "RIGHT", 0, 0)
172                         self.contentframe:SetHeight(self.contentframe:GetHeight() + frame:GetHeight())
173                         self.contentRepo[#self.contentRepo+1] = frame
174                 else
175                         self.contentframe:SetHeight(frame:GetHeight())
176                         frame:SetPoint("TOPLEFT", self.contentframe, "TOPLEFT", 0, 0)
177                         frame:SetPoint("RIGHT", self.contentframe, "RIGHT", 0, 0)
178                         self.contentRepo[1] = frame
179                 end
180                 if self.contentframe:GetHeight() > UIParent:GetHeight()*2/5 - 20 then
181                         self.scrollframe:SetWidth(146)
182                         self:SetHeight(UIParent:GetHeight()*2/5)
183                         self.slider:Show()
184                         self:SetScript("OnMouseWheel", OnMouseWheel)
185                         self.scrollframe:UpdateScrollChildRect()
186                         self.slider:SetMinMaxValues(0, self.contentframe:GetHeight()-self.scrollframe:GetHeight())
187                 else
188                         self.scrollframe:SetWidth(160)
189                         self:SetHeight(self.contentframe:GetHeight()+25)
190                         self.slider:Hide()
191                         self:SetScript("OnMouseWheel", nil)
192                         self.scrollframe:UpdateScrollChildRect()
193                         self.slider:SetMinMaxValues(0, 0)
194                 end
195                 self.contentframe:SetWidth(self.scrollframe:GetWidth())
196         end
197
198         local function ClearFrames(self)
199                 for i, frame in ipairs(self.contentRepo) do
200                         frame:ReturnSelf()
201                         self.contentRepo[i] = nil
202                 end
203         end
204
205         local function slider_OnValueChanged(self, value)
206                 self.frame.scrollframe:SetVerticalScroll(value)
207         end
208
209         local DropDownCache = {}
210         function AGSMW:GetDropDownFrame()
211                 local frame
212                 if next(DropDownCache) then
213                         frame = table.remove(DropDownCache)
214                 else
215                         frame = CreateFrame("Frame", nil, UIParent)
216                                 frame:SetClampedToScreen(true)
217                                 frame:SetWidth(188)
218                                 frame:SetBackdrop(frameBackdrop)
219                                 frame:SetFrameStrata("TOOLTIP")
220                                 frame:EnableMouseWheel(true)
221
222                         local contentframe = CreateFrame("Frame", nil, frame)
223                                 contentframe:SetWidth(160)
224                                 contentframe:SetHeight(0)
225                         frame.contentframe = contentframe
226                         local scrollframe = CreateFrame("ScrollFrame", nil, frame)
227                                 scrollframe:SetPoint("TOPLEFT", frame, "TOPLEFT", 14, -13)
228                                 scrollframe:SetPoint("BOTTOM", frame, "BOTTOM", 0, 12)
229                                 scrollframe:SetWidth(160)
230                                 scrollframe:SetScrollChild(contentframe)
231                         frame.scrollframe = scrollframe
232                         local bgTex = frame:CreateTexture(nil, "ARTWORK")
233                                 bgTex:SetAllPoints(scrollframe)
234                         frame.bgTex = bgTex
235
236                         frame.AddFrame = AddFrame
237                         frame.ClearFrames = ClearFrames
238                         frame.contentRepo = {} -- store all our frames in here so we can get rid of them later
239                         local slider = CreateFrame("Slider", nil, scrollframe)
240                                 slider:SetOrientation("VERTICAL")
241                                 slider:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -14, -10)
242                                 slider:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -14, 10)
243                                 slider:SetBackdrop(sliderBackdrop)
244                                 slider:SetThumbTexture([[Interface\Buttons\UI-SliderBar-Button-Vertical]])
245                                 slider:SetMinMaxValues(0, 1)
246                                 --slider:SetValueStep(1)
247                                 slider:SetWidth(12)
248                                 slider.frame = frame
249                                 slider:SetScript("OnValueChanged", slider_OnValueChanged)
250                         frame.slider = slider
251                 end
252                 frame:SetHeight(UIParent:GetHeight()*2/5)
253                 frame.slider:SetValue(0)
254                 frame:Show()
255                 return frame
256         end
257
258         function AGSMW:ReturnDropDownFrame(frame)
259                 ClearFrames(frame)
260                 frame:ClearAllPoints()
261                 frame:Hide()
262                 frame:SetBackdrop(frameBackdrop)
263                 frame.bgTex:SetTexture(nil)
264                 table.insert(DropDownCache, frame)
265                 return nil
266         end
267 end