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
18 changed files with 277 additions and 523 deletions
Showing only changes of commit 2932a7d85a - Show all commits

View file

@ -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

View file

@ -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

View file

@ -1,28 +1,21 @@
local FighterParent = require "scenes.battlesystem.fighters.fighter" local FighterParent = require "scenes.battlesystem.fighters.fighter"
local HeroFighter = FighterParent:extend() local HeroFighter = FighterParent:extend()
local StatusBar = require "game.modules.gui.statusbar"
local SelectionSystem = require "scenes.battlesystem.fighters.character.selection" local SelectionSystem = require "scenes.battlesystem.fighters.character.selection"
local actionList = require "scenes.battlesystem.fighters.character.actions" local actionList = require "scenes.battlesystem.fighters.character.actions"
local HEROES_LINE = 2; local HEROES_LINE = 2;
local HUDSIZE = 91
function HeroFighter:new(owner, character, id) function HeroFighter:new(owner, character, id)
self.name = character self.name = character
self.super.new(self, owner, true, id) self.super.new(self, owner, true, id)
self.statusbar = StatusBar(self.abstract, self.turnSystem.scene)
self:initVoices() self:initVoices()
self.selection = nil self.selection = nil
self.exp = self.abstract.exp self.exp = self.abstract.exp
end end
function HeroFighter:updateAssets(dt)
self.statusbar:update(dt)
end
function HeroFighter:update(dt) function HeroFighter:update(dt)
HeroFighter.super.update(self, dt) HeroFighter.super.update(self, dt)
if (self.selection ~= nil) then if (self.selection ~= nil) then
@ -47,7 +40,7 @@ function HeroFighter:startAction()
core.debug:print("cbs/heroFighter", "launching the action menu") core.debug:print("cbs/heroFighter", "launching the action menu")
self.action = nil self.action = nil
self:talk("turnstart") self:talk("turnstart")
self.turnSystem.scene.menu:set( self ) self.turnSystem.scene.gui.screens["hud"]:buildMenu( self )
end end
function HeroFighter:endAction() function HeroFighter:endAction()
@ -102,17 +95,19 @@ function HeroFighter:receiveTarget(target)
end end
function HeroFighter:goBackToMenu() function HeroFighter:goBackToMenu()
self.owner.turnSystem.scene.menusystem:activate() self.turnSystem.scene.gui:setFocus("battleMenu")
self.selection = nil self.selection = nil
end end
-- LIFE functions -- LIFE functions
function HeroFighter:updatePP() function HeroFighter:updatePP()
self.statusbar:updatePP() local elem = self.turnSystem.scene.gui:getElement(self.abstract.name .. "StatutBar")
elem:updatePP()
end end
function HeroFighter:updateHP() function HeroFighter:updateHP()
self.statusbar:updateHP() local elem = self.turnSystem.scene.gui:getElement(self.abstract.name .. "StatutBar")
elem:updateHP()
end end
-- VOICE SYSTEM -- VOICE SYSTEM
@ -139,14 +134,4 @@ function HeroFighter:drawIcon(x, y)
self.assets.tileset["charicons"]:drawTile(iconID, x, y) self.assets.tileset["charicons"]:drawTile(iconID, x, y)
end 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 return HeroFighter

View file

@ -46,12 +46,7 @@ function EnnemyController:addBoss(ennData)
boss:setCheapEffect(ennData.cheapEffect) boss:setCheapEffect(ennData.cheapEffect)
self.turnSystem.canFleeBattle = false self.turnSystem.canFleeBattle = false
self:add(boss) self:add(boss)
end boss:createHPBar()
function EnnemyController:draw()
for i, villain in ipairs(self.list) do
villain:drawHUD()
end
end end
return EnnemyController return EnnemyController

View file

@ -2,11 +2,10 @@ local FighterParent = require "scenes.battlesystem.fighters.fighter"
local VillainFighter = FighterParent:extend() local VillainFighter = FighterParent:extend()
local SimpleHPBar = require "game.modules.gui.simplehpbar" 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 EnnemyAction = require "scenes.battlesystem.fighters.ennemy.action"
local behaviourList = require "scenes.battlesystem.fighters.ennemy.behaviours" local behaviourList = require "scenes.battlesystem.fighters.ennemy.behaviours"
local POSITIONS = {1, 3, 5} local POSITIONS = {1, 3, 5}
local ENNEMY_LINE = 11; local ENNEMY_LINE = 11;
@ -25,11 +24,6 @@ end
function VillainFighter:updateAssets(dt) function VillainFighter:updateAssets(dt)
self.hpbar:update(dt) self.hpbar:update(dt)
if (self.bossHpBar ~= nil) then
self.bossHpBar:update(dt)
else
self.bossHpBar = BossHPBar(self.abstract.hp)
end
end end
function VillainFighter:getAbstract() function VillainFighter:getAbstract()
@ -90,7 +84,9 @@ end
function VillainFighter:setHP(value, relative) function VillainFighter:setHP(value, relative)
VillainFighter.super.setHP(self, value, relative) VillainFighter.super.setHP(self, value, relative)
self.hpbar:setHP(self.abstract.hp) 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 end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
@ -107,10 +103,8 @@ function VillainFighter:drawOversprite(x, y)
end end
end end
function VillainFighter:drawHUD() function VillainFighter:createHPBar()
if (self.isBoss and self.bossHpBar ~= nil) then self.bossHpBar = BossHPBar(self.abstract.hp)
self.bossHpBar:draw(280, 28)
end
end end
return VillainFighter return VillainFighter

View file

@ -10,6 +10,10 @@ function FighterControllerParent:get(id)
return self.list[id] return self.list[id]
end end
function FighterControllerParent:getList()
return self.list
end
function FighterControllerParent:add(fighter) function FighterControllerParent:add(fighter)
table.insert(self.list, fighter) table.insert(self.list, fighter)
end end
@ -73,10 +77,6 @@ function FighterControllerParent:putActions(actionList)
end end
end end
function FighterControllerParent:draw()
--Aucun dessin par defaut, ils sont géré différements
end
function FighterControllerParent:removeFighter(fighterToRemove) function FighterControllerParent:removeFighter(fighterToRemove)
-- remove the actor from the battler liste -- remove the actor from the battler liste
for i, fighter in ipairs(self.list) do for i, fighter in ipairs(self.list) do

View file

@ -14,17 +14,10 @@ function HeroFighterController:initHeroes()
end end
end end
function HeroFighterController:fleeBattle() function HeroFighterController:fleeBattle()
for i, hero in ipairs(self.list) do for i, hero in ipairs(self.list) do
hero.actor:flee() hero.actor:flee()
end end
end end
function HeroFighterController:draw()
for i, hero in ipairs(self.list) do
hero:drawHUD()
end
end
return HeroFighterController return HeroFighterController

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -3,12 +3,13 @@ local Scene = require "game.scenes"
local BattleSystem = Scene:extend() local BattleSystem = Scene:extend()
local World = require "scenes.battlesystem.world" local World = require "scenes.battlesystem.world"
local MenuSystem = require "scenes.battlesystem.gui.menus.controller"
local Turns = require "scenes.battlesystem.turns" local Turns = require "scenes.battlesystem.turns"
local VictoryScreen = require "scenes.battlesystem.gui.screens.victory" local VictoryScreen = require "scenes.battlesystem.gui.screens.victory"
local GameOverScreen = require "game.modules.gui.gameover" local GameOverScreen = require "game.modules.gui.gameover"
local CbsScreen = require "scenes.battlesystem.gui"
local TweenManager = require "birb.classes.time" local TweenManager = require "birb.classes.time"
function BattleSystem:new(battleData) function BattleSystem:new(battleData)
@ -20,6 +21,8 @@ function BattleSystem:new(battleData)
self:initManagers(battleData) self:initManagers(battleData)
self:startBattle() self:startBattle()
CbsScreen()
self.screen = nil self.screen = nil
self.tweens = TweenManager(self) self.tweens = TweenManager(self)
end end
@ -32,7 +35,6 @@ end
function BattleSystem:initManagers(battleData) function BattleSystem:initManagers(battleData)
self.datas = {} self.datas = {}
self.world = World(self) self.world = World(self)
self.menu = MenuSystem(self)
self.turns = Turns(self, battleData) self.turns = Turns(self, battleData)
end end
@ -66,10 +68,7 @@ function BattleSystem:looseBattle()
end end
function BattleSystem:haveMenus() function BattleSystem:haveMenus()
for k,v in pairs(self.menusystem.menus) do return self.gui.elements["battleMenu"].isVisible
return true
end
return false
end end
function BattleSystem:update(dt) function BattleSystem:update(dt)

View file

@ -3,8 +3,6 @@ local TurnController = Object:extend()
local Player = require "scenes.battlesystem.fighters.player" local Player = require "scenes.battlesystem.fighters.player"
local Ennemy = require "scenes.battlesystem.fighters.ennemies" local Ennemy = require "scenes.battlesystem.fighters.ennemies"
local HUD = require "scenes.battlesystem.gui.hud"
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
function TurnController:new(scene, battleData) function TurnController:new(scene, battleData)
@ -26,7 +24,7 @@ function TurnController:new(scene, battleData)
self.canFleeBattle = true self.canFleeBattle = true
self.hud = HUD(self) self.gui = self.scene.gui
self.player = Player(self) self.player = Player(self)
self.ennemies = Ennemy(self, battleData) self.ennemies = Ennemy(self, battleData)
@ -49,33 +47,25 @@ function TurnController:fleeBattle()
self.scene:fleeBattle() self.scene:fleeBattle()
end end
function TurnController:showMessage(message)
self.hud:showMessage(message)
end
function TurnController:startBattle() function TurnController:startBattle()
self.isActive = true self.isActive = true
self.hud:movePlayerHUD(true)
end end
function TurnController:finishBattle() function TurnController:finishBattle()
self.isActive = false self.isActive = false
self.actionlist = {} self.actionlist = {}
self.hud:movePlayerHUD(false)
self.scene:finishBattle() self.scene:finishBattle()
end end
function TurnController:looseBattle() function TurnController:looseBattle()
self.isActive = false self.isActive = false
self.actionlist = {} self.actionlist = {}
self.hud:movePlayerHUD(false)
self.scene:looseBattle() self.scene:looseBattle()
end end
function TurnController:update(dt) function TurnController:update(dt)
self.player:update(dt) self.player:update(dt)
self.ennemies:update(dt) self.ennemies:update(dt)
self.hud:update(dt)
if (self.isActive) then if (self.isActive) then
if (self.currentFighter ~= nil) then if (self.currentFighter ~= nil) then
self.currentFighter:update(dt) self.currentFighter:update(dt)
@ -156,7 +146,7 @@ function TurnController:startAction()
self.currentFighter = nextFighter self.currentFighter = nextFighter
core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name) core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name)
self.currentFighter:setActive() self.currentFighter:setActive()
self.hud:moveBattleCursor(self.turns.current) self.gui:newTween("turnbar", 0, 0.2, {cursor = self.turns.current}, 'inCubic')
end end
end end
@ -168,11 +158,4 @@ function TurnController:sendSignalToCurrentBattler(signal, subSignal)
self.actionList[self.turns.current].actor:receiveSignal(signal, subSignal) self.actionList[self.turns.current].actor:receiveSignal(signal, subSignal)
end end
function TurnController:draw()
self.player:draw()
self.ennemies:draw()
self.hud:draw()
end
return TurnController return TurnController