From 7de62efc14d0e0f037051bd887c96f28fd9a3215 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 7 Dec 2008 09:03:10 +0000 Subject: add system map, prepare source tree for dataset reorganization --- src/client/map.cc | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 src/client/map.cc (limited to 'src/client/map.cc') diff --git a/src/client/map.cc b/src/client/map.cc new file mode 100644 index 0000000..1183457 --- /dev/null +++ b/src/client/map.cc @@ -0,0 +1,161 @@ + +/* + 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 "core/application.h" +#include "client/map.h" +#include "client/targets.h" +#include "ui/paint.h" +#include "render/gl.h" +#include "render/textures.h" + +namespace client { + +Map::Map(ui::Widget *parent) : ui::Widget(parent) +{ + set_label("map"); + set_border(true); + set_background(true); + hide(); +} + +Map::~Map() +{ +} + +void Map::toggle() +{ + if (visible()) + hide(); + else + show(); +} +void Map::draw() +{ + const float margin = font()->width() * 2.0f; + const float w = width() - margin * 2.0f; + const float h = height() - margin * 2.0f; + const float s = math::min(w, h); + const float blue = 0.8f; + const float gridsize=16; + + math::Vector2f v(global_location()); + v.x += margin; + v.y += margin; + + if (h > s ) { + v.y += (h-s) * 0.5f; + } else { + v.x += (w-s) * 0.5f; + } + + 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.x += s * 0.5f; + v.y += s * 0.5f; + + core::Zone *zone = core::localplayer()->zone(); + + const float r = 24.0f; + float scale = 2048.0f; + scale *= 2; + + gl::enable(GL_TEXTURE_2D); + gl::begin(gl::Quads); + + for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { + core::Entity *entity = (*it); + + bool draw_icon = false; + if ((entity->model()) || (entity->type() == core::Entity::Globe)) { + draw_icon = true; + + if ((entity->type() == core::Entity::Dynamic) || (entity->type() == core::Entity::Controlable)) { + core::EntityDynamic *ed = dynamic_cast(entity); + if (ed->eventstate() ==core::Entity::Docked) { + draw_icon = false; + } + } + + if (entity == core::localcontrol()) { + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { + draw_icon = false; + } + } + + if (entity == targets::current()) { + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { + draw_icon = false; + } + } + } + + if (draw_icon) { + if (entity->type() == core::Entity::Globe) { + if ((entity->flags() & core::Entity::Bright) == 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); + } + } + + math::Vector2f l(v); + l.x -= s / scale * entity->location().y; + l.y -= s / scale * entity->location().x; + + math::Color color(entity->color()); + color.a = 1.0f; + gl::color(color); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(l.x, l.y); + + glTexCoord2f(1.0f, 0.0f); + gl::vertex(l.x+r, l.y); + + glTexCoord2f(1.0f, 1.0f); + gl::vertex(l.x+r, l.y+r); + + glTexCoord2f(0.0f, 1.0f); + gl::vertex(l.x, l.y+r); + + } + } + gl::end(); + gl::disable(GL_TEXTURE_2D); +} + +} \ No newline at end of file -- cgit v1.2.3