feat: add prompt system
This commit is contained in:
parent
f7afcdd5a9
commit
ba7b4ce977
5 changed files with 182 additions and 4 deletions
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
@ -38,7 +38,7 @@ end
|
||||||
|
|
||||||
function TweenManager:getTimerInfo(name)
|
function TweenManager:getTimerInfo(name)
|
||||||
if (self.timers[name] ~= nil) then
|
if (self.timers[name] ~= nil) then
|
||||||
self.timers[name]:getInfo()
|
return self.timers[name]:getInfo()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
local QteParent = Object:extend()
|
local QteParent = Object:extend()
|
||||||
|
|
||||||
local TweenManager = require "game.modules.tweenmanager"
|
local TweenManager = require "game.modules.tweenmanager"
|
||||||
|
local Prompts = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte.prompts"
|
||||||
|
|
||||||
function QteParent:new(choregraphySystem, arguments)
|
function QteParent:new(choregraphySystem, arguments)
|
||||||
self.choregraphy = choregraphySystem
|
self.choregraphy = choregraphySystem
|
||||||
self.arguments = arguments
|
self.arguments = arguments
|
||||||
self.tweens = TweenManager(self)
|
self.tweens = TweenManager(self)
|
||||||
self.isBlocking = nil
|
self.isBlocking = nil
|
||||||
|
self.prompts = Prompts(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function QteParent:blockAction(action, isBlocked)
|
function QteParent:blockAction(action, isBlocked)
|
||||||
|
@ -45,6 +47,8 @@ function QteParent:updateQte(dt)
|
||||||
else
|
else
|
||||||
self:update(dt)
|
self:update(dt)
|
||||||
self.tweens:update(dt)
|
self.tweens:update(dt)
|
||||||
|
self.prompts:update(dt)
|
||||||
|
self:verifyPrompts()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,6 +66,21 @@ function QteParent:finish(success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function QteParent:verifyPrompts()
|
||||||
|
local promptResult = self.prompts:verifyPrompts()
|
||||||
|
if (promptResult == 1) then
|
||||||
|
self:promptSuccess()
|
||||||
|
elseif (promptResult == -1) then
|
||||||
|
self:fail()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function QteParent:draw()
|
||||||
|
self:drawOverButtons()
|
||||||
|
self.prompts:draw(self.x, self.y)
|
||||||
|
self:drawUnderButtons()
|
||||||
|
end
|
||||||
|
|
||||||
-- USABLE FUNCTIONS
|
-- USABLE FUNCTIONS
|
||||||
-- Use these functions to access some of the API
|
-- Use these functions to access some of the API
|
||||||
|
|
||||||
|
@ -76,10 +95,10 @@ function QteParent:delay(time)
|
||||||
end
|
end
|
||||||
|
|
||||||
function QteParent:getTimerInfo()
|
function QteParent:getTimerInfo()
|
||||||
self.tweens:getTimerInfo("qteTimer")
|
return self.tweens:getTimerInfo("qteTimer")
|
||||||
end
|
end
|
||||||
|
|
||||||
function QteParent:succes()
|
function QteParent:success()
|
||||||
self:finish(true)
|
self:finish(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,11 +117,19 @@ function QteParent:update(dt)
|
||||||
--
|
--
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function QteParent:promptSuccess()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function QteParent:isSuccessOnEnd()
|
function QteParent:isSuccessOnEnd()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function QteParent:draw()
|
function QteParent:drawOverButtons()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function QteParent:drawUnderButtons()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
local Button = Object:extend()
|
||||||
|
local TweenManager = require "game.modules.tweenmanager"
|
||||||
|
|
||||||
|
local keys = {"A", "B", "C"}
|
||||||
|
local BTN_SIZE = 21
|
||||||
|
local CANVAS_SIZE = 21+2
|
||||||
|
|
||||||
|
local function myStencilFunction()
|
||||||
|
love.graphics.circle("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2 - 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Button:new(prompt, key, number, beginTime)
|
||||||
|
self.prompt = prompt
|
||||||
|
self.key = key
|
||||||
|
self.number = number or 1
|
||||||
|
|
||||||
|
self.isPressed = false
|
||||||
|
|
||||||
|
self.lum = 1
|
||||||
|
self.opacity = 0
|
||||||
|
self.frame = self:getFrame()
|
||||||
|
self.scale = 1.25
|
||||||
|
|
||||||
|
self.timerTexture = nil
|
||||||
|
self.tweens = TweenManager(self)
|
||||||
|
self.tweens:newTween(0, beginTime, {opacity = 1, scale = 1}, "inOutQuart")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Button:getFrame()
|
||||||
|
for i, key in ipairs(keys) do
|
||||||
|
if (key == self.key) then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error("Non existing key " .. self.keys)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Button:update(dt, isFirst)
|
||||||
|
self.tweens:update(dt)
|
||||||
|
|
||||||
|
if (isFirst) then
|
||||||
|
self.timerTexture = love.graphics.newCanvas(CANVAS_SIZE, CANVAS_SIZE)
|
||||||
|
love.graphics.setCanvas({self.timerTexture, stencil = true})
|
||||||
|
love.graphics.setColor(0.5, 0.5, 0.5, 1)
|
||||||
|
love.graphics.circle("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2)
|
||||||
|
utils.graphics.setColorHSV(self.prompt:getTimer()/3, 1, 1)
|
||||||
|
love.graphics.stencil(myStencilFunction, "replace", 1)
|
||||||
|
love.graphics.setStencilTest("greater", 0)
|
||||||
|
love.graphics.arc("fill", CANVAS_SIZE/2, CANVAS_SIZE/2, BTN_SIZE/2, 0 - (math.pi/2), ((math.pi*2*self.prompt:getTimer()) - (math.pi/2)), 16)
|
||||||
|
love.graphics.setStencilTest()
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Button:verifyPrompts(sourceKeys, removeWhenPressed)
|
||||||
|
local mustBeRemoved = false
|
||||||
|
local keyValue = 0
|
||||||
|
self.lum = 1
|
||||||
|
for i, key in ipairs(keys) do
|
||||||
|
if (sourceKeys[key].isPressed) then
|
||||||
|
if (key == self.key) then
|
||||||
|
keyValue = 1
|
||||||
|
self.lum = 0.8
|
||||||
|
else
|
||||||
|
keyValue = -1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (removeWhenPressed and keyValue == 1) then
|
||||||
|
self.number = self.number - 1
|
||||||
|
if (self.number == 0) then
|
||||||
|
mustBeRemoved = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return keyValue, mustBeRemoved
|
||||||
|
end
|
||||||
|
|
||||||
|
function Button:finish()
|
||||||
|
self.tweens:newTween(0, 0.2, {opacity = 0, scale = 1.25}, "inOutQuart")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Button:draw(x, y, isFirst)
|
||||||
|
love.graphics.setColor(self.lum,self.lum,self.lum,self.opacity)
|
||||||
|
if (isFirst and self.timerTexture ~= nil) then
|
||||||
|
love.graphics.draw(self.timerTexture, x, y, 0, -self.scale, self.scale, 12, 11)
|
||||||
|
end
|
||||||
|
self.prompt.assets.tileset["qtebtn"]:drawTile(self.frame, x, y, 0, self.scale, self.scale, 8, 8)
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Button
|
|
@ -0,0 +1,60 @@
|
||||||
|
local QtePrompts = Object:extend()
|
||||||
|
local Button = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte.prompts.button"
|
||||||
|
|
||||||
|
QtePrompts.BEGINTIME = 0.2
|
||||||
|
|
||||||
|
function QtePrompts:new(qte)
|
||||||
|
self.qte = qte
|
||||||
|
self.canPress = true
|
||||||
|
self.removeWhenPressed = true
|
||||||
|
self.assets = qte.choregraphy.assets
|
||||||
|
self.scene = core.scenemanager.currentScene
|
||||||
|
self.current = 1
|
||||||
|
|
||||||
|
self.list = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function QtePrompts:add(key, number)
|
||||||
|
table.insert(self.list, Button(self, key, number, QtePrompts.BEGINTIME))
|
||||||
|
end
|
||||||
|
|
||||||
|
function QtePrompts:getTimer()
|
||||||
|
local defaultValue = 0
|
||||||
|
local _, _, timerValue = self.qte:getTimerInfo()
|
||||||
|
return timerValue or defaultValue
|
||||||
|
end
|
||||||
|
|
||||||
|
function QtePrompts:update(dt)
|
||||||
|
for i, button in ipairs(self.list) do
|
||||||
|
button:update(dt, (i == self.current))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function QtePrompts:verifyPrompts()
|
||||||
|
local buttonValue, mustBeRemoved = 0, false
|
||||||
|
if (self.list[self.current] ~= nil) then
|
||||||
|
local keys = self.scene.sources[1].keys
|
||||||
|
buttonValue, mustBeRemoved = self.list[self.current]:verifyPrompts(keys, self.removeWhenPressed)
|
||||||
|
if (not self.canPress and buttonValue == 1) then
|
||||||
|
buttonValue = -1
|
||||||
|
end
|
||||||
|
if (mustBeRemoved) then
|
||||||
|
self.list[self.current]:finish()
|
||||||
|
self.current = self.current + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return buttonValue
|
||||||
|
end
|
||||||
|
|
||||||
|
function QtePrompts:isOver()
|
||||||
|
return (self.current > #self.list)
|
||||||
|
end
|
||||||
|
|
||||||
|
function QtePrompts:draw(x, y)
|
||||||
|
local SIZE = 20
|
||||||
|
for i, button in ipairs(self.list) do
|
||||||
|
button:draw(x + (SIZE*(i-1)) - ((SIZE/2)*(#self.list-1)), y, (i == self.current))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return QtePrompts
|
Loading…
Reference in a new issue