improvement: add main menu transitions

Fixes #73
This commit is contained in:
Kazhnuz 2021-04-05 14:20:25 +02:00
parent f538ffa94a
commit fccc4a5d8e
11 changed files with 98 additions and 42 deletions

View file

@ -129,6 +129,10 @@ function Scene:drawEnd()
end
function Scene:drawOverTransition()
end
function Scene:drawWorld(dt)
if (self.world ~= nil) then
self.world:draw()

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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)

View file

@ -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}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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