modules/menus: add a simple way to switch menu

This commit is contained in:
Kazhnuz 2019-03-22 17:27:59 +01:00
parent 6f9235866d
commit 19aa49327c
2 changed files with 16 additions and 4 deletions

View file

@ -33,9 +33,10 @@ local MenuWidget = Widget.Text:extend()
function TestScene:new()
TestScene.super.new(self)
self.assets:addImageFont("medium", "examples/test_menus/assets/medium")
MenuType(self.menusystem, "testMenu1", 32, 32, 100, 24*8, 4)
Widget.Base(self.menusystem.menus["testMenu1"])
MenuWidget(self, "testMenu1", "text_menu1")
Widget.Base(self.menusystem.menus["testMenu1"])
Widget.Base(self.menusystem.menus["testMenu1"])
Widget.Base(self.menusystem.menus["testMenu1"])
@ -78,8 +79,6 @@ function TestScene:new()
self.menusystem.menus["testMenu2"].isLocked = true
self.menusystem.menus["testMenu3"].isLocked = true
self.assets:addImageFont("medium", "examples/test_menus/assets/medium")
local w, h = 424/2, 240 - 48
local x, y = w / 2, 24
@ -106,7 +105,7 @@ function TestScene:new()
MenuWidget(self, "text_menu3", "text_menu6")
MenuWidget(self, "text_menu3", "text_menu6")
self.menusystem:setAllMenuVisibility(false)
self.menusystem:switchMenu("testMenu1")
end
function TestScene:update(dt)

View file

@ -46,6 +46,19 @@ function MenuSystem:update(dt)
end
function MenuSystem:switchMenu(menu)
for k,v in pairs(self.menus) do
if k == menu then
v:getFocus()
v:setVisibility(true)
v.isActive = true
else
v:setVisibility(false)
v.isActive = false
end
end
end
function MenuSystem:setAllMenuVisibility(visibility)
for k,v in pairs(self.menus) do
v:setVisibility(visibility)