Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/hud.cc')
-rw-r--r--src/client/hud.cc153
1 files changed, 82 insertions, 71 deletions
diff --git a/src/client/hud.cc b/src/client/hud.cc
index 662bbe8..b7e2c43 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -1,7 +1,7 @@
/*
client/hud.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
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
@@ -13,7 +13,7 @@
#include "render/renderext.h"
#include "ui/ui.h"
-namespace client
+namespace client
{
HUD::HUD(ui::Widget *parent) : Widget(parent)
@@ -30,7 +30,7 @@ HUD::HUD(ui::Widget *parent) : Widget(parent)
*/
hud_center = new ui::Bitmap(this, "pointers/center");
hud_center->set_color(palette()->pointer());
-
+
}
void HUD::resize()
@@ -50,11 +50,11 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target)
float cx = 0;
float cy = 0;
- if ( target.y() * target.y() + target.z() * target.z() < 0.0001 ) {
+ if (target.y() * target.y() + target.z() * target.z() < 0.0001) {
// X - bound, behind (front is visible)
cx = 0.0f;
cy = -0.5f;
-
+
} else if (fabs(target.y()) > fabs(target.z())) {
// Y-bound
cx = math::sgnf(target.y()) * 0.5f;
@@ -67,18 +67,18 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target)
const float r = 16;
const float margin = 24;
- cx = (0.5f - cx) * ((float) render::State::width() - margin*2);
+ cx = (0.5f - cx) * ((float) render::State::width() - margin * 2);
cx += margin;
- cy = (0.5f - cy) * ((float) render::State::height() - margin*2);
+ cy = (0.5f - cy) * ((float) render::State::height() - margin * 2);
cy += margin;
gl::disable(GL_TEXTURE_2D);
gl::color(0, 0, 0, 1);
gl::begin(gl::LineLoop);
- glVertex3f(cx+r, cy+2, 0);
- glVertex3f(cx, cy+r+2, 0);
- glVertex3f(cx-r, cy+2, 0);
- glVertex3f(cx, cy-r+2, 0);
+ glVertex3f(cx + r, cy + 2, 0);
+ glVertex3f(cx, cy + r + 2, 0);
+ glVertex3f(cx - r, cy + 2, 0);
+ glVertex3f(cx, cy - r + 2, 0);
gl::end();
if (entity == core::localplayer()->mission_target()) {
@@ -90,10 +90,10 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target)
}
gl::begin(gl::LineLoop);
- glVertex3f(cx+r, cy, 0);
- glVertex3f(cx, cy+r, 0);
- glVertex3f(cx-r, cy, 0);
- glVertex3f(cx, cy-r, 0);
+ glVertex3f(cx + r, cy, 0);
+ glVertex3f(cx, cy + r, 0);
+ glVertex3f(cx - r, cy, 0);
+ glVertex3f(cx, cy - r, 0);
gl::end();
gl::enable(GL_TEXTURE_2D);
}
@@ -108,7 +108,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// don't draw target if it is outside the visible cone
Vector3f target(entity->location() - render::Camera::eye());
- if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75 ) {
+ if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75) {
draw_offscreen_target(entity, is_active_target);
return;
}
@@ -123,7 +123,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
float cx = render::State::width() * (0.5 - center.y());
float cy = render::State::height() * (0.5 - center.z() * render::State::aspect());
- if ((cx < 0 ) || (cy < 0) || (cx > render::State::width()) || (cy > render::State::height())) {
+ if ((cx < 0) || (cy < 0) || (cx > render::State::width()) || (cy > render::State::height())) {
draw_offscreen_target(entity, is_active_target);
return;
}
@@ -136,18 +136,18 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// outer square shadow
gl::color(0, 0, 0, 1);
gl::begin(gl::LineLoop);
- gl::vertex(cx+r, cy+2);
- gl::vertex(cx, cy+r+2);
- gl::vertex(cx-r, cy+2);
- gl::vertex(cx, cy-r+2);
+ gl::vertex(cx + r, cy + 2);
+ gl::vertex(cx, cy + r + 2);
+ gl::vertex(cx - r, cy + 2);
+ gl::vertex(cx, cy - r + 2);
gl::end();
if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) {
gl::begin(gl::LineLoop);
- gl::vertex(cx+ (r*0.25f), cy+2);
- gl::vertex(cx, cy+(r*0.25f)+2);
- gl::vertex(cx-(r*0.25f), cy+2);
- gl::vertex(cx, cy-(r*0.25f)+2);
+ gl::vertex(cx + (r*0.25f), cy + 2);
+ gl::vertex(cx, cy + (r*0.25f) + 2);
+ gl::vertex(cx - (r*0.25f), cy + 2);
+ gl::vertex(cx, cy - (r*0.25f) + 2);
gl::end();
}
@@ -161,28 +161,28 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// outer square0
gl::begin(gl::LineLoop);
- gl::vertex(cx+r, cy);
- gl::vertex(cx, cy+r);
- gl::vertex(cx-r, cy);
- gl::vertex(cx, cy-r);
+ gl::vertex(cx + r, cy);
+ gl::vertex(cx, cy + r);
+ gl::vertex(cx - r, cy);
+ gl::vertex(cx, cy - r);
gl::end();
-
+
if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) {
gl::begin(gl::LineLoop);
- gl::vertex(cx+(r*0.25f), cy);
- gl::vertex(cx, cy+(r*0.25f));
- gl::vertex(cx-(r*0.25f), cy);
- gl::vertex(cx, cy-(r*0.25f));
+ gl::vertex(cx + (r*0.25f), cy);
+ gl::vertex(cx, cy + (r*0.25f));
+ gl::vertex(cx - (r*0.25f), cy);
+ gl::vertex(cx, cy - (r*0.25f));
gl::end();
}
-
+
gl::enable(GL_TEXTURE_2D);
if (is_active_target) {
// entity name and distance
std::stringstream strdistance;
float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius();
- if (d > 0 ) {
+ if (d > 0) {
if (d > 100.0f) {
strdistance << roundf(d * 0.1f) << "km";
} else {
@@ -197,8 +197,8 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
if (ec->owner()) {
render::Text::setcolor('B');
- render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
- cy-r-4-2*render::Text::fontheight(), ec->owner()->name());
+ render::Text::draw(cx - aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
+ cy - r - 4 - 2*render::Text::fontheight(), ec->owner()->name());
}
render::Text::setcolor('B');
@@ -209,24 +209,24 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
render::Text::setcolor('N');
}
- render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
- cy-r-4-render::Text::fontheight(), entity->name());
+ render::Text::draw(cx - aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
+ cy - r - 4 - render::Text::fontheight(), entity->name());
render::Text::draw(cx - aux::text_length(strdistance.str()) * render::Text::fontwidth() * 0.5f,
- cy+r+4, strdistance);
+ cy + r + 4, strdistance);
}
}
bool HUD::on_keypress(const int key, const unsigned int modifier)
{
- switch( key ) {
- case SDLK_ESCAPE:
- if (targets::current()) {
- targets::reset();
- } else {
- ui::root()->show_menu("game");
- }
- return true;
+ switch (key) {
+ case SDLK_ESCAPE:
+ if (targets::current()) {
+ targets::reset();
+ } else {
+ ui::root()->show_menu("game");
+ }
+ return true;
}
return false;
@@ -238,21 +238,21 @@ void HUD::draw()
std::stringstream status;
if (core::localcontrol() && (input::mouse_control || input::joystick_control) &&
- (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
+ (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
hud_center->set_visible(true);
} else {
hud_center->set_visible(false);
}
-
+
gl::enable(GL_TEXTURE_2D);
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
-
+
core::Zone *zone = core::localcontrol()->zone();
// draw HUD targets
- for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
+ for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
if (entity == targets::current()) {
@@ -261,11 +261,12 @@ void HUD::draw()
} else if (entity == core::localplayer()->mission_target()) {
draw_target(entity, false);
- } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))){
+ } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))) {
draw_target(entity, false);
}
}
+ /*
unsigned int state = core::localcontrol()->state();
if (state) {
std::stringstream statestr;
@@ -275,13 +276,14 @@ void HUD::draw()
} else if (state == core::Entity::Impulse) {
//statestr << "^FKinetic impulse";
} else if (state == core::Entity::JumpInitiate) {
- statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer();
+ statestr << "^FInitializing hyperspace jump drive " << core::localcontrol()->timer();
} else if (state == core::Entity::Jump) {
statestr << "^FJumping...";
}
- Text::draw(4, render::State::height() - Text::fontheight()*3-4, statestr);
+ Text::draw(4, render::State::height() - Text::fontheight()*3 - 4, statestr);
}
+ */
core::Entity *target = targets::current();
std::stringstream strdistance;
@@ -290,10 +292,10 @@ void HUD::draw()
std::stringstream strtarget;
strtarget << "^B" << target->name() << "\n^B";
- float d = math::distance(core::localcontrol()->location(), target->location())
- - target->radius() - core::localcontrol()->radius();
+ float d = math::distance(core::localcontrol()->location(), target->location())
+ - target->radius() - core::localcontrol()->radius();
- if (d > 0 ) {
+ if (d > 0) {
strtarget << "^Ndist:^B ";
if (d > 100.0f) {
strtarget << roundf(d * 0.1f) << "km";
@@ -303,7 +305,7 @@ void HUD::draw()
if (core::localcontrol()->speed() > 0.1f) {
strtarget << "^N eta:^B ";
- float eta = floorf(d / core::localcontrol()->speed() );
+ float eta = floorf(d / core::localcontrol()->speed());
if (eta > 60.0f) {
float etamin = floorf(eta / 60.0f);
strtarget << etamin << "min ";
@@ -315,13 +317,13 @@ void HUD::draw()
strtarget << " --";
}
strtarget << '\n';
- Text::draw(width() - 4-Text::fontwidth()*30, height() - Text::fontheight()*2 -4, strtarget);
+ Text::draw(width() - 4 - Text::fontwidth()*30, height() - Text::fontheight()*2 - 4, strtarget);
}
- // draw player info
+ // draw player info
std::stringstream playerinfostr;
- playerinfostr <<"^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
- Text::draw(width() - 4-Text::fontwidth()*52, height() - Text::fontheight()*2 -4, playerinfostr);
+ playerinfostr << "^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
+ Text::draw(width() - 4 - Text::fontwidth()*52, height() - Text::fontheight()*2 - 4, playerinfostr);
Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
gl::color(1, 1, 1, 1);
@@ -342,14 +344,23 @@ void HUD::draw()
gl::end();
float u = core::localcontrol()->thrust();
- if (core::localcontrol()->state() == core::Entity::Impulse) {
- u = 1.0;
+
+ 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 ((u > 0) || (core::localcontrol()->state() == core::Entity::Impulse)) {
- if (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) {
@@ -379,11 +390,11 @@ void HUD::draw()
std::stringstream speedstr;
speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
- Text::draw( 316+4+10, height() - 6 -16 - render::Text::fontwidth() /2, speedstr);
+ Text::draw(316 + 4 + 10, height() - 6 - 16 - render::Text::fontwidth() / 2, speedstr);
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
-
+
gl::disable(GL_TEXTURE_2D);
}