1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
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.
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.
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
22 #include <sigc++/functors/mem_fun.h>
24 #include "army-bonus-dialog.h"
26 #include "glade-helpers.h"
27 #include "image-helpers.h"
28 #include "ucompose.hpp"
31 #include "armysetlist.h"
33 #include "GraphicsCache.h"
36 ArmyBonusDialog::ArmyBonusDialog(Player *p)
39 Glib::RefPtr<Gtk::Builder> xml
40 = Gtk::Builder::create_from_file(get_glade_path()
41 + "/army-bonus-dialog.ui");
43 xml->get_widget("dialog", dialog);
45 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
46 dialog->set_icon_from_file(File::getMiscFile("various/castle_icon.png"));
48 armies_list = Gtk::ListStore::create(armies_columns);
49 xml->get_widget("treeview", armies_treeview);
50 armies_treeview->set_model(armies_list);
51 armies_treeview->append_column("", armies_columns.image);
52 armies_treeview->append_column("", armies_columns.name);
53 armies_treeview->append_column("Str", armies_columns.str);
54 armies_treeview->append_column("Move", armies_columns.move);
55 armies_treeview->append_column("", armies_columns.move_image);
56 armies_treeview->append_column("Bonus", armies_columns.bonus);
57 armies_treeview->set_headers_visible(true);
59 guint32 max = Armysetlist::getInstance()->getSize(d_player->getArmyset());
60 for (unsigned int i = 0; i < max; i++)
64 ArmyBonusDialog::~ArmyBonusDialog()
68 void ArmyBonusDialog::set_parent_window(Gtk::Window &parent)
70 dialog->set_transient_for(parent);
71 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
74 void ArmyBonusDialog::hide()
79 void ArmyBonusDialog::run()
81 static int width = -1;
82 static int height = -1;
84 if (width != -1 && height != -1)
85 dialog->set_default_size(width, height);
90 dialog->get_size(width, height);
94 void ArmyBonusDialog::addArmyType(guint32 army_type)
96 GraphicsCache *gc = GraphicsCache::getInstance();
99 a = Armysetlist::getInstance()->getArmy(p->getArmyset(), army_type);
101 return; //we don't want to show heroes in this list
102 Gtk::TreeIter i = armies_list->append();
103 (*i)[armies_columns.name] = a->getName();
104 (*i)[armies_columns.image] = gc->getArmyPic(p->getArmyset(), army_type,
105 p, NULL)->to_pixbuf();
106 (*i)[armies_columns.str] = a->getStrength();
107 (*i)[armies_columns.move] = a->getMaxMoves();
108 guint32 b = a->getMoveBonus();
109 (*i)[armies_columns.move_image] = gc->getMoveBonusPic(b, false)->to_pixbuf();
110 (*i)[armies_columns.bonus] = "-";
112 std::string s = a->getArmyBonusDescription();
114 (*i)[armies_columns.bonus] = "-";
116 (*i)[armies_columns.bonus] = s;