Refonte pour utiliser le systeme de GUI #112
4 changed files with 116 additions and 98 deletions
|
@ -22,98 +22,23 @@
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local Scene = require "game.scenes"
|
local Scene = require "game.scenes"
|
||||||
local TitleScreen = Scene:extend()
|
local Title = Scene:extend()
|
||||||
local gui = require "game.modules.gui"
|
local TitleScreen = require "scenes.menus.titlescreen.screen"
|
||||||
|
|
||||||
local TweenManager = require "birb.classes.time"
|
function Title:new(fromMenu)
|
||||||
local Menu = require "scenes.menus.titlescreen.menu"
|
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:addImage("logo", "assets/artworks/logo.png")
|
||||||
self.assets:addTileset("charicons", "assets/sprites/characters/charicons")
|
self.assets:addTileset("charicons", "assets/sprites/characters/charicons")
|
||||||
|
|
||||||
self.tweens = TweenManager(self)
|
TitleScreen(fromMenu)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function TitleScreen:initBackground()
|
function Title:startPressed()
|
||||||
self.background = love.graphics.newImage("datas/gamedata/maps/sti/stuff/tilescreen.png")
|
|
||||||
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")
|
self.assets:playSFX("mSelect")
|
||||||
Menu(self)
|
|
||||||
self.haveMenu = true
|
|
||||||
self.menusystem:setSoundFromSceneAssets("mBeep")
|
self.menusystem:setSoundFromSceneAssets("mBeep")
|
||||||
end
|
self.gui.focusedElement = nil
|
||||||
|
self.gui:playScreenTransform("titleScreen", "showMenu")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function TitleScreen:draw()
|
return Title
|
||||||
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
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
local RadianceMenu = require "game.modules.menus.parents.menu"
|
local RadianceMenu = require "birb.modules.gui.menus.listbox"
|
||||||
local RadianceWidget = require "game.modules.menus.parents.widget"
|
local RadianceWidget = require "birb.modules.gui.menus.widgets.base"
|
||||||
local SaveMenu = RadianceMenu:extend()
|
local SaveMenu = RadianceMenu:extend()
|
||||||
local SaveWidget = RadianceWidget:extend()
|
local SaveWidget = RadianceWidget:extend()
|
||||||
|
|
||||||
|
@ -11,26 +11,31 @@ local radTransitions = require "game.modules.transitions"
|
||||||
local HPADDING = 68
|
local HPADDING = 68
|
||||||
local VPADDING = 28
|
local VPADDING = 28
|
||||||
|
|
||||||
function SaveMenu:new(scene)
|
function SaveMenu:new()
|
||||||
local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2)
|
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()
|
local metadata = game:getMetadata()
|
||||||
for i, save in ipairs(metadata) do
|
for i, save in ipairs(metadata) do
|
||||||
SaveWidget(self.scene, i, save)
|
SaveWidget(self.scene, i, save)
|
||||||
end
|
end
|
||||||
self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, (h / 3))
|
self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, (h / 3))
|
||||||
|
self.isVisible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function SaveMenu:cancelAction()
|
function SaveMenu:cancelAction()
|
||||||
self.scene.assets:playSFX("mBack")
|
self:playSFX("back")
|
||||||
self.scene.menusystem:reset()
|
self.gui:playScreenTransform("titleScreen", "hideMenu")
|
||||||
self.scene.haveMenu = false
|
self:looseFocus()
|
||||||
end
|
end
|
||||||
|
|
||||||
function SaveWidget:new(scene, saveid, savedata)
|
function SaveWidget:new(scene, saveid, savedata)
|
||||||
SaveWidget.super.new(self, scene, "save")
|
SaveWidget.super.new(self, "save")
|
||||||
self.scene.menusystem:switchMenu("save")
|
|
||||||
self.saveid = saveid
|
self.saveid = saveid
|
||||||
self.savedata = savedata
|
self.savedata = savedata
|
||||||
self.emeralds = gui.getEmeraldsTexture(self.savedata.emeralds)
|
self.emeralds = gui.getEmeraldsTexture(self.savedata.emeralds)
|
||||||
|
@ -46,7 +51,7 @@ function SaveWidget:drawCanvas()
|
||||||
str = str .. "\n"
|
str = str .. "\n"
|
||||||
str = str .. self.savedata.location .. "\n"
|
str = str .. self.savedata.location .. "\n"
|
||||||
str = str .. "Rings: " .. self.savedata.rings
|
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
|
for i, charName in ipairs(self.savedata.team) do
|
||||||
local data = core.datas:get("characters", charName)
|
local data = core.datas:get("characters", charName)
|
||||||
|
@ -56,12 +61,11 @@ function SaveWidget:drawCanvas()
|
||||||
|
|
||||||
love.graphics.draw(self.emeralds, basex + 168, basey + 21)
|
love.graphics.draw(self.emeralds, basex + 168, basey + 21)
|
||||||
else
|
else
|
||||||
self.font:draw("New save", basex + 8, basey + 4)
|
self.assets.fonts["small"]:draw("New save", basex + 8, basey + 4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function SaveWidget:action()
|
function SaveWidget:action()
|
||||||
self.scene.assets:playSFX("mSelect")
|
|
||||||
game:read(self.saveid)
|
game:read(self.saveid)
|
||||||
core.screen:startTransition(radTransitions.borders, defTransitions.circle, function() scenes.menus.main() end, 424/2, 240/2)
|
core.screen:startTransition(radTransitions.borders, defTransitions.circle, function() scenes.menus.main() end, 424/2, 240/2)
|
||||||
end
|
end
|
||||||
|
|
30
sonic-radiance.love/scenes/menus/titlescreen/pressStart.lua
Normal file
30
sonic-radiance.love/scenes/menus/titlescreen/pressStart.lua
Normal file
|
@ -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
|
59
sonic-radiance.love/scenes/menus/titlescreen/screen.lua
Normal file
59
sonic-radiance.love/scenes/menus/titlescreen/screen.lua
Normal file
|
@ -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
|
Loading…
Reference in a new issue