/*Copyright (C) 2010-2012 Duncan Deveaux

This file is part of Hikou no mizu.

Hikou no mizu is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Hikou no mizu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Hikou no mizu.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "FightInterface.hpp"

FightInterface::FightInterface() :
Drawable(), m_namesFont(NULL), m_barsFont(NULL)
{
    
}

void FightInterface::draw()
{
    //UpdateMatrix
    Drawable::pushMatrix();
    Drawable::updateMatrix();
    
    for (unsigned int i = 0; i < m_playerInfos.size(); i++)
    {
        m_playerInfos[i].draw();
        glTranslatef(m_playerInfos[i].getWidth() + 50, 0, 0);
    }
    
    Drawable::popMatrix();
}

void FightInterface::update()
{
    for (unsigned int i = 0; i < m_playerInfos.size(); i++)
        m_playerInfos[i].update();
}

void FightInterface::addPlayer(Player &player, int playerIx)
{
    PlayerInfo playerInfo;
    playerInfo.setFonts(*m_namesFont, *m_barsFont);
    playerInfo.setPlayer(player);
    
    if (playerIx == -1)
        m_playerInfos.push_back(playerInfo);
    else if (playerIx >= 0 && playerIx <= static_cast<int>(m_playerInfos.size()) - 1)
        m_playerInfos[playerIx] = playerInfo;
}

void FightInterface::removePlayer(int playerIx)
{
    if (playerIx >= 0 && playerIx <= static_cast<int>(m_playerInfos.size()) - 1)
        m_playerInfos.erase(m_playerInfos.begin() + playerIx);
}

//Get and set methods
void FightInterface::setFonts(Font &namesFont, Font &barsFont)
{
    m_namesFont = &namesFont;
    m_barsFont = &barsFont;
    
    for (unsigned int i = 0; i < m_playerInfos.size(); i++)
        m_playerInfos[i].setFonts(*m_namesFont, *m_barsFont);
}

const Font &FightInterface::getNamesFont() const
{
    return *m_namesFont;
}

const Font &FightInterface::getBarsFont() const
{
    return *m_barsFont;
}
