From 9ff9a53d2ad934d290cb277a2187812d9b29b7e2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 21 Aug 2021 12:45:49 +0200 Subject: [PATCH 001/102] wip: initial version of the GUI --- .../birb/modules/gui/elements/linked.lua | 21 ++++ .../birb/modules/gui/elements/parent.lua | 112 ++++++++++++++++++ sonic-radiance.love/birb/modules/gui/init.lua | 65 ++++++++++ .../birb/modules/gui/mixins/elements.lua | 28 +++++ .../birb/modules/gui/mixins/screens.lua | 16 +++ .../birb/modules/gui/screen.lua | 42 +++++++ sonic-radiance.love/birb/modules/scenes.lua | 5 + 7 files changed, 289 insertions(+) create mode 100644 sonic-radiance.love/birb/modules/gui/elements/linked.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/parent.lua create mode 100644 sonic-radiance.love/birb/modules/gui/init.lua create mode 100644 sonic-radiance.love/birb/modules/gui/mixins/elements.lua create mode 100644 sonic-radiance.love/birb/modules/gui/mixins/screens.lua create mode 100644 sonic-radiance.love/birb/modules/gui/screen.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/linked.lua b/sonic-radiance.love/birb/modules/gui/elements/linked.lua new file mode 100644 index 0000000..3e44fea --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/linked.lua @@ -0,0 +1,21 @@ +local Parent = require "birb.modules.gui.elements.parent" +local LinkedElement = Parent:extend() + +function LinkedElement:new(name, x, y, w, h, object, varName) + LinkedElement.super.new(self, name, x, y, w, h) + self.object = object + self.variables = {} + self:addVariable(varName, "main") +end + +function LinkedElement:addVariable(varName, internalName) + internalName = internalName or varName + self.variables[internalName] = varName +end + +function LinkedElement:getVariableContent(varName) + varName = varName or "main" + return self.object[self.variables[varName]] +end + +return LinkedElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua new file mode 100644 index 0000000..e672886 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -0,0 +1,112 @@ +local Rect = require "birb.objects.2D.rect" +local GuiElement = Rect:extend() + +function GuiElement:new(name, x, y, w, h) + GuiElement.super.new(self, x, y, w, h) + self.name = name + + self.isVisible = false + self.screen = nil + + self.depth = 0 + + self:register() +end + +function GuiElement:getGui() + local scene = core.scenemanager.currentScene + return scene.gui +end + +function GuiElement:register() + local gui = self:getGui() + gui:addElement(self.name, self) +end + +function GuiElement:destroy() + local gui = self:getGui() + gui:removeElement(self.name) + if (self.screen == nil) then + self.screen:removeElement(self.name) + end +end + +-- VISIBILITY/ACTIVITY +-- Handle drawing and how we interact with + +function GuiElement:setDepth(depth) + self.depth = depth or 0 +end + +function GuiElement:getVisibility() + if (self.screen ~= nil) then + return (self.isVisible and self.screen.isVisible) + else + return self.isVisible + end +end + +function GuiElement:setVisibility(visibility) + self.isVisible = visibility +end + +function GuiElement:getFocus() + local gui = self:getGui() + gui.focusedMenu = self.name +end + +function GuiElement:haveFocus() + local gui = self:getGui() + return (gui.focusedMenu == self.name) +end + +function GuiElement:looseFocus() + if (self:haveFocus()) then + local gui = self:getGui() + gui.focusedMenu = nil + end +end + +-- UPDATE FUNCTIONS +-- Update the menu every game update + +-- External update function +function GuiElement:updateElement(dt) + self:update(dt) +end + +-- Internal update function +function GuiElement:update(dt) + -- Cette fonction ne contient rien par défaut +end + +-- DRAW FUNCTIONS +-- Draw the menu and its content + +function GuiElement:drawElement() + self:draw() +end + +function GuiElement:draw() + -- nothing here +end + +-- KEYBOARD FUNCTIONS +-- Handle key press + +function GuiElement:keyreleased(key) + -- Cette fonction ne contient rien par défaut +end + +-- MOUSE FUNCTIONS +-- Handle pointers (clic/touch) + +function GuiElement:mousemoved(x, y) + -- Cette fonction ne contient rien par défaut +end + +function GuiElement:mousepressed(x, y, button, istouch) + -- Cette fonction ne contient rien par défaut +end + +return GuiElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua new file mode 100644 index 0000000..06319f0 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -0,0 +1,65 @@ +-- modules/gui :: a simple gui system, that manage all overhead elements of the game. + +--[[ + 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 + 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 Gui = Object:extend() + +local ElementList = require "birb.modules.gui.mixins.elements" +local ScreenList = require "birb.modules.gui.mixins.screens" +Gui:implement(ScreenList) +Gui:implement(ElementList) + + +function Gui:new(scene) + self.scene = scene + self:reset() +end + +function Gui:reset() + self:initElements() + self:initScreens() +end + +function Gui:update(dt) + for _, element in ipairs(self.elements) do + if (element ~= nil) then + element:updateElement(dt) + end + end +end + +-- DRAW FUNCTIONS +-- Draw the menu and its content + +function Gui:drawTop() + for _, element in ipairs(self:getVisibleElement(true)) do + element:drawElement() + end +end + +function Gui:drawBottom() + for _, element in ipairs(self:getVisibleElement(false)) do + element:drawElement() + end +end + +return Gui \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua new file mode 100644 index 0000000..a5270a8 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -0,0 +1,28 @@ +local ElementList = Object:extend() + +function ElementList:initElements() + self.elements = {} + self.focusedElem = nil +end + +function ElementList:addElement(name, element) + self.elements[name] = element +end + +function ElementList:deleteElement(name) + self.elements[name] = nil +end + +function ElementList:getVisibleElement(topLayer) + local visibleList = {} + for _, element in ipairs(self.elements) do + if (element ~= nil) then + if (element:getVisibility() and ((element.depth) < 0 == topLayer)) then + table.insert(visibleList, element) + end + end + end + return visibleList +end + +return ElementList \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/mixins/screens.lua b/sonic-radiance.love/birb/modules/gui/mixins/screens.lua new file mode 100644 index 0000000..4e594eb --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/mixins/screens.lua @@ -0,0 +1,16 @@ +local ScreenList = Object:extend() + +function ScreenList:initScreens() + self.screens = {} +end + +function ScreenList:addScreen(name, screen) + self.screens[name] = screen +end + +function ScreenList:deleteScreen(name) + self.screens[name]:purgeElements() + self.screens[name] = nil +end + +return ScreenList \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua new file mode 100644 index 0000000..6fe8196 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -0,0 +1,42 @@ +local GuiScreen = Object:extend() +local ElementList = require "birb.modules.gui.mixins.elements" +local ScreenList = require "birb.modules.gui.mixins.screens" +GuiScreen:implement(ScreenList) +GuiScreen:implement(ElementList) + +function GuiScreen:new(controller, name) + self.controller = controller + self.name = name + self.isVisible = false + self:reset() +end + +function GuiScreen:getGui() + local scene = core.scenemanager.currentScene + return scene.gui +end + +function GuiScreen:reset() + self:initElements() + self:initScreens() +end + +function GuiScreen:registerElements() + local elementList = self:createElements() + for _, element in ipairs(elementList) do + if (element.is ~= nil) then + self:addElement(element.name, element) + else + self:addElement(element[1].name, element[1]) + if (element[2] == false) then + element[1].isVisible = false + end + end + end +end + +function GuiScreen:createElements() + -- Empty function +end + +return GuiScreen \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/scenes.lua b/sonic-radiance.love/birb/modules/scenes.lua index 6a9750e..646b8a6 100644 --- a/sonic-radiance.love/birb/modules/scenes.lua +++ b/sonic-radiance.love/birb/modules/scenes.lua @@ -28,6 +28,7 @@ local Scene = Object:extend() local Assets = require(cwd .. "assets") local MenuSystem = require(cwd .. "menusystem") +local Gui = require (cwd .. "gui") -- INIT FUNCTIONS -- Initialize and configure the scene @@ -39,6 +40,7 @@ function Scene:new() self.assets = Assets() self.menusystem = MenuSystem(self) self.sources = core.input:getSources() + self.gui = Gui(self) self.inputLocked = true self.inputLockedTimer = 2 @@ -71,6 +73,7 @@ function Scene:updateScene(dt) self.assets:update(dt) self:updateMenus(dt) self:updateDialog(dt) + self.gui:update(dt) self:updateWorld(dt) self:update(dt) self:updateEnd(dt) @@ -150,9 +153,11 @@ function Scene:drawScene() self:drawWorld() self:draw() self:drawMenus() + self.gui:drawBottom() self:drawDialog() self:drawEnd() core.screen:drawTransition() + self.gui:drawTop() self:drawOverTransition() end -- 2.30.2 From 7218b7892ef6b1e6f868883a2755fa3f531a24ef Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 21 Aug 2021 17:00:42 +0200 Subject: [PATCH 002/102] feat: add a parent scene class for the game --- sonic-radiance.love/game/modules/subgames/init.lua | 4 +--- sonic-radiance.love/game/scenes/init.lua | 13 +++++++++++++ sonic-radiance.love/scenes/battlesystem/init.lua | 3 +-- .../scenes/menus/debugmenus/animation/init.lua | 3 +-- .../scenes/menus/debugmenus/battleBack/init.lua | 3 +-- .../scenes/menus/debugmenus/choregraphy/init.lua | 3 +-- sonic-radiance.love/scenes/menus/mainmenu/init.lua | 3 +-- sonic-radiance.love/scenes/menus/options/init.lua | 3 +-- .../scenes/menus/titlescreen/init.lua | 5 +---- sonic-radiance.love/scenes/overworld/init.lua | 5 +---- .../overworld/screens/mainmenu/character/init.lua | 1 - .../scenes/overworld/screens/mainmenu/items.lua | 1 - 12 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 sonic-radiance.love/game/scenes/init.lua diff --git a/sonic-radiance.love/game/modules/subgames/init.lua b/sonic-radiance.love/game/modules/subgames/init.lua index 358dd3e..1c383c3 100644 --- a/sonic-radiance.love/game/modules/subgames/init.lua +++ b/sonic-radiance.love/game/modules/subgames/init.lua @@ -1,14 +1,12 @@ -local Scene = require("birb.modules.scenes") +local Scene = require("game.scenes") local PlayStyle = Scene:extend() local PauseMenu = require("game.modules.subgames.pause") local TestWorld = require("game.modules.subgames.world.parent") function PlayStyle:new(supportedLevels, missionfile) - PlayStyle.super.new(self) self.timer = 0 - self.assets:batchImport("assets.commons") self.assets:batchImport("assets.subgames") --self:loadMissionFile(supportedLevels, missionfile) diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua new file mode 100644 index 0000000..83c1e81 --- /dev/null +++ b/sonic-radiance.love/game/scenes/init.lua @@ -0,0 +1,13 @@ +local BirbScene = require "birb.modules.scenes" +local RadianceScene = BirbScene:extend() + +function RadianceScene:new() + RadianceScene.super.new(self) + + -- Importation Global des assets + self.assets:batchImport("assets.commons") + self.assets.fonts["small"]:setLineHeight(16/18) + self.assets.fonts["small"]:setFilter("shadow") +end + +return RadianceScene \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 0418eb9..6a7a474 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -1,4 +1,4 @@ -local Scene = require "birb.modules.scenes" +local Scene = require "game.scenes" local BattleSystem = Scene:extend() @@ -14,7 +14,6 @@ local TweenManager = require "birb.classes.time" function BattleSystem:new(battleData) BattleSystem.super.new(self) - self.assets:batchImport("assets.commons") self.assets:batchImport("assets.battle") self:playMusic(battleData.music) diff --git a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua index 83d018f..853aabb 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua @@ -1,4 +1,4 @@ -local Scene = require "birb.modules.scenes" +local Scene = require "game.scenes" local menu = require "scenes.menus.debugmenus.animation.menu" local CharAnimViewer = Scene:extend() @@ -8,7 +8,6 @@ local Sprite = require "birb.modules.assets.types.sprites" function CharAnimViewer:new() CharAnimViewer.super.new(self) - self.assets:batchImport("assets.commons") self.assets:batchImport("assets.debug") local mainMenu = menu.commons.DebugMenu(self, "MainMenu") diff --git a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua index d24455a..7928d32 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua @@ -1,4 +1,4 @@ -local Scene = require "birb.modules.scenes" +local Scene = require "game.scenes" local menu = require "scenes.menus.debugmenus.battleBack.menu" local BackgroundViewer = Scene:extend() @@ -8,7 +8,6 @@ local backgroundList = require "datas.gamedata.maps.shoot.zones" function BackgroundViewer:new() BackgroundViewer.super.new(self) - self.assets:batchImport("assets.commons") self.assets:batchImport("assets.debug") menu.commons.DebugMenu(self, "MainMenu") diff --git a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua index 16c501e..8105301 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua @@ -1,4 +1,4 @@ -local Scene = require "birb.modules.scenes" +local Scene = require "game.scenes" local menu = require "scenes.menus.debugmenus.choregraphy.menu" local ChoregraphyViewer = Scene:extend() @@ -8,7 +8,6 @@ local Fighter = require "scenes.menus.debugmenus.choregraphy.mocks.fighter" function ChoregraphyViewer:new() ChoregraphyViewer.super.new(self) - self.assets:batchImport("assets.commons") self.assets:batchImport("assets.battle") self.world = World(self) diff --git a/sonic-radiance.love/scenes/menus/mainmenu/init.lua b/sonic-radiance.love/scenes/menus/mainmenu/init.lua index 6082bc2..1c031bb 100644 --- a/sonic-radiance.love/scenes/menus/mainmenu/init.lua +++ b/sonic-radiance.love/scenes/menus/mainmenu/init.lua @@ -1,4 +1,4 @@ -local Scene = require "birb.modules.scenes" +local Scene = require "game.scenes" local menu = require "scenes.menus.mainmenu.menu" local DebugMenu = Scene:extend() @@ -11,7 +11,6 @@ local TweenManager = require "birb.classes.time" function DebugMenu:new() DebugMenu.super.new(self) - self.assets:batchImport("assets.commons") menu.commons.MainMenu(self, "BaseMenu") menu.StartGameWidget(self, "BaseMenu") menu.commons.SceneWidget(self, "BaseMenu", scenes.menus.options, "Options") diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index ad7ace7..a0e5f7b 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -1,4 +1,4 @@ -local Scene = require "birb.modules.scenes" +local Scene = require "game.scenes" local OptionsMenu = Scene:extend() local OptionMenu = require "scenes.menus.options.menu" @@ -10,7 +10,6 @@ local MenuBack = require "game.modules.gui.menuback" function OptionsMenu:new() OptionsMenu.super.new(self) - self.assets:batchImport("assets.commons") self:addMenu("main", true) self:addSubMenu("video", "Video") self:addSubMenu("audio", "Audio") diff --git a/sonic-radiance.love/scenes/menus/titlescreen/init.lua b/sonic-radiance.love/scenes/menus/titlescreen/init.lua index abca10b..f5ee9de 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/init.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/init.lua @@ -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 "game.scenes" local TitleScreen = Scene:extend() local gui = require "game.modules.gui" @@ -34,11 +34,8 @@ function TitleScreen:new(fromMenu) local fromMenu = (fromMenu == true) self.borders = gui.newBorder(424, 30, 8) - self.assets:batchImport("assets.commons") self.assets:addImage("logo", "assets/artworks/logo.png") self.assets:addTileset("charicons", "assets/sprites/characters/charicons") - self.assets.fonts["small"]:setLineHeight(16/18) - self.assets.fonts["small"]:setFilter("shadow") self.tweens = TweenManager(self) self:initBackground() diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 004ea9e..67f1648 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -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 "game.scenes" local OverWorld = Scene:extend() local World = require "scenes.overworld.world" @@ -38,10 +38,7 @@ local MessageQueue = require "game.modules.messagequeue" function OverWorld:new(area, playerx, playery) OverWorld.super.new(self) self.charsetManager = CharsetManager(self) - self.assets:batchImport("assets.commons") self.assets:batchImport("assets.overworld") - self.assets.fonts["small"]:setLineHeight(16/18) - self.assets.fonts["small"]:setFilter("shadow") self.tweens = TweenManager(self) self.screens = screens diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua index a5b307a..e442e9d 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua @@ -72,7 +72,6 @@ function CharacterScreen:setMenu() end function CharacterScreen:draw() - self.scene.assets.fonts["small"]:setLineHeight(16/18) if (self.page ~= nil) then self.page:draw() end diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua index 6b024f7..65e1308 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua @@ -90,7 +90,6 @@ function ItemsScreen:removeUseMenu() end function ItemsScreen:draw() - self.scene.assets.fonts["small"]:setLineHeight(16/18) self:drawPocket() self:drawDescription(const.X, const.Y2 - (88+16)) self:drawEffects(const.X, const.Y2 - 40) -- 2.30.2 From c586fb733d66ff643d88adabd4317b6f49539b46 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 21 Aug 2021 17:05:49 +0200 Subject: [PATCH 003/102] fix: replace drawAnimation by draw --- sonic-radiance.love/birb/modules/assets/types/sprites.lua | 6 +++--- .../birb/modules/world/actors/utils/sprites.lua | 2 +- sonic-radiance.love/game/modules/gui/emblem.lua | 2 +- sonic-radiance.love/scenes/battlesystem/actors/parent.lua | 4 ++-- .../scenes/menus/debugmenus/animation/init.lua | 2 +- sonic-radiance.love/scenes/overworld/actors/encounter.lua | 2 +- .../scenes/overworld/actors/player/actions.lua | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sonic-radiance.love/birb/modules/assets/types/sprites.lua b/sonic-radiance.love/birb/modules/assets/types/sprites.lua index b7cf49d..7f21a22 100644 --- a/sonic-radiance.love/birb/modules/assets/types/sprites.lua +++ b/sonic-radiance.love/birb/modules/assets/types/sprites.lua @@ -97,11 +97,11 @@ end -- DRAW FUNCTIONS -- Draw sprites using these functions -function Sprite:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky) +function Sprite:draw(x, y, r, sx, sy, ox, oy, kx, ky) self.animator:draw(x, y, r, sx, sy, ox, oy, kx, ky) end -function Sprite:drawAnimationMask(x, y, r, sx, sy, ox, oy, kx, ky) +function Sprite:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) self.animator:drawMask(x, y, r, sx, sy, ox, oy, kx, ky) end @@ -122,7 +122,7 @@ function Sprite:drawPart(x, y, w, h, r, sx, sy, ox, oy, kx, ky) end love.graphics.setScissor(x - ox, y - oy, w, h) - self:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky) + self:draw(x, y, r, sx, sy, ox, oy, kx, ky) love.graphics.setScissor( ) end diff --git a/sonic-radiance.love/birb/modules/world/actors/utils/sprites.lua b/sonic-radiance.love/birb/modules/world/actors/utils/sprites.lua index 293f378..2a1012d 100644 --- a/sonic-radiance.love/birb/modules/world/actors/utils/sprites.lua +++ b/sonic-radiance.love/birb/modules/world/actors/utils/sprites.lua @@ -112,7 +112,7 @@ function Sprite:draw(x, y, r, sx, sy, ox, oy, kx, ky) if (self.spriteClone ~= nil) then self.spriteClone:draw(x, y, r, sx, sy, ox, oy, kx, ky) else - self.assets.sprites[self.name]:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky) + self.assets.sprites[self.name]:draw(x, y, r, sx, sy, ox, oy, kx, ky) end end end diff --git a/sonic-radiance.love/game/modules/gui/emblem.lua b/sonic-radiance.love/game/modules/gui/emblem.lua index 6d15a80..2721a9a 100644 --- a/sonic-radiance.love/game/modules/gui/emblem.lua +++ b/sonic-radiance.love/game/modules/gui/emblem.lua @@ -18,7 +18,7 @@ function Emblem:drawForeground(x, y) local emblem2 = "m_" .. self.abstract.data.class core.screen:setScissor(x, y-16, 32, 40) if (self.abstract.hp > 0) then - self.assets.sprites[self.charid]:drawAnimation(x+14, y+14) + self.assets.sprites[self.charid]:draw(x+14, y+14) else greyscale.startShader() self.assets.sprites[self.charid]:drawFrame(1, x+14, y+14) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua index e74441f..d1d5d63 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua @@ -200,7 +200,7 @@ function Parent:drawSprite(tx, ty) if (self.sprite.clone ~= nil) then self.sprite.clone:draw(x + tx, y + ty, 0, sx, sy, self.sprite.ox, self.sprite.oy) else - self.assets.sprites[self.sprite.name]:drawAnimation(x + tx, y + ty, 0, sx, sy, self.sprite.ox, self.sprite.oy) + self.assets.sprites[self.sprite.name]:draw(x + tx, y + ty, 0, sx, sy, self.sprite.ox, self.sprite.oy) end end end @@ -285,7 +285,7 @@ function Parent:drawShadow() local x, y = self.world.map:gridToPixel(self.x, self.y, true) self.assets.images["actorsShadow"]:draw(x, y, 0, self.sprite.sx, self.sprite.sy, 12, 5) if (self.isSelected == true) then - self.assets.sprites["cursorground"]:drawAnimation(x - 2, y - 1, 0, 1, 1, 12, 5) + self.assets.sprites["cursorground"]:draw(x - 2, y - 1, 0, 1, 1, 12, 5) end end diff --git a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua index 853aabb..023f999 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua @@ -54,7 +54,7 @@ end function CharAnimViewer:draw() self.background:draw() if (self.sprite ~= nil) then - self.sprite:drawAnimation(424/2, 240/1.5) + self.sprite:draw(424/2, 240/1.5) end end diff --git a/sonic-radiance.love/scenes/overworld/actors/encounter.lua b/sonic-radiance.love/scenes/overworld/actors/encounter.lua index 9cccda1..53aa5c3 100644 --- a/sonic-radiance.love/scenes/overworld/actors/encounter.lua +++ b/sonic-radiance.love/scenes/overworld/actors/encounter.lua @@ -30,7 +30,7 @@ function Encounter:drawCharset(charset, charId) self.assets.images["shadow"]:draw(x, y + 11) utils.graphics.resetColor() - self.assets.sprites["encounter"]:drawAnimation(x - 1, y + 10) + self.assets.sprites["encounter"]:draw(x - 1, y + 10) end return Encounter \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua index 4d82e2c..3aa3dfe 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua @@ -219,7 +219,7 @@ function PlayerActions:drawActionEffect() dy = -8 end local x, y = self.x + 8 - dx, self.y + 8 - self.z + dy - self.assets.sprites["dash"]:drawAnimation(x, y, math.rad(self.charsetManager.angle[self.charDir])) + self.assets.sprites["dash"]:draw(x, y, math.rad(self.charsetManager.angle[self.charDir])) end if (self.currentAction == "punch") then local dx, dy = utils.math.lengthdir(20, math.rad(self.charsetManager.angle[self.charDir])) @@ -227,7 +227,7 @@ function PlayerActions:drawActionEffect() dy = 8 end local x, y = self.x + 8 - dx, self.y + 8 - self.z + dy - self.assets.sprites["punch"]:drawAnimation(x, y, math.rad(self.charsetManager.angle[self.charDir])) + self.assets.sprites["punch"]:draw(x, y, math.rad(self.charsetManager.angle[self.charDir])) end end -- 2.30.2 From c658f68e147448d2845106595c34633f49dc31a4 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 12:39:44 +0200 Subject: [PATCH 004/102] feat: add depth sorting --- .../birb/modules/gui/elements/parent.lua | 2 +- .../birb/modules/gui/mixins/elements.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index e672886..f0653b0 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -20,7 +20,7 @@ end function GuiElement:register() local gui = self:getGui() - gui:addElement(self.name, self) + self.creationId = gui:addElement(self.name, self) end function GuiElement:destroy() diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index a5270a8..ddfb608 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -3,10 +3,13 @@ local ElementList = Object:extend() function ElementList:initElements() self.elements = {} self.focusedElem = nil + self.nbrElement = 0 end function ElementList:addElement(name, element) + self.nbrElement = self.nbrElement + 1 self.elements[name] = element + return self.nbrElement end function ElementList:deleteElement(name) @@ -22,6 +25,15 @@ function ElementList:getVisibleElement(topLayer) end end end + + table.sort(visibleList, function (a, b) + if (a.depth == b.depth) then + return (a.creationId < b.creationId) + else + return (a.depth > b.depth) + end + end) + return visibleList end -- 2.30.2 From 401d5340fbe58a7bc2b5063ada6a2b6da8b01acd Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 13:02:52 +0200 Subject: [PATCH 005/102] fix: fix guiElements drawing --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 6 +++--- sonic-radiance.love/birb/modules/gui/mixins/elements.lua | 2 +- sonic-radiance.love/birb/modules/scenes.lua | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index f0653b0..ad6ee1d 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -1,11 +1,11 @@ -local Rect = require "birb.objects.2D.rect" +local Rect = require "birb.classes.2D.rect" local GuiElement = Rect:extend() function GuiElement:new(name, x, y, w, h) GuiElement.super.new(self, x, y, w, h) self.name = name - self.isVisible = false + self.isVisible = true self.screen = nil self.depth = 0 @@ -14,7 +14,7 @@ function GuiElement:new(name, x, y, w, h) end function GuiElement:getGui() - local scene = core.scenemanager.currentScene + local scene = core.scenemanager.nextScene or core.scenemanager.currentScene return scene.gui end diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index ddfb608..a7a5020 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -18,7 +18,7 @@ end function ElementList:getVisibleElement(topLayer) local visibleList = {} - for _, element in ipairs(self.elements) do + for _, element in pairs(self.elements) do if (element ~= nil) then if (element:getVisibility() and ((element.depth) < 0 == topLayer)) then table.insert(visibleList, element) diff --git a/sonic-radiance.love/birb/modules/scenes.lua b/sonic-radiance.love/birb/modules/scenes.lua index 646b8a6..45218ac 100644 --- a/sonic-radiance.love/birb/modules/scenes.lua +++ b/sonic-radiance.love/birb/modules/scenes.lua @@ -151,9 +151,9 @@ end function Scene:drawScene() self:drawStart() self:drawWorld() + self.gui:drawBottom() self:draw() self:drawMenus() - self.gui:drawBottom() self:drawDialog() self:drawEnd() core.screen:drawTransition() -- 2.30.2 From f1b61c9db7f2de45bb79dc546796aadaa7e0867b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 13:46:33 +0200 Subject: [PATCH 006/102] feat: add basic tweening to guiElements --- .../birb/modules/gui/elements/parent.lua | 20 +++++++++++++++++++ sonic-radiance.love/birb/modules/gui/init.lua | 17 +++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index ad6ee1d..7b5f9e1 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -1,6 +1,8 @@ local Rect = require "birb.classes.2D.rect" local GuiElement = Rect:extend() +local TweenManager = require "birb.classes.time" + function GuiElement:new(name, x, y, w, h) GuiElement.super.new(self, x, y, w, h) self.name = name @@ -10,6 +12,8 @@ function GuiElement:new(name, x, y, w, h) self.depth = 0 + self.tweens = TweenManager(self) + self:register() end @@ -73,6 +77,7 @@ end -- External update function function GuiElement:updateElement(dt) self:update(dt) + self.tweens:update(dt) end -- Internal update function @@ -80,6 +85,21 @@ function GuiElement:update(dt) -- Cette fonction ne contient rien par défaut end +-- TWEEN FUNCTIONS +-- Handle tweening + +function GuiElement:newTween(start, duration, target, easing) + self.tweens:newTween(start, duration, target, easing) +end + +function GuiElement:newMovement(start, duration, x, y, easing) + self:newTween(start, duration, {x = x, y = y}, easing) +end + +function GuiElement:newSwitch(start, bools) + self:newSwitch(start, bools) +end + -- DRAW FUNCTIONS -- Draw the menu and its content diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 06319f0..ebccac2 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -40,13 +40,28 @@ function Gui:reset() end function Gui:update(dt) - for _, element in ipairs(self.elements) do + for _, element in pairs(self.elements) do if (element ~= nil) then element:updateElement(dt) end end end +-- TWEEN FUNCTIONS +-- Handle tweening + +function Gui:newTween(element, start, duration, target, easing) + self.elements[element]:newTween(start, duration, target, easing) +end + +function Gui:newMovement(element, start, duration, x, y, easing) + self.elements[element]:newMovement(start, duration, x, y, easing) +end + +function Gui:newSwitch(element, start, bools) + self.elements[element]:newSwitch(start, bools) +end + -- DRAW FUNCTIONS -- Draw the menu and its content -- 2.30.2 From dd0fcf2547ccfe5f6f9cb52fb1a72a0271f777f2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 16:38:27 +0200 Subject: [PATCH 007/102] feat: add transformation from list --- sonic-radiance.love/birb/modules/gui/init.lua | 20 +++++++++++++++++++ sonic-radiance.love/birb/structures/tween.lua | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 sonic-radiance.love/birb/structures/tween.lua diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index ebccac2..a826238 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -28,6 +28,7 @@ local ScreenList = require "birb.modules.gui.mixins.screens" Gui:implement(ScreenList) Gui:implement(ElementList) +local TransformDataStruct = require "birb.structures.tween" function Gui:new(scene) self.scene = scene @@ -50,6 +51,25 @@ end -- TWEEN FUNCTIONS -- Handle tweening +function Gui:transform(data) + for _, rawTransform in ipairs(data) do + self:transformOne(rawTransform) + end +end + +function Gui:transformOne(rawTransform) + local struct = TransformDataStruct[rawTransform[2]] + assert(struct ~= nil, "Structure " .. rawTransform[1] .. " doesn't exists ") + local transform = utils.table.parse(rawTransform, struct, 0) + if transform.type == "tween" then + self:newTween(transform.name, transform.start, transform.duration, transform.target, transform.easing) + elseif transform.type == "movement" then + self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing) + elseif transform.type == "switch" then + self:newSwitch(transform.name, transform.start, transform.bools) + end +end + function Gui:newTween(element, start, duration, target, easing) self.elements[element]:newTween(start, duration, target, easing) end diff --git a/sonic-radiance.love/birb/structures/tween.lua b/sonic-radiance.love/birb/structures/tween.lua new file mode 100644 index 0000000..2b84b41 --- /dev/null +++ b/sonic-radiance.love/birb/structures/tween.lua @@ -0,0 +1,5 @@ +return { + tween = {"name", "type", "start", "duration", "target", "easing"}, + movement = {"name", "type", "start", "duration", "x", "y", "easing"}, + switch = {"name", "type", "start", "bools"}, +} \ No newline at end of file -- 2.30.2 From 39d11596f09231706e757e8f0a8a91e6c6f0e132 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 16:45:43 +0200 Subject: [PATCH 008/102] feat: add some special guiElements --- .../birb/modules/gui/elements/assets.lua | 16 ++++++++++ .../birb/modules/gui/elements/color.lua | 19 ++++++++++++ .../birb/modules/gui/elements/drawable.lua | 30 +++++++++++++++++++ .../birb/modules/gui/elements/text.lua | 22 ++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 sonic-radiance.love/birb/modules/gui/elements/assets.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/color.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/drawable.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/text.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/assets.lua b/sonic-radiance.love/birb/modules/gui/elements/assets.lua new file mode 100644 index 0000000..2e05410 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/assets.lua @@ -0,0 +1,16 @@ +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, depth) + local gui = self:getGui() + local asset = gui.scene.assets[assetType][assetName] + assert(asset ~= nil, assetName .. ' (' .. assetType .. ") doesn't exist") + + AssetElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity, depth) +end + +function AssetElement:draw() + self.drawable:draw(self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy) +end + +return AssetElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/color.lua b/sonic-radiance.love/birb/modules/gui/elements/color.lua new file mode 100644 index 0000000..f1aa94f --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/color.lua @@ -0,0 +1,19 @@ +local Parent = require "birb.modules.gui.elements.parent" +local ColorElement = Parent:extend() + +function ColorElement:new(name, r, g, b, opacity) + local w, h = core.screen:getDimensions() + ColorElement.super.new(self, name, self.x, self.y, w, h) + self.r = r or 1 + self.g = g or 1 + self.b = b or 1 + self.opacity = opacity or 1 +end + +function ColorElement:draw() + love.graphics.setColor(self.r, self.g, self.b, self.opacity) + love.graphics.rectangle("fill", 0, 0, self.w, self.h) + utils.graphics.resetColor() +end + +return ColorElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/drawable.lua b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua new file mode 100644 index 0000000..76c1031 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua @@ -0,0 +1,30 @@ +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, depth) + self.drawable = drawable + + local w, h = self.drawable:getDimensions() + DrawableElement.super.new(self, name, x, y, w, h) + self.r = r or 0 + self.sx, self.sy = sx or 1, sy or 1 + self.ox, self.oy = self:parseOrigin(ox, w), self:parseOrigin(oy, h) + self.opacity = opacity or 1 + self.depth = depth or 0 +end + +function DrawableElement:parseOrigin(origin, size) + if (origin == "center") then + return size/2 + elseif (origin == "end") then + return size + else + return origin or 0 + end +end + +function DrawableElement:draw() + love.graphics.draw(self.drawable, self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy) +end + +return DrawableElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/text.lua b/sonic-radiance.love/birb/modules/gui/elements/text.lua new file mode 100644 index 0000000..ebd4ffa --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/text.lua @@ -0,0 +1,22 @@ +local Parent = require "birb.modules.gui.elements.parent" +local TextElement = Parent:extend() + +function TextElement:new(name, fontName, text, x, y, align, depth) + self.text = text + local gui = self:getGui() + self.font = gui.scene.assets.fonts[fontName] + + TextElement.super.new(self, name, x, y, 1, 1) + self.align = align + self.depth = depth or 0 +end + +function TextElement:getText() + return self.text +end + +function TextElement:draw() + self.font:draw(self:getText(), self.x, self.y, -1, self.align) +end + +return TextElement \ No newline at end of file -- 2.30.2 From c397f9d981de4464f4c05c6c19d53093d44bb307 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 17:22:14 +0200 Subject: [PATCH 009/102] feat: add TimedFunctions --- .../birb/classes/time/func.lua | 14 +++++++++ .../birb/classes/time/init.lua | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 sonic-radiance.love/birb/classes/time/func.lua diff --git a/sonic-radiance.love/birb/classes/time/func.lua b/sonic-radiance.love/birb/classes/time/func.lua new file mode 100644 index 0000000..3684bf4 --- /dev/null +++ b/sonic-radiance.love/birb/classes/time/func.lua @@ -0,0 +1,14 @@ +local Timer = require "birb.classes.time.timer" +local TimedFunction = Timer:extend() + +function TimedFunction:new(actor, name, func, t) + TimedFunction.super.new(self, actor, name, t) + self.func = func +end + +function TimedFunction:finish() + self.actor.funcs[self.name] = nil + self.func() +end + +return TimedFunction \ No newline at end of file diff --git a/sonic-radiance.love/birb/classes/time/init.lua b/sonic-radiance.love/birb/classes/time/init.lua index 006e83a..ebd4b80 100644 --- a/sonic-radiance.love/birb/classes/time/init.lua +++ b/sonic-radiance.love/birb/classes/time/init.lua @@ -27,6 +27,7 @@ local TweenManager = Object:extend() 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 @@ -36,6 +37,7 @@ function TweenManager:new(subject) self.switches = {} self.timers = {} + self.funcs = {} end function TweenManager:newTween(start, duration, target, easing) @@ -84,6 +86,29 @@ function TweenManager:removeTimer(name) self.timers[name] = nil end +-- FUNCTION FUNCTIONS +-- Help to get functions + +function TweenManager:newFunc(start, name, func) + self.funcs[name] = TimedFunction(self, name, func, start) +end + +function TweenManager:delayFunc(time, name, absolute) + if (self.funcs[name] ~= nil) then + self.funcs[name]:delay(time, absolute) + end +end + +function TweenManager:getFuncInfo(name) + if (self.funcs[name] ~= nil) then + return self.funcs[name]:getInfo() + end +end + +function TweenManager:removeFunc(name) + self.funcs[name] = nil +end + -- SWITCH FUNCTIONS -- Help to handle switches @@ -129,6 +154,10 @@ function TweenManager:update(dt) timer:update(dt) end + for k, func in pairs(self.funcs) do + func:update(dt) + end + self:clearEndedTweens() end -- 2.30.2 From 42fbda0c58e6416708ce3e39bb091806dfbbdb7c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 24 Aug 2021 19:41:25 +0200 Subject: [PATCH 010/102] fea(gui): add initial support for inputs --- .../birb/modules/gui/elements/parent.lua | 14 ++++++++---- sonic-radiance.love/birb/modules/gui/init.lua | 22 +++++++++++++++++++ .../birb/modules/gui/mixins/elements.lua | 21 +++++++++++++++++- sonic-radiance.love/birb/modules/scenes.lua | 1 + sonic-radiance.love/birb/structures/tween.lua | 1 + 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 7b5f9e1..5cc2bc7 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -56,18 +56,18 @@ end function GuiElement:getFocus() local gui = self:getGui() - gui.focusedMenu = self.name + gui.focusedElement = self.name end function GuiElement:haveFocus() local gui = self:getGui() - return (gui.focusedMenu == self.name) + return (gui.focusedElement == self.name) end function GuiElement:looseFocus() if (self:haveFocus()) then local gui = self:getGui() - gui.focusedMenu = nil + gui.focusedElement = nil end end @@ -97,7 +97,13 @@ function GuiElement:newMovement(start, duration, x, y, easing) end function GuiElement:newSwitch(start, bools) - self:newSwitch(start, bools) + self.tweens:newSwitch(start, bools) +end + +function GuiElement:delayFocus(start) + self.tweens:newFunc(start, "focus", function () + self:getFocus() + end) end -- DRAW FUNCTIONS diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index a826238..416f066 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -67,6 +67,8 @@ function Gui:transformOne(rawTransform) self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing) elseif transform.type == "switch" then self:newSwitch(transform.name, transform.start, transform.bools) + elseif transform.type == "delayFocus" then + self:delayFocus(transform.name, transform.start) end end @@ -82,6 +84,26 @@ function Gui:newSwitch(element, start, bools) self.elements[element]:newSwitch(start, bools) end +function Gui:delayFocus(element, start) + self.elements[element]:delayFocus(start) +end + +-- KEYBOARD FUNCTIONS +-- Handle keyboard + +function Gui:keycheck(keys) + local haveFocus = self:haveFocus() + if (haveFocus) then + local elem = self:getFocusedElement() + for key,_ in pairs(keys) do + if keys[key].isPressed then + elem:keypressed(key) + end + end + end + return haveFocus +end + -- DRAW FUNCTIONS -- Draw the menu and its content diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index a7a5020..e2dfb10 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -2,7 +2,7 @@ local ElementList = Object:extend() function ElementList:initElements() self.elements = {} - self.focusedElem = nil + self.focusedElement = nil self.nbrElement = 0 end @@ -16,6 +16,25 @@ function ElementList:deleteElement(name) self.elements[name] = nil end +function ElementList:elementExists(name) + return (self:getElement(name) ~= nil) +end + +function ElementList:haveFocus() + return self:elementExists(self.focusedElement) +end + +function ElementList:getFocusedElement() + return self:getElement(self.focusedElement) +end + +function ElementList:getElement(name) + if (not utils.string.isEmpty(name)) then + return self.elements[name] + end + return nil +end + function ElementList:getVisibleElement(topLayer) local visibleList = {} for _, element in pairs(self.elements) do diff --git a/sonic-radiance.love/birb/modules/scenes.lua b/sonic-radiance.love/birb/modules/scenes.lua index 45218ac..552a088 100644 --- a/sonic-radiance.love/birb/modules/scenes.lua +++ b/sonic-radiance.love/birb/modules/scenes.lua @@ -107,6 +107,7 @@ 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 diff --git a/sonic-radiance.love/birb/structures/tween.lua b/sonic-radiance.love/birb/structures/tween.lua index 2b84b41..cbc6147 100644 --- a/sonic-radiance.love/birb/structures/tween.lua +++ b/sonic-radiance.love/birb/structures/tween.lua @@ -2,4 +2,5 @@ return { tween = {"name", "type", "start", "duration", "target", "easing"}, movement = {"name", "type", "start", "duration", "x", "y", "easing"}, switch = {"name", "type", "start", "bools"}, + delayFocus = {"name", "type", "start"}, } \ No newline at end of file -- 2.30.2 From 4322a80571c015bbff8a14fff99f956787cc9714 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 Aug 2021 23:23:22 +0200 Subject: [PATCH 011/102] feat: more screen support --- sonic-radiance.love/birb/modules/gui/init.lua | 51 +++++++++++++++--- .../birb/modules/gui/screen.lua | 54 +++++++++++++++++-- 2 files changed, 95 insertions(+), 10 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 416f066..01c2f0f 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -46,48 +46,85 @@ function Gui:update(dt) element:updateElement(dt) end end + for _, screen in pairs(self.screens) do + if (screen ~= nil) then + screen:update(dt) + end + end end -- TWEEN FUNCTIONS -- Handle tweening -function Gui:transform(data) +function Gui:transform(data, delay) + delay = delay or 0 + + local time = 0 for _, rawTransform in ipairs(data) do - self:transformOne(rawTransform) + local newTime = self:transformOne(rawTransform, delay) + time = math.max(time, newTime) end + return time end -function Gui:transformOne(rawTransform) +function Gui:playScreenTransform(screenname, name, delay) + return self.screens[screenname]:playTransform(name, delay) +end + +function Gui:transformOne(rawTransform, delay) + delay = delay or 0 + local struct = TransformDataStruct[rawTransform[2]] assert(struct ~= nil, "Structure " .. rawTransform[1] .. " doesn't exists ") local transform = utils.table.parse(rawTransform, struct, 0) + + local time = transform.start + delay + if transform.type == "tween" then - self:newTween(transform.name, transform.start, transform.duration, transform.target, transform.easing) + self:newTween(transform.name, time, transform.duration, transform.target, transform.easing) elseif transform.type == "movement" then - self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing) + self:newMovement(transform.name, time, transform.duration, transform.x, transform.y, transform.easing) elseif transform.type == "switch" then - self:newSwitch(transform.name, transform.start, transform.bools) + self:newSwitch(transform.name, time, transform.bools) elseif transform.type == "delayFocus" then - self:delayFocus(transform.name, transform.start) + self:delayFocus(transform.name, time) end + + if (transform.duration ~= nil) then + time = time + transform.duration + end + return time end function Gui:newTween(element, start, duration, target, easing) + assert(self.elements[element] ~= nil, element .. " does not exists") self.elements[element]:newTween(start, duration, target, easing) end function Gui:newMovement(element, start, duration, x, y, easing) + assert(self.elements[element] ~= nil, element .. " does not exists") self.elements[element]:newMovement(start, duration, x, y, easing) end function Gui:newSwitch(element, start, bools) + assert(self.elements[element] ~= nil, element .. " does not exists") self.elements[element]:newSwitch(start, bools) end function Gui:delayFocus(element, start) + assert(self.elements[element] ~= nil, element .. " does not exists") self.elements[element]:delayFocus(start) end +function Gui:hideScreen(screenname) + self.screens[screenname]:hide() +end + + +function Gui:showScreen(screenname) + self.screens[screenname]:show() +end + -- KEYBOARD FUNCTIONS -- Handle keyboard diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua index 6fe8196..9ecddf6 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -4,15 +4,61 @@ local ScreenList = require "birb.modules.gui.mixins.screens" GuiScreen:implement(ScreenList) GuiScreen:implement(ElementList) -function GuiScreen:new(controller, name) - self.controller = controller +local TweenManager = require "birb.classes.time" + +function GuiScreen:new(name, controller) + self.controller = controller or self:getGui() self.name = name self.isVisible = false + self.transforms = {} + self.tweens = TweenManager(self) + self:reset() + self:registerElements() + self.controller:addScreen(name, self) +end + +function GuiScreen:update(dt) + self.tweens:update(dt) + for _, screen in pairs(self.screens) do + if (screen ~= nil) then + screen:update(dt) + end + end +end + +function GuiScreen:show() + if (not self.isVisible) then + self.isVisible = true + if (self.transforms["show"] ~= nil) then + self:playTransform("show") + end + end +end + +function GuiScreen:hide() + if (self.isVisible) then + if (self.transforms["hide"] ~= nil) then + local time = self:playTransform("hide") + print(time) + self.tweens:newFunc(time, "hide", function () + self.isVisible = false + end) + end + end +end + +function GuiScreen:addTransform(name, transform) + self.transforms[name] = transform +end + +function GuiScreen:playTransform(name, delay) + local gui = self:getGui() + return gui:transform(self.transforms[name], delay) end function GuiScreen:getGui() - local scene = core.scenemanager.currentScene + local scene = core.scenemanager.nextScene or core.scenemanager.currentScene return scene.gui end @@ -26,11 +72,13 @@ function GuiScreen:registerElements() for _, element in ipairs(elementList) do if (element.is ~= nil) then self:addElement(element.name, element) + element.screen = self else self:addElement(element[1].name, element[1]) if (element[2] == false) then element[1].isVisible = false end + element[1].screen = self end end end -- 2.30.2 From 01a30e73b2df24d023a2058b621c52ed218307cf Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 Aug 2021 23:23:32 +0200 Subject: [PATCH 012/102] feat: add an either function --- sonic-radiance.love/birb/utils/math.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sonic-radiance.love/birb/utils/math.lua b/sonic-radiance.love/birb/utils/math.lua index 47ded13..3d0ba85 100644 --- a/sonic-radiance.love/birb/utils/math.lua +++ b/sonic-radiance.love/birb/utils/math.lua @@ -56,6 +56,14 @@ function Math.between(num, value1, value2) return math.min(math.max(num, min), max) end +function Math.either(bool, val1, val2) + if (bool) then + return val1 + else + return val2 + end +end + -- VECTOR/DIRECTION functions -- Easy-to-use function to handle point and motion -- 2.30.2 From 5f1a9d20d0e9b34a8bc6365af9f137ee307fb882 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 Aug 2021 23:27:21 +0200 Subject: [PATCH 013/102] feat: add overlay --- .../game/modules/gui/overlay.lua | 96 +++++++++++++++++++ sonic-radiance.love/game/scenes/init.lua | 15 ++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/game/modules/gui/overlay.lua diff --git a/sonic-radiance.love/game/modules/gui/overlay.lua b/sonic-radiance.love/game/modules/gui/overlay.lua new file mode 100644 index 0000000..ae18c4c --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/overlay.lua @@ -0,0 +1,96 @@ +local GuiScreen = require "birb.modules.gui.screen" +local TextureElement = require "birb.modules.gui.elements.drawable" +local ColorElement = require "birb.modules.gui.elements.color" +local TextElement = require "birb.modules.gui.elements.text" + +local OverlayScreen = GuiScreen:extend() + +local gui = require "game.modules.gui" +local either = utils.math.either + +local OVERLAY_OPACITY = 0.5 +local wasActive = false +local hadVersion = false + +local animateAppear = { + {"upBorder", "movement", 0.0, 0.5, 0, 30, "inOutQuart"}, + {"downBorder", "movement", 0.0, 0.5, 424, 210, "inOutQuart"} +} + +local animateDisappear = { + {"upBorder", "movement", 0.0, 0.5, 0, 0, "inOutQuart"}, + {"downBorder", "movement", 0.0, 0.5, 424, 240, "inOutQuart"}, + {"version", "movement", 0.0, 0.5, 380, 250, "inOutQuart"}, + {"overlayDarken", "tween", 0.0, 0.4, {opacity = 0}, "outExpo"} +} + +local showBackground = { + {"overlayDarken", "tween", 0.0, 0.4, {opacity = OVERLAY_OPACITY}, "inExpo"} +} + +local hideBackground = { + {"overlayDarken", "tween", 0.0, 0.4, {opacity = 0}, "outExpo"} +} + +local showVersion = { + {"version", "movement", 0.0, 0.5, 380, 220, "inOutQuart"}, +} + +local hideVersion = { + {"version", "movement", 0.0, 0.5, 380, 250, "inOutQuart"}, +} + +function OverlayScreen:new(active, doShowVersion) + self.borders = gui.newBorder(424, 30, 8) + self.doShowVersion = doShowVersion + + OverlayScreen.super.new(self, "overlay") + + local transformStuff = false + if (active == wasActive) then + self.isVisible = active + else + transformStuff = true + end + + self:addTransform("show", animateAppear) + self:addTransform("hide", animateDisappear) + self:addTransform("showBackground", showBackground) + self:addTransform("hideBackground", hideBackground) + self:addTransform("showVersion", showVersion) + self:addTransform("hideVersion", hideVersion) + + if (transformStuff) then + if (active) then + self:show() + else + self:hide() + end + end + + if (active) then + if (self.doShowVersion) then + self:playTransform("showVersion") + else + self:playTransform("hideVersion") + end + end +end + +function OverlayScreen:update(dt) + wasActive = self.isVisible + hadVersion = self.doShowVersion +end + +function OverlayScreen:createElements() + local d = either(wasActive, 30, 0) + local v = either(hadVersion, 30, 0) + return { + {TextureElement("upBorder", self.borders, 0, d, 0, 1, -1, 0, 0, 1, -1), 0}, + {TextureElement("downBorder", self.borders, 424, 240 - d, 0, -1, 1, 0, 0, 1, -1), 0}, + {ColorElement("overlayDarken", 0, 0, 0, 0), 0}, + {TextElement("version", "small", "v" .. game.version, 380, 250 - v, "left", -1), 0} + } +end + +return OverlayScreen \ No newline at end of file diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua index 83c1e81..10bf7d6 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -1,13 +1,26 @@ local BirbScene = require "birb.modules.scenes" local RadianceScene = BirbScene:extend() -function RadianceScene:new() +local Overlay = require "game.modules.gui.overlay" + +function RadianceScene:new(haveBorder, showVersion) RadianceScene.super.new(self) -- Importation Global des assets self.assets:batchImport("assets.commons") self.assets.fonts["small"]:setLineHeight(16/18) self.assets.fonts["small"]:setFilter("shadow") + + Overlay(haveBorder, showVersion) end +function RadianceScene:hideOverlay() + self.gui:hideScreen("overlay") +end + +function RadianceScene:showOverlay() + self.gui:showScreen("overlay") +end + + return RadianceScene \ No newline at end of file -- 2.30.2 From c37048a49a2075ebdbf607842f2c6da17dae15e4 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 Aug 2021 23:27:43 +0200 Subject: [PATCH 014/102] improvement: make menuback a gui element --- .../game/modules/gui/menuback.lua | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/sonic-radiance.love/game/modules/gui/menuback.lua b/sonic-radiance.love/game/modules/gui/menuback.lua index e9bcf20..8439d58 100644 --- a/sonic-radiance.love/game/modules/gui/menuback.lua +++ b/sonic-radiance.love/game/modules/gui/menuback.lua @@ -1,4 +1,9 @@ -local MenuBack = Object:extend() +local TextureElement = require "birb.modules.gui.elements.parent" +local MenuBack = TextureElement:extend() + +local backx = 0 +local bordery = 0 +local turn = 0 local fancyBackShader = love.graphics.newShader[[ uniform number screenWidth; @@ -13,52 +18,55 @@ local fancyBackShader = love.graphics.newShader[[ ]] function MenuBack:new() - self.backx = 0 - self.bordery = 0 - self.turn = 0 self.back = love.graphics.newImage("assets/gui/back/background.png") self.border = love.graphics.newImage("assets/gui/back/border.png") self.emblem = love.graphics.newImage("assets/gui/back/emblem.png") self.star = love.graphics.newImage("assets/gui/back/star.png") + self.backImage = love.graphics.newImage("assets/artworks/back.png") self.canvas = nil local w, h = love.graphics.getDimensions() fancyBackShader:send("screenWidth",w) fancyBackShader:send("screenHeight",h) + MenuBack.super.new(self, "menuBack", 0, 0, w, h) + self.depth = 200 end function MenuBack:update(dt) - self.backx = (self.backx + dt * 20) % 96 - self.bordery = (self.bordery + dt * 35) % 160 - self.turn = self.turn + (dt/1.5) % 1 + backx = (backx + dt * 20) % 96 + bordery = (bordery + dt * 35) % 160 + turn = turn + (dt/1.5) % 1 self.canvas = love.graphics.newCanvas( 424, 240 ) love.graphics.setCanvas(self.canvas) for i = 0, (math.ceil(424/96)), 1 do for j = 0, (math.ceil(240/96)), 1 do - love.graphics.draw(self.back, self.backx + ((i - 1 ) * 96), self.backx + ((j - 1 ) * 96)) + love.graphics.draw(self.back, backx + ((i - 1 ) * 96), backx + ((j - 1 ) * 96)) end end for j = 0, (math.ceil(240/160)), 1 do - love.graphics.draw(self.border, 0, self.bordery + ((j - 1) * 160)) + love.graphics.draw(self.border, 0, bordery + ((j - 1) * 160)) end love.graphics.draw(self.emblem, 424, 240 - 32, 0, 0.8, 0.8, 200, 200) - love.graphics.draw(self.star, 424, 240 - 32, self.turn, 0.8, 0.8, 200, 200) + love.graphics.draw(self.star, 424, 240 - 32, turn, 0.8, 0.8, 200, 200) love.graphics.setColor(1, 1, 1, 1) love.graphics.setCanvas() - end function MenuBack:draw() + love.graphics.setColor(1, 1, 1, 1) + love.graphics.rectangle("fill", 0, 0, 424, 240) love.graphics.setShader(fancyBackShader) if (self.canvas ~= nil) then love.graphics.draw(self.canvas, 0, 0) end love.graphics.setShader() + utils.graphics.resetColor() + love.graphics.draw(self.backImage, 0, 0) end return MenuBack \ No newline at end of file -- 2.30.2 From 12ef4728a862c358ce219372b57d68a879073975 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 27 Aug 2021 00:44:01 +0200 Subject: [PATCH 015/102] feat: add birb's menu to the gui system --- .../birb/modules/gui/elements/parent.lua | 2 +- .../birb/modules/gui/menus/flowbox.lua | 144 +++++++++ .../birb/modules/gui/menus/grid.lua | 276 ++++++++++++++++++ .../birb/modules/gui/menus/hlistbox.lua | 101 +++++++ .../birb/modules/gui/menus/listbox.lua | 100 +++++++ .../birb/modules/gui/menus/model/init.lua | 189 ++++++++++++ .../birb/modules/gui/menus/model/page.lua | 185 ++++++++++++ .../birb/modules/gui/menus/parent.lua | 243 +++++++++++++++ .../birb/modules/gui/menus/views/view1D.lua | 49 ++++ .../birb/modules/gui/menus/views/view2D.lua | 61 ++++ .../birb/modules/gui/menus/widgets/base.lua | 156 ++++++++++ .../birb/modules/gui/menus/widgets/init.lua | 30 ++ .../birb/modules/gui/menus/widgets/text.lua | 95 ++++++ .../birb/modules/gui/mixins/elements.lua | 6 + .../birb/modules/gui/textmenu/init.lua | 78 +++++ .../modules/gui/textmenu/widgets/back.lua | 37 +++ .../modules/gui/textmenu/widgets/basic.lua | 47 +++ .../modules/gui/textmenu/widgets/init.lua | 31 ++ .../modules/gui/textmenu/widgets/submenu.lua | 39 +++ .../birb/modules/gui/utils.lua | 57 ++++ 20 files changed, 1925 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/birb/modules/gui/menus/flowbox.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/grid.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/listbox.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/model/init.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/model/page.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/parent.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/views/view2D.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/widgets/init.lua create mode 100644 sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua create mode 100644 sonic-radiance.love/birb/modules/gui/textmenu/init.lua create mode 100644 sonic-radiance.love/birb/modules/gui/textmenu/widgets/back.lua create mode 100644 sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua create mode 100644 sonic-radiance.love/birb/modules/gui/textmenu/widgets/init.lua create mode 100644 sonic-radiance.love/birb/modules/gui/textmenu/widgets/submenu.lua create mode 100644 sonic-radiance.love/birb/modules/gui/utils.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 5cc2bc7..5103a04 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -120,7 +120,7 @@ end -- KEYBOARD FUNCTIONS -- Handle key press -function GuiElement:keyreleased(key) +function GuiElement:keypressed(key) -- Cette fonction ne contient rien par défaut end diff --git a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua new file mode 100644 index 0000000..f0a40fb --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua @@ -0,0 +1,144 @@ +-- 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 View2D = require(cwd .. "views.view2D") + +-- INIT FUNCTIONS +-- Initialize and configure the flowbox + +function FlowBox:new(name, x, y, w, h, slots_hor, slots_vert) + self.view = View2D(slots_hor, slots_vert) + FlowBox.super.new(self, name, x, y, w, h) + self:setRealSize() +end + +function FlowBox:setRealSize() + -- On fait en sorte que la hauteur et la largeur + -- soit un multiple du nombre de slot et de leur dimensions + self:updateWidgetSize() + self.w = self.view.colNumber * self.widgetSize.w + self.h = self.view.lineNumber * self.widgetSize.h +end + +function FlowBox:resetView() + self.view:reset() +end + +-- UPDATE FUNCTIONS +-- Update the menu and its view + +function FlowBox:updateWidgetSize() + self.widgetSize.h = math.floor( self.h / self.view.lineNumber ) + self.widgetSize.w = math.floor( self.w / self.view.colNumber ) +end + +function FlowBox:update(dt) + self.view:updateFirstSlot(self.widget:getSelected()) +end + +-- CURSOR FUNCTIONS +-- Handle the cursor in a 2D menu + +function FlowBox:moveCursor2D(new_col, new_line) + local lastcol, lastline = self.view:getCoord(self.widget:lenght()) + + new_line = utils.math.wrapAndLimit(new_line, 0, lastline) + + if (new_line == lastline) then + new_col = utils.math.wrapAndLimit(new_col, 0, lastcol) + else + new_col = utils.math.wrapAndLimit(new_col, 0, (self.view.colNumber - 1)) + end + + self.widget:moveCursor((new_line * self.view.colNumber) + new_col + 1) +end + +-- KEYS FUNCTIONS +-- Handle the keyboard/controller inputs + +function FlowBox:moveByKeys(key) + local col, line = self.view:getCoord(self.widget:getSelected()) + if key == 'left' then + self:moveCursor2D(col - 1, line) + end + + if key == 'right' then + self:moveCursor2D(col + 1, line) + end + + if key == 'up' then + self:moveCursor2D(col, line - 1) + end + + if key == 'down' then + self:moveCursor2D(col, line + 1) + end +end + +-- POSITION FUNCTIONS +-- Get a widget by a position. + +function FlowBox:getWidgetAtPoint(x, y) + local col = math.floor(x / self.widgetSize.w) + local line = math.floor(y / self.widgetSize.h) + return self.view:getFromCoord(col, line) +end + +-- DRAW FUNCTIONS +-- Draw the menu and its content + +function FlowBox:draw() + self.view:updateFirstSlot(self.widget:getSelected()) + local widgety = self.y + local widgetx = self.x + + local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) + + for _, widget in ipairs(listWidget) do + widget:drawWidget(widgetx, widgety, self.w, self.widgetSize.h) + + -- On calcule la position du prochain widget + widgetx = widgetx + self.widgetSize.w + if widgetx >= (self.x + self.w) then + widgetx = self.x + widgety = widgety + self.widgetSize.h + end + end +end + +function FlowBox:getGraphicalCursorPosition() + self.view:updateFirstSlot(self.widget:getSelected()) + local _, beginline = self.view:getCoord(self.view.firstSlot) + local w, h = self:getWidgetSize() + local col, line = self.view:getCoord(self.widget:getSelected()) + local x = (col) * h + local y = (line - beginline) * h + return self.x + x, self.y + y, w, h +end + +return FlowBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/grid.lua b/sonic-radiance.love/birb/modules/gui/menus/grid.lua new file mode 100644 index 0000000..8cd62e3 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/grid.lua @@ -0,0 +1,276 @@ +-- 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 View2D = require "birb.modules.gui.menus.views.view2D" + +-- INIT FUNCTIONS +-- Initialize and configure the menu + +function GridBox:new(name, x, y, w, h, colNumber, lineNumber) + self.view = View2D(colNumber, lineNumber) + GridBox.super.new(self, name, x, y, w, h) + self.h = lineNumber * self.widgetSize.h -- On fait en sorte que la hauteur + self.w = colNumber * self.widgetSize.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 + + table.insert(self.slots, slot) +end + +function GridBox:updateWidgetSize() + self.widgetSize.h = math.floor( self.h / self.view.lineNumber ) + self.widgetSize.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.widgetSize.w * self.slots[slot].w, self.widgetSize.h * self.slots[slot].h + end +end + +function GridBox:getSlotHitbox(slot) + local x, y, w, h + x = self.slots[slot].x * self.widgetSize.w + y = self.slots[slot].y * self.widgetSize.h + w = self.slots[slot].w * self.widgetSize.w + h = self.slots[slot].h * self.widgetSize.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 +end + +function GridBox:resetView() + self.view:reset() +end + + +-- KEYS FUNCTIONS +-- Handle the keyboard/manette functions + +function GridBox:keyreleased(key, code) + local slotID = self:getWidgetSlot(self.widget:getSelected()) + 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:getSelected() <= self.widget:lenght() then + self.widget.list[self.widget:getSelected()]:action("key") + end +end + +function GridBox:moveCol(direction) + local orig_x, orig_y = self:getSlotCenter(self.widget:getSelected()) + local distance = self.w -- on met directement à la distance max possible le système + local nearestWidget = 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) + nearestWidget = v.widgetID + end + end + end + + if (nearestWidget ~= 0) then + self.widget:setCursor(nearestWidget) + end +end + +function GridBox:moveLine(direction) + local orig_x, orig_y = self:getSlotCenter(self.widget:getSelected()) + local distance = self.h -- on met directement à la distance max possible le système + local nearestWidget = 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) + nearestWidget = v.widgetID + end + end + end + + if (nearestWidget ~= 0) then + self.widget:setCursor(nearestWidget) + 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:getSelected() = widgetID + -- self:getFocus() + -- end + + -- if self.widget:getSelected() < 1 then + -- self.widget:getSelected() = 1 + -- end + -- if self.widget:getSelected() > self.widget:lenght() then + -- self.widget:getSelected() = self.widget:lenght() + -- end + +end + +function GridBox:mousepressed(x, y, button, isTouch) + local widgetID = self:getWidgetAtPoint(x, y) + + -- if (widgetID ~= nil) then + -- self.widget:getSelected() = widgetID + -- self:getFocus() + + -- if self.widget:lenght() > 0 and self.widget:getSelected() > 1 and self.widget:getSelected() <= self.widget:lenght() then + -- self.widget.list[self.widget:getSelected()]: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.widgetSize.w) + local widgety = self.y + (v.y * self.widgetSize.h) + if self.widget:getSelected() == 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:getSelected() >= 1 and self.widget:getSelected() <= self.widget:lenght()) then + local slot = self:getWidgetSlot(self.widget:getSelected()) + 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(self.x + x, self.y + y, w, h) + end +end + +return GridBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua new file mode 100644 index 0000000..faec6bc --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua @@ -0,0 +1,101 @@ +-- 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 View1D = require(cwd .. "views.view1D") + +-- INIT FUNCTIONS +-- Initialize and configure functions. + +function HListBox:new(name, x, y, w, h, slotNumber) + self.view = View1D(slotNumber) + HListBox.super.new(self, name, x, y, w, h) + self.w = slotNumber * self.widgetSize.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.widgetSize.h = self.h + self.widgetSize.w = math.floor( self.w / self.view.slotNumber ) +end + +function HListBox:update(dt) + self.view:updateFirstSlot(self.widget:getSelected()) +end + +function HListBox:resetView() + self.view:reset() +end + +-- KEYBOARD FUNCTIONS +-- Handle key check. + +function HListBox:moveByKeys(key, code) + if key == 'left' then + self.widget:moveCursor(-1) + end + + if key == 'right' then + self.widget:moveCursor(1) + end +end + +-- POSITION FUNCTIONS +-- Get a widget by a position. + +function HListBox:getWidgetAtPoint(x, y) + return (self.view.firstSlot + math.floor(x / self.widgetSize.w)) +end + +-- DRAW FUNCTIONS +-- Draw the menu and its content + +function HListBox:draw() + self.view:updateFirstSlot(self.widget:getSelected()) + + local widgetx = self.x + + local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) + + for _, widget in ipairs(listWidget) do + widget:drawWidget(widgetx, self.y, self.widgetSize.w, self.h) + widgetx = widgetx + self.widgetSize.w + end +end + +function HListBox:getGraphicalCursorPosition() + self.view:updateFirstSlot(self.widget:getSelected()) + local w, h = self:getWidgetSize() + local x = (self.widget:getSelected() - self.view.firstSlot) * w + + return self.x + x,self.y, w, h +end + +return HListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua new file mode 100644 index 0000000..d99d614 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -0,0 +1,100 @@ +-- 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 View1D = require(cwd .. "views.view1D") + +-- INIT FUNCTIONS +-- Initialize and configure functions. + +function ListBox:new(name, x, y, w, h, slotNumber) + self.view = View1D(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 +end + +-- UPDATE FUNCTIONS +-- Update the menu every step. + +function ListBox:updateWidgetSize() + self.widgetSize.h = math.floor( self.h / self.view.slotNumber ) + self.widgetSize.w = self.w +end + +function ListBox:update(dt) + self.view:updateFirstSlot(self.widget:getSelected()) +end + +function ListBox:resetView() + self.view:reset() +end + +-- KEYBOARD FUNCTIONS +-- Handle input from keyboard/controllers. + +function ListBox:moveByKeys(key) + if key == 'up' then + self.widget:moveCursor(-1) + end + + if key == 'down' then + self.widget:moveCursor(1) + end +end + +-- POSITION FUNCTIONS +-- Get a widget by a position. + +function ListBox:getWidgetAtPoint(x, y) + return (self.view.firstSlot + math.floor(y / self.widgetSize.h)) +end + +-- DRAW FUNCTIONS +-- draw the menu and the rest of content. + +function ListBox:draw() + self.view:updateFirstSlot(self.widget:getSelected()) + local widgety = self.y + + local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) + + for _, widget in ipairs(listWidget) do + widget:drawWidget(self.x, widgety, self.w, self.widgetSize.h) + widgety = widgety + self.widgetSize.h + end +end + +function ListBox:getGraphicalCursorPosition() + self.view:updateFirstSlot(self.widget:getSelected()) + local w, h = self:getWidgetSize() + local y = (self.widget:getSelected() - self.view.firstSlot) * h + + return self.x,self.y + y, w, h +end + +return ListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua new file mode 100644 index 0000000..2aba865 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua @@ -0,0 +1,189 @@ +local MenuModel = Object:extend() +local Page = require "birb.modules.gui.menus.model.page" + +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 basic functions. + +function MenuModel:new() + self:clear() + + self.list = {} + self.selected = 0 + self.selectedPrevious = 0 + self.cancel = 0 + self.limit = -1 + -- self:updateWidgetSize() +end + +function MenuModel:clear() + self.pages = {} + self:addPage("main") +end + +-- PAGE FUNCTIONS +-- Handle pages + +function MenuModel:addPage(pageName) + local page = Page() + self.pages[pageName] = page + self.currentPage = pageName + return page +end + +function MenuModel:addSubmenu(pageName, parent) + local page = self:addPage(pageName) + page:setParent(parent) +end + +function MenuModel:removePage(pageName) + self.pages[pageName] = nil +end + +function MenuModel:pageExists(pageName) + return (self.pages[pageName] ~= nil) +end + +function MenuModel:getPage(pageName) + return self.pages[pageName] +end + +function MenuModel:switch(pageName) + if (self:pageExists(pageName)) then + self.currentPage = pageName + end +end + +function MenuModel:back() + local page = self:getCurrentPage() + self:switch(page:getParent()) +end + +function MenuModel:getCurrentPage() + return self:getPage(self.currentPage) +end + +-- UPDATE/DRAW FUNCTIONS +-- All the update functions + +function MenuModel:update(dt) + local page = self:getCurrentPage() + page:update(dt) +end + +function MenuModel:updateWidgetsOrder() + local page = self:getCurrentPage() + page:updateWidgetByOrder() +end + +function MenuModel:updateWidgetsID() + local page = self:getCurrentPage() + page:updateWidgetsID() +end + +-- ACTION FUNCTIONS +-- All the actions callback used by the widgets + +function MenuModel:cancelAction() + local page = self:getCurrentPage() + page:cancelAction() +end + +function MenuModel:action(id, type) + local page = self:getCurrentPage() + page:action(id, type) +end + +function MenuModel:selectedAction() + local page = self:getCurrentPage() + page:selectedAction() +end + +-- WIDGET FUNCTIONS +-- All the functions to handle widgets + +function MenuModel:addWidget(newWidget) + local page = self:getCurrentPage() + page:addWidget(newWidget) +end + +function MenuModel:getList(first, lenght) + local page = self:getCurrentPage() + return page:getList(first, lenght) +end + +function MenuModel:removeDestroyedWidgets() + local page = self:getCurrentPage() + page:removeDestroyedWidgets() +end + +function MenuModel:lenght() + local page = self:getCurrentPage() + return page:lenght() +end + +function MenuModel:widgetExist(id) + local page = self:getCurrentPage() + return page:widgetExist(id) +end + +function MenuModel:setLimit(limit) + local page = self:getCurrentPage() + page:setLimit(limit) +end + +-- CANCEL FUNCTIONS +-- Add a widget as a "cancel" function + +function MenuModel:setCancelWidget() + local page = self:getCurrentPage() + page:setCancelWidget() +end + +function MenuModel:getCancelWidget() + local page = self:getCurrentPage() + return page:getCancelWidget() +end + +-- CURSOR FUNCTIONS +-- Set or move the cursor of the menu + +function MenuModel:getSelected() + local page = self:getCurrentPage() + return page:getSelected() +end + +function MenuModel:haveCursor() + local page = self:getCurrentPage() + return page:haveCursor() +end + +function MenuModel:trySelectWidget(cursorid) + local page = self:getCurrentPage() + return page:trySelectWidget(cursorid) +end + +function MenuModel:setCursor(cursorid) + local page = self:getCurrentPage() + page:setCursor(cursorid) +end + +function MenuModel:moveCursorAbsolute(newSelected) + local page = self:getCurrentPage() + page:moveCursorAbsolute(newSelected) +end + +function MenuModel:moveCursor(relative) + local page = self:getCurrentPage() + page:moveCursor(relative) +end + + +return MenuModel diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua new file mode 100644 index 0000000..e6a0496 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua @@ -0,0 +1,185 @@ +local Page = 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 basic functions. + +function Page:new() + self.widgets = {} + self.selected = 0 + self.selectedPrevious = 0 + self.cancel = 0 + self.limit = -1 + self.parent = nil + -- self:updateWidgetSize() +end + +function Page:clear() + self.widgets = {} + self.cancel = 0 +end + +function Page:setLimit(limit) + self.limit = limit +end + +-- PAGE FUNCTIONS +-- functions to handle other pages + +function Page:setParent(parent) + self.parent = parent +end + +function Page:getParent() + return self.parent +end + +-- UPDATE/DRAW FUNCTIONS +-- All the update functions + +function Page:update(dt) + self:removeDestroyedWidgets() + for id, widget in ipairs(self.widgets) do + widget.id = id + widget:update(dt) + end +end + +function Page:updateWidgetsOrder() + table.sort(self.widgets, updateWidgetByOrder) +end + +function Page:updateWidgetsID() + for id, widget in ipairs(self.widgets) do + widget.id = id + end +end + +-- ACTION FUNCTIONS +-- All the actions callback used by the widgets + +function Page:cancelAction() + if (self.cancel ~= 0) then + self:action(self.cancel, "key") + end +end + +function Page:action(id, type) + if (self:widgetExist(id)) then + self.widgets[id]:action(type) + end +end + +function Page:selectedAction() + if (self.selected ~= 0) then + self:action(self.selected, "key") + end +end + +-- WIDGET FUNCTIONS +-- All the functions to handle widgets + +function Page:addWidget(newWidget) + if (self.limit ~= -1 and #self.widgets >= self.limit) then + return + end + if #self.widgets == 0 then + self.selected = 1 + end + table.insert(self.widgets, newWidget) + self:updateWidgetsID() + self:updateWidgetsOrder() +end + +function Page:getList(first, lenght) + local listWidget = {} + local first = first or 1 + local lenght = lenght or #self.widgets + lenght = math.min(lenght, (#self.widgets + 1 - first)) + local last = (first + lenght - 1) + + for i = first, (last) do + table.insert(listWidget, self.widgets[i]) + end + + return listWidget +end + +function Page:removeDestroyedWidgets() -- On retire les widgets marquées comme supprimées + for i, v in ipairs(self.widgets) do + if (v.destroyed == true) then + table.remove(self.widgets, i) + end + end +end + +function Page:lenght() + return #self.widgets +end + +function Page:widgetExist(id) + local id = id or 0 + return (id >= 1 and id <= #self.widgets) +end + +-- CANCEL FUNCTIONS +-- Add a widget as a "cancel" function + +function Page:setCancelWidget(id) + self.cancel = #self.widgets +end + +function Page:getCancelWidget(id) + return self.cancel +end + +-- CURSOR FUNCTIONS +-- Set or move the cursor of the menu + +function Page:getSelected() + return self.selected +end + +function Page:haveCursor() + return self:widgetExist(self.selected) +end + +function Page:trySelectWidget(cursorid) + if (self:widgetExist(cursorid)) then + self:setCursor(cursorid) + return true + else + return false + end +end + +function Page:setCursor(cursorid) + self.selected = cursorid --math.max(1, math.min(cursorid, #self.widgets)) +end + +function Page:moveCursorAbsolute(newSelected) + -- self:playNavigationSound() + if newSelected < 1 then + self.selected = #self.widgets + newSelected + else + if newSelected > #self.widgets then + self.selected = newSelected - #self.widgets + else + self.selected = newSelected + end + end +end + +function Page:moveCursor(relative) + self:moveCursorAbsolute(self.selected + relative) +end + + +return Page diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua new file mode 100644 index 0000000..80f0893 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -0,0 +1,243 @@ +-- 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 GuiElement = require "birb.modules.gui.elements.parent" + +local Menu = GuiElement:extend() +local MenuModel = require "birb.modules.gui.menus.model" + +local menuUtils = require "birb.modules.gui.utils" + +-- INIT FUNCTIONS +-- Initialize and configure functions. + +function Menu:new(name, x, y, w, h) + Menu.super.new(self, name, x, y, w, h) + self.menusystem = self:getGui() + + self.widget = MenuModel() + self.widgetSize = {} + self:updateWidgetSize() + + self:resetSound() +end + +-- INTERACTION FUNCTIONS +-- Keyboard and mouse + +function Menu:keypressed(key) + self:moveByKeys(key) + self:actionAndCancel(key) +end + +function Menu:mousemoved(x, y) + local widgetID = self:getWidgetAtPoint(x, y) + + if (widgetID ~= nil) then + if self.widget:trySelectWidget(widgetID) then + self:getFocus() + end + end +end + +function Menu:mousepressed(x, y, button, istouch) + local widgetID = self:getWidgetAtPoint(x, y) + + if (widgetID ~= nil) then + if self.widget:trySelectWidget(widgetID) then + self:getFocus() + self.widget:action(widgetID, "pointer") + end + end +end + +function Menu:moveByKeys(key) + -- Cette fonction ne contient rien par défaut +end + +function Menu:actionAndCancel(key) + if key == "A" then + self.widget:selectedAction() + end + + if key == "B" then + self:cancelAction() + end +end + +-- PAGE FUNCTIONS +-- Wrapper around pages functions from the model + +function Menu:addPage(pageName) + self.widget:addPage(pageName) +end + +function Menu:addSubmenu(pageName, parent) + self.widget:addSubmenu(pageName, parent) +end + +function Menu:removePage(pageName) + self.widget:removePage(pageName) +end + +function Menu:pageExists(pageName) + return self.widget:pageExists(pageName) +end + +function Menu:getPage(pageName) + self.widget:getPage(pageName) +end + +function Menu:switch(pageName) + self.widget:switch(pageName) + self:resetView() +end + +function Menu:back() + self.widget:back() + self:resetView() +end + +-- ACTION FUNCTIONS +-- Send actions to the widgets + +function Menu:cancelAction() + self.widget:cancelAction() +end + +function Menu:clear() + self.widget:clear() +end + +function Menu:resize(x,y,w,h) + self:set(x,y,w,h) + + self:updateWidgetSize() +end + +-- UPDATE FUNCTIONS + +function Menu:updateElement(dt) + self:update(dt) + self.widget:update(dt) +end + +-- DRAW FUNCTIONS +-- Draw the menu and its content + +function Menu:drawElement() + self:draw() + if (self:haveFocus()) then + local x, y, w, h = self:getGraphicalCursorPosition() + self:drawGraphicalCursor(x, y, w, h) + end +end + +function Menu:drawGraphicalCursor(x, y, w, h) + menuUtils.drawCursor(x, y, w, h) +end + +function Menu:drawCanvas() + +end + +-- WIDGET FUNCTIONS +-- Handle widgets of the functions + +function Menu:addWidget(newwidget) + self.widget:addWidget(newwidget) +end + +function Menu:setCancelWidget(id) + self.widget:setCancelWidget(id) +end + +function Menu:updateWidgetSize() + self.widgetSize.h = 0 + self.widgetSize.w = 0 +end + +function Menu:getWidgetSize(id) + return self.widgetSize.w, self.widgetSize.h +end + +function Menu:getWidgetNumber() + return self.widget:lenght() +end + +function Menu:getWidgetAtPoint(x, y) + +end + +-- CURSOR FUNCTIONS +-- Set or move the cursor of the menu + +function Menu:setCursor(cursorid) + self.widget:setCursor(cursorid) +end + +function Menu:moveCursor(new_selected) + self:playNavigationSound() + self.widget:moveCursorAbsolute(new_selected) +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:getWithType(name, "sfx")) +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 diff --git a/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua b/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua new file mode 100644 index 0000000..563c602 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua @@ -0,0 +1,49 @@ +-- view1D.lua : A basic 1D view for menus. +-- Must be used as a subobject of a Menu + +--[[ + 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 View1D = Object:extend() + +function View1D:new(slotNumber) + self.slotNumber = slotNumber + self.firstSlot = 1 +end + +function View1D:reset() + self.firstSlot = 1 + print("reset") +end + +function View1D:updateFirstSlot(widgetID) + self.firstSlot = math.max(1, widgetID - (self.slotNumber - 1), math.min(widgetID, self.firstSlot)) +end + +function View1D:isBeforeView(x) + return (x < self.firstSlot) +end + +function View1D:isAfterView(x) + return (x >= (self.firstSlot + self.slotNumber)) +end + +return View1D \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/menus/views/view2D.lua b/sonic-radiance.love/birb/modules/gui/menus/views/view2D.lua new file mode 100644 index 0000000..feecf25 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/views/view2D.lua @@ -0,0 +1,61 @@ +-- view2D.lua : A basic 2D view for menus. +-- Must be used as a subobject of a Menu + +--[[ + 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 View1D = require "birb.modules.gui.menus.views.view1D" +local View2D = View1D:extend() + +function View2D:new(colNumber, lineNumber) + self.colNumber = colNumber + self.lineNumber = lineNumber + View2D.super.new(self, (colNumber * lineNumber)) +end + +function View2D:updateFirstSlot(widgetID) + local _, line = self:getCoord(widgetID) + local _, beginline = self:getCoord(self.firstSlot) + + beginline = math.min(line, math.max(0, beginline, line - (self.lineNumber - 1))) + self.view.firstSlot = (beginline * self.view.colNumber) + 1 +end + +-- INFO FUNCTIONS +-- Get informations + +function View2D:getCoord(x) + -- On simplifie les calcul en prenant 0 comme départ + local x = x - 1 + + local line, col + line = math.floor(x / self.view.colNumber) + col = x - (line * self.view.colNumber) + + return col, line +end + +function View2D:getFromCoord(col, line) + local _, beginline = self.view:getCoord(self.view.firstSlot) + local line = beginline + line + return (line * self.view.colNumber) + col + 1 +end + +return View2D diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua new file mode 100644 index 0000000..6a72cae --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua @@ -0,0 +1,156 @@ +-- widgets/base.lua :: 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 BaseWidget = Object:extend() + +-- INIT FUNCTIONS +-- Initialize and configure the widget + +function BaseWidget:new(menuName) + self.scene = self:getScene() + self.menu = self:getMenuByName(menuName) + self.assets = self:getAssets() + + self.destroyed = false + self.selectable = false + self.selection_margin = 0 + self.margin = 2 + + self.canvas = {} + self.canvas.texture = nil + self.canvas.needRedraw = true + + self.order = 0 + self:register() +end + +function BaseWidget:getMenuByName(name) + local gui = self:getGui() + assert(name ~= nil, "Name cant be nil") + return gui.elements[name] +end + +function BaseWidget:getScene() + return core.scenemanager.nextScene or core.scenemanager.currentScene +end + +function BaseWidget:getGui() + local scene = core.scenemanager.nextScene or core.scenemanager.currentScene + return scene.gui +end + +function BaseWidget:getAssets() + local scene = core.scenemanager.nextScene or core.scenemanager.currentScene + return scene.assets +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, self.height) + 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 + +-- DRAW WIDGETS +-- Draw the widget + +function BaseWidget:drawWidget(x, y, w, h) + if (self:haveFocus()) then + self:drawSelected(x, y, w, h) + else + self:draw(x, y, w, h) + end +end + +function BaseWidget:draw(x, y, w, h) + if self.canvas.texture ~= nil then + love.graphics.draw(self.canvas.texture, x, y) + 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 + +-- FOCUS FUNCTIONS +-- Detect if the widget have focus + +function BaseWidget:haveFocus() + return (self.menu:haveFocus() and self.menu.widget:getSelected() == self.id) +end + +-- ACTION FUNCTION +-- Functions to handle actions and selection. + +function BaseWidget:action(source) + --self:destroy() +end + +function BaseWidget:destroy() + self.destroyed = true +end + +return BaseWidget diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/init.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/init.lua new file mode 100644 index 0000000..0c8c4e8 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/init.lua @@ -0,0 +1,30 @@ +-- 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 = {} + +-- Add the widget as subvariable to the returned table +Widget.Base = require "birb.modules.gui.menus.widgets.base" +Widget.Text = require "birb.modules.gui.menus.widgets.text" + +return Widget diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua new file mode 100644 index 0000000..f8f9465 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua @@ -0,0 +1,95 @@ +-- widgets/text.lua :: basic text 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 BaseWidget = require "birb.modules.gui.menus.widgets.base" +local TextWidget = BaseWidget:extend() + +-- TEXT WIDGET +-- Simple text widget + +function TextWidget:new(menuName, font, label, position, padding) + TextWidget.super.new(self, menuName) + self.font = font + self.labels = {} + self.padding = padding or 0 + + -- We add the first label + local position = position or "center" + self:addLabel(label, position) + self:setSelectedColor(1, 1, 1) +end + +function TextWidget:addLabel(label, position) + local complexLabel = {} + complexLabel.label = label + complexLabel.position = position + table.insert(self.labels, complexLabel) +end + +function TextWidget:replaceLabel(id, newLabel) + self.labels[id].label = newLabel +end + +function TextWidget:setSelectedColor(r, g, b) + self.selectedColor = {} + self.selectedColor.r = r + self.selectedColor.g = g + self.selectedColor.b = b +end + +function TextWidget:getFont() + return self.assets:getFont(self.font) +end + +function TextWidget:getSelectedColor() + return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b +end + +function TextWidget:getPadding() + return self.padding +end + +function TextWidget:drawCanvas() + local w, h + local font = self:getFont() + h = math.floor(self.height / 2) - (font:getHeight() / 2) + + for _, complexLabel in pairs(self.labels) do + if (complexLabel.position == "center") then + w = math.floor(self.width / 2) + elseif (complexLabel.position == "left") then + w = self:getPadding() + elseif (complexLabel.position == "right") then + w = math.floor(self.width - self:getPadding()) + end + font:draw(complexLabel.label, w, h, -1, complexLabel.position) + end +end + +function TextWidget:drawSelected(x, y, w, h) + local r, g, b = self:getSelectedColor() + love.graphics.setColor(r, g, b, 1) + self:draw(x, y) + utils.graphics.resetColor() +end + +return TextWidget diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index e2dfb10..8afa4c9 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -16,6 +16,12 @@ function ElementList:deleteElement(name) self.elements[name] = nil end +function ElementList:setFocus(name) + assert(self:elementExists(name), "Element " .. name .. " doesn't exists") + self.focusedElement = name + self.elements[name].isVisible = true +end + function ElementList:elementExists(name) return (self:getElement(name) ~= nil) end diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua new file mode 100644 index 0000000..e36f8cf --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua @@ -0,0 +1,78 @@ +-- listbox : a text-based menu. +-- It allow to easily handle a listbox with text-widget and automatically add a widget +-- for submenu. +-- It also make the menu manage the font and the selection color, for a simpler handling + +--[[ + Copyright © 2020 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 ListBox = require "birb.modules.gui.menus.listbox" +local TextMenu = ListBox:extend() + +TextMenu.baseWidgets = require "birb.modules.gui.textmenu.widgets" + +local BASE_PADDING = 8 + +function TextMenu:new(name, font, x, y, w, slotNumber, padding) + self:setFont(font) + self.name = name + local h = self.font:getHeight() * slotNumber + self.padding = padding or BASE_PADDING + self:setSelectedColor(1,1,1) + TextMenu.super.new(self, name, x, y, w, h, slotNumber) +end + +function TextMenu:setFont(fontName) + local scene = core.scenemanager.currentScene + self.font = scene.assets:getFont(fontName) +end + +function TextMenu:getFont() + return self.font +end + +function TextMenu:setSelectedColor(r, g, b) + self.selectedColor = {} + self.selectedColor.r = r + self.selectedColor.g = g + self.selectedColor.b = b +end + +function TextMenu:getSelectedColor() + return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b +end + +function TextMenu:getPadding() + return self.padding +end + +function TextMenu:addSubmenu(pageName, label, parent, backWidget) + local label = label or pageName + local parent = parent or "main" + self:switch(parent) + TextMenu.baseWidgets.SubMenu(self.name, pageName, label) + TextMenu.super.addSubmenu(self, pageName, parent) + if (backWidget ~= false) then + TextMenu.baseWidgets.Back(self.name) + end +end + +return TextMenu \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/back.lua b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/back.lua new file mode 100644 index 0000000..ad053dd --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/back.lua @@ -0,0 +1,37 @@ +-- backwidget : the base widget to go to parent submenu + +--[[ + Copyright © 2020 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 TextMenuWidget = require "birb.modules.gui.textmenu.widgets.basic" + +local BackWidget = TextMenuWidget:extend() + +function BackWidget:new(menuName) + BackWidget.super.new(self, menuName, "Back", "left") + self.order = 1000 +end + +function BackWidget:action() + self.menu:back() +end + +return BackWidget \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua new file mode 100644 index 0000000..9544270 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua @@ -0,0 +1,47 @@ +-- widget : the base widget for a textmenu +-- It replace the functions to get the font and the selectionColor by wrapper to +-- TextMenu. + +--[[ + Copyright © 2020 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 TextWidget = require "birb.modules.gui.menus.widgets.text" + +local TextMenuWidget = TextWidget:extend() + +function TextMenuWidget:new(menuName, label, position) + local position = position or "left" + TextMenuWidget.super.new(self, menuName, "", label, position, 0) +end + +function TextMenuWidget:getFont() + return self.menu:getFont() +end + +function TextMenuWidget:getSelectedColor() + return self.menu:getSelectedColor() +end + +function TextMenuWidget:getPadding() + return self.menu:getPadding() +end + +return TextMenuWidget \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/init.lua b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/init.lua new file mode 100644 index 0000000..5c5e761 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/init.lua @@ -0,0 +1,31 @@ +-- 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 = {} + +-- Add the widget as subvariable to the returned table +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 diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/submenu.lua b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/submenu.lua new file mode 100644 index 0000000..a38d390 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/submenu.lua @@ -0,0 +1,39 @@ +-- widget : the base widget to go to a submenu +-- Make go to a submenu + +--[[ + Copyright © 2020 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 TextMenuWidget = require "birb.modules.gui.textmenu.widgets.basic" + +local SubmenuWidget = TextMenuWidget:extend() + +function SubmenuWidget:new(menuName, submenu, label, position) + self.submenu = submenu + SubmenuWidget.super.new(self, menuName, label, position) + self:addLabel(">", "right") +end + +function SubmenuWidget:action() + self.menu:switch(self.submenu) +end + +return SubmenuWidget \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/utils.lua b/sonic-radiance.love/birb/modules/gui/utils.lua new file mode 100644 index 0000000..a8c73e6 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/utils.lua @@ -0,0 +1,57 @@ +-- menusystem/utils :: basic utility functions for the gui + +--[[ + 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 guiUtils = {} + +function guiUtils.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 guiUtils -- 2.30.2 From afad9f7d08614ece0a6460bc194c5cf487c9ad2a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 11:16:11 +0200 Subject: [PATCH 016/102] feat(textmenu): add line sizing --- .../birb/modules/gui/menus/widgets/base.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua index 6a72cae..e6b594e 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua @@ -41,6 +41,11 @@ function BaseWidget:new(menuName) self.order = 0 self:register() + self.func = nil +end + +function BaseWidget:setFunc(func) + self.func = func end function BaseWidget:getMenuByName(name) @@ -101,7 +106,9 @@ function BaseWidget:drawCanvas() end function BaseWidget:selectAction() - -- Do nothing + if (self.func ~= nil) then + self.func(self) + end end -- DRAW WIDGETS -- 2.30.2 From 44781ba3254178754dbb3c5482cf80ff3746d6c2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 11:24:09 +0200 Subject: [PATCH 017/102] feat: add line sizing --- sonic-radiance.love/birb/modules/gui/textmenu/init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua index e36f8cf..5b3b607 100644 --- a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua +++ b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua @@ -31,13 +31,15 @@ TextMenu.baseWidgets = require "birb.modules.gui.textmenu.widgets" local BASE_PADDING = 8 -function TextMenu:new(name, font, x, y, w, slotNumber, padding) +function TextMenu:new(name, font, x, y, w, slotNumber, padding, lineSize) + lineSize = lineSize or 1 self:setFont(font) + self.lineHeight = self.font:getHeight() * lineSize self.name = name - local h = self.font:getHeight() * slotNumber + self.padding = padding or BASE_PADDING self:setSelectedColor(1,1,1) - TextMenu.super.new(self, name, x, y, w, h, slotNumber) + TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber) end function TextMenu:setFont(fontName) -- 2.30.2 From 0ce811fa977e1dae5a5e67c8d63405f8b702b0ba Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 14:30:26 +0200 Subject: [PATCH 018/102] chore(textwidget): fail if position is wrong --- sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua index f8f9465..511bb0f 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua @@ -80,6 +80,8 @@ function TextWidget:drawCanvas() w = self:getPadding() elseif (complexLabel.position == "right") then w = math.floor(self.width - self:getPadding()) + else + error("Position " .. complexLabel.position .. " is unknown for label " .. complexLabel.label) end font:draw(complexLabel.label, w, h, -1, complexLabel.position) end -- 2.30.2 From 02edc4fc079c69bca4c9a6385fcaf55b1b7d375c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 15:48:09 +0200 Subject: [PATCH 019/102] feat(rect): add getDimensions --- sonic-radiance.love/birb/classes/2D/rect.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic-radiance.love/birb/classes/2D/rect.lua b/sonic-radiance.love/birb/classes/2D/rect.lua index 81f2849..75e46f0 100644 --- a/sonic-radiance.love/birb/classes/2D/rect.lua +++ b/sonic-radiance.love/birb/classes/2D/rect.lua @@ -67,6 +67,10 @@ function Rect:getRelativeCoordinate(dx, dy) return dx - self.x, dy - self.y end +function Rect:getDimensions() + return self.w, self.h +end + function Rect:drawBox() utils.graphics.box(self.x, self.y, self.w, self.h) end -- 2.30.2 From fa8f59cf2c37ab8f0a733ba8beb4dcb986036c8a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 15:48:27 +0200 Subject: [PATCH 020/102] feat: use indirect rendering for menus --- .../birb/modules/gui/elements/canvas.lua | 65 +++++++++++++++++++ .../birb/modules/gui/menus/flowbox.lua | 6 +- .../birb/modules/gui/menus/grid.lua | 6 +- .../birb/modules/gui/menus/hlistbox.lua | 6 +- .../birb/modules/gui/menus/listbox.lua | 7 +- .../birb/modules/gui/menus/parent.lua | 10 ++- 6 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 sonic-radiance.love/birb/modules/gui/elements/canvas.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua new file mode 100644 index 0000000..a1f654e --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -0,0 +1,65 @@ +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, depth) + self:initCanvas() + CanvasElement.super.new(self, name, x, y, w, h) + self.r = r or 0 + self.sx, self.sy = sx or 1, sy or 1 + self.ox, self.oy = self:parseOrigin(ox, w), self:parseOrigin(oy, h) + self.opacity = opacity or 1 + self.depth = depth or 0 +end + +function CanvasElement:initCanvas() + self.canvas = {} + self.canvas.needRedraw = true + self.canvas.texture = nil + self.canvas.isAnimated = false + self.canvas.padding = 8 +end + +function CanvasElement:getCanvasDimensions() + return self:getDimensions() +end + +function CanvasElement:redraw() + local w, h = self:getDimensions() + + local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2)) + love.graphics.setCanvas(canvas) + + self:drawTexture() + self.canvas.needRedraw = false + love.graphics.setCanvas() + if (self.canvas.isAnimated) then + self.canvas.texture = canvas + else + local imageData = canvas:newImageData() + self.canvas.texture = love.graphics.newImage(imageData) + canvas:release() + imageData:release() + end +end + +function CanvasElement:drawTexture() + +end + +function CanvasElement:parseOrigin(origin, size) + if (origin == "center") then + return size/2 + elseif (origin == "end") then + return size - self.canvas.padding + else + return origin or self.canvas.padding + end +end + +function CanvasElement:draw() + love.graphics.setColor(1, 1, 1, self.opacity) + love.graphics.draw(self.canvas.texture, self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy) + love.graphics.setColor(1, 1, 1, 1) +end + +return CanvasElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua index f0a40fb..52a8870 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua @@ -112,10 +112,10 @@ end -- DRAW FUNCTIONS -- Draw the menu and its content -function FlowBox:draw() +function FlowBox:drawTexture() self.view:updateFirstSlot(self.widget:getSelected()) - local widgety = self.y - local widgetx = self.x + local widgety = self.canvas.padding + local widgetx = self.canvas.padding local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) diff --git a/sonic-radiance.love/birb/modules/gui/menus/grid.lua b/sonic-radiance.love/birb/modules/gui/menus/grid.lua index 8cd62e3..1bd0bf1 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/grid.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/grid.lua @@ -247,12 +247,12 @@ end -- DRAW FUNCTIONS -- Draw the menu and its content -function GridBox:draw() +function GridBox:drawTexture() for i,v in ipairs(self.slots) do if self:haveWidget(i) then - local widgetx = self.x + (v.x * self.widgetSize.w) - local widgety = self.y + (v.y * self.widgetSize.h) + local widgetx = self.canvas.padding + (v.x * self.widgetSize.w) + local widgety = self.canvas.padding + (v.y * self.widgetSize.h) if self.widget:getSelected() == v.widgetID and self:haveFocus() == true then self.widget.list[v.widgetID]:drawSelected(widgetx, widgety) else diff --git a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua index faec6bc..c10d772 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua @@ -77,15 +77,15 @@ end -- DRAW FUNCTIONS -- Draw the menu and its content -function HListBox:draw() +function HListBox:drawTexture() self.view:updateFirstSlot(self.widget:getSelected()) - local widgetx = self.x + local widgetx = self.canvas.padding local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) for _, widget in ipairs(listWidget) do - widget:drawWidget(widgetx, self.y, self.widgetSize.w, self.h) + widget:drawWidget(widgetx, self.canvas.padding, self.widgetSize.w, self.h) widgetx = widgetx + self.widgetSize.w end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index d99d614..2a6f30c 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -77,14 +77,15 @@ end -- DRAW FUNCTIONS -- draw the menu and the rest of content. -function ListBox:draw() +function ListBox:drawTexture() self.view:updateFirstSlot(self.widget:getSelected()) - local widgety = self.y + local widgety = self.canvas.padding local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) for _, widget in ipairs(listWidget) do - widget:drawWidget(self.x, widgety, self.w, self.widgetSize.h) + print(self.canvas.padding, widgety) + widget:drawWidget(self.canvas.padding, widgety, self.w, self.widgetSize.h) widgety = widgety + self.widgetSize.h end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index 80f0893..dba9084 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -21,7 +21,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -local GuiElement = require "birb.modules.gui.elements.parent" +local GuiElement = require "birb.modules.gui.elements.canvas" local Menu = GuiElement:extend() local MenuModel = require "birb.modules.gui.menus.model" @@ -40,6 +40,7 @@ function Menu:new(name, x, y, w, h) self:updateWidgetSize() self:resetSound() + self:initCanvas() end -- INTERACTION FUNCTIONS @@ -78,10 +79,12 @@ end function Menu:actionAndCancel(key) if key == "A" then self.widget:selectedAction() + self.canvas.needRedraw = true end if key == "B" then self:cancelAction() + self.canvas.needRedraw = true end end @@ -140,6 +143,9 @@ end function Menu:updateElement(dt) self:update(dt) self.widget:update(dt) + if (self.canvas.needRedraw or self.canvas.isAnimated) then + self:redraw() + end end -- DRAW FUNCTIONS @@ -194,11 +200,13 @@ end function Menu:setCursor(cursorid) self.widget:setCursor(cursorid) + self.canvas.needRedraw = true end function Menu:moveCursor(new_selected) self:playNavigationSound() self.widget:moveCursorAbsolute(new_selected) + self.canvas.needRedraw = true end -- SOUND FUNCTION -- 2.30.2 From cf6cd3c7a3232599cf6027a6973cb1d427052bd5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 18:07:29 +0200 Subject: [PATCH 021/102] fix: utilisation du padding comme il faut --- sonic-radiance.love/birb/modules/gui/elements/canvas.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua index a1f654e..616efc0 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -50,15 +50,15 @@ function CanvasElement:parseOrigin(origin, size) if (origin == "center") then return size/2 elseif (origin == "end") then - return size - self.canvas.padding + return size else - return origin or self.canvas.padding + return origin or 0 end end function CanvasElement:draw() love.graphics.setColor(1, 1, 1, self.opacity) - love.graphics.draw(self.canvas.texture, self.x,self.y,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 -- 2.30.2 From ae13c1d5ae4444142894961473c9b3d87438fa28 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 18:08:02 +0200 Subject: [PATCH 022/102] feat: ajout support du son au menu GUI --- sonic-radiance.love/birb/modules/gui/init.lua | 18 ++++++++++++ .../birb/modules/gui/menus/flowbox.lua | 4 +++ .../birb/modules/gui/menus/grid.lua | 4 +++ .../birb/modules/gui/menus/hlistbox.lua | 2 ++ .../birb/modules/gui/menus/listbox.lua | 5 ++-- .../birb/modules/gui/menus/model/page.lua | 1 + .../birb/modules/gui/menus/parent.lua | 28 +++++-------------- .../birb/modules/gui/menus/widgets/base.lua | 13 ++++++--- 8 files changed, 48 insertions(+), 27 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 01c2f0f..7f6fbe5 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -33,6 +33,7 @@ local TransformDataStruct = require "birb.structures.tween" function Gui:new(scene) self.scene = scene self:reset() + self.sfx = {} end function Gui:reset() @@ -125,6 +126,23 @@ function Gui:showScreen(screenname) self.screens[screenname]:show() end +-- SOUND FUNCTIONS +-- Handle SFX + +function Gui:addSFX(guiName, sfxName) + self.sfx[guiName] = sfxName +end + +function Gui:playSFX(type) + local sfxName = self.sfx[type] + if (sfxName ~= nil) then + local sfx = self.scene.assets.sfx[sfxName] + if (sfx ~= nil) then + sfx:play() + end + end +end + -- KEYBOARD FUNCTIONS -- Handle keyboard diff --git a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua index 52a8870..328bb7a 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua @@ -85,18 +85,22 @@ function FlowBox:moveByKeys(key) local col, line = self.view:getCoord(self.widget:getSelected()) if key == 'left' then self:moveCursor2D(col - 1, line) + self:playNavigationSound() end if key == 'right' then self:moveCursor2D(col + 1, line) + self:playNavigationSound() end if key == 'up' then self:moveCursor2D(col, line - 1) + self:playNavigationSound() end if key == 'down' then self:moveCursor2D(col, line + 1) + self:playNavigationSound() end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/grid.lua b/sonic-radiance.love/birb/modules/gui/menus/grid.lua index 1bd0bf1..3c98a1c 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/grid.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/grid.lua @@ -150,18 +150,22 @@ function GridBox:keyreleased(key, code) local col, line = self.cursor.x, self.cursor.y if key == 'left' then self:moveCol(-1) + self:playNavigationSound() end if key == 'right' then self:moveCol(1) + self:playNavigationSound() end if key == 'up' then self:moveLine(-1) + self:playNavigationSound() end if key == 'down' then self:moveLine(1) + self:playNavigationSound() end if key == "A" and self.widget:getSelected() <= self.widget:lenght() then diff --git a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua index c10d772..7c51643 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua @@ -60,10 +60,12 @@ end function HListBox:moveByKeys(key, code) if key == 'left' then self.widget:moveCursor(-1) + self:playNavigationSound() end if key == 'right' then self.widget:moveCursor(1) + self:playNavigationSound() end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index 2a6f30c..05a3095 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -60,10 +60,12 @@ end function ListBox:moveByKeys(key) if key == 'up' then self.widget:moveCursor(-1) + self:playNavigationSound() end if key == 'down' then self.widget:moveCursor(1) + self:playNavigationSound() end end @@ -84,7 +86,6 @@ function ListBox:drawTexture() local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) for _, widget in ipairs(listWidget) do - print(self.canvas.padding, widgety) widget:drawWidget(self.canvas.padding, widgety, self.w, self.widgetSize.h) widgety = widgety + self.widgetSize.h end @@ -95,7 +96,7 @@ function ListBox:getGraphicalCursorPosition() local w, h = self:getWidgetSize() local y = (self.widget:getSelected() - self.view.firstSlot) * h - return self.x,self.y + y, w, h + return self.x - self.ox,self.y + y - self.oy, w, h end return ListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua index e6a0496..e2c13e0 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua @@ -74,6 +74,7 @@ end function Page:action(id, type) if (self:widgetExist(id)) then self.widgets[id]:action(type) + self.widgets[id]:playSFX() end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index dba9084..c3dce9e 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -39,7 +39,6 @@ function Menu:new(name, x, y, w, h) self.widgetSize = {} self:updateWidgetSize() - self:resetSound() self:initCanvas() end @@ -141,7 +140,7 @@ end -- UPDATE FUNCTIONS function Menu:updateElement(dt) - self:update(dt) + Menu.super.updateElement(self, dt) self.widget:update(dt) if (self.canvas.needRedraw or self.canvas.isAnimated) then self:redraw() @@ -204,7 +203,6 @@ function Menu:setCursor(cursorid) end function Menu:moveCursor(new_selected) - self:playNavigationSound() self.widget:moveCursorAbsolute(new_selected) self.canvas.needRedraw = true end @@ -212,25 +210,13 @@ 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:getWithType(name, "sfx")) -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 + self:playSFX("navigate") +end + +function Menu:playSFX(name) + local gui = self:getGui() + gui:playSFX(name) end -- VIEW FUNCTIONS diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua index e6b594e..e295bb8 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua @@ -42,6 +42,7 @@ function BaseWidget:new(menuName) self.order = 0 self:register() self.func = nil + self.type = "select" end function BaseWidget:setFunc(func) @@ -106,9 +107,7 @@ function BaseWidget:drawCanvas() end function BaseWidget:selectAction() - if (self.func ~= nil) then - self.func(self) - end + -- Do nothing end -- DRAW WIDGETS @@ -152,8 +151,14 @@ end -- ACTION FUNCTION -- Functions to handle actions and selection. +function BaseWidget:playSFX() + self.menu:playSFX(self.type) +end + function BaseWidget:action(source) - --self:destroy() + if (self.func ~= nil) then + self.func(self) + end end function BaseWidget:destroy() -- 2.30.2 From 4daa0b16eb69f38c39d9d03d667f4e8bd85e51fa Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 18:58:38 +0200 Subject: [PATCH 023/102] feat: add everything needed for fancymenus --- .../birb/modules/gui/menus/listbox.lua | 19 ++++++++++--------- .../birb/modules/gui/menus/parent.lua | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index 05a3095..93051d8 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -79,24 +79,25 @@ end -- DRAW FUNCTIONS -- draw the menu and the rest of content. +function ListBox:getListPart(relativeNumber) + return 0, (relativeNumber) * self.widgetSize.h, self.w, self.widgetSize.h +end + function ListBox:drawTexture() self.view:updateFirstSlot(self.widget:getSelected()) - local widgety = self.canvas.padding - local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) - for _, widget in ipairs(listWidget) do - widget:drawWidget(self.canvas.padding, widgety, self.w, self.widgetSize.h) - widgety = widgety + self.widgetSize.h + for i, widget in ipairs(listWidget) do + local x, y, w, h = self:getListPart(i - 1) + self:drawWidgetBackground(x + self.canvas.padding, y + self.canvas.padding, w, h) + widget:drawWidget(x + self.canvas.padding, y + self.canvas.padding, w, h) end end function ListBox:getGraphicalCursorPosition() - self.view:updateFirstSlot(self.widget:getSelected()) - local w, h = self:getWidgetSize() - local y = (self.widget:getSelected() - self.view.firstSlot) * h + local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot) - return self.x - self.ox,self.y + y - self.oy, w, h + return self.x - self.ox + x,self.y + y - self.oy, w, h end return ListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index c3dce9e..e726388 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -166,6 +166,10 @@ function Menu:drawCanvas() end +function Menu:drawWidgetBackground(x, y, w, h) + +end + -- WIDGET FUNCTIONS -- Handle widgets of the functions -- 2.30.2 From 9ed2b44be27cf612eddd2a3a2231fdd599e5d1f5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 21:14:48 +0200 Subject: [PATCH 024/102] fix: redraw menu when selecting another widget --- sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua | 2 ++ sonic-radiance.love/birb/modules/gui/menus/listbox.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua index 7c51643..e94809b 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua @@ -60,11 +60,13 @@ end function HListBox:moveByKeys(key, code) if key == 'left' then self.widget:moveCursor(-1) + self.canvas.needRedraw = true self:playNavigationSound() end if key == 'right' then self.widget:moveCursor(1) + self.canvas.needRedraw = true self:playNavigationSound() end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index 93051d8..934d502 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -61,11 +61,13 @@ function ListBox:moveByKeys(key) if key == 'up' then self.widget:moveCursor(-1) self:playNavigationSound() + self.canvas.needRedraw = true end if key == 'down' then self.widget:moveCursor(1) self:playNavigationSound() + self.canvas.needRedraw = true end end -- 2.30.2 From 88a68d2f98bda0b28ebd527b75bb300159d5712e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 21:15:01 +0200 Subject: [PATCH 025/102] fix: propagate cancel widget --- .../birb/modules/gui/menus/model/init.lua | 4 ++-- .../birb/modules/gui/menus/model/page.lua | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua index 2aba865..e6979a1 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua @@ -142,9 +142,9 @@ end -- CANCEL FUNCTIONS -- Add a widget as a "cancel" function -function MenuModel:setCancelWidget() +function MenuModel:setCancelWidget(id) local page = self:getCurrentPage() - page:setCancelWidget() + page:setCancelWidget(id) end function MenuModel:getCancelWidget() diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua index e2c13e0..326b76f 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua @@ -66,8 +66,8 @@ end -- All the actions callback used by the widgets function Page:cancelAction() - if (self.cancel ~= 0) then - self:action(self.cancel, "key") + if (self:getCancelWidget() ~= 0) then + self:action(self:getCancelWidget(), "key") end end @@ -134,11 +134,18 @@ end -- Add a widget as a "cancel" function function Page:setCancelWidget(id) - self.cancel = #self.widgets + if (id == nil) then + id = #self.widgets + end + self.cancel = id end -function Page:getCancelWidget(id) - return self.cancel +function Page:getCancelWidget() + if (self.cancel == "last") then + return #self.widgets + else + return self.cancel + end end -- CURSOR FUNCTIONS -- 2.30.2 From 339d927d516ed213a06ea3e41ec7968d7d410ff1 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 21:15:27 +0200 Subject: [PATCH 026/102] fix(textwidget): better color management --- .../birb/modules/gui/menus/widgets/text.lua | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua index 511bb0f..9ecfb42 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua @@ -35,7 +35,7 @@ function TextWidget:new(menuName, font, label, position, padding) -- We add the first label local position = position or "center" self:addLabel(label, position) - self:setSelectedColor(1, 1, 1) + self:setColor(1, 1, 1) end function TextWidget:addLabel(label, position) @@ -49,6 +49,13 @@ function TextWidget:replaceLabel(id, newLabel) self.labels[id].label = newLabel end +function TextWidget:setColor(r, g, b) + self.color = {} + self.color.r = r + self.color.g = g + self.color.b = b +end + function TextWidget:setSelectedColor(r, g, b) self.selectedColor = {} self.selectedColor.r = r @@ -61,7 +68,15 @@ function TextWidget:getFont() end function TextWidget:getSelectedColor() - return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b + if (self.selectedColor ~= nil) then + return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b + else + return self:getColor() + end +end + +function TextWidget:getColor() + return self.color.r, self.color.g, self.color.b end function TextWidget:getPadding() @@ -87,10 +102,21 @@ function TextWidget:drawCanvas() end end +function TextWidget:draw(x, y, w, h) + local r, g, b = self:getColor() + love.graphics.setColor(r, g, b, 1) + if self.canvas.texture ~= nil then + love.graphics.draw(self.canvas.texture, x, y) + end + utils.graphics.resetColor() +end + function TextWidget:drawSelected(x, y, w, h) local r, g, b = self:getSelectedColor() love.graphics.setColor(r, g, b, 1) - self:draw(x, y) + if self.canvas.texture ~= nil then + love.graphics.draw(self.canvas.texture, x, y) + end utils.graphics.resetColor() end -- 2.30.2 From 6f6b4e6d741d8d9b2afb25afb57112076163da9c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:07:02 +0200 Subject: [PATCH 027/102] chore: make canvas redraw part of canvas --- sonic-radiance.love/birb/modules/gui/elements/canvas.lua | 7 +++++++ sonic-radiance.love/birb/modules/gui/menus/parent.lua | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua index 616efc0..62a6949 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -19,6 +19,13 @@ function CanvasElement:initCanvas() self.canvas.padding = 8 end +function CanvasElement:updateElement(dt) + CanvasElement.super.updateElement(self, dt) + if (self.canvas.needRedraw or self.canvas.isAnimated) then + self:redraw() + end +end + function CanvasElement:getCanvasDimensions() return self:getDimensions() end diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index e726388..bee182a 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -140,11 +140,8 @@ end -- UPDATE FUNCTIONS function Menu:updateElement(dt) - Menu.super.updateElement(self, dt) self.widget:update(dt) - if (self.canvas.needRedraw or self.canvas.isAnimated) then - self:redraw() - end + Menu.super.updateElement(self, dt) end -- DRAW FUNCTIONS -- 2.30.2 From d972fccb13952e3c3c41a7818e5659f0477f6496 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:10:26 +0200 Subject: [PATCH 028/102] feat: add assets access to gui elements --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 5103a04..1de6125 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -13,6 +13,7 @@ function GuiElement:new(name, x, y, w, h) self.depth = 0 self.tweens = TweenManager(self) + self.assets = self:getAssets() self:register() end @@ -22,6 +23,11 @@ function GuiElement:getGui() return scene.gui end +function GuiElement:getAssets() + local scene = core.scenemanager.nextScene or core.scenemanager.currentScene + return scene.assets +end + function GuiElement:register() local gui = self:getGui() self.creationId = gui:addElement(self.name, self) -- 2.30.2 From 08674dbf7ef1d5db2adaad6cfd3b84d455a1b745 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:10:53 +0200 Subject: [PATCH 029/102] fix: draw GUI over scene --- sonic-radiance.love/birb/modules/scenes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/scenes.lua b/sonic-radiance.love/birb/modules/scenes.lua index 552a088..d2c467b 100644 --- a/sonic-radiance.love/birb/modules/scenes.lua +++ b/sonic-radiance.love/birb/modules/scenes.lua @@ -152,8 +152,8 @@ end function Scene:drawScene() self:drawStart() self:drawWorld() - self.gui:drawBottom() self:draw() + self.gui:drawBottom() self:drawMenus() self:drawDialog() self:drawEnd() -- 2.30.2 From 8914dc2d09de9edd4a4dda009be825f37b164a05 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:11:08 +0200 Subject: [PATCH 030/102] feat: new element types --- .../birb/modules/gui/elements/composite.lua | 34 +++++++++++++++++++ .../birb/modules/gui/elements/counter.lua | 13 +++++++ .../birb/modules/gui/elements/linked.lua | 21 ------------ .../birb/modules/gui/elements/variable.lua | 14 ++++++++ 4 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 sonic-radiance.love/birb/modules/gui/elements/composite.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/counter.lua delete mode 100644 sonic-radiance.love/birb/modules/gui/elements/linked.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/variable.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/composite.lua b/sonic-radiance.love/birb/modules/gui/elements/composite.lua new file mode 100644 index 0000000..8c42561 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/composite.lua @@ -0,0 +1,34 @@ +local Parent = require "birb.modules.gui.elements.parent" +local CompositeElement = Parent:extend() + +function CompositeElement:new(name, x, y, childrenList) + self.children = {} + self:addChildren(childrenList) + CompositeElement.super.new(self, name, x, y, 1, 1) + self.isVisible = true +end + +function CompositeElement:addChildren(list) + for _, childData in ipairs(list) do + self:addChild(childData[1], childData[2], childData[3]) + end +end + +function CompositeElement:addChild(children, relx, rely) + local child = {} + child.name = children.name + child.relx = relx + child.rely = rely + table.insert(self.children, child) +end + +function CompositeElement:update(dt) + for _, child in ipairs(self.children) do + local childElement = self.getGui().elements[child.name] + childElement.x = self.x + child.relx + childElement.y = self.y + child.rely + childElement.isVisible = self.isVisible + end +end + +return CompositeElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/counter.lua b/sonic-radiance.love/birb/modules/gui/elements/counter.lua new file mode 100644 index 0000000..fc13296 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/counter.lua @@ -0,0 +1,13 @@ +local Parent = require "birb.modules.gui.elements.variable" +local CounterElement = Parent:extend() + +function CounterElement:new(name, fontName, object, varName, nbrs, x, y, align, depth) + CounterElement.super.new(self, name, fontName, object, varName, x, y, align, depth) + self.nbrs = nbrs or 0 +end + +function CounterElement:getText() + return utils.math.numberToString(CounterElement.super.getText(self), self.nbrs) +end + +return CounterElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/linked.lua b/sonic-radiance.love/birb/modules/gui/elements/linked.lua deleted file mode 100644 index 3e44fea..0000000 --- a/sonic-radiance.love/birb/modules/gui/elements/linked.lua +++ /dev/null @@ -1,21 +0,0 @@ -local Parent = require "birb.modules.gui.elements.parent" -local LinkedElement = Parent:extend() - -function LinkedElement:new(name, x, y, w, h, object, varName) - LinkedElement.super.new(self, name, x, y, w, h) - self.object = object - self.variables = {} - self:addVariable(varName, "main") -end - -function LinkedElement:addVariable(varName, internalName) - internalName = internalName or varName - self.variables[internalName] = varName -end - -function LinkedElement:getVariableContent(varName) - varName = varName or "main" - return self.object[self.variables[varName]] -end - -return LinkedElement \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/variable.lua b/sonic-radiance.love/birb/modules/gui/elements/variable.lua new file mode 100644 index 0000000..7716230 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/variable.lua @@ -0,0 +1,14 @@ +local Parent = require "birb.modules.gui.elements.text" +local VariableElement = Parent:extend() + +function VariableElement:new(name, fontName, object, varName, x, y, align, depth) + VariableElement.super.new(self, name, fontName, "", x, y, align, depth) + self.object = object + self.variable = varName +end + +function VariableElement:getText() + return self.object[self.variable] +end + +return VariableElement \ No newline at end of file -- 2.30.2 From c95ff30d6e6216187b012dc6aa8802fa2fd24444 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:11:27 +0200 Subject: [PATCH 031/102] improvement: better textmenus --- .../birb/modules/gui/textmenu/init.lua | 25 +++++++++++++++++-- .../modules/gui/textmenu/widgets/basic.lua | 7 +++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua index 5b3b607..290b548 100644 --- a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua +++ b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua @@ -38,10 +38,30 @@ function TextMenu:new(name, font, x, y, w, slotNumber, padding, lineSize) self.name = name self.padding = padding or BASE_PADDING - self:setSelectedColor(1,1,1) TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber) end +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" + if (additionnalItems ~= nil) then + for _, item in ipairs(additionnalItems) do + widget:addLabel(item[1], item[2]) + end + end + if (color ~= nil) then + widget:setColor(color[1], color[2], color[3]) + end +end + +function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget) + self:addSubmenu(pageName, label, parent, backWidget) + for _, data in ipairs(list) do + self:addItem(func(data)) + end +end + function TextMenu:setFont(fontName) local scene = core.scenemanager.currentScene self.font = scene.assets:getFont(fontName) @@ -59,7 +79,7 @@ function TextMenu:setSelectedColor(r, g, b) end function TextMenu:getSelectedColor() - return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b + return self.selectedColor end function TextMenu:getPadding() @@ -74,6 +94,7 @@ function TextMenu:addSubmenu(pageName, label, parent, backWidget) TextMenu.super.addSubmenu(self, pageName, parent) if (backWidget ~= false) then TextMenu.baseWidgets.Back(self.name) + self:setCancelWidget("last") end end diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua index 9544270..ae1d8ac 100644 --- a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua +++ b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua @@ -37,7 +37,12 @@ function TextMenuWidget:getFont() end function TextMenuWidget:getSelectedColor() - return self.menu:getSelectedColor() + local selectedColor = self.menu:getSelectedColor() + if (selectedColor ~= nil) then + return selectedColor.r, selectedColor.g, selectedColor.b + else + return self:getColor() + end end function TextMenuWidget:getPadding() -- 2.30.2 From 2065e4ce9c2990731b279a7337b886c884c2143c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:59:06 +0200 Subject: [PATCH 032/102] fix: use right function in element:destroy() --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 1de6125..a3b244b 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -35,9 +35,9 @@ end function GuiElement:destroy() local gui = self:getGui() - gui:removeElement(self.name) - if (self.screen == nil) then - self.screen:removeElement(self.name) + gui:deleteElement(self.name) + if (self.screen ~= nil) then + self.screen:deleteElement(self.name) end end -- 2.30.2 From 73fc3160ddc796f292ec7bed05a239e8fd786263 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 14:59:28 +0200 Subject: [PATCH 033/102] improvement(textmenu): better padding --- .../birb/modules/gui/menus/widgets/text.lua | 12 ++++++++++-- .../birb/modules/gui/textmenu/init.lua | 9 +++++++++ .../birb/modules/gui/textmenu/widgets/basic.lua | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua index 9ecfb42..5d784dd 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua @@ -83,6 +83,14 @@ function TextWidget:getPadding() return self.padding end +function TextWidget:getPaddingLeft() + return self.paddingLeft or self:getPadding() +end + +function TextWidget:getPaddingRight() + return self.paddingRight or self:getPadding() +end + function TextWidget:drawCanvas() local w, h local font = self:getFont() @@ -92,9 +100,9 @@ function TextWidget:drawCanvas() if (complexLabel.position == "center") then w = math.floor(self.width / 2) elseif (complexLabel.position == "left") then - w = self:getPadding() + w = self:getPaddingLeft() elseif (complexLabel.position == "right") then - w = math.floor(self.width - self:getPadding()) + w = math.floor(self.width - self:getPaddingRight()) else error("Position " .. complexLabel.position .. " is unknown for label " .. complexLabel.label) end diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua index 290b548..6370ea0 100644 --- a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua +++ b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua @@ -86,6 +86,15 @@ function TextMenu:getPadding() return self.padding end +function TextMenu:getPaddingLeft() + return self.paddingLeft or self:getPadding() +end + +function TextMenu:getPaddingRight() + return self.paddingRight or self:getPadding() +end + + function TextMenu:addSubmenu(pageName, label, parent, backWidget) local label = label or pageName local parent = parent or "main" diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua index ae1d8ac..a69470e 100644 --- a/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua +++ b/sonic-radiance.love/birb/modules/gui/textmenu/widgets/basic.lua @@ -49,4 +49,12 @@ function TextMenuWidget:getPadding() return self.menu:getPadding() end +function TextWidget:getPaddingLeft() + return self.menu:getPaddingLeft() or self:getPadding() +end + +function TextWidget:getPaddingRight() + return self.menu:getPaddingRight() or self:getPadding() +end + return TextMenuWidget \ No newline at end of file -- 2.30.2 From 700eebd3954d9a04469c0cb7e9ae7b9151869c25 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 30 Aug 2021 23:52:45 +0200 Subject: [PATCH 034/102] feat(game): add gui sfx to radiance's scene --- sonic-radiance.love/game/scenes/init.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua index 10bf7d6..050a2f9 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -10,6 +10,10 @@ function RadianceScene:new(haveBorder, showVersion) self.assets:batchImport("assets.commons") self.assets.fonts["small"]:setLineHeight(16/18) self.assets.fonts["small"]:setFilter("shadow") + self.gui:addSFX("select", "mSelect") + self.gui:addSFX("navigate", "mBeep") + self.gui:addSFX("back", "mBack") + self.gui:addSFX("error", "mError") Overlay(haveBorder, showVersion) end -- 2.30.2 From 75bd09f18b691b98d0f89ae63d55443b1b8a09e5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:01:24 +0200 Subject: [PATCH 035/102] feat: improve focus handling --- .../birb/modules/gui/elements/parent.lua | 6 +++--- .../birb/modules/gui/mixins/elements.lua | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index a3b244b..1d44c39 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -10,7 +10,7 @@ function GuiElement:new(name, x, y, w, h) self.isVisible = true self.screen = nil - self.depth = 0 + self.depth = 10 self.tweens = TweenManager(self) self.assets = self:getAssets() @@ -62,7 +62,7 @@ end function GuiElement:getFocus() local gui = self:getGui() - gui.focusedElement = self.name + gui:setFocus(self.name) end function GuiElement:haveFocus() @@ -73,7 +73,7 @@ end function GuiElement:looseFocus() if (self:haveFocus()) then local gui = self:getGui() - gui.focusedElement = nil + gui:removeFocus() end end diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index 8afa4c9..3bcffb6 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -3,6 +3,7 @@ local ElementList = Object:extend() function ElementList:initElements() self.elements = {} self.focusedElement = nil + self.lastFocused = nil self.nbrElement = 0 end @@ -18,10 +19,28 @@ end function ElementList:setFocus(name) assert(self:elementExists(name), "Element " .. name .. " doesn't exists") + self:storeLastFocus() self.focusedElement = name self.elements[name].isVisible = true end +function ElementList:removeFocus() + self:storeLastFocus() + self.focusedElement = nil +end + +function ElementList:storeLastFocus() + if (self.focusedElement ~= nil) then + self.lastFocused = self.focusedElement + end +end + +function ElementList:setLastFocus() + if (self:elementExists(self.lastFocused)) then + self:setFocus(self.lastFocused) + end +end + function ElementList:elementExists(name) return (self:getElement(name) ~= nil) end -- 2.30.2 From da9dbb30b8ce0eb11877638b2c26f22321c6370b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:56:11 +0200 Subject: [PATCH 036/102] improvement: better element data parsing --- .../birb/modules/gui/screen.lua | 33 ++++++++++++++----- .../birb/structures/elementData.lua | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 sonic-radiance.love/birb/structures/elementData.lua diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua index 9ecddf6..3a2c08e 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -6,6 +6,9 @@ GuiScreen:implement(ElementList) local TweenManager = require "birb.classes.time" +local elementDataStruct = require "birb.structures.elementData" + + function GuiScreen:new(name, controller) self.controller = controller or self:getGui() self.name = name @@ -69,16 +72,30 @@ end function GuiScreen:registerElements() local elementList = self:createElements() - for _, element in ipairs(elementList) do - if (element.is ~= nil) then - self:addElement(element.name, element) - element.screen = self + for _, rawElement in ipairs(elementList) do + if (rawElement.is ~= nil) then + self:addElement(rawElement.name, rawElement) + rawElement.screen = self else - self:addElement(element[1].name, element[1]) - if (element[2] == false) then - element[1].isVisible = false + local elemData = utils.table.parse(rawElement, elementDataStruct, 3) + local element = elemData.element + self:addElement(element.name, element) + if (elemData.delay > 0) then + element.isVisible = false + element:newSwitch(elemData.delay, {"isVisible"}) + print(elemData.delay) end - element[1].screen = self + if (elemData.depth ~= nil) then + element.depth = elemData.depth + end + print(element, element.name, elemData.depth, elemData.focus) + if (elemData.focus == true) then + element:getFocus() + end + if (elemData.keypress ~= nil) then + element:setKeyPressAction(elemData.keypress) + end + element.screen = self end end end diff --git a/sonic-radiance.love/birb/structures/elementData.lua b/sonic-radiance.love/birb/structures/elementData.lua new file mode 100644 index 0000000..63eff97 --- /dev/null +++ b/sonic-radiance.love/birb/structures/elementData.lua @@ -0,0 +1 @@ +return {"element", "delay", "depth", "focus", "keypress"} \ No newline at end of file -- 2.30.2 From 36b4d16939678277ea1d46d4eee528350dac9fad Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:56:43 +0200 Subject: [PATCH 037/102] improvement: let the screen handle opacity --- sonic-radiance.love/birb/modules/gui/elements/assets.lua | 4 ++-- sonic-radiance.love/birb/modules/gui/elements/canvas.lua | 3 +-- sonic-radiance.love/birb/modules/gui/elements/composite.lua | 1 + sonic-radiance.love/birb/modules/gui/elements/counter.lua | 4 ++-- sonic-radiance.love/birb/modules/gui/elements/drawable.lua | 3 +-- sonic-radiance.love/birb/modules/gui/elements/text.lua | 3 +-- sonic-radiance.love/birb/modules/gui/elements/variable.lua | 4 ++-- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/assets.lua b/sonic-radiance.love/birb/modules/gui/elements/assets.lua index 2e05410..95990c0 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/assets.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/assets.lua @@ -1,12 +1,12 @@ 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, depth) +function AssetElement:new(name, assetType, assetName, x, y,r,sx,sy,ox,oy, opacity) local gui = self:getGui() local asset = gui.scene.assets[assetType][assetName] assert(asset ~= nil, assetName .. ' (' .. assetType .. ") doesn't exist") - AssetElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity, depth) + AssetElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity) end function AssetElement:draw() diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua index 62a6949..f3b043c 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -1,14 +1,13 @@ 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, depth) +function CanvasElement:new(name, x, y, w, h, r,sx,sy,ox,oy, opacity) self:initCanvas() CanvasElement.super.new(self, name, x, y, w, h) self.r = r or 0 self.sx, self.sy = sx or 1, sy or 1 self.ox, self.oy = self:parseOrigin(ox, w), self:parseOrigin(oy, h) self.opacity = opacity or 1 - self.depth = depth or 0 end function CanvasElement:initCanvas() diff --git a/sonic-radiance.love/birb/modules/gui/elements/composite.lua b/sonic-radiance.love/birb/modules/gui/elements/composite.lua index 8c42561..92c072b 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/composite.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/composite.lua @@ -28,6 +28,7 @@ function CompositeElement:update(dt) childElement.x = self.x + child.relx childElement.y = self.y + child.rely childElement.isVisible = self.isVisible + childElement.depth = self.depth end end diff --git a/sonic-radiance.love/birb/modules/gui/elements/counter.lua b/sonic-radiance.love/birb/modules/gui/elements/counter.lua index fc13296..2730996 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/counter.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/counter.lua @@ -1,8 +1,8 @@ local Parent = require "birb.modules.gui.elements.variable" local CounterElement = Parent:extend() -function CounterElement:new(name, fontName, object, varName, nbrs, x, y, align, depth) - CounterElement.super.new(self, name, fontName, object, varName, x, y, align, depth) +function CounterElement:new(name, fontName, object, varName, nbrs, x, y, align) + CounterElement.super.new(self, name, fontName, object, varName, x, y, align) self.nbrs = nbrs or 0 end diff --git a/sonic-radiance.love/birb/modules/gui/elements/drawable.lua b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua index 76c1031..7027c52 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/drawable.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua @@ -1,7 +1,7 @@ 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, depth) +function DrawableElement:new(name, drawable, x, y,r,sx,sy,ox,oy, opacity) self.drawable = drawable local w, h = self.drawable:getDimensions() @@ -10,7 +10,6 @@ function DrawableElement:new(name, drawable, x, y,r,sx,sy,ox,oy, opacity, depth) self.sx, self.sy = sx or 1, sy or 1 self.ox, self.oy = self:parseOrigin(ox, w), self:parseOrigin(oy, h) self.opacity = opacity or 1 - self.depth = depth or 0 end function DrawableElement:parseOrigin(origin, size) diff --git a/sonic-radiance.love/birb/modules/gui/elements/text.lua b/sonic-radiance.love/birb/modules/gui/elements/text.lua index ebd4ffa..c5f9871 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/text.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/text.lua @@ -1,14 +1,13 @@ local Parent = require "birb.modules.gui.elements.parent" local TextElement = Parent:extend() -function TextElement:new(name, fontName, text, x, y, align, depth) +function TextElement:new(name, fontName, text, x, y, align) self.text = text local gui = self:getGui() self.font = gui.scene.assets.fonts[fontName] TextElement.super.new(self, name, x, y, 1, 1) self.align = align - self.depth = depth or 0 end function TextElement:getText() diff --git a/sonic-radiance.love/birb/modules/gui/elements/variable.lua b/sonic-radiance.love/birb/modules/gui/elements/variable.lua index 7716230..32a95b4 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/variable.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/variable.lua @@ -1,8 +1,8 @@ local Parent = require "birb.modules.gui.elements.text" local VariableElement = Parent:extend() -function VariableElement:new(name, fontName, object, varName, x, y, align, depth) - VariableElement.super.new(self, name, fontName, "", x, y, align, depth) +function VariableElement:new(name, fontName, object, varName, x, y, align) + VariableElement.super.new(self, name, fontName, "", x, y, align) self.object = object self.variable = varName end -- 2.30.2 From 70f1fe21e91a7ac3fe8dce59f4b1a3253877bdd3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:56:56 +0200 Subject: [PATCH 038/102] feat: add keypressed customization --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 1d44c39..10af95c 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -18,6 +18,10 @@ function GuiElement:new(name, x, y, w, h) self:register() end +function GuiElement:setKeyPressAction(func) + self.func = func +end + function GuiElement:getGui() local scene = core.scenemanager.nextScene or core.scenemanager.currentScene return scene.gui @@ -127,7 +131,9 @@ end -- Handle key press function GuiElement:keypressed(key) - -- Cette fonction ne contient rien par défaut + if (self.func ~= nil) then + self.func(key) + end end -- MOUSE FUNCTIONS -- 2.30.2 From 3c94f9c1c6b8dbe25d53f4e9701c737ee56bac00 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:57:24 +0200 Subject: [PATCH 039/102] feat: some parsing improvement --- sonic-radiance.love/birb/utils/bools.lua | 15 ++++++++++++++ sonic-radiance.love/birb/utils/string.lua | 2 +- sonic-radiance.love/birb/utils/table.lua | 24 ++++++++++++----------- 3 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 sonic-radiance.love/birb/utils/bools.lua diff --git a/sonic-radiance.love/birb/utils/bools.lua b/sonic-radiance.love/birb/utils/bools.lua new file mode 100644 index 0000000..2f43829 --- /dev/null +++ b/sonic-radiance.love/birb/utils/bools.lua @@ -0,0 +1,15 @@ +local Bools = {} + +function Bools.either(bool, val1, val2) + if (bool) then + return val1 + else + return val2 + end +end + +function Bools.toString(bool) + return Bools.either(bool, "true", "false") +end + +return Bools diff --git a/sonic-radiance.love/birb/utils/string.lua b/sonic-radiance.love/birb/utils/string.lua index 2ad8f7b..68eca05 100644 --- a/sonic-radiance.love/birb/utils/string.lua +++ b/sonic-radiance.love/birb/utils/string.lua @@ -21,6 +21,6 @@ function String.split(pString, pPattern) table.insert(Table, cap) end return Table - end +end return String \ No newline at end of file diff --git a/sonic-radiance.love/birb/utils/table.lua b/sonic-radiance.love/birb/utils/table.lua index 0c3b0d2..ce08309 100644 --- a/sonic-radiance.love/birb/utils/table.lua +++ b/sonic-radiance.love/birb/utils/table.lua @@ -22,6 +22,7 @@ ]] local Table = {} +local Bools = require "birb.utils.bools" --- Get the sum of a liste of number ---@param table table the table which you want to find if it contain the content @@ -39,22 +40,23 @@ end --- Get the table in form of a string ---@param table table the table which you want to transform into a string ---@return string string the string created from the table -function Table.toString(table) +function Table.toString(table, depth) + depth = depth or 2 local string = "{" for key, value in pairs(table) do - string = string .. key .. ":" - if (type(value) == "table") then - string = string .. Table.toString(value) - elseif type(value) == "boolean" then - if (value) then - string = string .. "true" + if (type(value) ~= "userdata" and depth > 0) then + if (type(value) == "table") then + if (value.is ~= nil) then + string = string .. "Object" + end + string = string .. Table.toString(value, depth - 1) + elseif (type(value) == "boolean") then + string = string .. Bools.toString(value) else - string = string .. "false" + string = string .. value end - else - string = string .. value + string = string .. "," end - string = string .. "," end return string .. "}" end -- 2.30.2 From 28f41fcc49bc49ed0204093de4b061498be7a960 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:57:34 +0200 Subject: [PATCH 040/102] feat: get skillname from character --- .../game/abstractmobs/character/datas.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sonic-radiance.love/game/abstractmobs/character/datas.lua b/sonic-radiance.love/game/abstractmobs/character/datas.lua index d688f71..abd7ca4 100644 --- a/sonic-radiance.love/game/abstractmobs/character/datas.lua +++ b/sonic-radiance.love/game/abstractmobs/character/datas.lua @@ -15,4 +15,18 @@ function CharacterData:getResistences() return self.data.resists end +function CharacterData:getSkillName(skill) + local skilldata = core.datas:get("skills", skill) + local name = skilldata.fullname + + + if (skilldata.altName ~= nil) then + if (skilldata.altName[self.simplename] ~= nil) then + name = skilldata.altName[self.simplename] + end + end + print(name) + return name +end + return CharacterData -- 2.30.2 From 839813768d1dece13a74964cceb712e2b2cff6bd Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 18:30:28 +0200 Subject: [PATCH 041/102] fix: focus fix --- sonic-radiance.love/birb/modules/gui/mixins/elements.lua | 9 ++++++++- sonic-radiance.love/birb/modules/gui/screen.lua | 8 +++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index 3bcffb6..0bf1511 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -46,7 +46,7 @@ function ElementList:elementExists(name) end function ElementList:haveFocus() - return self:elementExists(self.focusedElement) + return self:elementIsVisible(self.focusedElement) end function ElementList:getFocusedElement() @@ -81,4 +81,11 @@ function ElementList:getVisibleElement(topLayer) return visibleList end +function ElementList:elementIsVisible(name) + if (self:elementExists(name)) then + return self.elements[name]:getVisibility() + end + return false +end + return ElementList \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua index 3a2c08e..5ced2b2 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -80,18 +80,16 @@ function GuiScreen:registerElements() local elemData = utils.table.parse(rawElement, elementDataStruct, 3) local element = elemData.element self:addElement(element.name, element) + if (elemData.focus == true) then + element:getFocus() + end if (elemData.delay > 0) then element.isVisible = false element:newSwitch(elemData.delay, {"isVisible"}) - print(elemData.delay) end if (elemData.depth ~= nil) then element.depth = elemData.depth end - print(element, element.name, elemData.depth, elemData.focus) - if (elemData.focus == true) then - element:getFocus() - end if (elemData.keypress ~= nil) then element:setKeyPressAction(elemData.keypress) end -- 2.30.2 From 759daf5ec01035bfa930d002462e547570fd1d4e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 19:02:43 +0200 Subject: [PATCH 042/102] improvement: port confirmdialog to Gui --- .../game/modules/confirmdialog/init.lua | 77 ++++++++----------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/sonic-radiance.love/game/modules/confirmdialog/init.lua b/sonic-radiance.love/game/modules/confirmdialog/init.lua index 4a1272c..5ace915 100644 --- a/sonic-radiance.love/game/modules/confirmdialog/init.lua +++ b/sonic-radiance.love/game/modules/confirmdialog/init.lua @@ -1,14 +1,16 @@ -local ConfirmDialog = Object:extend() +local GuiElement = require "birb.modules.gui.elements.canvas" +local ConfirmDialog = GuiElement:extend() local gui = require "game.modules.gui" local WIDTH = 256 local PADWIDTH = 16 local PADHEIGHT = 16 +local DEFAULT_LINES = 2 function ConfirmDialog:new(scene, message, choice1func, choice1, choice2func, choice2) self.scene = scene - self.lines = 2 + self.lines = DEFAULT_LINES self.message = message self.choiceLabel = {} @@ -26,50 +28,43 @@ function ConfirmDialog:new(scene, message, choice1func, choice1, choice2func, ch self.currentChoice = 0 self.cancelChoice = -1 - self.isActive = false - self.scene.dialog = self - self.texture = self:createTexture() + ConfirmDialog.super.new(self, "dialog", 424/2, 240/2, WIDTH + PADWIDTH, self:computeHeight()) + self.back = gui.newTextBox("assets/gui/dialogbox.png", self.w, self.h) + self.ox = self.w/2 + self.oy = self.h/2 + self.canvas.padding = 0 + self.depth = 0 + self.isVisible = 1 + self:getFocus() end function ConfirmDialog:setLines(lines) self.lines = lines - self.texture = self:createTexture() + self.h = self:computeHeight() + self.oy = self.h/2 + self.canvas.needRedraw = true + self.back = gui.newTextBox("assets/gui/dialogbox.png", self.w, self.h) end -function ConfirmDialog:createTexture() - self.height = 32 + (self.lines * 16) + PADHEIGHT - return gui.newTextBox("assets/gui/dialogbox.png", WIDTH + PADWIDTH, self.height) +function ConfirmDialog:computeHeight() + return 32 + (self.lines * 16) + PADHEIGHT end function ConfirmDialog:setCancelChoice(choice) self.cancelChoice = choice - 1 end -function ConfirmDialog:update(dt) - if (self.isActive) then - self:keycheck() - else - self.isActive = true - end -end - -function ConfirmDialog:keycheck() - local keys = self.scene.sources[1].keys - if (keys["up"].isPressed or - self.scene.sources[1].keys["down"].isPressed) then +function ConfirmDialog:keypressed(key) + if (key == "up" or key == "down") then self.currentChoice = (self.currentChoice + 1) % 2 self.scene.assets.sfx["mBeep"]:play() - end - - if (keys["A"].isPressed) then + self.canvas.needRedraw = true + elseif (key == "A") then self:doAction(self.currentChoice) - end - - if (keys["B"].isPressed) then + elseif (key == "B") then self:doAction(self.cancelChoice) end - end function ConfirmDialog:doAction(choice) @@ -83,33 +78,21 @@ function ConfirmDialog:doAction(choice) end function ConfirmDialog:dismiss() + local guiSystem = self:getGui() + guiSystem:setLastFocus() self:destroy() end -function ConfirmDialog:destroy() - self.scene.dialog = nil -end - -function ConfirmDialog:draw() - local x, y = self:getCoord() +function ConfirmDialog:drawTexture() + love.graphics.draw(self.back, 0) local padx, pady = 8, 6 - if (self.darken) then - love.graphics.setColor(0,0,0,0.5) - love.graphics.rectangle("fill", 0, 0, 424, 240) - utils.graphics.resetColor() - end - love.graphics.draw(self.texture, x, y) - self.scene.assets.fonts["small"]:draw(self.message ,x + padx, y + pady,WIDTH,"left") + self.scene.assets.fonts["small"]:draw(self.message ,padx, pady, WIDTH,"left") for i = 1, 2, 1 do - self.scene.assets.fonts["small"]:draw(self.choiceLabel[i], x + padx + 8, y + pady + (self.lines + i - 1)*16) + self.scene.assets.fonts["small"]:draw(self.choiceLabel[i], padx + 8, pady + (self.lines + i - 1)*16) if ((self.currentChoice + 1) == i) then - self.scene.assets.fonts["small"]:draw(">", x + padx, y + pady + (self.lines + i - 1)*16) + self.scene.assets.fonts["small"]:draw(">", padx, pady + (self.lines + i - 1)*16) end end end -function ConfirmDialog:getCoord() - return (424-(WIDTH + PADWIDTH))/2, (240 - self.height)/2 -end - return ConfirmDialog \ No newline at end of file -- 2.30.2 From 83a89dc69b760b86bb88a6bba4766ca2d2b8ebbc Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 19:12:40 +0200 Subject: [PATCH 043/102] feat: initial gui version of radiance's menus --- .../game/modules/gui/boxedmenu.lua | 71 +++++++++++++++++++ .../game/modules/gui/fancymenu.lua | 32 +++++++++ 2 files changed, 103 insertions(+) create mode 100644 sonic-radiance.love/game/modules/gui/boxedmenu.lua create mode 100644 sonic-radiance.love/game/modules/gui/fancymenu.lua diff --git a/sonic-radiance.love/game/modules/gui/boxedmenu.lua b/sonic-radiance.love/game/modules/gui/boxedmenu.lua new file mode 100644 index 0000000..6812251 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/boxedmenu.lua @@ -0,0 +1,71 @@ +local ParentMenu = require "birb.modules.gui.textmenu" +local BoxedList = ParentMenu:extend() + +local gui = require "game.modules.gui" + +function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder) + BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0) + self.paddingLeft = 12 + self.paddingRight = 4 + + self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") + self.cursorTransition = 0 + + self.isBoxed = isBoxed + if (isBoxed) then + local border = self.h + 16 + if (smallborder == true) then + border = self.h + 8 + end + self.box = gui.newTextBox("assets/gui/dialogbox.png", w + 8, border) + end +end + +function BoxedList:finalize() + self:setCancelWidget() +end + +function BoxedList:update(dt) + BoxedList.super.update(self, dt) + self:updateCursorPosition(dt) +end + +function BoxedList:updateCursorPosition(dt) + local relativecursor = self.widget.selected - self.view.firstSlot + + local transition = self.cursorTransition - relativecursor + if math.abs(transition) < 0.1 then + self.cursorTransition = relativecursor + else + local speed = dt * 45 + local movement = ((relativecursor) - (self.cursorTransition)) + self.cursorTransition = (self.cursorTransition) + movement * speed + end +end + +function BoxedList:drawCursor() + local x, y = self:getCursorPosition() + love.graphics.draw(self.cursorTexture, x, y) +end + +function BoxedList:getCursorPosition() + local addition = self.lineHeight + local x = self.x + 6 + local y = self.y + ((self.cursorTransition) * addition) + 1 + return x, y +end + +function BoxedList:draw() + if (self.isBoxed) then + local dy = 8 + if (self.smallborder) then + dy = 4 + end + local w, h = self.box:getDimensions() + local diff = (w-self.w)/2 + love.graphics.draw(self.box, self.x - self.ox - diff, self.y - self.oy - dy) + end + BoxedList.super.draw(self) +end + +return BoxedList diff --git a/sonic-radiance.love/game/modules/gui/fancymenu.lua b/sonic-radiance.love/game/modules/gui/fancymenu.lua new file mode 100644 index 0000000..61d4c96 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/fancymenu.lua @@ -0,0 +1,32 @@ +local ParentMenu = require "birb.modules.gui.textmenu" +local FancyMenu = ParentMenu:extend() + +local gui = require "game.modules.gui" + +function FancyMenu:new(name, x, y, w, itemNumber, haveBiseau) + FancyMenu.super.new(self, name, "small", x, y, w, itemNumber) + self.biseau = utils.math.either(haveBiseau, 8, 0) + self.itemNumber = itemNumber + self.box = gui.newChoiceBack(self.w + 24) + self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") +end + +function FancyMenu:getDimensions() + local w, h = FancyMenu.super.getDimensions(self) + return w + (self.biseau*self.itemNumber), h +end + +function FancyMenu:getListPart(i) + local x, y, w, h = FancyMenu.super.getListPart(self, i) + return x + (self.biseau*i), y, w, h +end + +function FancyMenu:drawWidgetBackground(x, y, w, h) + love.graphics.draw(self.box, x - 8, y + 2) +end + +function FancyMenu:drawGraphicalCursor(x, y, w, h) + love.graphics.draw(self.cursorTexture, x - 3, y + 1) +end + +return FancyMenu -- 2.30.2 From e0ebc4969ce5332a9732785a4deb95f3649f0206 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 19:12:56 +0200 Subject: [PATCH 044/102] feat: initial gui version of gameover --- .../game/modules/gui/gameover.lua | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sonic-radiance.love/game/modules/gui/gameover.lua diff --git a/sonic-radiance.love/game/modules/gui/gameover.lua b/sonic-radiance.love/game/modules/gui/gameover.lua new file mode 100644 index 0000000..af1fdab --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/gameover.lua @@ -0,0 +1,44 @@ +local Screen = require "birb.modules.gui.screen" +local GameOverScreen = Screen:extend() + +local TextElement = require "birb.modules.gui.elements.text" +local ConfirmDialog = require "game.modules.confirmdialog" + +local defTransitions = require "birb.modules.transitions" + +local HEIGHT = 40 + +local show = { + {"gameText", "movement", 0.9, 0.4, 424/2 - 4, HEIGHT, "inExpo"}, + {"overText", "movement", 0.9, 0.4, 424/2 + 4, HEIGHT, "inExpo"} + } + +function GameOverScreen:new() + GameOverScreen.super.new(self, "titleScreen") + self:addTransform("show", show) + self.scene:showOverlay(true) + self:show() +end + +function GameOverScreen:createElements() + return { + {TextElement("gameText", "SA2font", "GAME", 0, HEIGHT, "right"), 0, 1}, + {TextElement("overText", "SA2font", "OVER", 424, HEIGHT, "left"), 0, 1}, + {ConfirmDialog(self.scene, "Do you want to return to title ? \nYou can also reload your latest save.", + function() self:returnToTitle() end, "Return to title", + function() self:loadLastSave() end, "Reload last save"), + 1.8, 0} + } +end + +function GameOverScreen:returnToTitle() + core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2) +end + +function GameOverScreen:loadLastSave() + self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad") + core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2) +end + + +return GameOverScreen \ No newline at end of file -- 2.30.2 From 4ccb0556729423deb25db34709546bb0ea4ea79c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 19:13:17 +0200 Subject: [PATCH 045/102] feat: add overlay darkening --- sonic-radiance.love/game/modules/gui/overlay.lua | 14 +++++++------- sonic-radiance.love/game/scenes/init.lua | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sonic-radiance.love/game/modules/gui/overlay.lua b/sonic-radiance.love/game/modules/gui/overlay.lua index ae18c4c..7cca4c5 100644 --- a/sonic-radiance.love/game/modules/gui/overlay.lua +++ b/sonic-radiance.love/game/modules/gui/overlay.lua @@ -21,15 +21,15 @@ local animateDisappear = { {"upBorder", "movement", 0.0, 0.5, 0, 0, "inOutQuart"}, {"downBorder", "movement", 0.0, 0.5, 424, 240, "inOutQuart"}, {"version", "movement", 0.0, 0.5, 380, 250, "inOutQuart"}, - {"overlayDarken", "tween", 0.0, 0.4, {opacity = 0}, "outExpo"} + {"overlayDarken", "tween", 0.0, 0.6, {opacity = 0}, "outExpo"} } local showBackground = { - {"overlayDarken", "tween", 0.0, 0.4, {opacity = OVERLAY_OPACITY}, "inExpo"} + {"overlayDarken", "tween", 0.0, 0.6, {opacity = OVERLAY_OPACITY}, "inExpo"} } local hideBackground = { - {"overlayDarken", "tween", 0.0, 0.4, {opacity = 0}, "outExpo"} + {"overlayDarken", "tween", 0.0, 0.6, {opacity = 0}, "outExpo"} } local showVersion = { @@ -86,10 +86,10 @@ function OverlayScreen:createElements() local d = either(wasActive, 30, 0) local v = either(hadVersion, 30, 0) return { - {TextureElement("upBorder", self.borders, 0, d, 0, 1, -1, 0, 0, 1, -1), 0}, - {TextureElement("downBorder", self.borders, 424, 240 - d, 0, -1, 1, 0, 0, 1, -1), 0}, - {ColorElement("overlayDarken", 0, 0, 0, 0), 0}, - {TextElement("version", "small", "v" .. game.version, 380, 250 - v, "left", -1), 0} + {TextureElement("upBorder", self.borders, 0, d, 0, 1, -1, 0, 0, 1), 0, -1}, + {TextureElement("downBorder", self.borders, 424, 240 - d, 0, -1, 1, 0, 0, 1), 0, -1}, + {ColorElement("overlayDarken", 0, 0, 0, 0), 0, 5}, + {TextElement("version", "small", "v" .. game.version, 380, 250 - v, "left"), 0, -1} } end diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua index 050a2f9..c40517f 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -2,6 +2,7 @@ local BirbScene = require "birb.modules.scenes" local RadianceScene = BirbScene:extend() local Overlay = require "game.modules.gui.overlay" +local MessageQueue = require "game.modules.messagequeue" function RadianceScene:new(haveBorder, showVersion) RadianceScene.super.new(self) @@ -16,14 +17,18 @@ function RadianceScene:new(haveBorder, showVersion) self.gui:addSFX("error", "mError") Overlay(haveBorder, showVersion) + MessageQueue(self) end function RadianceScene:hideOverlay() self.gui:hideScreen("overlay") end -function RadianceScene:showOverlay() +function RadianceScene:showOverlay(darken) self.gui:showScreen("overlay") + if (darken) then + self.gui:playScreenTransform("overlay", "showBackground") + end end -- 2.30.2 From 4a84d2dc53fb88bb1f0656d212a5dea85b94a5c4 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 23:47:01 +0200 Subject: [PATCH 046/102] improvement: better wrapper handling in guiElement --- .../birb/modules/gui/elements/assets.lua | 4 +-- .../birb/modules/gui/elements/composite.lua | 2 +- .../birb/modules/gui/elements/parent.lua | 33 +++++++------------ .../birb/modules/gui/elements/text.lua | 7 ++-- .../birb/modules/gui/menus/parent.lua | 7 ++-- .../birb/modules/gui/menus/widgets/base.lua | 17 +++++----- .../birb/modules/gui/screen.lua | 18 +++++----- .../game/modules/confirmdialog/init.lua | 3 +- 8 files changed, 41 insertions(+), 50 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/assets.lua b/sonic-radiance.love/birb/modules/gui/elements/assets.lua index 95990c0..b12ca50 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/assets.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/assets.lua @@ -2,8 +2,8 @@ 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) - local gui = self:getGui() - local asset = gui.scene.assets[assetType][assetName] + self:initWrapper() + local asset = self.assets[assetType][assetName] assert(asset ~= nil, assetName .. ' (' .. assetType .. ") doesn't exist") AssetElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity) diff --git a/sonic-radiance.love/birb/modules/gui/elements/composite.lua b/sonic-radiance.love/birb/modules/gui/elements/composite.lua index 92c072b..d4d9aff 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/composite.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/composite.lua @@ -24,7 +24,7 @@ end function CompositeElement:update(dt) for _, child in ipairs(self.children) do - local childElement = self.getGui().elements[child.name] + local childElement = self.gui.elements[child.name] childElement.x = self.x + child.relx childElement.y = self.y + child.rely childElement.isVisible = self.isVisible diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 10af95c..f2dcad3 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -13,33 +13,27 @@ function GuiElement:new(name, x, y, w, h) self.depth = 10 self.tweens = TweenManager(self) - self.assets = self:getAssets() + self:initWrapper() self:register() end +function GuiElement:initWrapper() + self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene + self.gui = self.scene.gui + self.assets = self.scene.assets +end + function GuiElement:setKeyPressAction(func) self.func = func end -function GuiElement:getGui() - local scene = core.scenemanager.nextScene or core.scenemanager.currentScene - return scene.gui -end - -function GuiElement:getAssets() - local scene = core.scenemanager.nextScene or core.scenemanager.currentScene - return scene.assets -end - function GuiElement:register() - local gui = self:getGui() - self.creationId = gui:addElement(self.name, self) + self.creationId = self.gui:addElement(self.name, self) end function GuiElement:destroy() - local gui = self:getGui() - gui:deleteElement(self.name) + self.gui:deleteElement(self.name) if (self.screen ~= nil) then self.screen:deleteElement(self.name) end @@ -65,19 +59,16 @@ function GuiElement:setVisibility(visibility) end function GuiElement:getFocus() - local gui = self:getGui() - gui:setFocus(self.name) + self.gui:setFocus(self.name) end function GuiElement:haveFocus() - local gui = self:getGui() - return (gui.focusedElement == self.name) + return (self.gui.focusedElement == self.name) end function GuiElement:looseFocus() if (self:haveFocus()) then - local gui = self:getGui() - gui:removeFocus() + self.gui:removeFocus() end end diff --git a/sonic-radiance.love/birb/modules/gui/elements/text.lua b/sonic-radiance.love/birb/modules/gui/elements/text.lua index c5f9871..ce24c2b 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/text.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/text.lua @@ -2,11 +2,10 @@ local Parent = require "birb.modules.gui.elements.parent" local TextElement = Parent:extend() function TextElement:new(name, fontName, text, x, y, align) - self.text = text - local gui = self:getGui() - self.font = gui.scene.assets.fonts[fontName] - TextElement.super.new(self, name, x, y, 1, 1) + self.text = text + self.font = self.assets.fonts[fontName] + self.align = align end diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index bee182a..51e24c7 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -33,7 +33,9 @@ local menuUtils = require "birb.modules.gui.utils" function Menu:new(name, x, y, w, h) Menu.super.new(self, name, x, y, w, h) - self.menusystem = self:getGui() + + --TODO: remove this + self.menusystem = self.gui self.widget = MenuModel() self.widgetSize = {} @@ -216,8 +218,7 @@ function Menu:playNavigationSound() end function Menu:playSFX(name) - local gui = self:getGui() - gui:playSFX(name) + self.gui:playSFX(name) end -- VIEW FUNCTIONS diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua index e295bb8..9caee47 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua @@ -26,9 +26,8 @@ local BaseWidget = Object:extend() -- Initialize and configure the widget function BaseWidget:new(menuName) - self.scene = self:getScene() + self:initWrapper() self.menu = self:getMenuByName(menuName) - self.assets = self:getAssets() self.destroyed = false self.selectable = false @@ -45,25 +44,25 @@ function BaseWidget:new(menuName) self.type = "select" end +function BaseWidget:initWrapper() + self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene + self.gui = self.scene.gui + self.assets = self.scene.assets +end + function BaseWidget:setFunc(func) self.func = func end function BaseWidget:getMenuByName(name) - local gui = self:getGui() assert(name ~= nil, "Name cant be nil") - return gui.elements[name] + return self.gui.elements[name] end function BaseWidget:getScene() return core.scenemanager.nextScene or core.scenemanager.currentScene end -function BaseWidget:getGui() - local scene = core.scenemanager.nextScene or core.scenemanager.currentScene - return scene.gui -end - function BaseWidget:getAssets() local scene = core.scenemanager.nextScene or core.scenemanager.currentScene return scene.assets diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua index 5ced2b2..4a6eb49 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -10,7 +10,8 @@ local elementDataStruct = require "birb.structures.elementData" function GuiScreen:new(name, controller) - self.controller = controller or self:getGui() + self:initWrapper() + self.controller = controller or self.gui self.name = name self.isVisible = false self.transforms = {} @@ -21,6 +22,13 @@ function GuiScreen:new(name, controller) self.controller:addScreen(name, self) end +function GuiScreen:initWrapper() + local scene = core.scenemanager.nextScene or core.scenemanager.currentScene + self.scene = scene + self.gui = scene.gui + self.assets = scene.assets +end + function GuiScreen:update(dt) self.tweens:update(dt) for _, screen in pairs(self.screens) do @@ -56,13 +64,7 @@ function GuiScreen:addTransform(name, transform) end function GuiScreen:playTransform(name, delay) - local gui = self:getGui() - return gui:transform(self.transforms[name], delay) -end - -function GuiScreen:getGui() - local scene = core.scenemanager.nextScene or core.scenemanager.currentScene - return scene.gui + return self.gui:transform(self.transforms[name], delay) end function GuiScreen:reset() diff --git a/sonic-radiance.love/game/modules/confirmdialog/init.lua b/sonic-radiance.love/game/modules/confirmdialog/init.lua index 5ace915..9f9b502 100644 --- a/sonic-radiance.love/game/modules/confirmdialog/init.lua +++ b/sonic-radiance.love/game/modules/confirmdialog/init.lua @@ -78,8 +78,7 @@ function ConfirmDialog:doAction(choice) end function ConfirmDialog:dismiss() - local guiSystem = self:getGui() - guiSystem:setLastFocus() + self.gui:setLastFocus() self:destroy() end -- 2.30.2 From 959fd99ba493050666bfb2172f5a58dc67346ceb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 3 Sep 2021 11:12:25 +0200 Subject: [PATCH 047/102] feat(drawable): apply opacity. --- sonic-radiance.love/birb/modules/gui/elements/drawable.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/elements/drawable.lua b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua index 7027c52..e2ac258 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/drawable.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua @@ -23,7 +23,9 @@ function DrawableElement:parseOrigin(origin, size) end function DrawableElement:draw() + love.graphics.setColor(1, 1, 1, self.opacity) love.graphics.draw(self.drawable, self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy) + love.graphics.setColor(1, 1, 1, 1) end return DrawableElement \ No newline at end of file -- 2.30.2 From 07400ce991045f7ae21beb398b1687d5a047aad2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 3 Sep 2021 11:13:06 +0200 Subject: [PATCH 048/102] feat(textElem): add opacity handling --- sonic-radiance.love/birb/modules/gui/elements/text.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/elements/text.lua b/sonic-radiance.love/birb/modules/gui/elements/text.lua index ce24c2b..0db3ec0 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/text.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/text.lua @@ -7,6 +7,7 @@ function TextElement:new(name, fontName, text, x, y, align) self.font = self.assets.fonts[fontName] self.align = align + self.opacity = 1 end function TextElement:getText() @@ -14,7 +15,9 @@ function TextElement:getText() end function TextElement:draw() + self.font:setColor(1, 1, 1, self.opacity) self.font:draw(self:getText(), self.x, self.y, -1, self.align) + love.graphics.setColor(1, 1, 1, 1) end return TextElement \ No newline at end of file -- 2.30.2 From 6c55a070fecbbb20789ebbf96a0e25a35fdfd86b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 3 Sep 2021 11:44:17 +0200 Subject: [PATCH 049/102] fix: better handling of indirect rendering --- sonic-radiance.love/birb/core/init.lua | 1 + .../birb/core/scenemanager.lua | 4 ++ .../birb/modules/gui/elements/canvas.lua | 37 ++++++++++--------- .../birb/modules/gui/elements/parent.lua | 4 ++ sonic-radiance.love/birb/modules/gui/init.lua | 6 +++ .../birb/modules/gui/menus/model/init.lua | 7 ++++ .../birb/modules/gui/menus/model/page.lua | 6 +++ .../birb/modules/gui/menus/parent.lua | 5 +++ .../birb/modules/gui/menus/widgets/base.lua | 11 ++++-- sonic-radiance.love/birb/modules/scenes.lua | 4 ++ 10 files changed, 64 insertions(+), 21 deletions(-) diff --git a/sonic-radiance.love/birb/core/init.lua b/sonic-radiance.love/birb/core/init.lua index f88d879..c618bd0 100644 --- a/sonic-radiance.love/birb/core/init.lua +++ b/sonic-radiance.love/birb/core/init.lua @@ -138,6 +138,7 @@ end -- Draw the whole game function CoreSystem:draw() + self.scenemanager:redraw() self.scenemanager:draw() end diff --git a/sonic-radiance.love/birb/core/scenemanager.lua b/sonic-radiance.love/birb/core/scenemanager.lua index e613ea9..6344b02 100644 --- a/sonic-radiance.love/birb/core/scenemanager.lua +++ b/sonic-radiance.love/birb/core/scenemanager.lua @@ -127,4 +127,8 @@ function SceneManager:draw() self.controller.screen:cease() end +function SceneManager:redraw() + self.currentScene:redraw() +end + return SceneManager diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua index f3b043c..54d782f 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -20,9 +20,6 @@ end function CanvasElement:updateElement(dt) CanvasElement.super.updateElement(self, dt) - if (self.canvas.needRedraw or self.canvas.isAnimated) then - self:redraw() - end end function CanvasElement:getCanvasDimensions() @@ -30,22 +27,28 @@ function CanvasElement:getCanvasDimensions() end function CanvasElement:redraw() - local w, h = self:getDimensions() + if (self.canvas.needRedraw or self.canvas.isAnimated) then + self:generateTexture() + end +end - local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2)) - love.graphics.setCanvas(canvas) +function CanvasElement:generateTexture() + local w, h = self:getDimensions() - self:drawTexture() - self.canvas.needRedraw = false - love.graphics.setCanvas() - if (self.canvas.isAnimated) then - self.canvas.texture = canvas - else - local imageData = canvas:newImageData() - self.canvas.texture = love.graphics.newImage(imageData) - canvas:release() - imageData:release() - end + local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2)) + love.graphics.setCanvas(canvas) + + self:drawTexture() + self.canvas.needRedraw = false + love.graphics.setCanvas() + if (self.canvas.isAnimated) then + self.canvas.texture = canvas + else + local imageData = canvas:newImageData() + self.canvas.texture = love.graphics.newImage(imageData) + canvas:release() + imageData:release() + end end function CanvasElement:drawTexture() diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index f2dcad3..ae7ac02 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -110,6 +110,10 @@ end -- DRAW FUNCTIONS -- Draw the menu and its content +function GuiElement:redraw() + +end + function GuiElement:drawElement() self:draw() end diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 7f6fbe5..1a9bbf1 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -162,6 +162,12 @@ end -- DRAW FUNCTIONS -- Draw the menu and its content +function Gui:redraw() + for _, element in pairs(self.elements) do + element:redraw() + end +end + function Gui:drawTop() for _, element in ipairs(self:getVisibleElement(true)) do element:drawElement() diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua index e6979a1..39e8b53 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua @@ -185,5 +185,12 @@ function MenuModel:moveCursor(relative) page:moveCursor(relative) end +-- DRAW +-- Draw widget +function MenuModel:redraw() + local page = self:getCurrentPage() + page:redraw() +end + return MenuModel diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua index 326b76f..d99c471 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua @@ -189,5 +189,11 @@ function Page:moveCursor(relative) self:moveCursorAbsolute(self.selected + relative) end +-- DRAW +function Page:redraw() + for _, widget in ipairs(self.widgets) do + widget:redraw() + end +end return Page diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index 51e24c7..c5bfbd5 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -169,6 +169,11 @@ function Menu:drawWidgetBackground(x, y, w, h) end +function Menu:redraw() + self.widget:redraw() + Menu.super.redraw(self) +end + -- WIDGET FUNCTIONS -- Handle widgets of the functions diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua index 9caee47..ca106f6 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua @@ -73,7 +73,13 @@ function BaseWidget:register() self.menu:addWidget(self) end -function BaseWidget:redrawCanvas() +function BaseWidget:redraw() + if (self.canvas.needRedraw) then + self:generateTexture() + end +end + +function BaseWidget:generateTexture() self.width, self.height = self.menu:getWidgetSize(self.id) local canvas = love.graphics.newCanvas(self.width, self.height) @@ -134,9 +140,6 @@ end -- Update the widget function BaseWidget:update(dt) - if (self.canvas.needRedraw) then - self:redrawCanvas() - end -- N/A end diff --git a/sonic-radiance.love/birb/modules/scenes.lua b/sonic-radiance.love/birb/modules/scenes.lua index d2c467b..141da1e 100644 --- a/sonic-radiance.love/birb/modules/scenes.lua +++ b/sonic-radiance.love/birb/modules/scenes.lua @@ -149,6 +149,10 @@ end -- DRAW FUNCTIONS -- Draw the scene and its content +function Scene:redraw() + self.gui:redraw() +end + function Scene:drawScene() self:drawStart() self:drawWorld() -- 2.30.2 From 023e0185ef792b6782f324f479b5ec584bb8c69c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 12 Sep 2021 09:53:58 +0200 Subject: [PATCH 050/102] feat: add func support to guiElements --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index ae7ac02..2083f3e 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -101,6 +101,10 @@ function GuiElement:newSwitch(start, bools) self.tweens:newSwitch(start, bools) end +function GuiElement:newFunc(start, func) + self.tweens:newFunc(start, func) +end + function GuiElement:delayFocus(start) self.tweens:newFunc(start, "focus", function () self:getFocus() -- 2.30.2 From eb9ad6e208eebb00cde9bd79ba3c748c6df9e0f4 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 12 Sep 2021 09:54:54 +0200 Subject: [PATCH 051/102] feat: add a tile guiElement --- .../birb/modules/gui/elements/tile.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sonic-radiance.love/birb/modules/gui/elements/tile.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/tile.lua b/sonic-radiance.love/birb/modules/gui/elements/tile.lua new file mode 100644 index 0000000..8ae9f46 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/tile.lua @@ -0,0 +1,19 @@ +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) + self:initWrapper() + local asset = self.assets.tileset[assetName] + assert(asset ~= nil, assetName .. " ( tileset ) doesn't exist") + self.tileId = id + + TileElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity) +end + +function TileElement:draw() + love.graphics.setColor(1, 1, 1, self.opacity) + self.drawable:drawTile(self.tileId, self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy) + utils.graphics.resetColor() +end + +return TileElement \ No newline at end of file -- 2.30.2 From 486aa019d7d855d1d8976ae0b3f2af63b9c7207d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 12 Sep 2021 09:57:47 +0200 Subject: [PATCH 052/102] feat: add an element using the choice backgrounds --- .../game/modules/gui/choiceElem.lua | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 sonic-radiance.love/game/modules/gui/choiceElem.lua diff --git a/sonic-radiance.love/game/modules/gui/choiceElem.lua b/sonic-radiance.love/game/modules/gui/choiceElem.lua new file mode 100644 index 0000000..b846d2f --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/choiceElem.lua @@ -0,0 +1,22 @@ +local CanvasElement = require "birb.modules.gui.elements.canvas" +local ChoiceElement = CanvasElement:extend() + +local gui = require "game.modules.gui" + +function ChoiceElement:new(name, label1, label2, label3, x, y, approximateWidth) + self.background = gui.newChoiceBack(approximateWidth) + local w, h = self.background:getDimensions() + ChoiceElement.super.new(self, name, x, y, w, h) + self.label1 = label1 + self.label2 = label2 + self.label3 = label3 +end + +function ChoiceElement:drawTexture() + love.graphics.draw(self.background, 0, 0) + self.assets.fonts["small"]:draw(self.label1, 16, -2, -1, "left") + self.assets.fonts["small"]:draw(self.label2, self.w/2, -2, -1, "center") + self.assets.fonts["small"]:draw(self.label3, self.w - 20, -2, -1, "right") +end + +return ChoiceElement \ No newline at end of file -- 2.30.2 From 0fe46dea91cd560e9110bbf7f3138a3413edc515 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 12 Sep 2021 09:57:57 +0200 Subject: [PATCH 053/102] feat: add way to draw empty icons --- sonic-radiance.love/game/modules/gui/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sonic-radiance.love/game/modules/gui/init.lua b/sonic-radiance.love/game/modules/gui/init.lua index caf86b7..c8f0426 100644 --- a/sonic-radiance.love/game/modules/gui/init.lua +++ b/sonic-radiance.love/game/modules/gui/init.lua @@ -184,5 +184,13 @@ function gui.getEmeraldsTexture(number) return texture end +function gui.drawEmptyIcon(x, y) + local outlineLight = 0.15 + love.graphics.circle("fill", x + 8, y + 8, 2, 8) + love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1) + love.graphics.circle("line", x + 8, y + 8, 2, 8) + utils.graphics.resetColor() +end + return gui -- 2.30.2 From 9acb3b303bdd405078fd8004571742bba1979161 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 12 Sep 2021 10:00:41 +0200 Subject: [PATCH 054/102] feat: make the messagequeue a GuiElement --- sonic-radiance.love/game/modules/messagequeue/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/game/modules/messagequeue/init.lua b/sonic-radiance.love/game/modules/messagequeue/init.lua index 2947ba2..f9738ee 100644 --- a/sonic-radiance.love/game/modules/messagequeue/init.lua +++ b/sonic-radiance.love/game/modules/messagequeue/init.lua @@ -1,4 +1,5 @@ -local MessageQueue = Object:extend() +local GuiElement = require "birb.modules.gui.elements.parent" +local MessageQueue = GuiElement:extend() local Message = require "game.modules.messagequeue.message" local MAX = 3 @@ -6,6 +7,8 @@ function MessageQueue:new(scene) self.messages = {} self.permaMessage = nil self.scene = scene + MessageQueue.super.new(self, "messageQueue", 0, 0, 424, 240) + self.depth = 0 end function MessageQueue:addMessage(newMessage) -- 2.30.2 From ef05a48522c464c6b12fb0610285e650c3ff0830 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 20:40:43 +0200 Subject: [PATCH 055/102] fix: fix newFunc function --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 2083f3e..cb369a6 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -101,8 +101,8 @@ function GuiElement:newSwitch(start, bools) self.tweens:newSwitch(start, bools) end -function GuiElement:newFunc(start, func) - self.tweens:newFunc(start, func) +function GuiElement:newFunc(start, name, func) + self.tweens:newFunc(start, name, func) end function GuiElement:delayFocus(start) -- 2.30.2 From 973596cf93b4ff6ae56d02d1040271340f5ee114 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 20:42:34 +0200 Subject: [PATCH 056/102] improvement: port titlescreen to gui --- .../scenes/menus/titlescreen/init.lua | 97 +++---------------- .../scenes/menus/titlescreen/menu.lua | 28 +++--- .../scenes/menus/titlescreen/pressStart.lua | 30 ++++++ .../scenes/menus/titlescreen/screen.lua | 59 +++++++++++ 4 files changed, 116 insertions(+), 98 deletions(-) create mode 100644 sonic-radiance.love/scenes/menus/titlescreen/pressStart.lua create mode 100644 sonic-radiance.love/scenes/menus/titlescreen/screen.lua diff --git a/sonic-radiance.love/scenes/menus/titlescreen/init.lua b/sonic-radiance.love/scenes/menus/titlescreen/init.lua index f5ee9de..ff6954b 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/init.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/init.lua @@ -22,98 +22,23 @@ ]] local Scene = require "game.scenes" -local TitleScreen = Scene:extend() -local gui = require "game.modules.gui" +local Title = Scene:extend() +local TitleScreen = require "scenes.menus.titlescreen.screen" -local TweenManager = require "birb.classes.time" -local Menu = require "scenes.menus.titlescreen.menu" +function Title:new(fromMenu) + Title.super.new(self, true, true) -function TitleScreen:new(fromMenu) - TitleScreen.super.new(self) - - local fromMenu = (fromMenu == true) - - self.borders = gui.newBorder(424, 30, 8) self.assets:addImage("logo", "assets/artworks/logo.png") self.assets:addTileset("charicons", "assets/sprites/characters/charicons") - self.tweens = TweenManager(self) - self:initBackground() - - self.haveMenu = false - self.flashOpacity = 0 - self.showPressStart = true - self.showPressStartTimer = 0.5 - - if (fromMenu) then - self.darkenOpacity = 0 - self.canShowPressStart = true - self.borderY = 30 - self.logoX = 0 - else - self.darkenOpacity = 1 - self.canShowPressStart = false - self.borderY = 0 - self.logoX = 270 - - self.tweens:newTween(0.2, 0.5, {borderY = 30}, "inOutQuart") - self.tweens:newTween(0.5, 0.4, {darkenOpacity = 0}, "outExpo") - self.tweens:newTween(0.7, 0.6, {logoX = 0}, "inOutQuart") - self.tweens:newTween(1.3, 0.03, {flashOpacity = 1}, "inQuart") - self.tweens:newTween(1.45, 0.2, {flashOpacity = 0}, "outExpo") - self.tweens:newSwitch(1.4, { "canShowPressStart" }) - end + TitleScreen(fromMenu) end -function TitleScreen:initBackground() - self.background = love.graphics.newImage("datas/gamedata/maps/sti/stuff/tilescreen.png") +function Title:startPressed() + self.assets:playSFX("mSelect") + self.menusystem:setSoundFromSceneAssets("mBeep") + self.gui.focusedElement = nil + self.gui:playScreenTransform("titleScreen", "showMenu") end -function TitleScreen:update(dt) - self.tweens:update(dt) - if (self.canShowPressStart) then - self.showPressStartTimer = self.showPressStartTimer - dt - if self.showPressStartTimer < 0 then - self.showPressStart = (self.showPressStart == false) - self.showPressStartTimer = 0.5 - end - - local keys = self:getKeys(1) - if (keys["start"].isPressed and (self.haveMenu == false)) then - self.assets:playSFX("mSelect") - Menu(self) - self.haveMenu = true - self.menusystem:setSoundFromSceneAssets("mBeep") - end - - end -end - -function TitleScreen:draw() - utils.graphics.resetColor() - local w, h = self.background:getDimensions() - love.graphics.draw(self.background,424/2,240/2,0,1,1,w/2,h/2) - - love.graphics.setColor(0, 0, 0, self.darkenOpacity) - love.graphics.rectangle("fill", 0, 0, 424, 240) - utils.graphics.resetColor( ) - - local w, h = self.assets.images["logo"]:getDimensions() - self.assets:drawImage("logo", 240 - 32, 80 - self.logoX, 0, 1, 1, w/2, h/2) - - if (self.canShowPressStart) and (self.showPressStart) then - self.assets.fonts["SA2font"]:print("PRESS START", 424/2, 240/1.33, "center", 0, 1, 1) - end - - love.graphics.setColor(1, 1, 1, self.flashOpacity) - love.graphics.rectangle("fill", 0, 0, 424, 240) - utils.graphics.resetColor( ) -end - -function TitleScreen:drawOverTransition() - love.graphics.draw(self.borders, 0, self.borderY, 0, 1, -1) - love.graphics.draw(self.borders, 424, 240 - self.borderY, 0, -1, 1) - self.assets.fonts["small"]:draw("v" .. game.version, 424 - 44, 240 + 10 - self.borderY) -end - -return TitleScreen +return Title diff --git a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua index f6b0afe..5fe321b 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua @@ -1,5 +1,5 @@ -local RadianceMenu = require "game.modules.menus.parents.menu" -local RadianceWidget = require "game.modules.menus.parents.widget" +local RadianceMenu = require "birb.modules.gui.menus.listbox" +local RadianceWidget = require "birb.modules.gui.menus.widgets.base" local SaveMenu = RadianceMenu:extend() local SaveWidget = RadianceWidget:extend() @@ -11,26 +11,31 @@ local radTransitions = require "game.modules.transitions" local HPADDING = 68 local VPADDING = 28 -function SaveMenu:new(scene) +function SaveMenu:new() local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2) - SaveMenu.super.new(self, scene, "save", HPADDING, VPADDING + 1, w, h, 3) + SaveMenu.super.new(self, "save", 424/2, 240/2, w, h, 3) + self.ox = w/2 + self.oy = h/2 + self.sx = 0.8 + self.sy = 0.8 + self.opacity = 0 local metadata = game:getMetadata() for i, save in ipairs(metadata) do SaveWidget(self.scene, i, save) end self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, (h / 3)) + self.isVisible = true end function SaveMenu:cancelAction() - self.scene.assets:playSFX("mBack") - self.scene.menusystem:reset() - self.scene.haveMenu = false + self:playSFX("back") + self.gui:playScreenTransform("titleScreen", "hideMenu") + self:looseFocus() end function SaveWidget:new(scene, saveid, savedata) - SaveWidget.super.new(self, scene, "save") - self.scene.menusystem:switchMenu("save") + SaveWidget.super.new(self, "save") self.saveid = saveid self.savedata = savedata self.emeralds = gui.getEmeraldsTexture(self.savedata.emeralds) @@ -46,7 +51,7 @@ function SaveWidget:drawCanvas() str = str .. "\n" str = str .. self.savedata.location .. "\n" str = str .. "Rings: " .. self.savedata.rings - self.font:draw(str, basex + 8, basey + 4) + self.assets.fonts["small"]:draw(str, basex + 8, basey + 4) for i, charName in ipairs(self.savedata.team) do local data = core.datas:get("characters", charName) @@ -56,12 +61,11 @@ function SaveWidget:drawCanvas() love.graphics.draw(self.emeralds, basex + 168, basey + 21) else - self.font:draw("New save", basex + 8, basey + 4) + self.assets.fonts["small"]:draw("New save", basex + 8, basey + 4) end end function SaveWidget:action() - self.scene.assets:playSFX("mSelect") game:read(self.saveid) core.screen:startTransition(radTransitions.borders, defTransitions.circle, function() scenes.menus.main() end, 424/2, 240/2) end diff --git a/sonic-radiance.love/scenes/menus/titlescreen/pressStart.lua b/sonic-radiance.love/scenes/menus/titlescreen/pressStart.lua new file mode 100644 index 0000000..532b21c --- /dev/null +++ b/sonic-radiance.love/scenes/menus/titlescreen/pressStart.lua @@ -0,0 +1,30 @@ +local TextElement = require "birb.modules.gui.elements.text" +local PressStart = TextElement:extend() + +function PressStart:new(isVisible) + PressStart.super.new(self, "pressStart", "SA2font", "PRESS START", 424/2, 240/1.33, "center") + self.isVisible = isVisible or false + self.showPressStartTimer = 0 +end + +function PressStart:update(dt) + self.showPressStartTimer = self.showPressStartTimer - dt + if self.showPressStartTimer < 0 then + self.showPressStart = (self.showPressStart == false) + self.showPressStartTimer = 0.5 + end +end + +function PressStart:draw() + if (self.showPressStart) then + PressStart.super.draw(self) + end +end + +function PressStart:keypressed(key) + if (key == "start") then + self.scene:startPressed() + end +end + +return PressStart \ No newline at end of file diff --git a/sonic-radiance.love/scenes/menus/titlescreen/screen.lua b/sonic-radiance.love/scenes/menus/titlescreen/screen.lua new file mode 100644 index 0000000..0f587c9 --- /dev/null +++ b/sonic-radiance.love/scenes/menus/titlescreen/screen.lua @@ -0,0 +1,59 @@ +local Screen = require "birb.modules.gui.screen" +local TitleScreen = Screen:extend() + +local AssetElement = require "birb.modules.gui.elements.assets" +local TextureElement = require "birb.modules.gui.elements.drawable" +local PressStart = require "scenes.menus.titlescreen.pressStart" +local ColorElement = require "birb.modules.gui.elements.color" + +local Menu = require "scenes.menus.titlescreen.menu" + +local either = utils.math.either + +local show = { + {"fade", "tween", 0.3, 0.4, {opacity = 0}, "outExpo"}, + {"logo", "movement", 0.5, 0.6, 424/2, 80, "inOutQuart"}, + {"flash", "tween", 1.1, 0.03, {opacity = 1}, "inQuart"}, + {"flash", "tween", 1.25, 0.2, {opacity = 0}, "outExpo"}, + --{"pressStart", "switch", 1.2, {"isVisible"}}, + --{"pressStart", "delayFocus", 1.2}, + } +local showMenu = { + {"save", "tween", 0, 0.25, {sx = 1, sy = 1, opacity = 1}, "inExpo"}, + {"save", "delayFocus", 0.25}, +} +local hideMenu = { + {"save", "tween", 0, 0.25, {sx = 0.8, sy = 0.8, opacity = 0}, "outExpo"}, + {"pressStart", "delayFocus", 0.25}, +} + +function TitleScreen:new(fromMenu) + self.fromMenu = (fromMenu == true) + TitleScreen.super.new(self, "titleScreen") + self:addTransform("show", show) + self:addTransform("showMenu", showMenu) + self:addTransform("hideMenu", hideMenu) + if (not self.fromMenu) then + self:show() + else + self.isVisible = true + end +end + +function TitleScreen:createElements() + local background = love.graphics.newImage("datas/gamedata/maps/sti/stuff/tilescreen.png") + local o = either(self.fromMenu, 0, 1) + local y = either(self.fromMenu, 80, -190) + local d = either(self.fromMenu, 0, 1.2) + return { + {TextureElement("background", background, 0, 0, 0, 1, 1, 0, 0, 1), 0, 200}, + {ColorElement("fade", 0, 0, 0, o), 0, 5}, + {AssetElement("logo", "images", "logo", 424/2, y, 0, 1, 1, "center", "center", 1, 0), 0, 4}, + {ColorElement("flash", 1, 1, 1, 0), 0, 1}, + {PressStart(self.fromMenu), d, 10, true}, + {Menu(self), 0, 4}, + } +end + + +return TitleScreen \ No newline at end of file -- 2.30.2 From 0343c017d39137fc8b975e46449b8981708e6141 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 20:59:57 +0200 Subject: [PATCH 057/102] improvement: port the option menu to gui --- .../scenes/menus/options/init.lua | 106 +------ .../scenes/menus/options/menu.lua | 223 ++++++++++++- .../scenes/menus/options/widgets.lua | 300 ------------------ 3 files changed, 220 insertions(+), 409 deletions(-) delete mode 100644 sonic-radiance.love/scenes/menus/options/widgets.lua diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index a0e5f7b..7e4e7b4 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -2,123 +2,33 @@ local Scene = require "game.scenes" local OptionsMenu = Scene:extend() local OptionMenu = require "scenes.menus.options.menu" -local Widgets = require "scenes.menus.options.widgets" local gui = require "game.modules.gui" local MenuBack = require "game.modules.gui.menuback" function OptionsMenu:new() - OptionsMenu.super.new(self) - - self:addMenu("main", true) - self:addSubMenu("video", "Video") - self:addSubMenu("audio", "Audio") - --self:addSubMenu("langs", "langs") - self:addSubMenu("inputs", "Inputs") - self:addSubMenu("difficulty", "Difficulty") - - Widgets.Resolution(self, "video") - Widgets.Switch(self, "video", "fullscreen", "Fullscreen") - Widgets.Switch(self, "video", "borders", "Borders") - Widgets.Switch(self, "video", "vsync", "Vsync") - - self:addPlayerMenus() - self:addDifficultyMenu() - - --self:setLanguageMenu() - - Widgets.Audio(self, "audio", "sfx", "SFX") - Widgets.Audio(self, "audio", "music", "Music") - - Widgets.Delete(self, "main") - Widgets.Exit(self, "main") - - self.menusystem.menus["main"]:finalize() - self.menusystem:switchMenu("main") - - self.menusystem:setSoundFromSceneAssets("mBeep") + OptionsMenu.super.new(self, true, true) self.keyDetector = {} self.keyDetector.widget = nil - self.borderY = 30 - self.borders = gui.newBorder(424, 30, 8) - - self.back = MenuBack() -end - -function OptionsMenu:update(dt) - self.back:update(dt) -end - --- MENU FUNCTION --- Functions that serve the handling of menus - -function OptionsMenu:addMenu(name, nobackbutton) - OptionMenu(self, name) -end - -function OptionsMenu:addSubMenu(name, fullname) - self.menusystem.menus["main"]:addSubMenu(name, fullname) -end - -function OptionsMenu:addDifficultyMenu() - Widgets.DiffSwitch(self, "difficulty", "hazardMakesKo", "Hazards can make KO") - Widgets.DiffSwitch(self, "difficulty", "playerKoChar", "Play KO characters on maps") - Widgets.DiffSwitch(self, "difficulty", "easierBattles", "Easier battles") - Widgets.DiffSwitch(self, "difficulty", "checkPointRegen", "Checkpoints heal you") - Widgets.DiffSwitch(self, "difficulty", "levelUpHeal", "Gaining a level heal") - Widgets.DiffSwitch(self, "difficulty", "allDamage", "Hazards damage everybody") -end - -function OptionsMenu:addPlayerMenus() - for i,v in ipairs(core.input.data) do - - self.menusystem.menus["inputs"]:addSubMenu("player" .. i, "Player " .. i, "inputs") - - local keyList = require "datas.keys" - for j, key in ipairs(keyList) do - Widgets.Key(self, i, key) - end - end - -end - -function OptionsMenu:addScene(submenu, scene, fullname) - Widgets.Dummy(self, submenu, fullname) -end - -function OptionsMenu:setLanguageMenu() - for i,v in ipairs(core.lang.data.available) do - Widgets.Lang(self, "langs", v) - end + OptionMenu() + MenuBack() end function OptionsMenu:changeKey(widget) - self.keyDetector.isActive = true self.keyDetector.widget = widget end function OptionsMenu:keypressed( key ) - if (self.keyDetector.isActive) then + if (self.keyDetector.widget ~= nil) then + self.assets:playSFX("mSelect") + self.gui.elements["optionMenu"].isVisible = true + self.gui:delayFocus("optionMenu", 0.1) self.keyDetector.widget:receiveKey( key ) - self.menusystem:activate() self.keyDetector.isActive = false + self.keyDetector.widget = nil end end -function OptionsMenu:draw() - love.graphics.setColor(1, 1, 1, 1) - love.graphics.rectangle("fill", 0, 0, 424, 240) - self.back:draw() - utils.graphics.resetColor() - self.assets.images["background"]:draw(0, 0) -end - -function OptionsMenu:drawOverTransition() - love.graphics.draw(self.borders, 0, self.borderY, 0, 1, -1) - love.graphics.draw(self.borders, 424, 240 - self.borderY, 0, -1, 1) - self.assets.fonts["small"]:draw("v" .. game.version, 424 - 44, 240 + 10 - self.borderY) -end - return OptionsMenu diff --git a/sonic-radiance.love/scenes/menus/options/menu.lua b/sonic-radiance.love/scenes/menus/options/menu.lua index 1ec8937..52614d1 100644 --- a/sonic-radiance.love/scenes/menus/options/menu.lua +++ b/sonic-radiance.love/scenes/menus/options/menu.lua @@ -1,15 +1,216 @@ -local RadianceListMenu = require "game.modules.menus.list" +local Parent = require "game.modules.gui.boxedmenu" +local MainMenu = Parent:extend() -local OptionMenu = RadianceListMenu.ListMenu:extend() -local WIDTH = 128+108 -local ITEMNUMBER = 6 +local TextMenuWidget = require "birb.modules.gui.textmenu.widgets.basic" +local ResolutionWidget = TextMenuWidget:extend() +local SwitchWidget = TextMenuWidget:extend() +local AudioWidget = TextMenuWidget:extend() +local DifficultyWidget = TextMenuWidget:extend() +local KeysWidget = TextMenuWidget:extend() -function OptionMenu:new(scene, name) - local w, h = math.floor(WIDTH), math.floor(16 * ITEMNUMBER) - local screenw, screenh = core.screen:getDimensions() - local x = (screenw/2) - (w/2) - local y = (screenh/2) - (h/2) - OptionMenu.super.new(self, scene, name, x, y, w, ITEMNUMBER, true) +local defTransitions = require "birb.modules.transitions" +local ConfirmDialog = require "game.modules.confirmdialog" + +local MENU_Y = 48 +local MENU_W = 424 / 1.5 +local MENU_ITEM_NUMBER = 8 + +function MainMenu:new() + local screenw, screenh = core.screen:getDimensions() + MainMenu.super.new(self, "optionMenu", screenw/2, MENU_Y, MENU_W, MENU_ITEM_NUMBER, true) + self.ox = MENU_W/2 + self:addVideoMenu() + self:addAudioMenu() + self:addDifficultyMenu() + self:addInputMenu() + self:switch("main") + self:addItem("Delete save", "left", function() self:deleteSave() end, "select", nil, {1, 0.3, 0.3}) + self:addItem("Exit", "left", function() self:exit() end, "back") + self:setCancelWidget() + self:getFocus() end -return OptionMenu +function MainMenu:addVideoMenu() + self:addSubmenu("video", "Videos", "main", true) + ResolutionWidget() + SwitchWidget("fullscreen", "Fullscreen") + SwitchWidget("border", "Borders") + SwitchWidget("vsync", "Vsync") +end + +function MainMenu:addAudioMenu() + self:addSubmenu("audio", "Audio", "main", true) + AudioWidget("music", "Music") + AudioWidget("sfx", "SFX") +end + +function MainMenu:addDifficultyMenu() + self:addSubmenu("difficulty", "Difficulty", "main", true) + DifficultyWidget("hazardMakesKo", "Hazards can make KO") + DifficultyWidget("playerKoChar", "Play KO characters on maps") + DifficultyWidget("easierBattles", "Easier battles") + DifficultyWidget("checkPointRegen", "Checkpoints heal you") + DifficultyWidget("levelUpHeal", "Gaining a level heal") + DifficultyWidget("allDamage", "Hazards damage everybody") +end + +function MainMenu:addInputMenu() + self:addSubmenu("input", "Input", "main", true) + local keyList = require "datas.keys" + for j, key in ipairs(keyList) do + KeysWidget(key) + end +end + +function MainMenu:exit() + core.screen:startTransition(defTransitions.default, defTransitions.default, + function() scenes.menus.main() end, 0, 0) +end + +function MainMenu:deleteSave() + local confirm = ConfirmDialog(core.scenemanager.currentScene, + "Do you want to delete your save ? \nYou won't be able to recover your data.", + function() + core.scenemanager:setStoredScene("mainmenu") + game:deleteCurrentSave() + core.screen:startTransition(defTransitions.default, defTransitions.circle, + function() scenes.menus.title(true) end, + 424/2, 240/2) + end) + confirm:setCancelChoice(2) +end + + +-- WIDGETS + +function ResolutionWidget:new() + ResolutionWidget.super.new(self, "optionMenu", core.lang:translate("options", "resolution"), "left") + self:addLabel(self:getSecondLabel(), "right") +end + +function ResolutionWidget:getSecondLabel() + return "x" .. core.options.data.video.resolution +end + +function ResolutionWidget:action() + core.options.data.video.resolution = ((core.options.data.video.resolution) % 3) + 1 + self:replaceLabel(2, self:getSecondLabel()) + core.screen:applySettings() + self:invalidateCanvas() + core.options:write() +end + +-- SWITCH + +function SwitchWidget:new(keyname, label) + self.keyname = keyname + SwitchWidget.super.new(self, "optionMenu", label, "left") + self:addLabel(self:getSecondLabel(), "right") +end + +function SwitchWidget:modifyKey() + core.options.data.video[self.keyname] = (core.options.data.video[self.keyname] == false) + core.screen:applySettings() +end + +function SwitchWidget:getKey() + return core.options.data.video[self.keyname] +end + +function SwitchWidget:getSecondLabel() + return core.lang:translate("commons", utils.math.either(self:getKey(), "true", "false")) +end + +function SwitchWidget:action() + self:modifyKey() + self:replaceLabel(2, self:getSecondLabel()) + core.options:write() + self:invalidateCanvas() +end + +-- AUDIO + +function AudioWidget:new(audiotype, label) + self.audiotype = audiotype + SwitchWidget.super.new(self, "optionMenu", label, "left") + self:addLabel(self:getSecondLabel(), "right") + self.order = 0 +end + +function AudioWidget:getSecondLabel() + return utils.math.numberToString(self:getVolume(), 3) .. "%" +end + +function AudioWidget:getVolume() + return core.options.data.audio[self.audiotype] +end + +function AudioWidget:setVolume(vol) + core.options.data.audio[self.audiotype] = utils.math.either(vol >= 0, vol, 100) +end + +function AudioWidget:action() + local value = self:getVolume() + self:setVolume(value - 20) + self:replaceLabel(2, self:getSecondLabel()) + self:invalidateCanvas() + --self.scene.assets.music:setVolume(core.options.data.audio.music / 100) + core.options:write() +end + +-- DIFFICULTY + +function DifficultyWidget:new(keyname, label) + self.keyname = keyname + SwitchWidget.super.new(self, "optionMenu", label, "left") + self:addLabel(self:getSecondLabel(), "right") +end + +function DifficultyWidget:modifyKey() + game.difficulty:toggle(self.keyname) +end + +function DifficultyWidget:getKey() + return game.difficulty:get(self.keyname) +end + +function DifficultyWidget:getSecondLabel() + return core.lang:translate("commons", utils.math.either(self:getKey(), "true", "false")) +end + +function DifficultyWidget:action() + self:modifyKey() + self:replaceLabel(2, self:getSecondLabel()) + game:write() + self:invalidateCanvas() +end + +-- KEYS + +function KeysWidget:new(key) + self.source = 1 + self.key = key + + SwitchWidget.super.new(self, "optionMenu", self.key, "left") + self:addLabel(self:getSecondLabel(), "right") + self.type = "navigate" +end + +function KeysWidget:getSecondLabel() + return core.input.data[self.source].keys[self.key] +end + +function KeysWidget:action() + self.menu:playSFX("navigate") + self.scene:changeKey(self) + self.menu.isVisible = false + self.menu:looseFocus() +end + +function KeysWidget:receiveKey( key ) + core.options:setInputKey(self.source, self.key, key) + self:replaceLabel(2, self:getSecondLabel()) + self:invalidateCanvas() +end + +return MainMenu diff --git a/sonic-radiance.love/scenes/menus/options/widgets.lua b/sonic-radiance.love/scenes/menus/options/widgets.lua deleted file mode 100644 index 9f7e763..0000000 --- a/sonic-radiance.love/scenes/menus/options/widgets.lua +++ /dev/null @@ -1,300 +0,0 @@ -local widgets = {} - -local Widget = require "birb.modules.menusystem.widgets" -local RadianceListMenu = require "game.modules.menus.list" - -local DoubleTextWidget = Widget.Text:extend() - -widgets.SubMenu = DoubleTextWidget:extend() -widgets.Dummy = RadianceListMenu.DualTextWidget:extend() -widgets.Exit = RadianceListMenu.DualTextWidget:extend() -widgets.Switch = RadianceListMenu.DualTextWidget:extend() -widgets.Resolution = RadianceListMenu.DualTextWidget:extend() -widgets.Lang = RadianceListMenu.DualTextWidget:extend() -widgets.PlayerSubMenu = RadianceListMenu.DualTextWidget:extend() -widgets.Key = RadianceListMenu.DualTextWidget:extend() -widgets.Audio = RadianceListMenu.DualTextWidget:extend() -widgets.Delete = RadianceListMenu.DualTextWidget:extend() -widgets.DiffSwitch = RadianceListMenu.DualTextWidget:extend() - -local defTransitions = require "birb.modules.transitions" -local ConfirmDialog = require "game.modules.confirmdialog" - --- BASIC WIDGETS --- Simple and reusables widgets - --- DoubleText widget : a two-side text widget - -function DoubleTextWidget:new(menu, font, label1, label2) - DoubleTextWidget.super.new(self, menu, font, label1) - self.label2 = label2 or "" -end - -function DoubleTextWidget:drawCanvas() - local w, h - w = math.floor(self.width) - h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - self.font:draw(self.label, 4, h, -1, "left") - self.font:draw(self.label2, w-4, h, -1, "right") -end - --- Submenu widget :: go to a submenu - -function widgets.SubMenu:new(scene, menu, newmenu, fullname, order, label2) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] - local label = core.lang:translate("options", fullname) - local label2 = label2 or ">" - self.newmenu = newmenu - widgets.SubMenu.super.new(self, widgetmenu, font, label, label2) - self.order = order or 0 -end - -function widgets.SubMenu:action() - self.scene.assets:playSFX("mSelect") - self.scene.menusystem:switchMenu(self.newmenu) -end - --- Dummy widget :: An empty widget to serve as a base for others - -function widgets.Dummy:new(scene, menu, fullname) - widgets.Dummy.super.new(self, scene, menu, fullname) -end - -function widgets.Dummy:action() - -- shoosh -end - --- Delete Save : delete the current Save - -function widgets.Delete:new(scene, menu) - widgets.Exit.super.new(self, scene, menu, "Delete save", "") - self.color = {1, 0.3, 0.3} -end - -function widgets.Delete:action() - self.scene.assets:playSFX("mSelect") - - local confirm = ConfirmDialog(self.scene, "Do you want to delete your save ? \nYou won't be able to recover your data.", - function() self:deleteSave() end) - confirm:setCancelChoice(2) -end - -function widgets.Delete:deleteSave() - core.scenemanager:setStoredScene("mainmenu") - game:deleteCurrentSave() - core.screen:startTransition(defTransitions.default, defTransitions.circle, - function() scenes.menus.title(true) end, - 424/2, 240/2) -end - --- Exit Widget : exit the examples - -function widgets.Exit:new(scene, menu) - widgets.Exit.super.new(self, scene, menu, "Exit", "") -end - -function widgets.Exit:action() - self.scene.assets:playSFX("mSelect") - core.scenemanager:setStoredScene("mainmenu") - core.screen:startTransition(defTransitions.default, defTransitions.default, - function() scenes.menus.main() end, - 0, 0) -end - --- VIDEO WIDGETS --- Handle graphical settings - --- Switch widget (One widget to handle graphical switch) - -function widgets.Switch:new(scene, menu, keyname, label) - self.keyname = keyname - local label2 = self:getLabel() - widgets.Switch.super.new(self, scene, menu, label, label2) - self.order = 0 -end - -function widgets.Switch:modifyKey() - --self.key = (self.key == false) - if self.keyname == "fullscreen" then - core.options.data.video.fullscreen = (core.options.data.video.fullscreen == false) - elseif self.keyname == "borders" then - core.options.data.video.border = (core.options.data.video.border == false) - elseif self.keyname == "vsync" then - core.options.data.video.vsync = (core.options.data.video.vsync == false) - end - core.screen:applySettings() -end - -function widgets.Switch:getKey() - if self.keyname == "fullscreen" then - self.key = core.options.data.video.fullscreen - elseif self.keyname == "borders" then - self.key = (core.options.data.video.border) - elseif self.keyname == "vsync" then - self.key = (core.options.data.video.vsync) - end -end - -function widgets.Switch:getLabel() - self:getKey() - local label = "" - if (self.key) then - label = "true" - else - label = "false" - end - - return core.lang:translate("commons", label) -end - -function widgets.Switch:action() - self:modifyKey() - self.scene.assets:playSFX("mSelect") - self.label2 = self:getLabel() - core.options:write() - self:invalidateCanvas() -end - --- Resolution Widget - -function widgets.Resolution:new(scene, menu) - local label = core.lang:translate("options", "resolution") - local label2 = self:getLabel() - widgets.Resolution.super.new(self, scene, menu, label, label2) -end - -function widgets.Resolution:getLabel() - return "x" .. core.options.data.video.resolution -end - -function widgets.Resolution:action() - if core.options.data.video.resolution == 3 then - core.options.data.video.resolution = 1 - else - core.options.data.video.resolution = core.options.data.video.resolution + 1 - end - self.label2 = self:getLabel() - core.screen:applySettings() - self.scene.assets:playSFX("mSelect") - self:invalidateCanvas() - core.options:write() -end - --- Key widgets -function widgets.Key:new(scene, sourceid, key) - self.source = sourceid - self.key = key - - local menu = "player" .. self.source - local label = self.key - local label2 = self:getLabel() - - widgets.Key.super.new(self, scene, menu, label, label2) - self.order = 0 -end - -function widgets.Key:getLabel() - return core.input.data[self.source].keys[self.key] -end - -function widgets.Key:action() - self.scene.assets:playSFX("navigate") - self.scene:changeKey(self) - self.scene.menusystem:deactivate() -end - -function widgets.Key:receiveKey( key ) - self.scene.assets:playSFX("mSelect") - core.options:setInputKey(self.source, self.key, key) - self.label2 = self:getLabel() - self:invalidateCanvas() -end - --- AUDIO FUNCTIONS --- Sounds/Music functions - -function widgets.Audio:new(scene, menu, audiotype, label) - self.audiotype = audiotype - - local label2 = self:getLabel() - widgets.Audio.super.new(self, scene, menu, label, label2) - self.order = 0 -end - -function widgets.Audio:getLabel() - local value = self:getVolume() - string = utils.math.numberToString(value, 3) - local label = string .. "%" - - return label -end - -function widgets.Audio:getVolume() - if (self.audiotype == "sfx") then - return core.options.data.audio.sfx - else - return core.options.data.audio.music - end -end - -function widgets.Audio:setVolume(vol) - if (vol < 0) then vol = 100 end - - if (self.audiotype == "sfx") then - core.options.data.audio.sfx = vol - else - core.options.data.audio.music = vol - end - - self.label2 = self:getLabel() - self:invalidateCanvas() -end - -function widgets.Audio:action() - local value = self:getVolume() - self:setVolume(value - 20) - self.scene.assets:playSFX("mSelect") - --self.scene.assets.music:setVolume(core.options.data.audio.music / 100) - core.options:write() -end - --- Switch widget (One widget to handle graphical switch) - -function widgets.DiffSwitch:new(scene, menu, keyname, label) - self.keyname = keyname - local label2 = self:getLabel() - widgets.Switch.super.new(self, scene, menu, label, label2) - self.order = 0 -end - -function widgets.DiffSwitch:modifyKey() - game.difficulty:toggle(self.keyname) -end - -function widgets.DiffSwitch:getKey() - return game.difficulty:get(self.keyname) -end - -function widgets.DiffSwitch:getLabel() - self.key = self:getKey() - local label = "" - if (self.key) then - label = "true" - else - label = "false" - end - - return core.lang:translate("commons", label) -end - -function widgets.DiffSwitch:action() - self:modifyKey() - self.scene.assets:playSFX("mSelect") - self.label2 = self:getLabel() - game:write() - self:invalidateCanvas() -end - -return widgets -- 2.30.2 From 35764021af82aa9f86e265bca1cc235fde5cf643 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 21:00:39 +0200 Subject: [PATCH 058/102] improvement: port the main menu to gui --- .../scenes/menus/mainmenu/init.lua | 151 +----------------- .../scenes/menus/mainmenu/menu.lua | 123 +++----------- 2 files changed, 27 insertions(+), 247 deletions(-) diff --git a/sonic-radiance.love/scenes/menus/mainmenu/init.lua b/sonic-radiance.love/scenes/menus/mainmenu/init.lua index 1c031bb..5ab75d2 100644 --- a/sonic-radiance.love/scenes/menus/mainmenu/init.lua +++ b/sonic-radiance.love/scenes/menus/mainmenu/init.lua @@ -1,158 +1,15 @@ local Scene = require "game.scenes" -local menu = require "scenes.menus.mainmenu.menu" local DebugMenu = Scene:extend() -local panels = require "scenes.menus.mainmenu.infopanel" -local gui = require "game.modules.gui" local MenuBack = require "game.modules.gui.menuback" -local TweenManager = require "birb.classes.time" +local MainMenu = require "scenes.menus.mainmenu.menu" function DebugMenu:new() - DebugMenu.super.new(self) - menu.commons.MainMenu(self, "BaseMenu") - menu.StartGameWidget(self, "BaseMenu") - menu.commons.SceneWidget(self, "BaseMenu", scenes.menus.options, "Options") - self:buildDebugMenu() - menu.TitleWidget(self, "BaseMenu") - self.menusystem.menus["BaseMenu"]:setCancelWidget() - menu.ExitWidget(self, "BaseMenu") - - self.menusystem.menus["BaseMenu"]:finalize() - self.menusystem:activate() - self.menusystem:switchMenu("BaseMenu") - self.menusystem:setSoundFromSceneAssets("mBeep") - - self.panel = panels.Gamedata() - - self.borderY = 30 - self.borders = gui.newBorder(424, 30, 8) - self.backImage = love.graphics.newImage("assets/artworks/back.png") - - self.back = MenuBack() - self.tweens = TweenManager(self) -end - -function DebugMenu:buildDebugMenu() - if (core.debug.active) then - self:addSubMenu("debug", "BaseMenu", "Debug Menu") - self:buildBattleMenu() - --self:buildOverworldMenu() - self:buildSaveMenu() - self:buildOtherMenu() - end -end - -function DebugMenu:buildOverworldMenu() - self:addSubMenu("overworld", "debug", "Overworld") - menu.commons.SceneWidget(self, "overworld", scenes.overworld, "Launch Overworld") -end - -function DebugMenu:buildBattleMenu() - self:addSubMenu("combat", "debug", "Battle System") - self:addSubMenu("launchBattle", "combat", "Launch Battle") - - local listCat = core.datas:getCategories("battles") - for i,battleCat in ipairs(listCat) do - self:addBattles(battleCat) - end - - menu.commons.SceneWidget(self, "combat", scenes.menus.debug.battleBack, "Background Viewer") - menu.commons.SceneWidget(self, "combat", scenes.menus.debug.animation, "Animation Viewer") - menu.commons.SceneWidget(self, "combat", scenes.menus.debug.choregraphy, "Ennemies' Action Viewer") -end - -function DebugMenu:addBattles(battleCat) - local menuName = "b_" .. battleCat - self:addSubMenu(menuName, "launchBattle", battleCat) - - for i,battleName in ipairs(core.datas:getFromCategory("battles", battleCat)) do - local data = core.datas:get("battles", battleName) - menu.commons.SceneWidget(self, menuName, scenes.cbs, "Launch " .. battleName, data) - end -end - -function DebugMenu:buildSaveMenu() - self:addSubMenu("save", "debug", "Save System", panels.Gamedata, nil) - self:addSubMenu("characters", "save", "Characters", panels.Gamedata, nil) - self:addSubMenu("team", "save", "Team Formation", panels.Team, nil) - menu.ChangeLeaderWidget(self, "team") - for name, data in pairs(game.characters.list) do - self:addCharacterMenu(name, data) - menu.AddRemoveWidget(self, "team", data) - end - - self:addInventory() - - self:addSubMenu("load", "save", "Load Saves") - for i=1, game.slotNumber do - menu.LoadWidget(self, "load", i) - end - menu.SaveWidget(self, "save") -end - -function DebugMenu:addCharacterMenu(name, data) - self:addSubMenu(name, "characters", data.fullname, panels.Character, data) - menu.LevelUpWidget(self, name, data) -end - -function DebugMenu:addInventory() - self:addSubMenu("inventory", "save", "Inventory") - for i,pocket in ipairs(game.loot.inventory) do - self:addSubMenu(pocket.name, "inventory", pocket.fullname) - for j, item in ipairs(core.datas:getFromCategory("items", pocket.name)) do - menu.ItemWidget(self, pocket.name, core.datas:get("items", item)) - end - end -end - -function DebugMenu:buildOtherMenu() - self:addSubMenu("other", "debug", "Other gameplay") - self:addSubMenu("battle", "other", "Sonic Battle Maps") - local mapList = require "datas.gamedata.maps.battle" - for i, name in ipairs(mapList) do - local mapData = require("datas.gamedata.maps.battle." .. name) - local trueName = mapData.name - menu.commons.SceneWidget(self, "battle", scenes.test, trueName, name) - end - - menu.commons.SceneWidget(self, "other", scenes.test2, "Shadow Shot Maps") -end - - -function DebugMenu:update(dt) - if (love.keyboard.isDown("space") and (not self.menusystem.isActive)) then - self.menusystem:activate() - end - self.back:update(dt) - self.tweens:update(dt) -end - -function DebugMenu:addSubMenu(submenu, parent, name, panel, panelArgument) - local parent = parent or "BaseMenu" - self.menusystem.menus[parent]:addSubMenu(submenu, name) - if (panel ~= nil) then - --self.menusystem.menus[submenu]:setPanel(panel, panelArgument) - end -end - -function DebugMenu:draw() - love.graphics.setColor(1, 1, 1, 1) - love.graphics.rectangle("fill", 0, 0, 424, 240) - self.back:draw() - utils.graphics.resetColor() - love.graphics.draw(self.backImage, 0, 0) - - if (self.menusystem.isActive) then - self.panel:draw(240, 48) - end -end - -function DebugMenu:drawOverTransition() - love.graphics.draw(self.borders, 0, self.borderY, 0, 1, -1) - love.graphics.draw(self.borders, 424, 240 - self.borderY, 0, -1, 1) - self.assets.fonts["small"]:draw("v" .. game.version, 424 - 44, 240 + 10 - self.borderY) + DebugMenu.super.new(self, true, true) + MainMenu() + MenuBack() end return DebugMenu; diff --git a/sonic-radiance.love/scenes/menus/mainmenu/menu.lua b/sonic-radiance.love/scenes/menus/mainmenu/menu.lua index 82f8e1c..d5d2f40 100644 --- a/sonic-radiance.love/scenes/menus/mainmenu/menu.lua +++ b/sonic-radiance.love/scenes/menus/mainmenu/menu.lua @@ -1,115 +1,38 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.fancy" +local Parent = require "game.modules.gui.fancymenu" +local MainMenu = Parent:extend() local defTransitions = require "birb.modules.transitions" local radTransitions = require "game.modules.transitions" -local menu = {} -menu.commons = commons -menu.ExitWidget = listMenu.BaseWidget:extend() -menu.SaveWidget = listMenu.BaseWidget:extend() -menu.LoadWidget = listMenu.BaseWidget:extend() -menu.LevelUpWidget = listMenu.BaseWidget:extend() -menu.AddRemoveWidget = listMenu.BaseWidget:extend() -menu.ChangeLeaderWidget = listMenu.BaseWidget:extend() -menu.ItemWidget = listMenu.BaseWidget:extend() -menu.TitleWidget = listMenu.BaseWidget:extend() -menu.StartGameWidget = listMenu.BaseWidget:extend() +local MENU_X, MENU_Y = 24, 48 +local MENU_W = 424/3 +local MENU_ITEM_NUMBER = 8 - --- TitleWidget -function menu.StartGameWidget:new(scene, menuName) - local str = "Start game" - if (game.exists) then - str = "Continue game" - end - menu.TitleWidget.super.new(self, scene, menuName, str, "") +function MainMenu:new() + MainMenu.super.new(self, "mainmenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, false) + self:addItem("Launch game", "left", function() self:launchGame() end) + self:addItem("Options", "left", function() self:launchOptions() end) + self:addItem("Return to title", "left", function() self:returnToTitle() end, "back") + self:setCancelWidget() + self:addItem("Exit game", "left", function() self:exitGame() end) + self:getFocus() end -function menu.StartGameWidget:action() - self.scene.assets:playSFX("mSelect") - core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scenes.overworld() end, 424/2, 240/2) - self.scene.tweens:newTween(0, 0.5, {borderY = 0}, "inOutQuart") +function MainMenu:launchGame() + core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scenes.overworld() end, 424/2, 240/2) + core.scenemanager.currentScene:hideOverlay() end --- TitleWidget -function menu.TitleWidget:new(scene, menuName) - menu.TitleWidget.super.new(self, scene, menuName, "Return to Title", "") +function MainMenu:launchOptions() + core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2) end -function menu.TitleWidget:action() - self.scene.assets:playSFX("mBack") - core.screen:startTransition(defTransitions.circle, radTransitions.borders, function() scenes.menus.title(true) end, 424/2, 240/2) +function MainMenu:returnToTitle() + core.screen:startTransition(defTransitions.circle, radTransitions.borders, function() scenes.menus.title(true) end, 424/2, 240/2) end --- ExitWidget -function menu.ExitWidget:new(scene, menuName) - menu.ExitWidget.super.new(self, scene, menuName, "Exit", "") +function MainMenu:exitGame() + love.event.quit("000") end -function menu.ExitWidget:action() - self.scene.assets:playSFX("mSelect") - love.event.quit("000") -end - --- Save game -function menu.SaveWidget:new(scene, menuName) - menu.SaveWidget.super.new(self, scene, menuName, "Save game", "") -end - -function menu.SaveWidget:action() - game:write() -end - --- Save game -function menu.LoadWidget:new(scene, menuName, slot) - menu.LoadWidget.super.new(self, scene, menuName, "Load file ", slot) - self.slot = slot -end - -function menu.LoadWidget:action() - game:read(self.slot) -end - --- Level Up -function menu.LevelUpWidget:new(scene, menuName, character) - menu.LevelUpWidget.super.new(self, scene, menuName, "Levelup to", character.level + 1) - self.character = character -end - -function menu.LevelUpWidget:action() - self.character:levelUp() -end - --- Add Remove Widget -function menu.AddRemoveWidget:new(scene, menuName, character) - menu.AddRemoveWidget.super.new(self, scene, menuName, "Add/Remove", character.name) - self.character = character -end - -function menu.AddRemoveWidget:action() - game.characters:addOrRemoveToTeam(self.character.simplename) -end - ---Change Team Leader -function menu.ChangeLeaderWidget:new(scene, menuName) - menu.ChangeLeaderWidget.super.new(self, scene, menuName, "Change active character", "") -end - -function menu.ChangeLeaderWidget:action() - game.characters:setActiveCharacter(1) -end - --- ItemWidget -function menu.ItemWidget:new(scene, menuName, itemdata) - menu.ItemWidget.super.new(self, scene, menuName, itemdata.fullname, "") - self.category = menuName - self.itemName = itemdata.name -end - -function menu.ItemWidget:action() - game.loot:addItem(self.category, self.itemName, 1) -end - - -return menu +return MainMenu -- 2.30.2 From a6ff9b2ca2751c3ad7fc2e7169909da86d9913ec Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 21:18:57 +0200 Subject: [PATCH 059/102] improvement: make messages part of RadianceScene --- sonic-radiance.love/game/scenes/init.lua | 4 ++++ sonic-radiance.love/scenes/overworld/init.lua | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua index c40517f..f56775c 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -24,6 +24,10 @@ function RadianceScene:hideOverlay() self.gui:hideScreen("overlay") end +function RadianceScene:showMessage(message) + self.gui.elements["messageQueue"]:addMessage(message) +end + function RadianceScene:showOverlay(darken) self.gui:showScreen("overlay") if (darken) then diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 67f1648..8337da9 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -60,8 +60,6 @@ function OverWorld:new(area, playerx, playery) self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad") self.timeBorder = -10 - self.messages = MessageQueue(self) - self.isPlaying = "" self.events = EventManager(self) @@ -93,10 +91,6 @@ function OverWorld:endEvent() self.canPause = true end -function OverWorld:showMessage(message) - self.messages:addMessage(message) -end - function OverWorld:registerScreen(screen) if (self.currentScreen ~= nil) then self.currentScreen:quit() @@ -108,7 +102,6 @@ function OverWorld:update(dt) local keys = self:getKeys(1) self.tweens:update(dt) self.events:update(dt) - self.messages:update(dt) if (self.world.isActive) then self.charsetManager:update(dt) @@ -183,8 +176,6 @@ end function OverWorld:draw() self.events:draw() - - self.messages:draw() self:drawScreenBottomLayer() end -- 2.30.2 From bd2ec708a37742fa1062344eb8ba69988f20fa54 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 21:51:32 +0200 Subject: [PATCH 060/102] improvement: use the scene message queue --- .../scenes/battlesystem/fighters/character/actions/flee.lua | 6 +++--- .../scenes/battlesystem/gui/menus/widgets.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/flee.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/flee.lua index dea1186..96b605e 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/flee.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/flee.lua @@ -15,17 +15,17 @@ function FleeAction:startAction() local stats = self.fighter.abstract.stats if (self.fighter.abstract.name == "shadow") then - self.fighter.turns.hud:showMessage("You won't flee the battle") + self.fighter.turnSystem.scene:showMessage("You won't flee the battle") self:finishAction() return end local chanceToFlee = self.fighter.turnSystem:getChanceTooFlee(self.fighter:getStat(STATS.SPEED)) if (math.random(100) < chanceToFlee) then - self.fighter.turnSystem.hud:showMessage("You flee the battle") + self.fighter.turnSystem.scene:showMessage("You flee the battle") self.fighter.turnSystem:fleeBattle() else - self.fighter.turnSystem.hud:showMessage("You failed to flee the battle") + self.fighter.turnSystem.scene:showMessage("You failed to flee the battle") self:finishAction() end diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua index 441f494..7510b0a 100644 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua +++ b/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua @@ -134,7 +134,7 @@ function widgets.SkillWidget:sendCharacterData() core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist") self.character:doNothing() self.assets.sfx["mError"]:play() - self.scene.turns.hud:showMessage("You haven't enough PP!") + self.scene:showMessage("You haven't enough PP!") end end -- 2.30.2 From 30389a2655f29f21e30da5542271a71de7e5486f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:06:15 +0200 Subject: [PATCH 061/102] chore: initial cbs scene clean-up --- sonic-radiance.love/scenes/battlesystem/init.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 6a7a474..91bd6e3 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -17,11 +17,7 @@ function BattleSystem:new(battleData) self.assets:batchImport("assets.battle") self:playMusic(battleData.music) - self:initManagers(battleData) - - self:register() - self:startBattle() self.screen = nil @@ -86,8 +82,7 @@ function BattleSystem:update(dt) end function BattleSystem:draw() - self.world:draw() - self.turns:draw() + BattleSystem.super.draw(self) if (self.screen ~= nil) then self.screen:draw() end -- 2.30.2 From 14a7364c434584250e7cf9741966d585101eb8bb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:06:59 +0200 Subject: [PATCH 062/102] improvement: port to common game over --- sonic-radiance.love/scenes/battlesystem/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 91bd6e3..347e6c1 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -7,7 +7,7 @@ local MenuSystem = require "scenes.battlesystem.gui.menus.controller" local Turns = require "scenes.battlesystem.turns" local VictoryScreen = require "scenes.battlesystem.gui.screens.victory" -local GameOverScreen = require "scenes.battlesystem.gui.screens.gameover" +local GameOverScreen = require "game.modules.gui.gameover" local TweenManager = require "birb.classes.time" @@ -62,7 +62,7 @@ function BattleSystem:returnToOverworld(isFleeing) end function BattleSystem:looseBattle() - self.screen = GameOverScreen(self) + GameOverScreen(self) end function BattleSystem:haveMenus() -- 2.30.2 From 2932a7d85a0ae03a9d4e490d7cd4c139851bdf0b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:26:59 +0200 Subject: [PATCH 063/102] improvement: port the cbs menus and gui Make them handled by a single screen, removing a lot of dispersed drawing code in the turns handler --- .../game/modules/gui/bosshpbar.lua | 30 ---- .../game/modules/gui/statusbar.lua | 65 ------- .../battlesystem/fighters/character/init.lua | 27 +-- .../scenes/battlesystem/fighters/ennemies.lua | 7 +- .../battlesystem/fighters/ennemy/init.lua | 18 +- .../scenes/battlesystem/fighters/parent.lua | 8 +- .../scenes/battlesystem/fighters/player.lua | 7 - .../scenes/battlesystem/gui/hud.lua | 98 ----------- .../gui/hudelements/bosshpbar.lua | 30 ++++ .../battlesystem/gui/hudelements/menu.lua | 86 +++++++++ .../gui/hudelements/statutbar.lua | 68 ++++++++ .../battlesystem/gui/hudelements/turnbar.lua | 27 +++ .../scenes/battlesystem/gui/init.lua | 42 +++++ .../battlesystem/gui/menus/battlemenu.lua | 19 -- .../battlesystem/gui/menus/controller.lua | 72 -------- .../scenes/battlesystem/gui/menus/widgets.lua | 164 ------------------ .../scenes/battlesystem/init.lua | 11 +- .../scenes/battlesystem/turns.lua | 21 +-- 18 files changed, 277 insertions(+), 523 deletions(-) delete mode 100644 sonic-radiance.love/game/modules/gui/bosshpbar.lua delete mode 100644 sonic-radiance.love/game/modules/gui/statusbar.lua delete mode 100644 sonic-radiance.love/scenes/battlesystem/gui/hud.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/init.lua delete mode 100644 sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua delete mode 100644 sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua delete mode 100644 sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua diff --git a/sonic-radiance.love/game/modules/gui/bosshpbar.lua b/sonic-radiance.love/game/modules/gui/bosshpbar.lua deleted file mode 100644 index f421f28..0000000 --- a/sonic-radiance.love/game/modules/gui/bosshpbar.lua +++ /dev/null @@ -1,30 +0,0 @@ -local BossHpBar = Object:extend() - -local TweenManager = require "birb.classes.time" -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -function BossHpBar:new(hp) - self.tweens = TweenManager(self) - self.hp = hp - self.baseHP = hp - self.hpbar = ComplexHPBar(120) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) - - self.bossTexture = love.graphics.newImage("assets/gui/strings/boss.png") -end - -function BossHpBar:setHP(newHP) - self.tweens:newTween(0, 0.1, {hp = newHP}, 'inCubic') -end - -function BossHpBar:update(dt) - self.tweens:update(dt) -end - -function BossHpBar:draw(x, y) - self.hpbar:draw(x, y, self.hp / self.baseHP) - love.graphics.draw(self.bossTexture, x + 98, y + 10) -end - -return BossHpBar \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/gui/statusbar.lua b/sonic-radiance.love/game/modules/gui/statusbar.lua deleted file mode 100644 index 947d717..0000000 --- a/sonic-radiance.love/game/modules/gui/statusbar.lua +++ /dev/null @@ -1,65 +0,0 @@ -local StatusBar = Object:extend() -local TweenManager = require "birb.classes.time" - -local gui = require "game.modules.gui" - -local Emblem = require "game.modules.gui.emblem" -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -function StatusBar:new(abstract, scene) - self.assets = scene.assets - self.abstract = abstract - - self.emblem = Emblem(abstract, scene) - - self.hp = self.abstract.hp - self.pp = self.abstract.pp - self.stats = self.abstract:getStats() - - self.hpbar = ComplexHPBar(58) - self.ppbar = ComplexHPBar(58) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) - self.ppbar:setColorForeground(0, 248/255, 248/255, 1) - self.ppbar:setColorBackground(0, 54/255, 229/255) - - self.tweens = TweenManager(self) -end - -function StatusBar:update(dt) - self.tweens:update(dt) -end - -function StatusBar:updateHP() - self.tweens:newTween(0, 0.3, {hp = self.abstract.hp}, 'linear') -end - -function StatusBar:updatePP() - self.tweens:newTween(0, 0.3, {pp = self.abstract.pp}, 'linear') -end - -function StatusBar:draw(x, y) - self.emblem:drawBackground(x, y) - self:drawStatusArea(x+10, y-8) - self.emblem:drawForeground(x, y) -end - -function StatusBar:drawStatusArea(x, y) -self.assets.images["statusbar"]:draw(x, y) - -local hpmax = self.stats:get(self.stats.HPMAX) -local ppmax = self.stats:get(self.stats.PPMAX) - -self.assets.fonts["hudnbrs_small"]:set() -self.hpbar:drawWithLabels(x + 6, y + 9, self.hp, hpmax) -self.ppbar:drawWithLabels(x + 18, y + 21, self.pp, ppmax) - -local lvl = self.abstract.level - -if lvl < 100 then - lvl = "0" .. lvl -end - love.graphics.print(lvl, x+42, y+1) -end - -return StatusBar diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua index 120dbc1..2990b71 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua @@ -1,28 +1,21 @@ local FighterParent = require "scenes.battlesystem.fighters.fighter" local HeroFighter = FighterParent:extend() -local StatusBar = require "game.modules.gui.statusbar" local SelectionSystem = require "scenes.battlesystem.fighters.character.selection" local actionList = require "scenes.battlesystem.fighters.character.actions" local HEROES_LINE = 2; -local HUDSIZE = 91 function HeroFighter:new(owner, character, id) self.name = character self.super.new(self, owner, true, id) - self.statusbar = StatusBar(self.abstract, self.turnSystem.scene) self:initVoices() self.selection = nil self.exp = self.abstract.exp end -function HeroFighter:updateAssets(dt) - self.statusbar:update(dt) -end - function HeroFighter:update(dt) HeroFighter.super.update(self, dt) if (self.selection ~= nil) then @@ -47,7 +40,7 @@ function HeroFighter:startAction() core.debug:print("cbs/heroFighter", "launching the action menu") self.action = nil self:talk("turnstart") - self.turnSystem.scene.menu:set( self ) + self.turnSystem.scene.gui.screens["hud"]:buildMenu( self ) end function HeroFighter:endAction() @@ -102,17 +95,19 @@ function HeroFighter:receiveTarget(target) end function HeroFighter:goBackToMenu() - self.owner.turnSystem.scene.menusystem:activate() + self.turnSystem.scene.gui:setFocus("battleMenu") self.selection = nil end -- LIFE functions function HeroFighter:updatePP() - self.statusbar:updatePP() + local elem = self.turnSystem.scene.gui:getElement(self.abstract.name .. "StatutBar") + elem:updatePP() end function HeroFighter:updateHP() - self.statusbar:updateHP() + local elem = self.turnSystem.scene.gui:getElement(self.abstract.name .. "StatutBar") + elem:updateHP() end -- VOICE SYSTEM @@ -139,14 +134,4 @@ function HeroFighter:drawIcon(x, y) self.assets.tileset["charicons"]:drawTile(iconID, x, y) end -function HeroFighter:drawHUD() - local boxSize = 424 / 4 - local x = (self.id-0.5)*boxSize - local y = self.turnSystem.hud:getPlayerHUDPosition() - self.statusbar:draw(x - HUDSIZE/2, y) - if (self.action ~= nil) then - self.action:draw() - end -end - return HeroFighter diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua b/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua index 2b9f5ce..bb6a335 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua @@ -46,12 +46,7 @@ function EnnemyController:addBoss(ennData) boss:setCheapEffect(ennData.cheapEffect) self.turnSystem.canFleeBattle = false self:add(boss) -end - -function EnnemyController:draw() - for i, villain in ipairs(self.list) do - villain:drawHUD() - end + boss:createHPBar() end return EnnemyController diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua b/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua index 932026a..100479a 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua @@ -2,11 +2,10 @@ local FighterParent = require "scenes.battlesystem.fighters.fighter" local VillainFighter = FighterParent:extend() local SimpleHPBar = require "game.modules.gui.simplehpbar" -local BossHPBar = require "game.modules.gui.bosshpbar" +local BossHPBar = require "scenes.battlesystem.gui.hudelements.bosshpbar" local EnnemyAction = require "scenes.battlesystem.fighters.ennemy.action" local behaviourList = require "scenes.battlesystem.fighters.ennemy.behaviours" - local POSITIONS = {1, 3, 5} local ENNEMY_LINE = 11; @@ -25,11 +24,6 @@ end function VillainFighter:updateAssets(dt) self.hpbar:update(dt) - if (self.bossHpBar ~= nil) then - self.bossHpBar:update(dt) - else - self.bossHpBar = BossHPBar(self.abstract.hp) - end end function VillainFighter:getAbstract() @@ -90,7 +84,9 @@ end function VillainFighter:setHP(value, relative) VillainFighter.super.setHP(self, value, relative) self.hpbar:setHP(self.abstract.hp) - self.bossHpBar:setHP(self.abstract.hp) + if (self.bossHpBar ~= nil) then + self.bossHpBar:setHP(self.abstract.hp) + end end -- DRAW FUNCTIONS @@ -107,10 +103,8 @@ function VillainFighter:drawOversprite(x, y) end end -function VillainFighter:drawHUD() - if (self.isBoss and self.bossHpBar ~= nil) then - self.bossHpBar:draw(280, 28) - end +function VillainFighter:createHPBar() + self.bossHpBar = BossHPBar(self.abstract.hp) end return VillainFighter diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua index 7ac8d5f..f78bc35 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua @@ -10,6 +10,10 @@ function FighterControllerParent:get(id) return self.list[id] end +function FighterControllerParent:getList() + return self.list +end + function FighterControllerParent:add(fighter) table.insert(self.list, fighter) end @@ -73,10 +77,6 @@ function FighterControllerParent:putActions(actionList) end end -function FighterControllerParent:draw() - --Aucun dessin par defaut, ils sont géré différements -end - function FighterControllerParent:removeFighter(fighterToRemove) -- remove the actor from the battler liste for i, fighter in ipairs(self.list) do diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/player.lua b/sonic-radiance.love/scenes/battlesystem/fighters/player.lua index 6094d04..a569d21 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/player.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/player.lua @@ -14,17 +14,10 @@ function HeroFighterController:initHeroes() end end - function HeroFighterController:fleeBattle() for i, hero in ipairs(self.list) do hero.actor:flee() end end -function HeroFighterController:draw() - for i, hero in ipairs(self.list) do - hero:drawHUD() - end -end - return HeroFighterController diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hud.lua b/sonic-radiance.love/scenes/battlesystem/gui/hud.lua deleted file mode 100644 index 47d91a3..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/hud.lua +++ /dev/null @@ -1,98 +0,0 @@ -local HUD = Object:extend() - -local gui = require "game.modules.gui" -local TweenManager = require "birb.classes.time" -local MessageQueue = require "game.modules.messagequeue" - -local PLAYER_HUD_HIDDEN = 240+64 -local PLAYER_HUD_VISIBLE = 240-44 -local PLAYER_MESSAGE = 240 - 24 - -function HUD:new(turns) - self.turns = turns - self.scene = turns.scene - self.world = self.scene.world - self.assets = self.scene.assets - - self.frame = gui.newBorder(424, 30, 4) - self.tweens = TweenManager(self) - - self.playerHUDPosition = PLAYER_HUD_HIDDEN - self.battlerCursor = self.turns.turns.current - - self.messages = MessageQueue(self.scene) - - self.message = "Test de message" - self.messageOpacity = 0 -end - -function HUD:showMessage(message) - self.messages:addMessage(message) -end - -function HUD:update(dt) - self.tweens:update(dt) - self.messages:update(dt) -end - -function HUD:movePlayerHUD(beginBattle) - if (beginBattle) then - self.tweens:newTween(0, 0.4, {playerHUDPosition = PLAYER_HUD_VISIBLE}, 'inCubic') - else - self.tweens:newTween(0, 0.4, {playerHUDPosition = PLAYER_HUD_HIDDEN}, 'inCubic') - end -end - -function HUD:moveBattleCursor(moveCursorTo) - self.tweens:newTween(0, 0.2, {battlerCursor = moveCursorTo}, 'inCubic') -end - -function HUD:getPlayerHUDPosition() - return self.playerHUDPosition -end - -function HUD:draw() - local x, y = 4, 5 - - love.graphics.draw(self.frame, 0, 24, 0, 1, -1) - self.assets.images["hudturn"]:draw(x, y) - self.assets.fonts["hudnbrs"]:set() - local turnnbr = self.turns.turns.number - if (turnnbr < 10) then - turnnbr = "0" .. turnnbr - end - love.graphics.print(turnnbr, x + 33, y + 1) - - for i, action in ipairs(self.turns.actionList) do - if action.fighter:canFight() then - action.fighter:drawIcon(76 + (i-1)*(20), 5) - else - self:drawEmptyIcon(76 + (i-1)*(20), 5) - end - end - local cursorx = (self.battlerCursor-1) * 20 + 76 - - if #self.turns.actionList > 0 then - self.assets.images["menucursor"]:draw(cursorx, 5, math.rad(90), 1, 1, 4, 16) - end - - self.messages:draw() - love.graphics.setColor(0,0,0, 0.5 * self.messageOpacity) - love.graphics.rectangle("fill", 0, PLAYER_MESSAGE, 424, 16) - if (self.messageOpacity > 0) then - self.assets.fonts["small"]:setColor(1,1,1, self.messageOpacity) - self.assets.fonts["small"]:draw(self.message, 424/2, PLAYER_MESSAGE - 1, -1, "center") - self.assets.fonts["small"]:setColor(1,1,1, 1) - end - utils.graphics.resetColor() -end - -function HUD:drawEmptyIcon(x, y) - local outlineLight = 0.15 - love.graphics.circle("fill", x + 8, y + 8, 2, 8) - love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1) - love.graphics.circle("line", x + 8, y + 8, 2, 8) - utils.graphics.resetColor() -end - -return HUD diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua new file mode 100644 index 0000000..1485650 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua @@ -0,0 +1,30 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local BossHpBar = GuiElement:extend() + +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local POS_X, POS_Y = 280, 28 + +function BossHpBar:new(hp) + self.hp = hp + self.baseHP = hp + self.hpbar = ComplexHPBar(120) + self.hpbar:setColorForeground(248/255, 160/255, 0, 1) + self.hpbar:setColorBackground(112/255, 0, 0) + + self.bossTexture = love.graphics.newImage("assets/gui/strings/boss.png") + local w, h = self.bossTexture:getDimensions() + + BossHpBar.super.new(self, "BossHPBar", POS_X, POS_Y, w, h) +end + +function BossHpBar:setHP(newHP) + self:newTween(0, 0.1, {hp = newHP}, 'inCubic') +end + +function BossHpBar:draw() + self.hpbar:draw(self.x, self.y, self.hp / self.baseHP) + love.graphics.draw(self.bossTexture, self.x + 98, self.y + 10) +end + +return BossHpBar \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua new file mode 100644 index 0000000..0be7f2b --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua @@ -0,0 +1,86 @@ +local Parent = require "game.modules.gui.fancymenu" +local BattleMenu = Parent:extend() + +local defTransitions = require "birb.modules.transitions" +local radTransitions = require "game.modules.transitions" + +local MENU_X, MENU_Y = 88, 72 +local MENU_W = 180-32 +local MENU_ITEM_NUMBER = 6 + +function BattleMenu:new() + BattleMenu.super.new(self, "battleMenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, true) + self.isVisible = false +end + +function BattleMenu:rebuild(character) + self:clear() + self:addItem("Attack", "left", function() self:doAction(character, "attack") end) + self:generateSubmenu("skills", "Skill", "main", character.abstract.skills, function(data) return self:createSkillWidget(character, data) end, true) + self:createItemMenus(character) + self:switch("main") + self:addItem("Defend", "left", function() self:doAction(character, "defend") end) + self:addItem("Flee", "left", function() self:doAction(character, "flee") end) + self:getFocus() + self.canvas.needRedraw = true +end + +function BattleMenu:createItemMenus(character) + self:addSubmenu("items", "Items", "main", true) + for i,pocket in ipairs(game.loot.inventory) do + if (pocket.inBattle) then + self:generateSubmenu(pocket.name, pocket.fullname, "items", pocket.list, + function(itemInBag) + return self:createItemWidget(character, pocket.name, itemInBag) + end, true) + end + end +end + +function BattleMenu:createSkillWidget(character, skill) + local data = core.datas:get("skills", skill.name) + local isOk = (data.cost <= character.abstract.pp) + + local cost = {utils.math.numberToString(data.cost or 0, 2), "right"} + local color = utils.math.either(isOk, {1, 1, 1}, {1, 0.3, 0.3}) + local sfx = utils.math.either(isOk, "select", "error") + local func = function() self:doSkill(character, skill.name, isOk) end + + --text, position, func, type, additionnalItems, color + return character.abstract:getSkillName(skill.name), "left", func, sfx, {cost}, color +end + +function BattleMenu:createItemWidget(character, pocketName, itemInBag) + local data = core.datas:get("items", itemInBag.name) + local nbr = game.loot:getItemNumber(pocketName, itemInBag.name) + local nbrLabel = {"x" .. utils.math.numberToString(nbr, 2), "right"} + local func = function() self:useItem(character, pocketName, itemInBag.name) end + + --text, position, func, type, additionnalItems, color + return data.fullname, "left", func, "select", {nbrLabel}, {1, 1, 1} +end + + +function BattleMenu:doAction(character, action) + self:looseFocus() + self.isVisible = false + character:doBasicAction(action) +end + +function BattleMenu:useItem(character, pocketName, item) + self:looseFocus() + self.isVisible = false + character:useItem(pocketName, item) +end + +function BattleMenu:doSkill(character, skill, isOk) + if (isOk) then + self:looseFocus() + character:useSkill(skill) + self.isVisible = false + else + self.scene:showMessage("You haven't enough PP!") + end +end + +return BattleMenu diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua new file mode 100644 index 0000000..2754ebe --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua @@ -0,0 +1,68 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local StatusBar = GuiElement:extend() +local TweenManager = require "birb.classes.time" + +local Emblem = require "game.modules.gui.emblem" +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local DIST_STATUSBAR = 106 +local Y = 200 +local STATUSBAR_W = 90 + +function StatusBar:new(fighter, i) + self:initAbstract(fighter) + StatusBar.super.new(self, self.abstract.name .. "StatutBar", (i-0.5)*DIST_STATUSBAR-(STATUSBAR_W/2), Y, STATUSBAR_W, 64) + self:createParts(self.scene) +end + +function StatusBar:initAbstract(fighter) + self.abstract = fighter.abstract + self.hp = self.abstract.hp + self.pp = self.abstract.pp + self.stats = self.abstract:getStats() +end + +function StatusBar:createParts(scene) + self.emblem = Emblem(self.abstract, scene) + + self.hpbar = ComplexHPBar(58) + self.ppbar = ComplexHPBar(58) + self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1) + self.hpbar:setColorBackground(112 / 255, 0, 0) + self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1) + self.ppbar:setColorBackground(0, 54 / 255, 229 / 255) +end + +function StatusBar:updateHP() + self.tweens:newTween(0, 0.3, {hp = self.abstract.hp}, "linear") +end + +function StatusBar:updatePP() + self.tweens:newTween(0, 0.3, {pp = self.abstract.pp}, "linear") +end + +function StatusBar:draw() + self.emblem:drawBackground(self.x, self.y) + self:drawStatusArea(self.x + 10, self.y - 8) + self.emblem:drawForeground(self.x, self.y) +end + +function StatusBar:drawStatusArea(x, y) + self.assets.images["statusbar"]:draw(x, y) + + local hpmax = self.stats:get(self.stats.HPMAX) + local ppmax = self.stats:get(self.stats.PPMAX) + + self.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(x + 6, y + 9, self.hp, hpmax) + self.ppbar:drawWithLabels(x + 18, y + 21, self.pp, ppmax) + + local lvl = self.abstract.level + + if lvl < 100 then + lvl = "0" .. lvl + end + love.graphics.print(lvl, x + 42, y + 1) +end + +return StatusBar diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua new file mode 100644 index 0000000..2618d2d --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua @@ -0,0 +1,27 @@ +local Parent = require "birb.modules.gui.elements.parent" +local TurnBar = Parent:extend() + +local gui = require "game.modules.gui" + +function TurnBar:new() + TurnBar.super.new(self, "turnbar", 76, 5, 1, 1) + self.turns = self.scene.turns + self.cursor = self.turns.turns.current +end + +function TurnBar:draw() + for i, action in ipairs(self.turns.actionList) do + if action.fighter:canFight() then + action.fighter:drawIcon(self.x + (i-1)*(20), self.y) + else + gui.drawEmptyIcon(self.x + (i-1)*(20), self.y) + end + end + local cursorx = (self.cursor-1) * 20 + + if #self.turns.actionList > 0 then + self.assets.images["menucursor"]:draw(self.x + cursorx, self.y, math.rad(90), 1, 1, 4, 16) + end +end + +return TurnBar \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/init.lua b/sonic-radiance.love/scenes/battlesystem/gui/init.lua new file mode 100644 index 0000000..9302615 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/init.lua @@ -0,0 +1,42 @@ +local GuiScreen = require "birb.modules.gui.screen" +local CbsScreen = GuiScreen:extend() + +local StatutBar = require "scenes.battlesystem.gui.hudelements.statutbar" +local TurnBar = require "scenes.battlesystem.gui.hudelements.turnbar" +local BattleMenu = require "scenes.battlesystem.gui.hudelements.menu" + +local Composite = require "birb.modules.gui.elements.composite" +local Counter = require "birb.modules.gui.elements.counter" +local Asset = require "birb.modules.gui.elements.assets" + +local show = { + {"turns", "movement", 0.5, 0.6, 424/2, 80, "inOutQuart"}, +} + +function CbsScreen:new() + CbsScreen.super.new(self, "hud") + self:show() +end + +function CbsScreen:buildMenu(character) + self.elements["battleMenu"]:rebuild(character) +end + +function CbsScreen:createElements() + local turns = self.scene.turns + local list = { + {Composite("turns", 10, 10, { + {Asset("turnImg", "images", "hudturn", -1, -1), 0, 0}, + {Counter("turnCnt", "hudnbrs", turns.turns, "number", 2, -1, -1), 33, 1}, + {TurnBar(), 62, -3}, + }), 0}, + {BattleMenu(), 0} + } + for i, fighter in ipairs(turns.player:getList()) do + table.insert(list, {StatutBar(fighter, i), 0}) + end + + return list +end + +return CbsScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua deleted file mode 100644 index df60247..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua +++ /dev/null @@ -1,19 +0,0 @@ -local fancy = require "game.modules.menus.fancy" - -local BattleMenu = fancy.FancyMenu:extend() - -local MENUPOS_X1, MENUPOS_Y = 88, 72 -local MENU_WIDTH = 180-32 -local MENU_ITEM_NUMBER = 6 - -function BattleMenu:new(scene, name) - local x, y = MENUPOS_X1, MENUPOS_Y - local w = MENU_WIDTH - BattleMenu.super.new(self, scene, name, x, y, w, MENU_ITEM_NUMBER, true) -end - -function BattleMenu:clone(name) - return BattleMenu(self.scene, name) -end - -return BattleMenu diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua deleted file mode 100644 index 2d47122..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua +++ /dev/null @@ -1,72 +0,0 @@ -local MenuConstructor = Object:extend() -local CharacterMenu = require "scenes.battlesystem.gui.menus.battlemenu" -local widgets = require "scenes.battlesystem.gui.menus.widgets" - -function MenuConstructor:new( controller ) - self.scene = controller -end - -function MenuConstructor:reconstruct(character) - core.debug:print("cbs/menu", "Reconstructing the menu") - self.scene.menusystem:reset() - self:build(character) - - self.scene.menusystem:switchMenu("BaseMenu") -end - -function MenuConstructor:build(character) - core.debug:print("cbs/menu", "Building the menu") - self:buildBaseMenu(character) - self:buildSkillMenu(character) - self:buildObjectMenu(character) - - self.scene.menusystem.menus["BaseMenu"]:finalize() - self.scene.menusystem:setSoundFromSceneAssets("mBeep") - self.scene.menusystem:activate() -end - -function MenuConstructor:buildBaseMenu(character) - CharacterMenu(self.scene, "BaseMenu") - widgets.ActionWidget(character, "BaseMenu", "attack", "Attack") - self:addSubMenu("BaseMenu", "SkillMenu", "Skills") - self:addSubMenu("BaseMenu", "ObjectMenu", "Objects") - widgets.ActionWidget(character, "BaseMenu", "defend", "Defend") - widgets.ActionWidget(character, "BaseMenu", "flee", "Flee") -end - -function MenuConstructor:set(currentCharacter) - self:reconstruct(currentCharacter) -end - -function MenuConstructor:buildSkillMenu(character) - local list = character.abstract.skills - for k, skill in pairs(list) do - widgets.SkillWidget(character, "SkillMenu", skill.name, "") - end - --SubMenuWidget(character, "SkillMenu", "back", "BaseMenu") - - self.scene.menusystem.menus["SkillMenu"]:setCancelWidget() -end - -function MenuConstructor:buildObjectMenu(character) - for i,pocket in ipairs(game.loot.inventory) do - if (pocket.inBattle) then - CharacterMenu(self.scene, pocket.name) - self:addSubMenu("ObjectMenu", pocket.name, pocket.fullname) - for j,itemData in ipairs(pocket.list) do - widgets.ItemWidget(character, pocket.name, itemData.name) - end - end - end - self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget() -end - -function MenuConstructor:addSubMenu(menu, submenu, widgetName) - self.scene.menusystem.menus[menu]:addSubMenu(submenu, widgetName) -end - -function MenuConstructor:unset( ) - self.isActive = false -end - -return MenuConstructor diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua deleted file mode 100644 index 7510b0a..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua +++ /dev/null @@ -1,164 +0,0 @@ -local fancy = require "game.modules.menus.fancy" - -local widgets = {} - -widgets.BattleWidget = fancy.BaseWidget:extend() -widgets.ActionWidget = widgets.BattleWidget:extend() -widgets.SubMenuWidget = widgets.BattleWidget:extend() -widgets.BackMenuWidget = widgets.BattleWidget:extend() -widgets.SkillWidget = widgets.BattleWidget:extend() -widgets.ItemWidget = widgets.BattleWidget:extend() - --- WIDGETS --- All widgets used by the Characters menus - --- Basic Battle Widget --- The base used by all battle widgets - -function widgets.BattleWidget:new(character, menu_name, label1, label2) - local label1 = label1 or "" - local label2 = label2 or "" - - self.character = character - local scene = self.character.turnSystem.scene - - widgets.BattleWidget.super.new(self, scene, menu_name, label1, label2) - self.assets = self.scene.assets -end - --- Internal functions - -function widgets.BattleWidget:selectAction() - -- Rien de base, à voir ensuite comment je gère -end - -function widgets.BattleWidget:action() - self.scene:flushKeys() - self.scene.menusystem:deactivate() - - self:sendCharacterData() -end - --- External functions - -function widgets.BattleWidget:sendCharacterData() - self.character:doNothing() -end - --- ActionWidget --- The basic action widget - -function widgets.ActionWidget:new(character, menu_name, action, label) - self.actionType = action or "" - local label = label or self.actionType - widgets.ActionWidget.super.new(self, character, menu_name, label, "") -end - -function widgets.ActionWidget:sendCharacterData() - self.character:doBasicAction(self.actionType) -end - --- SubMenuWidget --- A simple widget to change menu - -function widgets.SubMenuWidget:new(character, menu_name, label, newmenu) - local label2 = "" - self.sfx = "mBack" - if label ~= "back" then - label2 = ">" - self.sfx = "mBeep" - end - widgets.SubMenuWidget.super.new(self, character, menu_name, label, label2) - self.newmenu = newmenu or "BaseMenu" -end - -function widgets.SubMenuWidget:action() - self.assets.sfx[self.sfx]:play() - self.scene.menusystem:switchMenu(self.newmenu) -end - --- BackMenuWidget --- Quit the menu - -function widgets.BackMenuWidget:new(character, menu_name) - widgets.BackMenuWidget.super.new(self, character, menu_name, "back", "") -end - -function widgets.BackMenuWidget:sendCharacterData() - self.assets.sfx["mBack"]:play() - self.character:receiveBackSignal() -end - --- SkillWidget --- A widget to handle skills - -function widgets.SkillWidget:new(character, menu_name, skill) - self.skillname = skill - local label2 = "00" - - self.skilldata = core.datas:get("skills", skill) - - if self.skilldata ~= nil then - label2 = self.skilldata.cost or 0 - if label2 < 10 then - label2 = "0" .. label2 - end - end - local color = {1, 1, 1} - if (self.skilldata.cost > character.abstract.pp) then - color = {1, 0.3, 0.3} - end - local fullName = self:getFullName(character) - - widgets.SkillWidget.super.new(self, character, menu_name, fullName, "-" .. label2, "skills") - self.color = color -end - -function widgets.SkillWidget:getFullName(character) - if (self.skilldata.altName == nil) then - return self.skilldata.fullname - end - if (self.skilldata.altName[character.abstract.simplename] ~= nil) then - return self.skilldata.altName[character.abstract.simplename] - else - return self.skilldata.fullname - end -end - -function widgets.SkillWidget:sendCharacterData() - - if (self.skilldata ~= nil and self.skilldata.cost <= self.character.abstract.pp) then - self.assets.sfx["mSelect"]:play() - self.character:useSkill(self.skillname) - else - core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist") - self.character:doNothing() - self.assets.sfx["mError"]:play() - self.scene:showMessage("You haven't enough PP!") - end - -end - --- ItemWidget --- A widget to handle items - -function widgets.ItemWidget:new(character, menu_name, item) - self.category = menu_name - self.itemname = item - local label2 = "00" - - self.number = game.loot:getItemNumber(menu_name, item) - self.itemdata = core.datas:get("items", item) - - label2 = self.number - - widgets.ItemWidget.super.new(self, character, menu_name, self.itemdata.fullname, "x" .. label2, "skills") -end - -function widgets.ItemWidget:sendCharacterData() - self.character:useItem(self.category, self.itemname) - self.assets.sfx["mBeep"]:play() -end - - -return widgets diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 347e6c1..88edf61 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -3,12 +3,13 @@ local Scene = require "game.scenes" local BattleSystem = Scene:extend() local World = require "scenes.battlesystem.world" -local MenuSystem = require "scenes.battlesystem.gui.menus.controller" local Turns = require "scenes.battlesystem.turns" local VictoryScreen = require "scenes.battlesystem.gui.screens.victory" local GameOverScreen = require "game.modules.gui.gameover" +local CbsScreen = require "scenes.battlesystem.gui" + local TweenManager = require "birb.classes.time" function BattleSystem:new(battleData) @@ -20,6 +21,8 @@ function BattleSystem:new(battleData) self:initManagers(battleData) self:startBattle() + CbsScreen() + self.screen = nil self.tweens = TweenManager(self) end @@ -32,7 +35,6 @@ end function BattleSystem:initManagers(battleData) self.datas = {} self.world = World(self) - self.menu = MenuSystem(self) self.turns = Turns(self, battleData) end @@ -66,10 +68,7 @@ function BattleSystem:looseBattle() end function BattleSystem:haveMenus() - for k,v in pairs(self.menusystem.menus) do - return true - end - return false + return self.gui.elements["battleMenu"].isVisible end function BattleSystem:update(dt) diff --git a/sonic-radiance.love/scenes/battlesystem/turns.lua b/sonic-radiance.love/scenes/battlesystem/turns.lua index e4f61de..f6e583f 100644 --- a/sonic-radiance.love/scenes/battlesystem/turns.lua +++ b/sonic-radiance.love/scenes/battlesystem/turns.lua @@ -3,8 +3,6 @@ local TurnController = Object:extend() local Player = require "scenes.battlesystem.fighters.player" local Ennemy = require "scenes.battlesystem.fighters.ennemies" -local HUD = require "scenes.battlesystem.gui.hud" - local maputils = require "scenes.battlesystem.utils" function TurnController:new(scene, battleData) @@ -26,7 +24,7 @@ function TurnController:new(scene, battleData) self.canFleeBattle = true - self.hud = HUD(self) + self.gui = self.scene.gui self.player = Player(self) self.ennemies = Ennemy(self, battleData) @@ -49,33 +47,25 @@ function TurnController:fleeBattle() self.scene:fleeBattle() end -function TurnController:showMessage(message) - self.hud:showMessage(message) -end - function TurnController:startBattle() self.isActive = true - self.hud:movePlayerHUD(true) end function TurnController:finishBattle() self.isActive = false self.actionlist = {} - self.hud:movePlayerHUD(false) self.scene:finishBattle() end function TurnController:looseBattle() self.isActive = false self.actionlist = {} - self.hud:movePlayerHUD(false) self.scene:looseBattle() end function TurnController:update(dt) self.player:update(dt) self.ennemies:update(dt) - self.hud:update(dt) if (self.isActive) then if (self.currentFighter ~= nil) then self.currentFighter:update(dt) @@ -156,7 +146,7 @@ function TurnController:startAction() self.currentFighter = nextFighter core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name) self.currentFighter:setActive() - self.hud:moveBattleCursor(self.turns.current) + self.gui:newTween("turnbar", 0, 0.2, {cursor = self.turns.current}, 'inCubic') end end @@ -168,11 +158,4 @@ function TurnController:sendSignalToCurrentBattler(signal, subSignal) self.actionList[self.turns.current].actor:receiveSignal(signal, subSignal) end -function TurnController:draw() - self.player:draw() - self.ennemies:draw() - self.hud:draw() -end - - return TurnController -- 2.30.2 From 5b0bdc68ce305f15676ee0ecb64a729a49f1b28b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:28:57 +0200 Subject: [PATCH 064/102] improvement: port the selection to guisystem It's a special guiElement, as it's not drawn by the GUISystem, but the input handling code is usefull. --- .../battlesystem/fighters/character/init.lua | 10 +---- .../fighters/character/selection.lua | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua index 2990b71..1d52b4c 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua @@ -12,15 +12,11 @@ function HeroFighter:new(owner, character, id) self:initVoices() - self.selection = nil self.exp = self.abstract.exp end function HeroFighter:update(dt) HeroFighter.super.update(self, dt) - if (self.selection ~= nil) then - self.selection:update(dt) - end end function HeroFighter:getAbstract() @@ -72,9 +68,9 @@ function HeroFighter:verifyTargets() if (needTarget) then if (targetEnnemies) then - self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies, true) + SelectionSystem(self, self.owner.turnSystem.ennemies, true) else - self.selection = SelectionSystem(self, self.owner, false) + SelectionSystem(self, self.owner, false) end else self.action:start() @@ -87,7 +83,6 @@ function HeroFighter:attack() end function HeroFighter:receiveTarget(target) - self.selection = nil if (self.action ~= nil) then self.action:setTarget(target) self.action:start() @@ -96,7 +91,6 @@ end function HeroFighter:goBackToMenu() self.turnSystem.scene.gui:setFocus("battleMenu") - self.selection = nil end -- LIFE functions diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua index 1db4db9..1040b7c 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua @@ -1,45 +1,42 @@ -local SelectionSystem = Object:extend() +local GuiElement = require "birb.modules.gui.elements.parent" +local SelectionSystem = GuiElement:extend() function SelectionSystem:new(owner, fighterSide, onlyAlive) + SelectionSystem.super.new(self, "selection", 0, 0, 1, 1) self.fighterList = fighterSide:getTargets(onlyAlive) self.owner = owner self.assets = self.owner.assets self.selectedTarget = 1 + self:updateTarget() + self:getFocus() end -function SelectionSystem:update(dt) - --Faire en sorte que cela permette de choisir la cible - local keys = self.owner.turnSystem.scene:getKeys(1) - self:purgeTarget() - if (keys["up"].isPressed) then +function SelectionSystem:keypressed(key) + if (key == "A") then + self.assets.sfx["mSelect"]:play() + self:selectTarget() + elseif (key == "B") then + self.assets.sfx["mBack"]:play() + self:goBack() + elseif (key == "up") then + self:purgeTarget() if (self.selectedTarget == 1) then self.selectedTarget = #self.fighterList else self.selectedTarget = self.selectedTarget - 1 end self.assets.sfx["mBeep"]:play() - end - if (keys["down"].isPressed) then + self:updateTarget() + elseif (key == "down") then + self:purgeTarget() if (self.selectedTarget == #self.fighterList) then self.selectedTarget = 1 else self.selectedTarget = self.selectedTarget + 1 end self.assets.sfx["mBeep"]:play() + self:updateTarget() end - - self:updateTarget() - - if (keys["A"].isPressed) then - self.assets.sfx["mSelect"]:play() - self:selectTarget() - end - - if (keys["B"].isPressed) then - self.assets.sfx["mBack"]:play() - self:goBack() - end - end function SelectionSystem:purgeTarget() @@ -53,11 +50,15 @@ function SelectionSystem:updateTarget() end function SelectionSystem:selectTarget() + self:looseFocus() + self:destroy() self:purgeTarget() self.owner:receiveTarget(self.fighterList[self.selectedTarget]) end function SelectionSystem:goBack() + self:looseFocus() + self:destroy() self:purgeTarget() self.owner:goBackToMenu() end -- 2.30.2 From 3c8a3ed312512626b0a061c11f1308170bf259a7 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:29:36 +0200 Subject: [PATCH 065/102] improvement: make qtes guiElements --- .../scenes/battlesystem/choregraphy/init.lua | 6 ---- .../battlesystem/choregraphy/qte/parent.lua | 35 ++++++++++--------- .../choregraphy/qte/prompts/button.lua | 21 +++++------ .../choregraphy/qte/prompts/init.lua | 5 ++- .../fighters/character/actions/parent.lua | 6 ---- 5 files changed, 29 insertions(+), 44 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua index b2bc558..3bb90c9 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua @@ -31,7 +31,6 @@ function ChoregraphySystem:new(action, choregraphy, subChoregraphy) end function ChoregraphySystem:update(dt) - self:updateQte(dt) self:updateSteps(dt) self.tweens:update(dt) self:updateSubChoregraphies(dt) @@ -49,9 +48,4 @@ function ChoregraphySystem:endChoregraphy() self.fighter.turnSystem:applyDeath() end -function ChoregraphySystem:draw() - self:drawQte() - self:drawSubChoregraphies() -end - return ChoregraphySystem diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua index 0afa2be..e14de48 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua @@ -1,18 +1,23 @@ -local QteParent = Object:extend() +local GuiElements = require "birb.modules.gui.elements.parent" +local QteParent = GuiElements:extend() -local TweenManager = require "birb.classes.time" local Prompts = require "scenes.battlesystem.choregraphy.qte.prompts" function QteParent:new(choregraphySystem, arguments) self.choregraphy = choregraphySystem self.arguments = arguments - self.tweens = TweenManager(self) self.isBlocking = nil self.prompts = Prompts(self) self.timer = 0 self.timerActive = false self.isSuccess = false self.tag = "" + + QteParent.super.new(self, "qte", -1, -1, 1, 1) + + self:start() + self.isStarted = true + self:getFocus() end function QteParent:setTag(tag) @@ -60,18 +65,13 @@ function QteParent:setOrigin(origin) end end -function QteParent:updateQte(dt, isActive) - if (not self.isStarted) then - self:start() - self.isStarted = true - else - self:update(dt) - self.tweens:update(dt) - self.prompts:update(dt) - if (isActive) then - self:verifyPrompts() - end - end +function QteParent:updateElement(dt) + QteParent.super.updateElement(self, dt) + self.prompts:update(dt) +end + +function QteParent:keypressed(key) + self:verifyPrompts(key) end function QteParent:timerResponse(timer) @@ -87,6 +87,7 @@ function QteParent:timerResponse(timer) self.prompts.defaultTimerValue = 0 elseif (timer == "endQte") then self.choregraphy:removeQte() + self:destroy() end end @@ -97,8 +98,8 @@ function QteParent:finish(success) self:endQte() end -function QteParent:verifyPrompts() - local promptResult = self.prompts:verifyPrompts() +function QteParent:verifyPrompts(key) + local promptResult = self.prompts:verifyPrompts(key) if (promptResult == 1) then self:promptSuccess() elseif (promptResult == -1) then diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua index a21d272..b6705ee 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua @@ -69,24 +69,21 @@ function Button:update(dt, isFirst) love.graphics.arc("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2, 0 - (math.pi/2), ((math.pi*2*self.prompt:getTimer()) - (math.pi/2)), 16) love.graphics.setStencilTest() love.graphics.setCanvas() + utils.graphics.resetColor() end end -function Button:verifyPrompts(sourceKeys, removeWhenPressed) +function Button:verifyPrompts(key, removeWhenPressed) local mustBeRemoved = false local keyValue = 0 self.lum = 1 - for i, key in ipairs(keys) do - if (sourceKeys[key].isPressed) then - if (key == self.key) then - keyValue = 1 - self.lum = 0.8 - table.insert(self.circles, ButtonCircle()) - else - keyValue = -1 - self.isFailed = true - end - end + if (key == self.key) then + keyValue = 1 + self.lum = 0.8 + table.insert(self.circles, ButtonCircle()) + else + keyValue = -1 + self.isFailed = true end if (removeWhenPressed and keyValue == 1) then self.number = self.number - 1 diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua index 7283b39..2584239 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua @@ -31,11 +31,10 @@ function QtePrompts:update(dt) end end -function QtePrompts:verifyPrompts() +function QtePrompts:verifyPrompts(key) local buttonValue, mustBeRemoved = 0, false if (self.list[self.current] ~= nil) then - local keys = self.scene.sources[1].keys - buttonValue, mustBeRemoved = self.list[self.current]:verifyPrompts(keys, self.removeWhenPressed) + buttonValue, mustBeRemoved = self.list[self.current]:verifyPrompts(key, self.removeWhenPressed) if (not self.canPress and buttonValue == 1) then buttonValue = -1 end diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua index 25bd887..6f624c0 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua @@ -53,10 +53,4 @@ function ActionParent:finishAction() self.fighter:finishAction() end -function ActionParent:draw() - if (self.choregraphy ~= nil) then - self.choregraphy:draw() - end -end - return ActionParent -- 2.30.2 From f520dbb3885d69a8ee7aa72cac0d91860bd992d6 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:31:46 +0200 Subject: [PATCH 066/102] chore: remove unused old gameover --- .../battlesystem/gui/screens/gameover.lua | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100644 sonic-radiance.love/scenes/battlesystem/gui/screens/gameover.lua diff --git a/sonic-radiance.love/scenes/battlesystem/gui/screens/gameover.lua b/sonic-radiance.love/scenes/battlesystem/gui/screens/gameover.lua deleted file mode 100644 index 322841d..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/screens/gameover.lua +++ /dev/null @@ -1,91 +0,0 @@ -local GameOverScreen = Object:extend() - -local TweenManager = require "birb.classes.time" -local ConfirmDialog = require "game.modules.confirmdialog" - -local defTransitions = require "birb.modules.transitions" -local radTransitions = require "game.modules.transitions" - -local gui = require "game.modules.gui" - -local tw, th = 128, 32 - -function GameOverScreen:new(scene) - self.scene = scene - self.assets = scene.assets - self.turnSystem = scene.turns - - self:setVariables() - - self.continueBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th) - - self.tweens = TweenManager(self) - self:prepareAnimation() -end - -function GameOverScreen:setVariables() - -- Vignette Opacity - self.vignetteOpacity = 0 - - -- Battle FInished Label - self.labelOpacity = 0 - local width, height = core.screen:getDimensions() - self.labelX = width/2 - - -- Infobox - self.tbSize = 0.6 - self.tbOpacity = 0 -end - -function GameOverScreen:prepareAnimation() - -- Vignette - self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo') - - -- Label - self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo') - self.tweens:newTween(0.9, 0.4, {labelX=4}, 'inExpo') - - self.tweens:newTimer(1.8, "continue") -end - -function GameOverScreen:update(dt) - self.tweens:update(dt) -end - -function GameOverScreen:draw() - local width, height = core.screen:getDimensions() - self:drawVignette(width, height) - self:drawLabel(width/2, 48, self.labelX, self.labelOpacity) -end - -function GameOverScreen:timerResponse(timer) - if (timer == "continue") then - local confirm = ConfirmDialog(self.scene, "Do you want to return to title ? \nYou can also reload your latest save.", - function() self:returnToTitle() end, "Return to title", - function() self:loadLastSave() end, "Reload last save") - confirm.darken = false - end -end - -function GameOverScreen:drawVignette(width, height) - love.graphics.setColor(0, 0, 0, self.vignetteOpacity) - love.graphics.rectangle("fill", 0, 0, width, height) -end - -function GameOverScreen:drawLabel(x, y, x2, opacity) - love.graphics.setColor(1, 1, 1, opacity) - - self.assets.fonts["SA2font"]:print("GAME", x - x2, y, "right") - self.assets.fonts["SA2font"]:print("OVER", x + x2, y, "left") -end - -function GameOverScreen:returnToTitle() - core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2) -end - -function GameOverScreen:loadLastSave() - self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad") - core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2) -end - -return GameOverScreen -- 2.30.2 From 4a7ad692cbfb27c943d155c3809f71345ece643c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 18 Sep 2021 19:04:49 +0200 Subject: [PATCH 067/102] feat: add a reward system for the cbs --- .../battlesystem/choregraphy/mixins/qtes.lua | 1 + .../choregraphy/mixins/wrappers.lua | 3 + .../scenes/battlesystem/fighters/fighter.lua | 4 + .../scenes/battlesystem/fighters/parent.lua | 10 +++ .../scenes/battlesystem/rewards.lua | 79 +++++++++++++++++++ .../scenes/battlesystem/turns.lua | 23 ++++-- 6 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 sonic-radiance.love/scenes/battlesystem/rewards.lua diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/qtes.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/qtes.lua index f803717..2953ed6 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/qtes.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/qtes.lua @@ -38,6 +38,7 @@ function QteMixin:endQte(success) self.qte.wasSuccess = success table.insert(self.qte.list, success) + self.rewards:addQTE(success) end function QteMixin:removeQte() diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/wrappers.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/wrappers.lua index b6e4200..c4bd086 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/wrappers.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/mixins/wrappers.lua @@ -6,6 +6,9 @@ function InfosMixin:initWrappers(action, target) self.actor = self.fighter.actor self.assets = self.fighter.actor.assets self.world = self.actor.world + self.scene = self.world.scene + self.turns = self.scene.turns + self.rewards = self.turns.rewards self:initTargets(target or action.target) end diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/fighter.lua b/sonic-radiance.love/scenes/battlesystem/fighters/fighter.lua index 8cd7f73..b2eb8e4 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/fighter.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/fighter.lua @@ -140,9 +140,13 @@ end function FighterParent:applyDamage(damage) core.debug:print("cbs/fighter", "Taken " .. damage .. " damage" ) self:setHP(damage * -1, true) + self.owner:registerDamage(damage) if (not self.isDefending) then self.actor:getHurt() end + if (not self.abstract:isAlive()) then + self.owner:registerKO() + end end function FighterParent:getAbstract() diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua index f78bc35..dac26f2 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua @@ -4,6 +4,8 @@ function FighterControllerParent:new(turnSystem) self.turnSystem = turnSystem self.world = turnSystem.world self.list = {} + self.damages = 0 + self.ko = 0 end function FighterControllerParent:get(id) @@ -22,6 +24,14 @@ function FighterControllerParent:count() return #self.list end +function FighterControllerParent:registerDamage(damage) + self.damages = math.floor(self.damages + damage) +end + +function FighterControllerParent:registerKO() + self.ko = self.ko + 1 +end + function FighterControllerParent:countAlive() local aliveCount = 0 for i, fighter in ipairs(self.list) do diff --git a/sonic-radiance.love/scenes/battlesystem/rewards.lua b/sonic-radiance.love/scenes/battlesystem/rewards.lua new file mode 100644 index 0000000..75e030e --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/rewards.lua @@ -0,0 +1,79 @@ +local Rewards = Object:extend() + +local rankFactor = {1, 1.25, 1.5, 1.75, 2} + +function Rewards:new(turns) + self.turns = turns + self.qte = 0 + self.qteSuccess = 0 +end + +function Rewards:apply() + local _, rings = self:getRewards(true) + game.loot.rings = game.loot.rings + rings +end + +function Rewards:getRank() + local ennemyNbr, turns, _, _, ko = self.turns:getDatas() + local qteSuccess, haveDoneQte = self:getQteSuccessRate() + local rank = 3 + + if (not haveDoneQte) then + rank = 3 + elseif (qteSuccess >= 0.75) then + rank = 4 + elseif (qteSuccess >= 0.5) then + rank = 3 + elseif (qteSuccess >= 0.25) then + rank = 2 + else + rank = 1 + end + + -- TODO: modifier l'effet de nombre de tour pour les boss + if (turns/ennemyNbr > 3) then + rank = rank - 1 + end + + if (ko == 0) then + rank = rank + 1 + end + + return math.max(1, math.min(5, rank)) +end + +function Rewards:getExp(character) + local exp = self:getRewards(true) + return character.abstract.exp + exp +end + +function Rewards:getRewards(real) + local exp, ring = 0, 0 + for i, ennemy in ipairs(self.turns.ennemies.list) do + exp = exp + ennemy.abstract.data.giveExp + ring = ring + ennemy.abstract.data.giveRings + end + + if (real) then + exp = exp * rankFactor[self:getRank()] + ring = ring * rankFactor[self:getRank()] + end + + return exp, ring +end + +function Rewards:getQteSuccessRate() + if (self.qte == 0) then + return 0, false + end + return self.qteSuccess/self.qte, true +end + +function Rewards:addQTE(success) + self.qte = self.qte + 1 + if (success) then + self.qteSuccess = self.qteSuccess + 1 + end +end + +return Rewards diff --git a/sonic-radiance.love/scenes/battlesystem/turns.lua b/sonic-radiance.love/scenes/battlesystem/turns.lua index f6e583f..eed59fa 100644 --- a/sonic-radiance.love/scenes/battlesystem/turns.lua +++ b/sonic-radiance.love/scenes/battlesystem/turns.lua @@ -3,6 +3,8 @@ local TurnController = Object:extend() local Player = require "scenes.battlesystem.fighters.player" local Ennemy = require "scenes.battlesystem.fighters.ennemies" +local Rewards = require "scenes.battlesystem.rewards" + local maputils = require "scenes.battlesystem.utils" function TurnController:new(scene, battleData) @@ -29,6 +31,8 @@ function TurnController:new(scene, battleData) self.player = Player(self) self.ennemies = Ennemy(self, battleData) + self.rewards = Rewards(self) + -- Change the seed at the start of each battle math.randomseed( os.time() ) self:applyDeath() @@ -55,6 +59,7 @@ function TurnController:finishBattle() self.isActive = false self.actionlist = {} self.scene:finishBattle() + self.rewards:apply() end function TurnController:looseBattle() @@ -80,16 +85,20 @@ function TurnController:update(dt) end function TurnController:getRank() - return 3 + return self.rewards:getRank() end function TurnController:getRewards() - local exp, ring = 0, 0 - for i, ennemy in ipairs(self.ennemies.list) do - exp = exp + ennemy.abstract.data.giveExp - ring = ring + ennemy.abstract.data.giveRings - end - return exp, ring + return self.rewards:getRewards(false) +end + +function TurnController:getDatas() + local ennemyNbr = #self.ennemies.list + local turns = self.turns.current + local dmgSent = self.ennemies.damages + local dmgTaken = self.player.damages + local ko = self.player.ko + return ennemyNbr, turns, dmgSent, dmgTaken, ko end function TurnController:nextAction() -- 2.30.2 From 205028718a0e86d84efc6e7298f927fcc5fa9875 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 18 Sep 2021 21:27:14 +0200 Subject: [PATCH 068/102] feat: add a prompt system to the RadianceScene --- .../game/modules/gui/actionPrompt.lua | 52 +++++++++++++++++++ sonic-radiance.love/game/scenes/init.lua | 6 +++ 2 files changed, 58 insertions(+) create mode 100644 sonic-radiance.love/game/modules/gui/actionPrompt.lua diff --git a/sonic-radiance.love/game/modules/gui/actionPrompt.lua b/sonic-radiance.love/game/modules/gui/actionPrompt.lua new file mode 100644 index 0000000..da354e9 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/actionPrompt.lua @@ -0,0 +1,52 @@ +local CanvasElement = require "birb.modules.gui.elements.parent" +local ActionPrompt = CanvasElement:extend() + +function ActionPrompt:new() + self.text = "" + ActionPrompt.super.new(self, "actionPrompt", 0, 0, 424, 240) + self.depth = -2 + self.opacity = 0 + self.isShown = false +end + +function ActionPrompt:setText(text) + if (utils.string.isEmpty(text)) then + self:hide() + else + self.text = text + self:show() + end +end + +function ActionPrompt:hide() + if (self.isShown) then + self.tweens.tweens = {} + self:newTween(0.0, 0.6, {opacity = 0}, "outExpo") + end + self.isShown = false +end + +function ActionPrompt:show() + if (not self.isShown) then + self.tweens.tweens = {} + self:newTween(0.0, 0.6, {opacity = 1}, "outExpo") + end + self.isShown = true +end + +function ActionPrompt:draw() + if (not utils.string.isEmpty(self.text)) then + local w = self.assets.fonts["small"]:getWidth(self.text) + 16 + love.graphics.setColor(0,0,0,0.5 * self.opacity) + local x, y = 424 - w/2 - 4, 240 - 20 + love.graphics.rectangle("fill", x - w/2, y + 1, w, 15, 8, 8) + love.graphics.setColor(1, 1, 1, self.opacity) + self.assets.fonts["small"]:setColor(1, 1, 1, self.opacity) + self.assets.fonts["small"]:draw(self.text, x, y, -1, "center") + self.assets.fonts["small"]:setColor(1, 1, 1, 1) + utils.graphics.resetColor() + end +end + + +return ActionPrompt \ No newline at end of file diff --git a/sonic-radiance.love/game/scenes/init.lua b/sonic-radiance.love/game/scenes/init.lua index f56775c..3a6fb28 100644 --- a/sonic-radiance.love/game/scenes/init.lua +++ b/sonic-radiance.love/game/scenes/init.lua @@ -3,6 +3,7 @@ local RadianceScene = BirbScene:extend() local Overlay = require "game.modules.gui.overlay" local MessageQueue = require "game.modules.messagequeue" +local ActionPrompt = require "game.modules.gui.actionPrompt" function RadianceScene:new(haveBorder, showVersion) RadianceScene.super.new(self) @@ -18,6 +19,7 @@ function RadianceScene:new(haveBorder, showVersion) Overlay(haveBorder, showVersion) MessageQueue(self) + ActionPrompt() end function RadianceScene:hideOverlay() @@ -28,6 +30,10 @@ function RadianceScene:showMessage(message) self.gui.elements["messageQueue"]:addMessage(message) end +function RadianceScene:setPrompt(message) + self.gui.elements["actionPrompt"]:setText(message) +end + function RadianceScene:showOverlay(darken) self.gui:showScreen("overlay") if (darken) then -- 2.30.2 From 8f2886be96a91289168e7aa0393ce2c4a66a70d5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 18 Sep 2021 21:31:17 +0200 Subject: [PATCH 069/102] feat: port the victory screen to gui --- .../battlesystem/gui/screens/victory.lua | 221 ------------------ .../scenes/battlesystem/gui/victory/exp.lua | 80 +++++++ .../scenes/battlesystem/gui/victory/init.lua | 122 ++++++++++ .../scenes/battlesystem/gui/victory/items.lua | 23 ++ .../scenes/battlesystem/gui/victory/loot.lua | 22 ++ .../scenes/battlesystem/init.lua | 17 +- 6 files changed, 250 insertions(+), 235 deletions(-) delete mode 100644 sonic-radiance.love/scenes/battlesystem/gui/screens/victory.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/victory/exp.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/victory/init.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/victory/items.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/gui/victory/loot.lua diff --git a/sonic-radiance.love/scenes/battlesystem/gui/screens/victory.lua b/sonic-radiance.love/scenes/battlesystem/gui/screens/victory.lua deleted file mode 100644 index e8c9e01..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/screens/victory.lua +++ /dev/null @@ -1,221 +0,0 @@ -local VictoryScreen = Object:extend() - -local TweenManager = require "birb.classes.time" - -local gui = require "game.modules.gui" - -local charutils = require "game.utils.characters" - -local tw, th = 280+48, 64 -local rankWidth, rankHeight = 64, 48 - -local rankFactor = {1, 1.2, 1.5, 2} - -function VictoryScreen:new(scene) - self.scene = scene - self.assets = scene.assets - self.turnSystem = scene.turns - - self:setVariables() - self:getRewards() - - self.infoBox = self:createInfoBox() - self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", rankWidth, rankHeight) - - self.tweens = TweenManager(self) - self:prepareAnimation() -end - -function VictoryScreen:setVariables() - -- Vignette Opacity - self.vignetteOpacity = 0 - - -- Battle FInished Label - self.labelOpacity = 0 - local _, height = core.screen:getDimensions() - self.labelY = height/2 - - -- Infobox - self.tbSize = 0.6 - self.tbOpacity = 0 - - -- Ranks - self.rankOpacity = 0 - self.rankSize = 4 - - self.addExp = false - - self.charDone = {} - self.nbrCharDone = 0 -end - -function VictoryScreen:prepareAnimation() - -- Vignette - self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo') - - -- Label - self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo') - self.tweens:newTween(0.9, 0.4, {labelY=32}, 'inExpo') - - -- Infobox - self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo') - - -- Ranks - self.tweens:newTween(1.9, 0.4, {rankSize=1, rankOpacity=1}, 'inExpo') - self.tweens:newTween(2.4, 0.3, {shownExp=self.realExp, shownRings=self.realRings}, 'inExpo') - self.tweens:newSwitch(2.7, {"addExp"}) -end - -function VictoryScreen:getRewards() - self.rank = self.turnSystem:getRank() - - local exp, rings = self.turnSystem:getRewards() - self.shownExp, self.shownRings = exp, rings - self.realExp = exp * rankFactor[self.rank] - self.realRings = rings * rankFactor[self.rank] - - for i,character in ipairs(self.turnSystem.player.list) do - character.targetExp = character.exp + self.realExp - end - - game.loot.rings = game.loot.rings + self.realRings -end - -function VictoryScreen:createInfoBox() - local textBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th) - local canvas = love.graphics.newCanvas(tw, th) - love.graphics.setCanvas(canvas) - love.graphics.draw(textBox, 0, 0) - self.assets.fonts["SA2font"]:print("ENNEMIES:", 6, 6) - self.assets.fonts["SA2font"]:print(self.turnSystem.ennemies:count(), tw - 6, 6, "right") - self.assets.fonts["SA2font"]:print("COMBOS:", 6, th - 6 - 22) - self.assets.fonts["SA2font"]:print("0/0", tw - 6, th - 6 - 22, "right") - love.graphics.setCanvas() - local imagedata = canvas:newImageData() - local texture = love.graphics.newImage( imagedata ) - imagedata:release() - canvas:release() - - return texture -end - -function VictoryScreen:update(dt) - self.tweens:update(dt) - - if ( self.addExp and (not self:allCharDone())) then - for i,character in ipairs(self.turnSystem.player.list) do - self:addCharacterExp(dt, character) - end - end - - if (self:allCharDone()) then - local keys = self.scene:getKeys(1) - if (keys["A"].isPressed) then - self.scene:returnToOverworld(false) - end - end - -end - -function VictoryScreen:addCharacterExp(dt, character) - if (self.charDone[character.name] == "done") then - return 0 - end - - local level = character.abstract.level - local xpAddRatio = charutils.getLevelExpRange(level) * 0.5 - local newExp = character.exp + (xpAddRatio * dt) - - if (newExp < character.targetExp) then - character.exp = newExp - local nextLevelExp = charutils.getExpValue(level + 1) - if (character.exp >= nextLevelExp) then - character.abstract:levelUp() - end - else - character.exp = character.targetExp - character.abstract.exp = character.exp - self.charDone[character.name] = "done" - self.nbrCharDone = self.nbrCharDone + 1 - end -end - -function VictoryScreen:allCharDone() - return (self.nbrCharDone >= self.turnSystem.player:count()) -end - -function VictoryScreen:draw() - local width, height = core.screen:getDimensions() - self:drawVignette(width, height) - self:drawLabel(width/2, self.labelY, self.labelOpacity) - - self:drawInfobox(width/2, height/2 - 32, self.tbSize, self.tbOpacity) - - local startx = (width/2 - tw/2) - local endx = (width/2 + tw/2) - local scorex = startx + rankWidth + 8 - local starty = height/2 + 8 - local endy = starty + rankHeight - - self:drawRankBox(startx, starty, self.rankSize, self.tbOpacity, self.rankOpacity) - self:drawText(scorex, starty, endx, "EXP:", math.floor(self.shownExp), self.tbOpacity) - self:drawText(scorex, endy - 24, endx, "RINGS:", math.floor(self.shownRings), self.tbOpacity) - - for i,character in ipairs(self.turnSystem.player.list) do - self:drawCharacterExp(startx + ((i-1)*84), endy + 8, character, self.tbOpacity) - end - - if (self:allCharDone()) then - self.assets.fonts["small"]:print("Press the A key to continue...", width/2, endy + 32, "center") - end - - utils.graphics.resetColor() -end - -function VictoryScreen:drawVignette(width, height) - love.graphics.setColor(0, 0, 0, self.vignetteOpacity) - - love.graphics.rectangle("fill", 0, 0, width, height) -end - -function VictoryScreen:drawLabel(x, y, opacity) - love.graphics.setColor(1, 1, 1, opacity) - - local w, h = self.assets.images["battlecompleted"]:getDimensions() - self.assets.images["battlecompleted"]:draw(x, y, 0, 1, 1, w/2, h/2) -end - -function VictoryScreen:drawInfobox(x, y, size, opacity) - love.graphics.setColor(1, 1, 1, opacity) - love.graphics.draw(self.infoBox, x, y, 0, size, size, tw/2, th/2) -end - -function VictoryScreen:drawRankBox(x, y, rankSize, boxOpacity, rankOpacity) - love.graphics.setColor(1, 1, 1, boxOpacity) - love.graphics.draw(self.rankBox, x, y) - love.graphics.setColor(1, 1, 1, rankOpacity) - self.assets.tileset["ranks"]:drawTile(self.rank, x + (rankWidth/2), y + (rankHeight/2), 0, rankSize, rankSize, 13, 13) -end - -function VictoryScreen:drawText(x, y, x2, text1, text2, opacity) - love.graphics.setColor(1, 1, 1, opacity) - self.assets.fonts["SA2font"]:print(text1, x, y) - self.assets.fonts["SA2font"]:print(text2, x2, y, "right") -end - -function VictoryScreen:drawCharacterExp(x, y, character, opacity) - love.graphics.setColor(1, 1, 1, opacity) - self.assets.images["expbar"]:draw(x, y) - character:drawIcon(x+1, y+6) - love.graphics.setColor(0, 0.8, 0.1, opacity) - local level = character.abstract.level - local exp = character.exp - local remainingExp = charutils.getRemainingExp(exp, level) - local expRatio = charutils.getRelativeExpValue(exp, level) / charutils.getLevelExpRange(level) - gui.drawBar(x + 22, y + 11, math.floor(56 * expRatio), 7) - love.graphics.setColor(1, 1, 1, opacity) - self.assets.fonts["hudnbrs_small"]:print(math.floor(remainingExp), x + 71, y + 11, "right") - self.assets.fonts["hudnbrs_small"]:print(level, x + 72, y + 1, "right") -end - -return VictoryScreen diff --git a/sonic-radiance.love/scenes/battlesystem/gui/victory/exp.lua b/sonic-radiance.love/scenes/battlesystem/gui/victory/exp.lua new file mode 100644 index 0000000..0c2d9d2 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/victory/exp.lua @@ -0,0 +1,80 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local CharacterExp = GuiElement:extend() + +local gui = require "game.modules.gui" +local charutils = require "game.utils.characters" + +function CharacterExp:new(x, y, character, number) + self.character = character + self.started = false + self.done = false + CharacterExp.super.new(self, character.name .. "Exp", x, y, 1, 1) + self.opacity = 0 + self.number = number + self:newTween(1.4, 0.4, {opacity = 1}, "inExpo") + if self.number == 1 then + self:startInSeconds(2.5) + end + self.targetExp = self.scene.turns.rewards:getExp(character) + self.exp = character.abstract.exp +end + +function CharacterExp:update(dt) + if (not self.done and (self.started)) then + self:addCharacterExp(dt) + end +end + +function CharacterExp:startInSeconds(seconds) + self:newFunc(seconds, "startMe", function() self:startExpGain(1) end) +end + +function CharacterExp:startExpGain(number) + self.started = true +end + +function CharacterExp:addCharacterExp(dt) + local level = self.character.abstract.level + local xpAddRatio = charutils.getLevelExpRange(level) * 0.5 + local newExp = self.exp + (xpAddRatio * dt) + + if (newExp < self.targetExp) then + self.exp = newExp + local nextLevelExp = charutils.getExpValue(level + 1) + if (self.exp >= nextLevelExp) then + self.character.abstract.abstract:levelUp() + end + else + self.exp = self.targetExp + self.character.abstract.exp = self.targetExp + self.done = true + self.isLast = self.screen:nextExp(self.number + 1) + if (self.isLast) then + self:getFocus() + end + end +end + +function CharacterExp:keypressed(key) + if (key == "A" and self.done and self.isLast) then + self.scene:returnToOverworld(false) + self.scene:setPrompt("") + end +end + +function CharacterExp:draw() + love.graphics.setColor(1, 1, 1, self.opacity) + self.assets.images["expbar"]:draw(self.x, self.y) + self.character:drawIcon(self.x + 1, self.y + 6) + love.graphics.setColor(0, 0.8, 0.1, self.opacity) + local level = self.character.abstract.level + local exp = self.exp + local remainingExp = charutils.getRemainingExp(exp, level) + local expRatio = charutils.getRelativeExpValue(exp, level) / charutils.getLevelExpRange(level) + gui.drawBar(self.x + 22, self.y + 11, math.floor(56 * expRatio), 7) + love.graphics.setColor(1, 1, 1, self.opacity) + self.assets.fonts["hudnbrs_small"]:print(math.floor(remainingExp), self.x + 71, self.y + 11, "right") + self.assets.fonts["hudnbrs_small"]:print(level, self.x + 72, self.y + 1, "right") +end + +return CharacterExp \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/victory/init.lua b/sonic-radiance.love/scenes/battlesystem/gui/victory/init.lua new file mode 100644 index 0000000..3607e4d --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/victory/init.lua @@ -0,0 +1,122 @@ +local Screen = require "birb.modules.gui.screen" +local VictoryScreen = Screen:extend() + +local TextElement = require "birb.modules.gui.elements.text" +local ChoiceElement = require "game.modules.gui.choiceElem" +local ConfirmDialog = require "game.modules.confirmdialog" +local TextureElement = require "birb.modules.gui.elements.drawable" +local LootElement = require "scenes.battlesystem.gui.victory.loot" +local ItemsElement = require "scenes.battlesystem.gui.victory.items" +local CharExperience = require "scenes.battlesystem.gui.victory.exp" +local TileElement = require "birb.modules.gui.elements.tile" + +local defTransitions = require "birb.modules.transitions" +local gui = require "game.modules.gui" + +local HEIGHT = 32 +local STARTX, STARTY = 32, HEIGHT + 44 +local ENDX, ENDY = 424 - 32, 240 - 24 +local SIZE_FEATS = 128+28 +local START_ITEMS = STARTX + SIZE_FEATS +local START_EXP = START_ITEMS + 128 + +local show = { + {"gameText", "movement", 0.9, 0.4, 424/2, HEIGHT, "inExpo"}, + --{"rankBox", "tween", 1.4, 0.4, {opacity = 1}, "inExpo"}, + {"loot", "tween", 1.4, 0.4, {opacity = 1}, "inExpo"}, + {"items", "tween", 1.4, 0.4, {opacity = 1}, "inExpo"}, + } + +function VictoryScreen:new() + self.feats = 0 + self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", 48, 32) + self.itemBox = gui.newTextBox("assets/gui/dialogbox.png", 96, 48) + + VictoryScreen.super.new(self, "titleScreen") + self:addTransform("show", show) + self.scene:showOverlay(true) + self:show() +end + +function VictoryScreen:createFeats(list) + local ennemyNbr, turns, dmgSent, dmgTaken, ko = self.turns:getDatas() + self:addFeat(list,"Ennemies", ennemyNbr) + self:addFeat(list,"Turns", turns) + self:addFeat(list,"Dmg sent", dmgSent) + if (dmgTaken == 0) then + self:addFeat(list,"No damage !", "") + else + self:addFeat(list,"Dmg taken", dmgTaken) + self:addFeat(list,"KO", ko) + end + local qteRate, haveDoneQte = self.rewards:getQteSuccessRate() + if (not haveDoneQte) then + self:addFeat(list,"No QTE done") + else + self:addFeat(list,"QTE success", math.floor(qteRate * 100) .. "%") + end + self:addRank(list) +end + +function VictoryScreen:addFeat(list, text, label) + self.feats = self.feats + 1 + local featID = "feat" .. self.feats + + label = label or "" + + local elem = ChoiceElement(featID, text, "", label, STARTX - 16, STARTY + (16*(self.feats-1)), SIZE_FEATS) + elem.opacity = 0 + elem:newTween(1 + (0.2*self.feats), 0.15, {opacity = 1, x = STARTX}, 'inQuad') + + table.insert(list, {elem, 0, 1}) +end + +function VictoryScreen:addRank(list) + local rank = TileElement("rank", "ranks", self.rewards:getRank(), 424/2, ENDY - 28,0,4,4,13,13, 0) + rank:newTween(1.9, 0.4, {sx=1, sy=1, opacity=1}, 'inExpo') + + table.insert(list, {rank, 0, 1}) +end + +function VictoryScreen:nextExp(nbr) + local list = self.scene.turns.player:getList() + local nextChar = list[nbr] + if nextChar ~= nil then + self.elements[nextChar.name .. "Exp"]:startExpGain(nbr) + return false + else + self.scene:setPrompt("Finish") + return true + end +end + +function VictoryScreen:createElements() + self.turns = self.scene.turns + self.rewards = self.turns.rewards + + local list = { + {TextElement("gameText", "SA2font", "BATTLE COMPLETED", 424/2, -24, "center"), 0, 1}, + --{TextureElement("rankBox", self.rankBox, 424/2, ENDY - 4, 0, 1,1, 64/2,48, 0), 0, 1}, + {LootElement(START_ITEMS + 2, STARTY - 2), 0, 1}, + {ItemsElement(START_ITEMS + 2, STARTY + 40, {"test", "test", "test"}), 0, 1} + } + self:createFeats(list) + + for i, character in ipairs(self.scene.turns.player:getList()) do + table.insert(list, {CharExperience(START_EXP - 4, STARTY + (i-1)*24 - 12, character, i), 0, 1}) + end + + return list +end + +function VictoryScreen:returnToTitle() + core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2) +end + +function VictoryScreen:loadLastSave() + self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad") + core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2) +end + + +return VictoryScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/victory/items.lua b/sonic-radiance.love/scenes/battlesystem/gui/victory/items.lua new file mode 100644 index 0000000..dbc4641 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/victory/items.lua @@ -0,0 +1,23 @@ +local CanvasElement = require "birb.modules.gui.elements.canvas" +local ItemsElement = CanvasElement:extend() + +local gui = require "game.modules.gui" + +function ItemsElement:new(x, y, list) + self.background = gui.newTextBox("assets/gui/dialogbox.png", 128, 40+16) + local w, h = self.background:getDimensions() + ItemsElement.super.new(self, "items", x, y, w, h) + self.opacity = 0 + self.list = list +end + +function ItemsElement:drawTexture() + love.graphics.draw(self.background, 0, 0) + for index, value in ipairs(self.list) do + if (index <= 4) then + self.assets.fonts["small"]:draw(value, 8, 4 + (16*(index-1)), -1, "left") + end + end +end + +return ItemsElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/victory/loot.lua b/sonic-radiance.love/scenes/battlesystem/gui/victory/loot.lua new file mode 100644 index 0000000..eb7c661 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/victory/loot.lua @@ -0,0 +1,22 @@ +local CanvasElement = require "birb.modules.gui.elements.canvas" +local LootElement = CanvasElement:extend() + +local gui = require "game.modules.gui" + +function LootElement:new(x, y) + self.background = gui.newTextBox("assets/gui/dialogbox.png", 128, 40) + local w, h = self.background:getDimensions() + LootElement.super.new(self, "loot", x, y, w, h) + self.canvas.isAnimated = true + self.opacity = 0 +end + +function LootElement:drawTexture() + love.graphics.draw(self.background, 0, 0) + self.assets.fonts["small"]:draw("Rings: ", 8, 4, -1, "left") + self.assets.fonts["small"]:draw("0", self.w - 8, 4, -1, "right") + self.assets.fonts["small"]:draw("Exp: ", 8, 20, -1, "left") + self.assets.fonts["small"]:draw("0", self.w - 8, 20, -1, "right") +end + +return LootElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 88edf61..43c0713 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -5,7 +5,7 @@ local BattleSystem = Scene:extend() local World = require "scenes.battlesystem.world" local Turns = require "scenes.battlesystem.turns" -local VictoryScreen = require "scenes.battlesystem.gui.screens.victory" +local VictoryScreen = require "scenes.battlesystem.gui.victory" local GameOverScreen = require "game.modules.gui.gameover" local CbsScreen = require "scenes.battlesystem.gui" @@ -14,7 +14,6 @@ local TweenManager = require "birb.classes.time" function BattleSystem:new(battleData) BattleSystem.super.new(self) - self.assets:batchImport("assets.battle") self:playMusic(battleData.music) @@ -45,7 +44,7 @@ end function BattleSystem:finishBattle() self.assets:setMusic("assets/music/victory.mp3") self.assets:playMusic() - self.screen = VictoryScreen(self) + VictoryScreen(self) end function BattleSystem:fleeBattle() @@ -73,18 +72,8 @@ end function BattleSystem:update(dt) self.tweens:update(dt) - self.world:update(dt) self.turns:update(dt) - if (self.screen ~= nil) then - self.screen:update(dt) - end -end - -function BattleSystem:draw() - BattleSystem.super.draw(self) - if (self.screen ~= nil) then - self.screen:draw() - end + self.world:update(dt) end function BattleSystem:exit() -- 2.30.2 From 1ab9159120d5083de90825e2661db1f34c18231a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 Dec 2021 17:50:41 +0100 Subject: [PATCH 070/102] fix: make sure overlay state reset when it must --- sonic-radiance.love/game/modules/gui/overlay.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sonic-radiance.love/game/modules/gui/overlay.lua b/sonic-radiance.love/game/modules/gui/overlay.lua index 7cca4c5..a32337d 100644 --- a/sonic-radiance.love/game/modules/gui/overlay.lua +++ b/sonic-radiance.love/game/modules/gui/overlay.lua @@ -44,6 +44,11 @@ function OverlayScreen:new(active, doShowVersion) self.borders = gui.newBorder(424, 30, 8) self.doShowVersion = doShowVersion + if (active == false) then + wasActive = active + hadVersion = self.doShowVersion + end + OverlayScreen.super.new(self, "overlay") local transformStuff = false @@ -80,6 +85,7 @@ end function OverlayScreen:update(dt) wasActive = self.isVisible hadVersion = self.doShowVersion + OverlayScreen.super.update(self, dt) end function OverlayScreen:createElements() -- 2.30.2 From 5291f9f8907ac48896accdede43a60bcb822b5bf Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 Dec 2021 17:51:03 +0100 Subject: [PATCH 071/102] feat: new assets --- sonic-radiance.love/assets/gui/animals.png | Bin 0 -> 3228 bytes sonic-radiance.love/assets/gui/ranks.png | Bin 1324 -> 11591 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 sonic-radiance.love/assets/gui/animals.png diff --git a/sonic-radiance.love/assets/gui/animals.png b/sonic-radiance.love/assets/gui/animals.png new file mode 100644 index 0000000000000000000000000000000000000000..ba34081831719f8c29423a1f26fbc9f0591f2bb9 GIT binary patch literal 3228 zcmV;N3}f?&P)EX>4Tx04R}tkvmAkP!xv$KBPV>B6bjQ$WWauh>AFB6^c+H)C#RSnB4RQO&XFE z7e~Rh;NWAi>fqw6tAnc`2tGjE+?*6$q{MTRLW>wL9PY<|@Bee|xq!c3W~vz+2UN{6 zQi-^b$*u~aS9Bpr)sG&Dnfjb4CgHih?&0J6U5saW-}`g*Dmjw@K7n|a>4rtTK|H-_ z>74h8BdjPX#OK6g1~o|h$aUG}H_ioz{X8>bq*L?65n`dx#&R38qM;H`5l0nOqkMnH zWrgz=XSG~q%|7`H!#Qnbnd?-;NMI355FtQD6(y8mAx67Kiis4R$36T*j$b5~Os*0b zITlcX3d!+<|H1Fsn)%5IHz^zkI$mu1V+0880*#t&e;?a+;{*si16NwhU#SB#pQP7X zTJ#9$+XgPKTbjHFTk8{ps& z7%foty2raa+voQ0o#y<00O_Z4a8^3?H2?qr24YJ`L;z?2E&!7Y)Gp@$000SaNLh0L z01FcU01FcV0GgZ_00007bV*G`2jvL_3Mm8F_nt5S000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}000VeNkl4Gm8T)Op8Gve>&>SUe&-EhJoAd z2E#BIiZozCNd*q(JOWe)&ui7*sMXbv#6jiDHTG*LXfRU1VjD)Hr7C*v=j-v%H|HQ9sEHBqav_$Q&grk|@0U5p zQY6Yiqq`B^Ym3l5;*f{}jX>QhV)<})IyClc0_Ux5_hGU{nfVFj`*CN-OR|ira^m?l z$1uO<7;imD9MsB&)5-7erEy+kzeYc`?LI~Gi%-$RYPBMF;Ed?`Du)9-ot?-qndBMh zUt5I2v>3E_JYX1x#&g05cX5+qf`rrBb{{=fvl3^m%c5Z2ZZ`nH?RHb}`T6-gU-;1{ za}PWnzSsF${K)D5ryjV~5netYox;!OAJlx&bzoAI4FGU^(5h-Yl)3|Pyh!18yV2tD zpqSC$cM}rz0RnJRlnu*DE@D~9#jwGX5J*yhvfNzMxCibT@auU#yq@P%UdTw=n-rUb z)`bnh94RLgv&{Px3lOQiGwaGS~LmCajD7Yfu}zFTn3#iq~E^4wF7ZQ42~Ms&aS~fvcqmxr7X; zg2sLgd%~;*{C+P5AfbTnh2CnXrk#=0VTlQ)Kd}`vInbQdI~A=D=-w_jDMW?FFn8Td47{MbiNYZ zulWKKnx8olDe)^%*do4r;NWcN`T0p~OM0U;z`O54ELuw`McmTK*nh zKK(V;Y?y+i*d(fnY=cQWjBeaggQVCb9Dgqdv!CYQG&o6_2@-C}_mb~?FprzY8z*ao z674*&^lnYD!HvdUH&NMM&+Cq;O6ItnoAepTF_x+V@Ok`qqjKiTiemJ1b_!~TY=a3& zu}QoPVXPh)s|UvFff4%l&*Amw$Nz@k-+xf^MO%wyA4Jkv>$>bgS6>%Sls_8Q1KP_= z1nU3*NZUPSi`5h`dfBK_!G$`oNx3cOefO)$tZKvcK5aw_jbNQnt9 zc=9s5putGG8uo?szs z+;tNy%L>NS0te(bJjv0C@<(y@r*SBMwVsAj*JTfO9$1RXr@BNn&tt%(&j@N^SE)cU zYc@=|+uz?M4j}K1z1X+C2z6#J3e#eEHqQlL^m)G|6WoA7Ovde=Lcw?Sb-^>xGFA_a z)dOSoKxjSC*rZ;Iy_alwv!H+U;K@8(m|c~-bul6tm411!t(-Vvv!rov*e!0B{~#%i%R zPWE?>mYNR+cdlD37T%cC=@c*`h(e(+xXDc{77LX~Pp9!K~l{0baujKv+*R_*c9NIQz+QbkQi==Oh``V3BhKw z$!>8FUC7FEbE%|4|Gg2aLM|O{ok0D@ZnsNbC%56FEH_tBPmq6esAfQpSeC`_>*{3f zlm?ISr6+uGATZ5sgHvo9d|Km-P7Phf9I=wLI;N)dN3-dfc(YE3`mciWlCr zkDTYM@BMSu`rdyhS$A^ZvuCcExn}mg_Fg+qOG6PKml_uU0N^Vt!E})SG02Ms8x#3! z0DaB}08rNi=^6UySos4zyxi>^UEn~UKo2+&9^hyP00b;m=Qw&X38zQheI)fp|Lj4F zRk^rgnJm2yWl`m5YOl6uSFz=zqKY`#;ZFA0>$?5kez#$vKKsTrXV$!O&*G@kMo<3*L#nT-+;TqVmq=fvZcDtE<)~3q-y)l&u=@GE<|tlVA8z38~T?Y z32Yv%=XZ5Ucd;g(&69*YOzqtp4h@q&k<^Y~C)*i6K73QO)b?I_eaU>CbMM&X?A@Jc zlc6d;_jgIfb>lA`&HLVrFHG)ra-R7YeM_1gr;+Zuqop>|m0)KYKYw;$pQU^kBXF^J zNuMryAMcpr?lx5?AmY3vow;u6wsYd7EAn!0;fAOU(PU59@KSAlSVgWy z?X8Y5`%iPBt_Hgw!Ae(>)o*XFE?bUczIhkrOP5&8r*!FmyLubn)s^3NC>_)LQ*`y* z?ags%TS6LVeffIsRolRM{KwLw3n~3er?+CS<^l?9KRmtMq!4WSSv1X38yvfR8%^s+ zxf%UEw5HC`I+;}{bg-3nr$9J~=|`(Mk!?s64Gp|LLmQGnt4i-K` z^Jhskw4v?e>~=U|qz{AQG-wSkE8Mq2I`ChWe%4VI6!e0AOs{%=@5gk5Hng}TU6sA5 z(fZ|66rsxRPOkbV62?w#Sq3J~yT2OYi>TIKyNgK^>|4*lmEo;}5ram6KJ!M!} ziI9(K{NsFwF4K1Y-dw}>JNgD@u8RlGpIfI(d;C{jmyd#GGuOIU%V1CD`Upe9QUmq1My0}Xhp8veVeQUwLm)Rc1?|t{I zrE6q~T$St2QL(8o@_=O3|L4lrUD5fPYV=CeB%dFXL7N&I+mFt?LS`QkKU&p%>$~E0 zHTvjnOV-(a`+Rvqsb{<6E9!>+)?W(uOoa`>TTDxlOM|%)u@jKE*Uz0@BU{A1qN(hv zUmpvN)OQ+4#T21LeEO90Lzg+D&&w*WgG3@&(*bc>B5uMdP83U|gP%)~DSpkIR_oM% z`Eo~4X$&=RFMEtl$=SYI$e^qLaj(eCIXBQv86mPNHO{g5Lb7IE%nof!US$4y=Gg9W z!W*%NPUm)B>!-~rO$U2%o=2%8rp`E&Pj@`R^JPV!4`7JcnSs2g!3J$}>lnzV-(6x#U z5<^=J>>oURtrL}1big@g$Ty%!CkI>A7V9j>YpFIN_|#=paU-!DAA z=7uEO8L@|7;?m^7=`_-0p(SV2=)iqt@*kC0j_tWszp+}G9V zDv#ZMS}9&Jsl(;Gs(`pd~=Zo5|J)PK#TB)7tA_w!71v>ppX16#0q}CnNFt+ z_z)2FW#&NzpGwFi=4q>z%V)7^;K~U$a29K^JrkN;reMqnPqf(i(OmXO&wWMqCA6VI zH95g4uQ56on?|GCvPpwnmW=o3r%wWP;;nsOj#ex1-EvgKh^C&Q8r}lN;8Kc(%_^nK zrRC1Xm3=f+k?oJ7cR4niRijycMDd4{?v45e6U|HzylHttzV63b^)+(ChfhCr^GcWH;W44G6 z;Mr{xzt_n`_=AZ53m)+mthUtlBX*en>#!O_>l_D74VX!#A5VYbs_oswmC6f9y%L8cknL1l-&kgvd+vRx)apO&Zd&o- zz-{jd0ggsnlrCO%w|+>n2QIDbCmf4g=F^^O1JlR1yX7;uM6U}!yvNFWDo(ukO?Dk6 zii#broW6vao<;YC0Kd+Ch-~2Nj>FONV~lbKF`2#Y6P%lEg}n|>j!A4xTPr!Po;?0Y zLy9!tmx^zTaNcj1WS7Y0JIV1AHGJ*IEfEuE<72WJ%1WO&Tfq5}j-{l++UK6SRBzlO zzTH(OJobP%yGT^YVJ`8i8UW^{xFX0VczR)Y^L6M2?3wmtnZ^x(DTOi$iyuLZiA$~x z5FbawE2fD&!fOV+Qgi;geSZ=wuQ-*B08C6=V9T~RLuZTDe%j%H9xwuwlE8H*&Xbp% zumpQGGC#1>BA_7ApDsEz%-e^OP7lm@gvy%bk{$=}B^}K8CnlR|3VVJG^|h>sNwVB@ zu;Nn{yl63(=X8(JkJFiM`^v%*qCJV-4LO7yxm2{4^DSXP7~Ak8AgDIKA z(|~@~G#`R2j%IA5WDLbq@AZ5dEMl?qR?e3&*b}E3v1)=4yhw{@WG*}3N=T~EYiZyK zmaq(+T}FyeZVPpmmHRV1?m=`e#X*Bi_C<3yFre zO42&ynx+HYV<^@`pJSuKdp8hbt1ki;lZs(P&-CL%K136@W{TKdsvTg$*R&Tc@zrqO z0ZOoOv}!kJwag7>K|_s%b?WovVm;->zL>-$cU*I$9Xo zI*mMd&|B=h;!(o*#Lrn~cH~DaSTcb^_E@+_3(H%S@I}+WyGeM0TsXZAbZ�@L6zi zolZa6u!%DsMmt_=IESl4zox%cG|KlFy-og!)CGN2TvKjVjTe}wi$%-=qD332`e|l7U}O7gCL9@0UZu*w zq%Kr4Pw-$7-WxCG(~*MjMwV7>^Me6(GMkw@ZwwZopy-S?B$=oTV zB}9v&!A6lBXbGHfTHNGQ3yPvCa(Fy|(Lu`~u9vLUQ#ep$$ui3pg_{n{3O8y$8dK8S z>@E=R+$0VzOx5G3PA`0VqG5gXDn(1!!;|9#&>;3eP3xjGj#tj?O#lhTLqM4NRXas@ zL4rYdD(b+qc@OWl^kq}lsWafAsV(OWhBb4F?93xhmUtJ_r$mf8DQHo=v*=t6*w5K8 z{WUVD=E7-Bqp8q(%@hhPl1?3VWObq5jow~bWcQM0wDzeZGVAMbhGdjuM1zy^(kJc8 zY<0xYg4RvYV^xX_TI?V`F>iblxD2}2#?{CQ%xq`f&zocsl%~@FYOTF!+#_OoV@qAK zZsPa4U$-Hmui!+lp@QKR>U(tiYH5;XxcJbbPW^V=p>)w;I0lLS=0!%<%CviGc&19MsnN`ms#z z)J-;lo#F~P3SwjS$B9k*^n}PYw{5Q|%cDfL^zUvLD*Gwy&It!!QMBZ9m=t^I%NT|t zb`P|Wm8i_fRg2W~>EnNr+wFU|!u&KslBrIBRwf_ijhieq$B!^t-4#fPrcZB-kQRlV zb#)b*-5d8Uio&GhnH|K^Zf>A?h7rT{i7vmXWt416j^Cq(Op;S%OgN}SS?L(Hlp#@n zuM&gz7&f-4Ys>K@L#C%t%>g6W-}AeAF$Ty}z-NTS+syM57AA^cz4z4DN8}$CsCA2v z!~KJ}d-2Z8tEhJp5DMQyp3^u2Th_qE)Y7k8nRU)|7;|VD4|&rMW8ZcJ&#~Z*amnS1 z!l(dH;!d+>)yAXVwzDcKtQJ(IIJ<}MKI?zEA-?ySR4ZXPektdmBTL|vff`iUPfCU$ z^1t83rA1mCD3-lGGox03x)EuLburZy*bT51q7C`SEbTC1S%I+c;Ko~Cg5snEYVA9~Psa#(f=qnKOFLTY@P)W4 zmiszygxFbU`64Dnl3tDG(=oo?2*+&JxlWp6Y7}PgvSOVNpY`6gx3{vp-IMpud>JwG1}hxyD0g!Mlf+VYo+d$Z8jC>ULFMvys- z;dbA7J%V_nvbQO^Dq`F29Ua35zY?d^?JAxCLu+|z;`RZmaLo0DJJU;Vvx@f42n;L` zrW%p@Ov_#SZkm*yABnd>v4$Ep#<=6lyj62DMO{iI+5$EvinXKV8Z z0wLrk7&gh$L_=)fr24V<@TuD#zT~2|GR}jZBb(iO`>?kG`0h3aEU0nusF1HsRNtIx zu**|Pmnd#1;oIXc&yEIP&aq+$w)OYvW+J}P%UHVOcG1Ef-0pTmgy@AYnTC*xvO3`y{1TJ!dDcg$7N0vjo)z;HF0yE5{oZiJ8kuPi%H*f^pp9 zJW^_h+lUFK6~()mkESMukZ|D=LdXzX7tj(mX8I_*lB-pr2C9$2bfjpH$h8;+i7!0v zV{ug8EjF;JmMKs(x>a#Twz&fL3G?kf-^u%(tWHjiCX zFjpQUC`~}bl#JQImT)=vp(KZ8b~mrNiH9@eT$vLjEkbmYDHFIIs<=P)89shuEM+=5 zGs7cNQYkwAb1&*Jl%qupg>5KHp(3CimO4{HGA$-hKZsed*d$Mo+8LAr{a%~;Lr-1+ zhOoPiIhk58oPfX=8#CNa3vF0pJvjQ=n%6v-^>+A$%#yhnz}Q?KhH}@ z?QK2AIp>HuW+)E zHp5Tl!_?rnNJ63lUCAmikaA2h7FvC!F(UHpdn34;kp z41-ZtWfYSl=P|rVCD&nFat#gGF0mzQd7iOr0KlJ>H3@pzrRhPxh4MMhnv<3^lKwU| zW8TJlDI#pzZHOp0_N+}OeS<#H=tfuUNICC26Zs2rdBp1#Ewk?+vLsrz^a5_zTyVJz z+gMT3D-UcArsQW^^ebKIgaH)=_;!YYYU=F*&`1b)$>jB9kil_g$%oC3UNL37^NKJ2 zAk~WrLSlfAZ-RUZaY%l#5mW90eqeUFBx(?Dt1Fw(+^aa{kaoG{3Jg=Rdkd9q2I8nL zC3)5386&dS*enJtGXi_lA1q}aDCBS-;;@iEJK>wrtaQIK9FKK0)bMnC0X^Sb-*-JC zIaj=zSq`U^ba{`HE8IXf8xh=*Q|;F`Fqf{x?lT^+Dnoz&z}Y$xzr*2dY$`&!0Ta^KGi z_ojUinmtUij%b|}yt!H7YCzJIBp1K>fX#PY_{B6f{>ddqzx%i@f$buR)ryBxdA~&_ zuAKyeD{umY*w6rW>AtmRr~PEG0o!ia>BYBCTNvOvp z%On%b>=Sn}0w{*2tmlk~`jRM-WC@nsS!%N(%EvvT@B8@}t#du~OTeQ0{F$$3eIw@! zzcCquh0){vL2gm)6;gf^FG5jMROW3%e8zb6#C82X$=(F(JTAg5O%l9~g>v3@ez@H$ zd!eCY%|Pe5p+Y?%AGJN?x7MeXG4WM99KAC1mn>yyE<9X_(K3AB?ejAFFbOHNjh{V_m{b+VY0^#; z8IFlISFQ4dlc~9+UViD=*DX5%QoEw{uQ_QS7A=jo?klwF3tEe*dWg<9yY zL>vg?LVc_Z)vf|%X!_O`TPr#3jbW8otH|NO1_yQ|1JKP)Bc4ZR>n>d`!H^*N`s>l! z$0ItRUV_@|B^H2s%NUG{qjaj$`W``?6QQp7qSH$8R7UU`n6S=f+=*ned{aD-t!UEalD-O{Suz3hNFV@ zQ~g}-PW{vU5A>(mEtCSQywtdOe2n!1mQRC}~O7&R> z%Lnz9w6 zeZFJu;94XEkUpb-gDE0{uHc>7xwf^MH`e(xxO8ouV8Fp^Xn8*H9`cBh+7Wq_XsE6x zX5;S4V`b}Z4d)4P^*|mq0ss=y0UlO1&Tt=~HQe6OO%incrV9jgw3P%s6jTSRdqCk1 zj!HpZaNQscJ)0nB8&O-3v=pvHfEW_M74BmN3~+UE^A-z`1pUSpL*D-q^MZiCReYQ! zL5AvDK&ZPH94Npezys!%4{-G314-cmCA@6y#B^W^e?lOiBtZ^7J|1Gcy#D_FJpTMV z?q2r15K&Q4UN9doA0IbTgWEgM&BrQ$+s&Kt7sMYJFu1pkm!pS|qq`gM7p9f9yRVNV z2!tF5{uQ6Ahr0UT@NV9JvVi1+H^9n+7s3PPb#>+ar-iqVydM(e&w&0{3vWH-i7c-U z+}qvP%LXp*2Y2&f{3nF1&ENJOzFscB)3LSTg}cCAk*eNEuaJLpsi>^3^|!?@3hW(S zJ$_pu$^JJ@A4j`?k@at}{Tlh5&OZY|n*WXaZ`yz5{#zNTrLHapbGPyR6`nFo67DXK5dmRtQDI?gZa!fVL4JN~I{`t+KOr=|9FbjV zIJv*are@5cXyEl{R#>A%kp=7110__ijt!@QX}wJ$N$;$x^T}wp8l8uE{?y4fWY5v zD`sW$hZAorKe+90M@YLrhHMMTfx7I^*6e=yPc1}l^0yr9+@dJ8)O6h&IZW#n@aY7kHy~s{);Ct zAA}n$$_)|GgNTZOA!7UxPB5Psl2hJ46XyLjtN+Sag7^R7MB=x?KVAb!yFX;e*9-D( z#ryZ`>QByo(fEJ(`Lh=PhaQm7|8?>o@%vx8{!791kTUZvcRY@z;eC@KV|j zDa7(oR+q=x!67C>VK{xohJ_SS`N$jkK;2z`t(yVAmveAipueM!1Mt^!?qS4z3IG62 zN*N}r=dkw0nA>|7@Fbl4WveVZ#BY)Q0i!d6EioC>O$8#yL zS|o$f=kHuEb&4Blbn@pUeR;n2wsWuZO%}!|OAmh!W#7P7{{#hZb}IDX1|=Mf0eqP` zDvrws;dz2_#~Hpu6o}ys+K?a1&*>XQKhr|{-oUbY8Y=iWlUNR0`N3e%)Vj+P^n@YK zXCx@c`jqR^#TB72qCpsuF?q&9M->XF-mq6m)C%2PTO@ExoofyQ%|Gt~jXoA)E;VVDl46!wBejw;#0JAD z%qUrC23~L}f;2TKNjKkZ&5*@f&z_~s^lEV`&b-$lsbHLY4EDe?hlpOTF=l~%Xmmof zrjvg1bn$#-?T)Hgij0HzS$Z|(;P4V2g0OC-oNr==wkF)t*J_K(pQpnp>@vT1VDzz- z%0KEzy`hRqLrcOQ8OMgcet{q&p8x42R6fDu)tU0P3IK@5Ke_hW3rXZx;MX9FF0POl zh9-VH+dbi*-CH0Te77jedX`I4xzOs_zV>bqV2+1hEqzuvChoMef&QL(7oveJ+iqx> z9H)a(NfgaM{w~;%(Kw>6z3@34p4(~-y*AK!he-TraG%8BoZsJ6m6&|KjC3f$3`m9P zHWQ;VcVM-mxvxQ}f_F%~b=4H)5=@KOQ}la&pM0LWKF>k-Eh6;N5u<3i3U!A>A5EBA8_g=EUYyJ3`18Y_jjT39O zn6<+Zy{b@evRI%8_xn=N)R{q`EVXz=aV8F}G3(b+Ro28jK9&*9WJyILul5Dag4Y>_ zr{X=2ck~hJ;5(mbqQR$cB+avrJrk^>(Lopn`w%be4moRQ1orMr5`}ch7R+LrZbK+5x8YF(?y5jO1=Yqom&y1Mq)I4#7SS)m~(!s1~YQ&So zQB~6^U&y$Bta9Gstd(o5)hB;pIH#{HbDe4k2`pj>5=1Ddp@cH3h|#W-Vj)H6aS#8X zz>95v3dd(E9&>l~*K zK$>Qiya5glfsq1buY0^Z)H%0*@3iLk16&?*olW09IXFx>l zGmw+Ol$f}BdstsTLUZ>+1=iGnU*v?9Gl}!624EynD<+O!4p_DoeSy)p_c9=hhiF(a zTDW-VO`=vzZ7d-@AFQhvIh>cP!{3c^z>-u}tXBK^c~!$x4f`bKcmd6OTzWZRfB9^5 zim8|}gH>`byX$Hn#50tb_Xs#q`#>9O_E?5Vfj^06CZ~0GN2on&} zc)rxnfKM+`>tX`%d+qS=l!1i;!?#PwZ6OUW;Dx?kN=15MO#m89%g^YTU`eW@9oOS> zc2q;Vn7F0g6R+sNAy8J!EPW9xLJ!TLvQdjFwk4J(ID zy0`~u!RqaFl*5h9zm4bYDlJ%_zIWm(xZB(urlIA6rJY#4ScqFkX#>%;z%+P%aTP>_-p+t}9%bok`77%@ Date: Sun, 5 Dec 2021 17:51:18 +0100 Subject: [PATCH 072/102] meta: better settings --- .vscode/settings.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6f4ea8e..766e731 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,13 @@ "utils", "birb", "enum" + ], + "Lua.runtime.version": "LuaJIT", + "Lua.workspace.library": [ + "${3rd}/love2d/library" + ], + "Lua.workspace.checkThirdParty": false, + "Lua.diagnostics.disable": [ + "redundant-parameter" ] } -- 2.30.2 From 87d4bd389d3653bc4b88dd4a13a64f0531f119e8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 Dec 2021 17:52:27 +0100 Subject: [PATCH 073/102] improvement: handle via gui the overworld hud --- .../scenes/overworld/actors/player/health.lua | 17 ----- .../scenes/overworld/actors/player/init.lua | 15 +---- .../overworld/actors/player/interactions.lua | 9 ++- .../scenes/overworld/actors/player/team.lua | 22 +------ .../overworld/gui/hudelements/emblems.lua | 30 +++++++++ .../gui/hudelements/interactions.lua | 25 +++++++ .../overworld/gui/hudelements/lifebars.lua | 25 +++++++ .../scenes/overworld/gui/hudelements/time.lua | 12 ++++ .../scenes/overworld/gui/init.lua | 65 +++++++++++++++++++ sonic-radiance.love/scenes/overworld/init.lua | 49 +++++--------- 10 files changed, 181 insertions(+), 88 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/init.lua diff --git a/sonic-radiance.love/scenes/overworld/actors/player/health.lua b/sonic-radiance.love/scenes/overworld/actors/player/health.lua index 96bb584..47a6448 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/health.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/health.lua @@ -1,27 +1,10 @@ local PlayerHealth = Object:extend() -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -local HPBAR_SIZE = 80 - function PlayerHealth:initHealth() - self.hpbar = ComplexHPBar(HPBAR_SIZE) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) self.fallDamage = 0 self.fallSound = "" end -function PlayerHealth:drawHealth(x, y) - for i, name in ipairs(game.characters.team) do - local yy = y + (i * 17) - local character = game.characters.list[name] - self.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX)) - self.assets.tileset["charicons"]:drawTile(character.data.icon, x, yy - 3) - end -end - function PlayerHealth:takeDamage(damage) local damage = damage or 10 damage = damage / 100 diff --git a/sonic-radiance.love/scenes/overworld/actors/player/init.lua b/sonic-radiance.love/scenes/overworld/actors/player/init.lua index b9c17af..5c0f9cd 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/init.lua @@ -42,7 +42,7 @@ function Player:new(world, x, y, id) end function Player:updateStart(dt) - self.interactionName = "" + self.scene.gui:getElement("interactions"):setInteractionName("") self.tweens:update(dt) self:updateTerrain() self:updateActiveCharacter() @@ -121,19 +121,6 @@ function Player:timerResponse(response) end end -function Player:drawHUD(id) - self:drawHealth((424 - self.scene:getEmblemsPosition()) - 48, 168) - self:drawEmblems(self.scene:getEmblemsPosition(), 24) - if (not utils.string.isEmpty(self.interactionName)) then - local w = self.assets.fonts["small"]:getWidth(self.interactionName) + 16 - love.graphics.setColor(0,0,0,0.5) - local x, y = 424 - w + 4, 240 - 24 - love.graphics.rectangle("fill", x - w/2, y + 1, w, 15, 8, 8) - utils.graphics.resetColor() - self.assets.fonts["small"]:draw(self.interactionName, x, y, -1, "center") - end -end - function Player:draw() Player.super.draw(self) self:drawActionEffect() diff --git a/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua b/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua index 6fa9ccd..0f8dc5c 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua @@ -24,7 +24,6 @@ function PlayerInteractions:initInteractions() self.lastPos = {} self.lastPos.x = self.x self.lastPos.y = self.y - self.interactionName = "" end function PlayerInteractions:updateInteraction() @@ -36,12 +35,12 @@ end function PlayerInteractions:collideWithGizmo(other) if (other.needButton) then - self.interactionName = other.interactionName + self.scene.gui:getElement("interactions"):setInteractionName(other.interactionName) if (self.keys["A"].isPressed) then other:doAction() self.haveCollided = true self.lastCollision = other.creationID - self.interactionName = "" + self.scene.gui:getElement("interactions"):setInteractionName("") end else if (self.lastCollision ~= other.creationID) then @@ -54,12 +53,12 @@ end function PlayerInteractions:talkToGizmo(other) if (self:faceRightDirection(other)) then - self.interactionName = other.interactionName + self.scene.gui:getElement("interactions"):setInteractionName(other.interactionName) if (self.keys["A"].isPressed) then other:doAction() self.haveCollided = true self.lastCollision = other.creationID - self.interactionName = "" + self.scene.gui:getElement("interactions"):setInteractionName("") end end end diff --git a/sonic-radiance.love/scenes/overworld/actors/player/team.lua b/sonic-radiance.love/scenes/overworld/actors/player/team.lua index ab44f0f..eba901a 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/team.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/team.lua @@ -1,17 +1,7 @@ local Team = Object:extend() -local Emblem = require "game.modules.gui.emblem" - function Team:initTeam() self.active = game.characters:getActiveCharacterData() - - self.emblems = {} - for i, name in ipairs(game.characters.team) do - game.characters:loadSprite(self.assets, name) - self.emblems[i] = Emblem(game.characters.list[name], self.scene) - end - - self.activeVisible = game.characters.active self.canChangeActive = true end @@ -42,23 +32,13 @@ function Team:switchActiveCharacter() self.active = game.characters:getActiveCharacterData() self.canChangeActive = false self.tweens:newTimer(0.3, "changeCharacter") - self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + count}, "inQuad") + self.scene.gui:getElement("teamEmblems"):changeActivePlayer(count) end end function Team:endCharacterSwitchAnimation() self.canChangeActive = true - self.activeVisible = game.characters.active self:updateCurrentCharset() end -function Team:drawEmblems(x, y) - for i,emblem in ipairs(self.emblems) do - local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90 - local rad = math.rad(angle) - local emblemX, emblemY = utils.math.lengthdir(18, rad) - emblem:draw(x + emblemX, y + emblemY) - end - end - return Team \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua new file mode 100644 index 0000000..c0fbcf5 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua @@ -0,0 +1,30 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local TeamEmblems = GuiElement:extend() + +local Emblem = require "game.modules.gui.emblem" + +function TeamEmblems:new(x, y) + TeamEmblems.super.new(self, "teamEmblems", x, y, 50, 50) + self.activeVisible = game.characters.active + + self.emblems = {} + for i, name in ipairs(game.characters.team) do + game.characters:loadSprite(self.assets, name) + self.emblems[i] = Emblem(game.characters.list[name], self.scene) + end +end + +function TeamEmblems:changeActivePlayer(count) + self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + count}, "inQuad") +end + +function TeamEmblems:draw() + for i,emblem in ipairs(self.emblems) do + local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90 + local rad = math.rad(angle) + local emblemX, emblemY = utils.math.lengthdir(18, rad) + emblem:draw(self.x + emblemX, self.y + emblemY) + end +end + +return TeamEmblems diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua new file mode 100644 index 0000000..efb3bf2 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua @@ -0,0 +1,25 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local Interactions = GuiElement:extend() + +function Interactions:new() + Interactions.super.new(self, "interactions", 428, 240 - 24, 50, 50) + self.interactionName = "" +end + +function Interactions:setInteractionName(interactionName) + self.interactionName = interactionName +end + +function Interactions:draw() + if (not utils.string.isEmpty(self.interactionName)) then + local w = self.assets.fonts["small"]:getWidth(self.interactionName) + 16 + love.graphics.setColor(0, 0, 0, 0.5) + local x = self.x - w + love.graphics.rectangle("fill", x - w / 2, self.y + 1, w, 15, 8, 8) + love.graphics.setColor(1, 1, 1, 1) + self.assets.fonts["small"]:draw(self.interactionName, x, self.y, -1, "center") + end + utils.graphics.resetColor() +end + +return Interactions diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua new file mode 100644 index 0000000..99e0640 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua @@ -0,0 +1,25 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local LifeBars = GuiElement:extend() + +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local HPBAR_SIZE = 80 + +function LifeBars:new(x, y) + LifeBars.super.new(self, "lifebars", x, y, 50, 50) + self.hpbar = ComplexHPBar(HPBAR_SIZE) + self.hpbar:setColorForeground(248/255, 160/255, 0, 1) + self.hpbar:setColorBackground(112/255, 0, 0) +end + +function LifeBars:draw() + for i, name in ipairs(game.characters.team) do + local yy = self.y + (i * 17) + local character = game.characters.list[name] + self.scene.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(self.x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX)) + self.assets.tileset["charicons"]:drawTile(character.data.icon, self.x, yy - 3) + end +end + +return LifeBars diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua new file mode 100644 index 0000000..f02a3d6 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua @@ -0,0 +1,12 @@ +local TextElement = require "birb.modules.gui.elements.text" +local TimeElement = TextElement:extend() + +function TimeElement:new(fontName, x, y, align) + TimeElement.super.new(self, "time", fontName, "", x, y, align) +end + +function TimeElement:getText() + return game:getTimeString() +end + +return TimeElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/init.lua b/sonic-radiance.love/scenes/overworld/gui/init.lua new file mode 100644 index 0000000..0241f3d --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/init.lua @@ -0,0 +1,65 @@ +local GuiScreen = require "birb.modules.gui.screen" +local OWScreen = GuiScreen:extend() + +local Composite = require "birb.modules.gui.elements.composite" +local Counter = require "birb.modules.gui.elements.counter" +local Asset = require "birb.modules.gui.elements.assets" + +local TimeElement = require "scenes.overworld.gui.hudelements.time" +local Emblems = require "scenes.overworld.gui.hudelements.emblems" +local Lifebars = require "scenes.overworld.gui.hudelements.lifebars" +local Interactions = require "scenes.overworld.gui.hudelements.interactions" + +local show = { + {"rings", "movement", 0, 0.3, 16, 16, "inOutQuart"}, + {"time", "movement", 0, 0.3, 408, 250, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 368, 24, "inOutQuart"}, + {"lifebars", "movement", 0, 0.3, 8, 168, "inOutQuart"}, +} + +local hide = { + {"rings", "movement", 0, 0.3, -16, -16, "inOutQuart"}, + {"time", "movement", 0, 0.3, 408, 250, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 500, 24, "inOutQuart"}, + {"lifebars", "movement", 0, 0.3, -124, 168, "inOutQuart"}, +} + +local showMenu = { + {"rings", "movement", 0, 0.5, 8, 8, "inOutQuart"}, + {"time", "movement", 0, 0.5, 408, 221, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 500, 24, "inOutQuart"}, + {"lifebars", "movement", 0, 0.3, -124, 168, "inOutQuart"}, +} + +local hideMenu = { + {"rings", "movement", 0, 0.5, 16, 16, "inOutQuart"}, + {"time", "movement", 0, 0.5, 408, 250, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 368, 24, "inOutQuart"}, + {"lifebars", "movement", 0, 0.3, 8, 168, "inOutQuart"} +} + +function OWScreen:new() + OWScreen.super.new(self, "hud") + self:addTransform("show", show) + self:addTransform("hide", hide) + self:addTransform("pause", showMenu) + self:addTransform("unpause", hideMenu) + self:show() +end + +function OWScreen:createElements() + local list = { + {Composite("rings", -16, -16, { + {Asset("guiRing", "images", "guiRing", -1, -1), 0, 0}, + {Counter("turnCnt", "hudnbrs", game.loot, "rings", 3, -1, -1), 14, 1} + }), 0, -100}, + {TimeElement("hudnbrs", 408, 250, "right"), 0, -100}, + Emblems(500, 24), + Lifebars(-124, 168), + Interactions() + } + + return list +end + +return OWScreen diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 8337da9..bf9df30 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -33,10 +33,11 @@ local gui = require "game.modules.gui" local TweenManager = require "birb.classes.time" local EventManager = require "game.events" -local MessageQueue = require "game.modules.messagequeue" + +local OWScreen = require "scenes.overworld.gui.init" function OverWorld:new(area, playerx, playery) - OverWorld.super.new(self) + OverWorld.super.new(self, false, false) self.charsetManager = CharsetManager(self) self.assets:batchImport("assets.overworld") @@ -52,17 +53,15 @@ function OverWorld:new(area, playerx, playery) self.backGroundOpacity = 0 self.borderPosition = 0 self.isPaused = false - self.canPause = true - - self.borders = gui.newBorder(424, 30, 8) - self.emblemPosition = 368 - self.ringBorder = -16 - self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad") - self.timeBorder = -10 + self.canPause = false + self.gui:hideScreen("overlay") + self.tweens:newSwitch(0.6, {"canPause"}) self.isPlaying = "" self.events = EventManager(self) + + OWScreen() end function OverWorld:updateCurrentMap(map) @@ -113,8 +112,10 @@ function OverWorld:update(dt) if (keys["start"].isPressed and self.canPause) then if (not self.isPaused) then - self.assets.sfx["mSelect"]:play() - self:pause() + if (not self.gui.screens["overlay"].isVisible) then + self.assets.sfx["mSelect"]:play() + self:pause() + end else self.assets.sfx["mBack"]:play() self:unpause() @@ -124,10 +125,8 @@ end function OverWorld:pause() self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") - self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad") - self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad") - self.tweens:newTween(0, 0.3, {ringBorder=8}, "inOutQuad") - self.tweens:newTween(0, 0.3, {timeBorder=19}, "inOutQuad") + self.gui:showScreen("overlay") + self.gui:playScreenTransform("hud", "pause") self.isPaused = true self.world.isActive = false screens.mainmenu.pause(self) @@ -135,9 +134,8 @@ end function OverWorld:gameover() self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") - self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad") - self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad") - self.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad") + self.gui:showScreen("overlay") + self.gui:hideScreen("hud") self.world.isActive = false screens.gameover(self) end @@ -155,11 +153,9 @@ end function OverWorld:unpause() self.tweens:newTween(0.1, 0.2, {backGroundOpacity=0}, "inQuad") - self.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad") - self.tweens:newTween(0, 0.3, {emblemPosition=368}, "inOutQuad") - self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad") - self.tweens:newTween(0, 0.3, {timeBorder=-20}, "inOutQuad") self.tweens:newTimer(0.2, "unPause") + self.gui:hideScreen("overlay") + self.gui:playScreenTransform("hud", "unpause") if (self.currentScreen ~= nil) then self.currentScreen:quit() @@ -195,15 +191,6 @@ function OverWorld:drawScreenBottomLayer() end function OverWorld:drawScreenTopLayer() - love.graphics.draw(self.borders, 0, self.borderPosition, 0, 1, -1) - love.graphics.draw(self.borders, 424, 240 - self.borderPosition, 0, -1, 1) - - self.assets.images["guiRing"]:draw(self.ringBorder, self.ringBorder) - local ringString = utils.math.numberToString(game.loot.rings, 3) - self.assets.fonts["hudnbrs"]:print(ringString, self.ringBorder + 14, self.ringBorder + 1) - - self.assets.fonts["hudnbrs"]:print(game:getTimeString(), 424 - 16, 240 - self.timeBorder, "right") - if (self.currentScreen ~= nil) then self.currentScreen:drawOverEverything() end -- 2.30.2 From c4db0f7d1499335121a5761bb59c8cd0c6a63e22 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 8 Dec 2021 11:05:46 +0100 Subject: [PATCH 074/102] fix: remove subscreen handling It'll be better handled by a special exclusive screen system --- sonic-radiance.love/birb/modules/gui/screen.lua | 8 -------- 1 file changed, 8 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua index 4a6eb49..d4906c6 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -1,7 +1,5 @@ local GuiScreen = Object:extend() 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 "birb.classes.time" @@ -31,11 +29,6 @@ end function GuiScreen:update(dt) self.tweens:update(dt) - for _, screen in pairs(self.screens) do - if (screen ~= nil) then - screen:update(dt) - end - end end function GuiScreen:show() @@ -69,7 +62,6 @@ end function GuiScreen:reset() self:initElements() - self:initScreens() end function GuiScreen:registerElements() -- 2.30.2 From 7ca60da3fd3f6b1c9e683097794a223bcca7ad4d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 8 Dec 2021 11:26:27 +0100 Subject: [PATCH 075/102] chore: add a screen package --- .../birb/modules/gui/{screen.lua => screen/init.lua} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename sonic-radiance.love/birb/modules/gui/{screen.lua => screen/init.lua} (94%) diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen/init.lua similarity index 94% rename from sonic-radiance.love/birb/modules/gui/screen.lua rename to sonic-radiance.love/birb/modules/gui/screen/init.lua index d4906c6..c9049c8 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/init.lua @@ -7,9 +7,8 @@ local TweenManager = require "birb.classes.time" local elementDataStruct = require "birb.structures.elementData" -function GuiScreen:new(name, controller) +function GuiScreen:new(name) self:initWrapper() - self.controller = controller or self.gui self.name = name self.isVisible = false self.transforms = {} @@ -17,13 +16,15 @@ function GuiScreen:new(name, controller) self:reset() self:registerElements() - self.controller:addScreen(name, self) + self.gui:addScreen(name, self) end function GuiScreen:initWrapper() local scene = core.scenemanager.nextScene or core.scenemanager.currentScene self.scene = scene self.gui = scene.gui + -- Présent pour la compatibilité + self.controller = self.gui self.assets = scene.assets end -- 2.30.2 From c7c9e37c998f314fadd939d11febe6dd5a91bea2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 31 Dec 2021 14:25:43 +0100 Subject: [PATCH 076/102] fix: fail if a label is absent --- sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua index 5d784dd..7809d04 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua @@ -40,8 +40,9 @@ end function TextWidget:addLabel(label, position) local complexLabel = {} + assert(label ~= nil, "Label can't be nil") complexLabel.label = label - complexLabel.position = position + complexLabel.position = position or "left" table.insert(self.labels, complexLabel) end -- 2.30.2 From 1a889163ae03deba03e62ac2dd5f11896d46e167 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 31 Dec 2021 14:27:35 +0100 Subject: [PATCH 077/102] feat: new subscreen system --- .../birb/modules/gui/screen/init.lua | 45 +++++++++++- .../birb/modules/gui/screen/screenset.lua | 69 +++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/birb/modules/gui/screen/screenset.lua diff --git a/sonic-radiance.love/birb/modules/gui/screen/init.lua b/sonic-radiance.love/birb/modules/gui/screen/init.lua index c9049c8..e4a3795 100644 --- a/sonic-radiance.love/birb/modules/gui/screen/init.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/init.lua @@ -3,10 +3,10 @@ local ElementList = require "birb.modules.gui.mixins.elements" GuiScreen:implement(ElementList) local TweenManager = require "birb.classes.time" +local ScreenSet = require "birb.modules.gui.screen.screenset" local elementDataStruct = require "birb.structures.elementData" - function GuiScreen:new(name) self:initWrapper() self.name = name @@ -33,12 +33,29 @@ function GuiScreen:update(dt) end function GuiScreen:show() + self:showSimple() + --TODO: show parent if we show directly the child + if (self.set ~= nil) then + self.set.owner:show() + end +end + +function GuiScreen:showSimple() if (not self.isVisible) then self.isVisible = true if (self.transforms["show"] ~= nil) then self:playTransform("show") end + + if (self.subscreens ~= nil) then + self.subscreens:show() + end + + if (self.set ~= nil) then + self.set:setCurrentScreen(self.name) + end end + end function GuiScreen:hide() @@ -50,7 +67,12 @@ function GuiScreen:hide() self.isVisible = false end) end + + if (self.subscreens ~= nil) then + self.subscreens:hideCurrent() + end end + end function GuiScreen:addTransform(name, transform) @@ -97,4 +119,25 @@ 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 \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/screen/screenset.lua b/sonic-radiance.love/birb/modules/gui/screen/screenset.lua new file mode 100644 index 0000000..357ba3f --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/screen/screenset.lua @@ -0,0 +1,69 @@ +-- screens/screenset :: a set of exclusive screens +-- Useful to handle a complexe menu with several screens + +--[[ + 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 + 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 ScreenSet = Object:extend() + +function ScreenSet:new(owner) + self.set = {} + self.defaultScreen = "" + self.currentScreen = "" + self.owner = owner +end + +function ScreenSet:show(screenName) + local screenName = screenName + if (screenName == nil) then + if self.currentScreen == "" then + screenName = self.defaultScreen + else + return + end + end + if screenName ~= "" then + self.set[screenName]:showSimple() + end +end + +function ScreenSet:setCurrentScreen(screenName) + screenName = screenName or self.defaultScreen + self:hideCurrent() + self.currentScreen = screenName +end + +function ScreenSet:hideCurrent() + if (self.currentScreen ~= "") then + self.set[self.currentScreen]:hide() + self.currentScreen = "" + end +end + +function ScreenSet:add(screen, setAsDefault) + self.set[screen.name] = screen + if (setAsDefault == true or self.defaultScreen == "") then + self.defaultScreen = screen.name + end + screen:setParentSet(self) +end + +return ScreenSet \ No newline at end of file -- 2.30.2 From 3c90fd1fe81905b0f87583aa3a431d681e425c38 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 31 Dec 2021 15:39:50 +0100 Subject: [PATCH 078/102] feat: add API to change focus on showing a screen --- .../birb/modules/gui/elements/parent.lua | 8 ++++++-- .../birb/modules/gui/menus/parent.lua | 7 +++++++ .../birb/modules/gui/mixins/elements.lua | 5 ++++- .../birb/modules/gui/screen/init.lua | 17 ++++++++++++----- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index cb369a6..2b202a6 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -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,10 @@ function GuiElement:looseFocus() end end +function GuiElement:setSubFocus() + -- Useless for basic element +end + -- UPDATE FUNCTIONS -- Update the menu every game update diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index c5bfbd5..d9b5708 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -122,6 +122,13 @@ function Menu:back() self:resetView() 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 diff --git a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua index 0bf1511..147a5c1 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/elements.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/elements.lua @@ -17,11 +17,14 @@ function ElementList:deleteElement(name) self.elements[name] = nil end -function ElementList:setFocus(name) +function ElementList:setFocus(name, widgetId, page) 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() diff --git a/sonic-radiance.love/birb/modules/gui/screen/init.lua b/sonic-radiance.love/birb/modules/gui/screen/init.lua index e4a3795..0ca313d 100644 --- a/sonic-radiance.love/birb/modules/gui/screen/init.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/init.lua @@ -17,6 +17,8 @@ function GuiScreen:new(name) self:reset() self:registerElements() self.gui:addScreen(name, self) + + self.defaultFocus = nil end function GuiScreen:initWrapper() @@ -32,19 +34,20 @@ function GuiScreen:update(dt) self.tweens:update(dt) end -function GuiScreen:show() - self:showSimple() - --TODO: show parent if we show directly the child +function GuiScreen:show(focusElement, widgetId, page) + self:showSimple(focusElement, widgetId, page) if (self.set ~= nil) then self.set.owner:show() end end -function GuiScreen:showSimple() +function GuiScreen:showSimple(focusElement, widgetId, page) + focusElement = focusElement or self.defaultFocus + local time = 0 if (not self.isVisible) then self.isVisible = true if (self.transforms["show"] ~= nil) then - self:playTransform("show") + time = self:playTransform("show") end if (self.subscreens ~= nil) then @@ -54,6 +57,10 @@ function GuiScreen:showSimple() if (self.set ~= nil) then self.set:setCurrentScreen(self.name) end + + if (focusElement) then + self.tweens:newFunc(time, "focus", function () self.gui:setFocus(focusElement, widgetId, page) end) + end end end -- 2.30.2 From b779a55eb779473bef289c804ef4b61f016ee180 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 31 Dec 2021 15:40:30 +0100 Subject: [PATCH 079/102] feat: ajouter un peu de marge au menu fancy --- sonic-radiance.love/game/modules/gui/fancymenu.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/sonic-radiance.love/game/modules/gui/fancymenu.lua b/sonic-radiance.love/game/modules/gui/fancymenu.lua index 61d4c96..15a7b94 100644 --- a/sonic-radiance.love/game/modules/gui/fancymenu.lua +++ b/sonic-radiance.love/game/modules/gui/fancymenu.lua @@ -9,6 +9,7 @@ function FancyMenu:new(name, x, y, w, itemNumber, haveBiseau) self.itemNumber = itemNumber self.box = gui.newChoiceBack(self.w + 24) self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") + self.canvas.padding = 24 end function FancyMenu:getDimensions() -- 2.30.2 From 784059f8f478e59569d9bb5f8e599dd10c5eba41 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 10:02:16 +0100 Subject: [PATCH 080/102] feat: add support for animated menu widgets --- sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua index ca106f6..d2f5356 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/base.lua @@ -37,6 +37,7 @@ function BaseWidget:new(menuName) self.canvas = {} self.canvas.texture = nil self.canvas.needRedraw = true + self.canvas.isAnimated = false self.order = 0 self:register() @@ -74,7 +75,7 @@ function BaseWidget:register() end function BaseWidget:redraw() - if (self.canvas.needRedraw) then + if (self.canvas.needRedraw or self.canvas.isAnimated) then self:generateTexture() end end -- 2.30.2 From e35d89f21ea49cd94142f2de27cca69baa6aab62 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 10:02:48 +0100 Subject: [PATCH 081/102] fix: remove an use of scissor for hp bars --- sonic-radiance.love/assets/gui/bar_small.lua | 6 ++++++ sonic-radiance.love/assets/gui/bar_small.png | Bin 0 -> 719 bytes sonic-radiance.love/game/modules/gui/init.lua | 20 ++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 sonic-radiance.love/assets/gui/bar_small.lua create mode 100644 sonic-radiance.love/assets/gui/bar_small.png diff --git a/sonic-radiance.love/assets/gui/bar_small.lua b/sonic-radiance.love/assets/gui/bar_small.lua new file mode 100644 index 0000000..fe8752b --- /dev/null +++ b/sonic-radiance.love/assets/gui/bar_small.lua @@ -0,0 +1,6 @@ +return { + metadata = { + height = 7, + width = 14, + } +} \ No newline at end of file diff --git a/sonic-radiance.love/assets/gui/bar_small.png b/sonic-radiance.love/assets/gui/bar_small.png new file mode 100644 index 0000000000000000000000000000000000000000..0e7413f81b1f7fd1c7b529bad0fca5ed6da0341e GIT binary patch literal 719 zcmV;=0xEX>4Tx04R}tkv&MmKpe$iTcsiu5j%(|M5s;{ii$XD6^c+H)C#RSm|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfb8}L3krMxx6k5c1aNLh~_a1le0DryARI?)nsG4P@ z5^*7uT@`|_2w@m~7(q;8ramW%NqCO0d-(Wz7v)*r=l&c$O3q|}PavLUx?vG-5KnJf zI_G`jFe^$5@j3ChK^G)`x%kia6AAVPqQDoQBBLX=jG6cZ`hk9+tB9luB}nOr3> zax9<%6_Voz|AXJ%n)%5IHz^bcI$v!2V-yJP0*#t&e;?a+;{*si16NwhU#SB#pQP7X zTI2}m-3BhMTbjHFTnGy0}1(0>bbuerT7_i_3Fq^Yaq4RCM> zj1?$*-Q(R|?Y;ebrrF;Q$Qg3U@cwO800006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNlirueSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{005^+L_t(Y$L-NU4uBvGMA7#ChproAVua40Mt61x@(Jc; zRaG>TnYrALh?vCJh8y1&PW*TRjh8=8;@o|dad)7*SaP(ElNfWfj!tZIw2ma+au zLpn}k#33D>*y50mBwlhTik1U8PGZS{9Gw_*AV(5EI0(g-13OOQmIFIFG2+0EB))M_ ziY15TIEl9$mZK9(4$Be6bxus?kKc~RH~;Ym@c||K`_mv?6Kenf002ovPDHLkV1ieo BD!l*z literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/game/modules/gui/init.lua b/sonic-radiance.love/game/modules/gui/init.lua index c8f0426..70f8869 100644 --- a/sonic-radiance.love/game/modules/gui/init.lua +++ b/sonic-radiance.love/game/modules/gui/init.lua @@ -1,6 +1,8 @@ local gui = {} +local TileSet = require "birb.modules.assets.types.tileset" local barborder = love.graphics.newImage("assets/gui/barborder.png") +local barSmall = TileSet("assets/gui/bar_small") function gui.newBorder(width, height, middlePosition) local tileset = love.graphics.newImage("assets/gui/borders.png") @@ -79,14 +81,18 @@ function gui.newChoiceBack(approximateWidth) end function gui.drawBar(x, y, width, height) + width = math.floor(width) + if (width > 0) then - local height = height or 7 - core.screen:setScissor(x, y, width, height) - love.graphics.draw(barborder, x, y) - local barwidth = math.max(width-14, 0) - love.graphics.rectangle("fill", x+7, y, barwidth, height) - love.graphics.draw(barborder, x+barwidth+7, y, 0, -1, -1, 7, 7) - core.screen:resetScissor( ) + height = 7 + if (width <= 8) then + barSmall:drawTile(9 - width, 0, 0) + else + love.graphics.draw(barborder, x, y) + local barwidth = math.max(width-14, 0) + love.graphics.rectangle("fill", x+7, y, barwidth, height) + love.graphics.draw(barborder, x+barwidth+7, y, 0, -1, -1, 7, 7) + end end end -- 2.30.2 From f7e1beae68627fec22c62ae5cc9194ca4725481a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 15:18:23 +0100 Subject: [PATCH 082/102] fix: make the box of boxedmenu part of its texture --- .../game/modules/gui/boxedmenu.lua | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/sonic-radiance.love/game/modules/gui/boxedmenu.lua b/sonic-radiance.love/game/modules/gui/boxedmenu.lua index 6812251..3789d9c 100644 --- a/sonic-radiance.love/game/modules/gui/boxedmenu.lua +++ b/sonic-radiance.love/game/modules/gui/boxedmenu.lua @@ -7,6 +7,7 @@ function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder) BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0) self.paddingLeft = 12 self.paddingRight = 4 + self.canvas.padding = 24 self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") self.cursorTransition = 0 @@ -27,35 +28,9 @@ end function BoxedList:update(dt) BoxedList.super.update(self, dt) - self:updateCursorPosition(dt) end -function BoxedList:updateCursorPosition(dt) - local relativecursor = self.widget.selected - self.view.firstSlot - - local transition = self.cursorTransition - relativecursor - if math.abs(transition) < 0.1 then - self.cursorTransition = relativecursor - else - local speed = dt * 45 - local movement = ((relativecursor) - (self.cursorTransition)) - self.cursorTransition = (self.cursorTransition) + movement * speed - end -end - -function BoxedList:drawCursor() - local x, y = self:getCursorPosition() - love.graphics.draw(self.cursorTexture, x, y) -end - -function BoxedList:getCursorPosition() - local addition = self.lineHeight - local x = self.x + 6 - local y = self.y + ((self.cursorTransition) * addition) + 1 - return x, y -end - -function BoxedList:draw() +function BoxedList:drawTexture() if (self.isBoxed) then local dy = 8 if (self.smallborder) then @@ -63,9 +38,13 @@ function BoxedList:draw() end local w, h = self.box:getDimensions() local diff = (w-self.w)/2 - love.graphics.draw(self.box, self.x - self.ox - diff, self.y - self.oy - dy) + love.graphics.draw(self.box, self.canvas.padding - diff, self.canvas.padding - dy) end - BoxedList.super.draw(self) + BoxedList.super.drawTexture(self) +end + +function BoxedList:drawGraphicalCursor(x, y, w, h) + love.graphics.draw(self.cursorTexture, x, y + 1) end return BoxedList -- 2.30.2 From a677902f6c6c0a04d925906bf99c1129da50ce7e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 17:11:42 +0100 Subject: [PATCH 083/102] feat: add more actions in menus --- .../birb/modules/gui/menus/listbox.lua | 9 +++++ .../birb/modules/gui/menus/model/init.lua | 33 ++++++++++++++++++- .../birb/modules/gui/menus/model/page.lua | 12 +++++++ .../birb/modules/gui/menus/parent.lua | 24 +++++++++++++- .../birb/modules/gui/textmenu/init.lua | 5 ++- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index 934d502..ad6d9e5 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -36,6 +36,7 @@ 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 end -- UPDATE FUNCTIONS @@ -54,6 +55,10 @@ function ListBox:resetView() self.view:reset() end +function ListBox:addLateralAction(func) + self.lateralFunc = func +end + -- KEYBOARD FUNCTIONS -- Handle input from keyboard/controllers. @@ -69,6 +74,10 @@ 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 diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua index 39e8b53..95ebeb1 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua @@ -21,6 +21,7 @@ function MenuModel:new() self.cancel = 0 self.limit = -1 -- self:updateWidgetSize() + self.hoverFunc = nil end function MenuModel:clear() @@ -33,6 +34,7 @@ end function MenuModel:addPage(pageName) local page = Page() + page.name = pageName self.pages[pageName] = page self.currentPage = pageName return page @@ -58,6 +60,7 @@ end function MenuModel:switch(pageName) if (self:pageExists(pageName)) then self.currentPage = pageName + self:hoverAction() end end @@ -70,6 +73,10 @@ function MenuModel:getCurrentPage() return self:getPage(self.currentPage) end +function MenuModel:getCurrentPageName() + return self.currentPage +end + -- UPDATE/DRAW FUNCTIONS -- All the update functions @@ -91,6 +98,10 @@ 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() @@ -106,6 +117,19 @@ 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 @@ -167,22 +191,29 @@ end function MenuModel:trySelectWidget(cursorid) local page = self:getCurrentPage() - return page:trySelectWidget(cursorid) + local isSuccess = page:trySelectWidget(cursorid) + if (isSuccess) then + self:hoverAction() + end + return isSuccess 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 diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua index d99c471..93f60ab 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua @@ -84,6 +84,18 @@ 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 diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index d9b5708..579c993 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -42,6 +42,18 @@ function Menu:new(name, x, y, w, h) self:updateWidgetSize() self:initCanvas() + self.cancelFunc = nil +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 @@ -112,14 +124,20 @@ 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) @@ -133,7 +151,11 @@ end -- Send actions to the widgets function Menu:cancelAction() - self.widget:cancelAction() + if (self.cancelFunc ~= nil) then + self.cancelFunc(self) + else + self.widget:cancelAction() + end end function Menu:clear() diff --git a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua index 6370ea0..aa0fc95 100644 --- a/sonic-radiance.love/birb/modules/gui/textmenu/init.lua +++ b/sonic-radiance.love/birb/modules/gui/textmenu/init.lua @@ -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) +function TextMenu:addItem(text, position, func, type, additionnalItems, color, additionnalDatas) local widget = TextMenu.baseWidgets.Base(self.name, text, position) widget:setFunc(func) widget.type = type or "select" @@ -53,6 +53,9 @@ function TextMenu:addItem(text, position, func, type, additionnalItems, color) 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) -- 2.30.2 From 47b86c18627d43ad8d46f75f507f0f9b25c7a09e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 17:11:52 +0100 Subject: [PATCH 084/102] feat: add wrap function --- sonic-radiance.love/birb/utils/math.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sonic-radiance.love/birb/utils/math.lua b/sonic-radiance.love/birb/utils/math.lua index 3d0ba85..84aeeaa 100644 --- a/sonic-radiance.love/birb/utils/math.lua +++ b/sonic-radiance.love/birb/utils/math.lua @@ -64,6 +64,18 @@ function Math.either(bool, val1, val2) end end +function Math.wrap(val, min, max) + while (val < min) do + local diff = ((min-1) - val) + val = max - diff + end + while (val > max) do + local diff = ((max+1) - val) + val = min + diff + end + return val +end + -- VECTOR/DIRECTION functions -- Easy-to-use function to handle point and motion -- 2.30.2 From d118a998ad0d18ca9c2cde3ac8bdba296bea95d3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 20:17:03 +0100 Subject: [PATCH 085/102] feat: add a way to pass arbitrary in scene switch --- sonic-radiance.love/birb/modules/gui/init.lua | 5 +++-- sonic-radiance.love/birb/modules/gui/screen/init.lua | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 1a9bbf1..7d33959 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -122,8 +122,9 @@ function Gui:hideScreen(screenname) end -function Gui:showScreen(screenname) - self.screens[screenname]:show() +function Gui:showScreen(screenname, focusElement, widgetId, page, arbitraryDatas) + self.screens[screenname]:show(focusElement, widgetId, page) + self.screens[screenname]:setDatas(arbitraryDatas) end -- SOUND FUNCTIONS diff --git a/sonic-radiance.love/birb/modules/gui/screen/init.lua b/sonic-radiance.love/birb/modules/gui/screen/init.lua index 0ca313d..e3f4a04 100644 --- a/sonic-radiance.love/birb/modules/gui/screen/init.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/init.lua @@ -65,6 +65,10 @@ function GuiScreen:showSimple(focusElement, widgetId, page) end +function GuiScreen:setDatas(datas) + +end + function GuiScreen:hide() if (self.isVisible) then if (self.transforms["hide"] ~= nil) then -- 2.30.2 From af23416c4e0920dbb143f793e04479faf35c07b8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 20:17:17 +0100 Subject: [PATCH 086/102] fix: redraw when adding a widget --- sonic-radiance.love/birb/modules/gui/menus/parent.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index 579c993..03ef62b 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -208,6 +208,7 @@ end function Menu:addWidget(newwidget) self.widget:addWidget(newwidget) + self.canvas.needRedraw = true end function Menu:setCancelWidget(id) -- 2.30.2 From 5c5b551d8d4067ea3d5b1bef9b5cd16cdcbd8701 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 22:28:38 +0100 Subject: [PATCH 087/102] feat: make the cursor part of texture --- .../birb/modules/gui/elements/canvas.lua | 24 ++++++++++++++++++- .../birb/modules/gui/menus/flowbox.lua | 2 +- .../birb/modules/gui/menus/grid.lua | 2 +- .../birb/modules/gui/menus/hlistbox.lua | 2 +- .../birb/modules/gui/menus/listbox.lua | 2 +- .../birb/modules/gui/menus/parent.lua | 6 ++++- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua index 54d782f..7fb1e23 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -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 diff --git a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua index 328bb7a..a963122 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua @@ -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 self.x + x, self.y + y, w, h + return x, y, w, h end return FlowBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/grid.lua b/sonic-radiance.love/birb/modules/gui/menus/grid.lua index 3c98a1c..afbd4c2 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/grid.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/grid.lua @@ -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(self.x + x, self.y + y, w, h) + self:drawGraphicalCursor(x, y, w, h) end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua index e94809b..fe4a594 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua @@ -99,7 +99,7 @@ function HListBox:getGraphicalCursorPosition() local w, h = self:getWidgetSize() local x = (self.widget:getSelected() - self.view.firstSlot) * w - return self.x + x,self.y, w, h + return x, 0, w, h end return HListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index ad6d9e5..b11c39b 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -108,7 +108,7 @@ end function ListBox:getGraphicalCursorPosition() local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot) - return self.x - self.ox + x,self.y + y - self.oy, w, h + return self:getListPart(self.widget:getSelected() - self.view.firstSlot) end return ListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index 03ef62b..65ca974 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -43,6 +43,7 @@ function Menu:new(name, x, y, w, h) self:initCanvas() self.cancelFunc = nil + self.canvas.dual = true end -- FUNCTIONS FUNCTIONS @@ -180,9 +181,12 @@ end function Menu:drawElement() self:draw() +end + +function Menu:drawFinalTexture() if (self:haveFocus()) then local x, y, w, h = self:getGraphicalCursorPosition() - self:drawGraphicalCursor(x, y, w, h) + self:drawGraphicalCursor(self.canvas.padding + x, self.canvas.padding + y, w, h) end end -- 2.30.2 From b20b9e5dd44adbe710e1ee869660078f3a155fce Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 22:29:40 +0100 Subject: [PATCH 088/102] fix: remove two stray print() --- sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua | 1 - sonic-radiance.love/birb/modules/gui/screen/init.lua | 1 - 2 files changed, 2 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua b/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua index 563c602..e5c0e07 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/views/view1D.lua @@ -31,7 +31,6 @@ end function View1D:reset() self.firstSlot = 1 - print("reset") end function View1D:updateFirstSlot(widgetID) diff --git a/sonic-radiance.love/birb/modules/gui/screen/init.lua b/sonic-radiance.love/birb/modules/gui/screen/init.lua index e3f4a04..beb54f5 100644 --- a/sonic-radiance.love/birb/modules/gui/screen/init.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/init.lua @@ -73,7 +73,6 @@ function GuiScreen:hide() if (self.isVisible) then if (self.transforms["hide"] ~= nil) then local time = self:playTransform("hide") - print(time) self.tweens:newFunc(time, "hide", function () self.isVisible = false end) -- 2.30.2 From 193b9cffbc2eca5a4aa14f45694c5ad0353eff50 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 4 Jan 2022 17:10:39 +0100 Subject: [PATCH 089/102] feat: add a way to know if there is tweens --- sonic-radiance.love/birb/classes/time/init.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic-radiance.love/birb/classes/time/init.lua b/sonic-radiance.love/birb/classes/time/init.lua index ebd4b80..c980378 100644 --- a/sonic-radiance.love/birb/classes/time/init.lua +++ b/sonic-radiance.love/birb/classes/time/init.lua @@ -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 -- 2.30.2 From 2ccf4d2e4e75c4445d79cc013075e9e431875472 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 4 Jan 2022 17:11:08 +0100 Subject: [PATCH 090/102] fix: don't pass key press to moving elements --- sonic-radiance.love/birb/modules/gui/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 7d33959..9e5370b 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -152,7 +152,7 @@ function Gui:keycheck(keys) if (haveFocus) then local elem = self:getFocusedElement() for key,_ in pairs(keys) do - if keys[key].isPressed then + if (keys[key].isPressed and not elem:isTransforming()) then elem:keypressed(key) end end -- 2.30.2 From e902ad6d821652c7c745d4c8b123e4f1f9eb02a5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 4 Jan 2022 17:11:30 +0100 Subject: [PATCH 091/102] fix: add haveTransform function --- sonic-radiance.love/birb/modules/gui/elements/parent.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/elements/parent.lua b/sonic-radiance.love/birb/modules/gui/elements/parent.lua index 2b202a6..aa73138 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/parent.lua @@ -76,6 +76,10 @@ function GuiElement:setSubFocus() -- Useless for basic element end +function GuiElement:isTransforming() + return self.tweens:haveTween() +end + -- UPDATE FUNCTIONS -- Update the menu every game update -- 2.30.2 From 13803e75606683350974d4784fa0b5300c315802 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 4 Jan 2022 17:11:45 +0100 Subject: [PATCH 092/102] feat: add delay to screen changes --- .../birb/modules/gui/screen/init.lua | 35 +++++++++++-------- .../birb/modules/gui/screen/screenset.lua | 8 +++-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/screen/init.lua b/sonic-radiance.love/birb/modules/gui/screen/init.lua index beb54f5..e95bd14 100644 --- a/sonic-radiance.love/birb/modules/gui/screen/init.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/init.lua @@ -43,26 +43,32 @@ end function GuiScreen:showSimple(focusElement, widgetId, page) focusElement = focusElement or self.defaultFocus - local time = 0 if (not self.isVisible) then self.isVisible = true - if (self.transforms["show"] ~= nil) then - time = self:playTransform("show") - end - - if (self.subscreens ~= nil) then - self.subscreens:show() - end - + local delay = 0 if (self.set ~= nil) then - self.set:setCurrentScreen(self.name) + delay = self.set:setCurrentScreen(self.name) end - if (focusElement) then - self.tweens:newFunc(time, "focus", function () self.gui:setFocus(focusElement, widgetId, page) 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 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) @@ -70,9 +76,10 @@ function GuiScreen:setDatas(datas) end function GuiScreen:hide() + local time = 0 if (self.isVisible) then if (self.transforms["hide"] ~= nil) then - local time = self:playTransform("hide") + time = self:playTransform("hide") self.tweens:newFunc(time, "hide", function () self.isVisible = false end) @@ -82,7 +89,7 @@ function GuiScreen:hide() self.subscreens:hideCurrent() end end - + return time end function GuiScreen:addTransform(name, transform) diff --git a/sonic-radiance.love/birb/modules/gui/screen/screenset.lua b/sonic-radiance.love/birb/modules/gui/screen/screenset.lua index 357ba3f..78143d0 100644 --- a/sonic-radiance.love/birb/modules/gui/screen/screenset.lua +++ b/sonic-radiance.love/birb/modules/gui/screen/screenset.lua @@ -29,6 +29,7 @@ function ScreenSet:new(owner) self.defaultScreen = "" self.currentScreen = "" self.owner = owner + self.delay = 0 end function ScreenSet:show(screenName) @@ -47,15 +48,18 @@ end function ScreenSet:setCurrentScreen(screenName) screenName = screenName or self.defaultScreen - self:hideCurrent() + local time = self:hideCurrent() + self.delay self.currentScreen = screenName + return time end function ScreenSet:hideCurrent() + local time = 0 if (self.currentScreen ~= "") then - self.set[self.currentScreen]:hide() + time = self.set[self.currentScreen]:hide() self.currentScreen = "" end + return time end function ScreenSet:add(screen, setAsDefault) -- 2.30.2 From ce1b1044e89c22940900168cbe997c8b5dc78dcf Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 Jan 2022 18:26:05 +0100 Subject: [PATCH 093/102] improvement: better textboxes --- sonic-radiance.love/assets/gui/dialogbox.png | Bin 444 -> 906 bytes .../game/modules/gui/boxedmenu.lua | 18 +-- sonic-radiance.love/game/modules/gui/init.lua | 128 +++++++++++------- .../scenes/menus/titlescreen/menu.lua | 4 +- 4 files changed, 88 insertions(+), 62 deletions(-) diff --git a/sonic-radiance.love/assets/gui/dialogbox.png b/sonic-radiance.love/assets/gui/dialogbox.png index 88c82b0340354ad53e664a8211346a7992fa8936..ec37baa38fe2097a677ffafef4a8e3dd0c8308ca 100644 GIT binary patch literal 906 zcmV;519kj~P)EX>4Tx04R}tkv&MmKpe$iTcsiu5j%(|M5s;{ii$XD6^c+H)C#RSm|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfb8}L3krMxx6k5c1aNLh~_a1le0DryARI?)nsG4P@ z5^*7uT@`|_2w@m~7(q;8ramW%NqCO0d-(Wz7v)*r=l&c$O3q|}PavLUx?vG-5KnJf zI_G`jFe^$5@j3ChK^G)`x%kia6AAVPqQDoQBBLX=jG6cZ`hk9+tB9luB}nOr3> zax9<%6_Voz|AXJ%n)%5IHz^bcI$v!2V-yJP0*#t&e;?a+;{*si16NwhU#SB#pQP7X zTI2}m-3BhMTbjHFTnGy0}1(0>bbuerT7_i_3Fq^Yaq4RCM> zj1?$*-Q(R|?Y;ebrrF;Q$Qg3U@cwO800006VoOIv02crN04;7@te5}*010qNS#tmY z3ljhU3ljkVnw%H_000McNliru<^cr|Ee%A<4xa!302y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{00Cl2L_t(o!|j+MNCQzE#=rmZg2gZ}ySy^%ieOpWxa1|b zFc=08Oe>m~1_R*?vUVnC8kWI<2$pS4i+Se3g5@!We}lgBykK~HCmy`7UHR_&{r|_~ zzDG#NYjha~G`v2i#AEEqY{VW!-}WLI{?MzUUM+8AeiuCh0H+{~g;!n*LZrh#J~kl`A}!V>?N3lg4stFFU;!+E1+V}X zzyeqR3-DD&3OvK6ztaVtq3w763_z$FSg)1=-^In%y*9*-c){thi~YTKRV_0YnXZ&7 z{OvGO<({*sl&aiQ7NtHBKE9PO4WUXs<^5WP4o-e|eYhn0&!>=(Z?CyNM#a|lZoUER g2J8mx2J*du55Jof`gcdx@v7EBhl3DGmXXzb~WxfkLvGArU3c`MJ5Nc_lzD1A}u>YGO%h zib8p2Nrr;Er*A-tUMf2S1EYeci(`n#@wd|yGY&gQwCgUXBXOD^~d0$x+ z7MZokYSF6IT&+$%ool>9I(e>~IhwnyZkK?duwjw#>rzjjo2kW>1qF|O{QLgnsC9GK zoRdMH*tyENo$tDe{(BP9v({0&V$L3B4^tPDhwJlgnd+Ca&fgVxbpa1hiOIw4djB+= zY~G09)dg>F2{6VynEkf#OvRID-{P_zrX5bJZn)X8(NuwJ@_bpAe_fYvR!*$Xc>mzb zPlpHV4VtI_nl!cKuD0pf&TRf$tGq9$z7Q(mtec$hs_K61gzd#O>cPv_u}@+65^{Ft z;YmBQFN?e9R>aH9+->%3L&()mi}K|mM-S&LiJxiwo~i%PlCXaklb7~93K4U?_{ybF hYxREN$NTr|#xHqr#o@f`ks44Sdb;|#taD0e0s#8_xI_Q| diff --git a/sonic-radiance.love/game/modules/gui/boxedmenu.lua b/sonic-radiance.love/game/modules/gui/boxedmenu.lua index 3789d9c..4ddca2b 100644 --- a/sonic-radiance.love/game/modules/gui/boxedmenu.lua +++ b/sonic-radiance.love/game/modules/gui/boxedmenu.lua @@ -6,20 +6,15 @@ local gui = require "game.modules.gui" function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder) BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0) self.paddingLeft = 12 - self.paddingRight = 4 + self.paddingRight = 6 self.canvas.padding = 24 self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") self.cursorTransition = 0 self.isBoxed = isBoxed - if (isBoxed) then - local border = self.h + 16 - if (smallborder == true) then - border = self.h + 8 - end - self.box = gui.newTextBox("assets/gui/dialogbox.png", w + 8, border) - end + self.border = utils.math.either(smallborder, 8, 16) + self.box = gui.newTextBox("assets/gui/dialogbox.png", self.w, self.h + self.border) end function BoxedList:finalize() @@ -32,13 +27,8 @@ end function BoxedList:drawTexture() if (self.isBoxed) then - local dy = 8 - if (self.smallborder) then - dy = 4 - end local w, h = self.box:getDimensions() - local diff = (w-self.w)/2 - love.graphics.draw(self.box, self.canvas.padding - diff, self.canvas.padding - dy) + love.graphics.draw(self.box, self.canvas.padding, self.canvas.padding - self.border/2) end BoxedList.super.drawTexture(self) end diff --git a/sonic-radiance.love/game/modules/gui/init.lua b/sonic-radiance.love/game/modules/gui/init.lua index 70f8869..5a6aacf 100644 --- a/sonic-radiance.love/game/modules/gui/init.lua +++ b/sonic-radiance.love/game/modules/gui/init.lua @@ -4,6 +4,22 @@ local TileSet = require "birb.modules.assets.types.tileset" local barborder = love.graphics.newImage("assets/gui/barborder.png") local barSmall = TileSet("assets/gui/bar_small") +local mask_shader = love.graphics.newShader[[ + vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) { + if (Texel(texture, texture_coords).rgb == vec3(0.0)) { + // a discarded pixel wont be applied as the stencil. + discard; + } + return vec4(1.0); + } +]] + +local function myStencilFunction(mask) + love.graphics.setShader(mask_shader) + love.graphics.draw(mask, 0, 0) + love.graphics.setShader() +end + function gui.newBorder(width, height, middlePosition) local tileset = love.graphics.newImage("assets/gui/borders.png") local tilequad = {} @@ -98,58 +114,78 @@ end function gui.newTextBox(filename, width, height) local baseimage = love.graphics.newImage(filename) - local quad = {} - quad[1] = love.graphics.newQuad(00, 00, 8, 8, 24, 24) - quad[2] = love.graphics.newQuad(00, 08, 8, 8, 24, 24) - quad[3] = love.graphics.newQuad(00, 16, 8, 8, 24, 24) - quad[4] = love.graphics.newQuad(08, 00, 8, 8, 24, 24) - quad[5] = love.graphics.newQuad(08, 08, 8, 8, 24, 24) - quad[6] = love.graphics.newQuad(08, 16, 8, 8, 24, 24) - quad[7] = love.graphics.newQuad(16, 00, 8, 8, 24, 24) - quad[8] = love.graphics.newQuad(16, 08, 8, 8, 24, 24) - quad[9] = love.graphics.newQuad(16, 16, 8, 8, 24, 24) - local canvas = love.graphics.newCanvas(width, height) + width, height = math.floor(width), math.floor(height) + local quad, quad_mask = {}, {} + quad[1] = love.graphics.newQuad(00, 00, 8, 8, 48, 32) + quad[2] = love.graphics.newQuad(00, 08, 8, 8, 48, 32) + quad[3] = love.graphics.newQuad(00, 16, 8, 8, 48, 32) + quad[4] = love.graphics.newQuad(08, 00, 8, 8, 48, 32) + quad[5] = love.graphics.newQuad(08, 08, 8, 8, 48, 32) + quad[6] = love.graphics.newQuad(08, 16, 8, 8, 48, 32) + quad[7] = love.graphics.newQuad(16, 00, 8, 8, 48, 32) + quad[8] = love.graphics.newQuad(16, 08, 8, 8, 48, 32) + quad[9] = love.graphics.newQuad(16, 16, 8, 8, 48, 32) - love.graphics.setCanvas( canvas ) + quad_mask[1] = love.graphics.newQuad(24+00, 00, 8, 8, 48, 32) + quad_mask[2] = love.graphics.newQuad(24+00, 08, 8, 8, 48, 32) + quad_mask[3] = love.graphics.newQuad(24+00, 16, 8, 8, 48, 32) + quad_mask[4] = love.graphics.newQuad(24+08, 00, 8, 8, 48, 32) + quad_mask[5] = love.graphics.newQuad(24+08, 08, 8, 8, 48, 32) + quad_mask[6] = love.graphics.newQuad(24+08, 16, 8, 8, 48, 32) + quad_mask[7] = love.graphics.newQuad(24+16, 00, 8, 8, 48, 32) + quad_mask[8] = love.graphics.newQuad(24+16, 08, 8, 8, 48, 32) + quad_mask[9] = love.graphics.newQuad(24+16, 16, 8, 8, 48, 32) + + local back = love.graphics.newQuad(00, 24, 8, 8, 48, 32) + local canvas = love.graphics.newCanvas(width, height) + local backCanvas = love.graphics.newCanvas(width, height) + local maskCanvas = love.graphics.newCanvas(width, height) - for i=1, math.floor(width/8) do - if (i == 1) then - -- first line - for j=1, math.floor(height/8) do - if j == 1 then - love.graphics.draw(baseimage, quad[1], (i-1)*8, (j-1)*8) - elseif j == math.floor(height/8) then - love.graphics.draw(baseimage, quad[3], (i-1)*8, (j-1)*8) - else - love.graphics.draw(baseimage, quad[2], (i-1)*8, (j-1)*8) - end - end - elseif (i == math.floor(width/8)) then - -- last line - for j=1, math.floor(height/8) do - if j == 1 then - love.graphics.draw(baseimage, quad[7], (i-1)*8, (j-1)*8) - elseif j == math.floor(height/8) then - love.graphics.draw(baseimage, quad[9], (i-1)*8, (j-1)*8) - else - love.graphics.draw(baseimage, quad[8], (i-1)*8, (j-1)*8) - end - end - else - -- middle lines - for j=1, math.floor(height/8) do - if j == 1 then - love.graphics.draw(baseimage, quad[4], (i-1)*8, (j-1)*8) - elseif j == math.floor(height/8) then - love.graphics.draw(baseimage, quad[6], (i-1)*8, (j-1)*8) - else - love.graphics.draw(baseimage, quad[5], (i-1)*8, (j-1)*8) - end - end + love.graphics.setCanvas( backCanvas ) + + for i=1, math.ceil(width/8) do + for j=1, math.ceil(height/8), 1 do + love.graphics.draw(baseimage, back, (i-1)*8, (j-1)*8) end end + --love.graphics.setScissor(0, 0, math.floor(width/8))) + love.graphics.setCanvas( maskCanvas ) + love.graphics.rectangle("fill", 0, 0, width, height) + + love.graphics.draw(baseimage, quad_mask[1], 0, 0) + love.graphics.draw(baseimage, quad_mask[7], width- 8, 0) + love.graphics.draw(baseimage, quad_mask[3], 0, height- 8) + love.graphics.draw(baseimage, quad_mask[9], width - 8, height - 8) + + love.graphics.setCanvas( {canvas, stencil = true} ) + + love.graphics.stencil(function () myStencilFunction(maskCanvas) end, "replace", 1) + love.graphics.setStencilTest("greater", 0) + love.graphics.draw(backCanvas) + love.graphics.setStencilTest() + + love.graphics.setScissor(8, 0, width-15, height) + for i = 0, math.floor(width/8), 1 do + love.graphics.draw(baseimage, quad[4], i*8, 0) + love.graphics.draw(baseimage, quad[6], i*8, height - 8) + end + + love.graphics.setScissor(0, 8, width, height-15) + for i = 0, math.floor(height/8), 1 do + love.graphics.draw(baseimage, quad[2], 0, i*8) + love.graphics.draw(baseimage, quad[8], width - 8, i * 8) + end + + love.graphics.setScissor( ) + + love.graphics.draw(baseimage, quad[1], 0, 0) + love.graphics.draw(baseimage, quad[7], width- 8, 0) + love.graphics.draw(baseimage, quad[3], 0, height- 8) + love.graphics.draw(baseimage, quad[9], width - 8, height - 8) + + love.graphics.setCanvas( ) local imagedata = canvas:newImageData() diff --git a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua index 5fe321b..ac7531b 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua @@ -9,7 +9,7 @@ local defTransitions = require "birb.modules.transitions" local radTransitions = require "game.modules.transitions" local HPADDING = 68 -local VPADDING = 28 +local VPADDING = 30 function SaveMenu:new() local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2) @@ -24,7 +24,7 @@ function SaveMenu:new() for i, save in ipairs(metadata) do SaveWidget(self.scene, i, save) end - self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, (h / 3)) + self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, self.widgetSize.h - 4) self.isVisible = true end -- 2.30.2 From ac63e377f91b4b655a0147693a81480c16ca254a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 Jan 2022 18:31:54 +0100 Subject: [PATCH 094/102] feat: add a way to pack listbox at their end --- sonic-radiance.love/birb/modules/gui/menus/listbox.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index b11c39b..41abf2a 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -37,6 +37,7 @@ function ListBox:new(name, x, y, w, h, slotNumber) 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 @@ -91,6 +92,7 @@ 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 -- 2.30.2 From 783ca58c783367c21d707592bfcaed9e936cc5e0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 Jan 2022 21:30:12 +0100 Subject: [PATCH 095/102] fix: only redraw visible elements --- sonic-radiance.love/birb/modules/gui/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index 9e5370b..2f2d7ce 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -164,7 +164,10 @@ end -- Draw the menu and its content function Gui:redraw() - for _, element in pairs(self.elements) do + for _, element in pairs(self:getVisibleElement(true)) do + element:redraw() + end + for _, element in pairs(self:getVisibleElement(false)) do element:redraw() end end -- 2.30.2 From d85cd894fb9c28eaf6169afae012e54f22ad8481 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 Jan 2022 23:25:19 +0100 Subject: [PATCH 096/102] feat: add a way to get screens from the gui --- sonic-radiance.love/birb/modules/gui/mixins/screens.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic-radiance.love/birb/modules/gui/mixins/screens.lua b/sonic-radiance.love/birb/modules/gui/mixins/screens.lua index 4e594eb..f41a502 100644 --- a/sonic-radiance.love/birb/modules/gui/mixins/screens.lua +++ b/sonic-radiance.love/birb/modules/gui/mixins/screens.lua @@ -13,4 +13,8 @@ function ScreenList:deleteScreen(name) self.screens[name] = nil end +function ScreenList:getScreen(name) + return self.screens[name] +end + return ScreenList \ No newline at end of file -- 2.30.2 From 17c4b0de8e1a69fd94edbf431342880c9a9f6b74 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 Jan 2022 23:26:09 +0100 Subject: [PATCH 097/102] feat: port the main menu to the new gui system --- .../game/modules/gui/overlay.lua | 11 + .../gui/menus/character/charbars.lua | 34 +++ .../gui/menus/character/description.lua | 21 ++ .../overworld/gui/menus/character/init.lua | 175 ++++++++++++ .../gui/menus/character/pageindicator.lua | 27 ++ .../gui/menus/character/subpages.lua | 56 ++++ .../overworld/gui/menus/character/texts.lua | 41 +++ .../overworld/gui/menus/commons/boxedtext.lua | 38 +++ .../overworld/gui/menus/commons/charmenu.lua | 91 ++++++ .../mainmenu => gui/menus/commons}/const.lua | 0 .../gui/menus/commons/screenName.lua | 35 +++ .../scenes/overworld/gui/menus/init.lua | 44 +++ .../scenes/overworld/gui/menus/items/init.lua | 171 ++++++++++++ .../overworld/gui/menus/items/roulette.lua | 40 +++ .../scenes/overworld/gui/menus/mainmenu.lua | 87 ++++++ .../overworld/gui/menus/useItem/equip.lua | 52 ++++ .../overworld/gui/menus/useItem/init.lua | 23 ++ .../overworld/gui/menus/useItem/number.lua | 21 ++ .../overworld/gui/menus/useItem/parent.lua | 91 ++++++ sonic-radiance.love/scenes/overworld/init.lua | 62 +---- .../scenes/overworld/screens/gameover.lua | 89 ------ .../scenes/overworld/screens/init.lua | 4 - .../screens/mainmenu/character/basicpage.lua | 69 ----- .../screens/mainmenu/character/init.lua | 122 --------- .../screens/mainmenu/character/pageparent.lua | 47 ---- .../screens/mainmenu/character/skillpage.lua | 71 ----- .../screens/mainmenu/character/statpage.lua | 88 ------ .../screens/mainmenu/common/charmenu.lua | 12 - .../screens/mainmenu/common/charwidget.lua | 65 ----- .../overworld/screens/mainmenu/equip.lua | 115 -------- .../overworld/screens/mainmenu/init.lua | 7 - .../overworld/screens/mainmenu/items.lua | 258 ------------------ .../overworld/screens/mainmenu/pause.lua | 137 ---------- .../overworld/screens/mainmenu/useitems.lua | 91 ------ .../scenes/overworld/screens/menu.lua | 103 ------- .../scenes/overworld/screens/parent.lua | 49 ---- 36 files changed, 1065 insertions(+), 1382 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/character/charbars.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/character/description.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/character/init.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/character/pageindicator.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/character/subpages.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/character/texts.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/commons/boxedtext.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/commons/charmenu.lua rename sonic-radiance.love/scenes/overworld/{screens/mainmenu => gui/menus/commons}/const.lua (100%) create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/commons/screenName.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/init.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/items/init.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/items/roulette.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/mainmenu.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/useItem/equip.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/useItem/init.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/useItem/number.lua create mode 100644 sonic-radiance.love/scenes/overworld/gui/menus/useItem/parent.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/gameover.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/init.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/character/pageparent.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/init.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/useitems.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/menu.lua delete mode 100644 sonic-radiance.love/scenes/overworld/screens/parent.lua diff --git a/sonic-radiance.love/game/modules/gui/overlay.lua b/sonic-radiance.love/game/modules/gui/overlay.lua index a32337d..4107a9d 100644 --- a/sonic-radiance.love/game/modules/gui/overlay.lua +++ b/sonic-radiance.love/game/modules/gui/overlay.lua @@ -32,6 +32,15 @@ local hideBackground = { {"overlayDarken", "tween", 0.0, 0.6, {opacity = 0}, "outExpo"} } + +local showBackgroundPause = { + {"overlayDarken", "tween", 0.0, 0.2, {opacity = OVERLAY_OPACITY}, "inOutQuart"} +} + +local hideBackgroundPause = { + {"overlayDarken", "tween", 0.0, 0.2, {opacity = 0}, "inOutQuart"} +} + local showVersion = { {"version", "movement", 0.0, 0.5, 380, 220, "inOutQuart"}, } @@ -62,6 +71,8 @@ function OverlayScreen:new(active, doShowVersion) self:addTransform("hide", animateDisappear) self:addTransform("showBackground", showBackground) self:addTransform("hideBackground", hideBackground) + self:addTransform("showBackgroundPause", showBackgroundPause) + self:addTransform("hideBackgroundPause", hideBackgroundPause) self:addTransform("showVersion", showVersion) self:addTransform("hideVersion", hideVersion) diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/character/charbars.lua b/sonic-radiance.love/scenes/overworld/gui/menus/character/charbars.lua new file mode 100644 index 0000000..cd2dd5e --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/character/charbars.lua @@ -0,0 +1,34 @@ +local CharBars = require("birb.modules.gui.elements.canvas"):extend() + +local HPBAR_SIZE = 80 +local W, H = HPBAR_SIZE*2, 32 + +local const = require "scenes.overworld.gui.menus.commons.const" + +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +function CharBars:new(name, x, y, character) + CharBars.super.new(self, name, x, y, W, H) + self.canvas.padding = 24 + self.character = character + + self.hpbar = ComplexHPBar(HPBAR_SIZE) + self.ppbar = ComplexHPBar(HPBAR_SIZE) + self.hpbar:setColorForeground(248/255, 160/255, 0, 1) + self.hpbar:setColorBackground(112/255, 0, 0) + self.ppbar:setColorForeground(0, 248/255, 248/255, 1) + self.ppbar:setColorBackground(0, 54/255, 229/255) + + self.opacity = 0 +end + +function CharBars:drawTexture() + local stats = self.character.stats + local x, y = self.canvas.padding, self.canvas.padding + self.scene.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(x, y - 4, self.character.hp, stats:get(stats.HPMAX)) + local xx = x + const.CHARPAGESIZE - HPBAR_SIZE - 7 + self.ppbar:drawWithLabels(xx, y - 4, self.character.pp, stats:get(stats.PPMAX)) +end + +return CharBars \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/character/description.lua b/sonic-radiance.love/scenes/overworld/gui/menus/character/description.lua new file mode 100644 index 0000000..d111ae1 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/character/description.lua @@ -0,0 +1,21 @@ +local Description = require("birb.modules.gui.elements.canvas"):extend() +local PLAYER_MESSAGE = 240 - 24 + +function Description:new(owner, name) + self.owner = owner + Description.super.new(self, name, 0, PLAYER_MESSAGE, 424, 16) + self.canvas.isAnimated = true +end + +function Description:drawTexture() + if (not utils.string.isEmpty(self.owner:getDescription())) then + love.graphics.setColor(0,0,0, 0.66) + love.graphics.rectangle("fill", self.canvas.padding, self.canvas.padding, self.w, self.h) + self.gui.scene.assets.fonts["small"]:setColor(1,1,1, 1) + self.gui.scene.assets.fonts["small"]:draw(self.owner:getDescription(), self.canvas.padding, self.canvas.padding - 1, self.w, "center") + self.gui.scene.assets.fonts["small"]:setColor(1,1,1, 1) + utils.graphics.resetColor() + end +end + +return Description \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/character/init.lua b/sonic-radiance.love/scenes/overworld/gui/menus/character/init.lua new file mode 100644 index 0000000..4402146 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/character/init.lua @@ -0,0 +1,175 @@ +local CharacterScreen = require("birb.modules.gui.screen"):extend() +local DrawableElement = require("birb.modules.gui.elements.drawable") + +local BoxedText = require "scenes.overworld.gui.menus.commons.boxedtext" +local PageIndicator = require "scenes.overworld.gui.menus.character.pageindicator" +local CharBars = require "scenes.overworld.gui.menus.character.charbars" +local Description = require "scenes.overworld.gui.menus.character.description" + +local FancyMenu = require "game.modules.gui.fancymenu" +local BoxedMenu = require "game.modules.gui.boxedmenu" + +local const = require "scenes.overworld.gui.menus.commons.const" +local subpages = require "scenes.overworld.gui.menus.character.subpages" +local textFunc = require "scenes.overworld.gui.menus.character.texts" + +local MENU_W = 128 +local MENU_X, MENU_Y = const.X2 - MENU_W - 14, const.Y2 - 48 + 2 +local PAGEINDIC_X, PAGEINDIC_Y = const.X2 - 16*5, const.Y - 14 + +function CharacterScreen:new(characterName) + self.characterName = characterName + self.artworkPosition = require("datas.gamedata.characters." .. characterName .. ".artwork") + self.character = game.characters.list[characterName] + CharacterScreen.super.new(self, characterName) + self:setCustomTransforms() + + self.defaultFocus = self.characterName .. "ActMenu" + self.nbr = 1 +end + +function CharacterScreen:setCustomTransforms() + local show = {} + local hide = {} + self:addCustomTween(show, "Artwork", false, 1, nil, self.artworkPosition.x) + self:addCustomTween(hide, "Artwork", true, -1, nil, self.artworkPosition.x) + self:addCustomTween(show, "ActMenu", false, 1, nil, MENU_X) + self:addCustomTween(hide, "ActMenu", true, -1, nil, MENU_X) + self:addCustomTween(show, "Indicator", false, 1, nil, PAGEINDIC_X) + self:addCustomTween(hide, "Indicator", true, -1, nil, PAGEINDIC_X) + self:addTweens(show, "basic", false, -1) + self:addTweens(hide, "", true, 1) + + self:addTransform("show", show) + self:addTransform("hide", hide) + self.desc = "" +end + +function CharacterScreen:createElements() + local elementDatas = subpages.getElements() + local list = {} + + local drawable = love.graphics.newImage("datas/gamedata/characters/" .. self.characterName .. "/artwork.png") + table.insert(list, {DrawableElement(self.characterName .. "Artwork", drawable, self.artworkPosition.x, self.artworkPosition.y,0,1,1,0,0, 0), 0, 1}) + + self.dataMenus = {} + for i, element in ipairs(elementDatas) do + local name = self.characterName .. element.name + local x, y, w, h = const.X - 16, const.Y + element.data.y, const.CHARPAGESIZE, element.data.h + if (element.data.isTextBox) then + local boxedText = BoxedText(name, x, y, w, h, function() return textFunc["get" .. element.name](self.character, const.CHARPAGESIZE) end) + table.insert(list, {boxedText, 0, 1}) + elseif (element.data.isMenu) then + self.dataMenus[element.name] = BoxedMenu(name, x, y + 4, w, h, true, true) + self.dataMenus[element.name].opacity = 0 + self.dataMenus[element.name]:addCancelAction(function () + self.gui.scene.assets.sfx["mBack"]:play() + self.gui:setFocus(self.characterName .. "ActMenu") + self.desc = "" + end) + table.insert(list, {self.dataMenus[element.name], 0, 1}) + else + table.insert(list, {CharBars(name, x, y, self.character), 0, 1}) + end + end + + self:rebuildMenus() + table.insert(list, {self:createGlobalMenu(), 0, 1}) + table.insert(list, {PageIndicator(self, self.characterName .. "Indicator", PAGEINDIC_X, PAGEINDIC_Y, subpages.list), 0, 1}) + table.insert(list, {Description(self, self.characterName .. "Description"), 0, -100}) + + return list +end + +function CharacterScreen:rebuildMenus() + for i, equip in ipairs(subpages.equip) do + local fullname = "No " .. equip + local obj = self.character.equip[equip] + if (not utils.string.isEmpty(obj)) then + fullname = core.datas:get("items", obj).fullname + end + self.dataMenus["EquipMenu"]:addItem(fullname, "left", function () end, "select") + end + + for _, skill in ipairs(self.character.skills) do + local skillData = core.datas:get("skills", skill.name) + local cost = utils.math.numberToString(skillData.cost, 2) + self.dataMenus["SkillsMenu"]:addItem(skillData.fullname, "left", function () end, "select", {{cost, "right"}}, nil, {skillData.description}) + end + + self.dataMenus["SkillsMenu"]:addHoverAction(function (widget) + self.desc = widget.datas[1] + end) +end + +function CharacterScreen:getDescription() + return self.desc or "" +end + +function CharacterScreen:createGlobalMenu() + self.menu = FancyMenu(self.characterName .. "ActMenu", MENU_X, MENU_Y, MENU_W, 3, false) + self.menu.opacity = 0 + + for i, name in ipairs(subpages.list) do + self.menu:addPage(name) + end + + self.menu:switch("skills") + self.menu:addItem("See skill", "left", function() + self.gui:setFocus(self.characterName .. "SkillsMenu") + self.desc = core.datas:get("skills", self.character.skills[1].name).description + end, "navigate") + self.menu:switch("stats") + self.menu:addItem("Remove item", "left", function() self.gui:setFocus(self.characterName .. "EquipMenu") end, "navigate") + + for i, name in ipairs(subpages.list) do + self.menu:switch(name) + self.menu:addItem("Back", "left", function() self.gui:showScreen("mainmenuScreen", "navCharMenu", self.nbr, "main") end, "back") + self.menu:setCancelWidget() + end + self.menu:addLateralAction(function (key) if (key == "left") then self:changePage(-1) else self:changePage(1) end end) + self.menu.packAtEnd = 1 + + self.menu:switch(subpages.list[1]) + return self.menu +end + +function CharacterScreen:changePage(direction) + local currentPage = self.menu:getCurrentPageName() + self.menu:switch(subpages.relativePage(currentPage, direction)) + self:hidePage(currentPage, utils.math.sign(direction)) + self:showPage(self.menu:getCurrentPageName(), utils.math.sign(direction)) + self.gui.scene.assets.sfx["mBeep"]:play() +end + +function CharacterScreen:hidePage(name, direction) + local transform = {} + self:addTweens(transform, name, true, direction) + self.gui:transform(transform, 0) +end + +function CharacterScreen:showPage(name, direction) + local transform = {} + self:addTweens(transform, name, false, direction) + self.gui:transform(transform, 0) +end + +function CharacterScreen:addTweens(list, name, isHiding, direction) + for _, elem in ipairs(subpages.getElements(name)) do + self:addCustomTween(list, elem.name, isHiding, direction) + end +end + +function CharacterScreen:addCustomTween(list, name, isHiding, direction, speed, x) + local begin, duration = utils.math.either(isHiding, 0, 0.1), speed or 0.3 + local trueDirection, opacity = utils.math.either(isHiding, direction, 0), utils.math.either(isHiding, 0, 1) + x = x or const.X + if (not isHiding) then self:addCustomTween(list, name, true, direction * -1, 0.1, x) end + table.insert(list, {self.characterName .. name, "tween", begin, duration, {x = x - 16*trueDirection, opacity = opacity}, "inOutQuad"}) +end + +function CharacterScreen:getCurrentPageName() + return self.menu:getCurrentPageName() +end + +return CharacterScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/character/pageindicator.lua b/sonic-radiance.love/scenes/overworld/gui/menus/character/pageindicator.lua new file mode 100644 index 0000000..1eb4d30 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/character/pageindicator.lua @@ -0,0 +1,27 @@ +local PageIndicator = require("birb.modules.gui.elements.canvas"):extend() + +local DIST = 16 +local RAD_SMALL, RAD_LARGE = 2, 3 +local OUTLINE_LIGHT = 0.15 + +function PageIndicator:new(owner, name, x, y, pageList) + self.pageList = pageList + self.owner = owner + local w, h = (DIST*(#pageList + 1)), 16 + PageIndicator.super.new(self, name, x, y, w, h) + self.canvas.isAnimated = true + self.opacity = 0 +end + +function PageIndicator:drawTexture() + for i, pageName in ipairs(self.pageList) do + local radius = utils.math.either (pageName == self.owner:getCurrentPageName(), RAD_LARGE, RAD_SMALL) + local x, y = (i+1) * DIST, math.floor(self.h / 2) + love.graphics.circle("fill", x, y, radius, 8) + love.graphics.setColor(OUTLINE_LIGHT, OUTLINE_LIGHT, OUTLINE_LIGHT, 1) + love.graphics.circle("line", x, y, radius, 8) + utils.graphics.resetColor() + end +end + +return PageIndicator \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/character/subpages.lua b/sonic-radiance.love/scenes/overworld/gui/menus/character/subpages.lua new file mode 100644 index 0000000..8616747 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/character/subpages.lua @@ -0,0 +1,56 @@ +local const = require "scenes.overworld.gui.menus.commons.const" +local subpages = {} + +subpages.list = {"basic", "stats", "skills"} + +subpages.elements = { + ["basic"] = {"IdentityBox", "Bars", "LevelBox", "WeakStrongBox"}, + ["stats"] = {"EquipMenu", "StatsBox"}, + ["skills"] = {"SkillsMenu"} +} + +subpages.equip = {"gloves", "shoes", "accessories"} + +subpages.elementsData = { + IdentityBox = {y = 0, h = 40, isTextBox = true }, + Bars = {y = 48, h = 0, isTextBox = false, isMenu = false}, + LevelBox = {y = 72-13, h = 56, isTextBox = true}, + WeakStrongBox = {y = 132-13, h = 40, isTextBox = true }, + EquipMenu = {y = 0, h = 3, isTextBox = false, isMenu = true}, + StatsBox = {y = 72, h = 72, isTextBox = true }, + SkillsMenu = {y = 0, h = 9, isTextBox = false, isMenu = true}, +} + +function subpages.fromId(id) + return subpages.list[id] +end + +function subpages.fromName(name) + for i, subPageName in ipairs(subpages.list) do + if subPageName == name then + return i + end + end + return -1 +end + +function subpages.relativePage(pageName, direction) + local id = utils.math.wrap(subpages.fromName(pageName) + direction, 1, #subpages.list) + return subpages.fromId(id) +end + +function subpages.getElements(filter) + local list = {} + for i, subpageName in ipairs(subpages.list) do + if (filter == nil or filter == "" or filter == subpageName) then + for j, elementName in ipairs(subpages.elements[subpageName]) do + local data = subpages.elementsData[elementName] + table.insert(list, {name = elementName, page = subpageName, data = data}) + end + end + end + + return list +end + +return subpages \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/character/texts.lua b/sonic-radiance.love/scenes/overworld/gui/menus/character/texts.lua new file mode 100644 index 0000000..ded23bb --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/character/texts.lua @@ -0,0 +1,41 @@ +local TextsFuncs = {} + +local STATS = require "datas.consts.stats" + +function TextsFuncs.getIdentityBox(character) + local identityString = character.fullname .. "\n" + identityString = identityString .. "Class: " .. character.data.class + + return {{1, identityString}} +end + +function TextsFuncs.getLevelBox(character) + local levelString = "Level: " .. character.level .. "\n" + levelString = levelString .. "Current exp: " .. character.exp .. "\n" + levelString = levelString .. "Next level: " .. character.exp_next + + return {{1, levelString}} +end + +function TextsFuncs.getWeakStrongBox(character) + local weakStrongString = "Weak to: Nothing" .. "\n"--"Earth, Lightning" + weakStrongString = weakStrongString .. "Resist To: Nothing" + + return {{1, weakStrongString}} +end + +function TextsFuncs.getStatsBox(character, pageSize) + local char = character + local statStringList = {} + for i, statName in ipairs(STATS.LIST) do + local xStat = (((i - 1) % 2) * (pageSize/2)) + 6 + local line = math.floor((i + 1)/2) + local middle = xStat + 10 + pageSize/4 + local stat = char.stats:get(statName) + table.insert(statStringList, {line, STATS.SIMPLENAME[statName], "left", xStat, 0, {1,1,1,1}, pageSize}) + table.insert(statStringList, {line, stat, "center", middle, 0, {1,1,1,0.9}, -1}) + end + return statStringList +end + +return TextsFuncs \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/commons/boxedtext.lua b/sonic-radiance.love/scenes/overworld/gui/menus/commons/boxedtext.lua new file mode 100644 index 0000000..adeb091 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/commons/boxedtext.lua @@ -0,0 +1,38 @@ +local BoxedTextElement = require("birb.modules.gui.elements.canvas"):extend() +local gui = require "game.modules.gui" + +local PADDING = 6 +local PADDING_H = 4 +local LINEHEIGHT = 16 + +function BoxedTextElement:new(name, x, y, w, h, linesFunc) + BoxedTextElement.super.new(self, name, x, y, w, h) + self.textwidth = w - (PADDING * 2) + self.opacity = 0 + self.canvas.isAnimated = true + self.linesFunc = linesFunc + + self.box = gui.newTextBox("assets/gui/dialogbox.png", w, h) + self.canvas.padding = 0 +end + +function BoxedTextElement:getLines() + -- return {line, text, align, x, y, color} + return self.linesFunc() +end + +function BoxedTextElement:drawTexture() + love.graphics.draw(self.box, 0, 0) + local lines = self:getLines() + assert(lines ~= nil, "No lines for " .. self.name) + for i, line in ipairs(lines) do + local lineNbr, text, align, x, y = line[1], line[2] or "", line[3] or "left", line[4] or 0, line[5] or 0 + local color, width = line[6] or {1, 1, 1, 1}, line[7] or self.textwidth + self.assets.fonts["small"]:setColor(color[1], color[2], color[3], color[4]) + self.assets.fonts["small"]:draw(text, PADDING + x, PADDING_H + LINEHEIGHT*(lineNbr-1) + y, width, align or "left") + self.assets.fonts["small"]:setColor(1, 1, 1, 1) + utils.graphics.resetColor() + end +end + +return BoxedTextElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/commons/charmenu.lua b/sonic-radiance.love/scenes/overworld/gui/menus/commons/charmenu.lua new file mode 100644 index 0000000..3d9667c --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/commons/charmenu.lua @@ -0,0 +1,91 @@ +local CharacterMenu = require("birb.modules.gui.menus.listbox"):extend() +local CharacterWidget = require("birb.modules.gui.menus.widgets.base"):extend() +local const = require "scenes.overworld.gui.menus.commons.const" + +local ComplexHPBar = require "game.modules.gui.complexhpbar" +local Emblem = require "game.modules.gui.emblem" + +function CharacterMenu:new(name, x, func, showEquip) + local w = const.WIDTH - x + 28 + CharacterMenu.super.new(self, name, x, const.Y, w, const.HEIGHT, 4) + self.func = func + self.showEquip = (showEquip == true) + self.opacity = 1 + self:buildFromTeam() + + self.canvas.isAnimated = true +end + +function CharacterMenu:buildFromTeam() + self.charName = game.characters.team[1] + for i, name in ipairs(game.characters.team) do + local widget = CharacterWidget(self.name, name) + widget:setFunc(function () self.func(name, i) end) + end + self:addHoverAction(function(widget) self.charName = widget.charName end) +end + +function CharacterWidget:new(menuName, charName) + CharacterWidget.super.new(self, menuName) + + self.charName = charName + self.emblem = Emblem(game.characters.list[charName], self.scene) + self.font = self.scene.assets.fonts["small"] + self.font2 = self.scene.assets.fonts["hudnbrs_small"] + self.hpbar = ComplexHPBar(88) + self.ppbar = ComplexHPBar(88) + self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1) + self.hpbar:setColorBackground(112 / 255, 0, 0) + self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1) + self.ppbar:setColorBackground(0, 54 / 255, 229 / 255) + + self.canvas.isAnimated = true + + self.character = game.characters.list[self.charName] +end + +function CharacterWidget:drawCanvas() + local xDebut = 32 + local yDebut = 16 + + self.emblem:draw(0, 6) + + self.font:setFilter("shadow") + self.font:draw(self.character.fullname, xDebut, 0, -1, "left") + + if (self.menu.showEquip ~= nil and self.menu.showEquip ~= false) then + self:drawEquip(xDebut, yDebut) + else + self:drawHPPP(xDebut, yDebut) + self:drawLvlExp(xDebut, yDebut) + end +end + +function CharacterWidget:drawLvlExp(x, y) + self.scene.assets.images["lvl"]:draw(x, y) + self.scene.assets.images["exp"]:draw(x, y + 10) + self.font2:print(self.character.level, x + 19, y, "left") + local expString = self.character.exp .. "/" .. self.character.exp_next + self.font2:print(expString, x + 19, y + 10, "left") +end + +function CharacterWidget:drawEquip(x, y) + local charEquip = self.character.equip[self.menu.showEquip] + local equipString = "None" + if (not utils.string.isEmpty(charEquip)) then + local data = core.datas:get("items", charEquip) + equipString = data.fullname + end + self.font:draw(equipString, x, y, -1, "left") +end + +function CharacterWidget:drawHPPP(x, y) + local xDebut = x + 20 + local yDebut = y - 1 + self.scene.assets.fonts["hudnbrs_small"]:set() + local stats = self.character.stats + self.hpbar:drawWithLabels(xDebut + 53, yDebut, self.character.hp, stats:get(stats.HPMAX)) + self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, self.character.pp, stats:get(stats.PPMAX)) +end + +return CharacterMenu diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/const.lua b/sonic-radiance.love/scenes/overworld/gui/menus/commons/const.lua similarity index 100% rename from sonic-radiance.love/scenes/overworld/screens/mainmenu/const.lua rename to sonic-radiance.love/scenes/overworld/gui/menus/commons/const.lua diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/commons/screenName.lua b/sonic-radiance.love/scenes/overworld/gui/menus/commons/screenName.lua new file mode 100644 index 0000000..88b33d4 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/commons/screenName.lua @@ -0,0 +1,35 @@ +local TextElement = require "birb.modules.gui.elements.text" +local ScreenNameElement = TextElement:extend() + +local nameList = { + mainmenuScreen = "Menu", + itemScreen = "Items", + useItemScreen = "Use item", + setEquipScreen = "Equip item" +} + +function ScreenNameElement:new(owner, fontName, x, y, align) + self.owner = owner + ScreenNameElement.super.new(self, "screenName", fontName, "", x, y, align) + self.opacity = 0 + self.currentScreen = "Menu" +end + + +function ScreenNameElement:getText() + if (self.owner.subscreens == nil) then + return "Menu" + end + local newScreen = self.owner.subscreens.currentScreen + if (not utils.string.isEmpty(newScreen)) then + if game.characters.list[newScreen] ~= nil then + local data = core.datas:get("characters", newScreen) + self.currentScreen = data.name + else + self.currentScreen = nameList[newScreen] + end + end + return self.currentScreen or "" +end + +return ScreenNameElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/init.lua b/sonic-radiance.love/scenes/overworld/gui/menus/init.lua new file mode 100644 index 0000000..59207f1 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/init.lua @@ -0,0 +1,44 @@ +local GuiScreen = require "birb.modules.gui.screen" +local MenuScreen = GuiScreen:extend() + +local ScreenNameElement = require "scenes.overworld.gui.menus.commons.screenName" + +local MainMenuScreen = require "scenes.overworld.gui.menus.mainmenu" +local ItemScreen = require "scenes.overworld.gui.menus.items" +local UseItemScreen = require "scenes.overworld.gui.menus.useItem" +local SetEquipScreen = require "scenes.overworld.gui.menus.useItem.equip" +local CharacterScreen = require "scenes.overworld.gui.menus.character" + +local show = { + {"screenName", "movement", 0, 0.5, 160, 12, "inOutQuart"}, + {"screenName", "tween", 0, 0.5, {opacity = 1}, "inOutQuart"}, +} + +local hide = { + {"screenName", "movement", 0, 0.5, 160, -18, "inOutQuart"}, + {"screenName", "tween", 0, 0.5, {opacity = 0}, "inOutQuart"}, +} + +function MenuScreen:new() + MenuScreen.super.new(self, "startmenu") + self:addTransform("show", show) + self:addTransform("hide", hide) + self:addSubscreen(MainMenuScreen()) + self:addSubscreen(ItemScreen()) + self:addSubscreen(UseItemScreen()) + self:addSubscreen(SetEquipScreen()) + for charName, _ in pairs(game.characters.list) do + self:addSubscreen(CharacterScreen(charName)) + end + self.subscreens.delay = -1 +end + +function MenuScreen:createElements() + local list = { + {ScreenNameElement(self, "SA2font", 160, -18, "left"), 0, -100} + } + + return list +end + +return MenuScreen diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/items/init.lua b/sonic-radiance.love/scenes/overworld/gui/menus/items/init.lua new file mode 100644 index 0000000..e3516be --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/items/init.lua @@ -0,0 +1,171 @@ +local ItemsScreen = require("birb.modules.gui.screen"):extend() +local ItemMenu = require("game.modules.gui.boxedmenu") +local BoxedText = require("scenes.overworld.gui.menus.commons.boxedtext") +local ItemRoulette = require("scenes.overworld.gui.menus.items.roulette") + +local POCKET_LIST = require "datas.gamedata.items" +local const = require "scenes.overworld.gui.menus.commons.const" + +local MENU_WIDTH, DESC_SIZE, USE_SIZE = 128+32, 48*4, 96 + +local EFFECT_H, DESC_H = 40, 56 +local HIDE_X, USE_X = 16, 16 - USE_SIZE / 2 +local DESC_Y, USE_Y = (EFFECT_H + 8) + DESC_H, 24 + +local ConfirmDialog = require "game.modules.confirmdialog" + +local show = { + {"itemRoulette", "movement", 0.1, 0.3, const.X, const.Y, "inOutQuart"}, + {"itemRoulette", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + {"descText", "movement", 0.1, 0.3, const.X, const.Y2 - DESC_Y, "inOutQuart"}, + {"descText", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + {"effectText", "movement", 0.1, 0.3, const.X, const.Y2 - EFFECT_H, "inOutQuart"}, + {"effectText", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + {"itemMenu", "movement", 0.1, 0.3, const.X2 - MENU_WIDTH, const.Y + 4, "inOutQuart"}, + {"itemMenu", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + {"useMenu", "tween", 0.0, 0.3, {opacity = 0, sx = 1, sy = 1}, "inOutQuart"}, +} + +local hide = { + {"itemRoulette", "movement", 0, 0.3, const.X - HIDE_X, const.Y, "inOutQuart"}, + {"itemRoulette", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {"descText", "movement", 0, 0.3, const.X - HIDE_X, const.Y2 - DESC_Y, "inOutQuart"}, + {"descText", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {"effectText", "movement", 0, 0.3, const.X - HIDE_X, const.Y2 - EFFECT_H, "inOutQuart"}, + {"effectText", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {"itemMenu", "movement", 0, 0.3, const.X2 - MENU_WIDTH + HIDE_X, const.Y + 4, "inOutQuart"}, + {"itemMenu", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {"useMenu", "tween", 0.0, 0.3, {opacity = 0, sx = 0.8, sy = 0.8}, "inOutQuart"}, +} + +local showUseMenu = { + {"useMenu", "tween", 0.0, 0.3, {opacity = 1, sx = 1, sy = 1}, "inOutQuart"}, + {"useMenu", "delayFocus", 0} +} + +local hideUseMenu = { + {"useMenu", "tween", 0.0, 0.3, {opacity = 0, sx = 0.8, sy = 0.8}, "inOutQuart"}, + {"itemMenu", "delayFocus", 0} +} + +function ItemsScreen:new() + self.desc, self.effect = "", "" + ItemsScreen.super.new(self, "itemScreen") + self:addTransform("show", show) + self:addTransform("hide", hide) + self:addTransform("showUseMenu", showUseMenu) + self:addTransform("hideUseMenu", hideUseMenu) + self.defaultFocus = "itemMenu" +end + +function ItemsScreen:createElements() + self.menu = ItemMenu("itemMenu", const.X2 - MENU_WIDTH, const.Y + 4, MENU_WIDTH, 9, true, true) + self.menu.opacity = 0 + self:rebuildMenu() + + self.use = ItemMenu("useMenu", const.X2 + USE_X, const.Y2 - USE_Y, USE_SIZE, 3, true, false) + self.use.opacity, self.use.ox, self.use.oy = 0, USE_SIZE/2, self.use.h / 2 + + return {{self.menu, 0, 1}, + {BoxedText("descText", const.X, const.Y2 - DESC_Y, DESC_SIZE, DESC_H, function () return {{1, self.desc}} end), 0, 1}, + {BoxedText("effectText", const.X, const.Y2 - EFFECT_H, DESC_SIZE, EFFECT_H, function () return {{1, self.effect}} end), 0, 1}, + {ItemRoulette(self, const.X, const.Y), 0, 1}, + {self.use, 0, 1} + } +end + +function ItemsScreen:rebuildMenu() + self.menu:clear() + for i, pocket in ipairs(POCKET_LIST) do + self.menu:addPage(pocket.name) + self.menu:switch(pocket.name) + local pocketData = game.loot:getPocketById(i) + + for j,item in ipairs(pocketData.list) do + local itemData = core.datas:get("items", item.name) + self.menu:addItem(itemData.fullname, "left", function () self:showUseMenu(item, j) end, "navigate", {{"x" .. utils.math.numberToString(item.number, 2), "right"}}, nil, {item.name}) + end + + self.menu:addItem("Back", "left", function() self.gui:showScreen("mainmenuScreen") end, "back") + self.menu:addHoverAction(function(widget) self:setDescEffectFromWidget(widget) end) + self.menu:setCancelWidget() + self.menu:addLateralAction(function (key) if (key == "left") then self:changePage(-1) else self:changePage(1) end end) + end + self.menu:switch("medicines") +end + +function ItemsScreen:showUseMenu(item, i) + self.dropQuantity = 1 + self.use:clear() + self.use:addItem("Use", "left", function () self:useItem(item.name, i) end, "") + self.use:addItem("Drop", "left", function () self:dropItem(item.name) end, "select", {{"<" .. utils.math.numberToString(self.dropQuantity, 2) .. ">", "right"}}) + self.use:addItem("Back", "left", function () self:playTransform("hideUseMenu") end, "back") + self.use:addLateralAction(function(key, funcWidget, id) + if (key == "left" and id == 2) then + self:modifyDrop(-1, funcWidget, item.number) + elseif (key == "right" and id == 2) then + self:modifyDrop(1, funcWidget, item.number) + end end) + self.use:setCancelWidget() + self:playTransform("showUseMenu") +end + +function ItemsScreen:useItem(itemName, i) + local pocketData = game.loot:getPocketByName(self.menu:getCurrentPageName()) + local itemData = core.datas:get("items", itemName) + if (pocketData.isEquipement) then + self.gui:showScreen("setEquipScreen", nil, nil, nil, {self.menu:getCurrentPageName(), game.loot:getPocketByName(self.menu:getCurrentPageName()).list[i], i}) + self.gui.scene.assets:playSFX("mSelect") + elseif (itemData.usableOnMap) then + self.gui:showScreen("useItemScreen", nil, nil, nil, {self.menu:getCurrentPageName(), game.loot:getPocketByName(self.menu:getCurrentPageName()).list[i], i}) + self.gui.scene.assets:playSFX("mSelect") + else + self.gui.scene.assets:playSFX("mError") + end +end + +function ItemsScreen:dropItem(itemName) + local confirm = ConfirmDialog(self.scene, "Do you want to drop these items ? \nYou won't be able to recover them.", + function() + game.loot:removeItem(self.menu:getCurrentPageName(), itemName, self.dropQuantity) + self:rebuildMenu() + self:playTransform("hideUseMenu") + end) + confirm:setCancelChoice(2) + confirm.autoDismiss = true +end + +function ItemsScreen:modifyDrop(direction, widget, max) + self.dropQuantity = utils.math.wrap(self.dropQuantity + direction, 1, max) + widget:replaceLabel(2, "<" .. utils.math.numberToString(self.dropQuantity, 2) .. ">") + widget.canvas.needRedraw = true + self.use.canvas.needRedraw = true + self.gui.scene.assets.sfx["mBeep"]:play() +end + +function ItemsScreen:setDescEffectFromWidget(widget) + if (widget.datas ~= nil) then + self:setDescEffect(widget.datas[1]) + else + self.desc, self.effect = "", "" + end +end + +function ItemsScreen:changePage(direction) + local id = self:getPocketData() + local newMenuIndex = utils.math.wrap(id + direction, 1, #POCKET_LIST) + self.menu:switch(POCKET_LIST[newMenuIndex].name) + self.gui.scene.assets.sfx["mBeep"]:play() +end + +function ItemsScreen:setDescEffect(name) + local itemData = core.datas:get("items", name) + self.desc, self.effect = itemData.description, game.loot:getEffectStrings("", name) +end + +function ItemsScreen:getPocketData() + local id = game.loot:getPocketIdByName(self.menu:getCurrentPageName()) + return id, self.menu:getCurrentPageName(), POCKET_LIST[id].fullname +end + +return ItemsScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/items/roulette.lua b/sonic-radiance.love/scenes/overworld/gui/menus/items/roulette.lua new file mode 100644 index 0000000..e4374aa --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/items/roulette.lua @@ -0,0 +1,40 @@ +local ItemRoulette = require("birb.modules.gui.elements.canvas"):extend() +local gui = require "game.modules.gui" + +local W, H = 48*4, 48 + 20 + +function ItemRoulette:new(owner, x, y) + ItemRoulette.super.new(self, "itemRoulette", x, y, W, H) + self.choiceBack = gui.newChoiceBack(W) + self.opacity = 0 + self.owner = owner + self.canvas.padding = 0 + self.canvas.isAnimated = true +end + +function ItemRoulette:drawTexture() + love.graphics.draw(self.choiceBack, 0, 0) + + local id, _, fullName = self.owner:getPocketData() + local x2, y2, w2 = 16, -2, (W - 24) + self.scene.assets.fonts["small"]:draw("<", x2, y2, w2, "left") + self.scene.assets.fonts["small"]:draw(">", x2, y2, w2, "right") + self.scene.assets.fonts["small"]:draw(fullName, x2, y2, w2, "center") + + for i, pocket in ipairs(game.loot.inventory) do + local trueIndex = i - id + if (trueIndex > 4) then + trueIndex = trueIndex - 8 + end + if (trueIndex < -4) then + trueIndex = trueIndex + 8 + end + if (trueIndex ~= 0) then + love.graphics.setColor(.3, .3, .3, .6) + end + self.scene.assets.tileset["itembox"]:drawTile(i, W/2 + ((trueIndex)*32), 20, 0, 1, 1, 14, 0) + utils.graphics.resetColor() + end +end + +return ItemRoulette \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/mainmenu.lua b/sonic-radiance.love/scenes/overworld/gui/menus/mainmenu.lua new file mode 100644 index 0000000..6bda72e --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/mainmenu.lua @@ -0,0 +1,87 @@ +local GuiScreen = require "birb.modules.gui.screen" +local MainMenuScreen = GuiScreen:extend() +local FancyMenu = require "game.modules.gui.fancymenu" +local const = require "scenes.overworld.gui.menus.commons.const" + +local NavigationMenu = FancyMenu:extend() +local CharacterMenu = require "scenes.overworld.gui.menus.commons.charmenu" + +local CHARMENU_X = const.X + 136 + +local defTransitions = require "birb.modules.transitions" +local ConfirmDialog = require "game.modules.confirmdialog" + +local show = { + {"navigationMenu", "movement", 0.1, 0.3, const.X, const.Y, "inOutQuart"}, + {"navigationMenu", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + {"navCharMenu", "movement", 0.1, 0.3, CHARMENU_X, const.Y, "inOutQuart"}, + {"navCharMenu", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, +} + +local hide = { + {"navigationMenu", "movement", 0, 0.3, const.X - 16, const.Y, "inOutQuart"}, + {"navigationMenu", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {"navCharMenu", "movement", 0, 0.3, CHARMENU_X + 16, const.Y, "inOutQuart"}, + {"navCharMenu", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, +} + +function MainMenuScreen:new() + MainMenuScreen.super.new(self, "mainmenuScreen") + self:addTransform("show", show) + self:addTransform("hide", hide) + self.defaultFocus = "navigationMenu" +end + +function MainMenuScreen:createElements() + local menu = FancyMenu("navigationMenu", const.X - 16, const.Y, 108, 10, false) + menu:addItem("Team", "left", function() self.gui:setFocus("navCharMenu") end, "navigate", {{">", "right"}}) + menu:addItem("Quest", "left", function() end, "navigate", {{">", "right"}}) + menu:addItem("Items", "left", function() self.gui:showScreen("itemScreen") end, "navigate", {{">", "right"}}) + menu:addItem("Chao", "left", function() end, "navigate", {{">", "right"}}) + menu:addItem("Encylopedia", "left", function() end, "navigate", {{">", "right"}}) + menu:addSubmenu("save", "Save / Exit", "main", true) + menu:addItem("Save game", "left", function() self:save() self.scene:unpause() end, "select") + menu:addItem("Save and exit", "left", function() self:save() self:exitToMenu() end, "navigate") + menu:addItem("Exit game", "left", function() self:exit() end, "select") + menu:switch("main") + menu:addItem("Resume", "left", function() self.scene:unpause() end, "back") + menu:setCancelWidget() + menu.opacity = 0 + + local charMenu = CharacterMenu("navCharMenu", CHARMENU_X + 16, + function (name, i) + self.gui:showScreen(name, nil, 1, "basic") + self.gui:getScreen(name).menu.canvas.needRedraw = true + self.gui:getScreen(name).desc = "" + self.gui:getScreen(name).nbr = i + end, false) + + charMenu:addCancelAction(function () + self.gui:setFocus("navigationMenu") + self.gui.scene.assets:playSFX("mBack") + end) + charMenu.opacity = 0 + return {{menu, 0, 1}, {charMenu, 0, 1}} +end + +function MainMenuScreen:save() + self.scene.world:savePosition() + game:write() +end + +function MainMenuScreen:exit() + local confirm = ConfirmDialog(self.scene, "Do you to exit the game ? \nAll unsaved data will be lost.", + function() self:exitToMenu() end) + confirm:setCancelChoice(2) +end + +function MainMenuScreen:exitToMenu() + core.screen:startTransition(defTransitions.default, defTransitions.circle, function() game:reload() scenes.menus.main() end, 424/2, 240/2) + self.gui:hideScreen("hud") +end + +function NavigationMenu:new() + NavigationMenu.super.new(self) +end + +return MainMenuScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/useItem/equip.lua b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/equip.lua new file mode 100644 index 0000000..3457077 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/equip.lua @@ -0,0 +1,52 @@ +local SetEquipScreen = require("scenes.overworld.gui.menus.useItem.parent"):extend() +local STATS = require "datas.consts.stats" + +function SetEquipScreen:new() + SetEquipScreen.super.new(self, "setEquip", 32 * 6, true) +end + +function SetEquipScreen:applyEffect(character) + character:setEquip(self.category, self.item.name) +end + +function SetEquipScreen:getDescription() + local returnData = {} + table.insert(returnData, {1, self.itemData.fullname}) + self.charName = self.gui:getElement("setEquipMenu").charName + if (self.charName ~= "") then + local char = game.characters.list[self.charName] + + for i, statName in ipairs(STATS.LIST) do + local lineNbr = math.floor((i-1)/2) + local isLeft = ((i%2) == 1) + + local stat = char.stats:get(statName) + local newStat = char:predictStat(statName, self.category, self.item.name) + + local sep = ": " + if i > 2 then + sep = ": " + end + + local line = STATS.SIMPLENAME[statName] .. sep .. utils.math.numberToString(stat, 3) .. " > " .. utils.math.numberToString(newStat, 3) + local color = {1, 1, 1, 1} + + if (newStat > stat) then + color = {0.3, 1, 0.3, 0.9} + elseif (newStat < stat) then + color = {1, 0.3, 0.3, 0.9} + end + + table.insert(returnData, {lineNbr + 2, line, utils.math.either(isLeft, "left", "right"), 0, 0, color}) + end + + end + return returnData +end + +function SetEquipScreen:setDatas(datas) + SetEquipScreen.super.setDatas(self, datas) + self.charMenu.showEquip = self.category +end + +return SetEquipScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/useItem/init.lua b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/init.lua new file mode 100644 index 0000000..23ab429 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/init.lua @@ -0,0 +1,23 @@ +local UseItemScreen = require("scenes.overworld.gui.menus.useItem.parent"):extend() +local EffectManager = require "game.loot.effectManager" + +function UseItemScreen:new() + self.effectManager = EffectManager() + UseItemScreen.super.new(self, "useItem", 128, false) +end + +function UseItemScreen:applyEffect(character) + self.effectManager:applyEffects(character) + game.loot:removeItem(self.category, self.item.name, 1) +end + +function UseItemScreen:setDatas(datas) + UseItemScreen.super.setDatas(self, datas) + self.effectManager:getItemData(self.category, self.item.name) +end + +function UseItemScreen:getDescription() + return {{1, self.itemData.fullname .. ":\n" .. self.effects}} +end + +return UseItemScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/useItem/number.lua b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/number.lua new file mode 100644 index 0000000..3b5d5b2 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/number.lua @@ -0,0 +1,21 @@ +local ItemNumberElement = require("birb.modules.gui.elements.canvas"):extend() + +local W = 48 + 16 +local gui = require "game.modules.gui" + +function ItemNumberElement:new(owner, name, x, y) + ItemNumberElement.super.new(self, name, x, y, W, 18) + + self.choiceBack = gui.newChoiceBack(W) + self.canvas.isAnimated, self.canvas.padding = true, 0 + self.owner = owner + self.opacity = 0 +end + +function ItemNumberElement:drawTexture() + love.graphics.draw(self.choiceBack, 0, 0) + + self.scene.assets.fonts["small"]:draw("x" .. self.owner:getItemNumber(), 16, -2, -1, "left") +end + +return ItemNumberElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/menus/useItem/parent.lua b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/parent.lua new file mode 100644 index 0000000..0abeee3 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/menus/useItem/parent.lua @@ -0,0 +1,91 @@ +local UseScreenParent = require("birb.modules.gui.screen"):extend() +local CharacterMenu = require("scenes.overworld.gui.menus.commons.charmenu") +local BoxedText = require "scenes.overworld.gui.menus.commons.boxedtext" +local ItemNumber = require "scenes.overworld.gui.menus.useItem.number" +local const = require "scenes.overworld.gui.menus.commons.const" + +local DESC_H = 40 + 48 +local NBR_Y = 24 + +function UseScreenParent:new(prefix, descW, showEquip) + self.prefix = prefix + + self.descW = descW + self.showEquip = showEquip + self.nbrX = const.X + self.descW - 48 + self.charMenuX = const.X + self.descW + 8 + + UseScreenParent.super.new(self, prefix .. "Screen") + self:addTransformsWithPrefix() + self.defaultFocus = prefix .. "Menu" +end + +function UseScreenParent:addTransformsWithPrefix() + local show = { + {self.prefix .. "Desc", "movement", 0.1, 0.3, const.X, const.Y, "inOutQuart"}, + {self.prefix .. "Desc", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + {self.prefix .. "Nbr", "movement", 0, 0.3, self.nbrX, const.Y2 - NBR_Y, "inOutQuart"}, + {self.prefix .. "Nbr", "tween", 0, 0.3, {opacity = 1}, "inOutQuart"}, + {self.prefix .. "Menu", "movement", 0.1, 0.3, self.charMenuX, const.Y, "inOutQuart"}, + {self.prefix .. "Menu", "tween", 0.1, 0.3, {opacity = 1}, "inOutQuart"}, + } + + local hide = { + {self.prefix .. "Desc", "movement", 0, 0.3, const.X - 16, const.Y, "inOutQuart"}, + {self.prefix .. "Desc", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {self.prefix .. "Nbr", "movement", 0, 0.3, self.nbrX - 16, const.Y2 - NBR_Y, "inOutQuart"}, + {self.prefix .. "Nbr", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + {self.prefix .. "Menu", "movement", 0, 0.3, self.charMenuX + 16, const.Y, "inOutQuart"}, + {self.prefix .. "Menu", "tween", 0, 0.3, {opacity = 0}, "inOutQuart"}, + } + + self:addTransform("show", show) + self:addTransform("hide", hide) +end + +function UseScreenParent:createElements() + self.charMenu = CharacterMenu(self.prefix .. "Menu", self.charMenuX + 16, function(name) self:useItem(name) end, self.showEquip) + self.charMenu:addCancelAction(function() self:exitScreen() end) + self.charMenu.opacity = 0 + return { + {self.charMenu, 0, 1}, + {BoxedText(self.prefix .. "Desc", const.X - 16, const.Y, self.descW, DESC_H, + function() if (self.itemData ~= nil) then return self:getDescription() else return {{1, ""}} end end), 0, 1}, + {ItemNumber(self, self.prefix .. "Nbr", self.nbrX - 16, const.Y2 - NBR_Y), 0, 1} + } +end + +function UseScreenParent:useItem(charName) + local character = game.characters.list[charName] + self:applyEffect(character) + self.gui:getScreen("itemScreen"):rebuildMenu() + if (self.item.number <= 1) then + self:exitScreen() + end +end + +function UseScreenParent:exitScreen() + self.gui:showScreen("itemScreen", nil, self.nbr, self.category) + self.gui.scene.assets:playSFX("mBack") +end + +function UseScreenParent:setDatas(datas) + --category, item, widgetId) + local category = datas[1] + self.item = datas[2] + self.nbr = datas[3] or 1 + self.itemData = core.datas:get("items", self.item.name) + self.category = category + + self.effects = game.loot:getEffectStrings(self.category, self.item.name) +end + +function UseScreenParent:getItemNumber() + if (self.item ~= nil) then + return self.item.number or 0 + end + return 0 +end + + +return UseScreenParent \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index bf9df30..9c199b3 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -27,14 +27,11 @@ local OverWorld = Scene:extend() local World = require "scenes.overworld.world" local CharsetManager = require "scenes.overworld.charsetmanager" -local screens = require "scenes.overworld.screens" - -local gui = require "game.modules.gui" local TweenManager = require "birb.classes.time" - local EventManager = require "game.events" local OWScreen = require "scenes.overworld.gui.init" +local MenusScreen = require "scenes.overworld.gui.menus" function OverWorld:new(area, playerx, playery) OverWorld.super.new(self, false, false) @@ -42,16 +39,11 @@ function OverWorld:new(area, playerx, playery) self.assets:batchImport("assets.overworld") self.tweens = TweenManager(self) - self.screens = screens World(self, area, playerx, playery) self.world:setPlayerNumber(1) self.world:loadMap() - self.currentScreen = nil - - self.backGroundOpacity = 0 - self.borderPosition = 0 self.isPaused = false self.canPause = false self.gui:hideScreen("overlay") @@ -62,6 +54,7 @@ function OverWorld:new(area, playerx, playery) self.events = EventManager(self) OWScreen() + MenusScreen() end function OverWorld:updateCurrentMap(map) @@ -90,13 +83,6 @@ function OverWorld:endEvent() self.canPause = true end -function OverWorld:registerScreen(screen) - if (self.currentScreen ~= nil) then - self.currentScreen:quit() - end - self.currentScreen = screen -end - function OverWorld:update(dt) local keys = self:getKeys(1) self.tweens:update(dt) @@ -106,10 +92,6 @@ function OverWorld:update(dt) self.charsetManager:update(dt) end - if (self.currentScreen ~= nil) then - self.currentScreen:update(dt) - end - if (keys["start"].isPressed and self.canPause) then if (not self.isPaused) then if (not self.gui.screens["overlay"].isVisible) then @@ -124,20 +106,19 @@ function OverWorld:update(dt) end function OverWorld:pause() - self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") self.gui:showScreen("overlay") self.gui:playScreenTransform("hud", "pause") + self.gui:playScreenTransform("overlay", "showBackgroundPause") self.isPaused = true self.world.isActive = false - screens.mainmenu.pause(self) + self.gui:showScreen("startmenu") end function OverWorld:gameover() - self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") self.gui:showScreen("overlay") self.gui:hideScreen("hud") + self.gui:playScreenTransform("overlay", "showBackgroundPause") self.world.isActive = false - screens.gameover(self) end function OverWorld:restored() @@ -152,18 +133,11 @@ function OverWorld:timerResponse(timer) end function OverWorld:unpause() - self.tweens:newTween(0.1, 0.2, {backGroundOpacity=0}, "inQuad") self.tweens:newTimer(0.2, "unPause") + self.gui:playScreenTransform("overlay", "hideBackgroundPause") self.gui:hideScreen("overlay") self.gui:playScreenTransform("hud", "unpause") - - if (self.currentScreen ~= nil) then - self.currentScreen:quit() - end -end - -function OverWorld:quitScreen() - self.currentScreen = nil + self.gui:hideScreen("startmenu") end function OverWorld:getEmblemsPosition() @@ -172,28 +146,6 @@ end function OverWorld:draw() self.events:draw() - self:drawScreenBottomLayer() -end - -function OverWorld:drawOverTransition() - self:drawScreenTopLayer() -end - -function OverWorld:drawScreenBottomLayer() - love.graphics.setColor(0, 0, 0, self.backGroundOpacity) - love.graphics.rectangle("fill", 0, 0, 424, 240) - utils.graphics.resetColor() - - if (self.currentScreen ~= nil) then - self.currentScreen:drawBackground() - self.currentScreen:drawForeground() - end -end - -function OverWorld:drawScreenTopLayer() - if (self.currentScreen ~= nil) then - self.currentScreen:drawOverEverything() - end end return OverWorld diff --git a/sonic-radiance.love/scenes/overworld/screens/gameover.lua b/sonic-radiance.love/scenes/overworld/screens/gameover.lua deleted file mode 100644 index 871db90..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/gameover.lua +++ /dev/null @@ -1,89 +0,0 @@ -local BaseScreen = require "scenes.overworld.screens.parent" -local GameOver = BaseScreen:extend() - -local TweenManager = require "birb.classes.time" - -local gui = require "game.modules.gui" - -local tw, th = 128, 32 - -local defTransitions = require "birb.modules.transitions" -local ConfirmDialog = require "game.modules.confirmdialog" - -function GameOver:new(scene) - GameOver.super.new(self, scene, "") - self.assets = scene.assets - self.turnSystem = scene.turns - - self:setVariables() - - self.continueBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th) - - self.tweens = TweenManager(self) - self:prepareAnimation() -end - -function GameOver:setVariables() - -- Vignette Opacity - self.vignetteOpacity = 0 - - -- Battle FInished Label - self.labelOpacity = 0 - local width, height = core.screen:getDimensions() - self.labelX = width/2 - - -- Infobox - self.tbSize = 0.6 - self.tbOpacity = 0 -end - -function GameOver:prepareAnimation() - -- Label - self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo') - self.tweens:newTween(0.9, 0.4, {labelX=4}, 'inExpo') - - self.tweens:newTimer(1.8, "continue") -end - -function GameOver:update(dt) - self.tweens:update(dt) -end - -function GameOver:draw() - local width, height = core.screen:getDimensions() - self:drawVignette(width, height) - self:drawLabel(width/2, 48, self.labelX, self.labelOpacity) -end - -function GameOver:timerResponse(timer) - if (timer == "continue") then - local confirm = ConfirmDialog(self.scene, "Do you want to return to title ? \nYou can also reload your latest save.", - function() self:returnToTitle() end, "Return to title", - function() self:loadLastSave() end, "Reload last save") - confirm.darken = false - end -end - -function GameOver:drawVignette(width, height) - love.graphics.setColor(0, 0, 0, self.vignetteOpacity) - - love.graphics.rectangle("fill", 0, 0, width, height) -end - -function GameOver:drawLabel(x, y, x2, opacity) - love.graphics.setColor(1, 1, 1, opacity) - - self.assets.fonts["SA2font"]:print("GAME", x - x2, y, "right") - self.assets.fonts["SA2font"]:print("OVER", x + x2, y, "left") -end - -function GameOver:returnToTitle() - core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2) -end - -function GameOver:loadLastSave() - self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad") - core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2) -end - -return GameOver diff --git a/sonic-radiance.love/scenes/overworld/screens/init.lua b/sonic-radiance.love/scenes/overworld/screens/init.lua deleted file mode 100644 index 568e5e9..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/init.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - mainmenu = require "scenes.overworld.screens.mainmenu", - gameover = require "scenes.overworld.screens.gameover" -} diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua deleted file mode 100644 index e639de3..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua +++ /dev/null @@ -1,69 +0,0 @@ -local PageParent = require "scenes.overworld.screens.mainmenu.character.pageparent" -local BasicPage = PageParent:extend() - -local menu = require "game.modules.menus.fancy" -local gui = require "game.modules.gui" -local const = require "scenes.overworld.screens.mainmenu.const" - -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -local HPBAR_SIZE = 80 - -function BasicPage:new(view, character) - self.view = view - self.character = game.characters.list[character] - - self.statBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 48+8) - self.nameBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 40) - - self.hpbar = ComplexHPBar(HPBAR_SIZE) - self.ppbar = ComplexHPBar(HPBAR_SIZE) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) - self.ppbar:setColorForeground(0, 248/255, 248/255, 1) - self.ppbar:setColorBackground(0, 54/255, 229/255) - - BasicPage.super.new(self, view, character, {}) -end - -function BasicPage:draw() - self:drawIdentity(const.X, const.Y) - self:drawHPPP(const.X, const.Y + 48) - self:drawLevel(const.X, 100) - self:drawWeakStrong(const.X, 160) -end - -function BasicPage:drawIdentity(x, y) - local identityString = self.character.fullname .. "\n" - identityString = identityString .. "Class: " .. self.character.data.class - - love.graphics.draw(self.nameBox, x, y) - self.view.scene.assets.fonts["small"]:draw(identityString, x + 6, y + 4, -1, "left") -end - -function BasicPage:drawHPPP(x, y) - local stats = self.character.stats - self.view.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(x, y - 4, self.character.hp, stats:get(stats.HPMAX)) - local xx = x + const.CHARPAGESIZE - HPBAR_SIZE - 7 - self.ppbar:drawWithLabels(xx, y - 4, self.character.pp, stats:get(stats.PPMAX)) -end - -function BasicPage:drawLevel(x, y) - local levelString = "Level: " .. self.character.level .. "\n" - local levelString = levelString .. "Current exp: " .. self.character.exp .. "\n" - local levelString = levelString .. "Next level: " .. self.character.exp_next - - love.graphics.draw(self.statBox, x, y) - self.view.scene.assets.fonts["small"]:draw(levelString, x + 6, y + 4, -1, "left") -end - -function BasicPage:drawWeakStrong(x, y) - local weakString = "Weak to: Nothing"--"Earth, Lightning" - local strongString = "Resist To: Nothing" - - love.graphics.draw(self.nameBox, x, y) - self.view.scene.assets.fonts["small"]:draw(weakString .. "\n" .. strongString, x + 6, y + 4, -1, "left") -end - -return BasicPage diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua deleted file mode 100644 index e442e9d..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua +++ /dev/null @@ -1,122 +0,0 @@ -local ParentScreen = require "scenes.overworld.screens.parent" -local CharacterScreen = ParentScreen:extend() - -local menu = require "game.modules.menus.fancy" -local gui = require "game.modules.gui" -local const = require "scenes.overworld.screens.mainmenu.const" - -local BasicPage = require "scenes.overworld.screens.mainmenu.character.basicpage" -local StatPage = require "scenes.overworld.screens.mainmenu.character.statpage" -local SkillPage = require "scenes.overworld.screens.mainmenu.character.skillpage" -local pageList = {BasicPage, StatPage, SkillPage} - -local ReturnWidget = menu.BaseWidget:extend() - -function CharacterScreen:new(scene, character) - self.character = game.characters.list[character] - self.charName = character - - self.page = BasicPage(self, character) - self.pageIndex = 1 - - self.artwork = love.graphics.newImage("datas/gamedata/characters/" .. character .. "/artwork.png") - self.artworkOrigin = require("datas.gamedata.characters." .. character .. ".artwork") - CharacterScreen.super.new(self, scene, self.character.name) -end - -function CharacterScreen:update(dt) - local keys = self.scene:getKeys(1) - if (keys["left"].isPressed) then - self:setPage(self.pageIndex - 1) - self.scene.assets.sfx["mBeep"]:play() - end - if (keys["right"].isPressed) then - self:setPage(self.pageIndex + 1) - self.scene.assets.sfx["mBeep"]:play() - end -end - -function CharacterScreen:setPage(newPageIndex) - local newPageIndex = newPageIndex or 1 - if (newPageIndex > #pageList) then - newPageIndex = 1 - end - if (newPageIndex < 1) then - newPageIndex = #pageList - end - - self.pageIndex = newPageIndex - self.page = pageList[self.pageIndex](self, self.charName) - self.scene.menusystem:reset() - self:setMenu() -end - -function CharacterScreen:setMenu() - local itemNumber = self.page:getMenuSize() - local y = const.Y2 - (16*itemNumber) + 2 - menu.FancyMenu(self.scene, "menu", const.X2 - 128 - 14, y, 128, itemNumber, false) - self.page:getMenuWidgets() - ReturnWidget(self.scene, self.charName) - - local customMenu = self.page:getCustomMenus() - - self.scene.menusystem:switchMenu("menu") - self.scene.menusystem.menus["menu"]:getFocus() - self.scene.menusystem.menus["menu"]:setCancelWidget() - self.scene.menusystem.menus["menu"].isLocked = true - if (customMenu ~= nil) then - customMenu.isLocked = true - customMenu.isVisible = true - end - self.scene.menusystem:setSoundFromSceneAssets("mBeep") -end - -function CharacterScreen:draw() - if (self.page ~= nil) then - self.page:draw() - end - - for i = 1, #pageList, 1 do - local radius = 2 - if (i == self.pageIndex) then - radius = 3 - end - local x = (16*i) + 240 + 64 - local y = 17 - local outlineLight = 0.15 - love.graphics.circle("fill", x + 8, y + 8, radius, 8) - love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1) - love.graphics.circle("line", x + 8, y + 8, radius, 8) - utils.graphics.resetColor() - end -end - -function CharacterScreen:drawBackground() - love.graphics.draw(self.artwork, self.artworkOrigin.x, self.artworkOrigin.y) -end - -function CharacterScreen:drawOverEverything() - if (self.page ~= nil) then - self.page:drawOverEverything() - end -end - --- Widgets - -function ReturnWidget:new(scene, charName) - self.charName = charName - ReturnWidget.super.new(self, scene, "menu", "Back", "") -end - -function ReturnWidget:action() - for i, name in ipairs(game.characters.team) do - if (name == self.charName) then - self.widgetSelected = i - end - end - self.scene.assets:playSFX("mBack") - - self.scene.screens.mainmenu["pause"](self.scene, "character", self.widgetSelected) -end - -return CharacterScreen diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/pageparent.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/pageparent.lua deleted file mode 100644 index b91b8cd..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/pageparent.lua +++ /dev/null @@ -1,47 +0,0 @@ -local PageParent = Object:extend() -local menu = require "game.modules.menus.fancy" -local Widget = menu.BaseWidget:extend() - -function PageParent:new(view, character, menu) - self.view = view - self.character = game.characters.list[character] - self.menu = menu or {} -end - -function PageParent:update(dt) -end - -function PageParent:getMenuSize() - return #self.menu + 1 -end - -function PageParent:getMenuWidgets() - for index, name in ipairs(self.menu) do - Widget(self, name, index) - end -end - -function PageParent:menuResponses(i) -end - -function PageParent:getCustomMenus() -end - -function PageParent:draw() -end - -function PageParent:drawOverEverything() -end - -function Widget:new(page, name, num) - self.num = num - self.page = page - Widget.super.new(self, self.page.view.scene, "menu", name, ">") -end - -function Widget:action() - self.page:menuResponses(self.num) - self.scene.assets.sfx["mBeep"]:play() -end - -return PageParent diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua deleted file mode 100644 index db4681c..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua +++ /dev/null @@ -1,71 +0,0 @@ -local PageParent = require "scenes.overworld.screens.mainmenu.character.pageparent" -local StatPage = PageParent:extend() - -local menu = require "game.modules.menus.list" -local const = require "scenes.overworld.screens.mainmenu.const" - -local SkillMenu = menu.ListMenu:extend() -local SkillWidget = menu.DualTextWidget:extend() -local PLAYER_MESSAGE = 240 - 24 - -function StatPage:new(view, character) - StatPage.super.new(self, view, character, {"See skill"}) - self.message = "" - self.showMessage = false -end - -function StatPage:getCustomMenus() - return SkillMenu(self, self.character) -end - -function StatPage:menuResponses(i) - if (#self.character.skills > 0) then - self.view.scene.menusystem:switchMenu("equip") - self.showMessage = true - end -end - -function StatPage:drawOverEverything() - if (not utils.string.isEmpty(self.message) and self.showMessage) then - love.graphics.setColor(0,0,0, 0.66) - love.graphics.rectangle("fill", 0, PLAYER_MESSAGE, 424, 16) - self.view.scene.assets.fonts["small"]:setColor(1,1,1, 1) - self.view.scene.assets.fonts["small"]:draw(self.message, 424/2, PLAYER_MESSAGE - 1, -1, "center") - self.view.scene.assets.fonts["small"]:setColor(1,1,1, 1) - utils.graphics.resetColor() - end -end - -function StatPage:setMessage(message) - self.message = message -end - -function StatPage:removeEquip(type) - self.character:removeEquip(type) -end - -function SkillMenu:new(page, character) - self.page = page - SkillMenu.super.new(self, page.view.scene, "equip", const.X, const.Y + 4, const.CHARPAGESIZE, 9, true, true) - for _, skill in ipairs(character.skills) do - SkillWidget(page, skill.name) - end -end - -function SkillMenu:cancelAction() - self.scene.menusystem.menus["menu"]:getFocus() - self.page.showMessage = false - self.scene.assets.sfx["mBack"]:play() -end - -function SkillWidget:new(page, skill) - self.page = page - self.skillData = core.datas:get("skills", skill) - SkillWidget.super.new(self, self.page.view.scene, "equip", self.skillData.fullname, utils.math.numberToString(self.skillData.cost, 2)) -end - -function SkillWidget:selectAction() - self.page:setMessage(self.skillData.description) -end - -return StatPage diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua deleted file mode 100644 index 4401ec3..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua +++ /dev/null @@ -1,88 +0,0 @@ -local PageParent = require "scenes.overworld.screens.mainmenu.character.pageparent" -local StatPage = PageParent:extend() - -local menu = require "game.modules.menus.list" -local gui = require "game.modules.gui" -local const = require "scenes.overworld.screens.mainmenu.const" - -local EquipMenu = menu.ListMenu:extend() -local EquipWidget = menu.DualTextWidget:extend() - -local STATS = require "datas.consts.stats" - -function StatPage:new(view, character) - self.statBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 40 + 32) - - StatPage.super.new(self, view, character, {"Remove item"}) -end - -function StatPage:getCustomMenus() - return EquipMenu(self) -end - -function StatPage:menuResponses(i) - self.view.scene.menusystem:switchMenu("equip") -end - -function StatPage:draw() - self:drawStats(const.X, 100) -end - -function StatPage:drawStats(x, y) - love.graphics.draw(self.statBox, x, y) - - local char = self.character - for i, statName in ipairs(STATS.LIST) do - local xStat = x + (((i - 1) % 2) * (const.CHARPAGESIZE/2)) + 6 - local yStat = y + (math.floor((i-1)/2) * 16) + 4 - local middle = xStat + 10 + const.CHARPAGESIZE/4 - local stat = char.stats:get(statName) - self.view.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, const.CHARPAGESIZE, "left") - self.view.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9) - self.view.scene.assets.fonts["small"]:draw(stat, middle, yStat, -1, "center") - self.view.scene.assets.fonts["small"]:setColor(1, 1, 1, 1) - utils.graphics.resetColor() - end -end - -function StatPage:removeEquip(type) - self.character:removeEquip(type) -end - -function EquipMenu:new(page) - self.page = page - EquipMenu.super.new(self, page.view.scene, "equip", const.X, const.Y + 4, const.CHARPAGESIZE, 3, true, true) - EquipWidget(page, "gloves") - EquipWidget(page, "shoes") - EquipWidget(page, "accessories") -end - -function EquipMenu:cancelAction() - self.scene.menusystem.menus["menu"]:getFocus() - self.scene.assets.sfx["mBack"]:play() -end - -function EquipWidget:new(page, type) - self.page = page - self.type = type - local label = self:getLabel() - EquipWidget.super.new(self, self.page.view.scene, "equip", label, "") -end - -function EquipWidget:getLabel() - local obj = self.page.character.equip[self.type] - if (utils.string.isEmpty(obj)) then - return "No " .. self.type - end - local data = core.datas:get("items", obj) - return data.fullname -end - -function EquipWidget:action() - self.page:removeEquip(self.type) - self.label = self:getLabel() - self:redrawCanvas() - self.scene.assets.sfx["mSelect"]:play() -end - -return StatPage diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua deleted file mode 100644 index 6ec5cbc..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua +++ /dev/null @@ -1,12 +0,0 @@ -local baseMenu = require "game.modules.menus.parents.menu" -local CharacterMenu = baseMenu:extend() - -local const = require "scenes.overworld.screens.mainmenu.const" - -function CharacterMenu:new(scene, x) - local x = x or const.X + 136 - local w = const.WIDTH - x + 28 - CharacterMenu.super.new(self, scene, "character", x, const.Y, w, const.HEIGHT, 4) -end - -return CharacterMenu diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua deleted file mode 100644 index c4fddf0..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua +++ /dev/null @@ -1,65 +0,0 @@ -local baseWidget = require "game.modules.menus.parents.widget" -local CharacterWidget = baseWidget:extend() - -local ComplexHPBar = require "game.modules.gui.complexhpbar" -local Emblem = require "game.modules.gui.emblem" - --- Hero custom widget --- -function CharacterWidget:new(scene, name, showEquip) - self.charName = name - self.emblem = Emblem(game.characters.list[name], scene) - self.font2 = scene.assets.fonts["hudnbrs_small"] - self.showEquip = showEquip - CharacterWidget.super.new(self, scene, "character") - - self.hpbar = ComplexHPBar(88) - self.ppbar = ComplexHPBar(88) - self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1) - self.hpbar:setColorBackground(112 / 255, 0, 0) - self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1) - self.ppbar:setColorBackground(0, 54 / 255, 229 / 255) -end - -function CharacterWidget:drawCanvas() - local character = game.characters.list[self.charName] - self.font:setFilter("shadow") - local debut = 0 - local xDebut = 32 - self.font:draw(character.fullname, xDebut, debut, -1, "left") - if (self.showEquip == nil) then - local yLvl = debut + 16 - local xLvl = xDebut - self.scene.assets.images["lvl"]:draw(xLvl, yLvl) - self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10) - self.font2:print(character.level, xLvl + 19, yLvl, "left") - local expString = character.exp .. "/" .. character.exp_next - self.font2:print(expString, xLvl + 19, yLvl + 10, "left") - else - local charEquip = character.equip[self.showEquip] - local equipString = "None" - if (not utils.string.isEmpty(charEquip)) then - local data = core.datas:get("items", charEquip) - equipString = data.fullname - end - self.font:draw(equipString, xDebut, debut + 16, -1, "left") - end -end - -function CharacterWidget:draw(x, y) - local character = game.characters.list[self.charName] - self.emblem:draw(x, y + 6) - if (self.showEquip == nil) then - local xDebut = x + 52 - local yDebut = y + 15 - self.scene.assets.fonts["hudnbrs_small"]:set() - local stats = character.stats - self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, stats:get(stats.HPMAX)) - self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, stats:get(stats.PPMAX)) - end - if self.canvas.texture ~= nil then - love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy) - end -end - -return CharacterWidget diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua deleted file mode 100644 index 51bd2cb..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua +++ /dev/null @@ -1,115 +0,0 @@ -local ParentScreen = require "scenes.overworld.screens.parent" -local EquipScreen = ParentScreen:extend() - -local menu = require "game.modules.menus.list" -local const = require "scenes.overworld.screens.mainmenu.const" -local gui = require "game.modules.gui" - -local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu" -local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget" -local CharacterMenu = baseCharacterMenu:extend() -local CharacterWidget = baseCharacterWidget:extend() - -local STATS = require "datas.consts.stats" - -local DESC_SIZE = 32 * 6 - -function EquipScreen:new(scene, category, item, widgetId) - self.category = category - self.item = item - self.itemData = core.datas:get("items", self.item.name) - self.widgetId = widgetId - - self.choiceBack = gui.newChoiceBack(48 + 16) - self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40 + 48+16) - - self.desc = self.itemData.description - self.charName = "" - EquipScreen.super.new(self, scene, "Equipement") -end - -function EquipScreen:setMenu() - CharacterMenu(self.scene, 224) - for i, name in ipairs(game.characters.team) do - CharacterWidget(self.scene, name, self.category) - end - self.scene.menusystem:switchMenu("character") -end - -function EquipScreen:draw() - self.scene.assets.fonts["small"]:setLineHeight(16 / 18) - self:drawPocket() - self:drawDescription(const.X, const.Y) -end - -function EquipScreen:drawDescription(x, y) - love.graphics.draw(self.descBox, x, y) - local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12 - self.scene.assets.fonts["small"]:draw(self.itemData.fullname, xx, yy, ww, "left") - if (self.charName ~= "") then - local char = game.characters.list[self.charName] - for i, statName in ipairs(STATS.LIST) do - local xStat = xx + (((i - 1) % 2) * (ww/2)) - local yStat = yy + (math.floor((i-1)/2) * 16) + 24 - local middle = xStat + 10 + ww/4 - local stat = char.stats:get(statName) - local newStat = char:predictStat(statName, self.category, self.item.name) - self.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, ww, "left") - self.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9) - self.scene.assets.fonts["small"]:draw(stat .. " ", middle, yStat, -1, "right") - self.scene.assets.fonts["small"]:draw(">", middle, yStat, -1, "center") - if (newStat > stat) then - self.scene.assets.fonts["small"]:setColor(0.3, 1, 0.3, 0.9) - elseif (newStat < stat) then - self.scene.assets.fonts["small"]:setColor(1, 0.3, 0.3, 0.9) - end - - self.scene.assets.fonts["small"]:draw(" " .. newStat, middle, yStat, -1, "left") - self.scene.assets.fonts["small"]:setColor(1, 1, 1, 1) - utils.graphics.resetColor() - end - end -end - -function EquipScreen:drawPocket() - local x = const.X + DESC_SIZE - 48 - local y = const.Y2 - 24 - love.graphics.draw(self.choiceBack, x, y) - - self.scene.assets.fonts["small"]:draw("x" .. self.item.number, x + 16, y - 2, -1, "left") -end - -function EquipScreen:goBack() - self.scene.screens.mainmenu["items"](self.scene, game.loot:getPocketIdByName(self.category), self.widgetId) -end - -function EquipScreen:useItem(charName) - local character = game.characters.list[charName] - if (self.item.number <= 1) then - character:setEquip(self.category, self.item.name) - self:goBack() - else - character:setEquip(self.category, self.item.name) - end -end - --- Character menu -function CharacterMenu:cancelAction() - -- Switch à l'écran précédant - self.scene.assets:playSFX("mBack") - self.scene.currentScreen:goBack() -end - --- Hero custom widget --- -function CharacterWidget:selectAction() - self.scene.currentScreen.charName = self.charName -end - -function CharacterWidget:action() - self.scene.assets:playSFX("mSelect") - self.scene.currentScreen:useItem(self.charName) - self:redrawCanvas() -end - -return EquipScreen diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/init.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/init.lua deleted file mode 100644 index 423dc7d..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -return { - pause = require "scenes.overworld.screens.mainmenu.pause", - character = require "scenes.overworld.screens.mainmenu.character", - items = require "scenes.overworld.screens.mainmenu.items", - useItems = require "scenes.overworld.screens.mainmenu.useitems", - equip = require "scenes.overworld.screens.mainmenu.equip" -} diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua deleted file mode 100644 index 65e1308..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua +++ /dev/null @@ -1,258 +0,0 @@ -local ParentScreen = require "scenes.overworld.screens.parent" -local ItemsScreen = ParentScreen:extend() - -local menu = require "game.modules.menus.list" -local const = require "scenes.overworld.screens.mainmenu.const" -local gui = require "game.modules.gui" - -local ItemWidget = menu.DualTextWidget:extend() -local BackWidget = menu.DualTextWidget:extend() -local ResumeWidget = menu.DualTextWidget:extend() -local DropWidget = menu.DualTextWidget:extend() -local UseWidget = menu.DualTextWidget:extend() - -local DESC_SIZE = 48*4 - -local ConfirmDialog = require "game.modules.confirmdialog" - -function ItemsScreen:new(scene, menuIndex, widgetIndex) - self.menuIndex = menuIndex or 1 - self.widgetIndex = widgetIndex or 1 - self.choiceBack = gui.newChoiceBack(DESC_SIZE) - self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40+16) - self.effectBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40) - self.desc = "" - self.effects = "" - ItemsScreen.super.new(self, scene, "Items") -end - -function ItemsScreen:update(dt) - if (self.scene.menusystem.menus["useMenu"] == nil) then - local keys = self.scene:getKeys(1) - if (keys["left"].isPressed) then - self.widgetIndex = 1 - self:getMenu(self.menuIndex - 1) - self.scene.assets.sfx["mBeep"]:play() - end - if (keys["right"].isPressed) then - self.widgetIndex = 1 - self:getMenu(self.menuIndex + 1) - self.scene.assets.sfx["mBeep"]:play() - end - end -end - -function ItemsScreen:getMenu(newMenuIndex) - local newMenuIndex = newMenuIndex or 1 - if (newMenuIndex > #game.loot.inventory) then - newMenuIndex = 1 - end - if (newMenuIndex < 1) then - newMenuIndex = #game.loot.inventory - end - - self.menuIndex = newMenuIndex - self.scene.menusystem:reset() - self:setMenu() -end - -function ItemsScreen:setMenu(widgetId) - self.pocket = game.loot:getPocketById(self.menuIndex) - local w = 128+32 - menu.ListMenu(self.scene, "menu", const.X2 - w, const.Y + 8, w, 9, true) - for i,item in ipairs(self.pocket.list) do - --menu.DualTextWidget(self.scene, "menu", item.name, "x" .. item.number) - ItemWidget(self.scene, self.pocket.name, item, i) - end - BackWidget(self.scene) - self.scene.menusystem.menus["menu"]:setCancelWidget() - self.scene.menusystem:switchMenu("menu") - self.scene.menusystem.menus["menu"].isLocked = true - self.scene.menusystem.menus["menu"].widget.selected = math.max(1, self.widgetIndex) - self.scene.menusystem.menus["menu"].cursorTransition = math.max(0, self.widgetIndex - 1) - self.scene.menusystem:setSoundFromSceneAssets("mBeep") -end - -function ItemsScreen:setUseMenu(item, widgetId) - local w = 96 - menu.ListMenu(self.scene, "useMenu", const.X2 + 16 - w, const.Y2 - 48, w, 3, true) - UseWidget(self.scene, self.pocket.name, item, widgetId) - DropWidget(self.scene, self.pocket.name, item, widgetId) - ResumeWidget(self.scene) - self.scene.menusystem.menus["useMenu"]:setCancelWidget() - self.scene.menusystem:switchMenu("useMenu") - self.scene.menusystem.menus["useMenu"]:setDepth(-1) -end - -function ItemsScreen:removeUseMenu() - self.scene.menusystem.menus["useMenu"]:destroy() - self.scene.menusystem:switchMenu("menu") -end - -function ItemsScreen:draw() - self:drawPocket() - self:drawDescription(const.X, const.Y2 - (88+16)) - self:drawEffects(const.X, const.Y2 - 40) -end - -function ItemsScreen:drawDescription(x, y) - love.graphics.draw(self.descBox, x, y) - local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12 - self.scene.assets.fonts["small"]:draw(self.desc, xx, yy, ww, "left") -end - -function ItemsScreen:drawEffects(x, y) - love.graphics.draw(self.effectBox, x, y) - local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12 - self.scene.assets.fonts["small"]:draw(self.effects, xx, yy, ww, "left") -end - -function ItemsScreen:drawPocket() - local middleX = ((16) + (DESC_SIZE - 24)) / 2 - love.graphics.draw(self.choiceBack, const.X, const.Y) - - self.scene.assets.fonts["small"]:draw("<", const.X + 16, const.Y - 2, -1, "left") - self.scene.assets.fonts["small"]:draw(">", const.X + DESC_SIZE - 24, const.Y - 2, -1, "right") - self.scene.assets.fonts["small"]:draw(self.pocket.fullname, const.X + middleX, const.Y - 2, -1, "center") - - self:drawPocketRoll(const.X + 48*2, const.Y + 20) -end - -function ItemsScreen:drawPocketRoll(x, y) - core.screen:setScissor(const.X, const.Y+ 16, 48*4, 48) - - local trueX = x - ((self.menuIndex - 1) * 32) - for i, pocket in ipairs(game.loot.inventory) do - local trueIndex = i - self.menuIndex - if (trueIndex > 4) then - trueIndex = trueIndex - 8 - end - if (trueIndex < -4) then - trueIndex = trueIndex + 8 - end - if (trueIndex ~= 0) then - love.graphics.setColor(.3, .3, .3, .6) - end - self.scene.assets.tileset["itembox"]:drawTile(i, x + ((trueIndex)*32), y, 0, 1, 1, 14, 0) - utils.graphics.resetColor() - end - - core.screen:resetScissor() -end - --- Items Widgets -function ItemWidget:new(scene, pocket, item, widgetId) - self.item = item - self.itemData = core.datas:get("items", self.item.name) - self.pocket = pocket - self.widgetId = widgetId - ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. utils.math.numberToString(self.item.number, 2)) -end - -function ItemWidget:selectAction() - self.scene.currentScreen.desc = self.itemData.description - self.scene.currentScreen.effects = game.loot:getEffectStrings(self.pocket, self.item.name) -end - -function ItemWidget:action() - self.scene.assets:playSFX("mSelect") - self.scene.currentScreen:setUseMenu(self.item, self.widgetId) -end - -function BackWidget:new(scene) - ItemWidget.super.new(self, scene, "menu", "Back", "") -end - -function BackWidget:selectAction() - self.scene.currentScreen.desc = "" - self.scene.currentScreen.effects = "" -end - -function BackWidget:action() - self.scene.assets:playSFX("mBack") - self.scene.screens.mainmenu["pause"](self.scene, "main", 3) -end - --- Use Menu Widget - -function UseWidget:new(scene, pocket, item, widgetId) - self.item = item - self.itemData = core.datas:get("items", self.item.name) - self.pocket = pocket - self.pocketData = game.loot:getPocketByName(self.pocket) - self.widgetId = widgetId - UseWidget.super.new(self, scene, "useMenu", "Use", "") - if (not (self.itemData.usableOnMap or self.pocketData.isEquipement)) then - self.color = {0.6, 0.6, 0.6} - end -end - -function UseWidget:action() - if (self.pocketData.isEquipement) then - self.scene.screens.mainmenu["equip"](self.scene, self.pocket, self.item, self.widgetId) - self.scene.assets:playSFX("mSelect") - elseif (self.itemData.usableOnMap) then - self.scene.screens.mainmenu["useItems"](self.scene, self.pocket, self.item, self.widgetId) - self.scene.assets:playSFX("mSelect") - else - self.scene.assets:playSFX("mError") - end -end - -function DropWidget:new(scene, pocket, item, widgetId) - self.item = item - self.itemData = core.datas:get("items", self.item.name) - self.pocket = pocket - self.max = self.item.number - self.widgetId = widgetId - self.number = 1 - DropWidget.super.new(self, scene, "useMenu", "Drop", "<" .. utils.math.numberToString(self.number, 2) .. ">") -end - -function DropWidget:updateSelected() - local keys = self.scene:getKeys(1) - if (keys["left"].isPressed) then - if (self.number > 1) then - self.number = self.number - 1 - else - self.number = self.max - end - self.label2 = "<" .. utils.math.numberToString(self.number, 2) .. ">" - self:invalidateCanvas() - end - if (keys["right"].isPressed) then - if (self.number < self.max) then - self.number = self.number + 1 - else - self.number = 1 - end - self.label2 = "<" .. utils.math.numberToString(self.number, 2) .. ">" - self:invalidateCanvas() - end -end - -function DropWidget:action() - self.scene.assets:playSFX("mSelect") - local confirm = ConfirmDialog(self.scene, "Do you want to drop these items ? \nYou won't be able to recover them.", - function() self:drop() end) - confirm:setCancelChoice(2) - confirm.autoDismiss = true -end - -function DropWidget:drop() - game.loot:removeItem(self.pocket, self.item.name, self.number) - self.scene.currentScreen.widgetIndex = self.widgetId - self.scene.currentScreen:removeUseMenu() - self.scene.currentScreen:setMenu() -end - -function ResumeWidget:new(scene) - ResumeWidget.super.new(self, scene, "useMenu", "Back", "") -end - -function ResumeWidget:action() - self.scene.assets:playSFX("mBack") - self.scene.currentScreen:removeUseMenu() -end - -return ItemsScreen diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua deleted file mode 100644 index c73f79c..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ /dev/null @@ -1,137 +0,0 @@ -local ParentScreen = require "scenes.overworld.screens.parent" -local PauseScreen = ParentScreen:extend() - -local menu = require "game.modules.menus.fancy" - -local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu" -local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget" -local CharacterMenu = baseCharacterMenu:extend() -local CharacterWidget = baseCharacterWidget:extend() - -local TeamWidget = menu.BaseWidget:extend() -local ViewWidget = menu.BaseWidget:extend() -local SaveExitWidget = menu.BaseWidget:extend() - -local defTransitions = require "birb.modules.transitions" -local radTransitions = require "game.modules.transitions" -local ConfirmDialog = require "game.modules.confirmdialog" - -local const = require "scenes.overworld.screens.mainmenu.const" - -function PauseScreen:new(scene, menu, widget) - self.menuSelected = menu or "main" - self.widgetSelected = widget - self.widget = widget - PauseScreen.super.new(self, scene, "Menu") -end - -function PauseScreen:setMenu() - menu.FancyMenu(self.scene, "main", const.X, const.Y, 108, 10, false) - TeamWidget(self.scene) - menu.BaseWidget(self.scene, "main", "Quest", ">") - ViewWidget(self.scene, "Items", "items") - menu.BaseWidget(self.scene, "main", "Chao", ">") - menu.BaseWidget(self.scene, "main", "Encylopedia", ">") - --menu.BaseWidget(self.scene, "main", "Options", ">") - self.scene.menusystem.menus["main"]:addSubMenu("save", "Save / Exit") - SaveExitWidget(self.scene, "main", "Resume", false, false) - - SaveExitWidget(self.scene, "save", "Save game", true, false) - SaveExitWidget(self.scene, "save", "Save and exit", true, true) - SaveExitWidget(self.scene, "save", "Exit game", false, true) - - self.scene.menusystem.menus["main"]:finalize() - self.scene.menusystem.menus["main"]:setCancelWidget() - - CharacterMenu(self.scene) - for i, name in ipairs(game.characters.team) do - CharacterWidget(self.scene, name) - end - self.scene.menusystem.menus["character"].isLocked = true - - self.scene.menusystem:switchMenu(self.menuSelected) - self.scene.menusystem.menus["main"].isVisible = true - if (self.widgetSelected ~= nil) then - self.scene.menusystem.menus[self.menuSelected].widget.selected = self.widgetSelected - self.scene.menusystem.menus[self.menuSelected].cursorTransition = self.widgetSelected - 1 - end - self.scene.menusystem:setSoundFromSceneAssets("mBeep") -end - -function PauseScreen:draw() - -end - --- Character menu -function CharacterMenu:cancelAction() - self.scene.assets:playSFX("mBeep") - self.scene.menusystem:switchMenu("main") -end - --- Hero custom widget --- -function CharacterWidget:action() - self.scene.assets:playSFX("mSelect") - self.scene.screens.mainmenu.character(self.scene, self.charName) -end - --- Team Widget --- - -function TeamWidget:new(scene) - TeamWidget.super.new(self, scene, "main", "Team", ">") -end - -function TeamWidget:action() - self.scene.assets:playSFX("mBeep") - self.scene.menusystem.menus["character"]:getFocus() -end - --- View Widget -function ViewWidget:new(scene, name, view) - TeamWidget.super.new(self, scene, "main", name, ">") - self.nextView = view -end - -function ViewWidget:action() - self.scene.assets:playSFX("mSelect") - self.scene.screens.mainmenu[self.nextView](self.scene) -end - --- Save & Exit Widget -function SaveExitWidget:new(scene, menu, name, save, exit) - SaveExitWidget.super.new(self, scene, menu, name, "") - self.exit = exit - self.save = save -end - -function SaveExitWidget:action() - if (self.save or self.exit) then - self.scene.assets:playSFX("mSelect") - else - self.scene.assets:playSFX("mBack") - end - if (self.save) then - self.scene.world:savePosition() - game:write() - end - if (self.exit) then - if (self.save) then - self:exitToMenu() - else - local confirm = ConfirmDialog(self.scene, "Do you to exit the game ? \nAll unsaved data will be lost.", - function() self:exitToMenu() end) - confirm:setCancelChoice(2) - end - else - self.scene:unpause() - end -end - -function SaveExitWidget:exitToMenu() - core.screen:startTransition(defTransitions.default, defTransitions.circle, function() game:reload() scenes.menus.main() end, 424/2, 240/2) - self.scene.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad") - self.scene.tweens:newTween(0, 0.3, {timeBorder=-20}, "inOutQuad") -end - -return PauseScreen diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/useitems.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/useitems.lua deleted file mode 100644 index 795dad2..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/useitems.lua +++ /dev/null @@ -1,91 +0,0 @@ -local ParentScreen = require "scenes.overworld.screens.parent" -local UseItemsScreen = ParentScreen:extend() - -local menu = require "game.modules.menus.list" -local const = require "scenes.overworld.screens.mainmenu.const" -local gui = require "game.modules.gui" - -local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu" -local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget" -local CharacterMenu = baseCharacterMenu:extend() -local CharacterWidget = baseCharacterWidget:extend() - -local EffectManager = require "game.loot.effectManager" - -local DESC_SIZE = 32 * 4 - -function UseItemsScreen:new(scene, category, item, widgetId) - UseItemsScreen.super.new(self, scene, "Use item") - self.category = category - self.item = item - self.itemData = core.datas:get("items", self.item.name) - self.widgetId = widgetId - - self.choiceBack = gui.newChoiceBack(48 + 16) - self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40 + 48) - - self.desc = self.itemData.description - self.effects = game.loot:getEffectStrings(self.category, self.item.name) - - self.effectManager = EffectManager() - self.effectManager:getItemData(category, self.item.name) -end - -function UseItemsScreen:setMenu() - CharacterMenu(self.scene) - for i, name in ipairs(game.characters.team) do - CharacterWidget(self.scene, name) - end - self.scene.menusystem:switchMenu("character") -end - -function UseItemsScreen:draw() - self.scene.assets.fonts["small"]:setLineHeight(16 / 18) - self:drawPocket() - self:drawDescription(const.X, const.Y) -end - -function UseItemsScreen:drawDescription(x, y) - love.graphics.draw(self.descBox, x, y) - local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12 - self.scene.assets.fonts["small"]:draw(self.itemData.fullname .. ":\n" .. self.effects, xx, yy, ww, "left") -end - -function UseItemsScreen:drawPocket() - local x = const.X + DESC_SIZE - 48 - local y = const.Y2 - 24 - love.graphics.draw(self.choiceBack, x, y) - - self.scene.assets.fonts["small"]:draw("x" .. self.item.number, x + 16, y - 2, -1, "left") -end - -function UseItemsScreen:goBack() - self.scene.screens.mainmenu["items"](self.scene, game.loot:getPocketIdByName(self.category), self.widgetId) -end - -function UseItemsScreen:useItem(charName) - local character = game.characters.list[charName] - self.effectManager:applyEffects(character) - if (self.item.number <= 1) then - game.loot:removeItem(self.category, self.item.name, 1) - self:goBack() - else - game.loot:removeItem(self.category, self.item.name, 1) - end -end - --- Character menu -function CharacterMenu:cancelAction() - -- Switch à l'écran précédant - self.scene.assets:playSFX("mBack") - self.scene.currentScreen:goBack() -end - --- Hero custom widget --- -function CharacterWidget:action() - self.scene.assets:playSFX("mSelect") - self.scene.currentScreen:useItem(self.charName) -end - -return UseItemsScreen diff --git a/sonic-radiance.love/scenes/overworld/screens/menu.lua b/sonic-radiance.love/scenes/overworld/screens/menu.lua deleted file mode 100644 index 9a46d31..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/menu.lua +++ /dev/null @@ -1,103 +0,0 @@ -local ListBox = require "birb.modules.menusystem.listbox" -local Widget = require "birb.modules.menusystem.widgets" - -local menu = {} -menu.CustomMenu = ListBox:extend() -menu.BasicMenu = ListBox:extend() -menu.BoxedMenu = menu.BasicMenu:extend() -menu.BasicWidget = Widget.Text:extend() -menu.BoxedWidget = menu.BasicWidget:extend() - -local CONST = {} -CONST.MENU = {} -CONST.MENU.ITEM_HEIGHT = 16 - -local gui = require "game.modules.gui" - --- Custom Menu -function menu.CustomMenu:new(scene, name, x, y, w, h, itemNumber) - self.scene = scene - menu.CustomMenu.super.new(self, scene.menusystem, name, x, y, w, h, itemNumber) -end - --- Basic menu -function menu.BasicMenu:new(scene, name, itemNumber, x, y, w) - self.scene = scene - local h = itemNumber * CONST.MENU.ITEM_HEIGHT - menu.BasicMenu.super.new(self, scene.menusystem, name, x, y, w, h, itemNumber) - self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") - self.cursorTransition = 0 -end - -function menu.BasicMenu:update(dt) - menu.BasicMenu.super.update(self, dt) - - local relativecursor = self.widget.selected - self.view.firstSlot - - local transition = self.cursorTransition - relativecursor - - if math.abs(transition) < 0.1 then - self.cursorTransition = relativecursor - else - self.cursorTransition = (self.cursorTransition) + ((relativecursor) - (self.cursorTransition)) * dt*45 - end - -end - -function menu.BasicMenu:drawCursor() - local addition = 17 - local x = self.x - 1 - local y = self.y + ((self.cursorTransition) * addition) + 1 - love.graphics.draw(self.cursorTexture, x, y) -end - --- Boxed menu -function menu.BoxedMenu:new(scene, name, itemNumber, x, y, w) - menu.BoxedMenu.super.new(self, scene, name, itemNumber, x, y, w) - self.box = gui.newTextBox("assets/gui/dialogbox.png", self.w+16, self.h+16) -end - -function menu.BoxedMenu:draw() - love.graphics.draw(self.box, self.x-8, self.y-8) - menu.BoxedMenu.super.draw(self) -end - --- Basic Widget -function menu.BasicWidget:new(scene, menu_name, label, label2) - local font = scene.assets.fonts["small"] - self.scene = scene - local widgetMenu = scene.menusystem.menus[menu_name] - self.label2 = label2 or "" - menu.BasicWidget.super.new(self, widgetMenu, font, label) -end - -function menu.BasicWidget:drawCanvas() - local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - love.graphics.setColor(0, 0, 0, 1) - self.font:print(self.label, 9, h, "left") - self.font:print(self.label2, self.width - 7, h, "right") - utils.graphics.resetColor() - self.font:print(self.label, 8, h, "left") - self.font:print(self.label2, self.width - 8, h, "right") -end - --- Basic Widget -function menu.BoxedWidget:new(scene, menu_name, label, label2) - menu.BoxedWidget.super.new(self, scene, menu_name, label, label2) - self.box = gui.newChoiceBack(self.menu.w + 24) -end - -function menu.BoxedWidget:drawCanvas() - love.graphics.draw(self.box, 0, 0) - - local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 1 - love.graphics.setColor(0, 0, 0, .8) - self.font:print(self.label, 17, h, "left") - self.font:print(self.label2, self.width - 8, h, "right") - utils.graphics.resetColor() - self.font:print(self.label, 16, h, "left") - self.font:print(self.label2, self.width - 9, h, "right") -end - - -return menu diff --git a/sonic-radiance.love/scenes/overworld/screens/parent.lua b/sonic-radiance.love/scenes/overworld/screens/parent.lua deleted file mode 100644 index 061077b..0000000 --- a/sonic-radiance.love/scenes/overworld/screens/parent.lua +++ /dev/null @@ -1,49 +0,0 @@ -local MenuScreenParent = Object:extend() - -local menu = require "scenes.overworld.screens.menu" -local const = require "scenes.overworld.screens.mainmenu.const" - -function MenuScreenParent:new(scene, title) - self.scene = scene - self.menusystem = scene.menusystem - - self.menuObj = menu - - self.title = title or "" - - self.scene:registerScreen(self) - self:setMenu() -end - -function MenuScreenParent:update(dt) - -end - -function MenuScreenParent:setMenu() - -end - -function MenuScreenParent:quit() - self.scene.menusystem:reset() - self.scene:quitScreen() -end - -function MenuScreenParent:drawForeground() - self.scene.assets.fonts["SA2font"]:print(self.title, 160, 12) - --love.graphics.rectangle("line", const.X, const.Y, const.WIDTH, const.HEIGHT) - self:draw() -end - - -function MenuScreenParent:draw() - -end - -function MenuScreenParent:drawBackground() - -end - -function MenuScreenParent:drawOverEverything() -end - -return MenuScreenParent -- 2.30.2 From 11e028e0e95ca9ee8f81c267f95a0ccf0c6745ca Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 14:34:45 +0100 Subject: [PATCH 098/102] improvement: port the debug menu to gui --- .../scenes/battlesystem/init.lua | 2 +- .../menus/debugmenus/animation/init.lua | 43 +++---- .../menus/debugmenus/animation/menu.lua | 19 --- .../menus/debugmenus/battleBack/init.lua | 27 ++--- .../menus/debugmenus/battleBack/menu.lua | 19 --- .../menus/debugmenus/choregraphy/init.lua | 61 ++++------ .../menus/debugmenus/choregraphy/menu.lua | 34 ------ .../scenes/menus/debugmenus/commons/scene.lua | 36 ++++++ .../scenes/menus/debugmenus/init.lua | 112 ++++++++++++++++++ sonic-radiance.love/scenes/menus/init.lua | 1 + .../scenes/menus/mainmenu/menu.lua | 7 ++ .../scenes/menus/options/const.lua | 5 + .../scenes/menus/options/init.lua | 2 - .../scenes/menus/options/menu.lua | 8 +- 14 files changed, 212 insertions(+), 164 deletions(-) delete mode 100644 sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua delete mode 100644 sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua delete mode 100644 sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua create mode 100644 sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua create mode 100644 sonic-radiance.love/scenes/menus/debugmenus/init.lua create mode 100644 sonic-radiance.love/scenes/menus/options/const.lua diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 43c0713..bc8be04 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -13,7 +13,7 @@ local CbsScreen = require "scenes.battlesystem.gui" local TweenManager = require "birb.classes.time" function BattleSystem:new(battleData) - BattleSystem.super.new(self) + BattleSystem.super.new(self, false, false) self.assets:batchImport("assets.battle") self:playMusic(battleData.music) diff --git a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua index 023f999..0f08f0a 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua @@ -1,35 +1,28 @@ -local Scene = require "game.scenes" -local menu = require "scenes.menus.debugmenus.animation.menu" +local Scene = require "scenes.menus.debugmenus.commons.scene" local CharAnimViewer = Scene:extend() local Background = require "game.modules.drawing.parallaxBackground" local Sprite = require "birb.modules.assets.types.sprites" - function CharAnimViewer:new() CharAnimViewer.super.new(self) - self.assets:batchImport("assets.debug") - local mainMenu = menu.commons.DebugMenu(self, "MainMenu") - - self:setBackground("city") - - for charName, _ in pairs(game.characters.list) do - mainMenu:addSubMenu(charName, charName) - local sprite = Sprite("datas/gamedata/characters/" .. charName .. "/sprites") - for animName, _ in pairs(sprite.data.animations) do - menu.AnimationWidget(self, charName, animName) - end - end - menu.commons.SceneWidget(self, "MainMenu", scenes.menus.main, "Back") - - self.menusystem:activate() - self.menusystem:switchMenu("MainMenu") + self.background = Background(self, 5, 1, "city") self.sprite = nil end -function CharAnimViewer:constructMenu() - +function CharAnimViewer:initMenu() + for charName, _ in pairs(game.characters.list) do + self.menu:addSubmenu(charName, charName, "main", true) + self.menu:switch(charName) + local sprite = Sprite("datas/gamedata/characters/" .. charName .. "/sprites") + for animName, _ in pairs(sprite.data.animations) do + self.menu:addItem(animName, "left", function() + self:setSpriteAndAnim(charName, animName) + self:hideMenu() + end, "select") + end + end end function CharAnimViewer:setSpriteAndAnim(character, animationName) @@ -39,18 +32,12 @@ end function CharAnimViewer:update(dt) - if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then - self.menusystem:activate() - end + CharAnimViewer.super.update(self,dt) if (self.sprite ~= nil) then self.sprite:update(dt) end end -function CharAnimViewer:setBackground(newBackground) - self.background = Background(self, 5, 1, newBackground) -end - function CharAnimViewer:draw() self.background:draw() if (self.sprite ~= nil) then diff --git a/sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua b/sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua deleted file mode 100644 index 1fe81b5..0000000 --- a/sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua +++ /dev/null @@ -1,19 +0,0 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.list" -local menu = {} -menu.commons = commons -menu.AnimationWidget = listMenu.DualTextWidget:extend() - --- ShowBackground -function menu.AnimationWidget:new(scene, menuName, animName) - menu.AnimationWidget.super.new(self, scene, menuName, animName, "") - self.charName = menuName - self.animName = animName -end - -function menu.AnimationWidget:action() - self.scene:setSpriteAndAnim(self.charName, self.animName) - self.scene.menusystem:deactivate() -end - -return menu diff --git a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua index 7928d32..25fcb0c 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua @@ -1,31 +1,20 @@ -local Scene = require "game.scenes" -local menu = require "scenes.menus.debugmenus.battleBack.menu" - +local Scene = require "scenes.menus.debugmenus.commons.scene" local BackgroundViewer = Scene:extend() + local Background = require "game.modules.drawing.parallaxBackground" local backgroundList = require "datas.gamedata.maps.shoot.zones" - function BackgroundViewer:new() BackgroundViewer.super.new(self) - self.assets:batchImport("assets.debug") - menu.commons.DebugMenu(self, "MainMenu") - self:setBackground("city") - - for backId, backgroundData in pairs(backgroundList) do - menu.ShowBackgroundWidget(self, "MainMenu", backgroundData.name, backId) - end - menu.commons.SceneWidget(self, "MainMenu", scenes.menus.main, "Back") - - self.menusystem:activate() - self.menusystem:switchMenu("MainMenu") end - -function BackgroundViewer:update(dt) - if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then - self.menusystem:activate() +function BackgroundViewer:initMenu() + for backId, backgroundData in pairs(backgroundList) do + self.menu:addItem(backgroundData.name, "left", function() + self:setBackground(backId) + self:hideMenu() + end, "select") end end diff --git a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua deleted file mode 100644 index 9927170..0000000 --- a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua +++ /dev/null @@ -1,19 +0,0 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.list" -local menu = {} -menu.commons = commons -menu.ShowBackgroundWidget = listMenu.DualTextWidget:extend() - --- ShowBackground -function menu.ShowBackgroundWidget:new(scene, menuName, backgroundName, backgroundId) - menu.ShowBackgroundWidget.super.new(self, scene, menuName, backgroundName, "") - self.backgroundId = backgroundId -end - -function menu.ShowBackgroundWidget:action() - self.scene:setBackground(self.backgroundId) - self.scene.menusystem:deactivate() -end - - -return menu diff --git a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua index 8105301..3ae8f6e 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua @@ -1,6 +1,4 @@ -local Scene = require "game.scenes" -local menu = require "scenes.menus.debugmenus.choregraphy.menu" - +local Scene = require "scenes.menus.debugmenus.commons.scene" local ChoregraphyViewer = Scene:extend() local World = require "scenes.battlesystem.world" @@ -11,48 +9,34 @@ function ChoregraphyViewer:new() self.assets:batchImport("assets.battle") self.world = World(self) - self:buildMenu() self:buildMocks() end -- MENU FUNCTIONS -function ChoregraphyViewer:buildMenu() - menu.commons.DebugMenu(self, "MainMenu") - - self:buildCharacterMenu() - - self.menusystem.menus["MainMenu"]:finalize() - self.menusystem:activate() - self.menusystem:switchMenu("MainMenu") - menu.commons.SceneWidget(self, "MainMenu", scenes.menus.main, "Back") -end - -function ChoregraphyViewer:buildCharacterMenu() +function ChoregraphyViewer:initMenu() for i,category in ipairs(core.datas:getCategories("ennemies")) do - self:buildEnnemyListMenu(category) + self:buildEnnemyMenu(category) end - self:addSubMenu("characters", "MainMenu", "Rivals") + self.menu:addSubmenu("characters", "Rivals", "main", true) for k, character in pairs(game.characters.list) do - self:addSubMenu(k, "characters", character.fullname) - menu.HeroChoregraphyWidget(self, k, core.datas:get("skills", "attack")) + self.menu:addSubmenu(k, character.fullname, "characters") + self:addItem("rivals", k, core.datas:get("skills", "attack")) self:buildSkillMenu(k) end end -function ChoregraphyViewer:buildEnnemyListMenu(category) - self:addSubMenu(category, "MainMenu", category) - for i,ennemy in ipairs(core.datas.getFromCategory("ennemies", category)) do - self:buildEnnemySkillMenu(category, ennemy) - end -end +function ChoregraphyViewer:buildEnnemyMenu(category) + self.menu:addSubmenu(category, category, "main", true) -function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy) - self:addSubMenu(ennemy, category, ennemy) - local data = core.datas:get("ennemies", ennemy) - for j,skillName in ipairs(data.skills) do - if (core.datas:exists("badskills", skillName)) then - menu.EnnemyChoregraphyWidget(self, category, ennemy, core.datas:get("badskills", skillName)) + for i,ennemy in ipairs(core.datas:getFromCategory("ennemies", category)) do + self.menu:addSubmenu(ennemy, ennemy, category, true) + local data = core.datas:get("ennemies", ennemy) + + for j,skillName in ipairs(data.skills) do + if (core.datas:exists("badskills", skillName)) then + self:addItem(category, ennemy, core.datas:get("badskills", skillName)) + end end end end @@ -65,15 +49,14 @@ function ChoregraphyViewer:buildSkillMenu(charName) if (skillTreated[skillName] ~= true) then skillTreated[skillName] = true if (core.datas:exists("skills", skillName)) then - menu.HeroChoregraphyWidget(self, charName, core.datas:get("skills", skillName)) + self:addItem("rivals", charName, core.datas:get("skills", skillName)) end end end end -function ChoregraphyViewer:addSubMenu(submenu, parent, name) - local parent = parent or "MainMenu" - self.menusystem.menus[parent]:addSubMenu(submenu, name) +function ChoregraphyViewer:addItem(category, ennemy, data) + self.menu:addItem(data.name, "left", function() self:playEnnemyChoregraphy(category, ennemy, data) end, "select") end -- MOCKS FUNCTIONS @@ -86,7 +69,11 @@ function ChoregraphyViewer:playHeroChoregraphy(character, data) end function ChoregraphyViewer:playEnnemyChoregraphy(category, ennemy, data) - self.fighter:playEnnemyChoregraphy(category, ennemy, data) + if (category == "rivals") then + self.fighter:playHeroChoregraphy(ennemy, data) + else + self.fighter:playEnnemyChoregraphy(category, ennemy, data) + end end -- OTHER diff --git a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua deleted file mode 100644 index 9ef4fac..0000000 --- a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua +++ /dev/null @@ -1,34 +0,0 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.list" -local menu = {} -menu.commons = commons -menu.HeroChoregraphyWidget = listMenu.DualTextWidget:extend() -menu.EnnemyChoregraphyWidget = listMenu.DualTextWidget:extend() - --- ShowBackground -function menu.HeroChoregraphyWidget:new(scene, charName, skillData) - menu.HeroChoregraphyWidget.super.new(self, scene, charName, skillData.name, "") - self.character = charName - self.skillData = skillData -end - -function menu.HeroChoregraphyWidget:action() - self.scene:playHeroChoregraphy(self.character, self.skillData) - self.scene.menusystem:deactivate() -end - --- ShowBackground -function menu.EnnemyChoregraphyWidget:new(scene, category, charName, skillData) - menu.EnnemyChoregraphyWidget.super.new(self, scene, charName, skillData.name, "") - self.category = category - self.character = charName - self.skillData = skillData -end - -function menu.EnnemyChoregraphyWidget:action() - self.scene:playEnnemyChoregraphy(self.category, self.character, self.skillData) - self.scene.menusystem:deactivate() -end - - -return menu diff --git a/sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua b/sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua new file mode 100644 index 0000000..19abdf6 --- /dev/null +++ b/sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua @@ -0,0 +1,36 @@ +local DebugScene = require("game.scenes"):extend() +local BoxedMenu = require("game.modules.gui.boxedmenu") + +local defTransitions = require "birb.modules.transitions" + +local CONST = { + MENU = {X = 16, Y = 48, W = (424/2)/ 1.5, ITEM_NUMBER = 8} +} + +function DebugScene:new() + DebugScene.super.new(self, false, false) + self.assets:batchImport("assets.debug") + self.menu = BoxedMenu("debugMenu", CONST.MENU.X, CONST.MENU.Y, CONST.MENU.W, CONST.MENU.ITEM_NUMBER, true, false) + self:initMenu() + self.menu:switch("main") + self.menu:addItem("Back", "left", function() + core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scenes.menus.debug.menu() end, 424/2, 240/2) + end, "back") + self.gui:setFocus("debugMenu") +end + +function DebugScene:initMenu() + +end + +function DebugScene:hideMenu() + self.menu.isVisible = false +end + +function DebugScene:update(dt) + if (love.keyboard.isDown("z") and (not self.menu.isVisible)) then + self.menu.isVisible = true + end +end + +return DebugScene \ No newline at end of file diff --git a/sonic-radiance.love/scenes/menus/debugmenus/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/init.lua new file mode 100644 index 0000000..737f8a9 --- /dev/null +++ b/sonic-radiance.love/scenes/menus/debugmenus/init.lua @@ -0,0 +1,112 @@ +local Scene = require "game.scenes" +local DebugMenu = Scene:extend() + +local MenuBack = require "game.modules.gui.menuback" +local BoxedMenu = require "game.modules.gui.boxedmenu" + +local const = require "scenes.menus.options.const" +local defTransitions = require "birb.modules.transitions" + +function DebugMenu:new(page, widgetId) + DebugMenu.super.new(self, true, true) + + local screenw, _ = core.screen:getDimensions() + self.menu = BoxedMenu("debugMenu", screenw/2, const.MENU_Y, const.MENU_W, const.MENU_ITEM_NUMBER, true) + MenuBack() + + self.menu.ox = const.MENU_W/2 + + self:rebuild() + + self.menu:switch(page or "main") + self.menu:setCursor(widgetId or 1) + self.gui:setFocus("debugMenu") +end + +function DebugMenu:rebuild() + self:buildBattleMenu() + self:buildSaveMenu() + self:buildOtherMenu() + self.menu:switch("main") + self.menu:addItem("Back", "left", function() self:changeScene(scenes.menus.main, nil, true) end, "back") + self.menu:setCancelWidget() +end + +function DebugMenu:buildBattleMenu() + self.menu:addSubmenu("combat", "Battle System", "main", true) + self.menu:addSubmenu("launchBattle", "Launch Battle", "combat", true) + + local listCat = core.datas:getCategories("battles") + + for i,battleCat in ipairs(listCat) do + local menuName = "b_" .. battleCat + + self.menu:addSubmenu(menuName, battleCat, "launchBattle", true) + + for j, battleName in ipairs(core.datas:getFromCategory("battles", battleCat)) do + local data = core.datas:get("battles", battleName) + self.menu:addItem("Launch " .. battleName, "left", function() self:changeScene(scenes.cbs, data, false) end, "select") + end + end + + self.menu:switch("combat") + + self.menu:addItem("Background Viewer ", "left", function() self:changeScene(scenes.menus.debug.battleBack, nil, false) end, "select") + self.menu:addItem("Animation Viewer ", "left", function() self:changeScene(scenes.menus.debug.animation, nil, false) end, "select") + self.menu:addItem("Ennemies' Action Viewer ", "left", function() self:changeScene(scenes.menus.debug.choregraphy, nil, false) end, "select") +end + + +function DebugMenu:buildSaveMenu() + self.menu:addSubmenu("characters", "Characters", "main", true) + self.menu:addSubmenu("team", "Team Formation", "characters", true) + + for name, data in pairs(game.characters.list) do + self.menu:switch("characters") + self:addCharacterMenu(name, data) + self.menu:switch("team") + self.menu:addItem(data.fullname, "left", function() + game.characters:addOrRemoveToTeam(name) + game:write() + end, "select") + end + + self:addInventory() +end + +function DebugMenu:addCharacterMenu(name, data) + self.menu:addSubmenu(name, data.fullname, "characters", true) + self.menu:addItem("Level Up", "left", function() data:levelUp() game:write() end, "select") +end + +function DebugMenu:addInventory() + self.menu:addSubmenu("inventory", "Inventory", "main", true) + for i,pocket in ipairs(game.loot.inventory) do + self.menu:addSubmenu(pocket.name, pocket.fullname, "inventory", true) + for j, item in ipairs(core.datas:getFromCategory("items", pocket.name)) do + local data = core.datas:get("items", item) + self.menu:addItem(data.fullname, "left", function() game.loot:addItem(pocket.name, item, 1) game:write() end, "select") + end + end +end + +function DebugMenu:buildOtherMenu() + self.menu:addSubmenu("other", "Other gameplay", "main", true) + self.menu:addItem("Shadow Shot Maps", "left", function() self:changeScene(scenes.test2, nil, false) end, "select") + self.menu:addSubmenu("battleMaps", "Sonic Battle Maps", "other", true) + + local mapList = require "datas.gamedata.maps.battle" + for i, name in ipairs(mapList) do + local mapData = require("datas.gamedata.maps.battle." .. name) + local trueName = mapData.name + self.menu:addItem(trueName, "left", function() self:changeScene(scenes.test, name, false) end, "select") + end + +end + +function DebugMenu:changeScene(scene, arg, useFade) + local trans2 = utils.math.either(useFade == true, defTransitions.default, defTransitions.circle) + core.screen:startTransition(defTransitions.default, trans2, function() scene(arg) end, 424/2, 240/2) +end + +return DebugMenu diff --git a/sonic-radiance.love/scenes/menus/init.lua b/sonic-radiance.love/scenes/menus/init.lua index 941170a..849e218 100644 --- a/sonic-radiance.love/scenes/menus/init.lua +++ b/sonic-radiance.love/scenes/menus/init.lua @@ -5,6 +5,7 @@ return { battleBack = require "scenes.menus.debugmenus.battleBack", choregraphy = require "scenes.menus.debugmenus.choregraphy", animation = require "scenes.menus.debugmenus.animation", + menu = require "scenes.menus.debugmenus" }, options = require "scenes.menus.options" } diff --git a/sonic-radiance.love/scenes/menus/mainmenu/menu.lua b/sonic-radiance.love/scenes/menus/mainmenu/menu.lua index d5d2f40..4743dd2 100644 --- a/sonic-radiance.love/scenes/menus/mainmenu/menu.lua +++ b/sonic-radiance.love/scenes/menus/mainmenu/menu.lua @@ -11,6 +11,9 @@ local MENU_ITEM_NUMBER = 8 function MainMenu:new() MainMenu.super.new(self, "mainmenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, false) self:addItem("Launch game", "left", function() self:launchGame() end) + if (core.debug.active) then + self:addItem("Debug Menu", "left", function() self:launchDebug() end) + end self:addItem("Options", "left", function() self:launchOptions() end) self:addItem("Return to title", "left", function() self:returnToTitle() end, "back") self:setCancelWidget() @@ -23,6 +26,10 @@ function MainMenu:launchGame() core.scenemanager.currentScene:hideOverlay() end +function MainMenu:launchDebug() + core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.debug.menu() end, 424/2, 240/2) +end + function MainMenu:launchOptions() core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2) end diff --git a/sonic-radiance.love/scenes/menus/options/const.lua b/sonic-radiance.love/scenes/menus/options/const.lua new file mode 100644 index 0000000..ec7965a --- /dev/null +++ b/sonic-radiance.love/scenes/menus/options/const.lua @@ -0,0 +1,5 @@ +return { + MENU_Y = 48, + MENU_W = math.floor(424 / 1.5), + MENU_ITEM_NUMBER = 8 +} \ No newline at end of file diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index 7e4e7b4..9db0b13 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -2,8 +2,6 @@ local Scene = require "game.scenes" local OptionsMenu = Scene:extend() local OptionMenu = require "scenes.menus.options.menu" - -local gui = require "game.modules.gui" local MenuBack = require "game.modules.gui.menuback" function OptionsMenu:new() diff --git a/sonic-radiance.love/scenes/menus/options/menu.lua b/sonic-radiance.love/scenes/menus/options/menu.lua index 52614d1..0b5b622 100644 --- a/sonic-radiance.love/scenes/menus/options/menu.lua +++ b/sonic-radiance.love/scenes/menus/options/menu.lua @@ -11,14 +11,12 @@ local KeysWidget = TextMenuWidget:extend() local defTransitions = require "birb.modules.transitions" local ConfirmDialog = require "game.modules.confirmdialog" -local MENU_Y = 48 -local MENU_W = 424 / 1.5 -local MENU_ITEM_NUMBER = 8 +local const = require "scenes.menus.options.const" function MainMenu:new() local screenw, screenh = core.screen:getDimensions() - MainMenu.super.new(self, "optionMenu", screenw/2, MENU_Y, MENU_W, MENU_ITEM_NUMBER, true) - self.ox = MENU_W/2 + MainMenu.super.new(self, "optionMenu", screenw/2, const.MENU_Y, const.MENU_W, const.MENU_ITEM_NUMBER, true) + self.ox = const.MENU_W/2 self:addVideoMenu() self:addAudioMenu() self:addDifficultyMenu() -- 2.30.2 From e19dd22d8c778d40216b4ead70ddc8c9b1192216 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 14:35:34 +0100 Subject: [PATCH 099/102] chore: remove old common menu --- .../scenes/menus/commons/menu.lua | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 sonic-radiance.love/scenes/menus/commons/menu.lua diff --git a/sonic-radiance.love/scenes/menus/commons/menu.lua b/sonic-radiance.love/scenes/menus/commons/menu.lua deleted file mode 100644 index e5da981..0000000 --- a/sonic-radiance.love/scenes/menus/commons/menu.lua +++ /dev/null @@ -1,76 +0,0 @@ -local menu = {} - -local RadianceListMenu = require "game.modules.menus.fancy" -local defTransitions = require "birb.modules.transitions" - -menu.MainMenu = RadianceListMenu.FancyMenu:extend() -menu.DebugMenu = RadianceListMenu.FancyMenu:extend() -menu.SceneWidget = RadianceListMenu.BaseWidget:extend() - -local CONST = {} -CONST.MENU = {} -CONST.MENU.X = 16 -CONST.MENU.Y = 48 -CONST.MENU.W = 424/2 -CONST.MENU.ITEM_NUMBER = 8 - --- Basic menu structure -function menu.MainMenu:new(scene, name) - local x, y = CONST.MENU.X, CONST.MENU.Y - local w = CONST.MENU.W / 1.5 - local itemNumber = CONST.MENU.ITEM_NUMBER - menu.MainMenu.super.new(self, scene, name, x, y, w, itemNumber, false) -end - -function menu.DebugMenu:new(scene, name) - local x, y = CONST.MENU.X, CONST.MENU.Y - local w = CONST.MENU.W - local itemNumber = CONST.MENU.ITEM_NUMBER - menu.DebugMenu.super.new(self, scene, name, x, y, w, itemNumber, false) -end - -function menu.DebugMenu:setPanel(panel, panelArgument) - self.panel = panel - self.panelArgument = panelArgument -end - -function menu.DebugMenu:activationAction() - if (self.panel ~= nil) then - self.scene.panel = self.panel(self.panelArgument) - end -end - -function menu.DebugMenu:clone(name) - return menu.DebugMenu(self.scene, name) -end - -function menu.DebugMenu:draw() - love.graphics.setColor(0, 0, 0, 0.5) - love.graphics.rectangle("fill", self.x, self.y, self.w, self.h) - utils.graphics.resetColor() - menu.DebugMenu.super.draw(self) -end - --- SceneWidget -function menu.SceneWidget:new(scene, menuName, newScene, newSceneName, sceneArgument) - menu.SceneWidget.super.new(self, scene, menuName, newSceneName, "") - self.newScene = newScene - self.sceneArgument = sceneArgument -end - -function menu.SceneWidget:action() - self.scene.assets:playSFX("mSelect") - self.scene:flushKeys() - if (self.sceneArgument ~= nil) then - core.screen:startTransition(defTransitions.default, defTransitions.default, - function() self.newScene(self.sceneArgument) end, - 0, 0) - else - core.screen:startTransition(defTransitions.default, defTransitions.default, - function() self.newScene() end, - 0, 0) - end -end - - -return menu -- 2.30.2 From f8a831d280427837a3dc9d6207f102a61b840d0b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 18:57:42 +0100 Subject: [PATCH 100/102] improvement: port subgames to gui --- .../game/modules/subgames/init.lua | 58 +++++++++---- .../game/modules/subgames/pause.lua | 86 ++++++++----------- .../subgames/world/actors/player/init.lua | 10 --- .../scenes/battlesystem/actors/gfx.lua | 4 +- 4 files changed, 79 insertions(+), 79 deletions(-) diff --git a/sonic-radiance.love/game/modules/subgames/init.lua b/sonic-radiance.love/game/modules/subgames/init.lua index 1c383c3..f1c1942 100644 --- a/sonic-radiance.love/game/modules/subgames/init.lua +++ b/sonic-radiance.love/game/modules/subgames/init.lua @@ -1,22 +1,25 @@ local Scene = require("game.scenes") local PlayStyle = Scene:extend() -local PauseMenu = require("game.modules.subgames.pause") +local TweenManager = require "birb.classes.time" +local PauseScreen = require("game.modules.subgames.pause") local TestWorld = require("game.modules.subgames.world.parent") function PlayStyle:new(supportedLevels, missionfile) - PlayStyle.super.new(self) + PlayStyle.super.new(self, false, false) self.timer = 0 self.assets:batchImport("assets.subgames") --self:loadMissionFile(supportedLevels, missionfile) - PauseMenu(self) - self:initWorld() self:initMission() self:initCharacters() + self.tweens = TweenManager(self) + PauseScreen() + self.haveStarted = false + self.canPause = true end function PlayStyle:loadMissionFile(supportedLevels, missionfile) @@ -51,28 +54,50 @@ function PlayStyle:update(dt) end function PlayStyle:updatePauseMenus(dt) - if self.menusystem.menus["pauseMenu"].isActive == false then + self.tweens:update(dt) + if self.gui.screens["pauseScreen"].isVisible == false then self.timer = self.timer + dt end local keys = self:getKeys(1); - if keys["start"].isPressed then - if not (self.menusystem.menus["pauseMenu"].isActive) then - self.menusystem.menus["pauseMenu"].isActive = true - self.menusystem.menus["pauseMenu"].isVisible = true - self.menusystem.menus["pauseMenu"]:getFocus() - self.assets.isActive = false - self.world.isActive = false + + if (keys["start"].isPressed and self.canPause) then + if (not self.isPaused) then + if (not self.gui.screens["overlay"].isVisible) then + self.assets.sfx["mSelect"]:play() + self:pause() + end else - self.menusystem.menus["pauseMenu"].isActive = false - self.menusystem.menus["pauseMenu"].isVisible = false - self.assets.isActive = true - self.world.isActive = true + self.assets.sfx["mBack"]:play() + self:unpause() end end end + +function PlayStyle:timerResponse(timer) + if (timer == "unPause") then + self.isPaused = false + self.world.isActive = true + end +end + +function PlayStyle:pause() + self.gui:showScreen("overlay") + self.gui:showScreen("pauseScreen") + self.gui:playScreenTransform("overlay", "showBackgroundPause") + self.isPaused = true + self.world.isActive = false +end + +function PlayStyle:unpause() + self.tweens:newTimer(0.2, "unPause") + self.gui:playScreenTransform("overlay", "hideBackgroundPause") + self.gui:hideScreen("overlay") + self.gui:hideScreen("pauseScreen") +end + function PlayStyle:startLevel() self.haveStarted = true self.world:loadMap() @@ -80,6 +105,7 @@ function PlayStyle:startLevel() end function PlayStyle:restartLevel() + self:unpause() self.world:reset() end diff --git a/sonic-radiance.love/game/modules/subgames/pause.lua b/sonic-radiance.love/game/modules/subgames/pause.lua index ecf113f..59623ac 100644 --- a/sonic-radiance.love/game/modules/subgames/pause.lua +++ b/sonic-radiance.love/game/modules/subgames/pause.lua @@ -1,63 +1,45 @@ -local RadianceListMenu = require "game.modules.menus.list" -local PauseMenu = RadianceListMenu.ListMenu:extend() +local PauseScreen = require("birb.modules.gui.screen"):extend() -local ResumeWidget = RadianceListMenu.DualTextWidget:extend() -local RestartWidget = RadianceListMenu.DualTextWidget:extend() -local ExitWidget = RadianceListMenu.DualTextWidget:extend() +local BoxedMenu = require("game.modules.gui.boxedmenu") +local TextElement = require("birb.modules.gui.elements.text") local WIDTH = 80 +local X, Y, TXT_Y = 424/2, 240/2, 240/6 +local OX, OY = WIDTH/2, (3*17)/2 -function PauseMenu:new(subgame) - local x, y - x = 424/2 - WIDTH/2 - y = 240/2 - (3*17)/2 +local show = { + {"pauseMenu", "tween", 0.1, 0.3, {opacity = 1, sx = 1, sy = 1}, "inOutQuart"}, + {"pauseText", "tween", 0.1, 0.3, {opacity = 1, y = TXT_Y}, "inOutQuart"}, +} - PauseMenu.super.new(self, subgame, "pauseMenu", x, y, WIDTH, 3, true) +local hide = { + {"pauseMenu", "tween", 0, 0.3, {opacity = 0, sx = 0.8, sy = 0.8}, "inOutQuart"}, + {"pauseText", "tween", 0, 0.3, {opacity = 0, y = TXT_Y - 16}, "inOutQuart"}, +} - self:setSound(self.scene.assets.sfx["navigate"]) - self.isActive = false - self.isVisible = false - - ResumeWidget(subgame) - self:setCancelWidget() - RestartWidget(subgame) - ExitWidget(subgame) +function PauseScreen:new() + PauseScreen.super.new(self, "pauseScreen") + self:addTransform("show", show) + self:addTransform("hide", hide) + self.defaultFocus = "pauseMenu" end ---- MENU WIDGETS +function PauseScreen:createElements() + local pauseMenu = BoxedMenu("pauseMenu", X, Y, WIDTH, 3, true, false) + pauseMenu:addItem("Resume", "left", function() self.scene:unpause() end, "back") + pauseMenu:setCancelWidget() + pauseMenu:addItem("Restart", "left", function() self.scene:restartLevel() end, "back") + pauseMenu:addItem("Exit", "left", function() self.scene:exitLevel() end, "back") + pauseMenu.opacity = 0 + pauseMenu.sx, pauseMenu.sy = 0.8, 0.8 + pauseMenu.ox, pauseMenu.oy = OX, OY -function ResumeWidget:new(scene) - ResumeWidget.super.new(self, scene, "pauseMenu", "Resume", "") + local text = TextElement("pauseText", "SA2font", "Pause", X, TXT_Y - 16, "center") + text.opacity = 0 + return { + {pauseMenu, 0, 1}, + {text, 0, 1} + } end -function ResumeWidget:action() - self.menu.isActive = false - self.menu.isVisible = false - self.scene.world.isActive = true - self.scene.assets.isActive = true - self.scene:flushKeys() -end - -function RestartWidget:new(scene) - ResumeWidget.super.new(self, scene, "pauseMenu", "Restart", "") -end - -function RestartWidget:action() - self.scene:restartLevel() - self.menu.isActive = false - self.menu.isVisible = false - self.scene.world.isActive = true - self.scene.assets.isActive = true - self.scene:flushKeys() -end - -function ExitWidget:new(scene) - ExitWidget.super.new(self, scene, "pauseMenu", "Exit", "") -end - -function ExitWidget:action() - self.scene:exitLevel() -end - - -return PauseMenu +return PauseScreen \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua index 285ac48..9a33c9e 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua @@ -2,8 +2,6 @@ local cwd = (...):gsub('%.player$', '') .. "." local Parent = require(cwd .. "parent") local Player = Parent:extend() -local Emblem = require "game.modules.gui.emblem" - function Player:new(world, x, y, z, id) Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true) self:setGravity(480*2) @@ -20,9 +18,6 @@ function Player:initPlayer() self.charName = game.characters:getActiveCharacter() self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites") self:setSprite(self.charName, true, 8, 10) - - self.emblem = Emblem(game.characters:getActiveCharacterData(), self.scene) - self.guiborder = game.gui.newBorder(424, 20, 6) end function Player:updateStart(dt) @@ -115,11 +110,6 @@ function Player:draw() Player.super.draw(self) end -function Player:drawHUD(id) - love.graphics.draw(self.guiborder, 0, 20, 0, 1, -1) - self.emblem:draw(424 - 40, 12) -end - function Player:setRing(value, isRelative) if (isRelative == false) then self.rings = 0 diff --git a/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua b/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua index 5a0c463..8e1be50 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/gfx.lua @@ -5,7 +5,9 @@ local GFX_DIRECTORY = "assets/sprites/gfx/" function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag) GFX.super.new(self, world, x, y, z) - self.char = self:getCharacter(creator.choregraphy.fighter) + if (creator.choregraphy ~= nil) then + self.char = self:getCharacter(creator.choregraphy.fighter) + end self:setAnimation(spritename) self.creator = creator -- 2.30.2 From 1db72079bf4dc774071a306daa75bc354f24be17 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 18:59:29 +0100 Subject: [PATCH 101/102] chore: delete the old radiance menus --- .../game/modules/menus/fancy.lua | 78 -------- .../game/modules/menus/list.lua | 172 ------------------ .../game/modules/menus/parents/menu.lua | 36 ---- .../game/modules/menus/parents/widget.lua | 13 -- 4 files changed, 299 deletions(-) delete mode 100644 sonic-radiance.love/game/modules/menus/fancy.lua delete mode 100644 sonic-radiance.love/game/modules/menus/list.lua delete mode 100644 sonic-radiance.love/game/modules/menus/parents/menu.lua delete mode 100644 sonic-radiance.love/game/modules/menus/parents/widget.lua diff --git a/sonic-radiance.love/game/modules/menus/fancy.lua b/sonic-radiance.love/game/modules/menus/fancy.lua deleted file mode 100644 index eae6269..0000000 --- a/sonic-radiance.love/game/modules/menus/fancy.lua +++ /dev/null @@ -1,78 +0,0 @@ -local List = require "game.modules.menus.list" - -local fancy = {} -fancy.FancyMenu = List.ListMenu:extend() -fancy.BaseWidget = List.CenteredWidget:extend() -fancy.SubMenuWidget = fancy.BaseWidget:extend() - -local MENU_ITEM_HEIGHT = 16 - -local gui = require "game.modules.gui" - -function fancy.FancyMenu:new(scene, name, x, y, w, itemNumber, haveBiseau) - fancy.FancyMenu.super.new(self, scene, name, x, y, w, itemNumber, false) - self.haveBiseau = haveBiseau -end - -function fancy.FancyMenu:getCursorPosition() - if (self.haveBiseau) then - local addition = MENU_ITEM_HEIGHT - local x = self.x + 4 + ((self.cursorTransition) * addition)/2 - local y = self.y + ((self.cursorTransition) * addition) - return x, y - else - return fancy.FancyMenu.super.getCursorPosition(self) - end -end - -function fancy.FancyMenu:getNextPosition(x, y, h) - if (self.haveBiseau) then - return (x + (h/2)), y+h - else - return fancy.FancyMenu.super.getNextPosition(self, x, y, h) - end -end - -function fancy.FancyMenu:clone(name) - return fancy.FancyMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber, self.haveBiseau) -end - -function fancy.FancyMenu:addSubMenuWidget(newmenu, name) - fancy.SubMenuWidget(self.scene, self.name, newmenu, name) -end - --- FancyWidgets --- Add Fancy Widgets -function fancy.BaseWidget:new(scene, menu_name, label, label2) - self.label2 = label2 - fancy.BaseWidget.super.new(self, scene, menu_name, label) - self.box = gui.newChoiceBack(self.menu.w + 24) -end - -function fancy.BaseWidget:drawCanvas() - love.graphics.draw(self.box, 0, 0) - local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2 - self.font:setColor(self.color[1], self.color[2], self.color[3], 1) - self.font:draw(self.label, 16, h, -1, "left") - self.font:draw(self.label2, self.width -8, h, -1, "right") - self.font:setColor(1, 1, 1, 1) - utils.graphics.resetColor() -end - --- Widget de sous-menu -function fancy.SubMenuWidget:new(scene, menu_name, newmenu, label) - local label2 = "" - if (label ~= "Back") then - label2 = ">" - end - fancy.SubMenuWidget.super.new(self, scene, menu_name, label, label2) - self.newmenu = newmenu -end - -function fancy.SubMenuWidget:action() - self.scene.assets:playSFX("mBeep") - self.scene.menusystem:switchMenu(self.newmenu) - self.scene.menusystem.menus[self.newmenu]:activationAction() -end - -return fancy diff --git a/sonic-radiance.love/game/modules/menus/list.lua b/sonic-radiance.love/game/modules/menus/list.lua deleted file mode 100644 index 2f41a2a..0000000 --- a/sonic-radiance.love/game/modules/menus/list.lua +++ /dev/null @@ -1,172 +0,0 @@ -local ParentMenu = require "game.modules.menus.parents.menu" -local Widget = require "birb.modules.menusystem.widgets" - -local list = {} -list.ListMenu = ParentMenu:extend() -list.CenteredWidget = Widget.Text:extend() -list.DualTextWidget = list.CenteredWidget:extend() -list.SubMenuWidget = list.DualTextWidget:extend() - -local MENU_ITEM_HEIGHT = 16 - -local gui = require "game.modules.gui" - --- ListMenu -function list.ListMenu:new(scene, name, x, y, w, itemNumber, isBoxed, smallborder) - self.scene = scene - self.name = name - local h = itemNumber * MENU_ITEM_HEIGHT - list.ListMenu.super.new(self, scene, name, x, y, w, h, itemNumber) - self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") - self.cursorTransition = 0 - self.submenus = {} - self.itemNumber = itemNumber - self.smallborder = (smallborder == true) - - self.isBoxed = isBoxed - if (self.isBoxed) then - local border = h+16 - if (self.smallborder) then - border = h+8 - end - self.box = gui.newTextBox("assets/gui/dialogbox.png", w, border) - end -end - -function list.ListMenu:addSubMenu(name, nicerName) - local submenu = self:clone(name) - self:addSubMenuWidget(name, nicerName) - table.insert(self.submenus, name) -end - -function list.ListMenu:addSubMenuWidget(newmenu, name) - list.SubMenuWidget(self.scene, self.name, newmenu, name) -end - -function list.ListMenu:finalize(parent) - if (parent ~= "" and parent ~= nil) then - self:addSubMenuWidget(parent, "Back") - self:setCancelWidget() - end - - for i,name in ipairs(self.submenus) do - if (self.menusystem.menus[name] ~= nil) then - self.menusystem.menus[name]:finalize(self.name) - end - end -end - -function list.ListMenu:clone(name) - return list.ListMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber, self.isBoxed) -end - -function list.ListMenu:update(dt) - list.ListMenu.super.update(self, dt) - self:updateCursorPosition(dt) -end - -function list.ListMenu:updateCursorPosition(dt) - local relativecursor = self.widget.selected - self.view.firstSlot - - local transition = self.cursorTransition - relativecursor - if math.abs(transition) < 0.1 then - self.cursorTransition = relativecursor - else - local speed = dt*45 - local movement = ((relativecursor) - (self.cursorTransition)) - self.cursorTransition = (self.cursorTransition) + movement * speed - end -end - -function list.ListMenu:drawCursor() - local x, y = self:getCursorPosition() - love.graphics.draw(self.cursorTexture, x, y) -end - -function list.ListMenu:getCursorPosition() - local addition = MENU_ITEM_HEIGHT - local x = self.x + 6 - local y = self.y + ((self.cursorTransition) * addition) + 1 - return x, y -end - -function list.ListMenu:draw() - if (self.isBoxed) then - local dy = 8 - if (self.smallborder) then - dy = 4 - end - love.graphics.draw(self.box, self.x, self.y - dy) - end - 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.w, self.widget.h) - if self.widget.selected == i and self:haveFocus() == true then - v:drawSelected(widgetx, widgety, self.w, self.widget.h) - else - v:draw(widgetx, widgety, self.w, self.widget.h) - end - widgetx, widgety = self:getNextPosition(widgetx, widgety, self.widget.h) - end - end -end - -function list.ListMenu:getNextPosition(x, y, h) - return x, y+h -end - --- Widgets --- Tout les widgets pour la liste de base - --- Widget centré -function list.CenteredWidget:new(scene, menu_name, label) - local font = scene.assets.fonts["small"] - font:setFilter("shadow") - self.scene = scene - local widgetMenu = scene.menusystem.menus[menu_name] - list.CenteredWidget.super.new(self, widgetMenu, font, label) -end - -function list.CenteredWidget:drawCanvas() - local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2 - self.font:setColor(self.color[1], self.color[2], self.color[3], 1) - self.font:draw(self.label, self.width / 2, h, -1, "center") - self.font:setColor(1, 1, 1, 1) - utils.graphics.resetColor() -end - --- Widget avec deux bouts de textes -function list.DualTextWidget:new(scene, menu_name, label, label2) - self.label2 = label2 - list.DualTextWidget.super.new(self, scene, menu_name, label) -end - -function list.DualTextWidget:drawCanvas() - local 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, 16, h, -1, "left") - self.font:draw(self.label2, self.width - 8, h, -1, "right") - self.font:setColor(1, 1, 1, 1) - utils.graphics.resetColor() -end - --- Widget de sous-menu -function list.SubMenuWidget:new(scene, menu_name, newmenu, label) - local label2 = "" - if (label ~= "Back") then - label2 = ">" - end - list.SubMenuWidget.super.new(self, scene, menu_name, label, label2) - self.newmenu = newmenu -end - -function list.SubMenuWidget:action() - self.scene.assets:playSFX("mBeep") - self.scene.menusystem:switchMenu(self.newmenu) - self.scene.menusystem.menus[self.newmenu]:activationAction() -end - -return list diff --git a/sonic-radiance.love/game/modules/menus/parents/menu.lua b/sonic-radiance.love/game/modules/menus/parents/menu.lua deleted file mode 100644 index cc9557a..0000000 --- a/sonic-radiance.love/game/modules/menus/parents/menu.lua +++ /dev/null @@ -1,36 +0,0 @@ -local ListBox = require "birb.modules.menusystem.listbox" -local TweenManager = require "birb.classes.time" - -local RadianceMenu = ListBox:extend() - -function RadianceMenu:new(scene, name, x, y, w, h, itemNumber) - self.scene = scene - self.tweens = TweenManager(self) - RadianceMenu.super.new(self, self.scene.menusystem, name, x, y, w, h, itemNumber) -end - -function RadianceMenu:update(dt) - self.tweens:update(dt) - RadianceMenu.super.update(self, dt) -end - -function RadianceMenu:moveFrom(x, y) - local newX, newY = self.x, self.y - self.x, self.y = x, y - - self.tweens:addTween(0, 0.3, {x = newX, y = newY}, "inOutQuad") -end - -function RadianceMenu:moveTo(newX, newY) - self.tweens:addTween(0, 0.3, {x = newX, y = newY}, "inOutQuad") -end - -function RadianceMenu:getCenter() - return self.x + self.width, self.y + self.height -end - -function RadianceMenu:activationAction() - -- Do nothing -end - -return RadianceMenu diff --git a/sonic-radiance.love/game/modules/menus/parents/widget.lua b/sonic-radiance.love/game/modules/menus/parents/widget.lua deleted file mode 100644 index 7990a58..0000000 --- a/sonic-radiance.love/game/modules/menus/parents/widget.lua +++ /dev/null @@ -1,13 +0,0 @@ -local Widget = require "birb.modules.menusystem.widgets" -local RadianceWidget = Widget.Text:extend() - -function RadianceWidget:new(scene, name, label, color) - self.scene = scene - local label = label or "" - local font = scene.assets.fonts["small"] - font:setFilter("shadow") - local widgetMenu = scene.menusystem.menus[name] - RadianceWidget.super.new(self, widgetMenu, font, label, color) -end - -return RadianceWidget -- 2.30.2 From 272627c937d59574075f36fc62f6b735b3a23183 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 19:11:10 +0100 Subject: [PATCH 102/102] chore: remove completely the old menusystem --- .../birb/core/scenemanager.lua | 2 - .../birb/modules/menusystem/flowbox.lua | 231 -------------- .../birb/modules/menusystem/grid.lua | 277 ---------------- .../birb/modules/menusystem/hlistbox.lua | 149 --------- .../birb/modules/menusystem/init.lua | 290 ----------------- .../birb/modules/menusystem/listbox.lua | 147 --------- .../birb/modules/menusystem/parent.lua | 302 ------------------ .../birb/modules/menusystem/widgets/init.lua | 153 --------- .../birb/modules/menusystem/widgets/utils.lua | 57 ---- sonic-radiance.love/birb/modules/scenes.lua | 37 +-- .../birb/modules/world/actors/mixins/base.lua | 4 - .../birb/modules/world/camera/init.lua | 12 - .../scenes/battlesystem/actors/parent.lua | 4 - .../debugmenus/choregraphy/mocks/fighter.lua | 5 - .../scenes/menus/titlescreen/init.lua | 1 - 15 files changed, 5 insertions(+), 1666 deletions(-) delete mode 100644 sonic-radiance.love/birb/modules/menusystem/flowbox.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/grid.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/hlistbox.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/init.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/listbox.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/parent.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/widgets/init.lua delete mode 100644 sonic-radiance.love/birb/modules/menusystem/widgets/utils.lua diff --git a/sonic-radiance.love/birb/core/scenemanager.lua b/sonic-radiance.love/birb/core/scenemanager.lua index 6344b02..8c081c8 100644 --- a/sonic-radiance.love/birb/core/scenemanager.lua +++ b/sonic-radiance.love/birb/core/scenemanager.lua @@ -90,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 diff --git a/sonic-radiance.love/birb/modules/menusystem/flowbox.lua b/sonic-radiance.love/birb/modules/menusystem/flowbox.lua deleted file mode 100644 index 35247c3..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/flowbox.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/grid.lua b/sonic-radiance.love/birb/modules/menusystem/grid.lua deleted file mode 100644 index d23895e..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/grid.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/hlistbox.lua b/sonic-radiance.love/birb/modules/menusystem/hlistbox.lua deleted file mode 100644 index 1123685..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/hlistbox.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/init.lua b/sonic-radiance.love/birb/modules/menusystem/init.lua deleted file mode 100644 index 02e7587..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/init.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/listbox.lua b/sonic-radiance.love/birb/modules/menusystem/listbox.lua deleted file mode 100644 index c2e51c8..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/listbox.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/parent.lua b/sonic-radiance.love/birb/modules/menusystem/parent.lua deleted file mode 100644 index 8ccb0d8..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/parent.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/widgets/init.lua b/sonic-radiance.love/birb/modules/menusystem/widgets/init.lua deleted file mode 100644 index 2fd287f..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/widgets/init.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/menusystem/widgets/utils.lua b/sonic-radiance.love/birb/modules/menusystem/widgets/utils.lua deleted file mode 100644 index e69c6d7..0000000 --- a/sonic-radiance.love/birb/modules/menusystem/widgets/utils.lua +++ /dev/null @@ -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 diff --git a/sonic-radiance.love/birb/modules/scenes.lua b/sonic-radiance.love/birb/modules/scenes.lua index 141da1e..59ddeb8 100644 --- a/sonic-radiance.love/birb/modules/scenes.lua +++ b/sonic-radiance.love/birb/modules/scenes.lua @@ -27,7 +27,6 @@ local cwd = (...):gsub('%.scenes$', '') .. "." local Scene = Object:extend() local Assets = require(cwd .. "assets") -local MenuSystem = require(cwd .. "menusystem") local Gui = require (cwd .. "gui") -- INIT FUNCTIONS @@ -38,7 +37,6 @@ 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) @@ -71,9 +69,7 @@ function Scene:updateScene(dt) self:updateStart(dt) self:setKeys() self.assets:update(dt) - self:updateMenus(dt) - self:updateDialog(dt) - self.gui:update(dt) + self:updateGUI(dt) self:updateWorld(dt) self:update(dt) self:updateEnd(dt) @@ -97,18 +93,11 @@ function Scene:updateWorld(dt) end end -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 +function Scene:updateGUI(dt) + if (self.gui ~= nil) then + self.gui:update(dt) + if (core.screen:isActive()) then self.gui:keycheck(self:getKeys(1)) - self.menusystem:keycheck() end end end @@ -158,8 +147,6 @@ function Scene:drawScene() self:drawWorld() self:draw() self.gui:drawBottom() - self:drawMenus() - self:drawDialog() self:drawEnd() core.screen:drawTransition() self.gui:drawTop() @@ -188,18 +175,6 @@ 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 @@ -209,10 +184,8 @@ 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 diff --git a/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua b/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua index 4d4e278..0bfcee3 100644 --- a/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua +++ b/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua @@ -111,8 +111,4 @@ function BaseActor:drawEnd() end -function BaseActor:drawHUD(id, height, width) - -end - return BaseActor diff --git a/sonic-radiance.love/birb/modules/world/camera/init.lua b/sonic-radiance.love/birb/modules/world/camera/init.lua index 129a338..3044ecf 100644 --- a/sonic-radiance.love/birb/modules/world/camera/init.lua +++ b/sonic-radiance.love/birb/modules/world/camera/init.lua @@ -214,7 +214,6 @@ function CameraSystem:detachView(id) local unscale = 1 / view.scale love.graphics.scale(unscale, unscale) - self:drawHUD(id) love.graphics.pop() end @@ -387,15 +386,4 @@ function CameraSystem:followAllActors(id) end end - --- DRAW FUNCTIONS --- Basic callback to draw stuff - -function CameraSystem:drawHUD(id) - local view = self:getView(id) - local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) - - view.target:drawHUD(id, vieww, viewh) -end - return CameraSystem diff --git a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua index d1d5d63..a5c196e 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua @@ -289,8 +289,4 @@ function Parent:drawShadow() end end -function Parent:drawHUD() - -end - return Parent diff --git a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/mocks/fighter.lua b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/mocks/fighter.lua index b40e5c5..e30e88f 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/mocks/fighter.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/mocks/fighter.lua @@ -40,11 +40,6 @@ function FighterMock:finishAction() self.action.target.actor:destroy() self.actor:destroy() self.action = nil - self.scene.menusystem:activate() -end - -function FighterMock:drawHUD() - end return FighterMock diff --git a/sonic-radiance.love/scenes/menus/titlescreen/init.lua b/sonic-radiance.love/scenes/menus/titlescreen/init.lua index ff6954b..4d1abf0 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/init.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/init.lua @@ -36,7 +36,6 @@ end function Title:startPressed() self.assets:playSFX("mSelect") - self.menusystem:setSoundFromSceneAssets("mBeep") self.gui.focusedElement = nil self.gui:playScreenTransform("titleScreen", "showMenu") end -- 2.30.2