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 ListBox = require "birb.modules.menusystem.menus.listbox"
|
||||||
local Widget = require "birb.modules.menusystem.menus.widgets"
|
local Widget = require "birb.modules.menusystem.menus.widgets"
|
||||||
|
|
||||||
local SubMenuWidget = Widget.Text:extend()
|
local TextMenu = require "birb.modules.menusystem.textmenu"
|
||||||
local SceneWidget = Widget.Text:extend()
|
|
||||||
local ExitWidget = Widget.Text:extend()
|
local SceneWidget = TextMenu.baseWidgets.Base:extend()
|
||||||
|
local ExitWidget = TextMenu.baseWidgets.Base:extend()
|
||||||
|
|
||||||
|
local MENU_NAME = "mainMenu"
|
||||||
|
|
||||||
function MainMenu:new()
|
function MainMenu:new()
|
||||||
MainMenu.super.new(self)
|
MainMenu.super.new(self)
|
||||||
self.assets:batchImport("scenes.mainmenu.assets")
|
self.assets:batchImport("scenes.mainmenu.assets")
|
||||||
|
print(self.assets:getFont("medium"))
|
||||||
self:addMenu("main", true)
|
local menu = self:addMenu()
|
||||||
for i=1, 4 do
|
for i=1, 4 do
|
||||||
local name = i .. "player"
|
local name = i .. "player"
|
||||||
self:addSubMenu(name, name)
|
menu:addSubmenu(name, core.lang:translate("commons", name))
|
||||||
if i == 1 then
|
if i == 1 then
|
||||||
self:addScene(scenes.Plateformer, "plateform", i)
|
self:addScene(scenes.Plateformer, "plateform", i)
|
||||||
end
|
end
|
||||||
|
@ -57,33 +60,30 @@ function MainMenu:new()
|
||||||
|
|
||||||
|
|
||||||
self.menusystem:setSoundFromSceneAssets("navigate")
|
self.menusystem:setSoundFromSceneAssets("navigate")
|
||||||
local menu = self.menusystem.menus["main"]
|
local menu = self.menusystem.menus[MENU_NAME]
|
||||||
menu:switch("main")
|
menu:switch("main")
|
||||||
|
|
||||||
ExitWidget(self, "main")
|
ExitWidget(self, "main")
|
||||||
self.menusystem:switchMenu("main")
|
self.menusystem:switchMenu(MENU_NAME)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MENU FUNCTION
|
-- MENU FUNCTION
|
||||||
-- Functions that serve the handling of menus
|
-- Functions that serve the handling of menus
|
||||||
|
|
||||||
function MainMenu:addMenu(name, nobackbutton)
|
function MainMenu:addMenu()
|
||||||
local w, h = 424/2, 240 - 48
|
local w = 424/2
|
||||||
local x, y = w / 2, 24
|
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
|
end
|
||||||
|
|
||||||
function MainMenu:addSubMenu(name, fullname)
|
function MainMenu:addSubMenu(name, fullname)
|
||||||
local menu = self.menusystem.menus["main"]
|
local menu = self.menusystem.menus[MENU_NAME]
|
||||||
menu:switch("main")
|
menu:addSubmenu(name, core.lang:translate("mainmenu", fullname))
|
||||||
SubMenuWidget(self, "main", name, fullname)
|
|
||||||
menu:addSubmenu(name)
|
|
||||||
SubMenuWidget(self, "main", "main", "back", 1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MainMenu:addScene(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, "main", scene, fullname, args)
|
SceneWidget(self, MENU_NAME, scene, fullname, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MainMenu:draw()
|
function MainMenu:draw()
|
||||||
|
@ -96,38 +96,14 @@ end
|
||||||
-- WIDGETS
|
-- WIDGETS
|
||||||
-- Widgets used by menus
|
-- 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
|
-- Scene widget :: switch scene
|
||||||
|
|
||||||
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 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, menu, font, label)
|
SceneWidget.super.new(self, MENU_NAME, label)
|
||||||
end
|
end
|
||||||
|
|
||||||
function SceneWidget:action()
|
function SceneWidget:action()
|
||||||
|
@ -140,9 +116,8 @@ end
|
||||||
|
|
||||||
function ExitWidget:new(scene, menu)
|
function ExitWidget:new(scene, menu)
|
||||||
self.scene = scene
|
self.scene = scene
|
||||||
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, menu, font, label)
|
SceneWidget.super.new(self, MENU_NAME, label)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ExitWidget:action()
|
function ExitWidget:action()
|
||||||
|
|
Loading…
Reference in a new issue