From 3c8a3ed312512626b0a061c11f1308170bf259a7 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:29:36 +0200 Subject: [PATCH] improvement: make qtes guiElements --- .../scenes/battlesystem/choregraphy/init.lua | 6 ---- .../battlesystem/choregraphy/qte/parent.lua | 35 ++++++++++--------- .../choregraphy/qte/prompts/button.lua | 21 +++++------ .../choregraphy/qte/prompts/init.lua | 5 ++- .../fighters/character/actions/parent.lua | 6 ---- 5 files changed, 29 insertions(+), 44 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua index b2bc558..3bb90c9 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/init.lua @@ -31,7 +31,6 @@ function ChoregraphySystem:new(action, choregraphy, subChoregraphy) end function ChoregraphySystem:update(dt) - self:updateQte(dt) self:updateSteps(dt) self.tweens:update(dt) self:updateSubChoregraphies(dt) @@ -49,9 +48,4 @@ function ChoregraphySystem:endChoregraphy() self.fighter.turnSystem:applyDeath() end -function ChoregraphySystem:draw() - self:drawQte() - self:drawSubChoregraphies() -end - return ChoregraphySystem diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua index 0afa2be..e14de48 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua @@ -1,18 +1,23 @@ -local QteParent = Object:extend() +local GuiElements = require "birb.modules.gui.elements.parent" +local QteParent = GuiElements:extend() -local TweenManager = require "birb.classes.time" local Prompts = require "scenes.battlesystem.choregraphy.qte.prompts" function QteParent:new(choregraphySystem, arguments) self.choregraphy = choregraphySystem self.arguments = arguments - self.tweens = TweenManager(self) self.isBlocking = nil self.prompts = Prompts(self) self.timer = 0 self.timerActive = false self.isSuccess = false self.tag = "" + + QteParent.super.new(self, "qte", -1, -1, 1, 1) + + self:start() + self.isStarted = true + self:getFocus() end function QteParent:setTag(tag) @@ -60,18 +65,13 @@ function QteParent:setOrigin(origin) end end -function QteParent:updateQte(dt, isActive) - if (not self.isStarted) then - self:start() - self.isStarted = true - else - self:update(dt) - self.tweens:update(dt) - self.prompts:update(dt) - if (isActive) then - self:verifyPrompts() - end - end +function QteParent:updateElement(dt) + QteParent.super.updateElement(self, dt) + self.prompts:update(dt) +end + +function QteParent:keypressed(key) + self:verifyPrompts(key) end function QteParent:timerResponse(timer) @@ -87,6 +87,7 @@ function QteParent:timerResponse(timer) self.prompts.defaultTimerValue = 0 elseif (timer == "endQte") then self.choregraphy:removeQte() + self:destroy() end end @@ -97,8 +98,8 @@ function QteParent:finish(success) self:endQte() end -function QteParent:verifyPrompts() - local promptResult = self.prompts:verifyPrompts() +function QteParent:verifyPrompts(key) + local promptResult = self.prompts:verifyPrompts(key) if (promptResult == 1) then self:promptSuccess() elseif (promptResult == -1) then diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua index a21d272..b6705ee 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/button.lua @@ -69,24 +69,21 @@ function Button:update(dt, isFirst) 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() + utils.graphics.resetColor() end end -function Button:verifyPrompts(sourceKeys, removeWhenPressed) +function Button:verifyPrompts(key, 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 - table.insert(self.circles, ButtonCircle()) - else - keyValue = -1 - self.isFailed = true - end - end + if (key == self.key) then + keyValue = 1 + self.lum = 0.8 + table.insert(self.circles, ButtonCircle()) + else + keyValue = -1 + self.isFailed = true end if (removeWhenPressed and keyValue == 1) then self.number = self.number - 1 diff --git a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua index 7283b39..2584239 100644 --- a/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua @@ -31,11 +31,10 @@ function QtePrompts:update(dt) end end -function QtePrompts:verifyPrompts() +function QtePrompts:verifyPrompts(key) 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) + buttonValue, mustBeRemoved = self.list[self.current]:verifyPrompts(key, self.removeWhenPressed) if (not self.canPress and buttonValue == 1) then buttonValue = -1 end diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua index 25bd887..6f624c0 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/actions/parent.lua @@ -53,10 +53,4 @@ function ActionParent:finishAction() self.fighter:finishAction() end -function ActionParent:draw() - if (self.choregraphy ~= nil) then - self.choregraphy:draw() - end -end - return ActionParent