From 5b0bdc68ce305f15676ee0ecb64a729a49f1b28b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 16 Sep 2021 22:28:57 +0200 Subject: [PATCH] improvement: port the selection to guisystem It's a special guiElement, as it's not drawn by the GUISystem, but the input handling code is usefull. --- .../battlesystem/fighters/character/init.lua | 10 +---- .../fighters/character/selection.lua | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua index 2990b71..1d52b4c 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua @@ -12,15 +12,11 @@ function HeroFighter:new(owner, character, id) self:initVoices() - self.selection = nil self.exp = self.abstract.exp end function HeroFighter:update(dt) HeroFighter.super.update(self, dt) - if (self.selection ~= nil) then - self.selection:update(dt) - end end function HeroFighter:getAbstract() @@ -72,9 +68,9 @@ function HeroFighter:verifyTargets() if (needTarget) then if (targetEnnemies) then - self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies, true) + SelectionSystem(self, self.owner.turnSystem.ennemies, true) else - self.selection = SelectionSystem(self, self.owner, false) + SelectionSystem(self, self.owner, false) end else self.action:start() @@ -87,7 +83,6 @@ function HeroFighter:attack() end function HeroFighter:receiveTarget(target) - self.selection = nil if (self.action ~= nil) then self.action:setTarget(target) self.action:start() @@ -96,7 +91,6 @@ end function HeroFighter:goBackToMenu() self.turnSystem.scene.gui:setFocus("battleMenu") - self.selection = nil end -- LIFE functions diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua index 1db4db9..1040b7c 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/selection.lua @@ -1,45 +1,42 @@ -local SelectionSystem = Object:extend() +local GuiElement = require "birb.modules.gui.elements.parent" +local SelectionSystem = GuiElement:extend() function SelectionSystem:new(owner, fighterSide, onlyAlive) + SelectionSystem.super.new(self, "selection", 0, 0, 1, 1) self.fighterList = fighterSide:getTargets(onlyAlive) self.owner = owner self.assets = self.owner.assets self.selectedTarget = 1 + self:updateTarget() + self:getFocus() end -function SelectionSystem:update(dt) - --Faire en sorte que cela permette de choisir la cible - local keys = self.owner.turnSystem.scene:getKeys(1) - self:purgeTarget() - if (keys["up"].isPressed) then +function SelectionSystem:keypressed(key) + if (key == "A") then + self.assets.sfx["mSelect"]:play() + self:selectTarget() + elseif (key == "B") then + self.assets.sfx["mBack"]:play() + self:goBack() + elseif (key == "up") then + self:purgeTarget() if (self.selectedTarget == 1) then self.selectedTarget = #self.fighterList else self.selectedTarget = self.selectedTarget - 1 end self.assets.sfx["mBeep"]:play() - end - if (keys["down"].isPressed) then + self:updateTarget() + elseif (key == "down") then + self:purgeTarget() if (self.selectedTarget == #self.fighterList) then self.selectedTarget = 1 else self.selectedTarget = self.selectedTarget + 1 end self.assets.sfx["mBeep"]:play() + self:updateTarget() end - - self:updateTarget() - - if (keys["A"].isPressed) then - self.assets.sfx["mSelect"]:play() - self:selectTarget() - end - - if (keys["B"].isPressed) then - self.assets.sfx["mBack"]:play() - self:goBack() - end - end function SelectionSystem:purgeTarget() @@ -53,11 +50,15 @@ function SelectionSystem:updateTarget() end function SelectionSystem:selectTarget() + self:looseFocus() + self:destroy() self:purgeTarget() self.owner:receiveTarget(self.fighterList[self.selectedTarget]) end function SelectionSystem:goBack() + self:looseFocus() + self:destroy() self:purgeTarget() self.owner:goBackToMenu() end