Compare commits
16 commits
c3179dcf9d
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
7fd8db592d | ||
|
a5f075d5d2 | ||
|
c64b9a42b7 | ||
|
5ab63a145a | ||
|
6d3c8de013 | ||
|
d5f446f4ed | ||
|
69a567e4c2 | ||
|
f3d175266b | ||
|
f9b936a726 | ||
|
3cb6c61cac | ||
|
eec43a522e | ||
|
f892b1ce4e | ||
|
de08fbd56b | ||
|
4722b734ed | ||
|
a315fcebb5 | ||
|
5178ee0020 |
180 changed files with 572 additions and 1928 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -3,7 +3,7 @@
|
|||
"love",
|
||||
"loadstring",
|
||||
"unpack",
|
||||
"birb",
|
||||
"framework",
|
||||
"utils",
|
||||
"core",
|
||||
"scenes",
|
||||
|
|
|
@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Project renamed to Birb and rebased entirely on Sonic Radiance codebase
|
||||
- Project renamed to Epervier Framework 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 birb
|
||||
- **core:** The core is now separated from the rest of the framework
|
||||
|
||||
- **core+assets:** Music are now managed directly by the core
|
||||
|
||||
|
|
42
README.md
42
README.md
|
@ -1,20 +1,40 @@
|
|||
# Birb Love2D Engine
|
||||
# Épervier Framework
|
||||
|
||||
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.
|
||||
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 use [Classic](https://github.com/rxi/classic/) as its base Object.
|
||||
Épervier use [Classic](https://github.com/rxi/classic/) as its base Object.
|
||||
|
||||
## How to load Birb
|
||||
## Core features
|
||||
|
||||
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.
|
||||
É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 :
|
||||
|
||||
Note : the `birb` and `utils` global namespace will be used by birb.
|
||||
- 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
|
||||
|
||||
````
|
||||
require "birb"
|
||||
## How to load Épervier
|
||||
|
||||
function love.load()
|
||||
birb.startCore()
|
||||
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)
|
||||
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
|
||||
```
|
|
@ -1,10 +0,0 @@
|
|||
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
|
|
@ -1,231 +0,0 @@
|
|||
-- 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
|
|
@ -1,277 +0,0 @@
|
|||
-- 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
|
|
@ -1,149 +0,0 @@
|
|||
-- 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
|
|
@ -1,290 +0,0 @@
|
|||
-- 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
|
|
@ -1,147 +0,0 @@
|
|||
-- 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
|
|
@ -1,302 +0,0 @@
|
|||
-- 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
|
|
@ -1,153 +0,0 @@
|
|||
-- 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
|
|
@ -1,57 +0,0 @@
|
|||
-- 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
|
|
@ -1,4 +0,0 @@
|
|||
return {
|
||||
default = require "birb.modules.transitions.default",
|
||||
circle = require "birb.modules.transitions.circle"
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
../birb/
|
1
examples/framework
Symbolic link
1
examples/framework
Symbolic link
|
@ -0,0 +1 @@
|
|||
../framework/
|
|
@ -1,4 +1,4 @@
|
|||
local GameSystem = require "birb.modules.gamesystem"
|
||||
local GameSystem = require "framework.gamesystem"
|
||||
local Game = GameSystem:extend()
|
||||
|
||||
function Game:new()
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
require "birb"
|
||||
require "framework"
|
||||
|
||||
scenes = require "scenes"
|
||||
|
||||
function love.load(args)
|
||||
print(utils.table.toString(args))
|
||||
birb.start("game", args)
|
||||
framework.start("game", args)
|
||||
scenes.MainMenu()
|
||||
end
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local TestScene = Scene:extend()
|
||||
|
||||
local MenuType = require "birb.modules.gui.menus.listbox"
|
||||
local MenuType2 = require "birb.modules.gui.menus.flowbox"
|
||||
local MenuType3 = require "birb.modules.gui.menus.grid"
|
||||
local Widget = require "birb.modules.gui.menus.widgets"
|
||||
local MenuType = require "framework.scenes.gui.menus.listbox"
|
||||
local MenuType2 = require "framework.scenes.gui.menus.flowbox"
|
||||
local MenuType3 = require "framework.scenes.gui.menus.grid"
|
||||
local Widget = require "framework.scenes.gui.menus.widgets"
|
||||
|
||||
local MenuWidget = Widget.Text:extend()
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local TestScene = Scene:extend()
|
||||
|
||||
function TestScene:new()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor2D"
|
||||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Parent = Base:extend()
|
||||
|
||||
function Parent:new(world, type, x, y, w, h)
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local TestScene = Scene:extend()
|
||||
|
||||
local folder = "scenes/basic/test_scene2/"
|
||||
|
||||
local World = require "birb.modules.world.baseworld"
|
||||
local World = require "framework.scenes.world.baseworld"
|
||||
|
||||
function TestScene:new()
|
||||
TestScene.super.new(self)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor3D"
|
||||
local Base = require "framework.scenes.world.actors.actor3D"
|
||||
local Box = Base:extend()
|
||||
|
||||
function Box:new(world, x, y, z)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor3D"
|
||||
local Base = require "framework.scenes.world.actors.actor3D"
|
||||
local Coin = Base:extend()
|
||||
|
||||
function Coin:new(world, x, y, z)
|
||||
|
|
|
@ -5,7 +5,7 @@ local cwd = (...):gsub('%.init$', '') .. "."
|
|||
Obj.Player = require(cwd .. "player")
|
||||
Obj.Box = require(cwd .. "box")
|
||||
Obj.Coin = require(cwd .. "coin")
|
||||
Obj.GFX = require("birb.modules.world.actors.gfx3D")
|
||||
Obj.GFX = require("framework.scenes.world.actors.gfx3D")
|
||||
|
||||
Obj.index = {}
|
||||
Obj.index["player"] = Obj.Player
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor3D"
|
||||
local Base = require "framework.scenes.world.actors.actor3D"
|
||||
local Parent = Base:extend()
|
||||
|
||||
function Parent:new(world, type, x, y, z, w, h, d, isSolid)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor3D"
|
||||
local Base = require "framework.scenes.world.actors.actor3D"
|
||||
local Wall = Base:extend()
|
||||
|
||||
function Wall:new(world, x, y, z, w, h, d)
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local MovePlayer = Scene:extend()
|
||||
|
||||
local World = require "birb.modules.world.world3D"
|
||||
local World = require "framework.scenes.world.world3D"
|
||||
|
||||
function MovePlayer:new(playerNumber, cameraMode)
|
||||
local playerNumber = playerNumber or 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor2D"
|
||||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Parent = Base:extend()
|
||||
|
||||
function Parent:new(world, type, x, y, w, h, isSolid)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor2D"
|
||||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Wall = Base:extend()
|
||||
|
||||
function Wall:new(world, x, y, w, h)
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local MovePlayer = Scene:extend()
|
||||
|
||||
local World = require "birb.modules.world.world2D"
|
||||
local World = require "framework.scenes.world.world2D"
|
||||
|
||||
function MovePlayer:new(playerNumber, cameraMode)
|
||||
local playerNumber = playerNumber or 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor3D"
|
||||
local Base = require "framework.scenes.world.actors.actor3D"
|
||||
local Parent = Base:extend()
|
||||
|
||||
function Parent:new(world, type, x, y, z, w, h, d, isSolid)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor3D"
|
||||
local Base = require "framework.scenes.world.actors.actor3D"
|
||||
local Wall = Base:extend()
|
||||
|
||||
function Wall:new(world, x, y, z, w, h, d)
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local MovePlayer = Scene:extend()
|
||||
|
||||
local World = require "birb.modules.world.world3D"
|
||||
local World = require "framework.scenes.world.world3D"
|
||||
|
||||
function MovePlayer:new(playerNumber, cameraMode)
|
||||
local playerNumber = playerNumber or 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor2D"
|
||||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Coin = Base:extend()
|
||||
|
||||
function Coin:new(world, x, y)
|
||||
|
|
|
@ -4,7 +4,7 @@ local Obj = {}
|
|||
local cwd = (...):gsub('%.init$', '') .. "."
|
||||
|
||||
Obj.Player = require(cwd .. "player")
|
||||
Obj.GFX = require("birb.modules.world.actors.gfx2D")
|
||||
Obj.GFX = require("framework.scenes.world.actors.gfx2D")
|
||||
|
||||
Obj.index = {}
|
||||
Obj.index["player"] = require(cwd .. "player")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor2D"
|
||||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Player = Base:extend()
|
||||
|
||||
function Player:new(world, x, y, id)
|
||||
|
@ -40,7 +40,7 @@ function Player:updateStart(dt)
|
|||
end
|
||||
|
||||
if (self.isPunching) then
|
||||
self:checkHitboxesCollisions()
|
||||
self:applyHitboxesCollisions()
|
||||
end
|
||||
|
||||
if self.keys["start"].isPressed then
|
||||
|
@ -87,7 +87,7 @@ function Player:setDirection(direction)
|
|||
if direction ~= 0 then
|
||||
direction = utils.math.sign(direction)
|
||||
self.direction = direction
|
||||
self.sprite:setScalling(direction, nil)
|
||||
self.sprite:setScallingX(direction)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local Base = require "birb.modules.world.actors.actor2D"
|
||||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Wall = Base:extend()
|
||||
|
||||
function Wall:new(world, x, y, w, h)
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local Plateformer = Scene:extend()
|
||||
|
||||
local World = require "birb.modules.world.world2D"
|
||||
local World = require "framework.scenes.world.world2D"
|
||||
local Pause = require "scenes.gameplay.plateform.pause"
|
||||
|
||||
function Plateformer:new()
|
||||
|
@ -36,24 +36,24 @@ function Plateformer:new()
|
|||
|
||||
World(self, folder .. ".actors", "datas/maps/plateformer/platformer.lua")
|
||||
|
||||
Pause(self)
|
||||
self.menusystem:deactivate()
|
||||
self.menusystem:lockWorldWhenActive(true)
|
||||
self.menusystem:lockAssetsWhenActive(true)
|
||||
--Pause(self)
|
||||
--self.menusystem:deactivate()
|
||||
--self.menusystem:lockWorldWhenActive(true)
|
||||
--self.menusystem:lockAssetsWhenActive(true)
|
||||
|
||||
self.world:loadMap()
|
||||
end
|
||||
|
||||
function Plateformer:restart()
|
||||
self.menusystem:deactivate()
|
||||
--self.menusystem:deactivate()
|
||||
collectgarbage()
|
||||
self.world:reset()
|
||||
end
|
||||
|
||||
function Plateformer:update(dt)
|
||||
if (self.menusystem.isActive == true) and self.sources[1].keys["start"].isPressed then
|
||||
self.menusystem:deactivate()
|
||||
end
|
||||
--if (self.menusystem.isActive == true) and self.sources[1].keys["start"].isPressed then
|
||||
--self.menusystem:deactivate()
|
||||
--end
|
||||
end
|
||||
|
||||
function Plateformer:draw()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local ListMenu = require "birb.modules.gui.menus.listbox"
|
||||
local Widget = require "birb.modules.gui.menus.widgets"
|
||||
local ListMenu = require "framework.scenes.gui.menus.listbox"
|
||||
local Widget = require "framework.scenes.gui.menus.widgets"
|
||||
|
||||
local PauseMenu = ListMenu:extend()
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local MainMenu = Scene:extend()
|
||||
|
||||
local Menu = require "scenes.mainmenu.menu"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local Parent = require "birb.modules.gui.textmenu"
|
||||
local Parent = require "framework.scenes.gui.textmenu"
|
||||
local MainMenu = Parent:extend()
|
||||
|
||||
local defTransitions = require "birb.modules.transitions"
|
||||
local defTransitions = require "framework.scenes.transitions"
|
||||
|
||||
local MENU_X, MENU_Y = 24, 48
|
||||
local MENU_W = 424/3
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local Inventory = Scene:extend()
|
||||
|
||||
local HListBox = require "birb.modules.gui.menus.hlistbox"
|
||||
local FloxBox = require "birb.modules.gui.menus.flowbox"
|
||||
local Widget = require "birb.modules.gui.menus.widgets"
|
||||
local HListBox = require "framework.scenes.gui.menus.hlistbox"
|
||||
local FloxBox = require "framework.scenes.gui.menus.flowbox"
|
||||
local Widget = require "framework.scenes.gui.menus.widgets"
|
||||
|
||||
local InventoryWidget = Widget.Text:extend()
|
||||
local ItemWidget = Widget.Text:extend()
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "birb.modules.scenes"
|
||||
local Scene = require "framework.scenes"
|
||||
local OptionsMenu = Scene:extend()
|
||||
|
||||
local Widgets = require "scenes.menus.options.widgets"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local TextMenu = require "birb.modules.gui.textmenu"
|
||||
local TextMenu = require "framework.scenes.gui.textmenu"
|
||||
local OptionMenu = TextMenu:extend()
|
||||
|
||||
local consts = require "scenes.menus.options.consts"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
local widgets = {}
|
||||
|
||||
local Widget = require "birb.modules.gui.textmenu.widgets.basic"
|
||||
local Widget = require "framework.scenes.gui.textmenu.widgets.basic"
|
||||
local DoubleTextWidget = Widget:extend()
|
||||
|
||||
widgets.SubMenu = DoubleTextWidget:extend()
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Rect = require "birb.classes.2D.rect"
|
||||
local Rect = require "framework.classes.2D.rect"
|
||||
local IndexedRect = Rect:extend()
|
||||
|
||||
function IndexedRect:new(origin, ox, oy, w, h)
|
|
@ -21,7 +21,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Point = require "birb.classes.2D.point"
|
||||
local Point = require "framework.classes.2D.point"
|
||||
local Rect = Point:extend()
|
||||
|
||||
function Rect:new(x, y, w, h)
|
|
@ -21,7 +21,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Point = require "birb.classes.3D.point3D"
|
||||
local Point = require "framework.classes.3D.point3D"
|
||||
local Box = Point:extend()
|
||||
|
||||
function Box:new(x, y, z, w, h, d)
|
|
@ -23,7 +23,7 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Rect = require "birb.classes.2D.rect"
|
||||
local Rect = require "framework.classes.2D.rect"
|
||||
local IndexedRect = Rect:extend()
|
||||
|
||||
function IndexedRect:new(origin, ox, oy, oz, w, h, d)
|
|
@ -28,7 +28,7 @@
|
|||
]]
|
||||
|
||||
local Predicate = Object:extend()
|
||||
local SimplePredicate = require "birb.classes.predicate.simple"
|
||||
local SimplePredicate = require "framework.classes.predicate.simple"
|
||||
|
||||
function Predicate.createPredicate(data, solver, asker)
|
||||
local predicate = nil
|
|
@ -34,7 +34,7 @@ local SEPARATOR = ":"
|
|||
local NOT = "not"
|
||||
local DEFAULT = "default"
|
||||
|
||||
SimplePredicate.utils = require "birb.classes.predicate.utils"
|
||||
SimplePredicate.utils = require "framework.classes.predicate.utils"
|
||||
|
||||
function SimplePredicate:new(data, solver, asker)
|
||||
self.solver = solver
|
|
@ -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 "birb.classes.serializable"
|
||||
local Serializable = require "framework.classes.serializable"
|
||||
local Serializer = Serializable:extend()
|
||||
local binser = require("birb.libs.binser")
|
||||
local binser = require("framework.libs.binser")
|
||||
|
||||
function Serializer:new(serializeFields, listSerializable)
|
||||
Serializer.super.new(self, serializeFields, listSerializable)
|
|
@ -1,4 +1,4 @@
|
|||
local Timer = require "birb.classes.time.timer"
|
||||
local Timer = require "framework.classes.time.timer"
|
||||
local TimedFunction = Timer:extend()
|
||||
|
||||
function TimedFunction:new(actor, name, func, t)
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
-- time.lua :: a timer, tweener and timed switch handler.
|
||||
-- This class need birb.libs.tween to work
|
||||
-- This class need framework.libs.tween to work
|
||||
|
||||
--[[
|
||||
Copyright © 2019 Kazhnuz
|
||||
|
@ -25,9 +25,9 @@
|
|||
|
||||
local TweenManager = Object:extend()
|
||||
|
||||
local tween = require "birb.libs.tween"
|
||||
local Timer = require "birb.classes.time.timer"
|
||||
local TimedFunction = require "birb.classes.time.func"
|
||||
local tween = require "framework.libs.tween"
|
||||
local Timer = require "framework.classes.time.timer"
|
||||
local TimedFunction = require "framework.classes.time.func"
|
||||
|
||||
function TweenManager:new(subject)
|
||||
self.subject = subject
|
||||
|
@ -63,6 +63,10 @@ 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
|
||||
|
|
@ -24,8 +24,8 @@
|
|||
]]
|
||||
|
||||
local DataManager = Object:extend()
|
||||
local DataPack = require "birb.classes.datapack"
|
||||
local Parser = require "birb.classes.parser"
|
||||
local DataPack = require "framework.classes.datapack"
|
||||
local Parser = require "framework.classes.parser"
|
||||
local index = require "datas.gamedata.index"
|
||||
|
||||
function DataManager:new(core)
|
||||
|
@ -36,7 +36,7 @@ end
|
|||
|
||||
function DataManager:loadDatas()
|
||||
self.datapacks = {}
|
||||
if (index.datapacks ~= nil) then
|
||||
if (index.datapack ~= 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])
|
|
@ -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 "birb.libs.lovebird"
|
||||
lovebird = require "framework.libs.lovebird"
|
||||
lovebird.update()
|
||||
end
|
||||
end
|
|
@ -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 "birb.classes.serializable.serializer"
|
||||
local Serializer = require "framework.classes.serializable.serializer"
|
||||
local OptionsManager = Serializer:extend()
|
||||
|
||||
local TRANSLATION_PATH = "datas/languages/"
|
|
@ -41,10 +41,6 @@ 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
|
||||
|
@ -94,14 +90,12 @@ function SceneManager:mousemoved(x, y, dx, dy)
|
|||
self.currentScene.mouse.x,
|
||||
self.currentScene.mouse.y = x, y
|
||||
self.currentScene:mousemoved(x, y, dx, dy)
|
||||
self.currentScene.menusystem:mousemoved(x, y, dx, dy)
|
||||
end
|
||||
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
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
local ScreenManager = Object:extend()
|
||||
|
||||
local CScreen = require("birb.libs.cscreen")
|
||||
local CScreen = require("framework.libs.cscreen")
|
||||
|
||||
-- INIT FUNCTIONS
|
||||
-- Initialize and configure the screen manager
|
|
@ -1,18 +1,17 @@
|
|||
-- modules/gamesystem :: a simple save system, based on the Deserialization feature
|
||||
-- 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.
|
||||
|
||||
--[[
|
||||
Copyright © 2021 Kazhnuz
|
||||
|
||||
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
|
||||
|
@ -21,67 +20,83 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local GameSystem = require("birb.classes.serializable.serializer"):extend()
|
||||
|
||||
function GameSystem:new(varToSerialize, slotNumber)
|
||||
local Serializer = require "framework.classes.serializable.serializer"
|
||||
local GameSystem = Serializer:extend()
|
||||
|
||||
local VAR_TO_SERIALIZE = {
|
||||
"gametime",
|
||||
"destroyedGizmo",
|
||||
"variables",
|
||||
"flags"
|
||||
}
|
||||
|
||||
function GameSystem:new()
|
||||
self.slot = -1
|
||||
self.slotNumber = slotNumber or 1
|
||||
self.slotNumber = 3
|
||||
self.version = core.conf.gameversion or "N/A"
|
||||
self:reset()
|
||||
GameSystem.super.new(self, VAR_TO_SERIALIZE)
|
||||
end
|
||||
|
||||
function GameSystem:reset()
|
||||
self.gametime = 0
|
||||
varToSerialize = varToSerialize or {}
|
||||
GameSystem.super.new(self, varToSerialize)
|
||||
|
||||
self.flags = {}
|
||||
self.destroyedGizmo = {}
|
||||
self.variables = {}
|
||||
self.mapName = ""
|
||||
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.metadata:update()
|
||||
self:serialize(self:getSaveName())
|
||||
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
|
|
@ -1,4 +1,5 @@
|
|||
-- birb :: The main birb script, loading the core and main utilities
|
||||
-- framework :: The main Épervier Framework script, loading the core and main
|
||||
-- utilities
|
||||
|
||||
--[[
|
||||
Copyright © 2021 Kazhnuz
|
||||
|
@ -21,32 +22,32 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
birb = {}
|
||||
framework = {}
|
||||
|
||||
-- GLOBAL UTILS/FUNCTION LOADING
|
||||
-- Load in the global namespace utilities that'll need to be reusable everywhere
|
||||
-- in the game
|
||||
|
||||
Object = require("birb.libs.classic")
|
||||
utils = require("birb.utils")
|
||||
enum = require("birb.utils.enum")
|
||||
Object = require("framework.libs.classic")
|
||||
utils = require("framework.utils")
|
||||
enum = require("framework.utils.enum")
|
||||
|
||||
birb.Core = require("birb.core")
|
||||
framework.Core = require("framework.core")
|
||||
|
||||
function birb.start(gamemodule, args)
|
||||
birb.startCore(args)
|
||||
function framework.start(gamemodule, args)
|
||||
framework.startCore(args)
|
||||
if (gamemodule ~= nil) then
|
||||
birb.startGame(gamemodule)
|
||||
framework.startGame(gamemodule)
|
||||
end
|
||||
end
|
||||
|
||||
function birb.startCore(args)
|
||||
core = birb.Core(args)
|
||||
function framework.startCore(args)
|
||||
core = framework.Core(args)
|
||||
end
|
||||
|
||||
function birb.startGame(gamemodule)
|
||||
function framework.startGame(gamemodule)
|
||||
local GameObject = require(gamemodule)
|
||||
game = GameObject()
|
||||
end
|
||||
|
||||
require("birb.callbacks")
|
||||
require("framework.callbacks")
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.drawable"
|
||||
local Parent = require "framework.scenes.gui.elements.drawable"
|
||||
local AssetElement = Parent:extend()
|
||||
|
||||
function AssetElement:new(name, assetType, assetName, x, y,r,sx,sy,ox,oy, opacity)
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.parent"
|
||||
local Parent = require "framework.scenes.gui.elements.parent"
|
||||
local CanvasElement = Parent:extend()
|
||||
|
||||
function CanvasElement:new(name, x, y, w, h, r,sx,sy,ox,oy, opacity)
|
||||
|
@ -16,6 +16,8 @@ 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)
|
||||
|
@ -30,6 +32,18 @@ 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()
|
||||
|
@ -55,6 +69,10 @@ function CanvasElement:drawTexture()
|
|||
|
||||
end
|
||||
|
||||
function CanvasElement:drawFinalTexture()
|
||||
|
||||
end
|
||||
|
||||
function CanvasElement:parseOrigin(origin, size)
|
||||
if (origin == "center") then
|
||||
return size/2
|
||||
|
@ -67,7 +85,11 @@ end
|
|||
|
||||
function CanvasElement:draw()
|
||||
love.graphics.setColor(1, 1, 1, self.opacity)
|
||||
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)
|
||||
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.setColor(1, 1, 1, 1)
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.parent"
|
||||
local Parent = require "framework.scenes.gui.elements.parent"
|
||||
local ColorElement = Parent:extend()
|
||||
|
||||
function ColorElement:new(name, r, g, b, opacity)
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.parent"
|
||||
local Parent = require "framework.scenes.gui.elements.parent"
|
||||
local CompositeElement = Parent:extend()
|
||||
|
||||
function CompositeElement:new(name, x, y, childrenList)
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.variable"
|
||||
local Parent = require "framework.scenes.gui.elements.variable"
|
||||
local CounterElement = Parent:extend()
|
||||
|
||||
function CounterElement:new(name, fontName, object, varName, nbrs, x, y, align)
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.parent"
|
||||
local Parent = require "framework.scenes.gui.elements.parent"
|
||||
local DrawableElement = Parent:extend()
|
||||
|
||||
function DrawableElement:new(name, drawable, x, y,r,sx,sy,ox,oy, opacity)
|
|
@ -1,7 +1,7 @@
|
|||
local Rect = require "birb.classes.2D.rect"
|
||||
local Rect = require "framework.classes.2D.rect"
|
||||
local GuiElement = Rect:extend()
|
||||
|
||||
local TweenManager = require "birb.classes.time"
|
||||
local TweenManager = require "framework.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:getScene()
|
||||
self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
|
||||
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()
|
||||
self.gui:setFocus(self.name)
|
||||
function GuiElement:getFocus(widgetId, page)
|
||||
self.gui:setFocus(self.name, widgetId, page)
|
||||
end
|
||||
|
||||
function GuiElement:haveFocus()
|
||||
|
@ -72,6 +72,14 @@ 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
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.parent"
|
||||
local Parent = require "framework.scenes.gui.elements.parent"
|
||||
local TextElement = Parent:extend()
|
||||
|
||||
function TextElement:new(name, fontName, text, x, y, align)
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.drawable"
|
||||
local Parent = require "framework.scenes.gui.elements.drawable"
|
||||
local TileElement = Parent:extend()
|
||||
|
||||
function TileElement:new(name, assetName, id, x, y,r,sx,sy,ox,oy, opacity)
|
|
@ -1,4 +1,4 @@
|
|||
local Parent = require "birb.modules.gui.elements.text"
|
||||
local Parent = require "framework.scenes.gui.elements.text"
|
||||
local VariableElement = Parent:extend()
|
||||
|
||||
function VariableElement:new(name, fontName, object, varName, x, y, align)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue