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 "army-bonus-dialog.h"
25 
26 #include "armysetlist.h"
27 #include "player.h"
28 #include "ImageCache.h"
29 #include "font-size.h"
30 
ArmyBonusDialog(Gtk::Window & parent,Player * p)31 ArmyBonusDialog::ArmyBonusDialog(Gtk::Window &parent, Player *p)
32  :LwDialog(parent, "army-bonus-dialog.ui")
33 {
34   d_player = p;
35 
36   armies_list = Gtk::ListStore::create(armies_columns);
37   xml->get_widget("treeview", armies_treeview);
38   armies_treeview->set_model(armies_list);
39   armies_treeview->append_column("", armies_columns.image);
40   armies_treeview->append_column("", armies_columns.name);
41   armies_treeview->append_column(_("Str"), armies_columns.str);
42   armies_treeview->append_column(_("Move"), armies_columns.move);
43   armies_treeview->append_column("", armies_columns.move_image);
44   armies_treeview->append_column(_("Bonus"), armies_columns.bonus);
45   armies_treeview->set_headers_visible(true);
46 
47   Armyset *as = Armysetlist::getInstance()->get(d_player->getArmyset());
48   for (Armyset::iterator i = as->begin(); i != as->end(); ++i)
49     addArmyType((*i)->getId());
50 }
51 
addArmyType(guint32 army_type)52 void ArmyBonusDialog::addArmyType(guint32 army_type)
53 {
54   ImageCache *gc = ImageCache::getInstance();
55   Player *p = d_player;
56   const ArmyProto *a =
57     Armysetlist::getInstance()->getArmy(p->getArmyset(), army_type);
58   if (a->isHero())
59     return; //we don't want to show heroes in this list
60   Gtk::TreeIter i = armies_list->append();
61   (*i)[armies_columns.name] = a->getName();
62   (*i)[armies_columns.image] =
63     gc->getCircledArmyPic(p->getArmyset(), army_type, p, NULL, false,
64                           p->getId(), true,
65                           FontSize::getInstance ()->get_height ())->to_pixbuf();
66   (*i)[armies_columns.str] = a->getStrength();
67   (*i)[armies_columns.move] = a->getMaxMoves();
68   guint32 b = a->getMoveBonus();
69   (*i)[armies_columns.move_image] =
70     gc->getMoveBonusPic(b, false,
71                         FontSize::getInstance ()->get_height ())->to_pixbuf();
72   (*i)[armies_columns.bonus] = "-";
73 
74   Glib::ustring s = a->getArmyBonusDescription();
75   if (s == "")
76     (*i)[armies_columns.bonus] = "-";
77   else
78     (*i)[armies_columns.bonus] = s;
79 }
80