src/Graphics/PlayerInfoView.cc
author Tero Marttila <terom@fixme.fi>
Wed, 21 Jan 2009 23:07:22 +0200
branchnew_graphics
changeset 412 721c60072091
parent 411 106aaf6eadfe
child 413 7dddc163489a
permissions -rw-r--r--
new graphics code compiles... no, it doesn't work yet

#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(),
        display.get_gc()
    );
    
    // stats - deaths
    std::stringstream ssdeaths;
    ssdeaths << "Deaths:  " << player->getDeaths();
    font.draw(
        area.left + 20 + 100 * bar_length,
        area.top + 30,
        ssdeaths.str(),
        display.get_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(),
        display.get_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(),
        display.get_gc()
    );
}



}