modules/menusystem: add functions to easily lock and set activity

This commit is contained in:
Kazhnuz 2019-04-07 12:59:25 +02:00
parent d1497836a2
commit 713b93eaf9
3 changed files with 46 additions and 3 deletions

View file

@ -49,11 +49,10 @@ function Inventory:new()
self:addItem("shield", 2)
self:addItem("shield", 1)
self.menusystem.menus["main"].isLocked = true
self.menusystem:lockMenu("main")
self.menusystem:switchMenu("main")
self.menusystem.menus["weapon"].isVisible = true
self.menusystem.menus["weapon"].isActive = true
self.menusystem:setMenuActivity("weapon", true)
end
-- MENU FUNCTION

View file

@ -26,6 +26,10 @@ function MenuSystem:addMenu(name, menu)
self.menus[name] = menu
end
function MenuSystem:menuExist(name)
return (self.menus[name] ~= nil)
end
function MenuSystem:update(dt)
self:removeDestroyedMenus()
for k,v in pairs(self.menus) do
@ -59,6 +63,38 @@ function MenuSystem:switchMenu(menu)
end
end
function MenuSystem:lockMenu(menu, lock)
local lock = lock or true
if self:menuExist(menu) then
self.menus[menu]:lock(lock)
end
end
function MenuSystem:lockMenuVisibility(menu, lock)
local lock = lock or true
if self:menuExist(menu) then
self.menus[menu]:lockVisibility(lock)
end
end
function MenuSystem:setMenuActivity(menu, activity)
local activity = activity or true
if self:menuExist(menu) then
self.menus[menu]:setActivity(activity)
if activity == true then
-- if we make the menu active, he have to be visible too
self.menus[menu]:setVisibility(true)
end
end
end
function MenuSystem:setMenuVisibility(menu, visibility)
local visibility = visibility or true
if self:menuExist(menu) then
self.menus[menu]:setVisibility(visibility)
end
end
function MenuSystem:setAllMenuVisibility(visibility)
for k,v in pairs(self.menus) do
v:setVisibility(visibility)

View file

@ -53,6 +53,14 @@ function Menu:setActivity(activity)
end
end
function Menu:lock(lock)
self.isLocked = lock
end
function Menu:lockVisibility(lock)
self.isAlwaysVisible = lock
end
function Menu:getFocus()
self.menusystem.focusedMenu = self.name
end