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
20 #include <sigc++/functors/mem_fun.h>
23 #include "triumphs-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
32 #include "GraphicsCache.h"
33 #include "armysetlist.h"
34 #include "playerlist.h"
37 TriumphsDialog::TriumphsDialog(Player *player)
40 Glib::RefPtr<Gtk::Builder> xml
41 = Gtk::Builder::create_from_file(get_glade_path() + "/triumphs-dialog.ui");
43 xml->get_widget("dialog", dialog);
45 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
48 xml->get_widget("outer_hbox", contents);
49 notebook = Gtk::manage(new Gtk::Notebook());
50 contents->pack_start(*notebook, true, true, 0);
52 //set the notebook to start off on the player's own page
53 notebook->set_current_page(d_player->getId());
56 TriumphsDialog::~TriumphsDialog()
60 void TriumphsDialog::set_parent_window(Gtk::Window &parent)
62 dialog->set_transient_for(parent);
63 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
66 void TriumphsDialog::hide()
70 void TriumphsDialog::run()
76 guint32 TriumphsDialog::tally(Player *p, Triumphs::TriumphType type)
78 Playerlist *pl = Playerlist::getInstance();
82 // add up what the other players did to us
83 for (Playerlist::iterator it = pl->begin(); it != pl->end(); it++)
85 if ((*it) == Playerlist::getInstance()->getNeutral())
87 count += p->getTriumphs()->getTriumphTally(*it, type);
92 // add up what we did to that player
93 count = d_player->getTriumphs()->getTriumphTally(p, type);
98 void TriumphsDialog::fill_in_page(Player *p)
100 GraphicsCache *gc = GraphicsCache::getInstance();
101 //here we tally up the stats, make a vbox and append it as a new page
102 //tally it up differently when p == d_player
106 count = tally(p, Triumphs::TALLY_HERO);
108 s = String::ucompose (ngettext("%1 hero earned fates worthy of legend!",
109 "%1 heroes earned fates worthy of legend!",
112 s = String::ucompose (ngettext
113 ("%1 so-called hero slaughtered without mercy!",
114 "%1 so-called heroes slaughtered without mercy!",
116 Gtk::Label *hero_label = new Gtk::Label(s);
118 const ArmyProto *hero = NULL;
119 const Armysetlist* al = Armysetlist::getInstance();
120 //let's go find the hero army
121 for (unsigned int j = 0; j < al->getSize(p->getArmyset()); j++)
123 const ArmyProto *a = al->getArmy (p->getArmyset(), j);
130 Gtk::Image *hero_image = new Gtk::Image();
131 hero_image->property_pixbuf() = gc->getArmyPic(p->getArmyset(), hero->getTypeId(), p, NULL)->to_pixbuf();
132 Gtk::HBox *hero_hbox = new Gtk::HBox();
133 hero_hbox->pack_start(*manage(hero_image), Gtk::PACK_SHRINK, 10);
134 hero_hbox->pack_start(*manage(hero_label), Gtk::PACK_SHRINK, 10);
136 count = tally(p, Triumphs::TALLY_SHIP);
138 s = String::ucompose (ngettext("%1 navy not currently in service!",
139 "%1 navies not currently in service!",
142 s = String::ucompose (ngettext("%1 navy rests with the fishes!",
143 "%1 navies rest with the fishes!",
145 Gtk::Label *ship_label = new Gtk::Label(s);
146 Gtk::Image *ship_image = new Gtk::Image ();
147 ship_image->property_pixbuf() = gc->getShipPic(p)->to_pixbuf();
148 Gtk::HBox *ship_hbox = new Gtk::HBox();
149 ship_hbox->pack_start(*manage(ship_image), Gtk::PACK_SHRINK, 10);
150 ship_hbox->pack_start(*manage(ship_label), Gtk::PACK_SHRINK, 10);
152 count = tally(p, Triumphs::TALLY_NORMAL);
154 s = String::ucompose (ngettext("%1 army died to ensure final victory!",
155 "%1 armies died to ensure final victory!",
158 s = String::ucompose (ngettext("%1 army smote like sheep!",
159 "%1 armies smote like sheep!",
161 Gtk::Label *normal_label = new Gtk::Label(s);
162 Gtk::Image *normal_image = new Gtk::Image();
163 normal_image->property_pixbuf() = gc->getArmyPic(p->getArmyset(), 0, p, NULL)->to_pixbuf();
164 Gtk::HBox *normal_hbox = new Gtk::HBox();
165 normal_hbox->pack_start(*manage(normal_image), Gtk::PACK_SHRINK, 10);
166 normal_hbox->pack_start(*manage(normal_label), Gtk::PACK_SHRINK, 10);
168 count = tally(p, Triumphs::TALLY_SPECIAL);
171 (ngettext ("%1 unnatural creature returned from whence it came!",
172 "%1 unnatural creatures returned from whence they came!",
175 s = String::ucompose (ngettext ("%1 unnatural creature dispatched!",
176 "%1 unnatural creatures dispatched!",
178 Gtk::Label *special_label = new Gtk::Label(s);
179 //let's go find a special army
180 const ArmyProto *special = NULL;
181 for (unsigned int j = 0; j < al->getSize(p->getArmyset()); j++)
183 const ArmyProto *a = al->getArmy (p->getArmyset(), j);
184 if (a->getAwardable())
190 Gtk::Image *special_image = new Gtk::Image();
191 special_image->property_pixbuf() =
192 gc->getArmyPic(p->getArmyset(), special->getTypeId(), p, NULL)->to_pixbuf();
193 Gtk::HBox *special_hbox = new Gtk::HBox();
194 special_hbox->pack_start(*manage(special_image), Gtk::PACK_SHRINK, 10);
195 special_hbox->pack_start(*manage(special_label), Gtk::PACK_SHRINK, 10);
197 count = tally(p, Triumphs::TALLY_FLAG);
199 s = String::ucompose (ngettext ("%1 standard betrayed by it's guardian!",
200 "%1 standards betrayed by it's guardian!",
203 s = String::ucompose (ngettext
204 ("%1 standard wrested from a vanquished foe!",
205 "%1 standards wrested from a vanquished foe!",
207 Gtk::Label *flag_label = new Gtk::Label(s);
208 Gtk::Image *flag_image = new Gtk::Image ();
209 flag_image->property_pixbuf() = gc->getPlantedStandardPic(p)->to_pixbuf();
210 Gtk::HBox *flag_hbox = new Gtk::HBox();
211 flag_hbox->pack_start(*manage(flag_image), Gtk::PACK_SHRINK, 10);
212 flag_hbox->pack_start(*manage(flag_label), Gtk::PACK_SHRINK, 10);
214 Gtk::VBox *contents = new Gtk::VBox();
215 contents->add(*manage(normal_hbox));
216 contents->add(*manage(special_hbox));
217 contents->add(*manage(hero_hbox));
218 contents->add(*manage(ship_hbox));
219 contents->add(*manage(flag_hbox));
220 Gtk::Image *shield_image = new Gtk::Image();
221 shield_image->property_pixbuf() = gc->getShieldPic(2, p)->to_pixbuf();
222 notebook->append_page (*manage(contents), *manage(shield_image));
225 void TriumphsDialog::fill_in_info()
227 for (unsigned int i = 0; i < MAX_PLAYERS; i++)
229 Player *p = Playerlist::getInstance()->getPlayer(i);
232 if (p == Playerlist::getInstance()->getNeutral())