1 // Copyright (C) 2008, 2009, 2014, 2020 Ben Asselstine
2 //
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.
7 //
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.
12 //
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
16 // 02110-1301, USA.
17
18 #include <config.h>
19
20 #include <gtkmm.h>
21 #include <sigc++/functors/mem_fun.h>
22
23 #include "diplomacy-report-dialog.h"
24
25 #include "defs.h"
26 #include "ImageCache.h"
27 #include "playerlist.h"
28 #include "player.h"
29 #include "font-size.h"
30
DiplomacyReportDialog(Gtk::Window & parent,Player * player)31 DiplomacyReportDialog::DiplomacyReportDialog(Gtk::Window &parent, Player *player)
32 : LwDialog(parent, "diplomacy-report-dialog.ui")
33 {
34 ImageCache *gc = ImageCache::getInstance();
35 Playerlist *pl = Playerlist::getInstance();
36 d_player = player;
37 xml->get_widget("diplomacy_table", d_table);
38
39 int order[MAX_PLAYERS];
40
41 /* find the diplomatic order of the players */
42 for (guint32 i = 0; i < MAX_PLAYERS; i++)
43 {
44 order[i] = -1;
45 for (Playerlist::iterator it = pl->begin(); it != pl->end(); ++it)
46 {
47 if (pl->getNeutral() == *it)
48 continue;
49 if ((*it)->isDead() == true)
50 continue;
51 if (i != (*it)->getDiplomaticRank() - 1)
52 continue;
53 order[i] = (int) (*it)->getId();
54 }
55 }
56
57 /* show the players in order of their diplomatic ranking. */
58 for (guint32 i = 0; i < MAX_PLAYERS; i++)
59 {
60 if (order[i] == -1)
61 continue;
62 Player *p = pl->getPlayer(order[i]);
63
64 Glib::RefPtr<Gdk::Pixbuf> pix =
65 gc->getShieldPic(2, p, false,
66 FontSize::getInstance ()->get_height ())->to_pixbuf();
67 Gtk::Image *im = manage(new Gtk::Image());
68 im->property_pixbuf() = pix;
69 d_table->attach(*im, 1, i+1, 1, 1);
70 Gtk::Image *im2 = manage(new Gtk::Image());
71 im2->property_pixbuf() = pix;
72 d_table->attach(*im2, i + 2, 0, 1, 1);
73 Gtk::Label *label = manage(new Gtk::Label(p->getDiplomaticTitle()));
74 d_table->attach(*label, 0, i+1, 1, 1);
75
76 for (guint32 j = 0; j < MAX_PLAYERS; j++)
77 {
78 if (order[j] == -1)
79 continue;
80 Player::DiplomaticState state;
81 state = p->getDiplomaticState(pl->getPlayer(order[j]));
82 Glib::RefPtr<Gdk::Pixbuf> pix2 =
83 gc->getDiplomacyPic
84 (0, state, FontSize::getInstance ()->get_height ())->to_pixbuf();
85 Gtk::Image *im3 = manage(new Gtk::Image());
86 im3->property_pixbuf() = pix2;
87 d_table->attach(*im3, i + 2, j + 1, 1, 1);
88 }
89 }
90 }
91