modules/menusystem: better comments
This commit is contained in:
parent
915b4a2ab8
commit
96f56a7284
8 changed files with 311 additions and 9 deletions
|
@ -1,10 +1,36 @@
|
||||||
local cwd = (...):gsub('%.flowbox$', '') .. "."
|
-- flowbox :: flexible box menu, that handle in grid the widgets
|
||||||
local Menu = require(cwd .. "parent")
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
|
local cwd = (...):gsub('%.flowbox$', '') .. "."
|
||||||
|
|
||||||
|
local Menu = require(cwd .. "parent")
|
||||||
local FlowBox = Menu:extend()
|
local FlowBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local menuutils = require(cwd .. "widgets.utils")
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the flowbox
|
||||||
|
|
||||||
function FlowBox:new(menusystem, name, x, y, w, h, slots_hor, slots_vert)
|
function FlowBox:new(menusystem, name, x, y, w, h, slots_hor, slots_vert)
|
||||||
self.view = {}
|
self.view = {}
|
||||||
self.view.slotNumber = slots_hor * slots_vert
|
self.view.slotNumber = slots_hor * slots_vert
|
||||||
|
@ -24,6 +50,9 @@ function FlowBox:updateWidgetSize()
|
||||||
self.widget.w = math.floor( self.w / self.view.colNumber )
|
self.widget.w = math.floor( self.w / self.view.colNumber )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the menu and its view
|
||||||
|
|
||||||
function FlowBox:update(dt)
|
function FlowBox:update(dt)
|
||||||
self:updateView()
|
self:updateView()
|
||||||
end
|
end
|
||||||
|
@ -150,6 +179,9 @@ function FlowBox:mousepressed(x, y, button, isTouch)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Draw the menu and its content
|
||||||
|
|
||||||
function FlowBox:draw()
|
function FlowBox:draw()
|
||||||
self:updateView()
|
self:updateView()
|
||||||
local widgety = self.y
|
local widgety = self.y
|
||||||
|
|
|
@ -1,10 +1,36 @@
|
||||||
local cwd = (...):gsub('%.grid$', '') .. "."
|
-- grid :: a menu with arbitrary widget placement and size on a grid.
|
||||||
local Menu = require(cwd .. "parent")
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
|
local cwd = (...):gsub('%.grid$', '') .. "."
|
||||||
|
|
||||||
|
local Menu = require(cwd .. "parent")
|
||||||
local GridBox = Menu:extend()
|
local GridBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local menuutils = require(cwd .. "widgets.utils")
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the menu
|
||||||
|
|
||||||
function GridBox:new(menusystem, name, x, y, w, h, colNumber, lineNumber)
|
function GridBox:new(menusystem, name, x, y, w, h, colNumber, lineNumber)
|
||||||
self.view = {}
|
self.view = {}
|
||||||
self.view.slotNumber = colNumber * lineNumber
|
self.view.slotNumber = colNumber * lineNumber
|
||||||
|
@ -40,6 +66,9 @@ function GridBox:updateWidgetSize()
|
||||||
self.widget.w = math.floor( self.w / self.view.colNumber )
|
self.widget.w = math.floor( self.w / self.view.colNumber )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- INFO FUNCTIONS
|
||||||
|
-- Get the info of the widgets
|
||||||
|
|
||||||
function GridBox:getWidgetSize(id)
|
function GridBox:getWidgetSize(id)
|
||||||
local slot = self:getWidgetSlot(id)
|
local slot = self:getWidgetSlot(id)
|
||||||
if slot == 0 then
|
if slot == 0 then
|
||||||
|
@ -106,10 +135,16 @@ function GridBox:getWidgetAtPoint(x, y)
|
||||||
return widgetID
|
return widgetID
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the Grid and its view
|
||||||
|
|
||||||
function GridBox:update(dt)
|
function GridBox:update(dt)
|
||||||
self.view.firstSlot = 1
|
self.view.firstSlot = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- KEYS FUNCTIONS
|
||||||
|
-- Handle the keyboard/manette functions
|
||||||
|
|
||||||
function GridBox:keyreleased(key, code)
|
function GridBox:keyreleased(key, code)
|
||||||
slotID = self:getWidgetSlot(self.widget.selected)
|
slotID = self:getWidgetSlot(self.widget.selected)
|
||||||
local col, line = self.cursor.x, self.cursor.y
|
local col, line = self.cursor.x, self.cursor.y
|
||||||
|
@ -176,6 +211,9 @@ function GridBox:moveLine(direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Handle the mouse and activate the widgets with it
|
||||||
|
|
||||||
function GridBox:mousemoved(x, y)
|
function GridBox:mousemoved(x, y)
|
||||||
local widgetID = self:getWidgetAtPoint(x, y)
|
local widgetID = self:getWidgetAtPoint(x, y)
|
||||||
|
|
||||||
|
@ -206,6 +244,9 @@ function GridBox:mousepressed(x, y, button, isTouch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Draw the menu and its content
|
||||||
|
|
||||||
function GridBox:draw()
|
function GridBox:draw()
|
||||||
|
|
||||||
for i,v in ipairs(self.slots) do
|
for i,v in ipairs(self.slots) do
|
||||||
|
|
|
@ -1,9 +1,35 @@
|
||||||
|
-- hlistbox : add an horizontal list of widgets.
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
local cwd = (...):gsub('%.hlistbox$', '') .. "."
|
local cwd = (...):gsub('%.hlistbox$', '') .. "."
|
||||||
|
|
||||||
local Menu = require(cwd .. "parent")
|
local Menu = require(cwd .. "parent")
|
||||||
|
local HListBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local menuutils = require(cwd .. "widgets.utils")
|
||||||
|
|
||||||
local HListBox = Menu:extend()
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure functions.
|
||||||
|
|
||||||
function HListBox:new(menusystem, name, x, y, w, h, slotNumber)
|
function HListBox:new(menusystem, name, x, y, w, h, slotNumber)
|
||||||
self.view = {}
|
self.view = {}
|
||||||
|
@ -14,6 +40,9 @@ function HListBox:new(menusystem, name, x, y, w, h, slotNumber)
|
||||||
-- soit un multiple du nombre de slot et de leur hauteur
|
-- soit un multiple du nombre de slot et de leur hauteur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the menu every step.
|
||||||
|
|
||||||
function HListBox:updateWidgetSize()
|
function HListBox:updateWidgetSize()
|
||||||
self.widget.h = self.h
|
self.widget.h = self.h
|
||||||
self.widget.w = math.floor( self.w / self.view.slotNumber )
|
self.widget.w = math.floor( self.w / self.view.slotNumber )
|
||||||
|
@ -36,6 +65,9 @@ function HListBox:updateView()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- KEYBOARD FUNCTIONS
|
||||||
|
-- Handle key check.
|
||||||
|
|
||||||
function HListBox:keyreleased(key, code)
|
function HListBox:keyreleased(key, code)
|
||||||
|
|
||||||
if key == 'left' then
|
if key == 'left' then
|
||||||
|
@ -60,6 +92,9 @@ function HListBox:keyreleased(key, code)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Click and stuff like that.
|
||||||
|
|
||||||
function HListBox:mousemoved(x, y)
|
function HListBox:mousemoved(x, y)
|
||||||
local widget_selected = self.view.firstSlot + math.floor(x / self.widget.w)
|
local widget_selected = self.view.firstSlot + math.floor(x / self.widget.w)
|
||||||
|
|
||||||
|
@ -82,6 +117,9 @@ function HListBox:mousepressed(x, y, button, isTouch)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Draw the menu and its content
|
||||||
|
|
||||||
function HListBox:draw()
|
function HListBox:draw()
|
||||||
self:updateView()
|
self:updateView()
|
||||||
local widgetx = self.x
|
local widgetx = self.x
|
||||||
|
|
|
@ -1,18 +1,47 @@
|
||||||
local MenuSystem = Object:extend()
|
-- menusystem :: the controller of the menu system. This object handle the
|
||||||
|
-- different menu objects
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
local cwd = (...):gsub('%.init$', '') .. "."
|
local cwd = (...):gsub('%.init$', '') .. "."
|
||||||
|
|
||||||
|
local MenuSystem = Object:extend()
|
||||||
|
|
||||||
|
-- Load the differents menu object to get an easy access
|
||||||
MenuSystem.Parent = require(cwd .. "parent")
|
MenuSystem.Parent = require(cwd .. "parent")
|
||||||
MenuSystem.ListBox = require(cwd .. "listbox")
|
MenuSystem.ListBox = require(cwd .. "listbox")
|
||||||
MenuSystem.FlowBox = require(cwd .. "flowbox")
|
MenuSystem.FlowBox = require(cwd .. "flowbox")
|
||||||
MenuSystem.Grid = require(cwd .. "grid")
|
MenuSystem.Grid = require(cwd .. "grid")
|
||||||
MenuSystem.TextMenu = require(cwd .. "textmenu")
|
MenuSystem.TextMenu = require(cwd .. "textmenu")
|
||||||
|
|
||||||
|
-- load widgets object
|
||||||
MenuSystem.Widget = require(cwd .. "widgets")
|
MenuSystem.Widget = require(cwd .. "widgets")
|
||||||
|
|
||||||
|
|
||||||
--local VirtualPad = require "modules.virtualpad"
|
--local VirtualPad = require "modules.virtualpad"
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the menu controller
|
||||||
|
|
||||||
function MenuSystem:new()
|
function MenuSystem:new()
|
||||||
self.menus = {}
|
self.menus = {}
|
||||||
self.focusedMenu = ""
|
self.focusedMenu = ""
|
||||||
|
@ -22,6 +51,9 @@ function MenuSystem:reset()
|
||||||
self.menus = {}
|
self.menus = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MENUS FUNCTIONS
|
||||||
|
-- Controle the menus of the menusystem
|
||||||
|
|
||||||
function MenuSystem:addMenu(name, menu)
|
function MenuSystem:addMenu(name, menu)
|
||||||
self.menus[name] = menu
|
self.menus[name] = menu
|
||||||
end
|
end
|
||||||
|
@ -30,6 +62,9 @@ function MenuSystem:menuExist(name)
|
||||||
return (self.menus[name] ~= nil)
|
return (self.menus[name] ~= nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the menus of the menusystem
|
||||||
|
|
||||||
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
|
||||||
|
@ -120,6 +155,9 @@ function MenuSystem:keyreleased(key, code)
|
||||||
-- TODO:depreciated function
|
-- TODO:depreciated function
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Send mouse inputs to the menu
|
||||||
|
|
||||||
function MenuSystem:mousemoved(x, y, dx, dy)
|
function MenuSystem:mousemoved(x, y, dx, dy)
|
||||||
for k,v in pairs(self.menus) do
|
for k,v in pairs(self.menus) do
|
||||||
if v.isActive then
|
if v.isActive then
|
||||||
|
@ -142,6 +180,9 @@ function MenuSystem:mousepressed( x, y, button, istouch )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- All functions to draw the menus of the menusystem
|
||||||
|
|
||||||
function MenuSystem:getDrawList()
|
function MenuSystem:getDrawList()
|
||||||
local drawList = {}
|
local drawList = {}
|
||||||
for k,v in pairs(self.menus) do
|
for k,v in pairs(self.menus) do
|
||||||
|
|
|
@ -1,9 +1,35 @@
|
||||||
|
-- listbox : add a vertical list of widgets.
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
local cwd = (...):gsub('%.listbox$', '') .. "."
|
local cwd = (...):gsub('%.listbox$', '') .. "."
|
||||||
local Menu = require(cwd .. "parent")
|
local Menu = require(cwd .. "parent")
|
||||||
|
|
||||||
|
local ListBox = Menu:extend()
|
||||||
|
|
||||||
local menuutils = require(cwd .. "widgets.utils")
|
local menuutils = require(cwd .. "widgets.utils")
|
||||||
|
|
||||||
local ListBox = Menu:extend()
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure functions.
|
||||||
|
|
||||||
function ListBox:new(menusystem, name, x, y, w, h, slotNumber)
|
function ListBox:new(menusystem, name, x, y, w, h, slotNumber)
|
||||||
self.view = {}
|
self.view = {}
|
||||||
|
@ -14,6 +40,9 @@ function ListBox:new(menusystem, name, x, y, w, h, slotNumber)
|
||||||
-- soit un multiple du nombre de slot et de leur hauteur
|
-- soit un multiple du nombre de slot et de leur hauteur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the menu every step.
|
||||||
|
|
||||||
function ListBox:updateWidgetSize()
|
function ListBox:updateWidgetSize()
|
||||||
self.widget.h = math.floor( self.h / self.view.slotNumber )
|
self.widget.h = math.floor( self.h / self.view.slotNumber )
|
||||||
self.widget.w = self.w
|
self.widget.w = self.w
|
||||||
|
@ -36,6 +65,9 @@ function ListBox:updateView()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- KEYBOARD FUNCTIONS
|
||||||
|
-- Handle input from keyboard/controllers.
|
||||||
|
|
||||||
function ListBox:keyreleased(key, code)
|
function ListBox:keyreleased(key, code)
|
||||||
|
|
||||||
if key == 'up' then
|
if key == 'up' then
|
||||||
|
@ -60,6 +92,9 @@ function ListBox:keyreleased(key, code)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Handle input from pointers.
|
||||||
|
|
||||||
function ListBox:mousemoved(x, y)
|
function ListBox:mousemoved(x, y)
|
||||||
local widget_selected = self.view.firstSlot + math.floor(y / self.widget.h)
|
local widget_selected = self.view.firstSlot + math.floor(y / self.widget.h)
|
||||||
|
|
||||||
|
@ -82,6 +117,9 @@ function ListBox:mousepressed(x, y, button, isTouch)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- draw the menu and the rest of content.
|
||||||
|
|
||||||
function ListBox:draw()
|
function ListBox:draw()
|
||||||
self:updateView()
|
self:updateView()
|
||||||
local widgety = self.y
|
local widgety = self.y
|
||||||
|
|
|
@ -1,5 +1,31 @@
|
||||||
|
-- parent.lua : The parent of the functions.
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
local Menu = Object:extend()
|
local Menu = Object:extend()
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure functions.
|
||||||
|
|
||||||
function Menu:new(menusystem, name, x, y, w, h)
|
function Menu:new(menusystem, name, x, y, w, h)
|
||||||
self.menusystem = menusystem
|
self.menusystem = menusystem
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -86,12 +112,18 @@ function Menu:getWidgetSize(id)
|
||||||
return self.widget.w, self.widget.h
|
return self.widget.w, self.widget.h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ACTION FUNCTIONS
|
||||||
|
-- Send actions to the widgets
|
||||||
|
|
||||||
function Menu:cancelAction()
|
function Menu:cancelAction()
|
||||||
if (self.widget.cancel ~= 0) then
|
if (self.widget.cancel ~= 0) then
|
||||||
self.widget.list[self.widget.cancel]:action("key")
|
self.widget.list[self.widget.cancel]:action("key")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the menu every game update
|
||||||
|
|
||||||
function Menu:update(dt)
|
function Menu:update(dt)
|
||||||
-- Cette fonction ne contient rien par défaut
|
-- Cette fonction ne contient rien par défaut
|
||||||
end
|
end
|
||||||
|
@ -114,6 +146,9 @@ function Menu:destroy()
|
||||||
self.destroyed = true
|
self.destroyed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW FUNCTIONS
|
||||||
|
-- Draw the menu and its content
|
||||||
|
|
||||||
function Menu:draw()
|
function Menu:draw()
|
||||||
-- nothing here
|
-- nothing here
|
||||||
end
|
end
|
||||||
|
@ -126,10 +161,16 @@ function Menu:drawCanvas()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- KEYBOARD FUNCTIONS
|
||||||
|
-- Handle key press
|
||||||
|
|
||||||
function Menu:keyreleased(key)
|
function Menu:keyreleased(key)
|
||||||
-- Cette fonction ne contient rien par défaut
|
-- Cette fonction ne contient rien par défaut
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- MOUSE FUNCTIONS
|
||||||
|
-- Handle pointers (clic/touch)
|
||||||
|
|
||||||
function Menu:mousemoved(x, y)
|
function Menu:mousemoved(x, y)
|
||||||
-- Cette fonction ne contient rien par défaut
|
-- Cette fonction ne contient rien par défaut
|
||||||
end
|
end
|
||||||
|
@ -138,6 +179,9 @@ function Menu:mousepressed( x, y, button, istouch )
|
||||||
-- Cette fonction ne contient rien par défaut
|
-- Cette fonction ne contient rien par défaut
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- WIDGET FUNCTIONS
|
||||||
|
-- Handle widgets of the functions
|
||||||
|
|
||||||
function Menu:addWidget(newwidget)
|
function Menu:addWidget(newwidget)
|
||||||
if #self.widget.list == 0 then
|
if #self.widget.list == 0 then
|
||||||
self.widget.selected = 1
|
self.widget.selected = 1
|
||||||
|
@ -168,6 +212,9 @@ function Menu:removeDestroyedWidgets() -- On retire les widgets marquées comme
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- CURSOR FUNCTIONS
|
||||||
|
-- Set or move the cursor of the menu
|
||||||
|
|
||||||
function Menu:setCursor(cursorid)
|
function Menu:setCursor(cursorid)
|
||||||
self.widget.selected = cursorid --math.max(1, math.min(cursorid, #self.widget.list))
|
self.widget.selected = cursorid --math.max(1, math.min(cursorid, #self.widget.list))
|
||||||
end
|
end
|
||||||
|
@ -185,6 +232,9 @@ function Menu:moveCursor(new_selected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- SOUND FUNCTION
|
||||||
|
-- Handle SFX
|
||||||
|
|
||||||
function Menu:setSound(soundasset)
|
function Menu:setSound(soundasset)
|
||||||
self.sound.active = true
|
self.sound.active = true
|
||||||
self.sound.asset = soundasset
|
self.sound.asset = soundasset
|
||||||
|
@ -198,6 +248,9 @@ function Menu:playSelectSound()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- VIEW FUNCTIONS
|
||||||
|
-- Handle the view of the menu
|
||||||
|
|
||||||
function Menu:resetView()
|
function Menu:resetView()
|
||||||
-- ne sert à rien ici, c'est juste pour éviter des crash
|
-- ne sert à rien ici, c'est juste pour éviter des crash
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,34 @@
|
||||||
|
-- widgets :: basic widget object
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
local Widget = {}
|
local Widget = {}
|
||||||
|
|
||||||
BaseWidget = Object:extend()
|
BaseWidget = Object:extend()
|
||||||
TextWidget = BaseWidget:extend()
|
TextWidget = BaseWidget:extend()
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initialize and configure the widget
|
||||||
|
|
||||||
function BaseWidget:new(menu)
|
function BaseWidget:new(menu)
|
||||||
self.menu = menu
|
self.menu = menu
|
||||||
|
|
||||||
|
@ -50,6 +76,9 @@ function BaseWidget:selectAction()
|
||||||
-- Do nothing
|
-- Do nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- DRAW WIDGETS
|
||||||
|
-- Draw the widget
|
||||||
|
|
||||||
function BaseWidget:draw(x, y)
|
function BaseWidget:draw(x, y)
|
||||||
if self.canvas.texture ~= nil then
|
if self.canvas.texture ~= nil then
|
||||||
utils.graphics.resetColor()
|
utils.graphics.resetColor()
|
||||||
|
@ -61,6 +90,9 @@ function BaseWidget:drawSelected(x,y,w,h)
|
||||||
self:draw(x, y, w, h)
|
self:draw(x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- UPDATE FUNCTIONS
|
||||||
|
-- Update the widget
|
||||||
|
|
||||||
function BaseWidget:update(dt)
|
function BaseWidget:update(dt)
|
||||||
if (self.canvas.needRedraw) then
|
if (self.canvas.needRedraw) then
|
||||||
self:redrawCanvas()
|
self:redrawCanvas()
|
||||||
|
@ -68,6 +100,9 @@ function BaseWidget:update(dt)
|
||||||
-- N/A
|
-- N/A
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ACTION FUNCTION
|
||||||
|
-- Functions to handle actions and selection.
|
||||||
|
|
||||||
function BaseWidget:action(source)
|
function BaseWidget:action(source)
|
||||||
--self:destroy()
|
--self:destroy()
|
||||||
end
|
end
|
||||||
|
@ -76,6 +111,7 @@ function BaseWidget:destroy()
|
||||||
self.destroyed = true
|
self.destroyed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TEXT WIDGET
|
||||||
-- Simple text widget
|
-- Simple text widget
|
||||||
|
|
||||||
function TextWidget:new(menu, font, label)
|
function TextWidget:new(menu, font, label)
|
||||||
|
@ -91,7 +127,7 @@ function TextWidget:drawCanvas()
|
||||||
self.font:draw(self.label, w, h, -1, "center")
|
self.font:draw(self.label, w, h, -1, "center")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Add the widget as subvariable to the returned table
|
||||||
Widget.Base = BaseWidget
|
Widget.Base = BaseWidget
|
||||||
Widget.Text = TextWidget
|
Widget.Text = TextWidget
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,31 @@
|
||||||
|
-- widgets/utils :: basic utility functions for the widgets
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
local menuUtils = {}
|
local menuUtils = {}
|
||||||
|
|
||||||
function menuUtils.drawCursor(x, y, w, h)
|
function menuUtils.drawCursor(x, y, w, h)
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
|
|
||||||
love.graphics.rectangle("fill", x, y, 4, 8)
|
love.graphics.rectangle("fill", x, y, 4, 8)
|
||||||
love.graphics.rectangle("fill", x, y, 8, 4)
|
love.graphics.rectangle("fill", x, y, 8, 4)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue