diff --git a/sonic-radiance.love/game/modules/gui/bosshpbar.lua b/sonic-radiance.love/game/modules/gui/bosshpbar.lua deleted file mode 100644 index f421f28..0000000 --- a/sonic-radiance.love/game/modules/gui/bosshpbar.lua +++ /dev/null @@ -1,30 +0,0 @@ -local BossHpBar = Object:extend() - -local TweenManager = require "birb.classes.time" -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -function BossHpBar:new(hp) - self.tweens = TweenManager(self) - self.hp = hp - self.baseHP = hp - self.hpbar = ComplexHPBar(120) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) - - self.bossTexture = love.graphics.newImage("assets/gui/strings/boss.png") -end - -function BossHpBar:setHP(newHP) - self.tweens:newTween(0, 0.1, {hp = newHP}, 'inCubic') -end - -function BossHpBar:update(dt) - self.tweens:update(dt) -end - -function BossHpBar:draw(x, y) - self.hpbar:draw(x, y, self.hp / self.baseHP) - love.graphics.draw(self.bossTexture, x + 98, y + 10) -end - -return BossHpBar \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/gui/statusbar.lua b/sonic-radiance.love/game/modules/gui/statusbar.lua deleted file mode 100644 index 947d717..0000000 --- a/sonic-radiance.love/game/modules/gui/statusbar.lua +++ /dev/null @@ -1,65 +0,0 @@ -local StatusBar = Object:extend() -local TweenManager = require "birb.classes.time" - -local gui = require "game.modules.gui" - -local Emblem = require "game.modules.gui.emblem" -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -function StatusBar:new(abstract, scene) - self.assets = scene.assets - self.abstract = abstract - - self.emblem = Emblem(abstract, scene) - - self.hp = self.abstract.hp - self.pp = self.abstract.pp - self.stats = self.abstract:getStats() - - self.hpbar = ComplexHPBar(58) - self.ppbar = ComplexHPBar(58) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) - self.ppbar:setColorForeground(0, 248/255, 248/255, 1) - self.ppbar:setColorBackground(0, 54/255, 229/255) - - self.tweens = TweenManager(self) -end - -function StatusBar:update(dt) - self.tweens:update(dt) -end - -function StatusBar:updateHP() - self.tweens:newTween(0, 0.3, {hp = self.abstract.hp}, 'linear') -end - -function StatusBar:updatePP() - self.tweens:newTween(0, 0.3, {pp = self.abstract.pp}, 'linear') -end - -function StatusBar:draw(x, y) - self.emblem:drawBackground(x, y) - self:drawStatusArea(x+10, y-8) - self.emblem:drawForeground(x, y) -end - -function StatusBar:drawStatusArea(x, y) -self.assets.images["statusbar"]:draw(x, y) - -local hpmax = self.stats:get(self.stats.HPMAX) -local ppmax = self.stats:get(self.stats.PPMAX) - -self.assets.fonts["hudnbrs_small"]:set() -self.hpbar:drawWithLabels(x + 6, y + 9, self.hp, hpmax) -self.ppbar:drawWithLabels(x + 18, y + 21, self.pp, ppmax) - -local lvl = self.abstract.level - -if lvl < 100 then - lvl = "0" .. lvl -end - love.graphics.print(lvl, x+42, y+1) -end - -return StatusBar diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua index 120dbc1..2990b71 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/character/init.lua @@ -1,28 +1,21 @@ local FighterParent = require "scenes.battlesystem.fighters.fighter" local HeroFighter = FighterParent:extend() -local StatusBar = require "game.modules.gui.statusbar" local SelectionSystem = require "scenes.battlesystem.fighters.character.selection" local actionList = require "scenes.battlesystem.fighters.character.actions" local HEROES_LINE = 2; -local HUDSIZE = 91 function HeroFighter:new(owner, character, id) self.name = character self.super.new(self, owner, true, id) - self.statusbar = StatusBar(self.abstract, self.turnSystem.scene) self:initVoices() self.selection = nil self.exp = self.abstract.exp end -function HeroFighter:updateAssets(dt) - self.statusbar:update(dt) -end - function HeroFighter:update(dt) HeroFighter.super.update(self, dt) if (self.selection ~= nil) then @@ -47,7 +40,7 @@ function HeroFighter:startAction() core.debug:print("cbs/heroFighter", "launching the action menu") self.action = nil self:talk("turnstart") - self.turnSystem.scene.menu:set( self ) + self.turnSystem.scene.gui.screens["hud"]:buildMenu( self ) end function HeroFighter:endAction() @@ -102,17 +95,19 @@ function HeroFighter:receiveTarget(target) end function HeroFighter:goBackToMenu() - self.owner.turnSystem.scene.menusystem:activate() + self.turnSystem.scene.gui:setFocus("battleMenu") self.selection = nil end -- LIFE functions function HeroFighter:updatePP() - self.statusbar:updatePP() + local elem = self.turnSystem.scene.gui:getElement(self.abstract.name .. "StatutBar") + elem:updatePP() end function HeroFighter:updateHP() - self.statusbar:updateHP() + local elem = self.turnSystem.scene.gui:getElement(self.abstract.name .. "StatutBar") + elem:updateHP() end -- VOICE SYSTEM @@ -139,14 +134,4 @@ function HeroFighter:drawIcon(x, y) self.assets.tileset["charicons"]:drawTile(iconID, x, y) end -function HeroFighter:drawHUD() - local boxSize = 424 / 4 - local x = (self.id-0.5)*boxSize - local y = self.turnSystem.hud:getPlayerHUDPosition() - self.statusbar:draw(x - HUDSIZE/2, y) - if (self.action ~= nil) then - self.action:draw() - end -end - return HeroFighter diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua b/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua index 2b9f5ce..bb6a335 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/ennemies.lua @@ -46,12 +46,7 @@ function EnnemyController:addBoss(ennData) boss:setCheapEffect(ennData.cheapEffect) self.turnSystem.canFleeBattle = false self:add(boss) -end - -function EnnemyController:draw() - for i, villain in ipairs(self.list) do - villain:drawHUD() - end + boss:createHPBar() end return EnnemyController diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua b/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua index 932026a..100479a 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/ennemy/init.lua @@ -2,11 +2,10 @@ local FighterParent = require "scenes.battlesystem.fighters.fighter" local VillainFighter = FighterParent:extend() local SimpleHPBar = require "game.modules.gui.simplehpbar" -local BossHPBar = require "game.modules.gui.bosshpbar" +local BossHPBar = require "scenes.battlesystem.gui.hudelements.bosshpbar" local EnnemyAction = require "scenes.battlesystem.fighters.ennemy.action" local behaviourList = require "scenes.battlesystem.fighters.ennemy.behaviours" - local POSITIONS = {1, 3, 5} local ENNEMY_LINE = 11; @@ -25,11 +24,6 @@ end function VillainFighter:updateAssets(dt) self.hpbar:update(dt) - if (self.bossHpBar ~= nil) then - self.bossHpBar:update(dt) - else - self.bossHpBar = BossHPBar(self.abstract.hp) - end end function VillainFighter:getAbstract() @@ -90,7 +84,9 @@ end function VillainFighter:setHP(value, relative) VillainFighter.super.setHP(self, value, relative) self.hpbar:setHP(self.abstract.hp) - self.bossHpBar:setHP(self.abstract.hp) + if (self.bossHpBar ~= nil) then + self.bossHpBar:setHP(self.abstract.hp) + end end -- DRAW FUNCTIONS @@ -107,10 +103,8 @@ function VillainFighter:drawOversprite(x, y) end end -function VillainFighter:drawHUD() - if (self.isBoss and self.bossHpBar ~= nil) then - self.bossHpBar:draw(280, 28) - end +function VillainFighter:createHPBar() + self.bossHpBar = BossHPBar(self.abstract.hp) end return VillainFighter diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua index 7ac8d5f..f78bc35 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/parent.lua @@ -10,6 +10,10 @@ function FighterControllerParent:get(id) return self.list[id] end +function FighterControllerParent:getList() + return self.list +end + function FighterControllerParent:add(fighter) table.insert(self.list, fighter) end @@ -73,10 +77,6 @@ function FighterControllerParent:putActions(actionList) end end -function FighterControllerParent:draw() - --Aucun dessin par defaut, ils sont géré différements -end - function FighterControllerParent:removeFighter(fighterToRemove) -- remove the actor from the battler liste for i, fighter in ipairs(self.list) do diff --git a/sonic-radiance.love/scenes/battlesystem/fighters/player.lua b/sonic-radiance.love/scenes/battlesystem/fighters/player.lua index 6094d04..a569d21 100644 --- a/sonic-radiance.love/scenes/battlesystem/fighters/player.lua +++ b/sonic-radiance.love/scenes/battlesystem/fighters/player.lua @@ -14,17 +14,10 @@ function HeroFighterController:initHeroes() end end - function HeroFighterController:fleeBattle() for i, hero in ipairs(self.list) do hero.actor:flee() end end -function HeroFighterController:draw() - for i, hero in ipairs(self.list) do - hero:drawHUD() - end -end - return HeroFighterController diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hud.lua b/sonic-radiance.love/scenes/battlesystem/gui/hud.lua deleted file mode 100644 index 47d91a3..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/hud.lua +++ /dev/null @@ -1,98 +0,0 @@ -local HUD = Object:extend() - -local gui = require "game.modules.gui" -local TweenManager = require "birb.classes.time" -local MessageQueue = require "game.modules.messagequeue" - -local PLAYER_HUD_HIDDEN = 240+64 -local PLAYER_HUD_VISIBLE = 240-44 -local PLAYER_MESSAGE = 240 - 24 - -function HUD:new(turns) - self.turns = turns - self.scene = turns.scene - self.world = self.scene.world - self.assets = self.scene.assets - - self.frame = gui.newBorder(424, 30, 4) - self.tweens = TweenManager(self) - - self.playerHUDPosition = PLAYER_HUD_HIDDEN - self.battlerCursor = self.turns.turns.current - - self.messages = MessageQueue(self.scene) - - self.message = "Test de message" - self.messageOpacity = 0 -end - -function HUD:showMessage(message) - self.messages:addMessage(message) -end - -function HUD:update(dt) - self.tweens:update(dt) - self.messages:update(dt) -end - -function HUD:movePlayerHUD(beginBattle) - if (beginBattle) then - self.tweens:newTween(0, 0.4, {playerHUDPosition = PLAYER_HUD_VISIBLE}, 'inCubic') - else - self.tweens:newTween(0, 0.4, {playerHUDPosition = PLAYER_HUD_HIDDEN}, 'inCubic') - end -end - -function HUD:moveBattleCursor(moveCursorTo) - self.tweens:newTween(0, 0.2, {battlerCursor = moveCursorTo}, 'inCubic') -end - -function HUD:getPlayerHUDPosition() - return self.playerHUDPosition -end - -function HUD:draw() - local x, y = 4, 5 - - love.graphics.draw(self.frame, 0, 24, 0, 1, -1) - self.assets.images["hudturn"]:draw(x, y) - self.assets.fonts["hudnbrs"]:set() - local turnnbr = self.turns.turns.number - if (turnnbr < 10) then - turnnbr = "0" .. turnnbr - end - love.graphics.print(turnnbr, x + 33, y + 1) - - for i, action in ipairs(self.turns.actionList) do - if action.fighter:canFight() then - action.fighter:drawIcon(76 + (i-1)*(20), 5) - else - self:drawEmptyIcon(76 + (i-1)*(20), 5) - end - end - local cursorx = (self.battlerCursor-1) * 20 + 76 - - if #self.turns.actionList > 0 then - self.assets.images["menucursor"]:draw(cursorx, 5, math.rad(90), 1, 1, 4, 16) - end - - self.messages:draw() - love.graphics.setColor(0,0,0, 0.5 * self.messageOpacity) - love.graphics.rectangle("fill", 0, PLAYER_MESSAGE, 424, 16) - if (self.messageOpacity > 0) then - self.assets.fonts["small"]:setColor(1,1,1, self.messageOpacity) - self.assets.fonts["small"]:draw(self.message, 424/2, PLAYER_MESSAGE - 1, -1, "center") - self.assets.fonts["small"]:setColor(1,1,1, 1) - end - utils.graphics.resetColor() -end - -function HUD:drawEmptyIcon(x, y) - local outlineLight = 0.15 - love.graphics.circle("fill", x + 8, y + 8, 2, 8) - love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1) - love.graphics.circle("line", x + 8, y + 8, 2, 8) - utils.graphics.resetColor() -end - -return HUD diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua new file mode 100644 index 0000000..1485650 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/bosshpbar.lua @@ -0,0 +1,30 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local BossHpBar = GuiElement:extend() + +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local POS_X, POS_Y = 280, 28 + +function BossHpBar:new(hp) + self.hp = hp + self.baseHP = hp + self.hpbar = ComplexHPBar(120) + self.hpbar:setColorForeground(248/255, 160/255, 0, 1) + self.hpbar:setColorBackground(112/255, 0, 0) + + self.bossTexture = love.graphics.newImage("assets/gui/strings/boss.png") + local w, h = self.bossTexture:getDimensions() + + BossHpBar.super.new(self, "BossHPBar", POS_X, POS_Y, w, h) +end + +function BossHpBar:setHP(newHP) + self:newTween(0, 0.1, {hp = newHP}, 'inCubic') +end + +function BossHpBar:draw() + self.hpbar:draw(self.x, self.y, self.hp / self.baseHP) + love.graphics.draw(self.bossTexture, self.x + 98, self.y + 10) +end + +return BossHpBar \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua new file mode 100644 index 0000000..0be7f2b --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/menu.lua @@ -0,0 +1,86 @@ +local Parent = require "game.modules.gui.fancymenu" +local BattleMenu = Parent:extend() + +local defTransitions = require "birb.modules.transitions" +local radTransitions = require "game.modules.transitions" + +local MENU_X, MENU_Y = 88, 72 +local MENU_W = 180-32 +local MENU_ITEM_NUMBER = 6 + +function BattleMenu:new() + BattleMenu.super.new(self, "battleMenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, true) + self.isVisible = false +end + +function BattleMenu:rebuild(character) + self:clear() + self:addItem("Attack", "left", function() self:doAction(character, "attack") end) + self:generateSubmenu("skills", "Skill", "main", character.abstract.skills, function(data) return self:createSkillWidget(character, data) end, true) + self:createItemMenus(character) + self:switch("main") + self:addItem("Defend", "left", function() self:doAction(character, "defend") end) + self:addItem("Flee", "left", function() self:doAction(character, "flee") end) + self:getFocus() + self.canvas.needRedraw = true +end + +function BattleMenu:createItemMenus(character) + self:addSubmenu("items", "Items", "main", true) + for i,pocket in ipairs(game.loot.inventory) do + if (pocket.inBattle) then + self:generateSubmenu(pocket.name, pocket.fullname, "items", pocket.list, + function(itemInBag) + return self:createItemWidget(character, pocket.name, itemInBag) + end, true) + end + end +end + +function BattleMenu:createSkillWidget(character, skill) + local data = core.datas:get("skills", skill.name) + local isOk = (data.cost <= character.abstract.pp) + + local cost = {utils.math.numberToString(data.cost or 0, 2), "right"} + local color = utils.math.either(isOk, {1, 1, 1}, {1, 0.3, 0.3}) + local sfx = utils.math.either(isOk, "select", "error") + local func = function() self:doSkill(character, skill.name, isOk) end + + --text, position, func, type, additionnalItems, color + return character.abstract:getSkillName(skill.name), "left", func, sfx, {cost}, color +end + +function BattleMenu:createItemWidget(character, pocketName, itemInBag) + local data = core.datas:get("items", itemInBag.name) + local nbr = game.loot:getItemNumber(pocketName, itemInBag.name) + local nbrLabel = {"x" .. utils.math.numberToString(nbr, 2), "right"} + local func = function() self:useItem(character, pocketName, itemInBag.name) end + + --text, position, func, type, additionnalItems, color + return data.fullname, "left", func, "select", {nbrLabel}, {1, 1, 1} +end + + +function BattleMenu:doAction(character, action) + self:looseFocus() + self.isVisible = false + character:doBasicAction(action) +end + +function BattleMenu:useItem(character, pocketName, item) + self:looseFocus() + self.isVisible = false + character:useItem(pocketName, item) +end + +function BattleMenu:doSkill(character, skill, isOk) + if (isOk) then + self:looseFocus() + character:useSkill(skill) + self.isVisible = false + else + self.scene:showMessage("You haven't enough PP!") + end +end + +return BattleMenu diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua new file mode 100644 index 0000000..2754ebe --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua @@ -0,0 +1,68 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local StatusBar = GuiElement:extend() +local TweenManager = require "birb.classes.time" + +local Emblem = require "game.modules.gui.emblem" +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local DIST_STATUSBAR = 106 +local Y = 200 +local STATUSBAR_W = 90 + +function StatusBar:new(fighter, i) + self:initAbstract(fighter) + StatusBar.super.new(self, self.abstract.name .. "StatutBar", (i-0.5)*DIST_STATUSBAR-(STATUSBAR_W/2), Y, STATUSBAR_W, 64) + self:createParts(self.scene) +end + +function StatusBar:initAbstract(fighter) + self.abstract = fighter.abstract + self.hp = self.abstract.hp + self.pp = self.abstract.pp + self.stats = self.abstract:getStats() +end + +function StatusBar:createParts(scene) + self.emblem = Emblem(self.abstract, scene) + + self.hpbar = ComplexHPBar(58) + self.ppbar = ComplexHPBar(58) + self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1) + self.hpbar:setColorBackground(112 / 255, 0, 0) + self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1) + self.ppbar:setColorBackground(0, 54 / 255, 229 / 255) +end + +function StatusBar:updateHP() + self.tweens:newTween(0, 0.3, {hp = self.abstract.hp}, "linear") +end + +function StatusBar:updatePP() + self.tweens:newTween(0, 0.3, {pp = self.abstract.pp}, "linear") +end + +function StatusBar:draw() + self.emblem:drawBackground(self.x, self.y) + self:drawStatusArea(self.x + 10, self.y - 8) + self.emblem:drawForeground(self.x, self.y) +end + +function StatusBar:drawStatusArea(x, y) + self.assets.images["statusbar"]:draw(x, y) + + local hpmax = self.stats:get(self.stats.HPMAX) + local ppmax = self.stats:get(self.stats.PPMAX) + + self.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(x + 6, y + 9, self.hp, hpmax) + self.ppbar:drawWithLabels(x + 18, y + 21, self.pp, ppmax) + + local lvl = self.abstract.level + + if lvl < 100 then + lvl = "0" .. lvl + end + love.graphics.print(lvl, x + 42, y + 1) +end + +return StatusBar diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua new file mode 100644 index 0000000..2618d2d --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/turnbar.lua @@ -0,0 +1,27 @@ +local Parent = require "birb.modules.gui.elements.parent" +local TurnBar = Parent:extend() + +local gui = require "game.modules.gui" + +function TurnBar:new() + TurnBar.super.new(self, "turnbar", 76, 5, 1, 1) + self.turns = self.scene.turns + self.cursor = self.turns.turns.current +end + +function TurnBar:draw() + for i, action in ipairs(self.turns.actionList) do + if action.fighter:canFight() then + action.fighter:drawIcon(self.x + (i-1)*(20), self.y) + else + gui.drawEmptyIcon(self.x + (i-1)*(20), self.y) + end + end + local cursorx = (self.cursor-1) * 20 + + if #self.turns.actionList > 0 then + self.assets.images["menucursor"]:draw(self.x + cursorx, self.y, math.rad(90), 1, 1, 4, 16) + end +end + +return TurnBar \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/init.lua b/sonic-radiance.love/scenes/battlesystem/gui/init.lua new file mode 100644 index 0000000..9302615 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/gui/init.lua @@ -0,0 +1,42 @@ +local GuiScreen = require "birb.modules.gui.screen" +local CbsScreen = GuiScreen:extend() + +local StatutBar = require "scenes.battlesystem.gui.hudelements.statutbar" +local TurnBar = require "scenes.battlesystem.gui.hudelements.turnbar" +local BattleMenu = require "scenes.battlesystem.gui.hudelements.menu" + +local Composite = require "birb.modules.gui.elements.composite" +local Counter = require "birb.modules.gui.elements.counter" +local Asset = require "birb.modules.gui.elements.assets" + +local show = { + {"turns", "movement", 0.5, 0.6, 424/2, 80, "inOutQuart"}, +} + +function CbsScreen:new() + CbsScreen.super.new(self, "hud") + self:show() +end + +function CbsScreen:buildMenu(character) + self.elements["battleMenu"]:rebuild(character) +end + +function CbsScreen:createElements() + local turns = self.scene.turns + local list = { + {Composite("turns", 10, 10, { + {Asset("turnImg", "images", "hudturn", -1, -1), 0, 0}, + {Counter("turnCnt", "hudnbrs", turns.turns, "number", 2, -1, -1), 33, 1}, + {TurnBar(), 62, -3}, + }), 0}, + {BattleMenu(), 0} + } + for i, fighter in ipairs(turns.player:getList()) do + table.insert(list, {StatutBar(fighter, i), 0}) + end + + return list +end + +return CbsScreen \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua deleted file mode 100644 index df60247..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/battlemenu.lua +++ /dev/null @@ -1,19 +0,0 @@ -local fancy = require "game.modules.menus.fancy" - -local BattleMenu = fancy.FancyMenu:extend() - -local MENUPOS_X1, MENUPOS_Y = 88, 72 -local MENU_WIDTH = 180-32 -local MENU_ITEM_NUMBER = 6 - -function BattleMenu:new(scene, name) - local x, y = MENUPOS_X1, MENUPOS_Y - local w = MENU_WIDTH - BattleMenu.super.new(self, scene, name, x, y, w, MENU_ITEM_NUMBER, true) -end - -function BattleMenu:clone(name) - return BattleMenu(self.scene, name) -end - -return BattleMenu diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua deleted file mode 100644 index 2d47122..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/controller.lua +++ /dev/null @@ -1,72 +0,0 @@ -local MenuConstructor = Object:extend() -local CharacterMenu = require "scenes.battlesystem.gui.menus.battlemenu" -local widgets = require "scenes.battlesystem.gui.menus.widgets" - -function MenuConstructor:new( controller ) - self.scene = controller -end - -function MenuConstructor:reconstruct(character) - core.debug:print("cbs/menu", "Reconstructing the menu") - self.scene.menusystem:reset() - self:build(character) - - self.scene.menusystem:switchMenu("BaseMenu") -end - -function MenuConstructor:build(character) - core.debug:print("cbs/menu", "Building the menu") - self:buildBaseMenu(character) - self:buildSkillMenu(character) - self:buildObjectMenu(character) - - self.scene.menusystem.menus["BaseMenu"]:finalize() - self.scene.menusystem:setSoundFromSceneAssets("mBeep") - self.scene.menusystem:activate() -end - -function MenuConstructor:buildBaseMenu(character) - CharacterMenu(self.scene, "BaseMenu") - widgets.ActionWidget(character, "BaseMenu", "attack", "Attack") - self:addSubMenu("BaseMenu", "SkillMenu", "Skills") - self:addSubMenu("BaseMenu", "ObjectMenu", "Objects") - widgets.ActionWidget(character, "BaseMenu", "defend", "Defend") - widgets.ActionWidget(character, "BaseMenu", "flee", "Flee") -end - -function MenuConstructor:set(currentCharacter) - self:reconstruct(currentCharacter) -end - -function MenuConstructor:buildSkillMenu(character) - local list = character.abstract.skills - for k, skill in pairs(list) do - widgets.SkillWidget(character, "SkillMenu", skill.name, "") - end - --SubMenuWidget(character, "SkillMenu", "back", "BaseMenu") - - self.scene.menusystem.menus["SkillMenu"]:setCancelWidget() -end - -function MenuConstructor:buildObjectMenu(character) - for i,pocket in ipairs(game.loot.inventory) do - if (pocket.inBattle) then - CharacterMenu(self.scene, pocket.name) - self:addSubMenu("ObjectMenu", pocket.name, pocket.fullname) - for j,itemData in ipairs(pocket.list) do - widgets.ItemWidget(character, pocket.name, itemData.name) - end - end - end - self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget() -end - -function MenuConstructor:addSubMenu(menu, submenu, widgetName) - self.scene.menusystem.menus[menu]:addSubMenu(submenu, widgetName) -end - -function MenuConstructor:unset( ) - self.isActive = false -end - -return MenuConstructor diff --git a/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua b/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua deleted file mode 100644 index 7510b0a..0000000 --- a/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua +++ /dev/null @@ -1,164 +0,0 @@ -local fancy = require "game.modules.menus.fancy" - -local widgets = {} - -widgets.BattleWidget = fancy.BaseWidget:extend() -widgets.ActionWidget = widgets.BattleWidget:extend() -widgets.SubMenuWidget = widgets.BattleWidget:extend() -widgets.BackMenuWidget = widgets.BattleWidget:extend() -widgets.SkillWidget = widgets.BattleWidget:extend() -widgets.ItemWidget = widgets.BattleWidget:extend() - --- WIDGETS --- All widgets used by the Characters menus - --- Basic Battle Widget --- The base used by all battle widgets - -function widgets.BattleWidget:new(character, menu_name, label1, label2) - local label1 = label1 or "" - local label2 = label2 or "" - - self.character = character - local scene = self.character.turnSystem.scene - - widgets.BattleWidget.super.new(self, scene, menu_name, label1, label2) - self.assets = self.scene.assets -end - --- Internal functions - -function widgets.BattleWidget:selectAction() - -- Rien de base, à voir ensuite comment je gère -end - -function widgets.BattleWidget:action() - self.scene:flushKeys() - self.scene.menusystem:deactivate() - - self:sendCharacterData() -end - --- External functions - -function widgets.BattleWidget:sendCharacterData() - self.character:doNothing() -end - --- ActionWidget --- The basic action widget - -function widgets.ActionWidget:new(character, menu_name, action, label) - self.actionType = action or "" - local label = label or self.actionType - widgets.ActionWidget.super.new(self, character, menu_name, label, "") -end - -function widgets.ActionWidget:sendCharacterData() - self.character:doBasicAction(self.actionType) -end - --- SubMenuWidget --- A simple widget to change menu - -function widgets.SubMenuWidget:new(character, menu_name, label, newmenu) - local label2 = "" - self.sfx = "mBack" - if label ~= "back" then - label2 = ">" - self.sfx = "mBeep" - end - widgets.SubMenuWidget.super.new(self, character, menu_name, label, label2) - self.newmenu = newmenu or "BaseMenu" -end - -function widgets.SubMenuWidget:action() - self.assets.sfx[self.sfx]:play() - self.scene.menusystem:switchMenu(self.newmenu) -end - --- BackMenuWidget --- Quit the menu - -function widgets.BackMenuWidget:new(character, menu_name) - widgets.BackMenuWidget.super.new(self, character, menu_name, "back", "") -end - -function widgets.BackMenuWidget:sendCharacterData() - self.assets.sfx["mBack"]:play() - self.character:receiveBackSignal() -end - --- SkillWidget --- A widget to handle skills - -function widgets.SkillWidget:new(character, menu_name, skill) - self.skillname = skill - local label2 = "00" - - self.skilldata = core.datas:get("skills", skill) - - if self.skilldata ~= nil then - label2 = self.skilldata.cost or 0 - if label2 < 10 then - label2 = "0" .. label2 - end - end - local color = {1, 1, 1} - if (self.skilldata.cost > character.abstract.pp) then - color = {1, 0.3, 0.3} - end - local fullName = self:getFullName(character) - - widgets.SkillWidget.super.new(self, character, menu_name, fullName, "-" .. label2, "skills") - self.color = color -end - -function widgets.SkillWidget:getFullName(character) - if (self.skilldata.altName == nil) then - return self.skilldata.fullname - end - if (self.skilldata.altName[character.abstract.simplename] ~= nil) then - return self.skilldata.altName[character.abstract.simplename] - else - return self.skilldata.fullname - end -end - -function widgets.SkillWidget:sendCharacterData() - - if (self.skilldata ~= nil and self.skilldata.cost <= self.character.abstract.pp) then - self.assets.sfx["mSelect"]:play() - self.character:useSkill(self.skillname) - else - core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist") - self.character:doNothing() - self.assets.sfx["mError"]:play() - self.scene:showMessage("You haven't enough PP!") - end - -end - --- ItemWidget --- A widget to handle items - -function widgets.ItemWidget:new(character, menu_name, item) - self.category = menu_name - self.itemname = item - local label2 = "00" - - self.number = game.loot:getItemNumber(menu_name, item) - self.itemdata = core.datas:get("items", item) - - label2 = self.number - - widgets.ItemWidget.super.new(self, character, menu_name, self.itemdata.fullname, "x" .. label2, "skills") -end - -function widgets.ItemWidget:sendCharacterData() - self.character:useItem(self.category, self.itemname) - self.assets.sfx["mBeep"]:play() -end - - -return widgets diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 347e6c1..88edf61 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -3,12 +3,13 @@ local Scene = require "game.scenes" local BattleSystem = Scene:extend() local World = require "scenes.battlesystem.world" -local MenuSystem = require "scenes.battlesystem.gui.menus.controller" local Turns = require "scenes.battlesystem.turns" local VictoryScreen = require "scenes.battlesystem.gui.screens.victory" local GameOverScreen = require "game.modules.gui.gameover" +local CbsScreen = require "scenes.battlesystem.gui" + local TweenManager = require "birb.classes.time" function BattleSystem:new(battleData) @@ -20,6 +21,8 @@ function BattleSystem:new(battleData) self:initManagers(battleData) self:startBattle() + CbsScreen() + self.screen = nil self.tweens = TweenManager(self) end @@ -32,7 +35,6 @@ end function BattleSystem:initManagers(battleData) self.datas = {} self.world = World(self) - self.menu = MenuSystem(self) self.turns = Turns(self, battleData) end @@ -66,10 +68,7 @@ function BattleSystem:looseBattle() end function BattleSystem:haveMenus() - for k,v in pairs(self.menusystem.menus) do - return true - end - return false + return self.gui.elements["battleMenu"].isVisible end function BattleSystem:update(dt) diff --git a/sonic-radiance.love/scenes/battlesystem/turns.lua b/sonic-radiance.love/scenes/battlesystem/turns.lua index e4f61de..f6e583f 100644 --- a/sonic-radiance.love/scenes/battlesystem/turns.lua +++ b/sonic-radiance.love/scenes/battlesystem/turns.lua @@ -3,8 +3,6 @@ local TurnController = Object:extend() local Player = require "scenes.battlesystem.fighters.player" local Ennemy = require "scenes.battlesystem.fighters.ennemies" -local HUD = require "scenes.battlesystem.gui.hud" - local maputils = require "scenes.battlesystem.utils" function TurnController:new(scene, battleData) @@ -26,7 +24,7 @@ function TurnController:new(scene, battleData) self.canFleeBattle = true - self.hud = HUD(self) + self.gui = self.scene.gui self.player = Player(self) self.ennemies = Ennemy(self, battleData) @@ -49,33 +47,25 @@ function TurnController:fleeBattle() self.scene:fleeBattle() end -function TurnController:showMessage(message) - self.hud:showMessage(message) -end - function TurnController:startBattle() self.isActive = true - self.hud:movePlayerHUD(true) end function TurnController:finishBattle() self.isActive = false self.actionlist = {} - self.hud:movePlayerHUD(false) self.scene:finishBattle() end function TurnController:looseBattle() self.isActive = false self.actionlist = {} - self.hud:movePlayerHUD(false) self.scene:looseBattle() end function TurnController:update(dt) self.player:update(dt) self.ennemies:update(dt) - self.hud:update(dt) if (self.isActive) then if (self.currentFighter ~= nil) then self.currentFighter:update(dt) @@ -156,7 +146,7 @@ function TurnController:startAction() self.currentFighter = nextFighter core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name) self.currentFighter:setActive() - self.hud:moveBattleCursor(self.turns.current) + self.gui:newTween("turnbar", 0, 0.2, {cursor = self.turns.current}, 'inCubic') end end @@ -168,11 +158,4 @@ function TurnController:sendSignalToCurrentBattler(signal, subSignal) self.actionList[self.turns.current].actor:receiveSignal(signal, subSignal) end -function TurnController:draw() - self.player:draw() - self.ennemies:draw() - self.hud:draw() -end - - return TurnController