modules/menusystem: more code cleanup

This commit is contained in:
Kazhnuz 2019-04-11 16:58:42 +02:00
parent 96f56a7284
commit c9e3f5b82a
3 changed files with 45 additions and 36 deletions

View File

@ -45,14 +45,14 @@ function FlowBox:new(menusystem, name, x, y, w, h, slots_hor, slots_vert)
-- soit un multiple du nombre de slot et de leur dimensions
end
-- UPDATE FUNCTIONS
-- Update the menu and its view
function FlowBox:updateWidgetSize()
self.widget.h = math.floor( self.h / self.view.lineNumber )
self.widget.w = math.floor( self.w / self.view.colNumber )
end
-- UPDATE FUNCTIONS
-- Update the menu and its view
function FlowBox:update(dt)
self:updateView()
end
@ -76,6 +76,9 @@ function FlowBox:updateView()
self.view.firstSlot = beginline * self.view.colNumber + 1
end
-- INFO FUNCTIONS
-- Get informations
function FlowBox:getCoord(id_selected)
id_selected = id_selected - 1 -- On simplifie les calcul en prenant 0 comme départ
local line, col
@ -84,6 +87,9 @@ function FlowBox:getCoord(id_selected)
return col, line
end
-- CURSOR FUNCTIONS
-- Handle the cursor in a 2D menu
function FlowBox:moveCursor(new_col, new_line)
local col, line = self:getCoord(self.widget.selected)
local lastcol, lastline = self:getCoord(#self.widget.list)
@ -122,6 +128,9 @@ function FlowBox:moveCursor(new_col, new_line)
self.widget.selected = (new_line * self.view.colNumber) + new_col + 1
end
-- KEYS FUNCTIONS
-- Handle the keyboard/controller inputs
function FlowBox:keyreleased(key, code)
local col, line = self:getCoord(self.widget.selected)
if key == 'left' then
@ -147,6 +156,9 @@ function FlowBox:keyreleased(key, code)
end
end
-- MOUSE FUNCTIONS
-- Handle the mouse/touch pointer
function FlowBox:mousemoved(x, y)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.view.firstSlot)

View File

@ -36,9 +36,6 @@ MenuSystem.TextMenu = require(cwd .. "textmenu")
-- load widgets object
MenuSystem.Widget = require(cwd .. "widgets")
--local VirtualPad = require "modules.virtualpad"
-- INIT FUNCTIONS
-- Initialize and configure the menu controller
@ -62,29 +59,6 @@ function MenuSystem:menuExist(name)
return (self.menus[name] ~= nil)
end
-- UPDATE FUNCTIONS
-- Update the menus of the menusystem
function MenuSystem:update(dt)
self:removeDestroyedMenus()
for k,v in pairs(self.menus) do
v:update(dt)
v:updateWidgets(dt)
end
if self.menus[self.focusedMenu] ~= nil then
-- Only check buttons if the current focused menu is actually active
if self.menus[self.focusedMenu].isActive then
for k,v in pairs(self.keys) do
if self.keys[k].isPressed then
self.menus[self.focusedMenu]:keyreleased(k)
end
end
end
end
end
function MenuSystem:switchMenu(menu)
for k,v in pairs(self.menus) do
if k == menu then
@ -151,6 +125,29 @@ function MenuSystem:removeDestroyedMenus()
end
end
-- UPDATE FUNCTIONS
-- Update the menus of the menusystem
function MenuSystem:update(dt)
self:removeDestroyedMenus()
for k,v in pairs(self.menus) do
v:update(dt)
v:updateWidgets(dt)
end
if self.menus[self.focusedMenu] ~= nil then
-- Only check buttons if the current focused menu is actually active
if self.menus[self.focusedMenu].isActive then
for k,v in pairs(self.keys) do
if self.keys[k].isPressed then
self.menus[self.focusedMenu]:keyreleased(k)
end
end
end
end
end
function MenuSystem:keyreleased(key, code)
-- TODO:depreciated function
end

View File

@ -121,13 +121,6 @@ function Menu:cancelAction()
end
end
-- UPDATE FUNCTIONS
-- Update the menu every game update
function Menu:update(dt)
-- Cette fonction ne contient rien par défaut
end
function Menu:clear()
self.widget.list = {}
self.widget.cancel = 0
@ -146,6 +139,13 @@ function Menu:destroy()
self.destroyed = true
end
-- UPDATE FUNCTIONS
-- Update the menu every game update
function Menu:update(dt)
-- Cette fonction ne contient rien par défaut
end
-- DRAW FUNCTIONS
-- Draw the menu and its content