From d2e9d7532f58f07c0ede3fad2dbf39a92130670c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 23 Dec 2012 17:10:54 +0000 Subject: Split HUD components into seperate widgets, added health bar,added temporary target health bar. --- src/client/hudenginestatus.cc | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/client/hudenginestatus.cc (limited to 'src/client/hudenginestatus.cc') diff --git a/src/client/hudenginestatus.cc b/src/client/hudenginestatus.cc new file mode 100644 index 0000000..04b6f63 --- /dev/null +++ b/src/client/hudenginestatus.cc @@ -0,0 +1,86 @@ +/* + client/hudenginestatus.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "client/hudenginestatus.h" +#include "core/core.h" +#include "core/application.h" +#include "ui/ui.h" +#include "ui/paint.h" +#include "render/gl.h" + +namespace client +{ + +HUDEngineStatus::HUDEngineStatus(ui::Widget *parent) : ui::Widget(parent) +{ + set_border(false); + set_background(false); +} + +void HUDEngineStatus::draw() +{ + const float padding = font()->width() * 0.25f; + + math::Vector2f pos(global_location()); + pos[0] += padding; + pos[1] += padding; + + math::Vector2f s(size()); + s[0] -= 2.0f * padding; + s[1] -= 2.0f * padding; + + // thrust + std::ostringstream thruststr; + if (core::localcontrol()->state() == core::Entity::Normal) { + thruststr << "^B" << roundf(core::localcontrol()->thrust() * 100.0f) << "%"; + } else { + thruststr << "^B--"; + } + + // speed + std::ostringstream speedstr; + speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f); + + ui::Paint::set_color(palette()->foreground()); + ui::Paint::draw_label(pos, s, ui::root()->font_large(), thruststr.str(), ui::AlignLeft | ui::AlignVCenter); + ui::Paint::draw_label(pos, s, ui::root()->font_large(), speedstr.str(), ui::AlignRight | ui::AlignVCenter); + + // health bar size + const float hb_width = width() - 12 * ui::root()->font_large()->width() - 2.0f * padding; + const float hb_height = ui::root()->font_tiny()->width(); + const float hb_f = hb_width * core::localcontrol()->health() / 100.0f; + + pos.assign(global_location()); + pos[0] += (width() - hb_width) * 0.5f; + pos[1] += (height() - hb_height) * 0.5f; + + // health bar + gl::color(0, 1, 0, 1); + gl::begin(gl::Quads); + gl::vertex(pos[0], pos[1]); + gl::vertex(pos[0] + hb_f, pos[1]); + gl::vertex(pos[0] + hb_f, pos[1] + hb_height); + gl::vertex(pos[0], pos[1] + hb_height); + gl::end(); + + // health bar frame + gl::color(palette()->foreground()); + + gl::begin(gl::LineLoop); + gl::vertex(pos[0], pos[1]); + gl::vertex(pos[0] + hb_width, pos[1]); + gl::vertex(pos[0] + hb_width, pos[1] + hb_height); + gl::vertex(pos[0], pos[1] + hb_height); + gl::end(); +} + +bool HUDEngineStatus::on_keypress(const int key, const unsigned int modifier) +{ + return false; +} + +} // namespace client + -- cgit v1.2.3