Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-10-07 21:46:02 +0000
committerStijn Buys <ingar@osirion.org>2012-10-07 21:46:02 +0000
commit60b0e02ab6b8910b3870d16a6eef9d67c6a6f34e (patch)
tree8702424723a66ad2d65298d63160ef25ef83898e
parente065de3bf7f15b895c7a22e9fdbf8125c94406b3 (diff)
Add galactic map, make it possible to other zones on the map.
-rw-r--r--src/client/Makefile.am2
-rw-r--r--src/client/galaxymapwidget.cc164
-rw-r--r--src/client/galaxymapwidget.h49
-rw-r--r--src/client/mapwidget.cc65
-rw-r--r--src/client/mapwidget.h17
-rw-r--r--src/client/mapwindow.cc265
-rw-r--r--src/client/mapwindow.h24
7 files changed, 482 insertions, 104 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 77ff3c3..7b3c69b 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -16,6 +16,7 @@ noinst_HEADERS = \
client.h \
clientext.h \
entitymenu.h \
+ galaxymapwidget.h \
gamewindow.h \
hud.h \
infowidget.h \
@@ -46,6 +47,7 @@ libclient_la_SOURCES = \
client.cc \
clientext.cc \
entitymenu.cc \
+ galaxymapwidget.cc \
gamewindow.cc \
hud.cc \
infowidget.cc \
diff --git a/src/client/galaxymapwidget.cc b/src/client/galaxymapwidget.cc
new file mode 100644
index 0000000..508567a
--- /dev/null
+++ b/src/client/galaxymapwidget.cc
@@ -0,0 +1,164 @@
+/*
+ client/galaxymapwidget.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "client/galaxymapwidget.h"
+#include "core/application.h"
+#include "ui/paint.h"
+#include "render/render.h"
+#include "render/gl.h"
+#include "ui/ui.h"
+
+namespace client {
+
+GalaxyMapWidget::GalaxyMapWidget(ui::Widget *parent) : ui::Widget(parent)
+{
+ set_label("galaxymapwidget");
+ galaxymapwidget_zone = 0;
+ galaxymapwidget_hover_id = 0;
+ galaxymapwidget_zoom = 1.0f;
+}
+
+GalaxyMapWidget::~GalaxyMapWidget()
+{
+
+}
+
+void GalaxyMapWidget::set_zoom(const float zoom)
+{
+ galaxymapwidget_zoom = zoom;
+}
+
+void GalaxyMapWidget::set_zone(core::Zone *zone)
+{
+ galaxymapwidget_zone = zone;
+}
+
+bool GalaxyMapWidget::on_keypress(const int key, const unsigned int modifier)
+{
+ if (key == 512 + SDL_BUTTON_LEFT) {
+ if (has_mouse_focus() && hover()) {
+ if (zone() && (zone()->id() == hover())) {
+ emit(ui::Widget::EventDoubleClicked);
+ } else {
+ set_zone(core::Zone::find(hover()));
+ emit(ui::Widget::EventClicked);
+ }
+ }
+ return true;
+
+ }
+ return false;
+}
+
+void GalaxyMapWidget::draw()
+{
+ // size and global location of the map
+ const float map_size = math::min(width(), height());
+ math::Vector2f map_location(global_location());
+
+ if (map_size < width()) {
+ map_location[0] += (width() - map_size) * 0.5f;
+ }
+ if (map_size < height()) {
+ map_location[1] += (height() - map_size) * 0.5f;
+ }
+
+ // draw background
+ math::Vector2f background_size(map_size, map_size);
+ ui::Paint::draw_material(map_location, background_size, "ui/background");
+
+ // number of squares in one grid segment
+ const float grid_size = 16.0f;
+
+ // draw the grid itself
+ gl::color(0, 0, 0.8f);
+ gl::begin(gl::Lines);
+
+ for (float i = 0; i <= grid_size; i += 1.0f) {
+ gl::vertex(map_location.x(), map_location.y() + map_size / grid_size * i);
+ gl::vertex(map_location.x() + map_size, map_location.y() + map_size / grid_size * i);
+
+ gl::vertex(map_location.x() + map_size / grid_size * i, map_location.y());
+ gl::vertex(map_location.x() + map_size / grid_size * i, map_location.y() + map_size);
+ }
+ gl::end();
+
+ // request required textures
+ const size_t texture_zone = render::Textures::load("bitmaps/icons/entity_default");
+ render::Textures::bind(texture_zone);
+
+ // global mouse cursor location
+ const math::Vector2f cursor(ui::root()->global_mouse_coords());
+ galaxymapwidget_hover_id = 0;
+
+ // 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
+ 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;
+
+ // draw map icons
+ /*
+ * Note: the galactic coordinate system differs from the zone coordinate system:
+ * positive X-axis runs left-to-right on the screen and the positive U-axis runs bottom-to-top on the screen.
+ *
+ * This is because I'm lazy and I just copy the coordinates from the SVG starsystem roadmap as shown in Inkscape.
+ */
+ gl::enable(GL_TEXTURE_2D);
+ gl::begin(gl::Quads);
+
+
+ for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
+ zone = (*it).second;
+
+ bool draw_icon = true;
+
+ icon_location.assign(map_location);
+ icon_location[0] += map_size / scale * zone->location().x();
+ icon_location[1] += map_size - map_size / scale * zone->location().y(); // flip vertically
+
+ if (math::distancesquared(cursor, icon_location) < (r*r)) {
+ galaxymapwidget_hover_id = zone->id();
+ }
+
+ if (zone == galaxymapwidget_zone) {
+ if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
+ draw_icon = false;
+ }
+ }
+ // TODO draw a ship icon for current location
+ if (draw_icon) {
+ gl::begin(gl::Quads);
+
+ 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, 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::disable(GL_TEXTURE_2D);
+
+ if (has_mouse_focus()) {
+ if (galaxymapwidget_hover_id)
+ ui::root()->set_pointer("target", ui::Palette::Active, true);
+ }
+}
+
+} // namespace client
+
diff --git a/src/client/galaxymapwidget.h b/src/client/galaxymapwidget.h
new file mode 100644
index 0000000..3e74903
--- /dev/null
+++ b/src/client/galaxymapwidget.h
@@ -0,0 +1,49 @@
+/*
+ client/mapwidget.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_GALAXYMAPWIDGET_H__
+#define __INCLUDED_CLIENT_GALAXYMAPWIDGET_H__
+
+#include "core/zone.h"
+#include "ui/widget.h"
+
+namespace client {
+
+class GalaxyMapWidget : public ui::Widget
+{
+public:
+ GalaxyMapWidget(ui::Widget *parent = 0);
+
+ virtual ~GalaxyMapWidget();
+
+ void set_zoom(const float zoom);
+
+ void set_zone(core::Zone *zone);
+
+ inline unsigned int hover() const {
+ return galaxymapwidget_hover_id;
+ }
+
+ inline core::Zone *zone() const {
+ return galaxymapwidget_zone;
+ }
+
+protected:
+ virtual void draw();
+
+ /// called when the widget receives a key press
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
+private:
+ float galaxymapwidget_zoom;
+
+ core::Zone *galaxymapwidget_zone;
+ unsigned int galaxymapwidget_hover_id;
+
+}; // class GalaxyMapWidget
+
+} // namespace client
+#endif // __INCLUDED_CLIENT_GALAXYMAPWIDGET_H__
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()) {
diff --git a/src/client/mapwidget.h b/src/client/mapwidget.h
index fb5a905..0482330 100644
--- a/src/client/mapwidget.h
+++ b/src/client/mapwidget.h
@@ -12,9 +12,11 @@
namespace client {
-class MapWidget : public ui::Widget {
+class MapWidget : public ui::Widget
+{
public:
MapWidget(ui::Widget *parent = 0);
+
virtual ~MapWidget();
void set_zoom(const float zoom);
@@ -23,13 +25,24 @@ public:
void set_target(const core::Entity *entity);
- inline unsigned int hover() {
+ inline unsigned int hover() const {
return mapwidget_hover_id;
}
+
+ inline const core::Entity *target() const {
+ return mapwidget_target;
+ }
+
+ inline core::Zone *zone() const {
+ return mapwidget_zone;
+ }
protected:
virtual void draw();
+ /// called when the widget receives a key press
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
private:
float mapwidget_zoom;
diff --git a/src/client/mapwindow.cc b/src/client/mapwindow.cc
index ed88f88..1c429dd 100644
--- a/src/client/mapwindow.cc
+++ b/src/client/mapwindow.cc
@@ -41,14 +41,24 @@ MapWindow::MapWindow(ui::Widget *parent) : ui::Window(parent)
mapwindow_mapwidget = new MapWidget(this);
mapwindow_mapwidget->set_background(false);
mapwindow_mapwidget->set_border(false);
-
- // map label (map widget child)
- mapwindow_maplabel = new ui::Label(mapwindow_mapwidget);
+
+ // galaxy map widget
+ mapwindow_galaxymapwidget = new GalaxyMapWidget(this);
+ mapwindow_galaxymapwidget->set_background(false);
+ mapwindow_galaxymapwidget->set_border(false);
+ mapwindow_galaxymapwidget->hide();
+
+ // map label
+ mapwindow_maplabel = new ui::Label(this);
mapwindow_maplabel->set_label("maplabel");
mapwindow_maplabel->set_background(false);
mapwindow_maplabel->set_border(false);
mapwindow_maplabel->set_alignment(ui::AlignCenter);
+ // map buttons
+ mapwindow_zonebutton = new ui::IconButton(this, "bitmaps/icons/button_map");
+ mapwindow_galaxybutton = new ui::IconButton(this, "bitmaps/icons/button_galaxy");
+
// modelview
mapwindow_modelview = new ui::ModelView(this);
mapwindow_modelview->set_label("modelview");
@@ -56,7 +66,7 @@ MapWindow::MapWindow(ui::Widget *parent) : ui::Window(parent)
mapwindow_modelview->set_border(false);
// target title (modelview child)
- mapwindow_targetlabel = new ui::Label(mapwindow_modelview);
+ mapwindow_targetlabel = new ui::Label(this);
mapwindow_targetlabel->set_label("targetlabel");
mapwindow_targetlabel->set_background(false);
mapwindow_targetlabel->set_border(false);
@@ -68,7 +78,6 @@ MapWindow::MapWindow(ui::Widget *parent) : ui::Window(parent)
mapwindow_scrollpane->set_border(false);
mapwindow_scrollpane->set_alignment(ui::AlignTop);
- set_target(0);
hide();
}
@@ -79,17 +88,32 @@ MapWindow::~MapWindow()
void MapWindow::hide()
{
ui::Window::hide();
- mapwindow_target = 0;
}
void MapWindow::show()
{
ui::Window::show();
+
+ // show map widget
+ mapwindow_mode = ShowZone;
+ mapwindow_galaxymapwidget->hide();
+ mapwindow_mapwidget->show();
+ mapwindow_mapwidget->set_zone(core::localplayer()->zone());
+ mapwindow_maplabel->set_text(mapwindow_mapwidget->zone()->name());
+
+ // use current HUD target as default selection
if (core::localplayer()->view()) {
- set_target(core::localplayer()->view());
+ mapwindow_mapwidget->set_target(core::localplayer()->view());
} else {
- set_target(targets::current());
+ mapwindow_mapwidget->set_target(targets::current());
}
+
+ // show target or zone info
+ if (mapwindow_mapwidget->target()) {
+ show_entity_info(mapwindow_mapwidget->target());
+ } else {
+ show_zone_info(mapwindow_mapwidget->zone());
+ }
}
void MapWindow::toggle()
@@ -103,6 +127,7 @@ void MapWindow::toggle()
void MapWindow::resize()
{
const float padding = ui::root()->font_large()->height();
+ const float icon_size = 24.0f; // small icons
// resize title label
mapwindow_titlelabel->set_size(width() - padding * 2.0f, mapwindow_titlelabel->font()->height());
@@ -112,32 +137,46 @@ void MapWindow::resize()
mapwindow_closebutton->set_size(mapwindow_titlelabel->font()->height(), mapwindow_titlelabel->font()->height());
mapwindow_closebutton->set_location(mapwindow_titlelabel->width() - mapwindow_closebutton->width(), 0);
- // resize map widget
- mapwindow_mapwidget->set_size((width() - padding * 3.0f) * 0.5f, height() - mapwindow_titlelabel->bottom() - padding * 2.0f );
- mapwindow_mapwidget->set_location(padding, mapwindow_titlelabel->bottom() + padding);
+ // resize map label
+ mapwindow_maplabel->set_size((width() - padding * 3.0f) * 0.5f, padding );
+ mapwindow_maplabel->set_location(padding, mapwindow_titlelabel->bottom() + padding);
- // resize map label (map widget child)
- mapwindow_maplabel->set_size(mapwindow_mapwidget->width(), mapwindow_maplabel->font()->height());
- mapwindow_maplabel->set_location(0, 0);
+ // resize zone map widget
+ mapwindow_mapwidget->set_size(mapwindow_maplabel->width(), mapwindow_zonebutton->top() - mapwindow_maplabel->bottom() - 2.0f * padding);
+ mapwindow_mapwidget->set_location(mapwindow_maplabel->left(), mapwindow_maplabel->bottom() + padding);
- // resize target modelview
- mapwindow_modelview->set_size(width() - mapwindow_mapwidget->right() - padding * 2.0f, (height() - mapwindow_titlelabel->bottom() - padding * 3.0f) * 0.5f);
- mapwindow_modelview->set_location(mapwindow_mapwidget->right() + padding, mapwindow_titlelabel->bottom() + padding);
+ // set galaxy map size equal to zone map size
+ mapwindow_galaxymapwidget->set_geometry(mapwindow_mapwidget->location(), mapwindow_mapwidget->size());
- // resize target label (modelview child)
- mapwindow_targetlabel->set_size(mapwindow_modelview->width(), mapwindow_targetlabel->font()->height());
- mapwindow_targetlabel->set_location(0, 0);
+ // resize map buttons
+ float l = (mapwindow_mapwidget->width() - math::min(mapwindow_mapwidget->width(), mapwindow_mapwidget->height())) * 0.5f;
+
+ mapwindow_zonebutton->set_size(icon_size, icon_size);
+ mapwindow_zonebutton->set_location(mapwindow_maplabel->left() + l, height() - padding - mapwindow_zonebutton->height());
+
+ mapwindow_galaxybutton->set_size(icon_size, icon_size);
+ mapwindow_galaxybutton->set_location(mapwindow_maplabel->right() - l - mapwindow_galaxybutton->width(),
+ height() - padding - mapwindow_galaxybutton->height());
- // resize target infopane text
- mapwindow_scrollpane->set_size(width() - mapwindow_mapwidget->right() - padding * 2.0f, height() - mapwindow_modelview->bottom() - padding * 2.0f);
- mapwindow_scrollpane->set_location(mapwindow_mapwidget->right() + padding, mapwindow_modelview->bottom() + padding);
+ // resize target label
+ mapwindow_targetlabel->set_size(width() - mapwindow_mapwidget->right() - padding * 2.0f, padding);
+ mapwindow_targetlabel->set_location(mapwindow_maplabel->right() + padding, mapwindow_maplabel->top());
+
+ // resize target modelview
+ mapwindow_modelview->set_size(mapwindow_targetlabel->width(), (height() - mapwindow_targetlabel->bottom() - padding * 3.0f) * 0.5f);
+ mapwindow_modelview->set_location(mapwindow_mapwidget->right() + padding, mapwindow_targetlabel->bottom() + padding);
+
+ // resize target infopane text
+ mapwindow_scrollpane->set_size(mapwindow_modelview->size());
+ mapwindow_scrollpane->set_location(mapwindow_modelview->left(), mapwindow_modelview->bottom() + padding);
}
void MapWindow::draw()
{
ui::Window::draw();
+ /*
// make sure the target still exists
mapwindow_target = core::localplayer()->zone()->find_entity(mapwindow_target);
@@ -145,90 +184,109 @@ void MapWindow::draw()
mapwindow_mapwidget->set_target(mapwindow_target);
mapwindow_maplabel->set_text(core::localplayer()->zone()->name());
- if (mapwindow_target && mapwindow_target->info()) {
- if (mapwindow_infotimestamp != mapwindow_target->info()->timestamp()) {
+ */
+ if (mapwindow_inforecord) {
+ if (mapwindow_infotimestamp != mapwindow_inforecord->timestamp()) {
// update info
- set_target(mapwindow_target);
+ set_info(mapwindow_inforecord);
}
}
+
}
-void MapWindow::set_target(const core::Entity *entity) {
-
- mapwindow_target = entity;
+void MapWindow::set_info(const core::Info *info)
+{
+ mapwindow_inforecord = 0;
mapwindow_infotimestamp = 0;
- mapwindow_inforecord = 0;
mapwindow_infotext.clear();
- if (mapwindow_target) {
- // set title label to target name
- mapwindow_targetlabel->set_text(mapwindow_target->name());
+ if (info) {
+ mapwindow_inforecord = core::game()->request_info(info->id());
+ }
+
+ if (mapwindow_inforecord) {
+ for (core::Info::Text::const_iterator it = mapwindow_inforecord->text().begin(); it != mapwindow_inforecord->text().end(); it++) {
+ mapwindow_infotext.push_back((*it));
+ }
+ mapwindow_infotimestamp = mapwindow_inforecord->timestamp();
+ } else {
+ mapwindow_infotext.push_back("Information is not available");
+ mapwindow_infotimestamp = 0;
+ }
+}
+
+void MapWindow::show_entity_info(const core::Entity *entity)
+{
- if (mapwindow_target->info())
- mapwindow_inforecord = core::game()->request_info(mapwindow_target->info()->id());
- else
- mapwindow_inforecord = 0;
-
- if (mapwindow_inforecord) {
- for (core::Info::Text::const_iterator it = mapwindow_inforecord->text().begin(); it != mapwindow_inforecord->text().end(); it++) {
- mapwindow_infotext.push_back((*it));
- }
- mapwindow_infotimestamp = mapwindow_inforecord->timestamp();
- } else {
- mapwindow_infotext.push_back("Information is not available");
- mapwindow_infotimestamp = 0;
- }
-
- if (mapwindow_target->model()) {
+ if (core::localplayer()->zone() == entity->zone()) {
+ targets::set_target(entity);
+ }
+
+ if (entity) {
+ if (entity->model()) {
mapwindow_modelview->set_mode(ui::ModelView::Model);
- mapwindow_modelview->set_modelname(mapwindow_target->model()->name());
- mapwindow_modelview->set_colors(mapwindow_target->color(), mapwindow_target->color_second());
+ mapwindow_modelview->set_modelname(entity->model()->name());
+ mapwindow_modelview->set_colors(entity->color(), entity->color_second());
mapwindow_modelview->set_zoom(2.5f);
mapwindow_modelview->set_radius(2.0f);
- } else if (mapwindow_target->type() == core::Entity::Globe) {
+ } else if (entity->type() == core::Entity::Globe) {
mapwindow_modelview->set_mode(ui::ModelView::Globe);
- const core::EntityGlobe *globe = static_cast<const core::EntityGlobe *>(mapwindow_target);
- mapwindow_modelview->set_colors(mapwindow_target->color(), mapwindow_target->color_second());
+ const core::EntityGlobe *globe = static_cast<const core::EntityGlobe *>(entity);
+ mapwindow_modelview->set_colors(globe->color(), globe->color_second());
mapwindow_modelview->set_globetexturename(
globe->texturename(),
globe->flag_is_set(core::Entity::Bright),
globe->coronaname()
);
mapwindow_modelview->set_zoom(2.5f);
- if (globe->flag_is_set(core::Entity::Bright))
+ if (globe->flag_is_set(core::Entity::Bright)) {
mapwindow_modelview->set_radius(0.5f);
- else
+ } else {
mapwindow_modelview->set_radius(1.0f);
+ }
} else {
- mapwindow_modelview->set_mode(ui::ModelView::Model);
- const std::string empty;
- mapwindow_modelview->set_modelname(empty);
+ mapwindow_modelview->clear();
}
+ mapwindow_targetlabel->set_text(entity->name());
+
+ set_info(entity->info());
mapwindow_modelview->show();
- mapwindow_scrollpane->show();
} else {
-
- mapwindow_modelview->hide();
- mapwindow_scrollpane->hide();
+ set_info(0);
+ mapwindow_infotext.clear();
+ mapwindow_targetlabel->clear();
+ mapwindow_modelview->clear();
}
}
-bool MapWindow::on_keypress(const int key, const unsigned int modifier)
+void MapWindow::show_zone_info(const core::Zone *zone)
{
- if (key == 512 + SDL_BUTTON_LEFT) {
- if (mapwindow_mapwidget->has_mouse_focus() && mapwindow_mapwidget->hover()) {
- core::Entity *target = core::localplayer()->zone()->find_entity(mapwindow_mapwidget->hover());
- if (targets::is_valid_map_target(target)) {
- set_target(target);
- targets::set_target(mapwindow_target);
- }
+ if (zone) {
+ set_info(zone->info());
+
+ switch (mapwindow_mode) {
+ case ShowZone:
+ mapwindow_targetlabel->clear();
+ break;
+
+ case ShowWorld:
+ mapwindow_targetlabel->set_text(zone->name());
+ break;
}
- return true;
+ } else {
+ set_info(0);
+ mapwindow_infotext.clear();
+ mapwindow_targetlabel->clear();
+ }
+ mapwindow_modelview->clear();
+}
- } else if (key == SDLK_ESCAPE) {
+bool MapWindow::on_keypress(const int key, const unsigned int modifier)
+{
+ if (key == SDLK_ESCAPE) {
if (visible()) {
hide();
return true;
@@ -243,6 +301,67 @@ bool MapWindow::on_emit(ui::Widget *sender, const ui::Widget::Event event, void
if (sender == mapwindow_closebutton) {
if (event == ui::Widget::EventButtonClicked) {
hide();
+ }
+ return true;
+
+ } else if (sender == mapwindow_mapwidget) {
+ if (event == ui::Widget::EventClicked) {
+ if (mapwindow_mapwidget->target()) {
+ show_entity_info(mapwindow_mapwidget->target());
+ } else {
+ show_zone_info(mapwindow_mapwidget->zone());
+ }
+ return true;
+ }
+
+ } else if (sender == mapwindow_galaxymapwidget) {
+ if (event == ui::Widget::EventClicked) {
+ show_zone_info(mapwindow_galaxymapwidget->zone());
+ return true;
+ } else if (event == ui::Widget::EventDoubleClicked) {
+ if (mapwindow_galaxymapwidget->zone()) {
+ mapwindow_mode = ShowZone;
+ mapwindow_galaxymapwidget->hide();
+ mapwindow_mapwidget->set_zone(mapwindow_galaxymapwidget->zone());
+ mapwindow_mapwidget->show();
+ mapwindow_maplabel->set_text(mapwindow_mapwidget->zone()->name());
+ show_zone_info(mapwindow_mapwidget->zone());
+ }
+ return true;
+ }
+
+ } else if (sender == mapwindow_zonebutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ if (mapwindow_mode == ShowZone) {
+ mapwindow_mapwidget->set_target(0);
+ show_zone_info(mapwindow_mapwidget->zone());
+ } else {
+ mapwindow_mode = ShowZone;
+ if (mapwindow_galaxymapwidget->zone()) {
+ mapwindow_mapwidget->set_zone(mapwindow_galaxymapwidget->zone());
+ } else {
+ mapwindow_mapwidget->set_zone(core::localplayer()->zone());
+ }
+ mapwindow_mapwidget->show();
+ mapwindow_galaxymapwidget->hide();
+ mapwindow_maplabel->set_text(mapwindow_mapwidget->zone()->name());
+ }
+ return true;
+ }
+
+ } else if (sender == mapwindow_galaxybutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ if (mapwindow_mode == ShowWorld) {
+ mapwindow_galaxymapwidget->set_zone(0);
+ show_zone_info(0);
+ } else {
+ mapwindow_mode = ShowWorld;
+ mapwindow_mapwidget->hide();
+ mapwindow_galaxymapwidget->show();
+ mapwindow_galaxymapwidget->set_zone(mapwindow_mapwidget->zone());
+ show_zone_info(mapwindow_galaxymapwidget->zone());
+ mapwindow_maplabel->set_text("Starsystems");
+ }
return true;
}
}
diff --git a/src/client/mapwindow.h b/src/client/mapwindow.h
index 66f8f45..d667ca4 100644
--- a/src/client/mapwindow.h
+++ b/src/client/mapwindow.h
@@ -15,6 +15,7 @@
#include "ui/scrollpane.h"
#include "ui/window.h"
#include "client/mapwidget.h"
+#include "client/galaxymapwidget.h"
namespace client
{
@@ -22,6 +23,8 @@ namespace client
class MapWindow : public ui::Window
{
public:
+ enum Mode { ShowZone = 0, ShowWorld = 1 };
+
MapWindow(ui::Widget *parent = 0);
virtual ~MapWindow();
@@ -47,26 +50,35 @@ protected:
virtual void draw();
private:
- /// set the map target
- void set_target(const core::Entity *entity);
+ /// show zone information
+ void show_zone_info(const core::Zone *zone);
+
+ /// show target entity information
+ void show_entity_info(const core::Entity *entity);
+
+ /// update inforecord textpane
+ void set_info(const core::Info *info);
ui::Label *mapwindow_titlelabel;
MapWidget *mapwindow_mapwidget;
+ GalaxyMapWidget *mapwindow_galaxymapwidget;
ui::Label *mapwindow_maplabel;
ui::ModelView *mapwindow_modelview;
ui::Label *mapwindow_targetlabel;
ui::ScrollPane *mapwindow_scrollpane;
ui::IconButton *mapwindow_closebutton;
+ ui::IconButton *mapwindow_zonebutton;
+ ui::IconButton *mapwindow_galaxybutton;
-
- const core::Entity *mapwindow_target;
- const core::Info *mapwindow_inforecord;
- unsigned long mapwindow_infotimestamp;
+ const core::Info *mapwindow_inforecord;
+ unsigned long mapwindow_infotimestamp;
ui::Text mapwindow_infotext;
+ Mode mapwindow_mode;
+
}; // class MapWindow