aboutsummaryrefslogtreecommitdiffstats
path: root/Menu.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Menu.lua')
-rwxr-xr-xMenu.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/Menu.lua b/Menu.lua
new file mode 100755
index 0000000..e75fa01
--- /dev/null
+++ b/Menu.lua
@@ -0,0 +1,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