1 // Copyright (C) 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
21 #include <sigc++/functors/mem_fun.h>
23 #include "diplomacy-report-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
31 #include "GraphicsCache.h"
32 #include "playerlist.h"
35 DiplomacyReportDialog::DiplomacyReportDialog(Player *player)
37 GraphicsCache *gc = GraphicsCache::getInstance();
38 Playerlist *pl = Playerlist::getInstance();
40 Glib::RefPtr<Gtk::Builder> xml
41 = Gtk::Builder::create_from_file(get_glade_path() +
42 "/diplomacy-report-dialog.ui");
44 xml->get_widget("dialog", dialog);
46 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
48 xml->get_widget("diplomacy_table", d_table);
50 int order[MAX_PLAYERS];
52 /* find the diplomatic order of the players */
53 for (guint32 i = 0; i < MAX_PLAYERS; i++)
56 for (Playerlist::iterator it = pl->begin(); it != pl->end(); ++it)
58 if (pl->getNeutral() == *it)
60 if ((*it)->isDead() == true)
62 if (i != (*it)->getDiplomaticRank() - 1)
64 order[i] = (int) (*it)->getId();
68 /* show the players in order of their diplomatic ranking. */
69 for (guint32 i = 0; i < MAX_PLAYERS; i++)
73 Player *p = pl->getPlayer(order[i]);
75 Glib::RefPtr<Gdk::Pixbuf> pix = gc->getShieldPic(2, p)->to_pixbuf();
76 Gtk::Image *im = manage(new Gtk::Image());
77 im->property_pixbuf() = pix;
78 d_table->attach(*im, 1, 2, i + 1, i + 2, Gtk::SHRINK, Gtk::SHRINK);
79 Gtk::Image *im2 = manage(new Gtk::Image());
80 im2->property_pixbuf() = pix;
81 d_table->attach(*im2, i + 2, i + 3, 0, 0 + 1, Gtk::SHRINK, Gtk::SHRINK);
82 Gtk::Label *label = manage(new Gtk::Label(p->getDiplomaticTitle()));
83 d_table->attach(*label, 0, 1, i + 1, i + 2, Gtk::SHRINK, Gtk::SHRINK);
85 for (guint32 j = 0; j < MAX_PLAYERS; j++)
89 Player::DiplomaticState state;
90 state = p->getDiplomaticState(pl->getPlayer(order[j]));
91 Glib::RefPtr<Gdk::Pixbuf> pix2 = gc->getDiplomacyPic(0, state)->to_pixbuf();
92 Gtk::Image *im3 = manage(new Gtk::Image());
93 im3->property_pixbuf() = pix2;
94 d_table->attach(*im3, i + 2, i + 3, j + 1, j + 2,
95 Gtk::SHRINK, Gtk::SHRINK);
100 DiplomacyReportDialog::~DiplomacyReportDialog()
104 void DiplomacyReportDialog::set_parent_window(Gtk::Window &parent)
106 dialog->set_transient_for(parent);
107 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
110 void DiplomacyReportDialog::hide()
115 void DiplomacyReportDialog::run()