From 60b0e02ab6b8910b3870d16a6eef9d67c6a6f34e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 7 Oct 2012 21:46:02 +0000 Subject: Add galactic map, make it possible to other zones on the map. --- src/client/mapwidget.cc | 65 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'src/client/mapwidget.cc') diff --git a/src/client/mapwidget.cc b/src/client/mapwidget.cc index 5f5d5d6..44ec32a 100644 --- a/src/client/mapwidget.cc +++ b/src/client/mapwidget.cc @@ -5,6 +5,7 @@ */ #include "client/mapwidget.h" +#include "client/targets.h" #include "core/application.h" #include "ui/paint.h" #include "render/render.h" @@ -42,6 +43,22 @@ void MapWidget::set_zone(core::Zone *zone) mapwidget_zone = zone; } +bool MapWidget::on_keypress(const int key, const unsigned int modifier) +{ + if (key == 512 + SDL_BUTTON_LEFT) { + if (mapwidget_zone && has_mouse_focus() && hover()) { + core::Entity *target = mapwidget_zone->find_entity(hover()); + + if (targets::is_valid_map_target(target)) { + set_target(target); + emit(ui::Widget::EventClicked); + } + } + return true; + + } + return false; +} void MapWidget::draw() { if (!mapwidget_zone) @@ -170,39 +187,41 @@ void MapWidget::draw() } } + gl::end(); // draw localcontrol icon - entity = core::localcontrol(); + // TODO draw a ship icon + if (core::localcontrol()->zone() == mapwidget_zone) { + entity = core::localcontrol(); - //if (core::localcontrol()->state() != core::Entity::Docked) { - icon_location.assign(map_center); - icon_location[0] -= map_size / scale * entity->location().y(); - icon_location[1] -= map_size / scale * entity->location().x(); - - if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { - if (texture_current != texture_entity) { - gl::end(); + //if (core::localcontrol()->state() != core::Entity::Docked) { + icon_location.assign(map_center); + icon_location[0] -= map_size / scale * entity->location().y(); + icon_location[1] -= map_size / scale * entity->location().x(); + + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { texture_current = render::Textures::bind(texture_entity); gl::begin(gl::Quads); - } - - math::Color color(entity->color()); - color.a = 1.0f; - gl::color(color); - glTexCoord2f(0.0f, 0.0f); - gl::vertex(icon_location.x() - r, icon_location.y() - r); + + math::Color color(entity->color()); + color.a = 1.0f; + gl::color(color); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(icon_location.x() - r, icon_location.y() - r); - glTexCoord2f(1.0f, 0.0f); - gl::vertex(icon_location.x() + r, icon_location.y() - r); + glTexCoord2f(1.0f, 0.0f); + gl::vertex(icon_location.x() + r, icon_location.y() - r); - glTexCoord2f(1.0f, 1.0f); - gl::vertex(icon_location.x() + r, icon_location.y() + r); + glTexCoord2f(1.0f, 1.0f); + gl::vertex(icon_location.x() + r, icon_location.y() + r); - glTexCoord2f(0.0f, 1.0f); - gl::vertex(icon_location.x() - r, icon_location.y() + r); + glTexCoord2f(0.0f, 1.0f); + gl::vertex(icon_location.x() - r, icon_location.y() + r); + + gl::end(); + } } - gl::end(); gl::disable(GL_TEXTURE_2D); if (has_mouse_focus()) { -- cgit v1.2.3