Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@telenet.be>2020-07-19 00:05:03 +0200
committerStijn Buys <ingar@telenet.be>2020-07-19 00:05:03 +0200
commitcda61449e8d5ee83c050a357c6246652532026db (patch)
tree633507b58c94f8d4797cd6a1686a317c7bd041f7
parentae9160a0716d0cdcc72a3741e70aae3925c74add (diff)
Add target indicators and tooltips to the map.
-rw-r--r--src/client/galaxymapwidget.cc39
-rw-r--r--src/client/mapwidget.cc49
2 files changed, 87 insertions, 1 deletions
diff --git a/src/client/galaxymapwidget.cc b/src/client/galaxymapwidget.cc
index 25460b8..4bcf7c5 100644
--- a/src/client/galaxymapwidget.cc
+++ b/src/client/galaxymapwidget.cc
@@ -19,6 +19,9 @@ GalaxyMapWidget::GalaxyMapWidget(ui::Widget *parent) : ui::Widget(parent)
galaxymapwidget_zone = 0;
galaxymapwidget_hover_id = 0;
galaxymapwidget_zoom = 1.0f;
+
+ // make sure the map has a tooltip
+ set_tooltip();
}
GalaxyMapWidget::~GalaxyMapWidget()
@@ -112,11 +115,13 @@ void GalaxyMapWidget::draw()
// global mouse cursor location
const math::Vector2f cursor(ui::root()->global_mouse_coords());
galaxymapwidget_hover_id = 0;
+ set_tooltip();
// map center
//math::Vector2f map_center(map_location[0] + map_size / 2.0f, map_location[1] + map_size / 2.0f);
math::Vector2f icon_location;
- const float r = 12.0f; // radius of map icons
+ const float r = 12.0f; // radius of map icons
+ const float rt = 24.0f; // radius of target icons
float scale = 1024.0f; // galaxy size (in zone location units)
math::Color color(1.0f, 1.0f, 1.0f, 1.0f);
const core::Zone *zone = 0;
@@ -149,6 +154,7 @@ void GalaxyMapWidget::draw()
if (math::distancesquared(cursor, icon_location) < (r*r))
{
galaxymapwidget_hover_id = zone->id();
+ set_tooltip(zone->name());
}
if (zone == galaxymapwidget_zone)
@@ -180,6 +186,37 @@ void GalaxyMapWidget::draw()
}
gl::end();
+
+ if (galaxymapwidget_zone)
+ {
+ icon_location.assign(map_location);
+ icon_location[0] += map_size / scale * galaxymapwidget_zone->location().x();
+ icon_location[1] += map_size - map_size / scale * galaxymapwidget_zone->location().y(); // flip vertically
+
+ // draw target icon
+ const size_t texture_target = render::Textures::load("bitmaps/icons/map_target");
+ render::Textures::bind(texture_target);
+
+ gl::begin(gl::Quads);
+
+ math::Color color(1.0);
+ gl::color(color);
+
+ glTexCoord2f(0.0f, 0.0f);
+ gl::vertex(icon_location.x() - rt, icon_location.y() - rt);
+
+ glTexCoord2f(1.0f, 0.0f);
+ gl::vertex(icon_location.x() + rt, icon_location.y() - rt);
+
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(icon_location.x() + rt, icon_location.y() + rt);
+
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(icon_location.x() - rt, icon_location.y() + rt);
+
+ gl::end();
+ }
+
gl::disable(GL_TEXTURE_2D);
// if (has_mouse_focus()) {
diff --git a/src/client/mapwidget.cc b/src/client/mapwidget.cc
index 20bb979..49100b2 100644
--- a/src/client/mapwidget.cc
+++ b/src/client/mapwidget.cc
@@ -24,6 +24,9 @@ MapWidget::MapWidget(ui::Widget *parent) : ui::Widget(parent)
mapwidget_target = 0;
mapwidget_hover_id = 0;
mapwidget_zoom = 1.0f;
+
+ // make sure the map has a tooltip
+ set_tooltip();
}
MapWidget::~MapWidget()
@@ -43,6 +46,12 @@ void MapWidget::set_target(const core::Entity *entity)
void MapWidget::set_zone(core::Zone *zone)
{
mapwidget_zone = zone;
+
+ // verify current target
+ if (mapwidget_target && (mapwidget_zone != mapwidget_target->zone()))
+ {
+ mapwidget_target = nullptr;
+ }
}
bool MapWidget::on_mousepress(const unsigned int button)
@@ -124,11 +133,13 @@ void MapWidget::draw()
// global mouse cursor location
const math::Vector2f cursor(ui::root()->global_mouse_coords());
mapwidget_hover_id = 0;
+ set_tooltip();
// map center
math::Vector2f map_center(map_location[0] + map_size / 2.0f, map_location[1] + map_size / 2.0f);
math::Vector2f icon_location;
const float r = 12.0f; // radius of map icons
+ const float rt = 24.0f; // radius of target icons
float scale = 4096.0f; // map size in game units
math::Color color;
@@ -154,6 +165,7 @@ void MapWidget::draw()
if (math::distancesquared(cursor, icon_location) < (r*r))
{
mapwidget_hover_id = entity->id();
+ set_tooltip(entity->name());
}
if (entity == mapwidget_target)
@@ -264,6 +276,43 @@ void MapWidget::draw()
}
gl::end();
+
+ if (mapwidget_target)
+ {
+ // draw target icon
+ size_t texture_target = 0;
+ if (mapwidget_target->has_flag(core::Entity::Dockable))
+ {
+ texture_target = render::Textures::load("bitmaps/icons/map_dockable");
+ } else {
+ texture_target = render::Textures::load("bitmaps/icons/map_target");
+ }
+
+ icon_location.assign(map_center);
+ icon_location[0] -= map_size / scale * mapwidget_target->location().y();
+ icon_location[1] -= map_size / scale * mapwidget_target->location().x();
+
+ texture_current = render::Textures::bind(texture_target);
+
+ gl::begin(gl::Quads);
+
+ math::Color color(1.0);
+ gl::color(color);
+
+ glTexCoord2f(0.0f, 0.0f);
+ gl::vertex(icon_location.x() - rt, icon_location.y() - rt);
+
+ glTexCoord2f(1.0f, 0.0f);
+ gl::vertex(icon_location.x() + rt, icon_location.y() - rt);
+
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(icon_location.x() + rt, icon_location.y() + rt);
+
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(icon_location.x() - rt, icon_location.y() + rt);
+
+ gl::end();
+ }
// draw localcontrol icon
// TODO draw a ship icon