fix: adapt the menu system to the new concept
This commit is contained in:
parent
6bca41d794
commit
f3cfaf9ac2
4 changed files with 41 additions and 121 deletions
|
@ -17,6 +17,10 @@ function HeroFighter:updateAssets(dt)
|
|||
self.statusbar:update(dt)
|
||||
end
|
||||
|
||||
function HeroFighter:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function HeroFighter:getAbstract()
|
||||
return game.characters.list[self.name]
|
||||
end
|
||||
|
@ -27,13 +31,19 @@ function HeroFighter:createActor()
|
|||
end
|
||||
|
||||
function HeroFighter:startAction()
|
||||
|
||||
core.debug:print("cbs/heroFighter", "launching the action menu")
|
||||
self.turnSystem.scene.menu:set( self )
|
||||
end
|
||||
|
||||
function HeroFighter:endAction()
|
||||
|
||||
end
|
||||
|
||||
-- Basic actions
|
||||
function HeroFighter:doNothing()
|
||||
self:setInactive()
|
||||
end
|
||||
|
||||
-- DRAW FUNCTIONS
|
||||
function HeroFighter:drawIcon(x, y)
|
||||
local iconID = 1
|
||||
|
|
|
@ -47,7 +47,7 @@ end
|
|||
|
||||
function FighterParent:setInactive()
|
||||
self.isActive = false
|
||||
self.turnSystem:nextAction()
|
||||
self.turnSystem:endAction()
|
||||
end
|
||||
|
||||
function FighterParent:getNbrActionPerTurn()
|
||||
|
|
|
@ -106,7 +106,7 @@ function TurnController:startAction()
|
|||
end
|
||||
|
||||
function TurnController:endAction()
|
||||
self.currentlyPlaying = ""
|
||||
self.currentFighter = nil
|
||||
end
|
||||
|
||||
function TurnController:sendSignalToCurrentBattler(signal, subSignal)
|
||||
|
|
|
@ -15,34 +15,33 @@ local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
|
|||
local MENU_ITEM_NUMBER = 6
|
||||
|
||||
function MenuConstructor:new( controller )
|
||||
self.controller = controller
|
||||
self.scene = controller
|
||||
end
|
||||
|
||||
function MenuConstructor:reconstruct(character)
|
||||
self.controller.menusystem:reset()
|
||||
core.debug:print("cbs/menu", "Reconstructing the menu")
|
||||
self.scene.menusystem:reset()
|
||||
self:build(character)
|
||||
|
||||
self.controller.menusystem:switchMenu("BaseMenu")
|
||||
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.controller.menusystem:setSoundFromSceneAssets("mBeep")
|
||||
self.scene.menusystem:setSoundFromSceneAssets("mBeep")
|
||||
end
|
||||
|
||||
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")
|
||||
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
|
||||
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
|
||||
ActionWidget(character, "BaseMenu", "defend")
|
||||
ActionWidget(character, "BaseMenu", "flee")
|
||||
BackMenuWidget(character, "BaseMenu")
|
||||
|
||||
self.controller.menusystem.menus["BaseMenu"]:setCancelWidget()
|
||||
end
|
||||
|
||||
function MenuConstructor:set(currentCharacter)
|
||||
|
@ -50,23 +49,23 @@ function MenuConstructor:set(currentCharacter)
|
|||
end
|
||||
|
||||
function MenuConstructor:buildSkillMenu(character)
|
||||
CharacterMenu(self.controller, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
local list = game.characters:getSkillList(character.charid)
|
||||
CharacterMenu(self.scene, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
local list = character.abstract.skills
|
||||
for k, skill in pairs(list) do
|
||||
SkillWidget(character, "SkillMenu", skill.name, "")
|
||||
end
|
||||
SubMenuWidget(character, "SkillMenu", "back", "BaseMenu")
|
||||
|
||||
self.controller.menusystem.menus["SkillMenu"]:setCancelWidget()
|
||||
self.scene.menusystem.menus["SkillMenu"]:setCancelWidget()
|
||||
end
|
||||
|
||||
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.controller, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
CharacterMenu(self.controller, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
CharacterMenu(self.controller, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
CharacterMenu(self.scene, "MedMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
CharacterMenu(self.scene, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
CharacterMenu(self.scene, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
CharacterMenu(self.scene, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||
|
||||
|
||||
SubMenuWidget(character, "ObjectMenu", "heal", "MedMenu")
|
||||
|
@ -81,12 +80,12 @@ function MenuConstructor:buildObjectMenu(character)
|
|||
SubMenuWidget(character, "OtherMenu", "back", "ObjectMenu")
|
||||
|
||||
|
||||
self.controller.menusystem.menus["ObjectMenu"]:setCancelWidget()
|
||||
self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget()
|
||||
|
||||
self.controller.menusystem.menus["MedMenu"]:setCancelWidget()
|
||||
self.controller.menusystem.menus["RingMenu"]:setCancelWidget()
|
||||
self.controller.menusystem.menus["WispMenu"]:setCancelWidget()
|
||||
self.controller.menusystem.menus["OtherMenu"]:setCancelWidget()
|
||||
self.scene.menusystem.menus["MedMenu"]:setCancelWidget()
|
||||
self.scene.menusystem.menus["RingMenu"]:setCancelWidget()
|
||||
self.scene.menusystem.menus["WispMenu"]:setCancelWidget()
|
||||
self.scene.menusystem.menus["OtherMenu"]:setCancelWidget()
|
||||
end
|
||||
|
||||
|
||||
|
@ -149,7 +148,7 @@ end
|
|||
function BattleWidget:getControllers(character, menu_name)
|
||||
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.menusystem = self.scene.menusystem
|
||||
|
||||
|
@ -167,26 +166,7 @@ function BattleWidget:update(dt)
|
|||
end
|
||||
|
||||
function BattleWidget:selectAction()
|
||||
self:setActiveGrid()
|
||||
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
|
||||
-- Rien de base, à voir ensuite comment je gère
|
||||
end
|
||||
|
||||
function BattleWidget:drawCanvas()
|
||||
|
@ -217,9 +197,6 @@ function BattleWidget:drawCanvas()
|
|||
end
|
||||
|
||||
function BattleWidget:action()
|
||||
self.scene.world:resetActiveGrid()
|
||||
self.scene.world:resetEffectGrid()
|
||||
|
||||
self:sendCharacterData()
|
||||
|
||||
self.scene:flushKeys()
|
||||
|
@ -228,24 +205,8 @@ end
|
|||
|
||||
-- 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()
|
||||
self.character:receiveSignal()
|
||||
self.character:doNothing()
|
||||
end
|
||||
|
||||
-- ActionWidget
|
||||
|
@ -256,16 +217,8 @@ function ActionWidget:new(character, menu_name, action)
|
|||
ActionWidget.super.new(self, character, menu_name, action, "")
|
||||
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()
|
||||
self.character:receiveSignal(self.actionType)
|
||||
self.character:doNothing()
|
||||
end
|
||||
|
||||
-- SubMenuWidget
|
||||
|
@ -318,58 +271,15 @@ function SkillWidget:new(character, menu_name, skill)
|
|||
SkillWidget.super.new(self, character, menu_name, self.skillname, "-" .. label2, "skills")
|
||||
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()
|
||||
|
||||
if self.skilldata ~= nil then
|
||||
if self:haveActiveGrid() then
|
||||
local x, y, shape, size, direction = self:getActiveGrid()
|
||||
self.scene.world.cursor:setGridIgnoreActor(x, y, shape, size, direction)
|
||||
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
|
||||
self.assets.sfx["mSelect"]:play()
|
||||
self.character:doNothing()
|
||||
--self.character:useSkill(self.skillname, self.character.x, self.character.y)
|
||||
else
|
||||
core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist")
|
||||
self.character:receiveSignal("none")
|
||||
self.character:doNothing()
|
||||
self.assets.sfx["mError"]:play()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue