#include "PlayerInfoView.hh"
#include "Graphics.hh"
#include <sstream>
namespace graphics
{
void PlayerInfoView::draw (Display &display) {
CL_GraphicContext *gc = display.get_gc();
CL_Font font = graphics->fonts.getSimpleFont();
int bar_length = 3;
// draw status info at bottom of display
gc->fill_rect(
CL_Rect(area.left, area.top, area.right, area.bottom),
CL_Gradient(
CL_Color(0, 0, 0),
CL_Color(50, 50, 50),
CL_Color(50, 50, 50, 150),
CL_Color(100, 100, 100, 200)
)
);
// Health
double health_percent = player->getHealthPercent();
gc->draw_rect(
CL_Rect(
area.left + 9,
area.top + 9,
area.left + 11 + 100 * bar_length,
area.top + 31
),
CL_Color(150, 150, 150)
);
gc->fill_rect(
CL_Rect(
area.left + 10,
area.top + 10,
area.left + 10 + (int) (health_percent * bar_length),
area.top + 30
),
CL_Gradient(
CL_Color(200, 0, 0),
CL_Color(200 - (int)(health_percent * 2), (int)(health_percent * 2), 0),
CL_Color(200, 0, 0),
CL_Color(200 - (int)(health_percent * 2), (int)(health_percent * 2), 0)
)
);
// stats - kills
std::stringstream sskills;
sskills << "Kills: " << player->getKills();
font.draw(
area.left + 20 + 100 * bar_length,
area.top + 10,
sskills.str(),
gc
);
// stats - deaths
std::stringstream ssdeaths;
ssdeaths << "Deaths: " << player->getDeaths();
font.draw(
area.left + 20 + 100 * bar_length,
area.top + 30,
ssdeaths.str(),
gc
);
// stats - ratio
std::stringstream ssratio;
ssratio << "Ratio: " << (player->getKills() + 1) / (player->getDeaths() + 1);
font.draw(
area.left + 20 + 100 * bar_length,
area.top + 50,
ssratio.str(),
gc
);
// Weapon clip / reloading
gc->draw_rect(
CL_Rect(
area.left + 9,
area.top + 69,
area.left + 11 + 100 * bar_length,
area.top + 91
),
CL_Color(150, 150, 150)
);
gc->fill_rect(
CL_Rect(
area.left + 10,
area.top + 70,
area.left + 10 + (100 - (int) (
player->getCurrentWeapon()->getReloadTimer() * 100 / player->getCurrentWeapon()->getReloadTime()
)) * bar_length,
area.top + 90
),
CL_Gradient(
CL_Color(100, 100, 0),
CL_Color(100, 100, 0),
CL_Color(100, 100, 0),
CL_Color(100, 100, 100)
)
);
// current weapon name
font.draw(
area.left + 20 + 100 * bar_length,
area.top + 70,
player->getCurrentWeapon()->getName(),
gc
);
}
}