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() function MenuSystem:new()
self.menus = {} self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end end
function MenuSystem:reset() function MenuSystem:reset()
self.menus = {} self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end end
function MenuSystem:addMenu(menu) function MenuSystem:addMenu(menu)
@ -34,8 +32,8 @@ function MenuSystem:update(dt)
v:update(dt) v:update(dt)
v:updateWidgets(dt) v:updateWidgets(dt)
if v.haveFocus == true then if v.haveFocus == true then
for k,w in pairs(self.virtualpad.keys) do for k,w in pairs(self.keys) do
if self.virtualpad.keys[k].isPressed then if self.keys[k].isPressed then
v:keyreleased(k) v:keyreleased(k)
end end
end end

View file

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

View file

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