modules/menusystem: add functions to easily lock and set activity
This commit is contained in:
parent
d1497836a2
commit
713b93eaf9
3 changed files with 46 additions and 3 deletions
|
@ -49,11 +49,10 @@ function Inventory:new()
|
||||||
self:addItem("shield", 2)
|
self:addItem("shield", 2)
|
||||||
self:addItem("shield", 1)
|
self:addItem("shield", 1)
|
||||||
|
|
||||||
self.menusystem.menus["main"].isLocked = true
|
self.menusystem:lockMenu("main")
|
||||||
|
|
||||||
self.menusystem:switchMenu("main")
|
self.menusystem:switchMenu("main")
|
||||||
self.menusystem.menus["weapon"].isVisible = true
|
self.menusystem:setMenuActivity("weapon", true)
|
||||||
self.menusystem.menus["weapon"].isActive = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MENU FUNCTION
|
-- MENU FUNCTION
|
||||||
|
|
|
@ -26,6 +26,10 @@ function MenuSystem:addMenu(name, menu)
|
||||||
self.menus[name] = menu
|
self.menus[name] = menu
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MenuSystem:menuExist(name)
|
||||||
|
return (self.menus[name] ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
function MenuSystem:update(dt)
|
function MenuSystem:update(dt)
|
||||||
self:removeDestroyedMenus()
|
self:removeDestroyedMenus()
|
||||||
for k,v in pairs(self.menus) do
|
for k,v in pairs(self.menus) do
|
||||||
|
@ -59,6 +63,38 @@ function MenuSystem:switchMenu(menu)
|
||||||
end
|
end
|
||||||
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)
|
function MenuSystem:setAllMenuVisibility(visibility)
|
||||||
for k,v in pairs(self.menus) do
|
for k,v in pairs(self.menus) do
|
||||||
v:setVisibility(visibility)
|
v:setVisibility(visibility)
|
||||||
|
|
|
@ -53,6 +53,14 @@ function Menu:setActivity(activity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Menu:lock(lock)
|
||||||
|
self.isLocked = lock
|
||||||
|
end
|
||||||
|
|
||||||
|
function Menu:lockVisibility(lock)
|
||||||
|
self.isAlwaysVisible = lock
|
||||||
|
end
|
||||||
|
|
||||||
function Menu:getFocus()
|
function Menu:getFocus()
|
||||||
self.menusystem.focusedMenu = self.name
|
self.menusystem.focusedMenu = self.name
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue