From 974631a33120837165e6ad04bd0ff6acaec08ffa Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 8 Mar 2009 14:52:42 +0000 Subject: target selection updates --- src/client/map.cc | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'src/client/map.cc') diff --git a/src/client/map.cc b/src/client/map.cc index 6384588..10a207c 100644 --- a/src/client/map.cc +++ b/src/client/map.cc @@ -9,6 +9,7 @@ #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" @@ -17,6 +18,21 @@ namespace client { +bool is_valid_map_target(core::Entity *entity) +{ + if (entity->serverside()) { + 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 false; + } +} + Map::Map(ui::Widget *parent) : ui::Window(parent) { set_label("map"); @@ -24,7 +40,7 @@ Map::Map(ui::Widget *parent) : ui::Window(parent) set_background(true); set_font(ui::root()->font_small()); - map_target = 0; + //map_target = 0; map_hover = 0; hide(); } @@ -37,7 +53,7 @@ void Map::hide() { ui::Window::hide(); map_hover = 0; - map_target = 0; + //map_target = 0; } void Map::toggle() @@ -47,6 +63,7 @@ void Map::toggle() else show(); } + void Map::draw() { const float margin = font()->width() * 2.0f; @@ -113,7 +130,7 @@ void Map::draw() bool draw_icon = false; l.assign(v); - if (entity->flag_is_set(core::Entity::ShowOnMap)) { + if (is_valid_map_target(entity)) { draw_icon = true; l.x -= s / scale * entity->location().y; l.y -= s / scale * entity->location().x; @@ -122,7 +139,7 @@ void Map::draw() map_hover = entity->id(); } - if (entity == map_target) { + if (entity == targets::current()) { valid_target = true; if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { draw_icon = false; @@ -156,9 +173,14 @@ void Map::draw() gl::begin(gl::Quads); } } - - color.assign(entity->color()); + + 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); @@ -206,9 +228,7 @@ void Map::draw() gl::end(); - if (!valid_target) { - map_target = 0; - } else { + if (targets::current()) { l.assign(v); if (h > s ) { @@ -227,7 +247,7 @@ void Map::draw() render::Text::setcolor('B'); render::Text::setfont(font()->name().c_str(), font()->width(), font()->height()); - render::Text::draw(l.x, l.y, map_target->name()); + render::Text::draw(l.x, l.y, targets::current()->name()); render::Text::setcolor('N'); } @@ -238,10 +258,10 @@ bool Map::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_LEFT) { if (hover()) { - map_target = core::localplayer()->zone()->find_entity(hover()); - if (map_target) { - audio::play("ui/target"); - } + core::Entity *target = core::localplayer()->zone()->find_entity(hover()); + if (is_valid_map_target(target)) { + targets::select_target(target); + } } return true; -- cgit v1.2.3