feat: port the victory screen to gui

This commit is contained in:
Kazhnuz 2021-09-18 21:31:17 +02:00
parent 205028718a
commit 8f2886be96
6 changed files with 250 additions and 235 deletions

View file

@ -1,221 +0,0 @@
local VictoryScreen = Object:extend()
local TweenManager = require "birb.classes.time"
local gui = require "game.modules.gui"
local charutils = require "game.utils.characters"
local tw, th = 280+48, 64
local rankWidth, rankHeight = 64, 48
local rankFactor = {1, 1.2, 1.5, 2}
function VictoryScreen:new(scene)
self.scene = scene
self.assets = scene.assets
self.turnSystem = scene.turns
self:setVariables()
self:getRewards()
self.infoBox = self:createInfoBox()
self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", rankWidth, rankHeight)
self.tweens = TweenManager(self)
self:prepareAnimation()
end
function VictoryScreen:setVariables()
-- Vignette Opacity
self.vignetteOpacity = 0
-- Battle FInished Label
self.labelOpacity = 0
local _, height = core.screen:getDimensions()
self.labelY = height/2
-- Infobox
self.tbSize = 0.6
self.tbOpacity = 0
-- Ranks
self.rankOpacity = 0
self.rankSize = 4
self.addExp = false
self.charDone = {}
self.nbrCharDone = 0
end
function VictoryScreen:prepareAnimation()
-- Vignette
self.tweens:newTween(0, 0.6, {vignetteOpacity=0.75}, 'inExpo')
-- Label
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelY=32}, 'inExpo')
-- Infobox
self.tweens:newTween(1.4, 0.4, {tbSize=1, tbOpacity=1}, 'inExpo')
-- Ranks
self.tweens:newTween(1.9, 0.4, {rankSize=1, rankOpacity=1}, 'inExpo')
self.tweens:newTween(2.4, 0.3, {shownExp=self.realExp, shownRings=self.realRings}, 'inExpo')
self.tweens:newSwitch(2.7, {"addExp"})
end
function VictoryScreen:getRewards()
self.rank = self.turnSystem:getRank()
local exp, rings = self.turnSystem:getRewards()
self.shownExp, self.shownRings = exp, rings
self.realExp = exp * rankFactor[self.rank]
self.realRings = rings * rankFactor[self.rank]
for i,character in ipairs(self.turnSystem.player.list) do
character.targetExp = character.exp + self.realExp
end
game.loot.rings = game.loot.rings + self.realRings
end
function VictoryScreen:createInfoBox()
local textBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th)
local canvas = love.graphics.newCanvas(tw, th)
love.graphics.setCanvas(canvas)
love.graphics.draw(textBox, 0, 0)
self.assets.fonts["SA2font"]:print("ENNEMIES:", 6, 6)
self.assets.fonts["SA2font"]:print(self.turnSystem.ennemies:count(), tw - 6, 6, "right")
self.assets.fonts["SA2font"]:print("COMBOS:", 6, th - 6 - 22)
self.assets.fonts["SA2font"]:print("0/0", tw - 6, th - 6 - 22, "right")
love.graphics.setCanvas()
local imagedata = canvas:newImageData()
local texture = love.graphics.newImage( imagedata )
imagedata:release()
canvas:release()
return texture
end
function VictoryScreen:update(dt)
self.tweens:update(dt)
if ( self.addExp and (not self:allCharDone())) then
for i,character in ipairs(self.turnSystem.player.list) do
self:addCharacterExp(dt, character)
end
end
if (self:allCharDone()) then
local keys = self.scene:getKeys(1)
if (keys["A"].isPressed) then
self.scene:returnToOverworld(false)
end
end
end
function VictoryScreen:addCharacterExp(dt, character)
if (self.charDone[character.name] == "done") then
return 0
end
local level = character.abstract.level
local xpAddRatio = charutils.getLevelExpRange(level) * 0.5
local newExp = character.exp + (xpAddRatio * dt)
if (newExp < character.targetExp) then
character.exp = newExp
local nextLevelExp = charutils.getExpValue(level + 1)
if (character.exp >= nextLevelExp) then
character.abstract:levelUp()
end
else
character.exp = character.targetExp
character.abstract.exp = character.exp
self.charDone[character.name] = "done"
self.nbrCharDone = self.nbrCharDone + 1
end
end
function VictoryScreen:allCharDone()
return (self.nbrCharDone >= self.turnSystem.player:count())
end
function VictoryScreen:draw()
local width, height = core.screen:getDimensions()
self:drawVignette(width, height)
self:drawLabel(width/2, self.labelY, self.labelOpacity)
self:drawInfobox(width/2, height/2 - 32, self.tbSize, self.tbOpacity)
local startx = (width/2 - tw/2)
local endx = (width/2 + tw/2)
local scorex = startx + rankWidth + 8
local starty = height/2 + 8
local endy = starty + rankHeight
self:drawRankBox(startx, starty, self.rankSize, self.tbOpacity, self.rankOpacity)
self:drawText(scorex, starty, endx, "EXP:", math.floor(self.shownExp), self.tbOpacity)
self:drawText(scorex, endy - 24, endx, "RINGS:", math.floor(self.shownRings), self.tbOpacity)
for i,character in ipairs(self.turnSystem.player.list) do
self:drawCharacterExp(startx + ((i-1)*84), endy + 8, character, self.tbOpacity)
end
if (self:allCharDone()) then
self.assets.fonts["small"]:print("Press the A key to continue...", width/2, endy + 32, "center")
end
utils.graphics.resetColor()
end
function VictoryScreen:drawVignette(width, height)
love.graphics.setColor(0, 0, 0, self.vignetteOpacity)
love.graphics.rectangle("fill", 0, 0, width, height)
end
function VictoryScreen:drawLabel(x, y, opacity)
love.graphics.setColor(1, 1, 1, opacity)
local w, h = self.assets.images["battlecompleted"]:getDimensions()
self.assets.images["battlecompleted"]:draw(x, y, 0, 1, 1, w/2, h/2)
end
function VictoryScreen:drawInfobox(x, y, size, opacity)
love.graphics.setColor(1, 1, 1, opacity)
love.graphics.draw(self.infoBox, x, y, 0, size, size, tw/2, th/2)
end
function VictoryScreen:drawRankBox(x, y, rankSize, boxOpacity, rankOpacity)
love.graphics.setColor(1, 1, 1, boxOpacity)
love.graphics.draw(self.rankBox, x, y)
love.graphics.setColor(1, 1, 1, rankOpacity)
self.assets.tileset["ranks"]:drawTile(self.rank, x + (rankWidth/2), y + (rankHeight/2), 0, rankSize, rankSize, 13, 13)
end
function VictoryScreen:drawText(x, y, x2, text1, text2, opacity)
love.graphics.setColor(1, 1, 1, opacity)
self.assets.fonts["SA2font"]:print(text1, x, y)
self.assets.fonts["SA2font"]:print(text2, x2, y, "right")
end
function VictoryScreen:drawCharacterExp(x, y, character, opacity)
love.graphics.setColor(1, 1, 1, opacity)
self.assets.images["expbar"]:draw(x, y)
character:drawIcon(x+1, y+6)
love.graphics.setColor(0, 0.8, 0.1, opacity)
local level = character.abstract.level
local exp = character.exp
local remainingExp = charutils.getRemainingExp(exp, level)
local expRatio = charutils.getRelativeExpValue(exp, level) / charutils.getLevelExpRange(level)
gui.drawBar(x + 22, y + 11, math.floor(56 * expRatio), 7)
love.graphics.setColor(1, 1, 1, opacity)
self.assets.fonts["hudnbrs_small"]:print(math.floor(remainingExp), x + 71, y + 11, "right")
self.assets.fonts["hudnbrs_small"]:print(level, x + 72, y + 1, "right")
end
return VictoryScreen

View file

@ -0,0 +1,80 @@
local GuiElement = require "birb.modules.gui.elements.parent"
local CharacterExp = GuiElement:extend()
local gui = require "game.modules.gui"
local charutils = require "game.utils.characters"
function CharacterExp:new(x, y, character, number)
self.character = character
self.started = false
self.done = false
CharacterExp.super.new(self, character.name .. "Exp", x, y, 1, 1)
self.opacity = 0
self.number = number
self:newTween(1.4, 0.4, {opacity = 1}, "inExpo")
if self.number == 1 then
self:startInSeconds(2.5)
end
self.targetExp = self.scene.turns.rewards:getExp(character)
self.exp = character.abstract.exp
end
function CharacterExp:update(dt)
if (not self.done and (self.started)) then
self:addCharacterExp(dt)
end
end
function CharacterExp:startInSeconds(seconds)
self:newFunc(seconds, "startMe", function() self:startExpGain(1) end)
end
function CharacterExp:startExpGain(number)
self.started = true
end
function CharacterExp:addCharacterExp(dt)
local level = self.character.abstract.level
local xpAddRatio = charutils.getLevelExpRange(level) * 0.5
local newExp = self.exp + (xpAddRatio * dt)
if (newExp < self.targetExp) then
self.exp = newExp
local nextLevelExp = charutils.getExpValue(level + 1)
if (self.exp >= nextLevelExp) then
self.character.abstract.abstract:levelUp()
end
else
self.exp = self.targetExp
self.character.abstract.exp = self.targetExp
self.done = true
self.isLast = self.screen:nextExp(self.number + 1)
if (self.isLast) then
self:getFocus()
end
end
end
function CharacterExp:keypressed(key)
if (key == "A" and self.done and self.isLast) then
self.scene:returnToOverworld(false)
self.scene:setPrompt("")
end
end
function CharacterExp:draw()
love.graphics.setColor(1, 1, 1, self.opacity)
self.assets.images["expbar"]:draw(self.x, self.y)
self.character:drawIcon(self.x + 1, self.y + 6)
love.graphics.setColor(0, 0.8, 0.1, self.opacity)
local level = self.character.abstract.level
local exp = self.exp
local remainingExp = charutils.getRemainingExp(exp, level)
local expRatio = charutils.getRelativeExpValue(exp, level) / charutils.getLevelExpRange(level)
gui.drawBar(self.x + 22, self.y + 11, math.floor(56 * expRatio), 7)
love.graphics.setColor(1, 1, 1, self.opacity)
self.assets.fonts["hudnbrs_small"]:print(math.floor(remainingExp), self.x + 71, self.y + 11, "right")
self.assets.fonts["hudnbrs_small"]:print(level, self.x + 72, self.y + 1, "right")
end
return CharacterExp

View file

@ -0,0 +1,122 @@
local Screen = require "birb.modules.gui.screen"
local VictoryScreen = Screen:extend()
local TextElement = require "birb.modules.gui.elements.text"
local ChoiceElement = require "game.modules.gui.choiceElem"
local ConfirmDialog = require "game.modules.confirmdialog"
local TextureElement = require "birb.modules.gui.elements.drawable"
local LootElement = require "scenes.battlesystem.gui.victory.loot"
local ItemsElement = require "scenes.battlesystem.gui.victory.items"
local CharExperience = require "scenes.battlesystem.gui.victory.exp"
local TileElement = require "birb.modules.gui.elements.tile"
local defTransitions = require "birb.modules.transitions"
local gui = require "game.modules.gui"
local HEIGHT = 32
local STARTX, STARTY = 32, HEIGHT + 44
local ENDX, ENDY = 424 - 32, 240 - 24
local SIZE_FEATS = 128+28
local START_ITEMS = STARTX + SIZE_FEATS
local START_EXP = START_ITEMS + 128
local show = {
{"gameText", "movement", 0.9, 0.4, 424/2, HEIGHT, "inExpo"},
--{"rankBox", "tween", 1.4, 0.4, {opacity = 1}, "inExpo"},
{"loot", "tween", 1.4, 0.4, {opacity = 1}, "inExpo"},
{"items", "tween", 1.4, 0.4, {opacity = 1}, "inExpo"},
}
function VictoryScreen:new()
self.feats = 0
self.rankBox = gui.newTextBox("assets/gui/dialogbox.png", 48, 32)
self.itemBox = gui.newTextBox("assets/gui/dialogbox.png", 96, 48)
VictoryScreen.super.new(self, "titleScreen")
self:addTransform("show", show)
self.scene:showOverlay(true)
self:show()
end
function VictoryScreen:createFeats(list)
local ennemyNbr, turns, dmgSent, dmgTaken, ko = self.turns:getDatas()
self:addFeat(list,"Ennemies", ennemyNbr)
self:addFeat(list,"Turns", turns)
self:addFeat(list,"Dmg sent", dmgSent)
if (dmgTaken == 0) then
self:addFeat(list,"No damage !", "")
else
self:addFeat(list,"Dmg taken", dmgTaken)
self:addFeat(list,"KO", ko)
end
local qteRate, haveDoneQte = self.rewards:getQteSuccessRate()
if (not haveDoneQte) then
self:addFeat(list,"No QTE done")
else
self:addFeat(list,"QTE success", math.floor(qteRate * 100) .. "%")
end
self:addRank(list)
end
function VictoryScreen:addFeat(list, text, label)
self.feats = self.feats + 1
local featID = "feat" .. self.feats
label = label or ""
local elem = ChoiceElement(featID, text, "", label, STARTX - 16, STARTY + (16*(self.feats-1)), SIZE_FEATS)
elem.opacity = 0
elem:newTween(1 + (0.2*self.feats), 0.15, {opacity = 1, x = STARTX}, 'inQuad')
table.insert(list, {elem, 0, 1})
end
function VictoryScreen:addRank(list)
local rank = TileElement("rank", "ranks", self.rewards:getRank(), 424/2, ENDY - 28,0,4,4,13,13, 0)
rank:newTween(1.9, 0.4, {sx=1, sy=1, opacity=1}, 'inExpo')
table.insert(list, {rank, 0, 1})
end
function VictoryScreen:nextExp(nbr)
local list = self.scene.turns.player:getList()
local nextChar = list[nbr]
if nextChar ~= nil then
self.elements[nextChar.name .. "Exp"]:startExpGain(nbr)
return false
else
self.scene:setPrompt("Finish")
return true
end
end
function VictoryScreen:createElements()
self.turns = self.scene.turns
self.rewards = self.turns.rewards
local list = {
{TextElement("gameText", "SA2font", "BATTLE COMPLETED", 424/2, -24, "center"), 0, 1},
--{TextureElement("rankBox", self.rankBox, 424/2, ENDY - 4, 0, 1,1, 64/2,48, 0), 0, 1},
{LootElement(START_ITEMS + 2, STARTY - 2), 0, 1},
{ItemsElement(START_ITEMS + 2, STARTY + 40, {"test", "test", "test"}), 0, 1}
}
self:createFeats(list)
for i, character in ipairs(self.scene.turns.player:getList()) do
table.insert(list, {CharExperience(START_EXP - 4, STARTY + (i-1)*24 - 12, character, i), 0, 1})
end
return list
end
function VictoryScreen:returnToTitle()
core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.menus.title(true) end, 424/2, 240/2)
end
function VictoryScreen:loadLastSave()
self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad")
core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2)
end
return VictoryScreen

View file

@ -0,0 +1,23 @@
local CanvasElement = require "birb.modules.gui.elements.canvas"
local ItemsElement = CanvasElement:extend()
local gui = require "game.modules.gui"
function ItemsElement:new(x, y, list)
self.background = gui.newTextBox("assets/gui/dialogbox.png", 128, 40+16)
local w, h = self.background:getDimensions()
ItemsElement.super.new(self, "items", x, y, w, h)
self.opacity = 0
self.list = list
end
function ItemsElement:drawTexture()
love.graphics.draw(self.background, 0, 0)
for index, value in ipairs(self.list) do
if (index <= 4) then
self.assets.fonts["small"]:draw(value, 8, 4 + (16*(index-1)), -1, "left")
end
end
end
return ItemsElement

View file

@ -0,0 +1,22 @@
local CanvasElement = require "birb.modules.gui.elements.canvas"
local LootElement = CanvasElement:extend()
local gui = require "game.modules.gui"
function LootElement:new(x, y)
self.background = gui.newTextBox("assets/gui/dialogbox.png", 128, 40)
local w, h = self.background:getDimensions()
LootElement.super.new(self, "loot", x, y, w, h)
self.canvas.isAnimated = true
self.opacity = 0
end
function LootElement:drawTexture()
love.graphics.draw(self.background, 0, 0)
self.assets.fonts["small"]:draw("Rings: ", 8, 4, -1, "left")
self.assets.fonts["small"]:draw("0", self.w - 8, 4, -1, "right")
self.assets.fonts["small"]:draw("Exp: ", 8, 20, -1, "left")
self.assets.fonts["small"]:draw("0", self.w - 8, 20, -1, "right")
end
return LootElement

View file

@ -5,7 +5,7 @@ local BattleSystem = Scene:extend()
local World = require "scenes.battlesystem.world"
local Turns = require "scenes.battlesystem.turns"
local VictoryScreen = require "scenes.battlesystem.gui.screens.victory"
local VictoryScreen = require "scenes.battlesystem.gui.victory"
local GameOverScreen = require "game.modules.gui.gameover"
local CbsScreen = require "scenes.battlesystem.gui"
@ -14,7 +14,6 @@ local TweenManager = require "birb.classes.time"
function BattleSystem:new(battleData)
BattleSystem.super.new(self)
self.assets:batchImport("assets.battle")
self:playMusic(battleData.music)
@ -45,7 +44,7 @@ end
function BattleSystem:finishBattle()
self.assets:setMusic("assets/music/victory.mp3")
self.assets:playMusic()
self.screen = VictoryScreen(self)
VictoryScreen(self)
end
function BattleSystem:fleeBattle()
@ -73,18 +72,8 @@ end
function BattleSystem:update(dt)
self.tweens:update(dt)
self.world:update(dt)
self.turns:update(dt)
if (self.screen ~= nil) then
self.screen:update(dt)
end
end
function BattleSystem:draw()
BattleSystem.super.draw(self)
if (self.screen ~= nil) then
self.screen:draw()
end
self.world:update(dt)
end
function BattleSystem:exit()