core: integrate the menu system to the scene manager

This commit is contained in:
Kazhnuz 2019-02-10 14:54:43 +01:00
parent 8553188a3e
commit 723806510b
3 changed files with 9 additions and 5 deletions

View file

@ -15,12 +15,10 @@ MenuSystem.Widget = require(cwd .. "widgets")
function MenuSystem:new()
self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end
function MenuSystem:reset()
self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end
function MenuSystem:addMenu(menu)
@ -34,8 +32,8 @@ function MenuSystem:update(dt)
v:update(dt)
v:updateWidgets(dt)
if v.haveFocus == true then
for k,w in pairs(self.virtualpad.keys) do
if self.virtualpad.keys[k].isPressed then
for k,w in pairs(self.keys) do
if self.keys[k].isPressed then
v:keyreleased(k)
end
end

View file

@ -24,12 +24,14 @@
local Scene = Object:extend()
local Assets = require "core.modules.assets"
local MenuSystem = require "core.modules.menusystem"
function Scene:new()
self.mouse = {}
self.mouse.x, self.mouse.y = core.screen:getMousePosition()
self.assets = Assets()
self.assets = Assets()
self.menusystem = MenuSystem()
end
function Scene:register()

View file

@ -34,7 +34,9 @@ function SceneManager:update(dt)
if (self.currentScene ~= nil) then
local keys = self.controller.input.keys
self.currentScene.keys = keys
self.currentScene.menusystem.keys = keys
self.currentScene.assets:update(dt)
self.currentScene.menusystem:update(dt)
self.currentScene:update(dt)
end
end
@ -43,10 +45,12 @@ function SceneManager:mousemoved(x, y, dx, dy)
self.currentScene.mouse.x,
self.currentScene.mouse.y = x, y
self.currentScene:mousemoved(x, y, dx, dy)
self.currentScene.menusystem:mousemoved(x, y, dx, dy)
end
function SceneManager:mousepressed( x, y, button, istouch )
self.currentScene:mousepressed( x, y, button, istouch )
self.currentScene.menusystem:mousepressed( x, y, button, istouch )
end
function SceneManager:clearScene()