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>2009-03-08 14:52:42 +0000
committerStijn Buys <ingar@osirion.org>2009-03-08 14:52:42 +0000
commit974631a33120837165e6ad04bd0ff6acaec08ffa (patch)
treebf45e62947214df7c8e4fdb071e91ae95491fff7 /src/client
parente4618a1c7e5fb0629997d389cb941a61095490ac (diff)
target selection updates
Diffstat (limited to 'src/client')
-rw-r--r--src/client/hud.cc20
-rw-r--r--src/client/map.cc48
-rw-r--r--src/client/map.h2
-rw-r--r--src/client/targets.cc77
-rw-r--r--src/client/targets.h5
5 files changed, 81 insertions, 71 deletions
diff --git a/src/client/hud.cc b/src/client/hud.cc
index c1cd8c1..d0b7e0d 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -231,18 +231,18 @@ void HUD::draw()
core::Zone *zone = core::localcontrol()->zone();
- // draw targets
+ // draw HUD targets
for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
-
- if (targets::is_legal_target(entity)) {
- if (entity == core::localplayer()->mission_target()) {
- draw_target(entity, true);
- } else if (entity == targets::current()) {
- draw_target(entity, true);
- } else if (entity->type() == core::Entity::Controlable) {
- draw_target(entity, false);
- }
+
+ if (entity == targets::current()) {
+ draw_target(entity, true);
+
+ } else if (entity == core::localplayer()->mission_target()) {
+ draw_target(entity, false);
+
+ } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))){
+ draw_target(entity, false);
}
}
diff --git a/src/client/map.cc b/src/client/map.cc
index 6384588..10a207c 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -9,6 +9,7 @@
#include "core/application.h"
#include "client/map.h"
#include "client/input.h"
+#include "client/targets.h"
#include "ui/ui.h"
#include "ui/paint.h"
#include "render/gl.h"
@@ -17,6 +18,21 @@
namespace client {
+bool is_valid_map_target(core::Entity *entity)
+{
+ if (entity->serverside()) {
+ return false;
+ } else if (entity == core::localcontrol()) {
+ return false;
+ } else if (entity->flag_is_set(core::Entity::ShowOnMap)) {
+ return true;
+ } else if (entity == core::localplayer()->mission_target()) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
Map::Map(ui::Widget *parent) : ui::Window(parent)
{
set_label("map");
@@ -24,7 +40,7 @@ Map::Map(ui::Widget *parent) : ui::Window(parent)
set_background(true);
set_font(ui::root()->font_small());
- map_target = 0;
+ //map_target = 0;
map_hover = 0;
hide();
}
@@ -37,7 +53,7 @@ void Map::hide()
{
ui::Window::hide();
map_hover = 0;
- map_target = 0;
+ //map_target = 0;
}
void Map::toggle()
@@ -47,6 +63,7 @@ void Map::toggle()
else
show();
}
+
void Map::draw()
{
const float margin = font()->width() * 2.0f;
@@ -113,7 +130,7 @@ void Map::draw()
bool draw_icon = false;
l.assign(v);
- if (entity->flag_is_set(core::Entity::ShowOnMap)) {
+ if (is_valid_map_target(entity)) {
draw_icon = true;
l.x -= s / scale * entity->location().y;
l.y -= s / scale * entity->location().x;
@@ -122,7 +139,7 @@ void Map::draw()
map_hover = entity->id();
}
- if (entity == map_target) {
+ if (entity == targets::current()) {
valid_target = true;
if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
draw_icon = false;
@@ -156,9 +173,14 @@ void Map::draw()
gl::begin(gl::Quads);
}
}
-
- color.assign(entity->color());
+
+ if (entity == core::localplayer()->mission_target()) {
+ color.assign(palette()->mission());
+ } else {
+ color.assign(entity->color());
+ }
color.a = 1.0f;
+
gl::color(color);
glTexCoord2f(0.0f, 0.0f);
gl::vertex(l.x-r, l.y-r);
@@ -206,9 +228,7 @@ void Map::draw()
gl::end();
- if (!valid_target) {
- map_target = 0;
- } else {
+ if (targets::current()) {
l.assign(v);
if (h > s ) {
@@ -227,7 +247,7 @@ void Map::draw()
render::Text::setcolor('B');
render::Text::setfont(font()->name().c_str(), font()->width(), font()->height());
- render::Text::draw(l.x, l.y, map_target->name());
+ render::Text::draw(l.x, l.y, targets::current()->name());
render::Text::setcolor('N');
}
@@ -238,10 +258,10 @@ bool Map::on_keypress(const int key, const unsigned int modifier)
{
if (key == 512 + SDL_BUTTON_LEFT) {
if (hover()) {
- map_target = core::localplayer()->zone()->find_entity(hover());
- if (map_target) {
- audio::play("ui/target");
- }
+ core::Entity *target = core::localplayer()->zone()->find_entity(hover());
+ if (is_valid_map_target(target)) {
+ targets::select_target(target);
+ }
}
return true;
diff --git a/src/client/map.h b/src/client/map.h
index 37da19a..b7b60cc 100644
--- a/src/client/map.h
+++ b/src/client/map.h
@@ -33,8 +33,6 @@ protected:
virtual void draw();
unsigned int map_hover;
-
- core::Entity *map_target;
};
diff --git a/src/client/targets.cc b/src/client/targets.cc
index af49826..08c0e14 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -39,29 +39,18 @@ unsigned int current_hover = 0;
core::Entity *current_target = 0;
core::Cvar *snd_engines = 0;
-
-bool is_legal_target(core::Entity *entity)
+bool is_valid_hud_target(core::Entity *entity)
{
+
if (entity->serverside()) {
return false;
} else if (!ext_render(entity)) {
return false;
- } else if (entity == core::localplayer()->mission_target()) {
- return true;
} else if (entity == core::localcontrol()) {
return false;
- } else if (ext_render(entity)->distance() < 0.001f) {
- return false;
} else {
- if (entity->type() != core::Entity::Controlable) {
- return ext_render(entity)->visible();
-
- } else if (ext_render(entity)->distance() < core::range::visible) {
- return true;
- }
+ return ext_render(entity)->visible();
}
-
- return false;
}
core::Entity* current()
@@ -122,7 +111,7 @@ void func_target_next(std::string const &args)
// first entity
it = zone->content().begin();
- while (!is_legal_target((*it)) && it != zone->content().end())
+ while (!is_valid_hud_target((*it)) && it != zone->content().end())
it++;
} else {
@@ -136,7 +125,7 @@ void func_target_next(std::string const &args)
if (it == zone->content().end()) {
it = zone->content().begin();
}
- while (!is_legal_target((*it))) {
+ while (!is_valid_hud_target((*it))) {
it++;
if (it == zone->content().end())
it = zone->content().begin();
@@ -175,7 +164,7 @@ void func_target_prev(std::string const &args)
if (!current_target_id) {
// last entity
rit = zone->content().rbegin();
- while (!is_legal_target((*rit)) && rit != zone->content().rend())
+ while (!is_valid_hud_target((*rit)) && rit != zone->content().rend())
rit++;
} else {
// current entity
@@ -188,7 +177,7 @@ void func_target_prev(std::string const &args)
if (rit == zone->content().rend()) {
rit = zone->content().rbegin();
}
- while (!is_legal_target((*rit))) {
+ while (!is_valid_hud_target((*rit))) {
++rit;
if (rit == zone->content().rend())
rit = zone->content().rbegin();
@@ -230,7 +219,7 @@ void func_target_center(std::string const &args)
math::Vector3f v(entity->location() - render::Camera::eye());
v.normalize();
- if (is_legal_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85 ) {
+ if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85 ) {
// calculate the distance from entity location to the line [eye - cursor]
float d = math::Vector3f::length(math::crossproduct( (center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye());
@@ -368,36 +357,36 @@ void frame()
}
// find the current target
- if (!core::localplayer()->view() && core::localcontrol() && is_legal_target(entity)) {
+ if (!core::localplayer()->view() && core::localcontrol()) {
if (entity->id() == current_target_id) {
current_target = entity;
- }
-
- // check if the mouse is hovering the entity
- Vector3f v(entity->location() - render::Camera::eye());
- v.normalize();
-
- if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
- // calculate the distance from entity location to the line [eye - cursor]
- float d = math::Vector3f::length(math::crossproduct( (cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye());
+ // check if the mouse is hovering the entity
+ Vector3f v(entity->location() - render::Camera::eye());
+ v.normalize();
+
+ if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
+
+ // calculate the distance from entity location to the line [eye - cursor]
+ float d = math::Vector3f::length(math::crossproduct( (cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye());
+
+ float r = entity->radius() * 0.5f;
+
+ if (ext_render(entity)->distance() > 512.0f)
+ math::clamp(r, 8.0f,r);
+ else if (ext_render(entity)->distance() > 256.0f)
+ math::clamp(r, 4.0f,r);
+ else if (ext_render(entity)->distance() > 128.0f)
+ math::clamp(r, 2.0f,r);
- float r = entity->radius() * 0.5f;
-
- if (ext_render(entity)->distance() > 512.0f)
- math::clamp(r, 8.0f,r);
- else if (ext_render(entity)->distance() > 256.0f)
- math::clamp(r, 4.0f,r);
- else if (ext_render(entity)->distance() > 128.0f)
- math::clamp(r, 2.0f,r);
-
- // if the cursor-beam hits the entity sphere
- if (d < r) {
- float myz = math::distance(cursor, entity->location());
- if (z < 0 || myz < z) {
- current_hover = entity->id();
- z = myz;
+ // if the cursor-beam hits the entity sphere
+ if (d < r) {
+ float myz = math::distance(cursor, entity->location());
+ if (z < 0 || myz < z) {
+ current_hover = entity->id();
+ z = myz;
+ }
}
}
}
diff --git a/src/client/targets.h b/src/client/targets.h
index d13d67c..67ee742 100644
--- a/src/client/targets.h
+++ b/src/client/targets.h
@@ -23,7 +23,7 @@ void shutdown();
void reset();
/// return true if the entity is a legal target
-bool is_legal_target(core::Entity *entity);
+bool is_valid_hud_target(core::Entity *entity);
/// render targets and sounds
void frame();
@@ -46,6 +46,9 @@ unsigned int hover();
/// target a specific entity
void select_target(unsigned int id);
+/// target a specific entity
+void select_target(core::Entity *entity);
+
}
}