fix: adapt the menu system to the new concept

This commit is contained in:
Kazhnuz 2020-07-19 18:09:53 +02:00
parent 6bca41d794
commit f3cfaf9ac2
4 changed files with 41 additions and 121 deletions

View file

@ -17,6 +17,10 @@ function HeroFighter:updateAssets(dt)
self.statusbar:update(dt) self.statusbar:update(dt)
end end
function HeroFighter:update(dt)
end
function HeroFighter:getAbstract() function HeroFighter:getAbstract()
return game.characters.list[self.name] return game.characters.list[self.name]
end end
@ -27,13 +31,19 @@ function HeroFighter:createActor()
end end
function HeroFighter:startAction() function HeroFighter:startAction()
core.debug:print("cbs/heroFighter", "launching the action menu")
self.turnSystem.scene.menu:set( self )
end end
function HeroFighter:endAction() function HeroFighter:endAction()
end end
-- Basic actions
function HeroFighter:doNothing()
self:setInactive()
end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
function HeroFighter:drawIcon(x, y) function HeroFighter:drawIcon(x, y)
local iconID = 1 local iconID = 1

View file

@ -47,7 +47,7 @@ end
function FighterParent:setInactive() function FighterParent:setInactive()
self.isActive = false self.isActive = false
self.turnSystem:nextAction() self.turnSystem:endAction()
end end
function FighterParent:getNbrActionPerTurn() function FighterParent:getNbrActionPerTurn()

View file

@ -106,7 +106,7 @@ function TurnController:startAction()
end end
function TurnController:endAction() function TurnController:endAction()
self.currentlyPlaying = "" self.currentFighter = nil
end end
function TurnController:sendSignalToCurrentBattler(signal, subSignal) function TurnController:sendSignalToCurrentBattler(signal, subSignal)

View file

@ -15,34 +15,33 @@ local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
local MENU_ITEM_NUMBER = 6 local MENU_ITEM_NUMBER = 6
function MenuConstructor:new( controller ) function MenuConstructor:new( controller )
self.controller = controller self.scene = controller
end end
function MenuConstructor:reconstruct(character) function MenuConstructor:reconstruct(character)
self.controller.menusystem:reset() core.debug:print("cbs/menu", "Reconstructing the menu")
self.scene.menusystem:reset()
self:build(character) self:build(character)
self.controller.menusystem:switchMenu("BaseMenu") self.scene.menusystem:switchMenu("BaseMenu")
end end
function MenuConstructor:build(character) function MenuConstructor:build(character)
core.debug:print("cbs/menu", "Building the menu")
self:buildBaseMenu(character) self:buildBaseMenu(character)
self:buildSkillMenu(character) self:buildSkillMenu(character)
self:buildObjectMenu(character) self:buildObjectMenu(character)
self.controller.menusystem:setSoundFromSceneAssets("mBeep") self.scene.menusystem:setSoundFromSceneAssets("mBeep")
end end
function MenuConstructor:buildBaseMenu(character) function MenuConstructor:buildBaseMenu(character)
CharacterMenu(self.controller, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
ActionWidget(character, "BaseMenu", "attack") ActionWidget(character, "BaseMenu", "attack")
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu") SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu") SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
ActionWidget(character, "BaseMenu", "defend") ActionWidget(character, "BaseMenu", "defend")
ActionWidget(character, "BaseMenu", "flee") ActionWidget(character, "BaseMenu", "flee")
BackMenuWidget(character, "BaseMenu")
self.controller.menusystem.menus["BaseMenu"]:setCancelWidget()
end end
function MenuConstructor:set(currentCharacter) function MenuConstructor:set(currentCharacter)
@ -50,23 +49,23 @@ function MenuConstructor:set(currentCharacter)
end end
function MenuConstructor:buildSkillMenu(character) function MenuConstructor:buildSkillMenu(character)
CharacterMenu(self.controller, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y)
local list = game.characters:getSkillList(character.charid) local list = character.abstract.skills
for k, skill in pairs(list) do for k, skill in pairs(list) do
SkillWidget(character, "SkillMenu", skill.name, "") SkillWidget(character, "SkillMenu", skill.name, "")
end end
SubMenuWidget(character, "SkillMenu", "back", "BaseMenu") SubMenuWidget(character, "SkillMenu", "back", "BaseMenu")
self.controller.menusystem.menus["SkillMenu"]:setCancelWidget() self.scene.menusystem.menus["SkillMenu"]:setCancelWidget()
end end
function MenuConstructor:buildObjectMenu(character) function MenuConstructor:buildObjectMenu(character)
CharacterMenu(self.controller, "ObjectMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "ObjectMenu", MENUPOS_X1 - 16, MENUPOS_Y)
CharacterMenu(self.controller, "MedMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "MedMenu", MENUPOS_X1 - 16, MENUPOS_Y)
CharacterMenu(self.controller, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y)
CharacterMenu(self.controller, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y)
CharacterMenu(self.controller, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y) CharacterMenu(self.scene, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y)
SubMenuWidget(character, "ObjectMenu", "heal", "MedMenu") SubMenuWidget(character, "ObjectMenu", "heal", "MedMenu")
@ -81,12 +80,12 @@ function MenuConstructor:buildObjectMenu(character)
SubMenuWidget(character, "OtherMenu", "back", "ObjectMenu") SubMenuWidget(character, "OtherMenu", "back", "ObjectMenu")
self.controller.menusystem.menus["ObjectMenu"]:setCancelWidget() self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget()
self.controller.menusystem.menus["MedMenu"]:setCancelWidget() self.scene.menusystem.menus["MedMenu"]:setCancelWidget()
self.controller.menusystem.menus["RingMenu"]:setCancelWidget() self.scene.menusystem.menus["RingMenu"]:setCancelWidget()
self.controller.menusystem.menus["WispMenu"]:setCancelWidget() self.scene.menusystem.menus["WispMenu"]:setCancelWidget()
self.controller.menusystem.menus["OtherMenu"]:setCancelWidget() self.scene.menusystem.menus["OtherMenu"]:setCancelWidget()
end end
@ -149,7 +148,7 @@ end
function BattleWidget:getControllers(character, menu_name) function BattleWidget:getControllers(character, menu_name)
self.character = character or core.debug:error("cbs/widget", "character must not be nil") self.character = character or core.debug:error("cbs/widget", "character must not be nil")
self.scene = self.character.scene self.scene = self.character.turnSystem.scene
self.assets = self.character.assets self.assets = self.character.assets
self.menusystem = self.scene.menusystem self.menusystem = self.scene.menusystem
@ -167,26 +166,7 @@ function BattleWidget:update(dt)
end end
function BattleWidget:selectAction() function BattleWidget:selectAction()
self:setActiveGrid() -- Rien de base, à voir ensuite comment je gère
self:setEffectGrid()
end
function BattleWidget:setActiveGrid()
if (self:haveActiveGrid()) then
local ox, oy, shape, size, idk = self:getActiveGrid()
self.scene.world:setActiveGrid(ox, oy, shape, size, idk)
else
self.scene.world:resetActiveGrid()
end
end
function BattleWidget:setEffectGrid()
if (self:haveEffectGrid()) then
local ox, oy, shape, size, idk = self:getEffectGrid()
self.scene.world:setEffectGrid(ox, oy, shape, size, idk)
else
self.scene.world:resetEffectGrid()
end
end end
function BattleWidget:drawCanvas() function BattleWidget:drawCanvas()
@ -217,9 +197,6 @@ function BattleWidget:drawCanvas()
end end
function BattleWidget:action() function BattleWidget:action()
self.scene.world:resetActiveGrid()
self.scene.world:resetEffectGrid()
self:sendCharacterData() self:sendCharacterData()
self.scene:flushKeys() self.scene:flushKeys()
@ -228,24 +205,8 @@ end
-- External functions -- External functions
function BattleWidget:haveActiveGrid()
return false
end
function BattleWidget:getActiveGrid()
return 0, 0, "point", 0, 0
end
function BattleWidget:haveEffectGrid()
return false
end
function BattleWidget:getEffectGrid()
return 0, 0, "point", 0, 0
end
function BattleWidget:sendCharacterData() function BattleWidget:sendCharacterData()
self.character:receiveSignal() self.character:doNothing()
end end
-- ActionWidget -- ActionWidget
@ -256,16 +217,8 @@ function ActionWidget:new(character, menu_name, action)
ActionWidget.super.new(self, character, menu_name, action, "") ActionWidget.super.new(self, character, menu_name, action, "")
end end
function ActionWidget:haveEffectGrid()
return (self.actionType == "attack")
end
function ActionWidget:getEffectGrid()
return self.character.x + self.character.direction, self.character.y, "point", 1, 1
end
function ActionWidget:sendCharacterData() function ActionWidget:sendCharacterData()
self.character:receiveSignal(self.actionType) self.character:doNothing()
end end
-- SubMenuWidget -- SubMenuWidget
@ -318,58 +271,15 @@ function SkillWidget:new(character, menu_name, skill)
SkillWidget.super.new(self, character, menu_name, self.skillname, "-" .. label2, "skills") SkillWidget.super.new(self, character, menu_name, self.skillname, "-" .. label2, "skills")
end end
function SkillWidget:selectAction()
if self.skilldata ~= nil then
SkillWidget.super.selectAction(self)
else
self.scene.world:resetActiveGrid()
self.scene.world:resetEffectGrid()
end
end
function SkillWidget:haveActiveGrid()
return (self.skilldata.target ~= nil)
end
function SkillWidget:haveEffectGrid()
return ((self.skilldata.target == nil) and (self.skilldata.effectArea ~= nil))
end
function SkillWidget:getActiveGrid()
local x = self.character.x + self.skilldata.target[1]
local y = self.character.y + self.skilldata.target[2]
local shape = self.skilldata.target[3]
local size = self.skilldata.target[4]
local direction = self.character.direction
return x, y, shape, size, direction
end
function SkillWidget:getEffectGrid()
local x = self.character.x + self.skilldata.effectArea[1]
local y = self.character.y + self.skilldata.effectArea[2]
local shape = self.skilldata.effectArea[3]
local size = self.skilldata.effectArea[4]
local direction = self.character.direction
return x, y, shape, size, direction
end
function SkillWidget:sendCharacterData() function SkillWidget:sendCharacterData()
if self.skilldata ~= nil then if self.skilldata ~= nil then
if self:haveActiveGrid() then self.assets.sfx["mSelect"]:play()
local x, y, shape, size, direction = self:getActiveGrid() self.character:doNothing()
self.scene.world.cursor:setGridIgnoreActor(x, y, shape, size, direction) --self.character:useSkill(self.skillname, self.character.x, self.character.y)
self.scene.world.cursor:set(self.character.x, self.character.y, "skill", self.skillname)
self.assets.sfx["mSelect"]:play()
else
self.assets.sfx["mSelect"]:play()
self.character:useSkill(self.skillname, self.character.x, self.character.y)
end
else else
core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist") core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist")
self.character:receiveSignal("none") self.character:doNothing()
self.assets.sfx["mError"]:play() self.assets.sfx["mError"]:play()
end end