Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
4 changed files with 79 additions and 79 deletions
Showing only changes of commit f8a831d280 - Show all commits

View file

@ -1,22 +1,25 @@
local Scene = require("game.scenes") local Scene = require("game.scenes")
local PlayStyle = Scene:extend() 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") local TestWorld = require("game.modules.subgames.world.parent")
function PlayStyle:new(supportedLevels, missionfile) function PlayStyle:new(supportedLevels, missionfile)
PlayStyle.super.new(self) PlayStyle.super.new(self, false, false)
self.timer = 0 self.timer = 0
self.assets:batchImport("assets.subgames") self.assets:batchImport("assets.subgames")
--self:loadMissionFile(supportedLevels, missionfile) --self:loadMissionFile(supportedLevels, missionfile)
PauseMenu(self)
self:initWorld() self:initWorld()
self:initMission() self:initMission()
self:initCharacters() self:initCharacters()
self.tweens = TweenManager(self)
PauseScreen()
self.haveStarted = false self.haveStarted = false
self.canPause = true
end end
function PlayStyle:loadMissionFile(supportedLevels, missionfile) function PlayStyle:loadMissionFile(supportedLevels, missionfile)
@ -51,26 +54,48 @@ function PlayStyle:update(dt)
end end
function PlayStyle:updatePauseMenus(dt) 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 self.timer = self.timer + dt
end end
local keys = self:getKeys(1); local keys = self:getKeys(1);
if keys["start"].isPressed then
if not (self.menusystem.menus["pauseMenu"].isActive) then if (keys["start"].isPressed and self.canPause) then
self.menusystem.menus["pauseMenu"].isActive = true if (not self.isPaused) then
self.menusystem.menus["pauseMenu"].isVisible = true if (not self.gui.screens["overlay"].isVisible) then
self.menusystem.menus["pauseMenu"]:getFocus() self.assets.sfx["mSelect"]:play()
self.assets.isActive = false self:pause()
self.world.isActive = false end
else else
self.menusystem.menus["pauseMenu"].isActive = false self.assets.sfx["mBack"]:play()
self.menusystem.menus["pauseMenu"].isVisible = false self:unpause()
self.assets.isActive = true end
end
end
function PlayStyle:timerResponse(timer)
if (timer == "unPause") then
self.isPaused = false
self.world.isActive = true self.world.isActive = true
end end
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 end
function PlayStyle:startLevel() function PlayStyle:startLevel()
@ -80,6 +105,7 @@ function PlayStyle:startLevel()
end end
function PlayStyle:restartLevel() function PlayStyle:restartLevel()
self:unpause()
self.world:reset() self.world:reset()
end end

View file

@ -1,63 +1,45 @@
local RadianceListMenu = require "game.modules.menus.list" local PauseScreen = require("birb.modules.gui.screen"):extend()
local PauseMenu = RadianceListMenu.ListMenu:extend()
local ResumeWidget = RadianceListMenu.DualTextWidget:extend() local BoxedMenu = require("game.modules.gui.boxedmenu")
local RestartWidget = RadianceListMenu.DualTextWidget:extend() local TextElement = require("birb.modules.gui.elements.text")
local ExitWidget = RadianceListMenu.DualTextWidget:extend()
local WIDTH = 80 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 show = {
local x, y {"pauseMenu", "tween", 0.1, 0.3, {opacity = 1, sx = 1, sy = 1}, "inOutQuart"},
x = 424/2 - WIDTH/2 {"pauseText", "tween", 0.1, 0.3, {opacity = 1, y = TXT_Y}, "inOutQuart"},
y = 240/2 - (3*17)/2 }
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"]) function PauseScreen:new()
self.isActive = false PauseScreen.super.new(self, "pauseScreen")
self.isVisible = false self:addTransform("show", show)
self:addTransform("hide", hide)
ResumeWidget(subgame) self.defaultFocus = "pauseMenu"
self:setCancelWidget()
RestartWidget(subgame)
ExitWidget(subgame)
end 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) local text = TextElement("pauseText", "SA2font", "Pause", X, TXT_Y - 16, "center")
ResumeWidget.super.new(self, scene, "pauseMenu", "Resume", "") text.opacity = 0
return {
{pauseMenu, 0, 1},
{text, 0, 1}
}
end end
function ResumeWidget:action() return PauseScreen
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

View file

@ -2,8 +2,6 @@ local cwd = (...):gsub('%.player$', '') .. "."
local Parent = require(cwd .. "parent") local Parent = require(cwd .. "parent")
local Player = Parent:extend() local Player = Parent:extend()
local Emblem = require "game.modules.gui.emblem"
function Player:new(world, x, y, z, id) function Player:new(world, x, y, z, id)
Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true) Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true)
self:setGravity(480*2) self:setGravity(480*2)
@ -20,9 +18,6 @@ function Player:initPlayer()
self.charName = game.characters:getActiveCharacter() self.charName = game.characters:getActiveCharacter()
self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites") self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites")
self:setSprite(self.charName, true, 8, 10) self:setSprite(self.charName, true, 8, 10)
self.emblem = Emblem(game.characters:getActiveCharacterData(), self.scene)
self.guiborder = game.gui.newBorder(424, 20, 6)
end end
function Player:updateStart(dt) function Player:updateStart(dt)
@ -115,11 +110,6 @@ function Player:draw()
Player.super.draw(self) Player.super.draw(self)
end 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) function Player:setRing(value, isRelative)
if (isRelative == false) then if (isRelative == false) then
self.rings = 0 self.rings = 0

View file

@ -5,7 +5,9 @@ local GFX_DIRECTORY = "assets/sprites/gfx/"
function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag) function GFX:new(world, x, y, z, spritename, creator, blockProcess, tag)
GFX.super.new(self, world, x, y, z) GFX.super.new(self, world, x, y, z)
if (creator.choregraphy ~= nil) then
self.char = self:getCharacter(creator.choregraphy.fighter) self.char = self:getCharacter(creator.choregraphy.fighter)
end
self:setAnimation(spritename) self:setAnimation(spritename)
self.creator = creator self.creator = creator