From cda61449e8d5ee83c050a357c6246652532026db Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 19 Jul 2020 00:05:03 +0200 Subject: Add target indicators and tooltips to the map. --- src/client/galaxymapwidget.cc | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/client/galaxymapwidget.cc') 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()) { -- cgit v1.2.3