Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
2 changed files with 24 additions and 29 deletions
Showing only changes of commit 5b0bdc68ce - Show all commits

View file

@ -12,15 +12,11 @@ function HeroFighter:new(owner, character, id)
self:initVoices() self:initVoices()
self.selection = nil
self.exp = self.abstract.exp self.exp = self.abstract.exp
end end
function HeroFighter:update(dt) function HeroFighter:update(dt)
HeroFighter.super.update(self, dt) HeroFighter.super.update(self, dt)
if (self.selection ~= nil) then
self.selection:update(dt)
end
end end
function HeroFighter:getAbstract() function HeroFighter:getAbstract()
@ -72,9 +68,9 @@ function HeroFighter:verifyTargets()
if (needTarget) then if (needTarget) then
if (targetEnnemies) then if (targetEnnemies) then
self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies, true) SelectionSystem(self, self.owner.turnSystem.ennemies, true)
else else
self.selection = SelectionSystem(self, self.owner, false) SelectionSystem(self, self.owner, false)
end end
else else
self.action:start() self.action:start()
@ -87,7 +83,6 @@ function HeroFighter:attack()
end end
function HeroFighter:receiveTarget(target) function HeroFighter:receiveTarget(target)
self.selection = nil
if (self.action ~= nil) then if (self.action ~= nil) then
self.action:setTarget(target) self.action:setTarget(target)
self.action:start() self.action:start()
@ -96,7 +91,6 @@ end
function HeroFighter:goBackToMenu() function HeroFighter:goBackToMenu()
self.turnSystem.scene.gui:setFocus("battleMenu") self.turnSystem.scene.gui:setFocus("battleMenu")
self.selection = nil
end end
-- LIFE functions -- LIFE functions

View file

@ -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) function SelectionSystem:new(owner, fighterSide, onlyAlive)
SelectionSystem.super.new(self, "selection", 0, 0, 1, 1)
self.fighterList = fighterSide:getTargets(onlyAlive) self.fighterList = fighterSide:getTargets(onlyAlive)
self.owner = owner self.owner = owner
self.assets = self.owner.assets self.assets = self.owner.assets
self.selectedTarget = 1 self.selectedTarget = 1
self:updateTarget()
self:getFocus()
end end
function SelectionSystem:update(dt) function SelectionSystem:keypressed(key)
--Faire en sorte que cela permette de choisir la cible if (key == "A") then
local keys = self.owner.turnSystem.scene:getKeys(1) self.assets.sfx["mSelect"]:play()
self:selectTarget()
elseif (key == "B") then
self.assets.sfx["mBack"]:play()
self:goBack()
elseif (key == "up") then
self:purgeTarget() self:purgeTarget()
if (keys["up"].isPressed) then
if (self.selectedTarget == 1) then if (self.selectedTarget == 1) then
self.selectedTarget = #self.fighterList self.selectedTarget = #self.fighterList
else else
self.selectedTarget = self.selectedTarget - 1 self.selectedTarget = self.selectedTarget - 1
end end
self.assets.sfx["mBeep"]:play() self.assets.sfx["mBeep"]:play()
end self:updateTarget()
if (keys["down"].isPressed) then elseif (key == "down") then
self:purgeTarget()
if (self.selectedTarget == #self.fighterList) then if (self.selectedTarget == #self.fighterList) then
self.selectedTarget = 1 self.selectedTarget = 1
else else
self.selectedTarget = self.selectedTarget + 1 self.selectedTarget = self.selectedTarget + 1
end end
self.assets.sfx["mBeep"]:play() self.assets.sfx["mBeep"]:play()
end
self:updateTarget() self:updateTarget()
if (keys["A"].isPressed) then
self.assets.sfx["mSelect"]:play()
self:selectTarget()
end end
if (keys["B"].isPressed) then
self.assets.sfx["mBack"]:play()
self:goBack()
end
end end
function SelectionSystem:purgeTarget() function SelectionSystem:purgeTarget()
@ -53,11 +50,15 @@ function SelectionSystem:updateTarget()
end end
function SelectionSystem:selectTarget() function SelectionSystem:selectTarget()
self:looseFocus()
self:destroy()
self:purgeTarget() self:purgeTarget()
self.owner:receiveTarget(self.fighterList[self.selectedTarget]) self.owner:receiveTarget(self.fighterList[self.selectedTarget])
end end
function SelectionSystem:goBack() function SelectionSystem:goBack()
self:looseFocus()
self:destroy()
self:purgeTarget() self:purgeTarget()
self.owner:goBackToMenu() self.owner:goBackToMenu()
end end