improvement: use a confirm dialog for game over

Fixes #41
This commit is contained in:
Kazhnuz 2021-08-15 17:41:39 +02:00
parent cb6bd66174
commit 44f2bae574

View file

@ -1,9 +1,10 @@
local VictoryScreen = Object:extend() local VictoryScreen = Object:extend()
local TweenManager = require "birb.classes.time" local TweenManager = require "birb.classes.time"
local ConfirmDialog = require "game.modules.confirmdialog"
local BATTLECOMPLETE_START = 2 local defTransitions = require "birb.modules.transitions"
local BATTLECOMPLETE_STOP = 4 local radTransitions = require "game.modules.transitions"
local gui = require "game.modules.gui" local gui = require "game.modules.gui"
@ -34,9 +35,6 @@ function VictoryScreen:setVariables()
-- Infobox -- Infobox
self.tbSize = 0.6 self.tbSize = 0.6
self.tbOpacity = 0 self.tbOpacity = 0
self.continue = false
self.continueValue = -1
end end
function VictoryScreen:prepareAnimation() function VictoryScreen:prepareAnimation()
@ -50,7 +48,7 @@ function VictoryScreen:prepareAnimation()
-- Infobox -- Infobox
self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo') self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo')
self.tweens:newSwitch(1.8, {"continue"}) self.tweens:newTimer(1.8, "continue")
end end
function VictoryScreen:update(dt) function VictoryScreen:update(dt)
@ -76,8 +74,15 @@ function VictoryScreen:draw()
local width, height = core.screen:getDimensions() local width, height = core.screen:getDimensions()
self:drawVignette(width, height) self:drawVignette(width, height)
self:drawLabel(width/2, height/4, self.labelX, self.labelOpacity) self:drawLabel(width/2, height/4, self.labelX, self.labelOpacity)
end
self:drawContinueBox(width/2, height/2 + 32, self.continueValue, self.tbSize, self.tbOpacity) function VictoryScreen:timerResponse(timer)
if (timer == "continue") then
local confirm = ConfirmDialog(self.scene, "Do you want to continue ?",
function() self:toOverworld() end, "Yes",
function() self:toTitleScreen() end, "No")
confirm.darken = false
end
end end
function VictoryScreen:drawVignette(width, height) function VictoryScreen:drawVignette(width, height)
@ -86,6 +91,17 @@ function VictoryScreen:drawVignette(width, height)
love.graphics.rectangle("fill", 0, 0, width, height) love.graphics.rectangle("fill", 0, 0, width, height)
end end
function VictoryScreen:toOverworld()
core.screen:startTransition(radTransitions.borders, defTransitions.default, function()
game:reload()
scenes.overworld()
end, 424/2, 240/2)
end
function VictoryScreen:toTitleScreen()
core.screen:startTransition(radTransitions.borders, radTransitions.borders, function() scenes.menus.title(false) end, 424/2, 240/2)
end
function VictoryScreen:drawLabel(x, y, x2, opacity) function VictoryScreen:drawLabel(x, y, x2, opacity)
love.graphics.setColor(1, 1, 1, opacity) love.graphics.setColor(1, 1, 1, opacity)
@ -94,15 +110,4 @@ function VictoryScreen:drawLabel(x, y, x2, opacity)
self.assets.images["over"]:draw(x + x2, y, 0, 1, 1, 0, h/2) self.assets.images["over"]:draw(x + x2, y, 0, 1, 1, 0, h/2)
end end
function VictoryScreen:drawContinueBox(x, y, continueValue, size, opacity)
love.graphics.setColor(1, 1, 1, opacity)
love.graphics.draw(self.continueBox, x, y, 0, size, size, tw/2, th/2)
local text = "continue"
if (continueValue == 1) then
text = "quit"
end
self.assets.images["arrow"]:draw(x - continueValue*64, y, math.rad(-90) * continueValue, continueValue, 1, 13, 13)
self.assets.fonts["SA2font"]:print(text, x, y-13, "center")
end
return VictoryScreen return VictoryScreen