From fccc4a5d8e1eb85b98d0a0d68ddf250c5924d79a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 5 Apr 2021 14:20:25 +0200 Subject: [PATCH] improvement: add main menu transitions Fixes #73 --- sonic-radiance.love/core/modules/scenes.lua | 4 ++ sonic-radiance.love/core/scenemanager.lua | 1 + .../scenes/debug/commons/menu.lua | 9 +++- .../scenes/debug/menu/init.lua | 18 ++++--- .../scenes/debug/menu/menu.lua | 16 ++++++ .../scenes/menus/options/assets.lua | 2 +- .../scenes/menus/options/init.lua | 19 ++++--- .../scenes/menus/options/widgets.lua | 5 ++ .../scenes/menus/titlescreen/init.lua | 3 ++ sonic-radiance.love/scenes/overworld/init.lua | 53 +++++++++++-------- .../overworld/screens/mainmenu/pause.lua | 10 +++- 11 files changed, 98 insertions(+), 42 deletions(-) diff --git a/sonic-radiance.love/core/modules/scenes.lua b/sonic-radiance.love/core/modules/scenes.lua index 5ec2741..f658769 100644 --- a/sonic-radiance.love/core/modules/scenes.lua +++ b/sonic-radiance.love/core/modules/scenes.lua @@ -129,6 +129,10 @@ function Scene:drawEnd() end +function Scene:drawOverTransition() + +end + function Scene:drawWorld(dt) if (self.world ~= nil) then self.world:draw() diff --git a/sonic-radiance.love/core/scenemanager.lua b/sonic-radiance.love/core/scenemanager.lua index 2541e9b..70ddb0c 100644 --- a/sonic-radiance.love/core/scenemanager.lua +++ b/sonic-radiance.love/core/scenemanager.lua @@ -134,6 +134,7 @@ function SceneManager:draw() self.currentScene.menusystem:draw() self.currentScene:drawEnd() self.controller.screen:drawTransition() + self.currentScene:drawOverTransition() end self.controller.screen:cease() end diff --git a/sonic-radiance.love/scenes/debug/commons/menu.lua b/sonic-radiance.love/scenes/debug/commons/menu.lua index 72bc0f2..7963486 100644 --- a/sonic-radiance.love/scenes/debug/commons/menu.lua +++ b/sonic-radiance.love/scenes/debug/commons/menu.lua @@ -2,6 +2,7 @@ local menu = {} local RadianceListMenu = require "game.modules.menus.fancy" local Widget = require "core.modules.menusystem.widgets" +local defTransitions = require "core.modules.transitions" menu.MainMenu = RadianceListMenu.FancyMenu:extend() menu.DebugMenu = RadianceListMenu.FancyMenu:extend() @@ -61,9 +62,13 @@ end function menu.SceneWidget:action() self.scene:flushKeys() if (self.sceneArgument ~= nil) then - self.newScene(self.sceneArgument) + core.screen:startTransition(defTransitions.default, defTransitions.default, + function() self.newScene(self.sceneArgument) end, + 0, 0) else - self.newScene() + core.screen:startTransition(defTransitions.default, defTransitions.default, + function() self.newScene() end, + 0, 0) end end diff --git a/sonic-radiance.love/scenes/debug/menu/init.lua b/sonic-radiance.love/scenes/debug/menu/init.lua index f1a501d..6bd5cb2 100644 --- a/sonic-radiance.love/scenes/debug/menu/init.lua +++ b/sonic-radiance.love/scenes/debug/menu/init.lua @@ -9,11 +9,13 @@ local itemutils = require "game.utils.items" local gui = require "game.modules.gui" local MenuBack = require "game.modules.gui.menuback" +local TweenManager = require "game.modules.tweenmanager" + function DebugMenu:new() DebugMenu.super.new(self) self.assets:batchImport("scenes.debug.commons.assets") menu.commons.MainMenu(self, "BaseMenu") - menu.commons.SceneWidget(self, "BaseMenu", scenes.overworld, "Start playing") + menu.StartGameWidget(self, "BaseMenu") menu.commons.SceneWidget(self, "BaseMenu", scenes.options, "Options") self:buildDebugMenu() menu.TitleWidget(self, "BaseMenu") @@ -30,6 +32,7 @@ function DebugMenu:new() self.backImage = love.graphics.newImage("assets/artworks/back.png") self.back = MenuBack() + self.tweens = TweenManager(self) end function DebugMenu:buildDebugMenu() @@ -123,6 +126,7 @@ function DebugMenu:update(dt) self.menusystem:activate() end self.back:update(dt) + self.tweens:update(dt) end function DebugMenu:addSubMenu(submenu, parent, name, panel, panelArgument) @@ -139,14 +143,16 @@ function DebugMenu:draw() self.back:draw() utils.graphics.resetColor() love.graphics.draw(self.backImage, 0, 0) + if (self.menusystem.isActive) then - 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"]:print("v" .. game.version, 424 - 8, 240 - 20, "right") - 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) +end + return DebugMenu; diff --git a/sonic-radiance.love/scenes/debug/menu/menu.lua b/sonic-radiance.love/scenes/debug/menu/menu.lua index 4c8f018..1b27b15 100644 --- a/sonic-radiance.love/scenes/debug/menu/menu.lua +++ b/sonic-radiance.love/scenes/debug/menu/menu.lua @@ -14,6 +14,22 @@ 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() + + +-- 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, "") +end + +function menu.StartGameWidget:action() + 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") +end -- TitleWidget function menu.TitleWidget:new(scene, menuName) diff --git a/sonic-radiance.love/scenes/menus/options/assets.lua b/sonic-radiance.love/scenes/menus/options/assets.lua index 8569868..9558183 100644 --- a/sonic-radiance.love/scenes/menus/options/assets.lua +++ b/sonic-radiance.love/scenes/menus/options/assets.lua @@ -4,7 +4,7 @@ return { {"hitGFX", "assets/sprites/gfx/hit"}, }, ["textures"] = { - {"background", "assets/backgrounds/options.png"} + {"background", "assets/artworks/back.png"} }, ["fonts"] = { {"small", "assets/gui/fonts/PixelOperator.ttf", 16} diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index 05cc6ef..733b99e 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -5,6 +5,7 @@ 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) @@ -41,11 +42,11 @@ function OptionsMenu:new() self.borderY = 30 self.borders = gui.newBorder(424, 30, 8) - self.timer = 0 + self.back = MenuBack() end function OptionsMenu:update(dt) - self.timer = (self.timer + (30 * dt)) % 128 + self.back:update(dt) end -- MENU FUNCTION @@ -96,15 +97,17 @@ function OptionsMenu:keypressed( key ) end function OptionsMenu:draw() - local w, h = core.screen:getDimensions() - for i=-1, (w/128) do - for j=-1,(h/128) do - self.assets.images["background"]:draw(i*128 + self.timer, j*128 + self.timer) - end - end + 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/widgets.lua b/sonic-radiance.love/scenes/menus/options/widgets.lua index 7307bc7..76c3eba 100644 --- a/sonic-radiance.love/scenes/menus/options/widgets.lua +++ b/sonic-radiance.love/scenes/menus/options/widgets.lua @@ -15,6 +15,8 @@ widgets.PlayerSubMenu = RadianceListMenu.DualTextWidget:extend() widgets.Key = RadianceListMenu.DualTextWidget:extend() widgets.Audio = RadianceListMenu.DualTextWidget:extend() +local defTransitions = require "core.modules.transitions" + -- BASIC WIDGETS -- Simple and reusables widgets @@ -70,6 +72,9 @@ end function widgets.Exit:action() self.scene.assets:playSFX("mSelect") core.scenemanager:setStoredScene("mainmenu") + core.screen:startTransition(defTransitions.default, defTransitions.default, + function() scenes.debug.menu() end, + 0, 0) end -- VIDEO WIDGETS diff --git a/sonic-radiance.love/scenes/menus/titlescreen/init.lua b/sonic-radiance.love/scenes/menus/titlescreen/init.lua index 7314203..62b55b7 100644 --- a/sonic-radiance.love/scenes/menus/titlescreen/init.lua +++ b/sonic-radiance.love/scenes/menus/titlescreen/init.lua @@ -114,9 +114,12 @@ function TitleScreen:draw() 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 diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 431f797..bde2665 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -58,7 +58,8 @@ function OverWorld:new(area, playerx, playery) self.borders = gui.newBorder(424, 30, 8) self.emblemPosition = 368 - self.ringBorder = 16 + self.ringBorder = -16 + self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad") self.timeBorder = -10 self.message = "Test de message" self.messageOpacity = 0 @@ -174,27 +175,7 @@ function OverWorld:getEmblemsPosition() end function OverWorld:draw() - 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() - end - - 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:drawForeground() - end + self.events:draw() love.graphics.setColor(0,0,0, 0.5 * self.messageOpacity) love.graphics.rectangle("fill", 0, PLAYER_MESSAGE, 424, 16) @@ -204,8 +185,34 @@ function OverWorld:draw() self.assets.fonts["small"]:setColor(1,1,1, 1) end utils.graphics.resetColor() + 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() + 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") - self.events:draw() end return OverWorld diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua index 9b27bb8..0e68ab5 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua @@ -12,6 +12,9 @@ local TeamWidget = menu.BaseWidget:extend() local ViewWidget = menu.BaseWidget:extend() local SaveExitWidget = menu.BaseWidget:extend() +local defTransitions = require "core.modules.transitions" +local radTransitions = require "game.modules.transitions" + local const = require "scenes.overworld.screens.mainmenu.const" function PauseScreen:new(scene, menu, widget) @@ -28,7 +31,7 @@ function PauseScreen:setMenu() ViewWidget(self.scene, "Items", "items") menu.BaseWidget(self.scene, "main", "Chao", ">") menu.BaseWidget(self.scene, "main", "Encylopedia", ">") - menu.BaseWidget(self.scene, "main", "Options", ">") + --menu.BaseWidget(self.scene, "main", "Options", ">") self.scene.menusystem.menus["main"]:addSubMenu("save", "Save / Exit") SaveExitWidget(self.scene, "main", "Resume", false, false) @@ -102,7 +105,10 @@ function SaveExitWidget:action() game:write() end if (self.exit) then - scenes.debug.menu() + + core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.debug.menu() 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") else self.scene:unpause() end