#include "tank.h"
#include <render/render.h>
#include <resources.h>

namespace game{

tank::tank(const vec2u &pos, level *root):basicPipe(pos, vec2u(2), root)
{
    _capacity = 512;
    _needShowGui = false;
}

void tank::hover() noexcept
{
    _needShowShortInfo = true;
}

void tank::onGui() noexcept
{
    if(_needShowShortInfo && !_needShowGui)
    {
        _drawShortInfo();
        _needShowShortInfo = false;
    }

    if(!_needShowGui)
        return;

    if(currentlyShown != this)
    {
        _needShowGui = false;
        return;
    }
    _drawWindow();
}

void tank::draw()
{
    vec2u cursorDrawOffsets[4] = {vec2u(0),vec2u(1,0),vec2u(0,1),vec2u(1)};

    resources::atlas.draw(vec2f(0,-1)+_pos, vec2u(0,7),vec2u(2,3));

    if(_needShowGui)
        for(int i = 0; i < 4; i++)
            resources::atlas.draw(_pos+cursorDrawOffsets[i],vec2u(i+1,14));
    else if(_needShowShortInfo)
        for(int i = 0; i < 4; i++)
            resources::atlas.draw(_pos+cursorDrawOffsets[i],vec2u(i+1,13));

    if(_item != 0xFFFFFFFF && _amount >= 0.05)
        render::primitives2d::quad(_pos, vec2f(_size.x, getFilledSpace()*_size.y), rgba(0.8, (_item/8.0), 0.2 ,0.6));
}

}
