diff options
Diffstat (limited to 'src/client/mapwidget.cc')
-rw-r--r-- | src/client/mapwidget.cc | 49 |
1 files changed, 49 insertions, 0 deletions
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 |