1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2007, 2008, 2009, 2011, 2014, 2020 Ben Asselstine
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301, USA.
18
19 #include <config.h>
20
21 #include <gtkmm.h>
22 #include <sigc++/functors/mem_fun.h>
23
24 #include "hero-levels-dialog.h"
25
26 #include "ucompose.hpp"
27 #include "defs.h"
28 #include "player.h"
29 #include "army.h"
30 #include "hero.h"
31 #include "ImageCache.h"
32 #include "shield.h"
33 #include "font-size.h"
34
init(Player * theplayer)35 void HeroLevelsDialog::init(Player *theplayer)
36 {
37 player = theplayer;
38
39 heroes_list = Gtk::ListStore::create(heroes_columns);
40 xml->get_widget("treeview", heroes_treeview);
41 heroes_treeview->set_model(heroes_list);
42 heroes_treeview->append_column("", heroes_columns.image);
43 heroes_treeview->append_column(_("Hero"), heroes_columns.name);
44 heroes_treeview->append_column(_("Level"), heroes_columns.level);
45 heroes_treeview->append_column(_("Exp"), heroes_columns.exp);
46 heroes_treeview->append_column(_("Needs"), heroes_columns.needs);
47 heroes_treeview->append_column(_("Str"), heroes_columns.str);
48 heroes_treeview->append_column(_("Move"), heroes_columns.move);
49 heroes_treeview->set_headers_visible(true);
50 }
51
HeroLevelsDialog(Gtk::Window & parent,std::list<Hero * > heroes)52 HeroLevelsDialog::HeroLevelsDialog(Gtk::Window &parent, std::list<Hero*> heroes)
53 : LwDialog(parent, "hero-levels-dialog.ui")
54 {
55 init ((*heroes.front()).getOwner());
56 for (std::list<Hero*>::iterator it = heroes.begin(); it != heroes.end(); it++)
57 addHero(*it);
58 }
59
HeroLevelsDialog(Gtk::Window & parent,Player * theplayer)60 HeroLevelsDialog::HeroLevelsDialog(Gtk::Window &parent, Player *theplayer)
61 : LwDialog(parent, "hero-levels-dialog.ui")
62 {
63 init (theplayer);
64 std::list<Hero*> heroes = theplayer->getHeroes();
65 for (std::list<Hero*>::iterator it = heroes.begin(); it != heroes.end(); it++)
66 addHero(*it);
67 }
68
addHero(Hero * h)69 void HeroLevelsDialog::addHero(Hero *h)
70 {
71 Gtk::TreeIter i = heroes_list->append();
72 (*i)[heroes_columns.name] = h->getName();
73 (*i)[heroes_columns.image] =
74 ImageCache::getInstance()->getCircledArmyPic
75 (player->getArmyset(), h->getTypeId(), player, NULL, false, Shield::NEUTRAL,
76 true, FontSize::getInstance()->get_height ())->to_pixbuf();
77 (*i)[heroes_columns.level] = String::ucompose("%1", h->getLevel());
78 (*i)[heroes_columns.exp] = (guint32)h->getXP();
79 (*i)[heroes_columns.needs] = (guint32)h->getXpNeededForNextLevel();
80 (*i)[heroes_columns.str] = h->getStat(Army::STRENGTH, true);
81 (*i)[heroes_columns.move] = h->getStat(Army::MOVES, true);
82 }
83