From 93bbf5604723b89570ada838c4dc3356652c309b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 5 Dec 2020 09:02:42 +0100 Subject: [PATCH] chore: port the main menu to the new system --- examples/scenes/mainmenu/init.lua | 41 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/scenes/mainmenu/init.lua b/examples/scenes/mainmenu/init.lua index 161bb9e..f0a8b98 100644 --- a/examples/scenes/mainmenu/init.lua +++ b/examples/scenes/mainmenu/init.lua @@ -40,22 +40,25 @@ function MainMenu:new() local name = i .. "player" self:addSubMenu(name, name) if i == 1 then - self:addScene(name, scenes.Plateformer, "plateform", i) + self:addScene(scenes.Plateformer, "plateform", i) end - self:addScene(name, scenes.MovePlayer, "topdown", i) - self:addScene(name, scenes.MovePlayer3D, "topdown3D", i) - self:addScene(name, scenes.Action3D, "bigmap3D", i) + self:addScene(scenes.MovePlayer, "topdown", i) + self:addScene(scenes.MovePlayer3D, "topdown3D", i) + self:addScene(scenes.Action3D, "bigmap3D", i) if i > 1 then - self:addScene(name, scenes.MovePlayer, "topdown (zoom)", i, "zoom") - self:addScene(name, scenes.MovePlayer3D, "topdown3D (zoom)", i, "zoom") + self:addScene(scenes.MovePlayer, "topdown (zoom)", i, "zoom") + self:addScene(scenes.MovePlayer3D, "topdown3D (zoom)", i, "zoom") end end self:addSubMenu("menus", "menu") - self:addScene("menus", scenes.Inventory, "inventory") - self:addScene("menus", scenes.Options, "options") + self:addScene(scenes.Inventory, "inventory") + self:addScene(scenes.Options, "options") + self:addScene(scenes.TestMenu, "tests") self.menusystem:setSoundFromSceneAssets("navigate") + local menu = self.menusystem.menus["main"] + menu:switch("main") ExitWidget(self, "main") self.menusystem:switchMenu("main") @@ -65,21 +68,22 @@ end -- Functions that serve the handling of menus function MainMenu:addMenu(name, nobackbutton) - local screenHeight, screenWidth = core.screen:getDimensions() local w, h = 424/2, 240 - 48 local x, y = w / 2, 24 ListBox(self.menusystem, name, x, y, w, h, 8) end function MainMenu:addSubMenu(name, fullname) - self:addMenu(name) + local menu = self.menusystem.menus["main"] + menu:switch("main") SubMenuWidget(self, "main", name, fullname) - SubMenuWidget(self, name, "main", "back", 1) + menu:addSubmenu(name) + SubMenuWidget(self, "main", "main", "back", 1) 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} - SceneWidget(self, submenu, scene, fullname, args) + SceneWidget(self, "main", scene, fullname, args) end function MainMenu:draw() @@ -96,7 +100,6 @@ end function SubMenuWidget:new(scene, menu, newmenu, fullname, order) self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] local font = self.scene.assets:getFont("medium") self.newmenu = newmenu local label = "" @@ -107,13 +110,13 @@ function SubMenuWidget:new(scene, menu, newmenu, fullname, order) label = core.lang:translate("mainmenu", fullname) self.sfx = "confirm" end - SubMenuWidget.super.new(self, widgetmenu, font, label) + SubMenuWidget.super.new(self, menu, font, label) self.order = order or 0 end function SubMenuWidget:action() self.scene.assets:playSFX(self.sfx) - self.scene.menusystem:switchMenu(self.newmenu) + self.menu:switch(self.newmenu) end -- Scene widget :: switch scene @@ -121,11 +124,10 @@ end function SceneWidget:new(scene, menu, newscene, fullname, args) self.scene = scene self.args = args - local widgetmenu = self.scene.menusystem.menus[menu] local font = self.scene.assets:getFont("medium") self.newscene = newscene local label = core.lang:translate("mainmenu", fullname) - SceneWidget.super.new(self, widgetmenu, font, label) + SceneWidget.super.new(self, menu, font, label) end function SceneWidget:action() @@ -138,10 +140,9 @@ end function ExitWidget:new(scene, menu) self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] local font = self.scene.assets:getFont("medium") local label = core.lang:translate("commons", "exit") - SceneWidget.super.new(self, widgetmenu, font, label) + SceneWidget.super.new(self, menu, font, label) end function ExitWidget:action()