fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosFixed music probability screen erroringa8c6765

v2.1.5
9.6 KiB338 linesraw
1local PANEL = class.create("MusicFileSlider", "Panel")
2
3PANEL:ACCESSOR("FilePath", "m_strFilePath", "")
4
5function PANEL:MusicFileSlider()
6	self:super()
7
8	self:SetHeight(56)
9
10	self.m_pSlider = self:Add("SliderPanel")
11	self.m_pSlider:Dock(DOCK_RIGHT)
12	self.m_pSlider:SetWidth(128)
13	self.m_pSlider:SetNeedsFocus(true)
14
15	self.m_pFileName = self:Add("LabelIcon")
16	self.m_pFileName:Dock(DOCK_FILL)
17	self.m_pFileName:SetTextAlignmentX("left")
18	self.m_pFileName:SetTextAlignmentY("center")
19	self.m_pFileName:SetImage("textures/gui/page.png")
20	self.m_pFileName:SetWrapped(true)
21	self.m_pFileName:TextMargin(28, 7, 4, 4)
22
23	self:InheritMethods(self.m_pSlider)
24	self:SetTextFormat("%d%%")
25end
26
27function PANEL:SetValue(value)
28	self.m_pSlider:SetValue(value)
29end
30
31function PANEL:GetValue()
32	return self.m_pSlider:GetValue()
33end
34
35function PANEL:SetFileName(str)
36	self.m_pFileName:SetText(str)
37end
38
39function PANEL:GetFileName()
40	return self.m_pFileName:GetText()
41end
42
43local PANEL = class.create("MusicDirectory", "Panel")
44
45function PANEL:MusicDirectory()
46	self:super()
47
48	self.m_pDirectoryLabel = self:Add("ButtonIcon")
49	self.m_pDirectoryLabel:SetFocusable(true)
50	self.m_pDirectoryLabel:Dock(DOCK_TOP)
51	self.m_pDirectoryLabel:SetTextAlignmentX("left")
52	self.m_pDirectoryLabel:SetImage("textures/gui/folder_link.png")
53
54	function self.m_pDirectoryLabel:OnClick()
55		love.system.openURL(("file://%s/%s"):format(love.filesystem.getSaveDirectory(), self:GetText()))
56	end
57
58	self.m_pFiles = self:Add("Panel")
59	self.m_pFiles:Dock(DOCK_FILL)
60	self.m_pFiles:DockPadding(0,0,0,0)
61	self.m_pFiles:DockMargin(0,0,0,0)
62	self.m_pFiles:SetDrawPanel(false)
63end
64
65function PANEL:SetPath(str)
66	self.m_pDirectoryLabel:SetText(str)
67end
68
69function PANEL:AddFile(name)
70	local file = self.m_pFiles:Add("MusicFileSlider")
71	file:Dock(DOCK_TOP)
72	file:SetFileName(name)
73	return file
74end
75
76function PANEL:GetFiles()
77	return self.m_pFiles:GetChildren()
78end
79
80function PANEL:PerformLayout()
81	self.m_pFiles:SizeToChildren(false, true)
82	self:SizeToChildren(false, true)
83end
84
85function PANEL:Search(text)
86	local numVis = 0
87	for k, child in ipairs(self.m_pFiles:GetChildren()) do
88		local vis = string.find(child:GetFileName():lower(), text:lower(), 1, true) ~= nil
89		if vis then numVis = numVis + 1 end
90		child:SetVisible(vis)
91	end
92	self:SetVisible(numVis > 0)
93end
94
95local PANEL = class.create("MusicProbability", "Panel")
96
97local music = require("music")
98
99local MODE_GLOBAL = 0
100local MODE_STATE = 1
101
102function PANEL:UpdatePlaylist()
103	local mode = self.PROBMODE:GetOption()
104	local playlistTree = music.getPlaylistTree()
105
106	self.PLAYLIST:Clear()
107
108	for folder, entries in pairs(playlistTree) do
109		local directory = self.PLAYLIST:Add("MusicDirectory")
110		directory:Dock(DOCK_TOP)
111		directory:SetPath(folder)
112
113		for k, entry in ipairs(entries) do
114			local file = directory:AddFile(entry.FILENAME)
115			local path = entry.FILEPATH
116
117			file:SetFilePath(path)
118
119			self.m_tblStateValues[MODE_GLOBAL][path] = music.getGlobalFileProbability(path)
120			self.m_tblStateValues[MODE_STATE][path] = music.getStateFileProbability(path)
121
122			file:SetValue(self.m_tblStateValues[mode][path])
123		end
124	end
125end
126
127function PANEL:GetTableValues()
128	local tbl = {}
129	for k, directory in ipairs(self.PLAYLIST:GetCanvas():GetChildren()) do
130		for k, file in ipairs(directory:GetFiles()) do
131			tbl[file:GetFilePath()] = file:GetValue()
132		end
133	end
134	return tbl
135end
136
137function PANEL:SetTableValues(tbl)
138	for k, directory in ipairs(self.PLAYLIST:GetCanvas():GetChildren()) do
139		for k, file in ipairs(directory:GetFiles()) do
140			local path = file:GetFilePath()
141			if tbl[path] then
142				file:SetValue(tbl[path])
143			end
144		end
145	end
146end
147
148function PANEL:ResetAll(mode)
149	for k, directory in ipairs(self.PLAYLIST:GetCanvas():GetChildren()) do
150		for k, file in ipairs(directory:GetFiles()) do
151			if file:IsVisible() then
152				local path = file:GetFilePath()
153
154				local value
155
156				if mode == MODE_GLOBAL then
157					value = music.getGlobalFileProbability(path)
158				else
159					value = music.getStateFileProbability(path)
160				end
161
162				file:SetValue(value)
163			end
164		end
165	end
166end
167
168function PANEL:SetAllValue(value)
169	for k, directory in ipairs(self.PLAYLIST:GetCanvas():GetChildren()) do
170		for k, file in ipairs(directory:GetFiles()) do
171			if file:IsVisible() then
172				file:SetValue(value)
173			end
174		end
175	end
176end
177
178function PANEL:MusicProbability()
179	self:super()
180
181	self.TOPBAR = self:Add("Panel")
182	self.TOPBAR:Dock(DOCK_TOP)
183	self.TOPBAR:SetHeight(28)
184	self.TOPBAR:DockPadding(0,0,0,0)
185	self.TOPBAR:DockMargin(0,0,0,0)
186	self.TOPBAR:SetBorderColor(color_blank)
187
188	self.SEARCH = self.TOPBAR:Add("TextEntry")
189	self.SEARCH:Dock(DOCK_FILL)
190	self.SEARCH:SetTextHint("Search..")
191
192	self.SEARCH.OnTextChanged = function(this, text, add)
193		self.PLAYLIST:SetScroll(0)
194		for k, child in ipairs(self.PLAYLIST:GetCanvas():GetChildren()) do
195			child:Search(text)
196		end
197		return true
198	end
199
200	self.m_tblStateValues = {
201		[MODE_GLOBAL] = {},
202		[MODE_STATE] = {},
203	}
204
205	self.REFRESH = self.TOPBAR:Add("ButtonIcon")
206	self.REFRESH:SetImage("textures/gui/arrow_refresh.png")
207	self.REFRESH:Dock(DOCK_RIGHT)
208	self.REFRESH:SetText("Refresh")
209	self.REFRESH:SetWidth(24)
210	self.REFRESH:SetTooltipTitle("REFRESH")
211	self.REFRESH:SetTooltipBody([[This button will refetch all the songs for the given state of the game.
212
213NOTE: If you are on the menus, pressing this button will display all songs that can play on the menu. If you are on a stage, it will display all songs that can play when on that stage.]])
214
215	self.PROBMODE = self.TOPBAR:Add("RadioPanel")
216	self.PROBMODE:SetHorizontal(true)
217	self.PROBMODE:SetDrawPanel(false)
218	self.PROBMODE:SetDrawLabel(false)
219	self.PROBMODE:Dock(DOCK_RIGHT)
220	self.PROBMODE:DockMargin(0, 0, 0, 0)
221	self.PROBMODE:DockPadding(0, 0, 0, 0)
222
223	local global = self.PROBMODE:AddOption(MODE_GLOBAL, "Global", true)
224	global:SetWidth(70)
225	global:SetTooltipParent(self.PROBMODE)
226	global:SetTooltipTitle("GLOBAL PROBABILITY")
227	global:SetTooltipBody([[When in global mode, you can adjust the probability the given song will play at a global level. This will apply across all possible game states.
228
229NOTE: A song that has been adjusted in "state" mode will override the probability of its "global" mode value.]])
230
231	local state = self.PROBMODE:AddOption(MODE_STATE, "State")
232	state:SetWidth(66)
233	state:SetTooltipParent(self.PROBMODE)
234	state:SetTooltipTitle("STATE PROBABILITY")
235	state:SetTooltipBody([[When in state mode, you can adjust the probability the given song will play during the currently active state.
236
237NOTE: A "state" refers to the state of the game, such as being on the menus, or within a stage. Each stage is considered its own "state" and will allow you to fine-tune the probability of a single song across multiple states.]])
238
239	self.PROBMODE.OnSelectOption = function(this, mode, previous)
240		self.m_tblStateValues[previous] = self:GetTableValues()
241		self:SetTableValues(self.m_tblStateValues[mode])
242	end
243
244	self.REFRESH.OnClick = function(this)
245		self:UpdatePlaylist()
246	end
247
248	self.PLAYLIST = self:Add("ScrollPanel")
249	self.PLAYLIST:Dock(DOCK_FILL)
250	self.PLAYLIST:DockPadding(0,0,0,0)
251
252	self.OPTIONS = self:Add("Panel")
253	self.OPTIONS:Dock(DOCK_BOTTOM)
254	self.OPTIONS:SetHeight(28)
255	self.OPTIONS:DockPadding(0,0,0,0)
256	self.OPTIONS:DockMargin(0,0,0,0)
257	self.OPTIONS:SetBorderColor(color_blank)
258
259	self.ZERO = self.OPTIONS:Add("ButtonIcon")
260	self.ZERO:SetImage("textures/gui/bullet_arrow_down.png")
261	self.ZERO:TextMargin(24, 0, 0, 0)
262	self.ZERO:Dock(DOCK_LEFT)
263	self.ZERO:SetText("Zero")
264	self.ZERO:SetWidth(24)
265	self.ZERO:SetTooltipTitle("ZERO")
266	self.ZERO:SetTooltipBody([[Sets all songs on this playlist to have 0% chance of playing.]])
267
268	self.ZERO.OnClick = function(this)
269		self:SetAllValue(0)
270	end
271
272	self.MID = self.OPTIONS:Add("ButtonIcon")
273	self.MID:SetImage("textures/gui/bullet_arrow_center.png")
274	self.MID:TextMargin(24, 0, 0, 0)
275	self.MID:Dock(DOCK_LEFT)
276	self.MID:SetText("Center")
277	self.MID:SetWidth(24)
278	self.MID:SetTooltipTitle("CENTER")
279	self.MID:SetTooltipBody([[Sets all songs on this playlist to have 50% chance of playing.]])
280
281	self.MID.OnClick = function(this)
282		self:SetAllValue(50)
283	end
284
285	self.MAX = self.OPTIONS:Add("ButtonIcon")
286	self.MAX:SetImage("textures/gui/bullet_arrow_up.png")
287	self.MAX:TextMargin(24, 0, 0, 0)
288	self.MAX:Dock(DOCK_LEFT)
289	self.MAX:SetText("Max")
290	self.MAX:SetWidth(24)
291	self.MAX:SetTooltipTitle("MAX")
292	self.MAX:SetTooltipBody([[Sets all songs on this playlist to have 100% chance of playing.]])
293
294	self.MAX.OnClick = function(this)
295		self:SetAllValue(100)
296	end
297
298	self.RESET = self.OPTIONS:Add("ButtonIcon")
299	self.RESET:SetImage("textures/gui/arrow_undo.png")
300	self.RESET:TextMargin(24, 0, 0, 0)
301	self.RESET:Dock(DOCK_LEFT)
302	self.RESET:SetText("Reset")
303	self.RESET:SetWidth(24)
304	self.RESET:SetTooltipTitle("RESET")
305	self.RESET:SetTooltipBody([[Sets all songs on this playlist to their previously known value.]])
306
307	self.RESET.OnClick = function(this)
308		self:ResetAll(self.PROBMODE:GetOption())
309	end
310
311	self.OKAY = self.OPTIONS:Add("ButtonIcon")
312	self.OKAY:SetImage("textures/gui/disk.png")
313	self.OKAY:Dock(DOCK_RIGHT)
314	self.OKAY:SetText("Save")
315	self.OKAY:SetWidth(64)
316	self.OKAY:SetTooltipTitle("SAVE")
317	self.OKAY:SetTooltipBody([[Save all changes to disk and exit.]])
318
319	self.OKAY.OnClick = function(this)
320		self:SetVisible(false)
321		self.m_tblStateValues[self.PROBMODE:GetOption()] = self:GetTableValues()
322		music.updateGlobalProbabilities(self.m_tblStateValues[MODE_GLOBAL])
323		music.updateStateProbabilities(self.m_tblStateValues[MODE_STATE])
324		music.saveProbabilities()
325	end
326
327	self.CANCEL = self.OPTIONS:Add("ButtonIcon")
328	self.CANCEL:SetImage("textures/gui/cancel.png")
329	self.CANCEL:Dock(DOCK_RIGHT)
330	self.CANCEL:SetText("Cancel")
331	self.CANCEL:SetWidth(76)
332	self.CANCEL:SetTooltipTitle("CANCEL")
333	self.CANCEL:SetTooltipBody([[Disregard any changes made and exit.]])
334
335	self.CANCEL.OnClick = function(this)
336		self:SetVisible(false)
337	end
338end