Compare commits

..

No commits in common. "main" and "c3179dcf9d0ccbbe723520d7a6a1223ea5a98021" have entirely different histories.

180 changed files with 1925 additions and 569 deletions

View file

@ -3,7 +3,7 @@
"love",
"loadstring",
"unpack",
"framework",
"birb",
"utils",
"core",
"scenes",

View file

@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
- Project renamed to Epervier Framework and rebased entirely on Sonic Radiance codebase
- Project renamed to Birb and rebased entirely on Sonic Radiance codebase
- New loading system
@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **core/input:** extract virtualpads from the input controller
- **core:** The core is now separated from the rest of the framework
- **core:** The core is now separated from the rest of birb
- **core+assets:** Music are now managed directly by the core

View file

@ -1,40 +1,20 @@
# Épervier Framework
# Birb Love2D Engine
The Épervier Framework is an RPG-oriented framework for Love2D. It aim to work as a set of managers to automatically handle inputs, screen, and several utilities to make game developpement easier and less repetitive. It's also specialized in game with RPG mechanics, with functions to serialize/deserialize easily datas.
Birb aim to be an integrated, simple engine for love2D, in replacement of my old "gamecore" love2D engine. It aim to work as a set of managers to automatically handle inputs, screen, and several utilities to make game developpement easier and less repetitive. It's also specialized in game with RPG mechanics, with functions to serialize/deserialize easily datas.
Épervier use [Classic](https://github.com/rxi/classic/) as its base Object.
Birb use [Classic](https://github.com/rxi/classic/) as its base Object.
## Core features
## How to load Birb
Épervier provide a lot of feature that can be usefull to create an RPG. This is a non-exhaustive list of what the framework can do :
The birb engine must be located in the `birb/` folder to work. After that, all you have to do is to load a gamecore based engine and then.
- Scene system to be able to change your gameplay easily, with transitions
- Easy data loading and parsing via the core.data module
- A save system using data serialization
- Tweening and time support via tween.lua
- A world system with support for camera, multiple hitbox per actor, and two type of physics (bump2D and bump3D) and tiled map loading (via sti.lua)
- A GUI system to make your game more easily have HUD and menus
- Several utilities functions
Note : the `birb` and `utils` global namespace will be used by birb.
## How to load Épervier
````
require "birb"
The framework must be located in the `framework/` folder to work. After that, all you have to do is to load a gamecore based engine and then.
Note : the `framework`, `core`, `game` and `utils` global namespaces will be used by the framework.
```lua
require "framework"
function love.load(args)
framework.start("game", args)
function love.load()
birb.startCore()
end
```
### Launch in debug mode
To launch in debug mode, the love2D game must be launched with a DEBUGLEVEL bigger than 1, for instance :
```sh
love ./examples DEBUGLEVEL=4
```
````

View file

@ -23,7 +23,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Rect = require "framework.classes.2D.rect"
local Rect = require "birb.classes.2D.rect"
local IndexedRect = Rect:extend()
function IndexedRect:new(origin, ox, oy, w, h)

View file

@ -21,7 +21,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Point = require "framework.classes.2D.point"
local Point = require "birb.classes.2D.point"
local Rect = Point:extend()
function Rect:new(x, y, w, h)

View file

@ -21,7 +21,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Point = require "framework.classes.3D.point3D"
local Point = require "birb.classes.3D.point3D"
local Box = Point:extend()
function Box:new(x, y, z, w, h, d)

View file

@ -23,7 +23,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Rect = require "framework.classes.2D.rect"
local Rect = require "birb.classes.2D.rect"
local IndexedRect = Rect:extend()
function IndexedRect:new(origin, ox, oy, oz, w, h, d)

View file

@ -0,0 +1,10 @@
local Color = Object:extend()
Color.BLACK = Color(0,0,0)
Color.WHITE = Color(1,1,1)
function Color:new(r, g, b, a)
end
return Color

View file

View file

@ -28,7 +28,7 @@
]]
local Predicate = Object:extend()
local SimplePredicate = require "framework.classes.predicate.simple"
local SimplePredicate = require "birb.classes.predicate.simple"
function Predicate.createPredicate(data, solver, asker)
local predicate = nil

View file

@ -34,7 +34,7 @@ local SEPARATOR = ":"
local NOT = "not"
local DEFAULT = "default"
SimplePredicate.utils = require "framework.classes.predicate.utils"
SimplePredicate.utils = require "birb.classes.predicate.utils"
function SimplePredicate:new(data, solver, asker)
self.solver = solver

View file

@ -20,9 +20,9 @@
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 Serializable = require "framework.classes.serializable"
local Serializable = require "birb.classes.serializable"
local Serializer = Serializable:extend()
local binser = require("framework.libs.binser")
local binser = require("birb.libs.binser")
function Serializer:new(serializeFields, listSerializable)
Serializer.super.new(self, serializeFields, listSerializable)

View file

@ -1,4 +1,4 @@
local Timer = require "framework.classes.time.timer"
local Timer = require "birb.classes.time.timer"
local TimedFunction = Timer:extend()
function TimedFunction:new(actor, name, func, t)

View file

@ -1,6 +1,6 @@
-- time.lua :: a timer, tweener and timed switch handler.
-- This class need framework.libs.tween to work
-- This class need birb.libs.tween to work
--[[
Copyright © 2019 Kazhnuz
@ -25,9 +25,9 @@
local TweenManager = Object:extend()
local tween = require "framework.libs.tween"
local Timer = require "framework.classes.time.timer"
local TimedFunction = require "framework.classes.time.func"
local tween = require "birb.libs.tween"
local Timer = require "birb.classes.time.timer"
local TimedFunction = require "birb.classes.time.func"
function TweenManager:new(subject)
self.subject = subject
@ -63,10 +63,6 @@ function TweenManager:removeNamedTween(name)
self.tweens[name] = nil
end
function TweenManager:haveTween()
return #self.tweens > 0
end
-- TIMER FUNCTIONS
-- Help to get info from timers

View file

@ -24,8 +24,8 @@
]]
local DataManager = Object:extend()
local DataPack = require "framework.classes.datapack"
local Parser = require "framework.classes.parser"
local DataPack = require "birb.classes.datapack"
local Parser = require "birb.classes.parser"
local index = require "datas.gamedata.index"
function DataManager:new(core)
@ -36,7 +36,7 @@ end
function DataManager:loadDatas()
self.datapacks = {}
if (index.datapack ~= nil) then
if (index.datapacks ~= nil) then
for key, datas in pairs(index.datapacks) do
self.core.debug:debug("datamanager", "loading data for " .. key)
self.datapacks[key] = DataPack(datas[1], datas[2], datas[3], datas[4], datas[5])

View file

@ -38,7 +38,7 @@ function DebugSystem:new(controller, debugLevel)
self.debugLevel = debugLevel or Levels.WARNING
self.active = (self.debugLevel == Levels.DEBUG)
if (self.active) then
lovebird = require "framework.libs.lovebird"
lovebird = require "birb.libs.lovebird"
lovebird.update()
end
end

View file

@ -21,7 +21,7 @@
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 Serializer = require "framework.classes.serializable.serializer"
local Serializer = require "birb.classes.serializable.serializer"
local OptionsManager = Serializer:extend()
local TRANSLATION_PATH = "datas/languages/"

View file

@ -41,6 +41,10 @@ function SceneManager:setScene(scene)
self.nextScene = scene
end
function SceneManager:getScene()
return self.nextScene or self.currentScene
end
function SceneManager:haveStoredScene(name)
return (self.storage[name] ~= nil)
end
@ -90,12 +94,14 @@ 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
end
function SceneManager:mousepressed( x, y, button, istouch )
if (self.currentScene ~= nil) then
self.currentScene:mousepressed( x, y, button, istouch )
self.currentScene.menusystem:mousepressed( x, y, button, istouch )
end
end

View file

@ -24,7 +24,7 @@
local ScreenManager = Object:extend()
local CScreen = require("framework.libs.cscreen")
local CScreen = require("birb.libs.cscreen")
-- INIT FUNCTIONS
-- Initialize and configure the screen manager

View file

@ -1,5 +1,4 @@
-- framework :: The main Épervier Framework script, loading the core and main
-- utilities
-- birb :: The main birb script, loading the core and main utilities
--[[
Copyright © 2021 Kazhnuz
@ -22,32 +21,32 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
framework = {}
birb = {}
-- GLOBAL UTILS/FUNCTION LOADING
-- Load in the global namespace utilities that'll need to be reusable everywhere
-- in the game
Object = require("framework.libs.classic")
utils = require("framework.utils")
enum = require("framework.utils.enum")
Object = require("birb.libs.classic")
utils = require("birb.utils")
enum = require("birb.utils.enum")
framework.Core = require("framework.core")
birb.Core = require("birb.core")
function framework.start(gamemodule, args)
framework.startCore(args)
function birb.start(gamemodule, args)
birb.startCore(args)
if (gamemodule ~= nil) then
framework.startGame(gamemodule)
birb.startGame(gamemodule)
end
end
function framework.startCore(args)
core = framework.Core(args)
function birb.startCore(args)
core = birb.Core(args)
end
function framework.startGame(gamemodule)
function birb.startGame(gamemodule)
local GameObject = require(gamemodule)
game = GameObject()
end
require("framework.callbacks")
require("birb.callbacks")

View file

@ -1,17 +1,18 @@
-- GameSystem :: The main GameSystem subsystem. Basically a big object that handle all the
-- GameSystem-related data like characters, monsters, etc. While the core aim to be
-- reusable at will, the GameSystem is specifically made for the current GameSystem.
-- modules/gamesystem :: a simple save system, based on the Deserialization feature
--[[
Copyright © 2019 Kazhnuz
Copyright © 2021 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
@ -20,83 +21,67 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local GameSystem = require("birb.classes.serializable.serializer"):extend()
local Serializer = require "framework.classes.serializable.serializer"
local GameSystem = Serializer:extend()
local VAR_TO_SERIALIZE = {
"gametime",
"destroyedGizmo",
"variables",
"flags"
}
function GameSystem:new()
function GameSystem:new(varToSerialize, slotNumber)
self.slot = -1
self.slotNumber = 3
self.slotNumber = slotNumber or 1
self.version = core.conf.gameversion or "N/A"
self:reset()
GameSystem.super.new(self, VAR_TO_SERIALIZE)
end
function GameSystem:reset()
self.gametime = 0
self.flags = {}
self.destroyedGizmo = {}
self.variables = {}
self.mapName = ""
varToSerialize = varToSerialize or {}
GameSystem.super.new(self, varToSerialize)
end
function GameSystem:reload()
self:read(self.slot)
end
function GameSystem:read(save_id)
self.slot = save_id
if (self.slot > 0) then
self:deserialize(self:getSaveName())
self:deserialize(self:getSaveName())
end
end
function GameSystem:deleteCurrentSave()
if (self.slot > 0) then
self:delete(self:getSaveName())
self.metadata:remove(self.slot)
self:delete(self:getSaveName())
self.metadata:remove(self.slot)
end
end
function GameSystem:write()
if (self.slot > 0) then
self:serialize(self:getSaveName())
self:serialize(self:getSaveName())
self.metadata:update()
end
end
function GameSystem:getSaveName(saveslot)
local saveslot = saveslot or self.slot
return "save" .. saveslot .. ".save"
end
function GameSystem:resetSaves()
for i=1, self.slotNumber do
self:delete(self:getSaveName(i))
for i = 1, self.slotNumber do
self:delete(self:getSaveName(i))
end
end
function GameSystem:update(dt)
self.gametime = self.gametime + dt
end
function GameSystem:getTime()
return utils.time.getFields(self.gametime)
end
function GameSystem:getTimeString()
function GameSystem:getTimeString()
return utils.time.toString(self.gametime)
end
function GameSystem:printTime()
core.debug:print(self:getTimeString())
end
return GameSystem
return GameSystem

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.drawable"
local Parent = require "birb.modules.gui.elements.drawable"
local AssetElement = Parent:extend()
function AssetElement:new(name, assetType, assetName, x, y,r,sx,sy,ox,oy, opacity)

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.parent"
local Parent = require "birb.modules.gui.elements.parent"
local CanvasElement = Parent:extend()
function CanvasElement:new(name, x, y, w, h, r,sx,sy,ox,oy, opacity)
@ -16,8 +16,6 @@ function CanvasElement:initCanvas()
self.canvas.texture = nil
self.canvas.isAnimated = false
self.canvas.padding = 8
self.canvas.final = nil
self.canvas.dual = false
end
function CanvasElement:updateElement(dt)
@ -32,18 +30,6 @@ function CanvasElement:redraw()
if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:generateTexture()
end
if (self.canvas.dual) then
local w, h = self:getDimensions()
local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2))
love.graphics.setCanvas(canvas)
love.graphics.draw(self.canvas.texture, 0, 0)
self:drawFinalTexture()
self.canvas.final = canvas
love.graphics.setCanvas()
end
end
function CanvasElement:generateTexture()
@ -69,10 +55,6 @@ function CanvasElement:drawTexture()
end
function CanvasElement:drawFinalTexture()
end
function CanvasElement:parseOrigin(origin, size)
if (origin == "center") then
return size/2
@ -85,11 +67,7 @@ end
function CanvasElement:draw()
love.graphics.setColor(1, 1, 1, self.opacity)
local texture = self.canvas.texture
if (self.canvas.dual) then
texture = self.canvas.final
end
love.graphics.draw(texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy)
love.graphics.draw(self.canvas.texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy)
love.graphics.setColor(1, 1, 1, 1)
end

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.parent"
local Parent = require "birb.modules.gui.elements.parent"
local ColorElement = Parent:extend()
function ColorElement:new(name, r, g, b, opacity)

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.parent"
local Parent = require "birb.modules.gui.elements.parent"
local CompositeElement = Parent:extend()
function CompositeElement:new(name, x, y, childrenList)

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.variable"
local Parent = require "birb.modules.gui.elements.variable"
local CounterElement = Parent:extend()
function CounterElement:new(name, fontName, object, varName, nbrs, x, y, align)

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.parent"
local Parent = require "birb.modules.gui.elements.parent"
local DrawableElement = Parent:extend()
function DrawableElement:new(name, drawable, x, y,r,sx,sy,ox,oy, opacity)

View file

@ -1,7 +1,7 @@
local Rect = require "framework.classes.2D.rect"
local Rect = require "birb.classes.2D.rect"
local GuiElement = Rect:extend()
local TweenManager = require "framework.classes.time"
local TweenManager = require "birb.classes.time"
function GuiElement:new(name, x, y, w, h)
GuiElement.super.new(self, x, y, w, h)
@ -19,7 +19,7 @@ function GuiElement:new(name, x, y, w, h)
end
function GuiElement:initWrapper()
self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.scene = core.scenemanager:getScene()
self.gui = self.scene.gui
self.assets = self.scene.assets
end
@ -58,8 +58,8 @@ function GuiElement:setVisibility(visibility)
self.isVisible = visibility
end
function GuiElement:getFocus(widgetId, page)
self.gui:setFocus(self.name, widgetId, page)
function GuiElement:getFocus()
self.gui:setFocus(self.name)
end
function GuiElement:haveFocus()
@ -72,14 +72,6 @@ function GuiElement:looseFocus()
end
end
function GuiElement:setSubFocus()
-- Useless for basic element
end
function GuiElement:isTransforming()
return self.tweens:haveTween()
end
-- UPDATE FUNCTIONS
-- Update the menu every game update

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.parent"
local Parent = require "birb.modules.gui.elements.parent"
local TextElement = Parent:extend()
function TextElement:new(name, fontName, text, x, y, align)

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.drawable"
local Parent = require "birb.modules.gui.elements.drawable"
local TileElement = Parent:extend()
function TileElement:new(name, assetName, id, x, y,r,sx,sy,ox,oy, opacity)

View file

@ -1,4 +1,4 @@
local Parent = require "framework.scenes.gui.elements.text"
local Parent = require "birb.modules.gui.elements.text"
local VariableElement = Parent:extend()
function VariableElement:new(name, fontName, object, varName, x, y, align)

View file

@ -23,12 +23,12 @@
local Gui = Object:extend()
local ElementList = require "framework.scenes.gui.mixins.elements"
local ScreenList = require "framework.scenes.gui.mixins.screens"
local ElementList = require "birb.modules.gui.mixins.elements"
local ScreenList = require "birb.modules.gui.mixins.screens"
Gui:implement(ScreenList)
Gui:implement(ElementList)
local TransformDataStruct = require "framework.structures.tween"
local TransformDataStruct = require "birb.structures.tween"
function Gui:new(scene)
self.scene = scene
@ -122,9 +122,8 @@ function Gui:hideScreen(screenname)
end
function Gui:showScreen(screenname, focusElement, widgetId, page, arbitraryDatas)
self.screens[screenname]:show(focusElement, widgetId, page)
self.screens[screenname]:setDatas(arbitraryDatas)
function Gui:showScreen(screenname)
self.screens[screenname]:show()
end
-- SOUND FUNCTIONS
@ -152,7 +151,7 @@ function Gui:keycheck(keys)
if (haveFocus) then
local elem = self:getFocusedElement()
for key,_ in pairs(keys) do
if (keys[key].isPressed and not elem:isTransforming()) then
if keys[key].isPressed then
elem:keypressed(key)
end
end
@ -164,10 +163,7 @@ end
-- Draw the menu and its content
function Gui:redraw()
for _, element in pairs(self:getVisibleElement(true)) do
element:redraw()
end
for _, element in pairs(self:getVisibleElement(false)) do
for _, element in pairs(self.elements) do
element:redraw()
end
end

View file

@ -142,7 +142,7 @@ function FlowBox:getGraphicalCursorPosition()
local col, line = self.view:getCoord(self.widget:getSelected())
local x = (col) * h
local y = (line - beginline) * h
return x, y, w, h
return self.x + x, self.y + y, w, h
end
return FlowBox

View file

@ -26,7 +26,7 @@ local cwd = (...):gsub('%.grid$', '') .. "."
local Menu = require(cwd .. "parent")
local GridBox = Menu:extend()
local View2D = require "framework.scenes.gui.menus.views.view2D"
local View2D = require "birb.modules.gui.menus.views.view2D"
-- INIT FUNCTIONS
-- Initialize and configure the menu
@ -273,7 +273,7 @@ function GridBox:drawCursor()
local w, h = self:getWidgetSize(slot)
local x = self.slots[slot].x * self.widgetSize.w
local y = self.slots[slot].y * self.widgetSize.h
self:drawGraphicalCursor(x, y, w, h)
self:drawGraphicalCursor(self.x + x, self.y + y, w, h)
end
end

View file

@ -99,7 +99,7 @@ function HListBox:getGraphicalCursorPosition()
local w, h = self:getWidgetSize()
local x = (self.widget:getSelected() - self.view.firstSlot) * w
return x, 0, w, h
return self.x + x,self.y, w, h
end
return HListBox

View file

@ -36,8 +36,6 @@ function ListBox:new(name, x, y, w, h, slotNumber)
ListBox.super.new(self, name, x, y, w, h)
self.h = slotNumber * self.widgetSize.h -- On fait en sorte que la hauteur
-- soit un multiple du nombre de slot et de leur hauteur
self.lateralFunc = nil
self.packAtEnd = false
end
-- UPDATE FUNCTIONS
@ -56,10 +54,6 @@ function ListBox:resetView()
self.view:reset()
end
function ListBox:addLateralAction(func)
self.lateralFunc = func
end
-- KEYBOARD FUNCTIONS
-- Handle input from keyboard/controllers.
@ -75,10 +69,6 @@ function ListBox:moveByKeys(key)
self:playNavigationSound()
self.canvas.needRedraw = true
end
if (self.lateralFunc ~= nil and (key == 'left' or key == 'right')) then
self.widget:lateralAction(self.lateralFunc, key)
end
end
-- POSITION FUNCTIONS
@ -92,7 +82,6 @@ end
-- draw the menu and the rest of content.
function ListBox:getListPart(relativeNumber)
if (self.packAtEnd) then relativeNumber = relativeNumber + math.max(0, self.view.slotNumber - self.widget:lenght()) end
return 0, (relativeNumber) * self.widgetSize.h, self.w, self.widgetSize.h
end
@ -110,7 +99,7 @@ end
function ListBox:getGraphicalCursorPosition()
local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot)
return self:getListPart(self.widget:getSelected() - self.view.firstSlot)
return self.x - self.ox + x,self.y + y - self.oy, w, h
end
return ListBox

View file

@ -1,5 +1,5 @@
local MenuModel = Object:extend()
local Page = require "framework.scenes.gui.menus.model.page"
local Page = require "birb.modules.gui.menus.model.page"
local function updateWidgetByOrder(a, b)
if a.order ~= b.order then
@ -21,7 +21,6 @@ function MenuModel:new()
self.cancel = 0
self.limit = -1
-- self:updateWidgetSize()
self.hoverFunc = nil
end
function MenuModel:clear()
@ -34,7 +33,6 @@ end
function MenuModel:addPage(pageName)
local page = Page()
page.name = pageName
self.pages[pageName] = page
self.currentPage = pageName
return page
@ -60,7 +58,6 @@ end
function MenuModel:switch(pageName)
if (self:pageExists(pageName)) then
self.currentPage = pageName
self:hoverAction()
end
end
@ -73,10 +70,6 @@ function MenuModel:getCurrentPage()
return self:getPage(self.currentPage)
end
function MenuModel:getCurrentPageName()
return self.currentPage
end
-- UPDATE/DRAW FUNCTIONS
-- All the update functions
@ -98,10 +91,6 @@ end
-- ACTION FUNCTIONS
-- All the actions callback used by the widgets
function MenuModel:addHoverAction(func)
self.hoverFunc = func
end
function MenuModel:cancelAction()
local page = self:getCurrentPage()
page:cancelAction()
@ -117,19 +106,6 @@ function MenuModel:selectedAction()
page:selectedAction()
end
function MenuModel:hoverAction()
local page = self:getCurrentPage()
if (self.hoverFunc ~= nil) then
page:hoverAction(self.hoverFunc)
end
end
function MenuModel:lateralAction(func, key)
local page = self:getCurrentPage()
page:lateralAction(func, key)
end
-- WIDGET FUNCTIONS
-- All the functions to handle widgets
@ -191,29 +167,22 @@ end
function MenuModel:trySelectWidget(cursorid)
local page = self:getCurrentPage()
local isSuccess = page:trySelectWidget(cursorid)
if (isSuccess) then
self:hoverAction()
end
return isSuccess
return page:trySelectWidget(cursorid)
end
function MenuModel:setCursor(cursorid)
local page = self:getCurrentPage()
page:setCursor(cursorid)
self:hoverAction()
end
function MenuModel:moveCursorAbsolute(newSelected)
local page = self:getCurrentPage()
page:moveCursorAbsolute(newSelected)
self:hoverAction()
end
function MenuModel:moveCursor(relative)
local page = self:getCurrentPage()
page:moveCursor(relative)
self:hoverAction()
end
-- DRAW

View file

@ -84,18 +84,6 @@ function Page:selectedAction()
end
end
function Page:hoverAction(func)
if (self:widgetExist(self.selected)) then
func(self.widgets[self.selected])
end
end
function Page:lateralAction(func, key)
if (self:widgetExist(self.selected)) then
func(key, self.widgets[self.selected], self.selected, self.name)
end
end
-- WIDGET FUNCTIONS
-- All the functions to handle widgets

View file

@ -21,12 +21,12 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local GuiElement = require "framework.scenes.gui.elements.canvas"
local GuiElement = require "birb.modules.gui.elements.canvas"
local Menu = GuiElement:extend()
local MenuModel = require "framework.scenes.gui.menus.model"
local MenuModel = require "birb.modules.gui.menus.model"
local menuUtils = require "framework.scenes.gui.utils"
local menuUtils = require "birb.modules.gui.utils"
-- INIT FUNCTIONS
-- Initialize and configure functions.
@ -42,19 +42,6 @@ function Menu:new(name, x, y, w, h)
self:updateWidgetSize()
self:initCanvas()
self.cancelFunc = nil
self.canvas.dual = true
end
-- FUNCTIONS FUNCTIONS
-- Add functions to the menu system
function Menu:addCancelAction(func)
self.cancelFunc = func
end
function Menu:addHoverAction(func)
self.widget:addHoverAction(func)
end
-- INTERACTION FUNCTIONS
@ -125,38 +112,21 @@ function Menu:getPage(pageName)
self.widget:getPage(pageName)
end
function Menu:getCurrentPageName()
return self.widget:getCurrentPageName()
end
function Menu:switch(pageName)
self.widget:switch(pageName)
self:resetView()
self.canvas.needRedraw = true
end
function Menu:back()
self.widget:back()
self:resetView()
self.canvas.needRedraw = true
end
function GuiElement:setSubFocus(widgetId, pageName)
if (pageName ~= nil) then
self.widget:switch(pageName)
end
self.widget:trySelectWidget(widgetId)
end
-- ACTION FUNCTIONS
-- Send actions to the widgets
function Menu:cancelAction()
if (self.cancelFunc ~= nil) then
self.cancelFunc(self)
else
self.widget:cancelAction()
end
self.widget:cancelAction()
end
function Menu:clear()
@ -181,12 +151,9 @@ end
function Menu:drawElement()
self:draw()
end
function Menu:drawFinalTexture()
if (self:haveFocus()) then
local x, y, w, h = self:getGraphicalCursorPosition()
self:drawGraphicalCursor(self.canvas.padding + x, self.canvas.padding + y, w, h)
self:drawGraphicalCursor(x, y, w, h)
end
end
@ -212,7 +179,6 @@ end
function Menu:addWidget(newwidget)
self.widget:addWidget(newwidget)
self.canvas.needRedraw = true
end
function Menu:setCancelWidget(id)

View file

@ -31,6 +31,7 @@ end
function View1D:reset()
self.firstSlot = 1
print("reset")
end
function View1D:updateFirstSlot(widgetID)

View file

@ -21,7 +21,7 @@
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 View1D = require "framework.scenes.gui.menus.views.view1D"
local View1D = require "birb.modules.gui.menus.views.view1D"
local View2D = View1D:extend()
function View2D:new(colNumber, lineNumber)

View file

@ -37,7 +37,6 @@ function BaseWidget:new(menuName)
self.canvas = {}
self.canvas.texture = nil
self.canvas.needRedraw = true
self.canvas.isAnimated = false
self.order = 0
self:register()
@ -46,7 +45,7 @@ function BaseWidget:new(menuName)
end
function BaseWidget:initWrapper()
self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.scene = core.scenemanager:getScene()
self.gui = self.scene.gui
self.assets = self.scene.assets
end
@ -61,11 +60,11 @@ function BaseWidget:getMenuByName(name)
end
function BaseWidget:getScene()
return core.scenemanager.nextScene or core.scenemanager.currentScene
return core.scenemanager:getScene()
end
function BaseWidget:getAssets()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
local scene = core.scenemanager:getScene()
return scene.assets
end
@ -75,7 +74,7 @@ function BaseWidget:register()
end
function BaseWidget:redraw()
if (self.canvas.needRedraw or self.canvas.isAnimated) then
if (self.canvas.needRedraw) then
self:generateTexture()
end
end

View file

@ -24,7 +24,7 @@
local Widget = {}
-- Add the widget as subvariable to the returned table
Widget.Base = require "framework.scenes.gui.menus.widgets.base"
Widget.Text = require "framework.scenes.gui.menus.widgets.text"
Widget.Base = require "birb.modules.gui.menus.widgets.base"
Widget.Text = require "birb.modules.gui.menus.widgets.text"
return Widget

View file

@ -20,7 +20,7 @@
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 BaseWidget = require "framework.scenes.gui.menus.widgets.base"
local BaseWidget = require "birb.modules.gui.menus.widgets.base"
local TextWidget = BaseWidget:extend()
-- TEXT WIDGET
@ -40,9 +40,8 @@ end
function TextWidget:addLabel(label, position)
local complexLabel = {}
assert(label ~= nil, "Label can't be nil")
complexLabel.label = label
complexLabel.position = position or "left"
complexLabel.position = position
table.insert(self.labels, complexLabel)
end

View file

@ -17,14 +17,11 @@ function ElementList:deleteElement(name)
self.elements[name] = nil
end
function ElementList:setFocus(name, widgetId, page)
function ElementList:setFocus(name)
assert(self:elementExists(name), "Element " .. name .. " doesn't exists")
self:storeLastFocus()
self.focusedElement = name
self.elements[name].isVisible = true
if (widgetId ~= nil) then
self.elements[name]:setSubFocus(widgetId, page)
end
end
function ElementList:removeFocus()

View file

@ -13,8 +13,4 @@ function ScreenList:deleteScreen(name)
self.screens[name] = nil
end
function ScreenList:getScreen(name)
return self.screens[name]
end
return ScreenList

View file

@ -1,14 +1,17 @@
local GuiScreen = Object:extend()
local ElementList = require "framework.scenes.gui.mixins.elements"
local ElementList = require "birb.modules.gui.mixins.elements"
local ScreenList = require "birb.modules.gui.mixins.screens"
GuiScreen:implement(ScreenList)
GuiScreen:implement(ElementList)
local TweenManager = require "framework.classes.time"
local ScreenSet = require "framework.scenes.gui.screen.screenset"
local TweenManager = require "birb.classes.time"
local elementDataStruct = require "framework.structures.elementData"
local elementDataStruct = require "birb.structures.elementData"
function GuiScreen:new(name)
function GuiScreen:new(name, controller)
self:initWrapper()
self.controller = controller or self.gui
self.name = name
self.isVisible = false
self.transforms = {}
@ -16,80 +19,44 @@ function GuiScreen:new(name)
self:reset()
self:registerElements()
self.gui:addScreen(name, self)
self.defaultFocus = nil
self.controller:addScreen(name, self)
end
function GuiScreen:initWrapper()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
local scene = core.scenemanager:getScene()
self.scene = scene
self.gui = scene.gui
-- Présent pour la compatibilité
self.controller = self.gui
self.assets = scene.assets
end
function GuiScreen:update(dt)
self.tweens:update(dt)
end
function GuiScreen:show(focusElement, widgetId, page)
self:showSimple(focusElement, widgetId, page)
if (self.set ~= nil) then
self.set.owner:show()
for _, screen in pairs(self.screens) do
if (screen ~= nil) then
screen:update(dt)
end
end
end
function GuiScreen:showSimple(focusElement, widgetId, page)
focusElement = focusElement or self.defaultFocus
function GuiScreen:show()
if (not self.isVisible) then
self.isVisible = true
local delay = 0
if (self.set ~= nil) then
delay = self.set:setCurrentScreen(self.name)
end
if (self.transforms["show"] ~= nil) then
if (delay == 0) then
self:showWithSubScreen(focusElement, widgetId, page)
else
self.tweens:newFunc(delay, "focus", function () self:showWithSubScreen(focusElement, widgetId, page) end)
end
self:playTransform("show")
end
end
end
function GuiScreen:showWithSubScreen(focusElement, widgetId, page)
self:playTransform("show")
if (focusElement ~= nil) then
self.gui:setFocus(focusElement, widgetId, page)
end
if (self.subscreens ~= nil) then
self.subscreens:show()
end
end
function GuiScreen:setDatas(datas)
end
function GuiScreen:hide()
local time = 0
if (self.isVisible) then
if (self.transforms["hide"] ~= nil) then
time = self:playTransform("hide")
local time = self:playTransform("hide")
print(time)
self.tweens:newFunc(time, "hide", function ()
self.isVisible = false
end)
end
if (self.subscreens ~= nil) then
self.subscreens:hideCurrent()
end
end
return time
end
function GuiScreen:addTransform(name, transform)
@ -102,6 +69,7 @@ end
function GuiScreen:reset()
self:initElements()
self:initScreens()
end
function GuiScreen:registerElements()
@ -136,25 +104,4 @@ function GuiScreen:createElements()
-- Empty function
end
function GuiScreen:setParentSet(set)
self.set = set
end
function GuiScreen:addSubscreen(screen)
self:initSubscreen()
self.subscreens:add(screen)
end
function GuiScreen:showSubscreen(screenname)
if (self.subscreens ~= nil) then
self.subscreens:show(screenname)
end
end
function GuiScreen:initSubscreen()
if (self.subscreens == nil) then
self.subscreens = ScreenSet(self)
end
end
return GuiScreen

View file

@ -24,10 +24,10 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local ListBox = require "framework.scenes.gui.menus.listbox"
local ListBox = require "birb.modules.gui.menus.listbox"
local TextMenu = ListBox:extend()
TextMenu.baseWidgets = require "framework.scenes.gui.textmenu.widgets"
TextMenu.baseWidgets = require "birb.modules.gui.textmenu.widgets"
local BASE_PADDING = 8
@ -41,7 +41,7 @@ function TextMenu:new(name, font, x, y, w, slotNumber, padding, lineSize)
TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber)
end
function TextMenu:addItem(text, position, func, type, additionnalItems, color, additionnalDatas)
function TextMenu:addItem(text, position, func, type, additionnalItems, color)
local widget = TextMenu.baseWidgets.Base(self.name, text, position)
widget:setFunc(func)
widget.type = type or "select"
@ -53,9 +53,6 @@ function TextMenu:addItem(text, position, func, type, additionnalItems, color, a
if (color ~= nil) then
widget:setColor(color[1], color[2], color[3])
end
if (additionnalDatas ~= nil) then
widget.datas = additionnalDatas
end
end
function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget)
@ -66,7 +63,7 @@ function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidge
end
function TextMenu:setFont(fontName)
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
local scene = core.scenemanager:getScene()
self.font = scene.assets:getFont(fontName)
end

View file

@ -21,7 +21,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local TextMenuWidget = require "framework.scenes.gui.textmenu.widgets.basic"
local TextMenuWidget = require "birb.modules.gui.textmenu.widgets.basic"
local BackWidget = TextMenuWidget:extend()

View file

@ -23,7 +23,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local TextWidget = require "framework.scenes.gui.menus.widgets.text"
local TextWidget = require "birb.modules.gui.menus.widgets.text"
local TextMenuWidget = TextWidget:extend()

View file

@ -24,8 +24,8 @@
local Widget = {}
-- Add the widget as subvariable to the returned table
Widget.Base = require "framework.scenes.gui.textmenu.widgets.basic"
Widget.SubMenu= require "framework.scenes.gui.textmenu.widgets.submenu"
Widget.Back = require "framework.scenes.gui.textmenu.widgets.back"
Widget.Base = require "birb.modules.gui.textmenu.widgets.basic"
Widget.SubMenu= require "birb.modules.gui.textmenu.widgets.submenu"
Widget.Back = require "birb.modules.gui.textmenu.widgets.back"
return Widget

View file

@ -22,7 +22,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local TextMenuWidget = require "framework.scenes.gui.textmenu.widgets.basic"
local TextMenuWidget = require "birb.modules.gui.textmenu.widgets.basic"
local SubmenuWidget = TextMenuWidget:extend()

View file

@ -0,0 +1,231 @@
-- flowbox :: flexible box menu, that handle in grid 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 cwd = (...):gsub('%.flowbox$', '') .. "."
local Menu = require(cwd .. "parent")
local FlowBox = Menu:extend()
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)
self.view = {}
self.view.slotNumber = slots_hor * slots_vert
self.view.lineNumber = slots_vert
self.view.colNumber = slots_hor
self.view.firstSlot = 1
FlowBox.super.new(self, menusystem, name, x, y, w, h)
self.widget.h = math.floor( self.h / slots_vert )
self.widget.w = math.floor( self.w / slots_hor )
self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur
self.w = slots_hor * self.widget.w -- et la largeur
-- 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
function FlowBox:update(dt)
self:updateView()
self:updateSelectedWidget(dt)
end
function FlowBox:updateView()
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.view.firstSlot)
if line < beginline then
beginline = line
end
if line > beginline + self.view.lineNumber - 1 then
beginline = line - self.view.lineNumber + 1
end
if beginline < 0 then
beginline = 0
end
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
line = math.floor(id_selected / self.view.colNumber)
col = id_selected - (line * self.view.colNumber)
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)
if new_line < 0 then
new_line = lastline
end
if new_line > lastline then
new_line = 0
end
if (new_line == lastline) then
if new_col < 0 then
new_col = lastcol
end
if new_col > lastcol then
if (line == lastline) then
new_col = 0
else
new_col = lastcol
end
end
else
if new_col < 0 then
new_col = self.view.colNumber - 1
end
if new_col == self.view.colNumber then
new_col = 0
end
end
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
self:moveCursor(col - 1, line)
end
if key == 'right' then
self:moveCursor(col + 1, line)
end
if key == 'up' then
self:moveCursor(col, line - 1)
end
if key == 'down' then
self:moveCursor(col, line + 1)
end
if key == "A" then
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
self.widget.list[self.widget.selected]:action("key")
end
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)
local newcol, newline, widget_selected
newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widget.w)
widget_selected = (newline * self.view.colNumber) + newcol + 1
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self:getFocus()
end
end
function FlowBox:mousepressed(x, y, button, isTouch)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.view.firstSlot)
local newline, newcol, widget_selected
newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widget.w)
widget_selected = (newline * self.view.colNumber) + newcol + 1
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self:getFocus()
self.widget.list[self.widget.selected]:action("pointer")
end
end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function FlowBox:draw()
self:updateView()
local widgety = self.y
local widgetx = self.x
for i,v in ipairs(self.widget.list) do
if (i >= self.view.firstSlot) and (i < self.view.firstSlot + self.view.slotNumber) then
v:draw(widgetx, widgety, self.widget.w, self.widget.h)
if self.widget.selected == i and self:haveFocus() == true then
v:drawSelected(widgetx, widgety, self.widget.w, self.widget.h)
else
v:draw(widgetx, widgety, self.widget.w, self.widget.h)
end
widgetx = widgetx + self.widget.w
if widgetx == (self.x + self.w) then
widgetx = self.x
widgety = widgety + self.widget.h
end
end
end
end
function FlowBox:drawCursor()
self:updateView()
local begincol, beginline = self:getCoord(self.view.firstSlot)
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local w, h = self:getWidgetSize()
local col, line = self:getCoord(self.widget.selected)
local x = (col) * h
local y = (line - beginline) * h
menuutils.drawCursor(self.x + x, self.y + y, w, h)
end
end
return FlowBox

View file

@ -0,0 +1,277 @@
-- grid :: a menu with arbitrary widget placement and size on a grid.
--[[
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 menuutils = require(cwd .. "widgets.utils")
-- INIT FUNCTIONS
-- Initialize and configure the menu
function GridBox:new(menusystem, name, x, y, w, h, colNumber, lineNumber)
self.view = {}
self.view.slotNumber = colNumber * lineNumber
self.view.colNumber = colNumber
self.view.lineNumber = lineNumber
self.view.firstSlot = 1
GridBox.super.new(self, menusystem, name, x, y, w, h)
self.h = lineNumber * self.widget.h -- On fait en sorte que la hauteur
self.w = colNumber * self.widget.w -- et la largeur
-- soit un multiple du nombre de slot et de leur dimensions
self.cursor = {}
self.cursor.x = 0
self.cursor.y = 0
-- La gridbox possède la particularité de pouvoir fusioner des slots, on fait
-- donc une liste de slots disponibles, qui serviront par la suite.
self.slots = {}
end
function GridBox:addSlot(widgetID, x, y, w, h)
local slot = {}
slot.x = x
slot.y = y
slot.w = w
slot.h = h
slot.widgetID = widgetID
table.insert(self.slots, slot)
end
function GridBox:updateWidgetSize()
self.widget.h = math.floor( self.h / self.view.lineNumber )
self.widget.w = math.floor( self.w / self.view.colNumber )
end
-- INFO FUNCTIONS
-- Get the info of the widgets
function GridBox:getWidgetSize(id)
local slot = self:getWidgetSlot(id)
if slot == 0 then
return 1, 1
else
return self.widget.w * self.slots[slot].w, self.widget.h * self.slots[slot].h
end
end
function GridBox:getSlotHitbox(slot)
local x, y, w, h
x = self.slots[slot].x * self.widget.w
y = self.slots[slot].y * self.widget.h
w = self.slots[slot].w * self.widget.w
h = self.slots[slot].h * self.widget.h
return x, y, w, h
end
function GridBox:getSlotCenter(slot)
local x, y, w, h = self:getSlotHitbox(slot)
return x + (w/2), y + (h/2)
end
function GridBox:getWidgetID(slot)
local widgetID
if self.slots[slot] ~= nil then
widgetID = self.slots[slot].widgetID
else
widgetID = 0
end
return widgetID
end
function GridBox:haveWidget(slot)
local id = self:getWidgetID(slot)
return self.widget.list[id] ~= nil
end
function GridBox:getWidgetSlot(widgetID)
local slot = 0
for i,v in ipairs(self.slots) do
if (self.slots[i].widgetID == widgetID) then
slot = i
end
end
return slot
end
function GridBox:getWidgetAtPoint(x, y)
local x = x or 0
local y = y or 0
local widgetID = nil
for i,v in ipairs(self.slots) do
local xx, yy, ww, hh = self:getSlotHitbox(i)
if (x >= xx) and (y >= yy) and (x < xx + ww) and (y < yy + hh) then
widgetID = v.widgetID
end
end
return widgetID
end
-- UPDATE FUNCTIONS
-- Update the Grid and its view
function GridBox:update(dt)
self.view.firstSlot = 1
self:updateSelectedWidget(dt)
end
-- KEYS FUNCTIONS
-- Handle the keyboard/manette functions
function GridBox:keyreleased(key, code)
local slotID = self:getWidgetSlot(self.widget.selected)
local col, line = self.cursor.x, self.cursor.y
if key == 'left' then
self:moveCol(-1)
end
if key == 'right' then
self:moveCol(1)
end
if key == 'up' then
self:moveLine(-1)
end
if key == 'down' then
self:moveLine(1)
end
if key == "A" and self.widget.selected <= #self.widget.list then
self.widget.list[self.widget.selected]:action("key")
end
end
function GridBox:moveCol(direction)
local orig_x, orig_y = self:getSlotCenter(self.widget.selected)
local distance = self.w -- on met directement à la distance max possible le système
local nearastWidget = 0
for i,v in ipairs(self.slots) do
local xx, yy = self:getSlotCenter(i)
-- On commence par vérifier si le slot est bien positionné par rapport au
-- widget de base
if utils.math.sign(xx - orig_x) == direction then
if utils.math.pointDistance(orig_x, orig_y, xx, yy) < distance then
distance = utils.math.pointDistance(orig_x, orig_y, xx, yy)
nearastWidget = v.widgetID
end
end
end
if nearastWidget ~= 0 then
self.widget.selected = nearastWidget
end
end
function GridBox:moveLine(direction)
local orig_x, orig_y = self:getSlotCenter(self.widget.selected)
local distance = self.h -- on met directement à la distance max possible le système
local nearastWidget = 0
for i,v in ipairs(self.slots) do
local xx, yy = self:getSlotCenter(i)
-- On commence par vérifier si le slot est bien positionné par rapport au
-- widget de base
if utils.math.sign(yy - orig_y) == direction then
if utils.math.pointDistance(orig_x, orig_y, xx, yy) < distance then
distance = utils.math.pointDistance(orig_x, orig_y, xx, yy)
nearastWidget = v.widgetID
end
end
end
if nearastWidget ~= 0 then
self.widget.selected = nearastWidget
end
end
-- MOUSE FUNCTIONS
-- Handle the mouse and activate the widgets with it
function GridBox:mousemoved(x, y)
local widgetID = self:getWidgetAtPoint(x, y)
if widgetID ~= nil then
self.widget.selected = widgetID
self:getFocus()
end
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
end
function GridBox:mousepressed(x, y, button, isTouch)
local widgetID = self:getWidgetAtPoint(x, y)
if widgetID ~= nil then
self.widget.selected = widgetID
self:getFocus()
if #self.widget.list > 0 and self.widget.selected > 1 and self.widget.selected <= #self.widget.list then
self.widget.list[self.widget.selected]:action("pointer")
end
end
end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function GridBox:draw()
for i,v in ipairs(self.slots) do
if self:haveWidget(i) then
local widgetx = self.x + (v.x * self.widget.w)
local widgety = self.y + (v.y * self.widget.h)
if self.widget.selected == v.widgetID and self:haveFocus() == true then
self.widget.list[v.widgetID]:drawSelected(widgetx, widgety)
else
self.widget.list[v.widgetID]:draw(widgetx, widgety)
end
end
end
end
function GridBox:drawCursor()
self:updateView()
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local slot = self:getWidgetSlot(self.widget.selected)
local w, h = self:getWidgetSize(slot)
local x = self.slots[slot].x * self.widget.w
local y = self.slots[slot].y * self.widget.h
menuutils.drawCursor(self.x + x, self.y + y, w, h)
end
end
return GridBox

View file

@ -0,0 +1,149 @@
-- 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 Menu = require(cwd .. "parent")
local HListBox = Menu:extend()
local menuutils = require(cwd .. "widgets.utils")
-- INIT FUNCTIONS
-- Initialize and configure functions.
function HListBox:new(menusystem, name, x, y, w, h, slotNumber)
self.view = {}
self.view.slotNumber = slotNumber
self.view.firstSlot = 1
HListBox.super.new(self, menusystem, name, x, y, w, h)
self.w = slotNumber * self.widget.w -- On fait en sorte que la hauteur
-- soit un multiple du nombre de slot et de leur hauteur
end
-- UPDATE FUNCTIONS
-- Update the menu every step.
function HListBox:updateWidgetSize()
self.widget.h = self.h
self.widget.w = math.floor( self.w / self.view.slotNumber )
end
function HListBox:update(dt)
self:updateView()
self:updateSelectedWidget(dt)
end
function HListBox:updateView()
if self.widget.selected < self.view.firstSlot then
self.view.firstSlot = self.widget.selected
end
if self.widget.selected > self.view.firstSlot + self.view.slotNumber - 1 then
self.view.firstSlot = self.widget.selected - self.view.slotNumber + 1
end
if self.view.firstSlot < 1 then
self.view.firstSlot = 1
end
end
-- KEYBOARD FUNCTIONS
-- Handle key check.
function HListBox:keyreleased(key, code)
if key == 'left' then
self:moveCursor(self.widget.selected - 1)
end
if key == 'right' then
self:moveCursor(self.widget.selected + 1)
end
if key == "A" then
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
self.widget.list[self.widget.selected]:action("key")
end
end
if key == "B" then
if (self.widget.cancel >= 1 and self.widget.cancel <= #self.widget.list) then
self.widget.list[self.widget.cancel]:action("key")
end
end
end
-- MOUSE FUNCTIONS
-- Click and stuff like that.
function HListBox:mousemoved(x, y)
local widget_selected = self.view.firstSlot + math.floor(x / self.widget.w)
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self:getFocus()
end
end
function HListBox:mousepressed(x, y, button, isTouch)
local widget_selected = self.view.firstSlot + math.floor(x / self.widget.w)
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self:getFocus()
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action("pointer")
end
end
end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function HListBox:draw()
self:updateView()
local widgetx = self.x
for i,v in ipairs(self.widget.list) do
if (i >= self.view.firstSlot) and (i < self.view.firstSlot + self.view.slotNumber) then
v:draw(widgetx, self.y, self.widget.w, self.h)
if self.widget.selected == i and self:haveFocus() == true then
v:drawSelected(widgetx, self.y, self.widget.w, self.h)
else
v:draw(widgetx, self.y, self.widget.w, self.h)
end
widgetx = widgetx + self.widget.w
end
end
end
function HListBox:drawCursor()
self:updateView()
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local w, h = self:getWidgetSize()
local x = (self.widget.selected - self.view.firstSlot) * w
menuutils.drawCursor(self.x + x,self.y, w, h)
end
end
return HListBox

View file

@ -0,0 +1,290 @@
-- 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 MenuSystem = Object:extend()
-- Load the differents menu object to get an easy access
MenuSystem.Parent = require(cwd .. "parent")
MenuSystem.ListBox = require(cwd .. "listbox")
MenuSystem.FlowBox = require(cwd .. "flowbox")
MenuSystem.Grid = require(cwd .. "grid")
-- load widgets object
MenuSystem.Widget = require(cwd .. "widgets")
-- INIT FUNCTIONS
-- Initialize and configure the menu controller
function MenuSystem:new(scene)
self.scene = scene
self.menus = {}
self.focusedMenu = ""
self.isActive = true
self.lockWorld = false
self.lockAssets = false
end
function MenuSystem:reset()
self.menus = {}
end
-- ACTIVATION FUNCTIONS
-- Activate and deactivate the whole menusystem
function MenuSystem:activate()
self.isActive = true
if (self.lockWorld) then
if (self.scene.world ~= nil) then
self.scene.world:setActivity(false)
end
end
if (self.lockAssets) then
if (self.scene.assets ~= nil) then
self.scene.assets:setActivity(false)
end
end
end
function MenuSystem:deactivate()
self.isActive = false
if (self.lockWorld) then
if (self.scene.world ~= nil) then
self.scene.world:setActivity(true)
end
end
if (self.lockAssets) then
if (self.scene.assets ~= nil) then
self.scene.assets:setActivity(true)
end
end
end
function MenuSystem:getActiveState()
return self.isActive
end
function MenuSystem:lockWorldWhenActive(state)
self.lockWorld = state
end
function MenuSystem:lockAssetsWhenActive(state)
self.lockAssets = state
end
-- MENUS FUNCTIONS
-- Controle the menus of the menusystem
function MenuSystem:addMenu(name, menu)
self.menus[name] = menu
end
function MenuSystem:menuExist(name)
return (self.menus[name] ~= nil)
end
function MenuSystem:switchMenu(menu)
for k,v in pairs(self.menus) do
if k == menu then
v:getFocus()
v:setVisibility(true)
v:setActivity(true)
else
v:setVisibility(false)
v:setActivity(false)
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)
for k,v in pairs(self.menus) do
v:setVisibility(visibility)
end
end
function MenuSystem:setAllMenuActivity(activity)
for k,v in pairs(self.menus) do
v.isActive = activity
end
end
function MenuSystem:removeDestroyedMenus()
-- On retire les entitées marquées comme supprimées
for k,v in pairs(self.menus) do
if (v.isDestroyed == true) then
self.menus[k] = nil
end
end
end
-- SOUND FUNCTIONS
-- Add sounds to every menus
function MenuSystem:setSoundFromSceneAssets(soundname)
for k,v in pairs(self.menus) do
v:setSoundFromSceneAssets(soundname)
end
end
function MenuSystem:setSound(soundasset)
for k,v in pairs(self.menus) do
v:setSound(soundasset)
end
end
-- UPDATE FUNCTIONS
-- Update the menus of the menusystem
function MenuSystem:update(dt)
if (self.isActive) then
self:removeDestroyedMenus()
for k,v in pairs(self.menus) do
v:update(dt)
v:updateWidgets(dt)
end
end
end
function MenuSystem:keycheck()
if (self.isActive) then
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
end
-- MOUSE FUNCTIONS
-- Send mouse inputs to the menu
function MenuSystem:mousemoved(x, y, dx, dy)
if (self.isActive) then
for k,v in pairs(self.menus) do
if v.isActive then
if (x > v.x) and (x < v.x + v.w) and (y > v.y) and (y < v.y + v.h) then
v:mousemoved(x - v.x, y - v.y)
break;
end
end
end
end
end
function MenuSystem:mousepressed( x, y, button, istouch )
if (self.isActive) then
for k,v in pairs(self.menus) do
if v.isActive then
if (x > v.x) and (x < v.x + v.w) and (y > v.y) and (y < v.y + v.h) then
v:mousepressed(x - v.x, y - v.y, button, istouch )
break;
end
end
end
end
end
-- DRAW FUNCTIONS
-- All functions to draw the menus of the menusystem
function MenuSystem:getDrawList()
local drawList = {}
for k,v in pairs(self.menus) do
local drawObject = {}
drawObject.name = k
drawObject.depth = v.depth
table.insert(drawList, drawObject)
end
table.sort(drawList, function(a,b) return a.depth > b.depth end)
return drawList
end
function MenuSystem:draw(dt)
if (self.isActive) then
-- Draw all the menus
self.drawList = self:getDrawList()
for i,v in ipairs(self.drawList) do
local v2 = self.menus[v.name]
if (v2.isVisible) then
v2:draw(dt)
end
end
if self.menus[self.focusedMenu] ~= nil then
if (self.menus[self.focusedMenu].isVisible) then
self.menus[self.focusedMenu]:drawCursor()
end
end
end
end
return MenuSystem

View file

@ -0,0 +1,147 @@
-- 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 Menu = require(cwd .. "parent")
local ListBox = Menu:extend()
local menuutils = require(cwd .. "widgets.utils")
-- INIT FUNCTIONS
-- Initialize and configure functions.
function ListBox:new(menusystem, name, x, y, w, h, slotNumber)
self.view = {}
self.view.slotNumber = slotNumber
self.view.firstSlot = 1
ListBox.super.new(self, menusystem, name, x, y, w, h)
self.h = slotNumber * self.widget.h -- On fait en sorte que la hauteur
-- soit un multiple du nombre de slot et de leur hauteur
end
-- UPDATE FUNCTIONS
-- Update the menu every step.
function ListBox:updateWidgetSize()
self.widget.h = math.floor( self.h / self.view.slotNumber )
self.widget.w = self.w
end
function ListBox:update(dt)
self:updateView()
self:updateSelectedWidget(dt)
end
function ListBox:updateView()
if self.widget.selected < self.view.firstSlot then
self.view.firstSlot = self.widget.selected
end
if self.widget.selected > self.view.firstSlot + self.view.slotNumber - 1 then
self.view.firstSlot = self.widget.selected - self.view.slotNumber + 1
end
if self.view.firstSlot < 1 then
self.view.firstSlot = 1
end
end
-- KEYBOARD FUNCTIONS
-- Handle input from keyboard/controllers.
function ListBox:keyreleased(key, code)
if key == 'up' then
self:moveCursor(self.widget.selected - 1)
end
if key == 'down' then
self:moveCursor(self.widget.selected + 1)
end
if key == "A" then
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
self.widget.list[self.widget.selected]:action("key")
end
end
if key == "B" then
self:cancelAction()
end
end
-- MOUSE FUNCTIONS
-- Handle input from pointers.
function ListBox:mousemoved(x, y)
local widget_selected = self.view.firstSlot + math.floor(y / self.widget.h)
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self:getFocus()
end
end
function ListBox:mousepressed(x, y, button, isTouch)
local widget_selected = self.view.firstSlot + math.floor(y / self.widget.h)
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self:getFocus()
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action("pointer")
end
end
end
-- DRAW FUNCTIONS
-- draw the menu and the rest of content.
function ListBox:draw()
self:updateView()
local widgety = self.y
for i,v in ipairs(self.widget.list) do
if (i >= self.view.firstSlot) and (i < self.view.firstSlot + self.view.slotNumber) then
if self.widget.selected == i and self:haveFocus() == true then
v:drawSelected(self.x, widgety, self.w, self.widget.h)
else
utils.graphics.resetColor()
v:draw(self.x, widgety, self.w, self.widget.h)
end
widgety = widgety + self.widget.h
end
end
end
function ListBox:drawCursor()
self:updateView()
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local w, h = self:getWidgetSize()
local y = (self.widget.selected - self.view.firstSlot) * h
menuutils.drawCursor(self.x,self.y + y, w, h)
end
end
return ListBox

View file

@ -0,0 +1,302 @@
-- 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 function updateWidgetByOrder(a, b)
if a.order ~= b.order then
return a.order < b.order
else
return a.creationID < b.creationID
end
end
-- INIT FUNCTIONS
-- Initialize and configure functions.
function Menu:new(menusystem, name, x, y, w, h)
self.menusystem = menusystem
self.name = name
self.x = x
self.y = y
self.w = w
self.h = h
self.widget = {}
self.widget.list = {}
self.widget.selected = 0
self.widget.selectedPrevious = 0
self.widget.cancel = 0
self:updateWidgetSize()
self.isDestroyed = false
self.isVisible = true
self.isActive = true
self.isLocked = false
self.isAlwaysVisible = false
self.depth = 0
self:resetSound()
self:register()
end
function Menu:setDepth(depth)
self.depth = depth or 0
end
function Menu:setVisibility(visibility)
if self.isLocked == false and self.isAlwaysVisible == false then
-- if the menu is locked (thus is always active), it should also
-- be always visible.
self.isVisible = visibility
else
self.isVisible = true
end
end
function Menu:setActivity(activity)
if self.isLocked == false then
self.isActive = activity
else
self.isActive = true
end
end
function Menu:lock(lock)
self.isLocked = lock
end
function Menu:lockVisibility(lock)
self.isAlwaysVisible = lock
end
function Menu:getFocus()
self.menusystem.focusedMenu = self.name
end
function Menu:haveFocus()
return (self.menusystem.focusedMenu == self.name)
end
function Menu:register()
self.menusystem:addMenu(self.name, self)
end
function Menu:setCancelWidget(id)
self.widget.cancel = #self.widget.list
end
function Menu:updateWidgetSize()
self.widget.h = 0
self.widget.w = 0
end
function Menu:getWidgetSize(id)
return self.widget.w, self.widget.h
end
function Menu:getWidgetNumber()
return #self.widget.list
end
-- ACTION FUNCTIONS
-- Send actions to the widgets
function Menu:cancelAction()
if (self.widget.cancel >= 1 and self.widget.cancel <= #self.widget.list) then
self.widget.list[self.widget.cancel]:action("key")
end
end
function Menu:clear()
self.widget.list = {}
self.widget.cancel = 0
end
function Menu:resize(x,y,w,h)
self.x = x
self.y = y
self.w = w
self.h = h
self:updateWidgetSize()
end
function Menu:destroy()
self.isDestroyed = true
end
function Menu:updateWidgetsOrder()
table.sort(self.widget.list, updateWidgetByOrder)
end
-- UPDATE FUNCTIONS
-- Update the menu every game update
function Menu:update(dt)
-- Cette fonction ne contient rien par défaut
self:updateSelectedWidget(dt)
end
function Menu:updateSelectedWidget(dt)
if (self.widget.selected ~= self.widget.previous) and (self.isActive) then
if (self.widget.list[self.widget.selected] ~= nil) then
self.widget.list[self.widget.selected]:selectAction()
self.widget.previous = self.widget.selected
end
end
if (self.widget.list[self.widget.selected] ~= nil) then
self.widget.list[self.widget.selected]:updateSelected(dt)
end
end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function Menu:draw()
-- nothing here
end
function Menu:drawCursor()
-- nothing here
end
function Menu:drawCanvas()
end
-- KEYBOARD FUNCTIONS
-- Handle key press
function Menu:keyreleased(key)
-- Cette fonction ne contient rien par défaut
end
-- MOUSE FUNCTIONS
-- Handle pointers (clic/touch)
function Menu:mousemoved(x, y)
-- Cette fonction ne contient rien par défaut
end
function Menu:mousepressed( x, y, button, istouch )
-- Cette fonction ne contient rien par défaut
end
-- WIDGET FUNCTIONS
-- Handle widgets of the functions
function Menu:addWidget(newwidget)
if #self.widget.list == 0 then
self.widget.selected = 1
end
table.insert(self.widget.list, newwidget)
self:updateWidgetsID()
self:updateWidgetsOrder()
end
function Menu:updateWidgets(dt)
self:removeDestroyedWidgets()
for i,v in ipairs(self.widget.list) do
v.id = i
v:update(dt)
end
end
function Menu:updateWidgetsID()
for i,v in ipairs(self.widget.list) do
v.id = i
end
end
function Menu:removeDestroyedWidgets() -- On retire les widgets marquées comme supprimées
for i,v in ipairs(self.widget.list) do
if (v.destroyed == true) then
table.remove(self.widget.list, i)
end
end
end
-- CURSOR FUNCTIONS
-- Set or move the cursor of the menu
function Menu:setCursor(cursorid)
self.widget.selected = cursorid --math.max(1, math.min(cursorid, #self.widget.list))
end
function Menu:moveCursor(new_selected)
self:playNavigationSound()
if new_selected < 1 then
self.widget.selected = #self.widget.list + new_selected
else
if new_selected > #self.widget.list then
self.widget.selected = new_selected - #self.widget.list
else
self.widget.selected = new_selected
end
end
end
-- SOUND FUNCTION
-- Handle SFX
function Menu:resetSound()
self.sound = {}
self.sound.active = false
self.sound.asset = nil
end
function Menu:setSoundFromSceneAssets(name)
self:setSound(self.menusystem.scene.assets.sfx[name])
end
function Menu:setSound(soundasset)
self.sound.active = true
self.sound.asset = soundasset
end
function Menu:playNavigationSound()
if self.sound.active == true then
self.sound.asset:play()
end
end
-- VIEW FUNCTIONS
-- Handle the view of the menu
function Menu:resetView()
-- ne sert à rien ici, c'est juste pour éviter des crash
end
function Menu:updateView()
-- ne sert à rien ici, c'est juste pour éviter des crash
end
function Menu:moveView()
-- ne sert à rien ici, c'est juste pour éviter des crash
end
return Menu

View file

@ -0,0 +1,153 @@
-- 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 BaseWidget = Object:extend()
local TextWidget = BaseWidget:extend()
-- INIT FUNCTIONS
-- Initialize and configure the widget
function BaseWidget:new(menu)
self.menu = menu
self.destroyed = false
self.selectable = false
self.selection_margin = 0
self.margin = 2
self.canvas = {}
self.canvas.texture = nil
self.canvas.needRedraw = true
self.ox = 0
self.oy = 0
self.order = 0
self:register()
end
function BaseWidget:register()
self.creationID = self.menu:getWidgetNumber()
self.menu:addWidget(self)
end
function BaseWidget:redrawCanvas()
self.width, self.height = self.menu:getWidgetSize(self.id)
local canvas = love.graphics.newCanvas(self.width * 2, self.height * 2)
love.graphics.setCanvas( canvas )
self:drawCanvas()
self.canvas.needRedraw = false
love.graphics.setCanvas( )
local imageData = canvas:newImageData( )
self.canvas.texture = love.graphics.newImage( imageData )
canvas:release( )
imageData:release( )
end
function BaseWidget:invalidateCanvas()
self.canvas.needRedraw = true
end
function BaseWidget:drawCanvas()
self.r = love.math.random(128)/256
self.g = love.math.random(128)/256
self.b = love.math.random(128)/256
love.graphics.setColor(self.r, self.g, self.b, 70)
love.graphics.rectangle("fill", 0, 0, self.width, self.height)
love.graphics.setColor(self.r, self.g, self.b)
love.graphics.rectangle("line", 0, 0, self.width, self.height)
utils.graphics.resetColor()
end
function BaseWidget:selectAction()
-- Do nothing
end
function BaseWidget:updateSelected(dt)
-- Do nothing
end
-- DRAW WIDGETS
-- Draw the widget
function BaseWidget:draw(x, y)
if self.canvas.texture ~= nil then
love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy)
end
end
function BaseWidget:drawSelected(x,y,w,h)
self:draw(x, y, w, h)
end
-- UPDATE FUNCTIONS
-- Update the widget
function BaseWidget:update(dt)
if (self.canvas.needRedraw) then
self:redrawCanvas()
end
-- N/A
end
-- ACTION FUNCTION
-- Functions to handle actions and selection.
function BaseWidget:action(source)
--self:destroy()
end
function BaseWidget:destroy()
self.destroyed = true
end
-- TEXT WIDGET
-- Simple text widget
function TextWidget:new(menu, font, label, color)
TextWidget.super.new(self, menu)
self.font = font
self.label = label
self.color = color or {1, 1, 1}
end
function TextWidget:drawCanvas()
local w, h
w = math.floor(self.width / 2)
h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
self.font:draw(self.label, w, h, -1, "center")
self.font:setColor(1, 1, 1, 1)
end
-- Add the widget as subvariable to the returned table
Widget.Base = BaseWidget
Widget.Text = TextWidget
return Widget

View file

@ -0,0 +1,57 @@
-- 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 = {}
function menuUtils.drawCursor(x, y, w, h)
love.graphics.setColor(0,0,0)
love.graphics.rectangle("fill", x, y, 4, 8)
love.graphics.rectangle("fill", x, y, 8, 4)
love.graphics.rectangle("fill", x + w, y, -4, 8)
love.graphics.rectangle("fill", x + w, y, -8, 4)
love.graphics.rectangle("fill", x, y + h, 4, -8)
love.graphics.rectangle("fill", x, y + h, 8, -4)
love.graphics.rectangle("fill", x + w, y + h, -4, -8)
love.graphics.rectangle("fill", x + w, y + h, -8, -4)
love.graphics.setColor(255,255,255)
love.graphics.rectangle("fill", x + 1, y + 1, 2, 6)
love.graphics.rectangle("fill", x + 1, y + 1, 6, 2)
love.graphics.rectangle("fill", x + w - 1, y + 1, -2, 6)
love.graphics.rectangle("fill", x + w - 1, y + 1, -6, 2)
love.graphics.rectangle("fill", x + 1, y + h - 1, 2, -6)
love.graphics.rectangle("fill", x + 1, y + h - 1, 6, -2)
love.graphics.rectangle("fill", x + w - 1, y + h - 1, -2, -6)
love.graphics.rectangle("fill", x + w - 1, y + h - 1, -6, -2)
end
return menuUtils

View file

@ -22,10 +22,13 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local cwd = (...):gsub('%.scenes$', '') .. "."
local Scene = Object:extend()
local Assets = require "framework.scenes.assets"
local Gui = require "framework.scenes.gui"
local Assets = require(cwd .. "assets")
local MenuSystem = require(cwd .. "menusystem")
local Gui = require (cwd .. "gui")
-- INIT FUNCTIONS
-- Initialize and configure the scene
@ -35,6 +38,7 @@ function Scene:new()
self.mouse.x, self.mouse.y = core.screen:getMousePosition()
self.assets = Assets()
self.menusystem = MenuSystem(self)
self.sources = core.input:getSources()
self.gui = Gui(self)
@ -67,7 +71,9 @@ function Scene:updateScene(dt)
self:updateStart(dt)
self:setKeys()
self.assets:update(dt)
self:updateGUI(dt)
self:updateMenus(dt)
self:updateDialog(dt)
self.gui:update(dt)
self:updateWorld(dt)
self:update(dt)
self:updateEnd(dt)
@ -91,11 +97,18 @@ function Scene:updateWorld(dt)
end
end
function Scene:updateGUI(dt)
if (self.gui ~= nil) then
self.gui:update(dt)
if (core.screen:isActive()) then
function Scene:updateDialog(dt)
if (self.dialog ~= nil) then
self.dialog:update(dt)
end
end
function Scene:updateMenus(dt)
if (self.menusystem ~= nil) then
self.menusystem:update(dt)
if (core.screen:isActive() and (self.dialog == nil)) then
self.gui:keycheck(self:getKeys(1))
self.menusystem:keycheck()
end
end
end
@ -145,6 +158,8 @@ function Scene:drawScene()
self:drawWorld()
self:draw()
self.gui:drawBottom()
self:drawMenus()
self:drawDialog()
self:drawEnd()
core.screen:drawTransition()
self.gui:drawTop()
@ -173,6 +188,18 @@ function Scene:drawWorld(dt)
end
end
function Scene:drawDialog(dt)
if (self.dialog ~= nil) then
self.dialog:draw()
end
end
function Scene:drawMenus()
if (self.menusystem ~= nil) then
self.menusystem:draw()
end
end
-- INPUT FUNCTIONS
-- Handle inputs from keyboard/controllers
@ -182,8 +209,10 @@ function Scene:setKeys()
if (self.inputLockedTimer <= 0 ) then
self.inputLocked = false
end
self.menusystem.keys = self:getKeys(1)
else
self.sources = core.input.sources
self.menusystem.keys = self:getKeys(1)
end
end

View file

@ -1,4 +1,4 @@
local TransitionParent = require "framework.scenes.transitions.parent"
local TransitionParent = require "birb.modules.transitions.parent"
local CanvasTransition = TransitionParent:extend()
function CanvasTransition:new(func, ox, oy, fadeOut, easeIn, easeOut, duration, wait)

View file

@ -1,4 +1,4 @@
local TransitionParent = require "framework.scenes.transitions.canvas"
local TransitionParent = require "birb.modules.transitions.canvas"
local DefaultTransition = TransitionParent:extend()
function DefaultTransition:new(func, ox, oy, fadeOut)

View file

@ -1,4 +1,4 @@
local TransitionParent = require "framework.scenes.transitions.canvas"
local TransitionParent = require "birb.modules.transitions.canvas"
local DecalTransition = TransitionParent:extend()
function DecalTransition:new(func, ox, oy, fadeOut, decal)

View file

@ -1,4 +1,4 @@
local TransitionParent = require "framework.scenes.transitions.parent"
local TransitionParent = require "birb.modules.transitions.parent"
local DefaultTransition = TransitionParent:extend()
function DefaultTransition:new(func, ox, oy, fadeOut)

View file

@ -0,0 +1,4 @@
return {
default = require "birb.modules.transitions.default",
circle = require "birb.modules.transitions.circle"
}

View file

@ -1,5 +1,5 @@
local TransitionParent = Object:extend()
local TweenManager = require "framework.classes.time"
local TweenManager = require "birb.classes.time"
function TransitionParent:new(func, ox, oy, fadeOut, easeIn, easeOut, duration, wait)
self.tween = TweenManager(self)

View file

@ -21,13 +21,13 @@
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 Rect = require "framework.classes.2D.rect"
local Rect = require "birb.classes.2D.rect"
local BaseActor = require "framework.scenes.world.actors.mixins.base"
local SpritedActor = require("framework.scenes.world.actors.mixins.sprites")
local TimedActor = require("framework.scenes.world.actors.mixins.timers")
local InputActor = require("framework.scenes.world.actors.mixins.inputs")
local PhysicalActor = require("framework.scenes.world.actors.mixins.physics")
local BaseActor = require "birb.modules.world.actors.mixins.base"
local SpritedActor = require("birb.modules.world.actors.mixins.sprites")
local TimedActor = require("birb.modules.world.actors.mixins.timers")
local InputActor = require("birb.modules.world.actors.mixins.inputs")
local PhysicalActor = require("birb.modules.world.actors.mixins.physics")
local Actor2D = Rect:extend()
Actor2D:implement(BaseActor)
@ -36,7 +36,7 @@ Actor2D:implement(TimedActor)
Actor2D:implement(InputActor)
Actor2D:implement(PhysicalActor)
local Hitbox = require "framework.scenes.world.actors.utils.hitbox2D"
local Hitbox = require "birb.modules.world.actors.utils.hitbox2D"
-- INIT FUNCTIONS
-- Initialise the actor and its base functions

View file

@ -22,16 +22,16 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Hitbox = require("framework.scenes.world.actors.utils.hitbox3D")
local Boxes = require("framework.scenes.world.actors.utils.boxes")
local BasicBox = require "framework.classes.3D.box"
local Hitbox = require("birb.modules.world.actors.utils.hitbox3D")
local Boxes = require("birb.modules.world.actors.utils.boxes")
local BasicBox = require "birb.classes.3D.box"
local BaseActor = require("framework.scenes.world.actors.mixins.base")
local SpritedActor = require("framework.scenes.world.actors.mixins.sprites")
local TimedActor = require("framework.scenes.world.actors.mixins.timers")
local InputActor = require("framework.scenes.world.actors.mixins.inputs")
local PhysicalActor = require("framework.scenes.world.actors.mixins.physics")
local Shape3DActor = require("framework.scenes.world.actors.mixins.shapes")
local BaseActor = require("birb.modules.world.actors.mixins.base")
local SpritedActor = require("birb.modules.world.actors.mixins.sprites")
local TimedActor = require("birb.modules.world.actors.mixins.timers")
local InputActor = require("birb.modules.world.actors.mixins.inputs")
local PhysicalActor = require("birb.modules.world.actors.mixins.physics")
local Shape3DActor = require("birb.modules.world.actors.mixins.shapes")
local Actor3D = BasicBox:extend()
Actor3D:implement(BaseActor)

Some files were not shown because too many files have changed in this diff Show more