1 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #include "heroesmap.h"
22 #include "playerlist.h"
23 #include "GraphicsCache.h"
25 #include "stacklist.h"
27 #include "gui/image-helpers.h"
29 HeroesMap::HeroesMap(std::list<Hero*> h)
32 active_hero = *(heroes.begin());
35 void HeroesMap::draw_hero(Hero *hero, bool active)
37 Player *player = Playerlist::getActiveplayer();
38 Vector<int> start = player->getStacklist()->getPosition(hero->getId());
40 start = mapToSurface(start);
42 start += Vector<int>(int(pixels_per_tile/2), int(pixels_per_tile/2));
45 GraphicsCache::getInstance()->getSmallHeroPic(active);
47 heropic->blit_centered(surface, start);
50 void HeroesMap::after_draw()
52 OverviewMap::after_draw();
54 for (std::list<Hero*>::iterator it = heroes.begin(); it != heroes.end();
57 if (*it == active_hero)
60 draw_hero(*it, false);
63 map_changed.emit(surface);
66 void HeroesMap::mouse_button_event(MouseButtonEvent e)
68 Player *active = Playerlist::getActiveplayer();
69 if (e.button == MouseButtonEvent::LEFT_BUTTON &&
70 e.state == MouseButtonEvent::PRESSED)
73 dest = mapFromScreen(e.pos);
75 //is dest close to one of our heroes?
76 Hero *hero = active->getStacklist()->getNearestHero(dest, 4);
80 hero_selected.emit(hero);