Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-12-23 23:40:51 +0000
committerStijn Buys <ingar@osirion.org>2012-12-23 23:40:51 +0000
commita565dbb1982fe45d90fae1cbfc03e2cc058ebf6f (patch)
tree775e6897db77ea5ecc7927fae8dcf4c6a456d25e /src/client/hud.cc
parent79b1af52c004469dbad6b2fc8ba8ff239b48112f (diff)
Removed commented out code blocks,
added target selection popup effect.
Diffstat (limited to 'src/client/hud.cc')
-rw-r--r--src/client/hud.cc394
1 files changed, 100 insertions, 294 deletions
diff --git a/src/client/hud.cc b/src/client/hud.cc
index bcbc3a8..e0e0d89 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -21,6 +21,8 @@
namespace client
{
+const float SPLASH_POPUP_DELAY = 0.1f;
+
HUD::HUD(ui::Widget *parent) : Widget(parent)
{
set_label("hud");
@@ -38,7 +40,9 @@ HUD::HUD(ui::Widget *parent) : Widget(parent)
// target status
hud_targetstatus = new HUDTargetStatus(this);
-
+
+ hud_splash_time = 0.0f;
+ hud_last_target = 0;
}
void HUD::resize()
@@ -159,6 +163,9 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
float bitmap_radius = 32.0f;
if (is_active_target) {
bitmap_radius *= 2.0f;
+ if (hud_splash_time > 0.0f) {
+ bitmap_radius *= (core::application()->time() - hud_splash_time) / SPLASH_POPUP_DELAY;
+ }
}
math::Vector2f bitmap_location(cx - bitmap_radius, cy - bitmap_radius);
math::Vector2f bitmap_size(2.0f * bitmap_radius, 2.0f * bitmap_radius);
@@ -189,176 +196,103 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
ui::Paint::draw_bitmap(bitmap_location, bitmap_size, bitmap_color, bitmap_material);
- // labels
- std::string label_text;
-
- if (entity->type() == core::Entity::Controlable) {
- const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
- if (ec->owner()) {
- label_text.append("^B");
- label_text.append(ec->owner()->name());
- } else {
- label_text.append("^B");
- label_text.append(entity->name());
- }
- } else {
- if (entity->has_flag(core::Entity::Dockable)) {
- label_text.append("^B");
- } else {
- label_text.append("^N");
- }
- label_text.append(entity->name());
- }
-
- const ui::Font *label_font;
- if (is_active_target) {
- label_font = ui::root()->font_small();
- } else {
- label_font = ui::root()->font_tiny();
- }
-
- math::Vector2f label_size(2.0f * bitmap_radius, label_font->height());
- math::Vector2f label_location(cx - bitmap_radius, cy + bitmap_radius);
- ui::Paint::draw_label(label_location, label_size,label_font, label_text);
-
- if (is_active_target) {
-
- // draw distance
- std::ostringstream strdistance;
+ if (!(is_active_target && (hud_splash_time > 0.0f))) {
+
+ // labels
+ std::string label_text;
if (entity->type() == core::Entity::Controlable) {
- strdistance << "^B";
- } else if (entity->has_flag(core::Entity::Dockable)) {
- strdistance << "^B";
- } else {
- strdistance << "^N";
- }
-
- float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius();
- if (d > 0) {
- if (d > 100.0f) {
- strdistance << roundf(d * 0.1f) << "km";
+ const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
+ if (ec->owner()) {
+ label_text.append("^B");
+ label_text.append(ec->owner()->name());
} else {
- strdistance << roundf(d * 100.0f) << "m";
+ label_text.append("^B");
+ label_text.append(entity->name());
}
} else {
- strdistance << "--";
+ if (entity->has_flag(core::Entity::Dockable)) {
+ label_text.append("^B");
+ } else {
+ label_text.append("^N");
+ }
+ label_text.append(entity->name());
}
- label_location[1] += - label_size.height();
- ui::Paint::draw_label(label_location, label_size, label_font, strdistance.str());
- }
-
- if (entity->type() == core::Entity::Controlable) {
- const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
-
- // health bar size
- const float hb_width = bitmap_radius;
- float hb_height = ui::root()->font_tiny()->width();
- if (!is_active_target) {
- hb_height *= 0.5f;
+ const ui::Font *label_font;
+ if (is_active_target) {
+ label_font = ui::root()->font_small();
+ } else {
+ label_font = ui::root()->font_tiny();
}
- const float hb_f = hb_width * ec->health() / 100.0f;
-
- math::Vector2f pos;
- pos[0] = cx - bitmap_radius;
- pos[0] += bitmap_radius - 0.5f * hb_width;
- pos[1] = cy - bitmap_radius;
-
- // 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();
-
- }
-
- /*
- if (is_active_target) {
-
- gl::color(palette()->foreground());
- // owner name
- if (entity->type() == core::Entity::Controlable) {
- const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
+ math::Vector2f label_size(2.0f * bitmap_radius, label_font->height());
+ math::Vector2f label_location(cx - bitmap_radius, cy + bitmap_radius);
+ ui::Paint::draw_label(label_location, label_size,label_font, label_text);
+
+ if (is_active_target) {
+ // draw distance
+ std::ostringstream strdistance;
- if (ec->health() > 0) {
- // on-screen health indicator
- const float f = 2.0f * r * ec->health() / 100.0f;
-
- // health bar
- gl::color(0, 1, 0, 1);
- gl::begin(gl::Quads);
- gl::vertex(cx - r, cy + r - 4 - render::Text::fontheight() * 0.5f);
- gl::vertex(cx - r + f, cy + r - 4 - render::Text::fontheight() * 0.5f);
- gl::vertex(cx - r + f, cy + r - 4);
- gl::vertex(cx - r, cy + r - 4);
- gl::end();
-
- // frame
- gl::color(palette()->foreground());
-
- gl::begin(gl::LineLoop);
- gl::vertex(cx - r, cy + r - 4 - render::Text::fontheight() * 0.5f);
- gl::vertex(cx + r, cy + r - 4 - render::Text::fontheight() * 0.5f);
- gl::vertex(cx + r, cy + r - 4);
- gl::vertex(cx - r, cy + r - 4);
- gl::end();
+ if (entity->type() == core::Entity::Controlable) {
+ strdistance << "^B";
+ } else if (entity->has_flag(core::Entity::Dockable)) {
+ strdistance << "^B";
+ } else {
+ strdistance << "^N";
}
-
- gl::enable(GL_TEXTURE_2D);
-
- if (ec->owner()) {
- std::ostringstream strtoplabel;
- strtoplabel << "^B" << ec->owner()->name() << "^B\n";
- render::Text::draw(
- cx - aux::text_length(strtoplabel.str()) * render::Text::fontwidth() * 0.5f,
- cy - r - 4 - render::Text::fontheight(), strtoplabel.str()
- );
+
+ float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius();
+ if (d > 0) {
+ if (d > 100.0f) {
+ strdistance << roundf(d * 0.1f) << "km";
+ } else {
+ strdistance << roundf(d * 100.0f) << "m";
+ }
+ } else {
+ strdistance << "--";
}
-
- } else {
- gl::enable(GL_TEXTURE_2D);
+
+ label_location[1] += - label_size.height();
+ ui::Paint::draw_label(label_location, label_size, label_font, strdistance.str());
}
-
- gl::color(palette()->foreground());
-
- // on-screen entity name
- render::Text::draw(
- cx - aux::text_length(entity->name()) * render::Text::fontwidth() * 0.5f,
- cy + r + 4, entity->name()
- );
- // on-screen distance
- std::ostringstream strdistance;
- float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius();
- if (d > 0) {
- if (d > 100.0f) {
- strdistance << roundf(d * 0.1f) << "km";
- } else {
- strdistance << roundf(d * 100.0f) << "m";
+ if (entity->type() == core::Entity::Controlable) {
+ const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
+
+ // health bar size
+ const float hb_width = bitmap_radius;
+ float hb_height = ui::root()->font_tiny()->width();
+ if (!is_active_target) {
+ hb_height *= 0.5f;
}
- } else {
- strdistance << "--";
+ const float hb_f = hb_width * ec->health() / 100.0f;
+
+ math::Vector2f pos;
+ pos[0] = cx - bitmap_radius;
+ pos[0] += bitmap_radius - 0.5f * hb_width;
+ pos[1] = cy - bitmap_radius;
+
+ // 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();
+
}
- render::Text::draw(
- cx - aux::text_length(strdistance.str()) * render::Text::fontwidth() * 0.5f,
- cy + r + 4 + render::Text::fontheight(), strdistance.str()
- );
}
- */
}
bool HUD::on_keypress(const int key, const unsigned int modifier)
@@ -393,6 +327,18 @@ void HUD::draw()
core::Zone *zone = core::localcontrol()->zone();
+ if (targets::current()) {
+ if (targets::current()->id() != hud_last_target) {
+ hud_splash_time = core::application()->time();
+ } else if (hud_splash_time + SPLASH_POPUP_DELAY < core::application()->time()) {
+ hud_splash_time = 0.0f;
+ }
+ hud_last_target = targets::current()->id();
+ } else {
+ hud_splash_time = 0.0f;
+ hud_last_target = 0;
+ }
+
// draw HUD targets
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
@@ -416,147 +362,7 @@ void HUD::draw()
}
gl::disable(GL_TEXTURE_2D);
-
- /*
- // ---------------------------------------------------------
- // player info pane
-
- std::ostringstream playerinfostr;
- playerinfostr << "^B" << core::localplayer()->name() << '\n';
- playerinfostr << "^B" << core::localcontrol()->name() << '\n';
- playerinfostr << "^Ncredits: " << core::localplayer()->credits();
-
- Text::draw(width() - 4 - Text::fontwidth() * 52, height() - Text::fontheight() * 3 - 4, playerinfostr.str());
- */
-
- /*
- // ---------------------------------------------------------
- // target info pane
-
- const core::Entity *target = targets::current();
- if (target) {
- std::ostringstream strtarget;
-
- if (target->type() == core::Entity::Controlable) {
- const core::EntityControlable *target_controlable = static_cast<const core::EntityControlable *>(target);
- if (target_controlable->owner()) {
- strtarget << "^B" << target_controlable->owner()->name() << "\n";
- } else {
- strtarget << "\n";
- }
- } else {
- strtarget << "\n";
- }
-
- strtarget << "^B" << target->name() << "\n^B";
-
- float d = math::distance(core::localcontrol()->location(), target->location())
- - target->radius() - core::localcontrol()->radius();
-
- if (d > 0) {
- strtarget << "^Ndist:^B ";
- if (d > 100.0f) {
- strtarget << roundf(d * 0.1f) << "km";
- } else {
- strtarget << roundf(d * 100.0f) << "m";
- }
-
- if (core::localcontrol()->speed() > 0.1f) {
- strtarget << "^N eta:^B ";
- float eta = floorf(d / core::localcontrol()->speed());
- if (eta > 60.0f) {
- float etamin = floorf(eta / 60.0f);
- strtarget << etamin << "min ";
- eta -= etamin * 60;
- }
- strtarget << eta << "sec";
- }
- } else {
- strtarget << " --";
- }
- Text::draw(width() - 4 - Text::fontwidth() * 30, height() - Text::fontheight() * 3 - 4, strtarget.str());
- }
-
- */
-
- /*
-
- //----------------------------------------------------------
- // engine info pane
-
- // draw thruster indicator
- Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
- gl::color(1, 1, 1, 1);
- gl::begin(gl::Quads);
- glTexCoord2f(0, 0);
- gl::vertex(4, height() - 4 - 32, 0);
-
- glTexCoord2f(1, 0);
- gl::vertex(4 + 316, height() - 4 - 32, 0);
-
- glTexCoord2f(1, 1);
- gl::vertex(4 + 316, height() - 4 , 0);
-
- glTexCoord2f(0, 1);
- gl::vertex(4, height() - 4 , 0);
-
- gl::end();
-
- float u = core::localcontrol()->thrust();
-
- if (core::localcontrol()->state() != core::Entity::Normal) {
-
- if ((core::localcontrol()->state() == core::Entity::Docked ) || (core::localcontrol()->state() == core::Entity::NoPower )) {
- u = 0.0f;
- } else {
-
- u = 1.0f;
- }
- }
-
- if ((u > 0) || (core::localcontrol()->state() == core::Entity::Impulse)) {
-
- if ((core::localcontrol()->state() == core::Entity::Impulse) || (core::localcontrol()->state() == core::Entity::ImpulseInitiate)) {
- gl::color(0, .8, 0);
- } else if ((core::localcontrol()->state() == core::Entity::Jump) || (core::localcontrol()->state() == core::Entity::JumpInitiate)) {
- gl::color(0.8f, 0.0f, 0.0f);
- } else {
- float d = math::absf(input::local_thrust - u);
- if (d > 0.1) {
- d = 0.1f;
- }
- gl::color(1, 1, .5f + d * 5.0f);
- }
- Textures::bind("bitmaps/hud/thruster_indicator"); // 316 x 32 bitmap
- gl::begin(gl::Quads);
- glTexCoord2f(0, 0);
- gl::vertex(4, height() - 4 - 32, 0);
-
- glTexCoord2f(u, 0);
- gl::vertex(4.0f + u * 316.0f, height() - 4 - 32, 0);
-
- glTexCoord2f(u, 1);
- gl::vertex(4.0f + u * 316.0f, height() - 4 , 0);
-
- glTexCoord2f(0, 1);
- gl::vertex(4, height() - 4 , 0);
-
- gl::end();
- }
-
- Text::setfont("gui", 14, 24);
- Text::setcolor('B'); //set normal color
-
- std::ostringstream speedstr;
- speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
- Text::draw(316 + 4 + 10, height() - 6 - 16 - render::Text::fontwidth() / 2, speedstr.str());
-
- Text::setfont("gui", 12, 18);
- Text::setcolor('N'); //set normal color
-
- */
-
if (has_mouse_focus()) {
if (render::Camera::mode() == render::Camera::Overview) {