fix: port main menu to textmenu
This commit is contained in:
parent
870a4f7118
commit
99952487a9
1 changed files with 19 additions and 44 deletions
|
@ -27,18 +27,21 @@ local MainMenu = Scene:extend()
|
|||
local ListBox = require "birb.modules.menusystem.menus.listbox"
|
||||
local Widget = require "birb.modules.menusystem.menus.widgets"
|
||||
|
||||
local SubMenuWidget = Widget.Text:extend()
|
||||
local SceneWidget = Widget.Text:extend()
|
||||
local ExitWidget = Widget.Text:extend()
|
||||
local TextMenu = require "birb.modules.menusystem.textmenu"
|
||||
|
||||
local SceneWidget = TextMenu.baseWidgets.Base:extend()
|
||||
local ExitWidget = TextMenu.baseWidgets.Base:extend()
|
||||
|
||||
local MENU_NAME = "mainMenu"
|
||||
|
||||
function MainMenu:new()
|
||||
MainMenu.super.new(self)
|
||||
self.assets:batchImport("scenes.mainmenu.assets")
|
||||
|
||||
self:addMenu("main", true)
|
||||
print(self.assets:getFont("medium"))
|
||||
local menu = self:addMenu()
|
||||
for i=1, 4 do
|
||||
local name = i .. "player"
|
||||
self:addSubMenu(name, name)
|
||||
menu:addSubmenu(name, core.lang:translate("commons", name))
|
||||
if i == 1 then
|
||||
self:addScene(scenes.Plateformer, "plateform", i)
|
||||
end
|
||||
|
@ -57,33 +60,30 @@ function MainMenu:new()
|
|||
|
||||
|
||||
self.menusystem:setSoundFromSceneAssets("navigate")
|
||||
local menu = self.menusystem.menus["main"]
|
||||
local menu = self.menusystem.menus[MENU_NAME]
|
||||
menu:switch("main")
|
||||
|
||||
ExitWidget(self, "main")
|
||||
self.menusystem:switchMenu("main")
|
||||
self.menusystem:switchMenu(MENU_NAME)
|
||||
end
|
||||
|
||||
-- MENU FUNCTION
|
||||
-- Functions that serve the handling of menus
|
||||
|
||||
function MainMenu:addMenu(name, nobackbutton)
|
||||
local w, h = 424/2, 240 - 48
|
||||
function MainMenu:addMenu()
|
||||
local w = 424/2
|
||||
local x, y = w / 2, 24
|
||||
ListBox(self.menusystem, name, x, y, w, h, 8)
|
||||
return TextMenu(MENU_NAME, "medium", x, y, w, 8, 0)
|
||||
end
|
||||
|
||||
function MainMenu:addSubMenu(name, fullname)
|
||||
local menu = self.menusystem.menus["main"]
|
||||
menu:switch("main")
|
||||
SubMenuWidget(self, "main", name, fullname)
|
||||
menu:addSubmenu(name)
|
||||
SubMenuWidget(self, "main", "main", "back", 1)
|
||||
local menu = self.menusystem.menus[MENU_NAME]
|
||||
menu:addSubmenu(name, core.lang:translate("mainmenu", fullname))
|
||||
end
|
||||
|
||||
function MainMenu:addScene(scene, fullname, arg1, arg2, arg3, arg4, arg5)
|
||||
local args = {arg1, arg2, arg3, arg4, arg5}
|
||||
SceneWidget(self, "main", scene, fullname, args)
|
||||
SceneWidget(self, MENU_NAME, scene, fullname, args)
|
||||
end
|
||||
|
||||
function MainMenu:draw()
|
||||
|
@ -96,38 +96,14 @@ end
|
|||
-- WIDGETS
|
||||
-- Widgets used by menus
|
||||
|
||||
-- Submenu widget :: go to a submenu
|
||||
|
||||
function SubMenuWidget:new(scene, menu, newmenu, fullname, order)
|
||||
self.scene = scene
|
||||
local font = self.scene.assets:getFont("medium")
|
||||
self.newmenu = newmenu
|
||||
local label = ""
|
||||
if fullname == "back" then
|
||||
label = core.lang:translate("commons", fullname)
|
||||
self.sfx = "cancel"
|
||||
else
|
||||
label = core.lang:translate("mainmenu", fullname)
|
||||
self.sfx = "confirm"
|
||||
end
|
||||
SubMenuWidget.super.new(self, menu, font, label)
|
||||
self.order = order or 0
|
||||
end
|
||||
|
||||
function SubMenuWidget:action()
|
||||
self.scene.assets:playSFX(self.sfx)
|
||||
self.menu:switch(self.newmenu)
|
||||
end
|
||||
|
||||
-- Scene widget :: switch scene
|
||||
|
||||
function SceneWidget:new(scene, menu, newscene, fullname, args)
|
||||
self.scene = scene
|
||||
self.args = args
|
||||
local font = self.scene.assets:getFont("medium")
|
||||
self.newscene = newscene
|
||||
local label = core.lang:translate("mainmenu", fullname)
|
||||
SceneWidget.super.new(self, menu, font, label)
|
||||
SceneWidget.super.new(self, MENU_NAME, label)
|
||||
end
|
||||
|
||||
function SceneWidget:action()
|
||||
|
@ -140,9 +116,8 @@ end
|
|||
|
||||
function ExitWidget:new(scene, menu)
|
||||
self.scene = scene
|
||||
local font = self.scene.assets:getFont("medium")
|
||||
local label = core.lang:translate("commons", "exit")
|
||||
SceneWidget.super.new(self, menu, font, label)
|
||||
SceneWidget.super.new(self, MENU_NAME, label)
|
||||
end
|
||||
|
||||
function ExitWidget:action()
|
||||
|
|
Loading…
Reference in a new issue