From f8a831d280427837a3dc9d6207f102a61b840d0b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 18:57:42 +0100 Subject: [PATCH] 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