feat: add a team management panel

Fix #10
This commit is contained in:
Kazhnuz 2020-08-02 23:47:42 +02:00
parent d0229f8aff
commit 693150029c
6 changed files with 108 additions and 3 deletions

View file

@ -86,11 +86,57 @@ end
function CharacterManager:addToTeam(name)
self:heal(name)
table.insert(self.team, name)
if (#self.team < 4) then
table.insert(self.team, name)
end
end
function CharacterManager:removeToTeam(teamid)
self.team[teamid] = ""
if (#self.team > 1) then
table.remove(self.team, teamid)
end
end
function CharacterManager:getPositionInTeam(charName)
local charId = -1
for i,name in ipairs(self.team) do
if (name == charName) then
charId = i
end
end
return charId
end
function CharacterManager:addOrRemoveToTeam(charName)
local charId = self:getPositionInTeam(charName)
if (charId == -1) then
self:addToTeam(charName)
else
self:removeToTeam(charId)
if (charId < self.active) then
self.active = self.active - 1
end
end
self:fixActiveCharacter()
end
function CharacterManager:setActiveCharacter(direction)
local direction = direction or 1
self.active = self.active + utils.math.sign(direction)
if (self.active > #self.team) then
self.active = 1
end
if (self.active < 1) then
self.active = #self.team
end
end
function CharacterManager:fixActiveCharacter()
if (self.active < 1) then
self.active = 1
elseif (self.active > #self.team) then
self.active = #self.team
end
end
function CharacterManager:getActiveCharacter()

View file

@ -6,7 +6,7 @@ function Player:new(world, x, y, z, id)
Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true)
self:setGravity(480*2)
self.charName = game.characters.team[1]
self.charName = game.characters:getActiveCharacter()
self.assets:addSprite("player", "datas/gamedata/characters/" .. self.charName .. "/sprites")
self:setSprite("player", 8, 10)
self:cloneSprite()

View file

@ -3,4 +3,5 @@ local folder = "scenes.debug.menu.infopanel."
return {
Gamedata = require(folder .. "gamedata"),
Character = require(folder .. "character"),
Team = require(folder .. "team"),
}

View file

@ -0,0 +1,22 @@
local Parent = require "scenes.debug.menu.infopanel.parent"
local TeamPanel = Parent:extend()
function TeamPanel:new()
TeamPanel.super.new(self)
end
function TeamPanel:drawContent(x, y)
local debugString = "# Team" .. "\n"
for i,name in ipairs(game.characters.team) do
local char = game.characters.list[name]
debugString = debugString .. "- " .. char.name
if (game.characters.active == i) then
debugString = debugString .. " (Active) "
end
debugString = debugString .. "\n"
end
love.graphics.print(debugString, x, y)
end
return TeamPanel

View file

@ -39,8 +39,11 @@ end
function DebugMenu:buildSaveMenu()
self:addSubMenu("save", "BaseMenu", "Save System")
self:addSubMenu("characters", "save", "Characters")
self:addSubMenu("team", "save", "Team Formation", panels.Team, nil)
menu.ChangeLeaderWidget(self, "team")
for name, data in pairs(game.characters.list) do
self:addCharacterMenu(name, data)
menu.AddRemoveWidget(self, "team", data)
end
self:addSubMenu("load", "save", "Load Saves")
@ -53,10 +56,12 @@ function DebugMenu:buildSaveMenu()
menu.commons.SubMenuWidget(self, "save", "BaseMenu", "Back")
menu.commons.SubMenuWidget(self, "characters", "save", "Back")
menu.commons.SubMenuWidget(self, "load", "save", "Back")
menu.SubMenuWidget(self, "team", "save", "Back", panels.Gamedata, nil)
end
function DebugMenu:addCharacterMenu(name, data)
self:addSubMenu(name, "characters", data.fullname, panels.Character, data)
menu.LevelUpWidget(self, name, data)
menu.SubMenuWidget(self, name, "characters", "Back", panels.Gamedata, nil)
end

View file

@ -5,6 +5,9 @@ menu.ExitWidget = commons.DebugWidget:extend()
menu.ShowBackgroundWidget = commons.DebugWidget:extend()
menu.SaveWidget = commons.DebugWidget:extend()
menu.LoadWidget = commons.DebugWidget:extend()
menu.LevelUpWidget = commons.DebugWidget:extend()
menu.AddRemoveWidget = commons.DebugWidget:extend()
menu.ChangeLeaderWidget = commons.DebugWidget:extend()
menu.SubMenuWidget = commons.SubMenuWidget:extend()
-- ExitWidget
@ -56,6 +59,34 @@ function menu.SubMenuWidget:action()
self.scene.panel = self.panel(self.panelArgument)
end
-- Level Up
function menu.LevelUpWidget:new(scene, menuName, character)
menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Level Up")
self.character = character
end
function menu.LevelUpWidget:action()
self.character:levelUp()
end
-- Add Remove Widget
function menu.AddRemoveWidget:new(scene, menuName, character)
menu.AddRemoveWidget.super.new(self, scene, menuName, "Add/Remove " .. character.name)
self.character = character
end
function menu.AddRemoveWidget:action()
game.characters:addOrRemoveToTeam(self.character.simplename)
end
--Change Team Leader
function menu.ChangeLeaderWidget:new(scene, menuName)
menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Change active character")
end
function menu.ChangeLeaderWidget:action()
game.characters:setActiveCharacter(1)
end
return menu