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-dialog.h"
24 #include "diplomacy-report-dialog.h"
26 #include "glade-helpers.h"
27 #include "image-helpers.h"
28 #include "input-helpers.h"
29 #include "ucompose.hpp"
32 #include "GraphicsCache.h"
33 #include "playerlist.h"
36 DiplomacyDialog::DiplomacyDialog(Player *player)
38 GraphicsCache *gc = GraphicsCache::getInstance();
39 Playerlist *pl = Playerlist::getInstance();
41 Glib::RefPtr<Gtk::Builder> xml
42 = Gtk::Builder::create_from_file(get_glade_path() + "/diplomacy-dialog.ui");
44 xml->get_widget("dialog", dialog);
46 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
48 xml->get_widget("proposals_table", d_proposals_table);
49 xml->get_widget("offers_table", d_offers_table);
50 xml->get_widget("player_label", d_player_label);
51 xml->get_widget("player_shield_image", d_player_shield_image);
52 xml->get_widget("report_button", d_report_button);
54 d_report_button->signal_clicked().connect
55 (sigc::mem_fun(*this, &DiplomacyDialog::on_report_clicked));
57 // put the shields across the top of the proposals table, minus our own
60 for (unsigned int k = 0; k < MAX_PLAYERS; k++)
62 Player *p = pl->getPlayer(k);
65 if (pl->getNeutral() == p)
69 Glib::RefPtr<Gdk::Pixbuf> pixbuf= gc->getShieldPic(2, p)->to_pixbuf();
70 Gtk::Image *im = new Gtk::Image();
71 im->property_pixbuf() = pixbuf;
72 //im->set_padding(11, 0);
73 d_proposals_table->attach(*manage(im), i + 0, i + 1, 0, 1,
74 Gtk::SHRINK, Gtk::SHRINK);
77 d_proposals_table->set_col_spacings (16);
79 d_player_shield_image->property_pixbuf() = gc->getShieldPic(2, d_player)->to_pixbuf();
81 d_player_label->set_text(d_player->getName());
83 //fill in diplomatic state
86 for (unsigned int k = 0; k < MAX_PLAYERS; k++)
88 Player *p = pl->getPlayer(k);
91 if (pl->getNeutral() == p)
101 Player::DiplomaticState state = d_player->getDiplomaticState (p);
102 Glib::RefPtr<Gdk::Pixbuf> pixbuf= gc->getDiplomacyPic(1, state)->to_pixbuf();
103 Gtk::Image *im = new Gtk::Image();
104 im->property_pixbuf() = pixbuf;
105 d_proposals_table->attach(*manage(im), i + 0, i + 1, j + 1, j + 2,
106 Gtk::SHRINK, Gtk::SHRINK);
107 Player::DiplomaticProposal proposal = p->getDiplomaticProposal (d_player);
108 if (proposal != Player::NO_PROPOSAL)
111 Glib::RefPtr<Gdk::Pixbuf> pixbuf2;
114 case Player::PROPOSE_PEACE:
115 pixbuf2 = gc->getDiplomacyPic(1, Player::AT_PEACE)->to_pixbuf();
117 case Player::PROPOSE_WAR_IN_FIELD:
118 pixbuf2 = gc->getDiplomacyPic(1, Player::AT_WAR_IN_FIELD)->to_pixbuf();
120 case Player::PROPOSE_WAR:
121 pixbuf2 = gc->getDiplomacyPic(1, Player::AT_WAR)->to_pixbuf();
127 Gtk::Image *im2 = manage(new Gtk::Image());
128 im2->property_pixbuf() = pixbuf2;
129 d_proposals_table->attach(*manage(im2), i + 0, i + 1, j + 1, j + 2,
130 Gtk::SHRINK, Gtk::SHRINK);
136 // fill in the togglebuttons
139 for (unsigned int k = 0; k < MAX_PLAYERS; k++)
141 Player *p = pl->getPlayer(k);
144 if (pl->getNeutral() == p)
149 //show the peace radio buttons
151 Gtk::RadioButton *radio1= manage(new Gtk::RadioButton);
152 Gtk::Image *im3 = new Gtk::Image();
153 im3->property_pixbuf() =
154 gc->getDiplomacyPic(1, Player::AT_PEACE)->to_pixbuf();
155 radio1->add(*manage(im3));
156 radio1->set_mode(false);
157 Gtk::RadioButtonGroup group = radio1->get_group();
159 radio1->set_sensitive(false);
161 radio1->set_active (d_player->getDiplomaticProposal(p) ==
162 Player::PROPOSE_PEACE);
163 radio1->signal_toggled().connect(
164 sigc::bind(sigc::mem_fun
165 (this, &DiplomacyDialog::on_proposal_toggled),
166 radio1, p, Player::PROPOSE_PEACE));
167 d_offers_table->attach(*radio1, i, i + 1, j + 0, j + 1,
168 Gtk::SHRINK, Gtk::SHRINK);
171 Gtk::RadioButton *radio2= manage(new Gtk::RadioButton);
172 Gtk::Image *im4 = new Gtk::Image();
173 im4->property_pixbuf() =
174 gc->getDiplomacyPic(1, Player::AT_WAR_IN_FIELD)->to_pixbuf();
175 radio2->add(*manage(im4));
176 radio2->set_mode(false);
177 radio2->set_group(group);
179 radio2->set_sensitive(false);
181 radio2->set_active (d_player->getDiplomaticProposal(p) ==
182 Player::PROPOSE_WAR_IN_FIELD);
183 radio2->signal_toggled().connect(
184 sigc::bind(sigc::mem_fun(this,
185 &DiplomacyDialog::on_proposal_toggled),
186 radio2, p, Player::PROPOSE_WAR_IN_FIELD));
187 d_offers_table->attach(*radio2, i, i + 1, j + 0, j + 1,
188 Gtk::SHRINK, Gtk::SHRINK);
191 Gtk::RadioButton *radio3= manage(new Gtk::RadioButton);
192 Gtk::Image *im5 = new Gtk::Image();
193 im5->property_pixbuf() =
194 gc->getDiplomacyPic(1, Player::AT_WAR)->to_pixbuf();
195 radio3->add(*manage(im5));
196 radio3->set_mode(false);
197 radio3->set_group(group);
199 radio3->set_sensitive(false);
201 radio3->set_active (d_player->getDiplomaticProposal(p) ==
202 Player::PROPOSE_WAR);
203 radio3->signal_toggled().connect(
204 sigc::bind(sigc::mem_fun(this,
205 &DiplomacyDialog::on_proposal_toggled),
206 radio3, p, Player::PROPOSE_WAR));
207 d_offers_table->attach(*radio3, i, i + 1, j + 0, j + 1,
208 Gtk::SHRINK, Gtk::SHRINK);
213 DiplomacyDialog::~DiplomacyDialog()
217 void DiplomacyDialog::on_proposal_toggled (Gtk::ToggleButton *toggle,
219 Player::DiplomaticProposal proposal)
221 if (toggle->get_active() == true)
222 d_player->proposeDiplomacy (proposal, player);
225 void DiplomacyDialog::set_parent_window(Gtk::Window &parent)
227 dialog->set_transient_for(parent);
228 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
232 void DiplomacyDialog::on_report_clicked()
234 DiplomacyReportDialog d(d_player);
235 d.set_parent_window(*dialog);
240 void DiplomacyDialog::hide()
244 void DiplomacyDialog::run()