~ubuntu-branches/ubuntu/precise/lordsawar/precise

« back to all changes in this revision

Viewing changes to src/gui/triumphs-dialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2007-10-29 15:38:06 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071029153806-z2j47adhmdjc7wae
Tags: 0.0.4-1
* New upstream release
* Add desktop file and simple manpage for new binary lordsawar-army-editor
* Syntax fixes on manpages
* Move manpages to correct section (6)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  This program is free software; you can redistribute it and/or modify
 
2
//  it under the terms of the GNU General Public License as published by
 
3
//  the Free Software Foundation; either version 2 of the License, or
 
4
//  (at your option) any later version.
 
5
//
 
6
//  This program is distributed in the hope that it will be useful,
 
7
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
//  GNU Library General Public License for more details.
 
10
//
 
11
//  You should have received a copy of the GNU General Public License
 
12
//  along with this program; if not, write to the Free Software
 
13
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*
 
14
 
 
15
#include <config.h>
 
16
 
 
17
#include <libglademm/xml.h>
 
18
#include <sigc++/functors/mem_fun.h>
 
19
#include <gtkmm/label.h>
 
20
#include <gtkmm/scrolledwindow.h>
 
21
#include <gtkmm/notebook.h>
 
22
#include <gtkmm/image.h>
 
23
 
 
24
#include "triumphs-dialog.h"
 
25
 
 
26
#include "glade-helpers.h"
 
27
#include "image-helpers.h"
 
28
#include "input-helpers.h"
 
29
#include "../ucompose.hpp"
 
30
#include "../defs.h"
 
31
#include "../File.h"
 
32
#include "../GameMap.h"
 
33
#include "../GraphicsCache.h"
 
34
#include "../armysetlist.h"
 
35
#include "../playerlist.h"
 
36
#include "../player.h"
 
37
 
 
38
TriumphsDialog::TriumphsDialog(Player *player)
 
39
{
 
40
  d_player = player;
 
41
  Glib::RefPtr<Gnome::Glade::Xml> xml
 
42
    = Gnome::Glade::Xml::create(get_glade_path() + "/triumphs-dialog.glade");
 
43
 
 
44
  Gtk::Dialog *d = 0;
 
45
  xml->get_widget("dialog", d);
 
46
  dialog.reset(d);
 
47
 
 
48
  Gtk::HBox *contents;
 
49
  xml->get_widget("outer_hbox", contents);
 
50
  notebook = Gtk::manage(new Gtk::Notebook());
 
51
  contents->pack_start(*notebook, true, true, 0);
 
52
  fill_in_info();
 
53
  //set the notebook to start off on the player's own page
 
54
  notebook->set_current_page(d_player->getId());
 
55
}
 
56
 
 
57
void TriumphsDialog::set_parent_window(Gtk::Window &parent)
 
58
{
 
59
  dialog->set_transient_for(parent);
 
60
  //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
 
61
}
 
62
 
 
63
void TriumphsDialog::run()
 
64
{
 
65
  dialog->show_all();
 
66
  dialog->run();
 
67
}
 
68
 
 
69
Uint32 TriumphsDialog::tally(Player *p, Player::TriumphType type)
 
70
{
 
71
  Uint32 count = 0;
 
72
  if (p == d_player)
 
73
    {
 
74
      // add up what the other players did to us
 
75
      for (unsigned int i = 0; i < MAX_PLAYERS; i++)
 
76
        {
 
77
          count += p->getTriumphTally(Playerlist::getInstance()->getPlayer(i), 
 
78
                                      type);
 
79
        }
 
80
    }
 
81
  else
 
82
    {
 
83
      // add up what we did to that player
 
84
      count = d_player->getTriumphTally(p, type);
 
85
    }
 
86
  return count;
 
87
}
 
88
 
 
89
void TriumphsDialog::fill_in_page(Player *p)
 
90
{
 
91
  GraphicsCache *gc = GraphicsCache::getInstance();
 
92
  //here we tally up the stats, make a vbox and append it as a new page
 
93
  //tally it up differently when p == d_player
 
94
        
 
95
  Uint32 count;
 
96
  Glib::ustring s;
 
97
  count = tally(p, Player::TALLY_HERO);
 
98
  if (p == d_player)
 
99
    s = String::ucompose (ngettext("%1 hero earned fates worthy of legend!",
 
100
                                   "%1 heroes earned fates worthy of legend!",
 
101
                                   count), count);
 
102
  else
 
103
    s = String::ucompose (ngettext
 
104
                          ("%1 so-called hero slaughtered without mercy!",
 
105
                           "%1 so-called heroes slaughtered without mercy!",
 
106
                           count), count);
 
107
  Gtk::Label *hero_label = new Gtk::Label(s);
 
108
 
 
109
  const Army *hero = NULL;
 
110
  const Armysetlist* al = Armysetlist::getInstance();
 
111
  //let's go find the hero army
 
112
  for (unsigned int j = 0; j < al->getSize(p->getArmyset()); j++)
 
113
    {
 
114
      const Army *a = al->getArmy (p->getArmyset(), j);
 
115
      if (a->isHero())
 
116
        {
 
117
          hero = a;
 
118
          break;
 
119
        }
 
120
    }
 
121
  Gtk::Image *hero_image = new Gtk::Image
 
122
    (to_pixbuf(gc->getArmyPic(p->getArmyset(), hero->getType(), p, NULL)));
 
123
  Gtk::HBox *hero_hbox = new Gtk::HBox();
 
124
  hero_hbox->pack_start(*manage(hero_image), Gtk::PACK_SHRINK, 10);
 
125
  hero_hbox->pack_start(*manage(hero_label), Gtk::PACK_SHRINK, 10);
 
126
 
 
127
  count = tally(p, Player::TALLY_SHIP);
 
128
  if (p == d_player)
 
129
    s = String::ucompose (ngettext("%1 navy not currently in service!",
 
130
                                   "%1 navies not currently in service!",
 
131
                                   count), count);
 
132
  else
 
133
    s = String::ucompose (ngettext("%1 navy rests with the fishes!",
 
134
                                   "%1 navies rest with the fishes!",
 
135
                                   count), count);
 
136
  Gtk::Label *ship_label = new Gtk::Label(s);
 
137
  Gtk::Image *ship_image = new Gtk::Image (to_pixbuf(gc->getShipPic(p)));
 
138
  Gtk::HBox *ship_hbox = new Gtk::HBox();
 
139
  ship_hbox->pack_start(*manage(ship_image), Gtk::PACK_SHRINK, 10);
 
140
  ship_hbox->pack_start(*manage(ship_label), Gtk::PACK_SHRINK, 10);
 
141
 
 
142
  count = tally(p, Player::TALLY_NORMAL);
 
143
  if (p == d_player)
 
144
    s = String::ucompose (ngettext("%1 army died to ensure final victory!",
 
145
                                   "%1 armies died to ensure final victory!",
 
146
                                   count), count);
 
147
  else
 
148
    s = String::ucompose (ngettext("%1 army smote like sheep!",
 
149
                                   "%1 armies smote like sheep!",
 
150
                                   count), count);
 
151
  Gtk::Label *normal_label = new Gtk::Label(s);
 
152
  Gtk::Image *normal_image = new Gtk::Image
 
153
    (to_pixbuf(gc->getArmyPic(p->getArmyset(), 0, p, NULL)));
 
154
  Gtk::HBox *normal_hbox = new Gtk::HBox();
 
155
  normal_hbox->pack_start(*manage(normal_image), Gtk::PACK_SHRINK, 10);
 
156
  normal_hbox->pack_start(*manage(normal_label), Gtk::PACK_SHRINK, 10);
 
157
 
 
158
  count = tally(p, Player::TALLY_SPECIAL);
 
159
  if (p == d_player)
 
160
    s = String::ucompose 
 
161
      (ngettext ("%1 unnatural creature returned from whence it came!",
 
162
                 "%1 unnatural creatures returned from whence they came!",
 
163
                 count), count);
 
164
  else
 
165
    s = String::ucompose (ngettext ("%1 unnatural creature dispatched!",
 
166
                                    "%1 unnatural creatures dispatched!",
 
167
                                    count), count);
 
168
  Gtk::Label *special_label = new Gtk::Label(s);
 
169
  //let's go find a special army
 
170
  const Army *special = NULL;
 
171
  for (unsigned int j = 0; j < al->getSize(p->getArmyset()); j++)
 
172
    {
 
173
      const Army *a = al->getArmy (p->getArmyset(), j);
 
174
      if (a->getAwardable())
 
175
        {
 
176
          special = a;
 
177
          break;
 
178
        }
 
179
    }
 
180
  Gtk::Image *special_image = new Gtk::Image
 
181
    (to_pixbuf(gc->getArmyPic(p->getArmyset(), 
 
182
                              special->getType(), p, NULL)));
 
183
  Gtk::HBox *special_hbox = new Gtk::HBox();
 
184
  special_hbox->pack_start(*manage(special_image), Gtk::PACK_SHRINK, 10);
 
185
  special_hbox->pack_start(*manage(special_label), Gtk::PACK_SHRINK, 10);
 
186
 
 
187
  count = tally(p, Player::TALLY_FLAG);
 
188
  if (p == d_player)
 
189
    s = String::ucompose (ngettext ("%1 standard betrayed by it's guardian!",
 
190
                                    "%1 standards betrayed by it's guardian!",
 
191
                                    count), count);
 
192
  else
 
193
    s = String::ucompose (ngettext 
 
194
                          ("%1 standard wrested from a vanquished foe!",
 
195
                           "%1 standards wrested from a vanquished foe!",
 
196
                           count), count);
 
197
  Gtk::Label *flag_label = new Gtk::Label(s);
 
198
  Gtk::Image *flag_image = new Gtk::Image 
 
199
    (to_pixbuf(gc->getPlantedStandardPic(p)));
 
200
  Gtk::HBox *flag_hbox = new Gtk::HBox();
 
201
  flag_hbox->pack_start(*manage(flag_image), Gtk::PACK_SHRINK, 10);
 
202
  flag_hbox->pack_start(*manage(flag_label), Gtk::PACK_SHRINK, 10);
 
203
 
 
204
  Gtk::VBox *contents = new Gtk::VBox();
 
205
  contents->add(*manage(normal_hbox));
 
206
  contents->add(*manage(special_hbox));
 
207
  contents->add(*manage(hero_hbox));
 
208
  contents->add(*manage(ship_hbox));
 
209
  contents->add(*manage(flag_hbox));
 
210
  notebook->append_page 
 
211
    (*manage(contents), 
 
212
     *manage(new Gtk::Image(to_pixbuf(gc->getShieldPic(2, p)))));
 
213
}
 
214
 
 
215
void TriumphsDialog::fill_in_info()
 
216
{
 
217
  Playerlist::iterator pit = Playerlist::getInstance()->begin();
 
218
  for (; pit != Playerlist::getInstance()->end(); ++pit)
 
219
    {
 
220
      if (*pit == Playerlist::getInstance()->getNeutral())
 
221
        continue;
 
222
      fill_in_page(*pit);
 
223
    }
 
224
}