/*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()
{
    
}

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

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

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

void FightInterface::removePlayer(int playerIx)
{
    if (playerIx >= 0 && playerIx <= static_cast<int>(m_playerWidgets.size()) - 1)
        m_playerWidgets.erase(m_playerWidgets.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_playerWidgets.size(); i++)
        m_playerWidgets[i].setFonts(*m_namesFont, *m_barsFont);
}

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

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