diff options
Diffstat (limited to 'src/client/map.cc')
-rw-r--r-- | src/client/map.cc | 76 |
1 files changed, 62 insertions, 14 deletions
diff --git a/src/client/map.cc b/src/client/map.cc index 7a6fedc..34dcb40 100644 --- a/src/client/map.cc +++ b/src/client/map.cc @@ -32,8 +32,13 @@ Map::Map(ui::Widget *parent) : ui::Window(parent) 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); - map_target = 0; + set_target(0); map_hover = 0; hide(); } @@ -68,14 +73,29 @@ void Map::toggle() 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 margin = font()->width() * 2.0f; - const float s = ui::UI::elementsize.width() * 2.0f; + 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; - core::Entity *entity; + const core::Entity *entity; const core::Entity *current_target = map_target; map_target = 0; @@ -84,8 +104,8 @@ void Map::draw() math::Vector2f v(global_location()); math::Vector2f l; - v[0] += margin; - v[1] += (height() - s - 2.0f * margin) * 0.5f; + v[0] += fontmargin; + v[1] += fontmargin + (height() - s) * 0.5f; map_hover = 0; gl::color(0, 0, blue); @@ -147,20 +167,20 @@ void Map::draw() if (draw_icon) { if (entity->type() == core::Entity::Globe) { if (entity->flag_is_set(core::Entity::Bright)) { - if (texture_current != texture_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) { + if (texture_current != texture_globe) { gl::end(); texture_current = render::Textures::bind(texture_globe); gl::begin(gl::Quads); } } } else { - if (texture_current != texture_entity) { + if (texture_current != texture_entity) { gl::end(); texture_current = render::Textures::bind(texture_entity); gl::begin(gl::Quads); @@ -224,13 +244,42 @@ void Map::draw() 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_infotimestamp && 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) { - map_targetlabel->set_size(width() - s - margin * 3.0f, map_targetlabel->font()->height() * 2.0f); - map_targetlabel->set_location(s + margin * 2.0f, 4); + // set title label to target name map_targetlabel->set_text(map_target->name()); map_targetlabel->show(); + + map_inforecord = map_target->info(); + + 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_scrollpane->show(); } else { map_targetlabel->hide(); + map_scrollpane->hide(); } } @@ -240,9 +289,8 @@ bool Map::on_keypress(const int key, const unsigned int modifier) if (hover()) { core::Entity *target = core::localplayer()->zone()->find_entity(hover()); if (targets::is_valid_map_target(target)) { - map_target = target; - targets::select_target(map_target); - //audio::play("ui/target"); + set_target(target); + targets::set_target(map_target); } } return true; |