Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-12-20 14:52:10 +0000
committerStijn Buys <ingar@osirion.org>2008-12-20 14:52:10 +0000
commit62e480c2d887aae67add7ee7aed68463be897811 (patch)
tree6021c5d45e83d1bb858d2f0b3fcfff6490a79d78 /src
parent11229dcfef77baab5a7a3893a7c6281fbc5f7211 (diff)
map targetting
Diffstat (limited to 'src')
-rw-r--r--src/client/map.cc104
-rw-r--r--src/client/map.h11
-rw-r--r--src/client/targets.cc2
-rw-r--r--src/client/targets.h2
-rw-r--r--src/client/view.cc10
5 files changed, 87 insertions, 42 deletions
diff --git a/src/client/map.cc b/src/client/map.cc
index 1183457..4613ab7 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -8,6 +8,7 @@
#include "core/application.h"
#include "client/map.h"
#include "client/targets.h"
+#include "client/input.h"
#include "ui/paint.h"
#include "render/gl.h"
#include "render/textures.h"
@@ -26,6 +27,13 @@ Map::~Map()
{
}
+void Map::hide()
+{
+ ui::Widget::hide();
+ map_hover = 0;
+
+}
+
void Map::toggle()
{
if (visible())
@@ -45,6 +53,7 @@ void Map::draw()
math::Vector2f v(global_location());
v.x += margin;
v.y += margin;
+ map_hover = 0;
if (h > s ) {
v.y += (h-s) * 0.5f;
@@ -76,7 +85,9 @@ void Map::draw()
core::Zone *zone = core::localplayer()->zone();
- const float r = 24.0f;
+ const math::Vector2f cursor(input::mouse_position_x(), input::mouse_position_y());
+
+ const float r = 12.0f;
float scale = 2048.0f;
scale *= 2;
@@ -86,9 +97,11 @@ void Map::draw()
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
- bool draw_icon = false;
+ bool has_icon = false;
+ bool draw_icon = true;
+
if ((entity->model()) || (entity->type() == core::Entity::Globe)) {
- draw_icon = true;
+ has_icon = true;
if ((entity->type() == core::Entity::Dynamic) || (entity->type() == core::Entity::Controlable)) {
core::EntityDynamic *ed = dynamic_cast<core::EntityDynamic *>(entity);
@@ -110,52 +123,67 @@ void Map::draw()
}
}
- if (draw_icon) {
- if (entity->type() == core::Entity::Globe) {
- if ((entity->flags() & core::Entity::Bright) == core::Entity::Bright) {
- if (texture_current != texture_bright) {
- gl::end();
- texture_current = render::Textures::bind(texture_bright);
- gl::begin(gl::Quads);
+ if (has_icon) {
+ math::Vector2f l(v);
+ l.x -= s / scale * entity->location().y;
+ l.y -= s / scale * entity->location().x;
+
+ if (math::distancesquared(cursor, l) < (r*r)) {
+ map_hover = entity->id();
+ }
+
+ if (draw_icon) {
+ if (entity->type() == core::Entity::Globe) {
+ if ((entity->flags() & core::Entity::Bright) == core::Entity::Bright) {
+ if (texture_current != texture_bright) {
+ gl::end();
+ texture_current = render::Textures::bind(texture_bright);
+ gl::begin(gl::Quads);
+ }
+ } else {
+ if (texture_current != texture_globe) {
+ gl::end();
+ texture_current = render::Textures::bind(texture_globe);
+ gl::begin(gl::Quads);
+ }
}
} else {
- if (texture_current != texture_globe) {
+ if (texture_current != texture_entity) {
gl::end();
- texture_current = render::Textures::bind(texture_globe);
+ texture_current = render::Textures::bind(texture_entity);
gl::begin(gl::Quads);
}
}
- } else {
- if (texture_current != texture_entity) {
- gl::end();
- texture_current = render::Textures::bind(texture_entity);
- gl::begin(gl::Quads);
- }
- }
+
- math::Vector2f l(v);
- l.x -= s / scale * entity->location().y;
- l.y -= s / scale * entity->location().x;
-
- math::Color color(entity->color());
- color.a = 1.0f;
- gl::color(color);
- glTexCoord2f(0.0f, 0.0f);
- gl::vertex(l.x, l.y);
-
- glTexCoord2f(1.0f, 0.0f);
- gl::vertex(l.x+r, l.y);
-
- glTexCoord2f(1.0f, 1.0f);
- gl::vertex(l.x+r, l.y+r);
-
- glTexCoord2f(0.0f, 1.0f);
- gl::vertex(l.x, l.y+r);
-
+ math::Color color(entity->color());
+ color.a = 1.0f;
+ gl::color(color);
+ glTexCoord2f(0.0f, 0.0f);
+ gl::vertex(l.x-r, l.y-r);
+
+ glTexCoord2f(1.0f, 0.0f);
+ gl::vertex(l.x+r, l.y-r);
+
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(l.x+r, l.y+r);
+
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(l.x-r, l.y+r);
+ }
}
}
gl::end();
gl::disable(GL_TEXTURE_2D);
}
+bool Map::on_keypress(const int key, const unsigned int modifier)
+{
+ if ((hover()) && (key == 512 + SDL_BUTTON_LEFT)) {
+ targets::select_target(hover());
+ return true;
+ }
+
+ return false;
+}
} \ No newline at end of file
diff --git a/src/client/map.h b/src/client/map.h
index cbdc216..c7c1c29 100644
--- a/src/client/map.h
+++ b/src/client/map.h
@@ -17,10 +17,21 @@ public:
Map(ui::Widget *parent = 0);
virtual ~Map();
+ inline size_t hover() const { return map_hover; }
+
+ /// toggle the map window
void toggle();
+ /// hide the map window
+ virtual void hide();
+
+ /// called when the widget receives a key press
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
protected:
virtual void draw();
+
+ size_t map_hover;
};
diff --git a/src/client/targets.cc b/src/client/targets.cc
index c544e73..92e1294 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -324,7 +324,7 @@ void render_entity_sound(core::Entity *entity)
// render targets and sounds (in world coordinates)
-void draw()
+void frame()
{
core::Zone *zone = core::localplayer()->zone();
if (!zone)
diff --git a/src/client/targets.h b/src/client/targets.h
index 0366415..d13d67c 100644
--- a/src/client/targets.h
+++ b/src/client/targets.h
@@ -26,7 +26,7 @@ void reset();
bool is_legal_target(core::Entity *entity);
/// render targets and sounds
-void draw();
+void frame();
/// render sound listener properties
void render_listener_sound();
diff --git a/src/client/view.cc b/src/client/view.cc
index e7704f2..1c35708 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -273,8 +273,10 @@ void View::draw()
}
} else {
view_notify->set_visible(false);
-
view_chat->set_visible(false);
+ }
+
+ if (!core::localcontrol()) {
view_map->set_visible(false);
}
@@ -703,6 +705,10 @@ void set_cursor()
ui::root()->set_pointer();
+ } else if (client()->view()->map()->hover()) {
+
+ ui::root()->set_pointer("pointer");
+
} else if (render::Camera::mode() == render::Camera::Overview) {
ui::root()->set_pointer("aim");
@@ -748,7 +754,7 @@ void frame(float elapsed)
render::Camera::frustum();
render::draw(elapsed); // draw the world
- targets::draw(); // validate current target, render sound
+ targets::frame(); // validate current target, render sound
if (!core::localplayer()->view() && targets::current()) // draw target docks etc
draw_entity_world_target(targets::current());