chore: port the main menu to the new system

This commit is contained in:
Kazhnuz 2020-12-05 09:02:42 +01:00
parent abfda56b14
commit 93bbf56047

View file

@ -40,22 +40,25 @@ function MainMenu:new()
local name = i .. "player" local name = i .. "player"
self:addSubMenu(name, name) self:addSubMenu(name, name)
if i == 1 then if i == 1 then
self:addScene(name, scenes.Plateformer, "plateform", i) self:addScene(scenes.Plateformer, "plateform", i)
end end
self:addScene(name, scenes.MovePlayer, "topdown", i) self:addScene(scenes.MovePlayer, "topdown", i)
self:addScene(name, scenes.MovePlayer3D, "topdown3D", i) self:addScene(scenes.MovePlayer3D, "topdown3D", i)
self:addScene(name, scenes.Action3D, "bigmap3D", i) self:addScene(scenes.Action3D, "bigmap3D", i)
if i > 1 then if i > 1 then
self:addScene(name, scenes.MovePlayer, "topdown (zoom)", i, "zoom") self:addScene(scenes.MovePlayer, "topdown (zoom)", i, "zoom")
self:addScene(name, scenes.MovePlayer3D, "topdown3D (zoom)", i, "zoom") self:addScene(scenes.MovePlayer3D, "topdown3D (zoom)", i, "zoom")
end end
end end
self:addSubMenu("menus", "menu") self:addSubMenu("menus", "menu")
self:addScene("menus", scenes.Inventory, "inventory") self:addScene(scenes.Inventory, "inventory")
self:addScene("menus", scenes.Options, "options") self:addScene(scenes.Options, "options")
self:addScene(scenes.TestMenu, "tests")
self.menusystem:setSoundFromSceneAssets("navigate") self.menusystem:setSoundFromSceneAssets("navigate")
local menu = self.menusystem.menus["main"]
menu:switch("main")
ExitWidget(self, "main") ExitWidget(self, "main")
self.menusystem:switchMenu("main") self.menusystem:switchMenu("main")
@ -65,21 +68,22 @@ end
-- Functions that serve the handling of menus -- Functions that serve the handling of menus
function MainMenu:addMenu(name, nobackbutton) function MainMenu:addMenu(name, nobackbutton)
local screenHeight, screenWidth = core.screen:getDimensions()
local w, h = 424/2, 240 - 48 local w, h = 424/2, 240 - 48
local x, y = w / 2, 24 local x, y = w / 2, 24
ListBox(self.menusystem, name, x, y, w, h, 8) ListBox(self.menusystem, name, x, y, w, h, 8)
end end
function MainMenu:addSubMenu(name, fullname) function MainMenu:addSubMenu(name, fullname)
self:addMenu(name) local menu = self.menusystem.menus["main"]
menu:switch("main")
SubMenuWidget(self, "main", name, fullname) SubMenuWidget(self, "main", name, fullname)
SubMenuWidget(self, name, "main", "back", 1) menu:addSubmenu(name)
SubMenuWidget(self, "main", "main", "back", 1)
end end
function MainMenu:addScene(submenu, scene, fullname, arg1, arg2, arg3, arg4, arg5) function MainMenu:addScene(scene, fullname, arg1, arg2, arg3, arg4, arg5)
local args = {arg1, arg2, arg3, arg4, arg5} local args = {arg1, arg2, arg3, arg4, arg5}
SceneWidget(self, submenu, scene, fullname, args) SceneWidget(self, "main", scene, fullname, args)
end end
function MainMenu:draw() function MainMenu:draw()
@ -96,7 +100,6 @@ end
function SubMenuWidget:new(scene, menu, newmenu, fullname, order) function SubMenuWidget:new(scene, menu, newmenu, fullname, order)
self.scene = scene self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets:getFont("medium") local font = self.scene.assets:getFont("medium")
self.newmenu = newmenu self.newmenu = newmenu
local label = "" local label = ""
@ -107,13 +110,13 @@ function SubMenuWidget:new(scene, menu, newmenu, fullname, order)
label = core.lang:translate("mainmenu", fullname) label = core.lang:translate("mainmenu", fullname)
self.sfx = "confirm" self.sfx = "confirm"
end end
SubMenuWidget.super.new(self, widgetmenu, font, label) SubMenuWidget.super.new(self, menu, font, label)
self.order = order or 0 self.order = order or 0
end end
function SubMenuWidget:action() function SubMenuWidget:action()
self.scene.assets:playSFX(self.sfx) self.scene.assets:playSFX(self.sfx)
self.scene.menusystem:switchMenu(self.newmenu) self.menu:switch(self.newmenu)
end end
-- Scene widget :: switch scene -- Scene widget :: switch scene
@ -121,11 +124,10 @@ end
function SceneWidget:new(scene, menu, newscene, fullname, args) function SceneWidget:new(scene, menu, newscene, fullname, args)
self.scene = scene self.scene = scene
self.args = args self.args = args
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets:getFont("medium") local font = self.scene.assets:getFont("medium")
self.newscene = newscene self.newscene = newscene
local label = core.lang:translate("mainmenu", fullname) local label = core.lang:translate("mainmenu", fullname)
SceneWidget.super.new(self, widgetmenu, font, label) SceneWidget.super.new(self, menu, font, label)
end end
function SceneWidget:action() function SceneWidget:action()
@ -138,10 +140,9 @@ end
function ExitWidget:new(scene, menu) function ExitWidget:new(scene, menu)
self.scene = scene self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets:getFont("medium") local font = self.scene.assets:getFont("medium")
local label = core.lang:translate("commons", "exit") local label = core.lang:translate("commons", "exit")
SceneWidget.super.new(self, widgetmenu, font, label) SceneWidget.super.new(self, menu, font, label)
end end
function ExitWidget:action() function ExitWidget:action()