initial commit, lordsawar source, slightly modified
[lordsawar] / src / editor / armyset-window.cpp
1 //  Copyright (C) 2007, 2008, 2009 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 <iostream>
21 #include <iomanip>
22 #include <assert.h>
23 #include <libgen.h>
24 #include <string.h>
25
26 #include <sigc++/functors/mem_fun.h>
27 #include <sigc++/functors/ptr_fun.h>
28
29 #include <gtkmm.h>
30 #include "armyset-window.h"
31 #include "armyset-info-dialog.h"
32 #include "masked-image-editor-dialog.h"
33
34 #include "image-helpers.h"
35 #include "input-helpers.h"
36 #include "error-utils.h"
37
38 #include "defs.h"
39 #include "Configuration.h"
40 #include "GraphicsCache.h"
41 #include "armysetlist.h"
42 #include "Tile.h"
43 #include "File.h"
44 #include "shield.h"
45 #include "shieldsetlist.h"
46
47 #include "ucompose.hpp"
48
49 #include "glade-helpers.h"
50 #include "image-editor-dialog.h"
51
52
53 ArmySetWindow::ArmySetWindow(std::string load_filename)
54 {
55   needs_saving = false;
56   d_armyset = NULL;
57     Glib::RefPtr<Gtk::Builder> xml
58         = Gtk::Builder::create_from_file(get_glade_path() + "/armyset-window.ui");
59
60     xml->get_widget("window", window);
61     window->set_icon_from_file(File::getMiscFile("various/castle_icon.png"));
62     window->signal_delete_event().connect
63       (sigc::mem_fun(*this, &ArmySetWindow::on_window_closed));
64
65     xml->get_widget("white_image", white_image);
66     xml->get_widget("green_image", green_image);
67     xml->get_widget("yellow_image", yellow_image);
68     xml->get_widget("light_blue_image", light_blue_image);
69     xml->get_widget("red_image", red_image);
70     xml->get_widget("dark_blue_image", dark_blue_image);
71     xml->get_widget("orange_image", orange_image);
72     xml->get_widget("black_image", black_image);
73     xml->get_widget("neutral_image", neutral_image);
74     xml->get_widget("name_entry", name_entry);
75     name_entry->signal_changed().connect
76       (sigc::mem_fun(this, &ArmySetWindow::on_name_changed));
77     xml->get_widget("armies_treeview", armies_treeview);
78     xml->get_widget("description_textview", description_textview);
79     description_textview->get_buffer()->signal_changed().connect
80       (sigc::mem_fun(this, &ArmySetWindow::on_description_changed));
81     xml->get_widget("white_image_filechooserbutton", 
82                     white_image_filechooserbutton);
83     white_image_filechooserbutton->signal_selection_changed().connect
84       (sigc::mem_fun(this, &ArmySetWindow::on_white_image_changed));
85     xml->get_widget("green_image_filechooserbutton", 
86                     green_image_filechooserbutton);
87     green_image_filechooserbutton->signal_selection_changed().connect
88       (sigc::mem_fun(this, &ArmySetWindow::on_green_image_changed));
89     xml->get_widget("yellow_image_filechooserbutton", 
90                     yellow_image_filechooserbutton);
91     yellow_image_filechooserbutton->signal_selection_changed().connect
92       (sigc::mem_fun(this, &ArmySetWindow::on_yellow_image_changed));
93     xml->get_widget("light_blue_image_filechooserbutton", 
94                     light_blue_image_filechooserbutton);
95     light_blue_image_filechooserbutton->signal_selection_changed().connect
96       (sigc::mem_fun(this, &ArmySetWindow::on_light_blue_image_changed));
97     xml->get_widget("red_image_filechooserbutton", red_image_filechooserbutton);
98     red_image_filechooserbutton->signal_selection_changed().connect
99       (sigc::mem_fun(this, &ArmySetWindow::on_red_image_changed));
100     xml->get_widget("dark_blue_image_filechooserbutton", 
101                     dark_blue_image_filechooserbutton);
102     dark_blue_image_filechooserbutton->signal_selection_changed().connect
103       (sigc::mem_fun(this, &ArmySetWindow::on_dark_blue_image_changed));
104     xml->get_widget("orange_image_filechooserbutton", 
105                     orange_image_filechooserbutton);
106     orange_image_filechooserbutton->signal_selection_changed().connect
107       (sigc::mem_fun(this, &ArmySetWindow::on_orange_image_changed));
108     xml->get_widget("black_image_filechooserbutton", 
109                     black_image_filechooserbutton);
110     black_image_filechooserbutton->signal_selection_changed().connect
111       (sigc::mem_fun(this, &ArmySetWindow::on_black_image_changed));
112     xml->get_widget("neutral_image_filechooserbutton", 
113                     neutral_image_filechooserbutton);
114     neutral_image_filechooserbutton->signal_selection_changed().connect
115       (sigc::mem_fun(this, &ArmySetWindow::on_neutral_image_changed));
116     xml->get_widget("production_spinbutton", production_spinbutton);
117     production_spinbutton->set_range
118       (double(MIN_PRODUCTION_TURNS_FOR_ARMY_UNITS), 
119        double(MAX_PRODUCTION_TURNS_FOR_ARMY_UNITS));
120     production_spinbutton->signal_changed().connect
121       (sigc::mem_fun(this, &ArmySetWindow::on_production_changed));
122     production_spinbutton->signal_insert_text().connect
123       (sigc::mem_fun(this, &ArmySetWindow::on_production_text_changed));
124     xml->get_widget("cost_spinbutton", cost_spinbutton);
125     cost_spinbutton->set_range(double(MIN_COST_FOR_ARMY_UNITS), 
126                                double(MAX_COST_FOR_ARMY_UNITS));
127     cost_spinbutton->signal_changed().connect
128       (sigc::mem_fun(this, &ArmySetWindow::on_cost_changed));
129     cost_spinbutton->signal_insert_text().connect
130       (sigc::mem_fun(this, &ArmySetWindow::on_cost_text_changed));
131     xml->get_widget("new_cost_spinbutton", new_cost_spinbutton);
132     new_cost_spinbutton->set_range(double(MIN_NEW_COST_FOR_ARMY_UNITS), 
133                                    double(MAX_NEW_COST_FOR_ARMY_UNITS));
134     new_cost_spinbutton->signal_changed().connect
135       (sigc::mem_fun(this, &ArmySetWindow::on_new_cost_changed));
136     new_cost_spinbutton->signal_insert_text().connect
137       (sigc::mem_fun(this, &ArmySetWindow::on_new_cost_text_changed));
138     xml->get_widget("upkeep_spinbutton", upkeep_spinbutton);
139     upkeep_spinbutton->set_range (double(MIN_UPKEEP_FOR_ARMY_UNITS), 
140                                   double(MAX_UPKEEP_FOR_ARMY_UNITS));
141     upkeep_spinbutton->signal_changed().connect
142       (sigc::mem_fun(this, &ArmySetWindow::on_upkeep_changed));
143     upkeep_spinbutton->signal_insert_text().connect
144       (sigc::mem_fun(this, &ArmySetWindow::on_upkeep_text_changed));
145     xml->get_widget("strength_spinbutton", strength_spinbutton);
146     strength_spinbutton->set_range (double(MIN_STRENGTH_FOR_ARMY_UNITS), 
147                                     double(MAX_STRENGTH_FOR_ARMY_UNITS));
148     strength_spinbutton->signal_changed().connect
149       (sigc::mem_fun(this, &ArmySetWindow::on_strength_changed));
150     strength_spinbutton->signal_insert_text().connect
151       (sigc::mem_fun(this, &ArmySetWindow::on_strength_text_changed));
152     xml->get_widget("moves_spinbutton", moves_spinbutton);
153     moves_spinbutton->set_range(double(MIN_MOVES_FOR_ARMY_UNITS), 
154                                 double(MAX_MOVES_FOR_ARMY_UNITS));
155     moves_spinbutton->signal_changed().connect
156       (sigc::mem_fun(this, &ArmySetWindow::on_moves_changed));
157     moves_spinbutton->signal_insert_text().connect
158       (sigc::mem_fun(this, &ArmySetWindow::on_moves_text_changed));
159     xml->get_widget("exp_spinbutton", exp_spinbutton);
160     exp_spinbutton->set_range(double(MIN_EXP_FOR_ARMY_UNITS), 
161                               double(MAX_EXP_FOR_ARMY_UNITS));
162     exp_spinbutton->signal_changed().connect
163       (sigc::mem_fun(this, &ArmySetWindow::on_exp_changed));
164     exp_spinbutton->signal_insert_text().connect
165       (sigc::mem_fun(this, &ArmySetWindow::on_exp_text_changed));
166     xml->get_widget("gender_none_radiobutton", gender_none_radiobutton);
167     gender_none_radiobutton->signal_toggled().connect
168       (sigc::mem_fun(this, &ArmySetWindow::on_gender_none_toggled));
169     xml->get_widget("gender_male_radiobutton", gender_male_radiobutton);
170     gender_male_radiobutton->signal_toggled().connect
171       (sigc::mem_fun(this, &ArmySetWindow::on_gender_male_toggled));
172     xml->get_widget("gender_female_radiobutton", gender_female_radiobutton);
173     gender_female_radiobutton->signal_toggled().connect
174       (sigc::mem_fun(this, &ArmySetWindow::on_gender_female_toggled));
175     xml->get_widget("awardable_checkbutton", awardable_checkbutton);
176     awardable_checkbutton->signal_toggled().connect
177       (sigc::mem_fun(this, &ArmySetWindow::on_awardable_toggled));
178     xml->get_widget("defends_ruins_checkbutton", defends_ruins_checkbutton);
179     defends_ruins_checkbutton->signal_toggled().connect
180       (sigc::mem_fun(this, &ArmySetWindow::on_defends_ruins_toggled));
181     xml->get_widget("sight_spinbutton", sight_spinbutton);
182     sight_spinbutton->set_range(double(MIN_SIGHT_FOR_ARMY_UNITS), 
183                                 double(MAX_SIGHT_FOR_ARMY_UNITS));
184     sight_spinbutton->signal_changed().connect
185       (sigc::mem_fun(this, &ArmySetWindow::on_sight_changed));
186     sight_spinbutton->signal_insert_text().connect
187       (sigc::mem_fun(this, &ArmySetWindow::on_sight_text_changed));
188     xml->get_widget("move_forests_checkbutton", move_forests_checkbutton);
189     move_forests_checkbutton->signal_toggled().connect
190       (sigc::mem_fun(this, &ArmySetWindow::on_move_forests_toggled));
191     xml->get_widget("move_marshes_checkbutton", move_marshes_checkbutton);
192     move_marshes_checkbutton->signal_toggled().connect
193       (sigc::mem_fun(this, &ArmySetWindow::on_move_marshes_toggled));
194     xml->get_widget("move_hills_checkbutton", move_hills_checkbutton);
195     move_hills_checkbutton->signal_toggled().connect
196       (sigc::mem_fun(this, &ArmySetWindow::on_move_hills_toggled));
197     xml->get_widget("move_mountains_checkbutton", move_mountains_checkbutton);
198     move_mountains_checkbutton->signal_toggled().connect
199       (sigc::mem_fun(this, &ArmySetWindow::on_move_mountains_toggled));
200     xml->get_widget("can_fly_checkbutton", can_fly_checkbutton);
201     can_fly_checkbutton->signal_toggled().connect
202       (sigc::mem_fun(this, &ArmySetWindow::on_can_fly_toggled));
203     xml->get_widget("add1strinopen_checkbutton", add1strinopen_checkbutton);
204     add1strinopen_checkbutton->signal_toggled().connect
205       (sigc::mem_fun(this, &ArmySetWindow::on_add1strinopen_toggled));
206     xml->get_widget("add2strinopen_checkbutton", add2strinopen_checkbutton);
207     add2strinopen_checkbutton->signal_toggled().connect
208       (sigc::mem_fun(this, &ArmySetWindow::on_add2strinopen_toggled));
209     xml->get_widget("add1strinforest_checkbutton", add1strinforest_checkbutton);
210     add1strinforest_checkbutton->signal_toggled().connect
211       (sigc::mem_fun(this, &ArmySetWindow::on_add1strinforest_toggled));
212     xml->get_widget("add1strinhills_checkbutton", add1strinhills_checkbutton);
213     add1strinhills_checkbutton->signal_toggled().connect
214       (sigc::mem_fun(this, &ArmySetWindow::on_add1strinhills_toggled));
215     xml->get_widget("add1strincity_checkbutton", add1strincity_checkbutton);
216     add1strincity_checkbutton->signal_toggled().connect
217       (sigc::mem_fun(this, &ArmySetWindow::on_add1strincity_toggled));
218     xml->get_widget("add2strincity_checkbutton", add2strincity_checkbutton);
219     add2strincity_checkbutton->signal_toggled().connect
220       (sigc::mem_fun(this, &ArmySetWindow::on_add2strincity_toggled));
221     xml->get_widget("add1stackinhills_checkbutton", 
222                     add1stackinhills_checkbutton);
223     add1stackinhills_checkbutton->signal_toggled().connect
224       (sigc::mem_fun(this, &ArmySetWindow::on_add1stackinhills_toggled));
225     xml->get_widget("suballcitybonus_checkbutton", suballcitybonus_checkbutton);
226     suballcitybonus_checkbutton->signal_toggled().connect
227       (sigc::mem_fun(this, &ArmySetWindow::on_suballcitybonus_toggled));
228     xml->get_widget("sub1enemystack_checkbutton", sub1enemystack_checkbutton);
229     sub1enemystack_checkbutton->signal_toggled().connect
230       (sigc::mem_fun(this, &ArmySetWindow::on_sub1enemystack_toggled));
231     xml->get_widget("add1stack_checkbutton", add1stack_checkbutton);
232     add1stack_checkbutton->signal_toggled().connect
233       (sigc::mem_fun(this, &ArmySetWindow::on_add1stack_toggled));
234     xml->get_widget("add2stack_checkbutton", add2stack_checkbutton);
235     add2stack_checkbutton->signal_toggled().connect
236       (sigc::mem_fun(this, &ArmySetWindow::on_add2stack_toggled));
237     xml->get_widget("suballnonherobonus_checkbutton", 
238                     suballnonherobonus_checkbutton);
239     suballnonherobonus_checkbutton->signal_toggled().connect
240       (sigc::mem_fun(this, &ArmySetWindow::on_suballnonherobonus_toggled));
241     xml->get_widget("suballherobonus_checkbutton", suballherobonus_checkbutton);
242     suballherobonus_checkbutton->signal_toggled().connect
243       (sigc::mem_fun(this, &ArmySetWindow::on_suballherobonus_toggled));
244     xml->get_widget("add_army_button", add_army_button);
245     add_army_button->signal_clicked().connect
246       (sigc::mem_fun(this, &ArmySetWindow::on_add_army_clicked));
247     xml->get_widget("remove_army_button", remove_army_button);
248     remove_army_button->signal_clicked().connect
249       (sigc::mem_fun(this, &ArmySetWindow::on_remove_army_clicked));
250     xml->get_widget("army_vbox", army_vbox);
251     // connect callbacks for the menu
252     xml->get_widget("new_armyset_menuitem", new_armyset_menuitem);
253     new_armyset_menuitem->signal_activate().connect
254       (sigc::mem_fun(this, &ArmySetWindow::on_new_armyset_activated));
255     xml->get_widget("load_armyset_menuitem", load_armyset_menuitem);
256     load_armyset_menuitem->signal_activate().connect
257       (sigc::mem_fun(this, &ArmySetWindow::on_load_armyset_activated));
258     xml->get_widget("save_armyset_menuitem", save_armyset_menuitem);
259     save_armyset_menuitem->signal_activate().connect
260       (sigc::mem_fun(this, &ArmySetWindow::on_save_armyset_activated));
261     xml->get_widget("validate_armyset_menuitem", validate_armyset_menuitem);
262     validate_armyset_menuitem->signal_activate().connect
263       (sigc::mem_fun(this, &ArmySetWindow::on_validate_armyset_activated));
264     xml->get_widget("quit_menuitem", quit_menuitem);
265     quit_menuitem->signal_activate().connect
266        (sigc::mem_fun(this, &ArmySetWindow::on_quit_activated));
267     xml->get_widget("edit_armyset_info_menuitem", edit_armyset_info_menuitem);
268     edit_armyset_info_menuitem->signal_activate().connect
269       (sigc::mem_fun(this, &ArmySetWindow::on_edit_armyset_info_activated));
270     xml->get_widget("edit_standard_picture_menuitem", 
271                     edit_standard_picture_menuitem);
272     edit_standard_picture_menuitem->signal_activate().connect
273       (sigc::mem_fun(this, &ArmySetWindow::on_edit_standard_picture_activated));
274     xml->get_widget("edit_bag_picture_menuitem", edit_bag_picture_menuitem);
275     edit_bag_picture_menuitem->signal_activate().connect
276       (sigc::mem_fun(this, &ArmySetWindow::on_edit_bag_picture_activated));
277     xml->get_widget("edit_ship_picture_menuitem", edit_ship_picture_menuitem);
278     edit_ship_picture_menuitem->signal_activate().connect
279       (sigc::mem_fun(this, &ArmySetWindow::on_edit_ship_picture_activated));
280     xml->get_widget ("help_about_menuitem", help_about_menuitem);
281     help_about_menuitem->signal_activate().connect
282        (sigc::mem_fun(this, &ArmySetWindow::on_help_about_activated));
283
284     window->signal_delete_event().connect(
285         sigc::mem_fun(*this, &ArmySetWindow::on_delete_event));
286
287     armies_list = Gtk::ListStore::create(armies_columns);
288     armies_treeview->set_model(armies_list);
289     armies_treeview->append_column("", armies_columns.name);
290     armies_treeview->set_headers_visible(false);
291     armies_treeview->get_selection()->signal_changed().connect
292       (sigc::mem_fun(*this, &ArmySetWindow::on_army_selected));
293     armies_treeview->set_reorderable(true);
294
295     update_army_panel();
296     update_armyset_buttons();
297
298     update_armyset_buttons();
299     update_armyset_menuitems();
300
301     if (load_filename.empty() == false)
302       {
303         load_armyset (load_filename);
304         update_armyset_buttons();
305         update_armyset_menuitems();
306         update_army_panel();
307       }
308 }
309
310 void
311 ArmySetWindow::update_armyset_menuitems()
312 {
313   if (d_armyset == NULL)
314     {
315       save_armyset_menuitem->set_sensitive(false);
316       validate_armyset_menuitem->set_sensitive(false);
317       edit_armyset_info_menuitem->set_sensitive(false);
318       edit_standard_picture_menuitem->set_sensitive(false);
319       edit_ship_picture_menuitem->set_sensitive(false);
320     }
321   else
322     {
323       std::string file = d_armyset->getConfigurationFile();
324       if (File::exists(file) == false)
325         save_armyset_menuitem->set_sensitive(true);
326       else if (File::is_writable(file) == false)
327         save_armyset_menuitem->set_sensitive(false);
328       else
329         save_armyset_menuitem->set_sensitive(true);
330       edit_armyset_info_menuitem->set_sensitive(true);
331       edit_standard_picture_menuitem->set_sensitive(true);
332       edit_ship_picture_menuitem->set_sensitive(true);
333       validate_armyset_menuitem->set_sensitive(true);
334     }
335 }
336
337 void
338 ArmySetWindow::update_armyset_buttons()
339 {
340   if (!armies_treeview->get_selection()->get_selected())
341     remove_army_button->set_sensitive(false);
342   else
343     remove_army_button->set_sensitive(true);
344   if (d_armyset == NULL)
345     add_army_button->set_sensitive(false);
346   else
347     add_army_button->set_sensitive(true);
348 }
349
350 void
351 ArmySetWindow::update_army_panel()
352 {
353   //if nothing selected in the treeview, then we don't show anything in
354   //the army panel
355   if (armies_treeview->get_selection()->get_selected() == 0)
356     {
357       //clear all values
358       name_entry->set_text("");
359       description_textview->get_buffer()->set_text("");
360       production_spinbutton->set_value(MIN_PRODUCTION_TURNS_FOR_ARMY_UNITS);
361       cost_spinbutton->set_value(MIN_COST_FOR_ARMY_UNITS);
362       new_cost_spinbutton->set_value(MIN_NEW_COST_FOR_ARMY_UNITS);
363       upkeep_spinbutton->set_value(MIN_UPKEEP_FOR_ARMY_UNITS);
364       strength_spinbutton->set_value(MIN_STRENGTH_FOR_ARMY_UNITS);
365       moves_spinbutton->set_value(MIN_MOVES_FOR_ARMY_UNITS);
366       exp_spinbutton->set_value(0);
367       gender_none_radiobutton->set_active(true);
368       gender_male_radiobutton->set_active(false);
369       gender_female_radiobutton->set_active(false);
370       awardable_checkbutton->set_active(false);
371       defends_ruins_checkbutton->set_active(false);
372       sight_spinbutton->set_value(0);
373       move_forests_checkbutton->set_active(false);
374       move_marshes_checkbutton->set_active(false);
375       move_hills_checkbutton->set_active(false);
376       move_mountains_checkbutton->set_active(false);
377       can_fly_checkbutton->set_active(false);
378       add1strinopen_checkbutton->set_active(false);
379       add2strinopen_checkbutton->set_active(false);
380       add1strinforest_checkbutton->set_active(false);
381       add1strinhills_checkbutton->set_active(false);
382       add1strincity_checkbutton->set_active(false);
383       add2strincity_checkbutton->set_active(false);
384       add1stackinhills_checkbutton->set_active(false);
385       suballcitybonus_checkbutton->set_active(false);
386       sub1enemystack_checkbutton->set_active(false);
387       add1stack_checkbutton->set_active(false);
388       add2stack_checkbutton->set_active(false);
389       suballnonherobonus_checkbutton->set_active(false);
390       suballherobonus_checkbutton->set_active(false);
391       white_image->clear();
392       green_image->clear();
393       yellow_image->clear();
394       light_blue_image->clear();
395       red_image->clear();
396       dark_blue_image->clear();
397       orange_image->clear();
398       black_image->clear();
399       neutral_image->clear();
400       army_vbox->set_sensitive(false);
401       return;
402     }
403   army_vbox->set_sensitive(true);
404   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
405   Gtk::TreeModel::iterator iterrow = selection->get_selected();
406
407   if (iterrow) 
408     {
409       // Row selected
410       Gtk::TreeModel::Row row = *iterrow;
411
412       ArmyProto *a = row[armies_columns.army];
413       fill_army_info(a);
414     }
415 }
416 ArmySetWindow::~ArmySetWindow()
417 {
418   delete window;
419 }
420
421 void ArmySetWindow::show()
422 {
423   window->show();
424 }
425
426 void ArmySetWindow::hide()
427 {
428   window->hide();
429 }
430
431 bool ArmySetWindow::on_delete_event(GdkEventAny *e)
432 {
433   hide();
434
435   return true;
436 }
437
438 void ArmySetWindow::on_new_armyset_activated()
439 {
440   std::string name = "";
441   int id = Armysetlist::getNextAvailableId();
442   Armyset *armyset = new Armyset(id, name);
443   ArmySetInfoDialog d(armyset, false);
444   d.set_parent_window(*window);
445   int response = d.run();
446   if (response != Gtk::RESPONSE_ACCEPT)
447     {
448       delete armyset;
449       return;
450     }
451   if (d_armyset)
452     delete d_armyset;
453   d_armyset = armyset;
454   armies_list->clear();
455   std::string dir = File::getUserArmysetDir() + "/" + d_armyset->getSubDir();
456   d_armyset->setDirectory(dir);
457   File::create_dir(dir);
458   current_save_filename = d_armyset->getConfigurationFile();
459
460   std::string imgpath = Glib::get_home_dir();
461   //we will copy an image from where the user points into the new armyset dir.
462   white_image_filechooserbutton->set_current_folder(imgpath);
463   green_image_filechooserbutton->set_current_folder(imgpath);
464   yellow_image_filechooserbutton->set_current_folder(imgpath);
465   light_blue_image_filechooserbutton->set_current_folder(imgpath);
466   red_image_filechooserbutton->set_current_folder(imgpath);
467   dark_blue_image_filechooserbutton->set_current_folder(imgpath);
468   orange_image_filechooserbutton->set_current_folder(imgpath);
469   black_image_filechooserbutton->set_current_folder(imgpath);
470   neutral_image_filechooserbutton->set_current_folder(imgpath);
471
472   update_armyset_buttons();
473   update_armyset_menuitems();
474
475   XML_Helper helper(current_save_filename, std::ios::out, false);
476   d_armyset->save(&helper);
477   helper.close();
478   needs_saving = true;
479 }
480
481 void ArmySetWindow::update_filechooserbutton(Gtk::FileChooserButton *b, ArmyProto *a, Shield::Colour c)
482 {
483   std::string file = d_armyset->getFile(a->getImageName(c));
484   if (File::exists(file) == false)
485     b->set_sensitive(true);
486   else if (File::is_writable(file) == false)
487     b->set_sensitive(false);
488   else
489     b->set_sensitive(true);
490 }
491 void ArmySetWindow::on_load_armyset_activated()
492 {
493   Gtk::FileChooserDialog chooser(*window, 
494                                  _("Choose an Armyset to Load"));
495   Gtk::FileFilter sav_filter;
496   sav_filter.add_pattern("*" + ARMYSET_EXT);
497   chooser.set_filter(sav_filter);
498   chooser.set_current_folder(File::getUserArmysetDir());
499
500   chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
501   chooser.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
502   chooser.set_default_response(Gtk::RESPONSE_ACCEPT);
503       
504   chooser.show_all();
505   int res = chooser.run();
506
507   if (res == Gtk::RESPONSE_ACCEPT)
508     {
509       load_armyset(chooser.get_filename());
510       chooser.hide();
511     }
512
513   update_armyset_buttons();
514   update_armyset_menuitems();
515   update_army_panel();
516 }
517
518 void ArmySetWindow::on_validate_armyset_activated()
519 {
520   std::list<std::string> msgs;
521   if (d_armyset == NULL)
522     return;
523   bool valid;
524   valid = d_armyset->validateSize();
525   if (!valid)
526     msgs.push_back(_("There must be at least one army unit in the armyset."));
527   valid = d_armyset->validateHero();
528   if (!valid)
529     msgs.push_back(_("There must be at least one hero in the armyset."));
530   valid = d_armyset->validatePurchasables();
531   if (!valid)
532     msgs.push_back(_("There must be at least one army unit with a production cost of more than zero."));
533   valid = d_armyset->validateRuinDefenders();
534   if (!valid)
535     msgs.push_back(_("There must be at least one army unit than can defend a ruin."));
536   valid = d_armyset->validateAwardables();
537   if (!valid)
538     msgs.push_back(_("There must be at least one army unit than can be awarded to a hero."));
539   valid = d_armyset->validateShip();
540   if (!valid)
541     msgs.push_back(_("The ship image must be set."));
542   valid = d_armyset->validateStandard();
543   if (!valid)
544     msgs.push_back(_("The hero's standard (the flag) image must be set."));
545   valid = d_armyset->validateBag();
546   if (!valid)
547     msgs.push_back(_("The picture for the bag of items must be set."));
548
549   for (Armyset::iterator it = d_armyset->begin(); it != d_armyset->end(); it++)
550     {
551       Shield::Colour c;
552       bool valid = d_armyset->validateArmyUnitImage(*it, c);
553       if (!valid)
554         {
555           msgs.push_back(String::ucompose(_("%1 does not have an image set for the %2 player"), (*it)->getName(), Shield::colourToString(c)));
556           break;
557         }
558     }
559
560   valid = d_armyset->validateArmyUnitNames();
561   if (!valid)
562     msgs.push_back(_("An army unit does not have a name."));
563
564   std::string msg = "";
565   for (std::list<std::string>::iterator it = msgs.begin(); it != msgs.end();
566        it++)
567     msg += (*it) + "\n";
568
569   if (msg != "")
570     {
571       Gtk::MessageDialog dialog(*window, msg);
572       dialog.run();
573       dialog.hide();
574     }
575
576   return;
577 }
578 void ArmySetWindow::on_save_armyset_activated()
579 {
580   if (current_save_filename.empty())
581     current_save_filename = d_armyset->getConfigurationFile();
582   
583   //Reorder the armyset according to the treeview
584   d_armyset->clear();
585   for (Gtk::TreeIter i = armies_list->children().begin(),
586        end = armies_list->children().end(); i != end; ++i) 
587     d_armyset->push_back((*i)[armies_columns.army]);
588
589   XML_Helper helper(current_save_filename, std::ios::out, false);
590   d_armyset->save(&helper);
591   helper.close();
592   needs_saving = false;
593 }
594
595 void ArmySetWindow::on_edit_ship_picture_activated()
596 {
597   std::string filename = "";
598   if (d_armyset->getShipImageName() != "")
599     filename = d_armyset->getFile(d_armyset->getShipImageName());
600   MaskedImageEditorDialog d(filename);
601   d.set_icon_from_file(File::getMiscFile("various/castle_icon.png"));
602   d.run();
603   if (d.get_selected_filename() != "")
604     {
605       std::string file = File::get_basename(d.get_selected_filename());
606       if (d.get_selected_filename() != d_armyset->getFile(file))
607         {
608           //fixme:warn on overrwite.
609           File::copy (d.get_selected_filename(), 
610                       d_armyset->getFile(file));
611         }
612       d_armyset->setShipImageName(file);
613       needs_saving = true;
614     }
615 }
616 void ArmySetWindow::on_edit_standard_picture_activated()
617 {
618   std::string filename = "";
619   if (d_armyset->getStandardImageName() != "")
620     filename = d_armyset->getFile(d_armyset->getStandardImageName());
621   MaskedImageEditorDialog d(filename);
622   d.set_icon_from_file(File::getMiscFile("various/castle_icon.png"));
623   d.run();
624   if (d.get_selected_filename() != "")
625     {
626       std::string file = File::get_basename(d.get_selected_filename());
627       if (d.get_selected_filename() != d_armyset->getFile(file))
628         {
629           //fixme:warn on overrwite.
630           File::copy (d.get_selected_filename(), 
631                       d_armyset->getFile(file));
632         }
633       d_armyset->setStandardImageName(file);
634       needs_saving = true;
635     }
636 }
637 void ArmySetWindow::on_edit_bag_picture_activated()
638 {
639   std::string filename = "";
640   if (d_armyset->getBagImageName().empty() == false)
641     filename = d_armyset->getFile(d_armyset->getBagImageName());
642   ImageEditorDialog d(filename, 1);
643   d.set_icon_from_file(File::getMiscFile("various/tileset_icon.png"));
644   d.set_parent_window(*window);
645   int response = d.run();
646   if (response == Gtk::RESPONSE_ACCEPT)
647     {
648       std::string filename = d.get_selected_filename();
649       std::string name = File::get_basename(filename);
650       File::copy(filename, d_armyset->getFile(name));
651       d_armyset->setBagImageName(name);
652       needs_saving = true;
653     }
654 }
655 void ArmySetWindow::on_edit_armyset_info_activated()
656 {
657   ArmySetInfoDialog d(d_armyset, true);
658   d.set_parent_window(*window);
659   int response = d.run();
660   if (response == Gtk::RESPONSE_ACCEPT)
661     needs_saving = true;
662 }
663
664 void ArmySetWindow::on_help_about_activated()
665 {
666   Gtk::AboutDialog* dialog;
667
668   Glib::RefPtr<Gtk::Builder> xml
669     = Gtk::Builder::create_from_file(get_glade_path() + "/../about-dialog.ui");
670
671   xml->get_widget("dialog", dialog);
672   dialog->set_transient_for(*window);
673   dialog->set_icon_from_file(File::getMiscFile("various/castle_icon.png"));
674
675   dialog->set_version(PACKAGE_VERSION);
676   dialog->set_logo(GraphicsCache::getMiscPicture("castle_icon.png")->to_pixbuf());
677   dialog->show_all();
678   dialog->run();
679   delete dialog;
680
681   return;
682 }
683
684 void ArmySetWindow::addArmyType(guint32 army_type)
685 {
686   ArmyProto *a;
687   //go get army_type in d_armyset
688   a = d_armyset->lookupArmyByType(army_type);
689   Gtk::TreeIter i = armies_list->append();
690   (*i)[armies_columns.name] = a->getName();
691   (*i)[armies_columns.army] = a;
692 }
693
694 void ArmySetWindow::on_army_selected()
695 {
696   update_army_panel();
697   update_armyset_buttons();
698 }
699
700 void ArmySetWindow::fill_army_image(Gtk::FileChooserButton *button, Gtk::Image *image, Shield::Colour c, ArmyProto *army)
701 {
702   if (army->getImageName(c) != "")
703     {
704       image->property_pixbuf() = army->getImage(c)->to_pixbuf();
705     
706       std::string path = d_armyset->getFile(army->getImageName(c));
707       button->set_filename(path);
708     }
709   else
710     {
711       std::string imgpath = d_armyset->getDirectory();
712       button->set_filename("");
713       button->set_current_folder(imgpath);
714       image->clear();
715     }
716 }
717
718 void ArmySetWindow::fill_army_info(ArmyProto *army)
719 {
720   fill_army_image(white_image_filechooserbutton, white_image, Shield::WHITE, 
721                   army);
722   fill_army_image(green_image_filechooserbutton, green_image, Shield::GREEN, 
723                   army);
724   fill_army_image(yellow_image_filechooserbutton, yellow_image, Shield::YELLOW,
725                   army);
726   fill_army_image(light_blue_image_filechooserbutton, light_blue_image, 
727                   Shield::LIGHT_BLUE, army);
728   fill_army_image(red_image_filechooserbutton, red_image, Shield::RED, army);
729   fill_army_image(dark_blue_image_filechooserbutton, dark_blue_image, 
730                   Shield::DARK_BLUE, army);
731   fill_army_image(orange_image_filechooserbutton, orange_image, Shield::ORANGE,
732                   army);
733   fill_army_image(black_image_filechooserbutton, black_image, Shield::BLACK,
734                   army);
735   fill_army_image(neutral_image_filechooserbutton, neutral_image, 
736                   Shield::NEUTRAL, army);
737   name_entry->set_text(army->getName());
738   description_textview->get_buffer()->set_text(army->getDescription());
739   double turns = army->getProduction();
740   production_spinbutton->set_value(turns);
741   cost_spinbutton->set_value(army->getProductionCost());
742   new_cost_spinbutton->set_value(army->getNewProductionCost());
743   upkeep_spinbutton->set_value(army->getUpkeep());
744   strength_spinbutton->set_value(army->getStrength());
745   moves_spinbutton->set_value(army->getMaxMoves());
746   exp_spinbutton->set_value(int(army->getXpReward()));
747   switch (army->getGender())
748     {
749     case Hero::NONE: gender_none_radiobutton->set_active(true); break;
750     case Hero::MALE: gender_male_radiobutton->set_active(true); break;
751     case Hero::FEMALE: gender_female_radiobutton->set_active(true); break;
752     }
753   awardable_checkbutton->set_active(army->getAwardable());
754   defends_ruins_checkbutton->set_active(army->getDefendsRuins());
755   sight_spinbutton->set_value(army->getSight());
756
757   guint32 bonus = army->getMoveBonus();
758   can_fly_checkbutton->set_active (bonus == 
759                                    (Tile::GRASS | Tile::WATER | 
760                                     Tile::FOREST | Tile::HILLS | 
761                                     Tile::MOUNTAIN | Tile::SWAMP));
762   if (can_fly_checkbutton->get_active() == false)
763     {
764       move_forests_checkbutton->set_active
765         ((bonus & Tile::FOREST) == Tile::FOREST);
766       move_marshes_checkbutton->set_active
767         ((bonus & Tile::SWAMP) == Tile::SWAMP);
768       move_hills_checkbutton->set_active
769         ((bonus & Tile::HILLS) == Tile::HILLS);
770       move_mountains_checkbutton->set_active
771         ((bonus & Tile::MOUNTAIN) == Tile::MOUNTAIN);
772     }
773   else
774     {
775       move_forests_checkbutton->set_active(false);
776       move_marshes_checkbutton->set_active(false);
777       move_hills_checkbutton->set_active(false);
778       move_mountains_checkbutton->set_active(false);
779     }
780   bonus = army->getArmyBonus();
781   add1strinopen_checkbutton->set_active
782     ((bonus & Army::ADD1STRINOPEN) == Army::ADD1STRINOPEN);
783   add2strinopen_checkbutton->set_active
784     ((bonus & Army::ADD2STRINOPEN) == Army::ADD2STRINOPEN);
785   add1strinforest_checkbutton->set_active
786     ((bonus & Army::ADD1STRINFOREST) == Army::ADD1STRINFOREST);
787   add1strinhills_checkbutton->set_active
788     ((bonus & Army::ADD1STRINHILLS) == Army::ADD1STRINHILLS);
789   add1strincity_checkbutton->set_active
790     ((bonus & Army::ADD1STRINCITY) == Army::ADD1STRINCITY);
791   add2strincity_checkbutton->set_active
792     ((bonus & Army::ADD2STRINCITY) == Army::ADD2STRINCITY);
793   add1stackinhills_checkbutton->set_active
794     ((bonus & Army::ADD1STACKINHILLS) == Army::ADD1STACKINHILLS);
795   suballcitybonus_checkbutton->set_active
796     ((bonus & Army::SUBALLCITYBONUS) == Army::SUBALLCITYBONUS);
797   sub1enemystack_checkbutton->set_active
798     ((bonus & Army::SUB1ENEMYSTACK) == Army::SUB1ENEMYSTACK);
799   add1stack_checkbutton->set_active
800     ((bonus & Army::ADD1STACK) == Army::ADD1STACK);
801   add2stack_checkbutton->set_active
802     ((bonus & Army::ADD2STACK) == Army::ADD2STACK);
803   suballnonherobonus_checkbutton->set_active
804     ((bonus & Army::SUBALLNONHEROBONUS) == Army::SUBALLNONHEROBONUS);
805   suballherobonus_checkbutton->set_active
806     ((bonus & Army::SUBALLHEROBONUS) == Army::SUBALLHEROBONUS);
807 }
808
809 void ArmySetWindow::on_name_changed()
810 {
811   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
812   Gtk::TreeModel::iterator iterrow = selection->get_selected();
813
814   if (iterrow) 
815     {
816       Gtk::TreeModel::Row row = *iterrow;
817       ArmyProto *a = row[armies_columns.army];
818       a->setName(name_entry->get_text());
819       row[armies_columns.name] = name_entry->get_text();
820       needs_saving = true;
821     }
822 }
823
824 void ArmySetWindow::on_description_changed()
825 {
826   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
827   Gtk::TreeModel::iterator iterrow = selection->get_selected();
828
829   if (iterrow) 
830     {
831       Gtk::TreeModel::Row row = *iterrow;
832       ArmyProto *a = row[armies_columns.army];
833       a->setDescription(description_textview->get_buffer()->get_text());
834       needs_saving = true;
835     }
836 }
837
838 void ArmySetWindow::on_image_changed(Gtk::FileChooserButton *button, Gtk::Image *image, Shield::Colour c)
839 {
840   if (button->get_filename().empty())
841     {
842       image->clear();
843       return;
844     }
845
846   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
847   Gtk::TreeModel::iterator iterrow = selection->get_selected();
848
849   if (iterrow) 
850     {
851       Gtk::TreeModel::Row row = *iterrow;
852       ArmyProto *a = row[armies_columns.army];
853       std::string file = File::get_basename(button->get_filename());
854       if (button->get_filename() != d_armyset->getFile(file))
855         {
856           //fixme:warn on overrwite.
857           File::copy (button->get_filename(), d_armyset->getFile(file));
858         }
859       a->setImageName(c, file);
860       Gdk::Color colour = Shieldsetlist::getInstance()->getColor(1, c);
861       a->instantiateImages(d_armyset->getTileSize(), c, 
862                            d_armyset->getFile(a->getImageName(c)));
863       if (c != Shield::NEUTRAL)
864         {
865           PixMask *army_image = GraphicsCache::applyMask(a->getImage(c), 
866                                                          a->getMask(c), 
867                                                          colour, false);
868           image->property_pixbuf() = army_image->to_pixbuf();
869           delete army_image;
870         }
871       else
872         image->property_pixbuf() = a->getImage(c)->to_pixbuf();
873
874       needs_saving = true;
875     }
876 }
877 void ArmySetWindow::on_white_image_changed()
878 {
879   on_image_changed(white_image_filechooserbutton, white_image, Shield::WHITE);
880 }
881 void ArmySetWindow::on_green_image_changed()
882 {
883   on_image_changed(green_image_filechooserbutton, green_image, Shield::GREEN);
884 }
885 void ArmySetWindow::on_yellow_image_changed()
886 {
887   on_image_changed(yellow_image_filechooserbutton, yellow_image, 
888                    Shield::YELLOW);
889 }
890 void ArmySetWindow::on_light_blue_image_changed()
891 {
892   on_image_changed(light_blue_image_filechooserbutton, light_blue_image, 
893                    Shield::LIGHT_BLUE);
894 }
895 void ArmySetWindow::on_red_image_changed()
896 {
897   on_image_changed(red_image_filechooserbutton, red_image, Shield::RED);
898 }
899 void ArmySetWindow::on_dark_blue_image_changed()
900 {
901   on_image_changed(dark_blue_image_filechooserbutton, dark_blue_image, 
902                    Shield::DARK_BLUE);
903 }
904 void ArmySetWindow::on_orange_image_changed()
905 {
906   on_image_changed(orange_image_filechooserbutton, orange_image, 
907                    Shield::ORANGE);
908 }
909 void ArmySetWindow::on_black_image_changed()
910 {
911   on_image_changed(black_image_filechooserbutton, black_image, 
912                    Shield::BLACK);
913 }
914 void ArmySetWindow::on_neutral_image_changed()
915 {
916   on_image_changed(neutral_image_filechooserbutton, neutral_image, 
917                    Shield::NEUTRAL);
918 }
919
920 void ArmySetWindow::on_production_text_changed(const Glib::ustring &s, int* p)
921 {
922   production_spinbutton->set_value(atoi(production_spinbutton->get_text().c_str()));
923   on_production_changed();
924 }
925 void ArmySetWindow::on_production_changed()
926 {
927   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
928   Gtk::TreeModel::iterator iterrow = selection->get_selected();
929
930   if (iterrow) 
931     {
932       Gtk::TreeModel::Row row = *iterrow;
933       ArmyProto *a = row[armies_columns.army];
934       if (production_spinbutton->get_value() < 
935           MIN_PRODUCTION_TURNS_FOR_ARMY_UNITS)
936         production_spinbutton->set_value(MIN_PRODUCTION_TURNS_FOR_ARMY_UNITS);
937       else if (production_spinbutton->get_value() > 
938                MAX_PRODUCTION_TURNS_FOR_ARMY_UNITS)
939         production_spinbutton->set_value(MAX_PRODUCTION_TURNS_FOR_ARMY_UNITS);
940       else
941         a->setProduction(int(production_spinbutton->get_value()));
942       needs_saving = true;
943     }
944 }
945
946 void ArmySetWindow::on_cost_text_changed(const Glib::ustring &s, int* p)
947 {
948   cost_spinbutton->set_value(atoi(cost_spinbutton->get_text().c_str()));
949   on_cost_changed();
950 }
951 void ArmySetWindow::on_cost_changed()
952 {
953   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
954   Gtk::TreeModel::iterator iterrow = selection->get_selected();
955
956   if (iterrow) 
957     {
958       Gtk::TreeModel::Row row = *iterrow;
959       ArmyProto *a = row[armies_columns.army];
960       if (cost_spinbutton->get_value() < MIN_COST_FOR_ARMY_UNITS)
961         cost_spinbutton->set_value(MIN_COST_FOR_ARMY_UNITS);
962       else if (strength_spinbutton->get_value() > MAX_COST_FOR_ARMY_UNITS)
963         cost_spinbutton->set_value(MAX_COST_FOR_ARMY_UNITS);
964       else
965         a->setProductionCost(int(cost_spinbutton->get_value()));
966       needs_saving = true;
967     }
968 }
969
970
971 void ArmySetWindow::on_new_cost_text_changed(const Glib::ustring &s, int* p)
972 {
973   new_cost_spinbutton->set_value(atoi(new_cost_spinbutton->get_text().c_str()));
974   on_new_cost_changed();
975 }
976 void ArmySetWindow::on_new_cost_changed()
977 {
978   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
979   Gtk::TreeModel::iterator iterrow = selection->get_selected();
980
981   if (iterrow) 
982     {
983       Gtk::TreeModel::Row row = *iterrow;
984       ArmyProto *a = row[armies_columns.army];
985       a->setNewProductionCost(int(new_cost_spinbutton->get_value()));
986       needs_saving = true;
987     }
988 }
989
990 void ArmySetWindow::on_upkeep_text_changed(const Glib::ustring &s, int* p)
991 {
992   upkeep_spinbutton->set_value(atoi(upkeep_spinbutton->get_text().c_str()));
993   on_upkeep_changed();
994 }
995 void ArmySetWindow::on_upkeep_changed()
996 {
997   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
998   Gtk::TreeModel::iterator iterrow = selection->get_selected();
999
1000   if (iterrow) 
1001     {
1002       Gtk::TreeModel::Row row = *iterrow;
1003       ArmyProto  *a = row[armies_columns.army];
1004       if (upkeep_spinbutton->get_value() < MIN_UPKEEP_FOR_ARMY_UNITS)
1005         upkeep_spinbutton->set_value(MIN_UPKEEP_FOR_ARMY_UNITS);
1006       else if (upkeep_spinbutton->get_value() > MAX_UPKEEP_FOR_ARMY_UNITS)
1007         upkeep_spinbutton->set_value(MAX_UPKEEP_FOR_ARMY_UNITS);
1008       else
1009         a->setUpkeep(int(upkeep_spinbutton->get_value()));
1010       needs_saving = true;
1011     }
1012 }
1013
1014 void ArmySetWindow::on_strength_text_changed(const Glib::ustring &s, int* p)
1015 {
1016   strength_spinbutton->set_value(atoi(strength_spinbutton->get_text().c_str()));
1017   on_strength_changed();
1018 }
1019 void ArmySetWindow::on_strength_changed()
1020 {
1021   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1022   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1023
1024   if (iterrow) 
1025     {
1026       Gtk::TreeModel::Row row = *iterrow;
1027       ArmyProto *a = row[armies_columns.army];
1028       if (strength_spinbutton->get_value() < MIN_STRENGTH_FOR_ARMY_UNITS)
1029         strength_spinbutton->set_value(MIN_STRENGTH_FOR_ARMY_UNITS);
1030       else if (strength_spinbutton->get_value() > MAX_STRENGTH_FOR_ARMY_UNITS)
1031         strength_spinbutton->set_value(MAX_STRENGTH_FOR_ARMY_UNITS);
1032       else
1033         a->setStrength(int(strength_spinbutton->get_value()));
1034       needs_saving = true;
1035     }
1036 }
1037
1038 void ArmySetWindow::on_moves_text_changed(const Glib::ustring &s, int* p)
1039 {
1040   moves_spinbutton->set_value(atoi(moves_spinbutton->get_text().c_str()));
1041   on_moves_changed();
1042 }
1043 void ArmySetWindow::on_moves_changed()
1044 {
1045   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1046   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1047
1048   if (iterrow) 
1049     {
1050       Gtk::TreeModel::Row row = *iterrow;
1051       ArmyProto *a = row[armies_columns.army];
1052       if (moves_spinbutton->get_value() < MIN_MOVES_FOR_ARMY_UNITS)
1053         moves_spinbutton->set_value(MIN_MOVES_FOR_ARMY_UNITS);
1054       else if (moves_spinbutton->get_value() > MAX_MOVES_FOR_ARMY_UNITS)
1055         moves_spinbutton->set_value(MAX_MOVES_FOR_ARMY_UNITS);
1056       else
1057         a->setMaxMoves(int(moves_spinbutton->get_value()));
1058       needs_saving = true;
1059     }
1060 }
1061
1062 void ArmySetWindow::on_exp_text_changed(const Glib::ustring &s, int* p)
1063 {
1064   exp_spinbutton->set_value(atoi(exp_spinbutton->get_text().c_str()));
1065   on_exp_changed();
1066 }
1067 void ArmySetWindow::on_exp_changed()
1068 {
1069   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1070   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1071
1072   if (iterrow) 
1073     {
1074       Gtk::TreeModel::Row row = *iterrow;
1075       ArmyProto *a = row[armies_columns.army];
1076       a->setXpReward(int(exp_spinbutton->get_value()));
1077       needs_saving = true;
1078     }
1079 }
1080
1081 void ArmySetWindow::on_sight_text_changed(const Glib::ustring &s, int* p)
1082 {
1083   sight_spinbutton->set_value(atoi(sight_spinbutton->get_text().c_str()));
1084   on_sight_changed();
1085 }
1086 void ArmySetWindow::on_sight_changed()
1087 {
1088   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1089   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1090
1091   if (iterrow) 
1092     {
1093       Gtk::TreeModel::Row row = *iterrow;
1094       ArmyProto *a = row[armies_columns.army];
1095       a->setSight(int(sight_spinbutton->get_value()));
1096       needs_saving = true;
1097     }
1098 }
1099
1100 void ArmySetWindow::on_gender_none_toggled()
1101 {
1102   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1103   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1104
1105   if (iterrow) 
1106     {
1107       Gtk::TreeModel::Row row = *iterrow;
1108       ArmyProto *a = row[armies_columns.army];
1109       a->setGender(Hero::NONE);
1110       needs_saving = true;
1111     }
1112 }
1113
1114 void ArmySetWindow::on_gender_male_toggled()
1115 {
1116   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1117   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1118
1119   if (iterrow) 
1120     {
1121       Gtk::TreeModel::Row row = *iterrow;
1122       ArmyProto *a = row[armies_columns.army];
1123       a->setGender(Hero::MALE);
1124       needs_saving = true;
1125     }
1126 }
1127
1128 void ArmySetWindow::on_gender_female_toggled()
1129 {
1130   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1131   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1132
1133   if (iterrow) 
1134     {
1135       Gtk::TreeModel::Row row = *iterrow;
1136       ArmyProto *a = row[armies_columns.army];
1137       a->setGender(Hero::FEMALE);
1138       needs_saving = true;
1139     }
1140 }
1141
1142 void ArmySetWindow::on_awardable_toggled()
1143 {
1144   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1145   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1146
1147   if (iterrow) 
1148     {
1149       Gtk::TreeModel::Row row = *iterrow;
1150       ArmyProto *a = row[armies_columns.army];
1151       a->setAwardable(awardable_checkbutton->get_active());
1152       needs_saving = true;
1153     }
1154 }
1155
1156 void ArmySetWindow::on_defends_ruins_toggled()
1157 {
1158   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1159   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1160
1161   if (iterrow) 
1162     {
1163       Gtk::TreeModel::Row row = *iterrow;
1164       ArmyProto *a = row[armies_columns.army];
1165       a->setDefendsRuins(defends_ruins_checkbutton->get_active());
1166       needs_saving = true;
1167     }
1168 }
1169
1170 void ArmySetWindow::on_move_forests_toggled()
1171 {
1172   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1173   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1174
1175   if (iterrow) 
1176     {
1177       Gtk::TreeModel::Row row = *iterrow;
1178       ArmyProto *a = row[armies_columns.army];
1179       guint32 bonus = a->getMoveBonus();
1180       if (move_forests_checkbutton->get_active() == true)
1181         {
1182           //if (can_fly_checkbutton->get_active())
1183           //can_fly_checkbutton->set_active(false);
1184           bonus |= Tile::FOREST;
1185         }
1186       else
1187         {
1188           if (bonus & Tile::FOREST)
1189             bonus ^= Tile::FOREST;
1190         }
1191       a->setMoveBonus(bonus);
1192       needs_saving = true;
1193     }
1194 }
1195
1196 void ArmySetWindow::on_move_marshes_toggled()
1197 {
1198   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1199   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1200
1201   if (iterrow) 
1202     {
1203       Gtk::TreeModel::Row row = *iterrow;
1204       ArmyProto *a = row[armies_columns.army];
1205       guint32 bonus = a->getMoveBonus();
1206       if (move_marshes_checkbutton->get_active() == true)
1207         {
1208           //if (can_fly_checkbutton->get_active())
1209           //can_fly_checkbutton->set_active(false);
1210           bonus |= Tile::SWAMP;
1211         }
1212       else
1213         {
1214           if (bonus & Tile::SWAMP)
1215             bonus ^= Tile::SWAMP;
1216         }
1217       a->setMoveBonus(bonus);
1218       needs_saving = true;
1219     }
1220 }
1221
1222 void ArmySetWindow::on_move_hills_toggled()
1223 {
1224   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1225   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1226
1227   if (iterrow) 
1228     {
1229       Gtk::TreeModel::Row row = *iterrow;
1230       ArmyProto *a = row[armies_columns.army];
1231       guint32 bonus = a->getMoveBonus();
1232       if (move_hills_checkbutton->get_active() == true)
1233         {
1234           //if (can_fly_checkbutton->get_active())
1235           //can_fly_checkbutton->set_active(false);
1236           bonus |= Tile::HILLS;
1237         }
1238       else
1239         {
1240           if (bonus & Tile::HILLS)
1241             bonus ^= Tile::HILLS;
1242         }
1243       a->setMoveBonus(bonus);
1244       needs_saving = true;
1245     }
1246 }
1247
1248 void ArmySetWindow::on_move_mountains_toggled()
1249 {
1250   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1251   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1252
1253   if (iterrow) 
1254     {
1255       Gtk::TreeModel::Row row = *iterrow;
1256       ArmyProto *a = row[armies_columns.army];
1257       guint32 bonus = a->getMoveBonus();
1258       if (move_mountains_checkbutton->get_active() == true)
1259         {
1260           //if (can_fly_checkbutton->get_active())
1261           //can_fly_checkbutton->set_active(false);
1262           bonus |= Tile::MOUNTAIN;
1263         }
1264       else
1265         {
1266           if (bonus & Tile::MOUNTAIN)
1267             bonus ^= Tile::MOUNTAIN;
1268         }
1269       a->setMoveBonus(bonus);
1270       needs_saving = true;
1271     }
1272 }
1273
1274 void ArmySetWindow::on_can_fly_toggled()
1275 {
1276   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1277   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1278
1279   if (iterrow) 
1280     {
1281       Gtk::TreeModel::Row row = *iterrow;
1282       ArmyProto *a = row[armies_columns.army];
1283       guint32 bonus = a->getMoveBonus();
1284       if (can_fly_checkbutton->get_active() == true)
1285         {
1286           bonus = (Tile::GRASS | Tile::WATER | Tile::FOREST | Tile::HILLS |
1287                    Tile::MOUNTAIN | Tile::SWAMP);
1288         }
1289       else
1290         {
1291           bonus = 0;
1292         }
1293       a->setMoveBonus(bonus);
1294       needs_saving = true;
1295     }
1296 }
1297
1298 void ArmySetWindow::on_add1strinopen_toggled()
1299 {
1300   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1301   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1302
1303   if (iterrow) 
1304     {
1305       Gtk::TreeModel::Row row = *iterrow;
1306       ArmyProto *a = row[armies_columns.army];
1307       guint32 bonus = a->getArmyBonus();
1308       if (add1strinopen_checkbutton->get_active() == true)
1309         bonus |= Army::ADD1STRINOPEN;
1310       else
1311         {
1312           if (bonus & Army::ADD1STRINOPEN)
1313             bonus ^= Army::ADD1STRINOPEN;
1314         }
1315       a->setArmyBonus(bonus);
1316       needs_saving = true;
1317     }
1318 }
1319
1320 void ArmySetWindow::on_add2strinopen_toggled()
1321 {
1322   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1323   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1324
1325   if (iterrow) 
1326     {
1327       Gtk::TreeModel::Row row = *iterrow;
1328       ArmyProto *a = row[armies_columns.army];
1329       guint32 bonus = a->getArmyBonus();
1330       if (add2strinopen_checkbutton->get_active() == true)
1331         bonus |= Army::ADD2STRINOPEN ;
1332       else
1333         {
1334           if (bonus & Army::ADD2STRINOPEN)
1335             bonus ^= Army::ADD2STRINOPEN;
1336         }
1337       a->setArmyBonus(bonus);
1338       needs_saving = true;
1339     }
1340 }
1341
1342 void ArmySetWindow::on_add1strinforest_toggled()
1343 {
1344   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1345   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1346
1347   if (iterrow) 
1348     {
1349       Gtk::TreeModel::Row row = *iterrow;
1350       ArmyProto *a = row[armies_columns.army];
1351       guint32 bonus = a->getArmyBonus();
1352       if (add1strinforest_checkbutton->get_active() == true)
1353         bonus |= Army::ADD1STRINFOREST;
1354       else
1355         {
1356           if (bonus & Army::ADD1STRINFOREST)
1357             bonus ^= Army::ADD1STRINFOREST;
1358         }
1359       a->setArmyBonus(bonus);
1360       needs_saving = true;
1361     }
1362 }
1363
1364 void ArmySetWindow::on_add1strinhills_toggled()
1365 {
1366   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1367   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1368
1369   if (iterrow) 
1370     {
1371       Gtk::TreeModel::Row row = *iterrow;
1372       ArmyProto *a = row[armies_columns.army];
1373       guint32 bonus = a->getArmyBonus();
1374       if (add1strinhills_checkbutton->get_active() == true)
1375         bonus |= Army::ADD1STRINHILLS;
1376       else
1377         {
1378           if (bonus & Army::ADD1STRINHILLS)
1379             bonus ^= Army::ADD1STRINHILLS;
1380         }
1381       a->setArmyBonus(bonus);
1382       needs_saving = true;
1383     }
1384 }
1385
1386 void ArmySetWindow::on_add1strincity_toggled()
1387 {
1388   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1389   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1390
1391   if (iterrow) 
1392     {
1393       Gtk::TreeModel::Row row = *iterrow;
1394       ArmyProto *a = row[armies_columns.army];
1395       guint32 bonus = a->getArmyBonus();
1396       if (add1strincity_checkbutton->get_active() == true)
1397         bonus |= Army::ADD1STRINCITY ;
1398       else
1399         {
1400           if (bonus & Army::ADD1STRINCITY)
1401             bonus ^= Army::ADD1STRINCITY;
1402         }
1403       a->setArmyBonus(bonus);
1404       needs_saving = true;
1405     }
1406 }
1407
1408 void ArmySetWindow::on_add2strincity_toggled()
1409 {
1410   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1411   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1412
1413   if (iterrow) 
1414     {
1415       Gtk::TreeModel::Row row = *iterrow;
1416       ArmyProto *a = row[armies_columns.army];
1417       guint32 bonus = a->getArmyBonus();
1418       if (add2strincity_checkbutton->get_active() == true)
1419         bonus |= Army::ADD2STRINCITY ;
1420       else
1421         {
1422           if (bonus & Army::ADD2STRINCITY)
1423             bonus ^= Army::ADD2STRINCITY;
1424         }
1425       a->setArmyBonus(bonus);
1426       needs_saving = true;
1427     }
1428 }
1429
1430 void ArmySetWindow::on_add1stackinhills_toggled()
1431 {
1432   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1433   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1434
1435   if (iterrow) 
1436     {
1437       Gtk::TreeModel::Row row = *iterrow;
1438       ArmyProto *a = row[armies_columns.army];
1439       guint32 bonus = a->getArmyBonus();
1440       if (add1stackinhills_checkbutton->get_active() == true)
1441         bonus |= Army::ADD1STACKINHILLS;
1442       else
1443         {
1444           if (bonus & Army::ADD1STACKINHILLS)
1445             bonus ^= Army::ADD1STACKINHILLS;
1446         }
1447       a->setArmyBonus(bonus);
1448       needs_saving = true;
1449     }
1450 }
1451
1452 void ArmySetWindow::on_suballcitybonus_toggled()
1453 {
1454   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1455   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1456
1457   if (iterrow) 
1458     {
1459       Gtk::TreeModel::Row row = *iterrow;
1460       ArmyProto *a = row[armies_columns.army];
1461       guint32 bonus = a->getArmyBonus();
1462       if (suballcitybonus_checkbutton->get_active() == true)
1463         bonus |= Army::SUBALLCITYBONUS;
1464       else
1465         {
1466           if (bonus & Army::SUBALLCITYBONUS)
1467             bonus ^= Army::SUBALLCITYBONUS;
1468         }
1469       a->setArmyBonus(bonus);
1470       needs_saving = true;
1471     }
1472 }
1473
1474 void ArmySetWindow::on_sub1enemystack_toggled()
1475 {
1476   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1477   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1478
1479   if (iterrow) 
1480     {
1481       Gtk::TreeModel::Row row = *iterrow;
1482       ArmyProto *a = row[armies_columns.army];
1483       guint32 bonus = a->getArmyBonus();
1484       if (sub1enemystack_checkbutton->get_active() == true)
1485         bonus |= Army::SUB1ENEMYSTACK;
1486       else
1487         {
1488           if (bonus & Army::SUB1ENEMYSTACK)
1489             bonus ^= Army::SUB1ENEMYSTACK;
1490         }
1491       a->setArmyBonus(bonus);
1492       needs_saving = true;
1493     }
1494 }
1495
1496 void ArmySetWindow::on_add1stack_toggled()
1497 {
1498   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1499   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1500
1501   if (iterrow) 
1502     {
1503       Gtk::TreeModel::Row row = *iterrow;
1504       ArmyProto *a = row[armies_columns.army];
1505       guint32 bonus = a->getArmyBonus();
1506       if (add1stack_checkbutton->get_active() == true)
1507         bonus |= Army::ADD1STACK;
1508       else
1509         {
1510           if (bonus & Army::ADD1STACK)
1511             bonus ^= Army::ADD1STACK;
1512         }
1513       a->setArmyBonus(bonus);
1514       needs_saving = true;
1515     }
1516 }
1517
1518 void ArmySetWindow::on_add2stack_toggled()
1519 {
1520   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1521   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1522
1523   if (iterrow) 
1524     {
1525       Gtk::TreeModel::Row row = *iterrow;
1526       ArmyProto *a = row[armies_columns.army];
1527       guint32 bonus = a->getArmyBonus();
1528       if (add2stack_checkbutton->get_active() == true)
1529         bonus |= Army::ADD2STACK;
1530       else
1531         {
1532           if (bonus & Army::ADD2STACK)
1533             bonus ^= Army::ADD2STACK;
1534         }
1535       a->setArmyBonus(bonus);
1536       needs_saving = true;
1537     }
1538 }
1539
1540 void ArmySetWindow::on_suballnonherobonus_toggled()
1541 {
1542   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1543   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1544
1545   if (iterrow) 
1546     {
1547       Gtk::TreeModel::Row row = *iterrow;
1548       ArmyProto *a = row[armies_columns.army];
1549       guint32 bonus = a->getArmyBonus();
1550       if (suballnonherobonus_checkbutton->get_active() == true)
1551         bonus |= Army::SUBALLNONHEROBONUS;
1552       else
1553         {
1554           if (bonus & Army::SUBALLNONHEROBONUS)
1555             bonus ^= Army::SUBALLNONHEROBONUS;
1556         }
1557       a->setArmyBonus(bonus);
1558       needs_saving = true;
1559     }
1560 }
1561
1562 void ArmySetWindow::on_suballherobonus_toggled()
1563 {
1564   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1565   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1566
1567   if (iterrow) 
1568     {
1569       Gtk::TreeModel::Row row = *iterrow;
1570       ArmyProto *a = row[armies_columns.army];
1571       guint32 bonus = a->getArmyBonus();
1572       if (suballherobonus_checkbutton->get_active() == true)
1573         bonus |= Army::SUBALLHEROBONUS;
1574       else
1575         {
1576           if (bonus & Army::SUBALLHEROBONUS)
1577             bonus ^= Army::SUBALLHEROBONUS;
1578         }
1579       a->setArmyBonus(bonus);
1580       needs_saving = true;
1581     }
1582 }
1583
1584 void ArmySetWindow::on_add_army_clicked()
1585 {
1586   //add a new empty army to the armyset
1587   ArmyProto *a = new ArmyProto();
1588   //add it to the treeview
1589   Gtk::TreeIter i = armies_list->append();
1590   a->setName("Untitled");
1591   (*i)[armies_columns.name] = a->getName();
1592   (*i)[armies_columns.army] = a;
1593   d_armyset->push_back(a);
1594   needs_saving = true;
1595
1596 }
1597
1598 void ArmySetWindow::on_remove_army_clicked()
1599 {
1600   //erase the selected row from the treeview
1601   //remove the army from the armyset
1602   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1603   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1604
1605   if (iterrow) 
1606     {
1607       Gtk::TreeModel::Row row = *iterrow;
1608       ArmyProto *a = row[armies_columns.army];
1609       armies_list->erase(iterrow);
1610       d_armyset->remove(a);
1611       needs_saving = true;
1612     }
1613 }
1614
1615 void ArmySetWindow::load_armyset(std::string filename)
1616 {
1617   current_save_filename = filename;
1618
1619   std::string name = File::get_basename(filename);
1620
1621   Armyset *armyset = Armyset::create(filename);
1622   if (armyset == NULL)
1623     {
1624       std::string msg;
1625       msg = "Error!  Armyset could not be loaded.";
1626       Gtk::MessageDialog dialog(*window, msg);
1627       dialog.run();
1628       dialog.hide();
1629       return;
1630     }
1631   armies_list->clear();
1632   if (d_armyset)
1633     delete d_armyset;
1634   d_armyset = armyset;
1635
1636   d_armyset->setSubDir(name);
1637   d_armyset->instantiateImages();
1638   guint32 max = d_armyset->getSize();
1639   for (unsigned int i = 0; i < max; i++)
1640     addArmyType(i);
1641   if (max)
1642     {
1643       Gtk::TreeModel::Row row;
1644       row = armies_treeview->get_model()->children()[0];
1645       if(row)
1646         armies_treeview->get_selection()->select(row);
1647     }
1648
1649   Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1650   Gtk::TreeModel::iterator iterrow = selection->get_selected();
1651   if (iterrow) 
1652     {
1653       Gtk::TreeModel::Row row = *iterrow;
1654       ArmyProto *a = row[armies_columns.army];
1655       update_filechooserbutton(white_image_filechooserbutton, a,
1656                                Shield::WHITE);
1657       update_filechooserbutton(yellow_image_filechooserbutton, a, 
1658                                Shield::YELLOW);
1659       update_filechooserbutton(green_image_filechooserbutton, a, 
1660                                Shield::GREEN);
1661       update_filechooserbutton(light_blue_image_filechooserbutton, a, 
1662                                Shield::LIGHT_BLUE);
1663       update_filechooserbutton(red_image_filechooserbutton, a, Shield::RED);
1664       update_filechooserbutton(dark_blue_image_filechooserbutton, a, 
1665                                Shield::DARK_BLUE);
1666       update_filechooserbutton(orange_image_filechooserbutton, a, 
1667                                Shield::ORANGE);
1668       update_filechooserbutton(black_image_filechooserbutton, a, 
1669                                Shield::BLACK);
1670       update_filechooserbutton(neutral_image_filechooserbutton, a, 
1671                                Shield::NEUTRAL);
1672     }
1673   std::string imgpath = d_armyset->getDirectory();
1674   white_image_filechooserbutton->set_current_folder(imgpath);
1675   green_image_filechooserbutton->set_current_folder(imgpath);
1676   yellow_image_filechooserbutton->set_current_folder(imgpath);
1677   light_blue_image_filechooserbutton->set_current_folder(imgpath);
1678   red_image_filechooserbutton->set_current_folder(imgpath);
1679   dark_blue_image_filechooserbutton->set_current_folder(imgpath);
1680   orange_image_filechooserbutton->set_current_folder(imgpath);
1681   black_image_filechooserbutton->set_current_folder(imgpath);
1682   neutral_image_filechooserbutton->set_current_folder(imgpath);
1683 }
1684 bool ArmySetWindow::quit()
1685 {
1686   if (needs_saving == true)
1687     {
1688       Gtk::Dialog* dialog;
1689       Glib::RefPtr<Gtk::Builder> xml
1690         = Gtk::Builder::create_from_file(get_glade_path() + 
1691                                          "/editor-quit-dialog.ui");
1692       xml->get_widget("dialog", dialog);
1693       dialog->set_transient_for(*window);
1694       int response = dialog->run();
1695       dialog->hide();
1696       delete dialog;
1697       
1698       if (response == Gtk::RESPONSE_CANCEL) //we don't want to quit
1699         return false;
1700
1701       else if (response == Gtk::RESPONSE_ACCEPT) // save and quit
1702         on_save_armyset_activated();
1703       //else if (Response == Gtk::CLOSE) // don't save just quit
1704       window->hide();
1705     }
1706   else
1707     window->hide();
1708   return true;
1709 }
1710 bool ArmySetWindow::on_window_closed(GdkEventAny*)
1711 {
1712   return !quit();
1713 }
1714 void ArmySetWindow::on_quit_activated()
1715 {
1716   quit();
1717 }