aboutsummaryrefslogtreecommitdiffstats
path: root/Menu.lua
blob: e75fa019d0fc93c7a81e72106232c29cbb46f3b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local Menu = {}

function loadSongs()
	local songs = {}
	for _,song in pairs(Files.findSongs(nil, nil)) do
	   	table.insert(songs, Files.getSMInfo(song))
	end
	table.sort(songs, Utils.sortByArtistAndTitle)
	return songs
end

function Menu:init()
	self.songs = loadSongs()
	self.pageNumber = 0
end

function Menu:update(dt)	
	Gui.group{grow = "down", pos = {Utils.percentCoordinates(10, 10)}, function()
		for id = (self.pageNumber*Config.songsPerPages)+1, (self.pageNumber*Config.songsPerPages)+Config.songsPerPages do
			local smInfo = self.songs[id]
			if smInfo and smInfo.title then
				if Gui.Button{text = string.format("%s — %s", smInfo.artist, smInfo.title), size = {Utils.percentCoordinates(80, 80/Config.songsPerPages)}} then
					Gamestate.switch(Menu.selectDifficulty, self.songs[id])
				end
			end
		end
	end}

	if self.pageNumber > 0 and Gui.Button{text = "<", pos = {Utils.percentCoordinates(2, 50)}, size = {Utils.percentCoordinates(5, 5)}} then
		self.pageNumber = self.pageNumber - 1
	end

	if self.pageNumber+1 < #self.songs/Config.songsPerPages and Gui.Button{text = ">", pos = {Utils.percentCoordinates(93, 50)}, size = {Utils.percentCoordinates(5, 5)}} then
		self.pageNumber = self.pageNumber + 1
	end
end

Menu.selectDifficulty = {}

function Menu.selectDifficulty:init()
	self.pageNumber = 0
end

function Menu.selectDifficulty:enter(previous, song)
	self.song = Files.readNotesInfos(song)
end

function Menu.selectDifficulty:update()
	Gui.group{grow = "down", pos = {Utils.percentCoordinates(10, 10)}, function()
		for id = (self.pageNumber*Config.songsPerPages)+1, (self.pageNumber*Config.songsPerPages)+Config.songsPerPages do
			local level = self.song["notes"][id]
			if level and level[SMFileSchema.NotesInfos.description][2] then
				if Gui.Button{text = string.format("%s — %s", level[SMFileSchema.NotesInfos.description][2], level[SMFileSchema.NotesInfos.difficultyClass][2]), size = {Utils.percentCoordinates(80, 80/Config.songsPerPages)}} then
					Gamestate.switch(Game, self.song, id)
				end
			end
		end
	end}
	if Gui.Button{text = "<-", pos = {Utils.percentCoordinates(50, 93)}, size = {Utils.percentCoordinates(5, 5)}} then
		Gamestate.switch(Menu)
	end
end

return Menu