From 45054b224d8f0f8b6d7db4bcd0b0abf6763a60ab Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 31 Jul 2011 18:24:01 +0000 Subject: Improved map window, moved the actual map widget into a seperate class. --- src/client/Makefile.am | 6 +- src/client/buymenu.cc | 1 + src/client/gamewindow.cc | 6 +- src/client/gamewindow.h | 21 ++- src/client/inventorywindow.cc | 2 +- src/client/map.cc | 312 ----------------------------------- src/client/map.h | 65 -------- src/client/mapwidget.cc | 215 ++++++++++++++++++++++++ src/client/mapwidget.h | 43 +++++ src/client/mapwindow.cc | 374 ++++++++++++++++++++++++++++++++++++++++++ src/client/mapwindow.h | 71 ++++++++ src/client/targets.cc | 16 +- src/client/testmodelwindow.cc | 2 + 13 files changed, 738 insertions(+), 396 deletions(-) delete mode 100644 src/client/map.cc delete mode 100644 src/client/map.h create mode 100644 src/client/mapwidget.cc create mode 100644 src/client/mapwidget.h create mode 100644 src/client/mapwindow.cc create mode 100644 src/client/mapwindow.h (limited to 'src') diff --git a/src/client/Makefile.am b/src/client/Makefile.am index ceddb6a..49ac08a 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -25,7 +25,8 @@ noinst_HEADERS = \ key.h \ keyboard.h \ mainwindow.h \ - map.h \ + mapwidget.h \ + mapwindow.h \ notifications.h \ soundext.h \ targeticonbutton.h \ @@ -51,7 +52,8 @@ libclient_la_SOURCES = \ key.cc \ keyboard.cc \ mainwindow.cc \ - map.cc \ + mapwidget.cc \ + mapwindow.cc \ notifications.cc \ soundext.cc \ targeticonbutton.cc \ diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc index 61198d3..6812bce 100644 --- a/src/client/buymenu.cc +++ b/src/client/buymenu.cc @@ -99,6 +99,7 @@ void BuyMenu::set_item(core::Info *info) if (menu_inforecord->type() && menu_inforecord->label().size()) { menu_namelabel->set_text(menu_inforecord->name()); menu_modelview->set_modelname(menu_inforecord->modelname()); + menu_modelview->set_colors(core::localplayer()->color(), core::localplayer()->color_second()); menu_buybutton->set_command("remote buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label() + "; view hide"); menu_buybutton->set_label("buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label()); diff --git a/src/client/gamewindow.cc b/src/client/gamewindow.cc index d539f53..3404703 100644 --- a/src/client/gamewindow.cc +++ b/src/client/gamewindow.cc @@ -31,7 +31,7 @@ GameWindow::GameWindow(ui::Widget *parent) : ui::Window(parent) label_viewname->set_font(ui::root()->font_large()); // sub menus - gamewindow_map = new Map(this); + gamewindow_map = new MapWindow(this); gamewindow_entitymenu = new EntityMenu(this); gamewindow_buymenu = new BuyMenu(this); gamewindow_trademenu = new TradeMenu(this); @@ -304,6 +304,8 @@ void GameWindow::resize() void GameWindow::draw() { + ui::Window::draw(); + const float smallmargin = ui::UI::elementsize.height(); if (core::localcontrol()->state() == core::Entity::Docked) { @@ -364,8 +366,6 @@ void GameWindow::draw() } else { gamewindow_homebutton->disable(); - //gamewindow_notify->set_geometry(gamewindow_map->location(), gamewindow_map->size()); - if (gamewindow_entitymenu->visible()) { gamewindow_entitymenu->hide(); } diff --git a/src/client/gamewindow.h b/src/client/gamewindow.h index 336158e..6c1ee83 100644 --- a/src/client/gamewindow.h +++ b/src/client/gamewindow.h @@ -10,13 +10,16 @@ #include "ui/window.h" #include "ui/label.h" #include "ui/iconbutton.h" + +#include "client/hud.h" + #include "client/chat.h" +#include "client/inventorywindow.h" +#include "client/mapwindow.h" + #include "client/buymenu.h" #include "client/entitymenu.h" -#include "client/inventorywindow.h" #include "client/trademenu.h" -#include "client/hud.h" -#include "client/map.h" namespace client { @@ -54,15 +57,19 @@ public: inline HUD *hud() { return gamewindow_hud; } - inline Map *map() { - return gamewindow_map; - } + inline Chat *chat() { return gamewindow_chat; } + + inline MapWindow *map() { + return gamewindow_map; + } + inline InventoryWindow *inventory() { return gamewindow_inventory; } + inline EntityMenu *menu() { return gamewindow_entitymenu; } @@ -77,7 +84,7 @@ protected: private: HUD *gamewindow_hud; Chat *gamewindow_chat; - Map *gamewindow_map; + MapWindow *gamewindow_map; InventoryWindow *gamewindow_inventory; EntityMenu *gamewindow_entitymenu; diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc index 604145a..cca8cc2 100644 --- a/src/client/inventorywindow.cc +++ b/src/client/inventorywindow.cc @@ -176,7 +176,6 @@ bool InventoryWindow::verify() const void InventoryWindow::resize() { - //const float smallmargin = ui::UI::elementsize.height(); const float padding = ui::root()->font_large()->height(); const float icon_size = 24.0f; // small icons @@ -260,6 +259,7 @@ void InventoryWindow::set_info(const core::Info *info, const int amount) core::game()->request_info(info->id()); inventorywindow_modelview->set_modelname(info->modelname()); inventorywindow_modelnamelabel->set_text(info->name()); + inventorywindow_modelview->set_colors(core::localplayer()->color(), core::localplayer()->color_second()); for (core::Info::Text::const_iterator it = inventorywindow_inforecord->text().begin(); it != inventorywindow_inforecord->text().end(); it++) { inventorywindow_infotext.push_back((*it)); diff --git a/src/client/map.cc b/src/client/map.cc deleted file mode 100644 index 54afc3f..0000000 --- a/src/client/map.cc +++ /dev/null @@ -1,312 +0,0 @@ - -/* - client/map.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "audio/audio.h" -#include "core/application.h" -#include "client/map.h" -#include "client/input.h" -#include "client/targets.h" -#include "ui/ui.h" -#include "ui/paint.h" -#include "render/gl.h" -#include "render/textures.h" -#include "render/text.h" - -namespace client -{ - -Map::Map(ui::Widget *parent) : ui::Window(parent) -{ - set_label("map"); - set_border(true); - set_background(true); - set_font(ui::root()->font_small()); - - map_targetlabel = new ui::Label(this); - map_targetlabel->set_label("targetlabel"); - map_targetlabel->set_background(false); - map_targetlabel->set_border(false); - map_targetlabel->set_font(ui::root()->font_large()); - map_targetlabel->set_alignment(ui::AlignCenter); - - map_scrollpane = new ui::ScrollPane(this, map_infotext); - map_scrollpane->set_background(false); - map_scrollpane->set_border(false); - map_scrollpane->set_alignment(ui::AlignTop); - - set_target(0); - map_hover = 0; - hide(); -} - -Map::~Map() -{ -} - -void Map::hide() -{ - ui::Window::hide(); - map_hover = 0; - map_target = 0; -} - -void Map::show() -{ - ui::Window::show(); - map_hover = 0; - if (core::localplayer()->view()) { - map_target = core::localplayer()->view(); - } else { - map_target = targets::current(); - } -} - -void Map::toggle() -{ - if (visible()) - hide(); - else - show(); -} - -void Map::resize() -{ - const float fontmargin = map_targetlabel->font()->height(); - - // resize label - map_targetlabel->set_size(width() - fontmargin * 2.0f, fontmargin); - map_targetlabel->set_location(fontmargin, fontmargin); - - // resize infotext pane - map_scrollpane->set_size(width() - ui::UI::elementsize.width() * 1.5f - fontmargin * 3.0f, - height() - ui::UI::elementsize.height() * 2.0f - fontmargin * 3.0f); - map_scrollpane->set_location(ui::UI::elementsize.width() * 1.5f + fontmargin * 2.0f, fontmargin * 3.0f); -} - -void Map::draw() -{ - const float fontmargin = map_targetlabel->font()->height(); - const float s = ui::UI::elementsize.width() * 1.5f; - - const float blue = 0.8f; - const float gridsize = 16; - - const core::Entity *entity; - const core::Entity *current_target = map_target; - map_target = 0; - - math::Color color; - - math::Vector2f v(global_location()); - math::Vector2f l; - - v[0] += fontmargin; - v[1] += fontmargin + (height() - s) * 0.5f; - map_hover = 0; - - gl::color(0, 0, blue); - - gl::begin(gl::Lines); - for (int i = 0; i <= gridsize; i++) { - gl::vertex(v.x(), v.y() + s / gridsize * i); - gl::vertex(v.x() + s, v.y() + s / gridsize * i); - - gl::vertex(v.x() + s / gridsize * i, v.y()); - gl::vertex(v.x() + s / gridsize * i, v.y() + s); - } - gl::end(); - - const size_t texture_entity = render::Textures::load("bitmaps/icons/entity_default"); - const size_t texture_globe = render::Textures::load("bitmaps/icons/entity_globe"); - const size_t texture_bright = render::Textures::load("bitmaps/icons/entity_bright"); - - size_t texture_current = render::Textures::bind(texture_entity); - - v[0] += s * 0.5f; - v[1] += s * 0.5f; - - core::Zone *zone = core::localplayer()->zone(); - - const math::Vector2f cursor(input::mouse_position_x(), input::mouse_position_y()); - - const float r = 12.0f; - float scale = 2048.0f; - scale *= 2; - - gl::enable(GL_TEXTURE_2D); - gl::begin(gl::Quads); - - // draw map icons - for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { - entity = (*it); - - bool draw_icon = false; - l.assign(v); - - if (targets::is_valid_map_target(entity)) { - draw_icon = true; - l[0] -= s / scale * entity->location().y(); - l[1] -= s / scale * entity->location().x(); - - if (math::distancesquared(cursor, l) < (r*r)) { - map_hover = entity->id(); - } - - if (entity == current_target) { - map_target = entity; - if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { - draw_icon = false; - } - } - } - - if (draw_icon) { - if (entity->type() == core::Entity::Globe) { - if (entity->flag_is_set(core::Entity::Bright)) { - if (texture_current != texture_bright) { - gl::end(); - texture_current = render::Textures::bind(texture_bright); - gl::begin(gl::Quads); - } - } else { - if (texture_current != texture_globe) { - gl::end(); - texture_current = render::Textures::bind(texture_globe); - gl::begin(gl::Quads); - } - } - } else { - if (texture_current != texture_entity) { - gl::end(); - texture_current = render::Textures::bind(texture_entity); - gl::begin(gl::Quads); - } - } - - if (entity == core::localplayer()->mission_target()) { - color.assign(palette()->mission()); - } else { - color.assign(entity->color()); - } - color.a = 1.0f; - - gl::color(color); - glTexCoord2f(0.0f, 0.0f); - gl::vertex(l.x() - r, l.y() - r); - - glTexCoord2f(1.0f, 0.0f); - gl::vertex(l.x() + r, l.y() - r); - - glTexCoord2f(1.0f, 1.0f); - gl::vertex(l.x() + r, l.y() + r); - - glTexCoord2f(0.0f, 1.0f); - gl::vertex(l.x() - r, l.y() + r); - } - - } - - // draw localcontrol icon - entity = core::localcontrol(); - - //if (core::localcontrol()->state() != core::Entity::Docked) { - l.assign(v); - l[0] -= s / scale * entity->location().y(); - l[1] -= s / scale * entity->location().x(); - if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { - if (texture_current != texture_entity) { - gl::end(); - 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(l.x() - r, l.y() - r); - - glTexCoord2f(1.0f, 0.0f); - gl::vertex(l.x() + r, l.y() - r); - - glTexCoord2f(1.0f, 1.0f); - gl::vertex(l.x() + r, l.y() + r); - - glTexCoord2f(0.0f, 1.0f); - gl::vertex(l.x() - r, l.y() + r); - } - //} - - gl::end(); - gl::disable(GL_TEXTURE_2D); - - if (map_target != current_target ) { - // this makes sure the map target exists - set_target(current_target); - - } else if (map_inforecord && (map_infotimestamp != map_inforecord->timestamp())) { - set_target(map_target); - } -} - -void Map::set_target(const core::Entity *entity) { - - map_target = entity; - map_infotimestamp = 0; - map_inforecord = 0; - map_infotext.clear(); - - if (map_target) { - // set title label to target name - map_targetlabel->set_text(map_target->name()); - map_targetlabel->show(); - - if (map_target->info()) - map_inforecord = core::game()->request_info(map_target->info()->id()); - else - map_inforecord = 0; - - if (map_inforecord) { - for (core::Info::Text::const_iterator it = map_inforecord->text().begin(); it != map_inforecord->text().end(); it++) { - map_infotext.push_back((*it)); - } - map_infotimestamp = map_inforecord->timestamp(); - } else { - map_infotext.push_back("Information is not available"); - map_infotimestamp = 0; - } - - map_scrollpane->show(); - } else { - map_targetlabel->hide(); - map_scrollpane->hide(); - } -} - -bool Map::on_keypress(const int key, const unsigned int modifier) -{ - if (key == 512 + SDL_BUTTON_LEFT) { - if (hover()) { - core::Entity *target = core::localplayer()->zone()->find_entity(hover()); - if (targets::is_valid_map_target(target)) { - set_target(target); - targets::set_target(map_target); - } - } - return true; - - } else if (key == SDLK_ESCAPE) { - if (visible()) { - hide(); - return true; - } - } - - return false; -} - -} diff --git a/src/client/map.h b/src/client/map.h deleted file mode 100644 index e0d8a2d..0000000 --- a/src/client/map.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - client/map.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_MAP_H__ -#define __INCLUDED_CLIENT_MAP_H__ - -#include "core/entity.h" -#include "core/info.h" -#include "ui/label.h" -#include "ui/scrollpane.h" -#include "ui/window.h" - -namespace client -{ - -class Map : public ui::Window -{ -public: - Map(ui::Widget *parent = 0); - virtual ~Map(); - - inline unsigned int hover() const { - return map_hover; - } - - /// set the map target - void set_target(const core::Entity *entity); - - /// toggle the map window - void toggle(); - - /// hide the map window - virtual void hide(); - - /// show the map window - virtual void show(); - - /// called when the widget receives a key press - virtual bool on_keypress(const int key, const unsigned int modifier); - -protected: - virtual void resize(); - - virtual void draw(); - - ui::Label *map_targetlabel; - ui::ScrollPane *map_scrollpane; - - unsigned int map_hover; - const core::Entity *map_target; - - const core::Info *map_inforecord; - unsigned long map_infotimestamp; - ui::Text map_infotext; -}; - - -} // namespace client - - -#endif // __INCLUDED_CLIENT_MAP_H__ - diff --git a/src/client/mapwidget.cc b/src/client/mapwidget.cc new file mode 100644 index 0000000..5f5d5d6 --- /dev/null +++ b/src/client/mapwidget.cc @@ -0,0 +1,215 @@ +/* + client/mapwidget.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/mapwidget.h" +#include "core/application.h" +#include "ui/paint.h" +#include "render/render.h" +#include "render/gl.h" +#include "client/targets.h" +#include "ui/ui.h" + +namespace client { + +MapWidget::MapWidget(ui::Widget *parent) : ui::Widget(parent) +{ + set_label("mapwidget"); + mapwidget_zone = 0; + mapwidget_target = 0; + mapwidget_hover_id = 0; + mapwidget_zoom = 1.0f; +} + +MapWidget::~MapWidget() +{ + +} + +void MapWidget::set_zoom(const float zoom) +{ + mapwidget_zoom = zoom; +} +void MapWidget::set_target(const core::Entity *entity) +{ + mapwidget_target = entity; +} + +void MapWidget::set_zone(core::Zone *zone) +{ + mapwidget_zone = zone; +} + +void MapWidget::draw() +{ + if (!mapwidget_zone) + return; + + // 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_entity = render::Textures::load("bitmaps/icons/entity_default"); + const size_t texture_globe = render::Textures::load("bitmaps/icons/entity_globe"); + const size_t texture_bright = render::Textures::load("bitmaps/icons/entity_bright"); + + size_t texture_current = render::Textures::bind(texture_entity); + + // global mouse cursor location + const math::Vector2f cursor(ui::root()->global_mouse_coords()); + mapwidget_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 = 4096.0f; // map size in game units + math::Color color; + const core::Entity *entity = 0; + + // draw map icons + gl::enable(GL_TEXTURE_2D); + gl::begin(gl::Quads); + + + for (core::Zone::Content::iterator it = mapwidget_zone->content().begin(); it != mapwidget_zone->content().end(); it++) { + entity = (*it); + + bool draw_icon = false; + + icon_location.assign(map_center); + + if (targets::is_valid_map_target(entity)) { + draw_icon = true; + icon_location[0] -= map_size / scale * entity->location().y(); + icon_location[1] -= map_size / scale * entity->location().x(); + + if (math::distancesquared(cursor, icon_location) < (r*r)) { + mapwidget_hover_id = entity->id(); + } + + if (entity == mapwidget_target) { + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { + draw_icon = false; + } + } + } + + if (draw_icon) { + if (entity->type() == core::Entity::Globe) { + if (entity->flag_is_set(core::Entity::Bright)) { + if (texture_current != texture_bright) { + gl::end(); + texture_current = render::Textures::bind(texture_bright); + gl::begin(gl::Quads); + } + } else { + if (texture_current != texture_globe) { + gl::end(); + texture_current = render::Textures::bind(texture_globe); + gl::begin(gl::Quads); + } + } + } else { + if (texture_current != texture_entity) { + gl::end(); + texture_current = render::Textures::bind(texture_entity); + gl::begin(gl::Quads); + } + } + + if (entity == core::localplayer()->mission_target()) { + color.assign(palette()->mission()); + } else { + color.assign(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, 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); + } + + } + + // draw localcontrol icon + 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(); + 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); + + 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 (mapwidget_hover_id) + ui::root()->set_pointer("target", ui::Palette::Active, true); + } +} + +} // namespace client + diff --git a/src/client/mapwidget.h b/src/client/mapwidget.h new file mode 100644 index 0000000..fb5a905 --- /dev/null +++ b/src/client/mapwidget.h @@ -0,0 +1,43 @@ +/* + 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_MAPWIDGET_H__ +#define __INCLUDED_CLIENT_MAPWIDGET_H__ + +#include "core/zone.h" +#include "ui/widget.h" + +namespace client { + +class MapWidget : public ui::Widget { +public: + MapWidget(ui::Widget *parent = 0); + virtual ~MapWidget(); + + void set_zoom(const float zoom); + + void set_zone(core::Zone *zone); + + void set_target(const core::Entity *entity); + + inline unsigned int hover() { + return mapwidget_hover_id; + } + +protected: + virtual void draw(); + +private: + float mapwidget_zoom; + + core::Zone *mapwidget_zone; + const core::Entity *mapwidget_target; + unsigned int mapwidget_hover_id; + +}; // class MapWidget + +} // namespace client +#endif // __INCLUDED_CLIENT_MAPWIDGET_H__ diff --git a/src/client/mapwindow.cc b/src/client/mapwindow.cc new file mode 100644 index 0000000..d6e45bc --- /dev/null +++ b/src/client/mapwindow.cc @@ -0,0 +1,374 @@ + +/* + client/mapwindow.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "audio/audio.h" +#include "core/application.h" +#include "client/mapwindow.h" +#include "client/targets.h" +#include "ui/ui.h" +#include "ui/paint.h" +#include "render/gl.h" +#include "render/textures.h" +#include "render/text.h" + +namespace client +{ + +MapWindow::MapWindow(ui::Widget *parent) : ui::Window(parent) +{ + set_label("map"); + set_border(true); + set_background(true); + set_font(ui::root()->font_small()); + + // window title + mapwindow_titlelabel = new ui::Label(this); + mapwindow_titlelabel->set_label("title"); + mapwindow_titlelabel->set_background(false); + mapwindow_titlelabel->set_border(false); + mapwindow_titlelabel->set_font(ui::root()->font_large()); + mapwindow_titlelabel->set_alignment(ui::AlignCenter); + mapwindow_titlelabel->set_text("STAR CHART"); + + // map widget + 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); + mapwindow_maplabel->set_label("maplabel"); + mapwindow_maplabel->set_background(false); + mapwindow_maplabel->set_border(false); + mapwindow_maplabel->set_alignment(ui::AlignCenter); + + // modelview + mapwindow_modelview = new ui::ModelView(this); + mapwindow_modelview->set_label("modelview"); + mapwindow_modelview->set_background(false); + mapwindow_modelview->set_border(false); + + // target title (modelview child) + mapwindow_targetlabel = new ui::Label(mapwindow_modelview); + mapwindow_targetlabel->set_label("targetlabel"); + mapwindow_targetlabel->set_background(false); + mapwindow_targetlabel->set_border(false); + mapwindow_targetlabel->set_alignment(ui::AlignCenter); + + // target text + mapwindow_scrollpane = new ui::ScrollPane(this, mapwindow_infotext); + mapwindow_scrollpane->set_background(false); + mapwindow_scrollpane->set_border(false); + mapwindow_scrollpane->set_alignment(ui::AlignTop); + + set_target(0); + hide(); +} + +MapWindow::~MapWindow() +{ +} + +void MapWindow::hide() +{ + ui::Window::hide(); + mapwindow_target = 0; +} + +void MapWindow::show() +{ + ui::Window::show(); + if (core::localplayer()->view()) { + set_target(core::localplayer()->view()); + } else { + set_target(targets::current()); + } +} + +void MapWindow::toggle() +{ + if (visible()) + hide(); + else + show(); +} + +void MapWindow::resize() +{ + const float padding = ui::root()->font_large()->height(); + + // resize title label + mapwindow_titlelabel->set_size(width() - padding * 2.0f, mapwindow_titlelabel->font()->height()); + mapwindow_titlelabel->set_location(padding, padding); + + // 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 (map widget child) + mapwindow_maplabel->set_size(mapwindow_mapwidget->width(), mapwindow_maplabel->font()->height()); + mapwindow_maplabel->set_location(0, 0); + + // 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); + + // resize target label (modelview child) + mapwindow_targetlabel->set_size(mapwindow_modelview->width(), mapwindow_targetlabel->font()->height()); + mapwindow_targetlabel->set_location(0, 0); + + // 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); + +} + +void MapWindow::draw() +{ + ui::Window::draw(); + + // make sure the target still exists + mapwindow_target = core::localplayer()->zone()->find_entity(mapwindow_target); + + mapwindow_mapwidget->set_zone(core::localplayer()->zone()); + mapwindow_mapwidget->set_target(mapwindow_target); + mapwindow_maplabel->set_text(core::localplayer()->zone()->name()); + + /* + const float fontmargin = mapwindow_targetlabel->font()->height(); + const float s = ui::UI::elementsize.width() * 1.5f; + + const float blue = 0.8f; + const float gridsize = 16; + + const core::Entity *entity; + const core::Entity *current_target = mapwindow_target; + mapwindow_target = 0; + + math::Color color; + + math::Vector2f v(global_location()); + math::Vector2f l; + + v[0] += fontmargin; + v[1] += fontmargin + (height() - s) * 0.5f; + mapwindow_hover = 0; + + gl::color(0, 0, blue); + + gl::begin(gl::Lines); + for (int i = 0; i <= gridsize; i++) { + gl::vertex(v.x(), v.y() + s / gridsize * i); + gl::vertex(v.x() + s, v.y() + s / gridsize * i); + + gl::vertex(v.x() + s / gridsize * i, v.y()); + gl::vertex(v.x() + s / gridsize * i, v.y() + s); + } + gl::end(); + + const size_t texture_entity = render::Textures::load("bitmaps/icons/entity_default"); + const size_t texture_globe = render::Textures::load("bitmaps/icons/entity_globe"); + const size_t texture_bright = render::Textures::load("bitmaps/icons/entity_bright"); + + size_t texture_current = render::Textures::bind(texture_entity); + + v[0] += s * 0.5f; + v[1] += s * 0.5f; + + core::Zone *zone = core::localplayer()->zone(); + + mapwindow_maplabel->set_text(zone->name()); + + const math::Vector2f cursor(input::mouse_position_x(), input::mouse_position_y()); + + const float r = 12.0f; + float scale = 2048.0f; + scale *= 2; + + gl::enable(GL_TEXTURE_2D); + gl::begin(gl::Quads); + + // draw map icons + for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { + entity = (*it); + + bool draw_icon = false; + l.assign(v); + + if (targets::is_valid_map_target(entity)) { + draw_icon = true; + l[0] -= s / scale * entity->location().y(); + l[1] -= s / scale * entity->location().x(); + + if (math::distancesquared(cursor, l) < (r*r)) { + mapwindow_hover = entity->id(); + } + + if (entity == current_target) { + mapwindow_target = entity; + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { + draw_icon = false; + } + } + } + + if (draw_icon) { + if (entity->type() == core::Entity::Globe) { + if (entity->flag_is_set(core::Entity::Bright)) { + if (texture_current != texture_bright) { + gl::end(); + texture_current = render::Textures::bind(texture_bright); + gl::begin(gl::Quads); + } + } else { + if (texture_current != texture_globe) { + gl::end(); + texture_current = render::Textures::bind(texture_globe); + gl::begin(gl::Quads); + } + } + } else { + if (texture_current != texture_entity) { + gl::end(); + texture_current = render::Textures::bind(texture_entity); + gl::begin(gl::Quads); + } + } + + if (entity == core::localplayer()->mission_target()) { + color.assign(palette()->mission()); + } else { + color.assign(entity->color()); + } + color.a = 1.0f; + + gl::color(color); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(l.x() - r, l.y() - r); + + glTexCoord2f(1.0f, 0.0f); + gl::vertex(l.x() + r, l.y() - r); + + glTexCoord2f(1.0f, 1.0f); + gl::vertex(l.x() + r, l.y() + r); + + glTexCoord2f(0.0f, 1.0f); + gl::vertex(l.x() - r, l.y() + r); + } + + } + + // draw localcontrol icon + entity = core::localcontrol(); + + //if (core::localcontrol()->state() != core::Entity::Docked) { + l.assign(v); + l[0] -= s / scale * entity->location().y(); + l[1] -= s / scale * entity->location().x(); + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { + if (texture_current != texture_entity) { + gl::end(); + 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(l.x() - r, l.y() - r); + + glTexCoord2f(1.0f, 0.0f); + gl::vertex(l.x() + r, l.y() - r); + + glTexCoord2f(1.0f, 1.0f); + gl::vertex(l.x() + r, l.y() + r); + + glTexCoord2f(0.0f, 1.0f); + gl::vertex(l.x() - r, l.y() + r); + } + //} + + gl::end(); + gl::disable(GL_TEXTURE_2D); + + if (mapwindow_target != current_target ) { + // this makes sure the map target exists + set_target(current_target); + + } else if (mapwindow_inforecord && (mapwindow_infotimestamp != mapwindow_inforecord->timestamp())) { + set_target(mapwindow_target); + } + */ +} + +void MapWindow::set_target(const core::Entity *entity) { + + mapwindow_target = entity; + 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 (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()) { + mapwindow_modelview->set_modelname(mapwindow_target->model()->name()); + mapwindow_modelview->set_colors(mapwindow_target->color(), mapwindow_target->color_second()); + } else { + mapwindow_modelview->set_modelname(0); + } + + mapwindow_modelview->show(); + mapwindow_scrollpane->show(); + + } else { + + mapwindow_modelview->hide(); + mapwindow_scrollpane->hide(); + } +} + +bool MapWindow::on_keypress(const int key, const unsigned int modifier) +{ + 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); + } + } + return true; + + } else if (key == SDLK_ESCAPE) { + if (visible()) { + hide(); + return true; + } + } + + return false; +} + +} diff --git a/src/client/mapwindow.h b/src/client/mapwindow.h new file mode 100644 index 0000000..d65e115 --- /dev/null +++ b/src/client/mapwindow.h @@ -0,0 +1,71 @@ +/* + client/mapwindow.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_MAPWINDOW_H__ +#define __INCLUDED_CLIENT_MAPWINDOW_H__ + +#include "core/entity.h" +#include "core/info.h" +#include "ui/label.h" +#include "ui/modelview.h" +#include "ui/scrollpane.h" +#include "ui/window.h" +#include "client/mapwidget.h" + +namespace client +{ + +class MapWindow : public ui::Window +{ +public: + MapWindow(ui::Widget *parent = 0); + virtual ~MapWindow(); + + /// toggle the map window + void toggle(); + + /// hide the map window + virtual void hide(); + + /// show the map window + virtual void show(); + + /// called when the widget receives a key press + virtual bool on_keypress(const int key, const unsigned int modifier); + +protected: + virtual void resize(); + + virtual void draw(); + +private: + /// set the map target + void set_target(const core::Entity *entity); + + + ui::Label *mapwindow_titlelabel; + + MapWidget *mapwindow_mapwidget; + ui::Label *mapwindow_maplabel; + + ui::ModelView *mapwindow_modelview; + ui::Label *mapwindow_targetlabel; + ui::ScrollPane *mapwindow_scrollpane; + + + const core::Entity *mapwindow_target; + const core::Info *mapwindow_inforecord; + unsigned long mapwindow_infotimestamp; + ui::Text mapwindow_infotext; + +}; // class MapWindow + + +} // namespace client + + +#endif // __INCLUDED_CLIENT_MAPWINDOW_H__ + diff --git a/src/client/targets.cc b/src/client/targets.cc index 46643bb..bd0ea48 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -40,20 +40,22 @@ unsigned int current_hover = 0; const core::Entity *current_target = 0; -bool is_valid_hud_target(const core::Entity *entity) +bool is_valid_map_target(const core::Entity *entity) { if (entity->serverside()) { return false; - } else if (!ext_render(entity)) { - return false; } else if (entity == core::localcontrol()) { return false; + } else if (entity->flag_is_set(core::Entity::ShowOnMap)) { + return true; + } else if (entity == core::localplayer()->mission_target()) { + return true; } else { - return ext_render(entity)->visible(); + return false; } } -bool is_valid_map_target(const core::Entity *entity) +bool is_valid_hud_target(const core::Entity *entity) { if (entity->serverside()) { return false; @@ -63,8 +65,10 @@ bool is_valid_map_target(const core::Entity *entity) return true; } else if (entity == core::localplayer()->mission_target()) { return true; - } else { + } else if (!ext_render(entity)) { return false; + } else { + return ext_render(entity)->visible(); } } diff --git a/src/client/testmodelwindow.cc b/src/client/testmodelwindow.cc index 9d8d0b0..d70fbbf 100644 --- a/src/client/testmodelwindow.cc +++ b/src/client/testmodelwindow.cc @@ -8,6 +8,7 @@ #include "ui/paint.h" #include "client/testmodelwindow.h" #include "model/model.h" +#include "core/gameinterface.h" namespace client { @@ -41,6 +42,7 @@ TestModelWindow::~TestModelWindow() void TestModelWindow::set_modelname(const std::string & modelname) { testmodelwindow_modelview->set_modelname(modelname); + testmodelwindow_modelview->set_colors(core::localplayer()->color(), core::localplayer()->color_second()); } void TestModelWindow::resize() -- cgit v1.2.3