1 // Copyright (C) 2007, 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
26 #include <sigc++/functors/mem_fun.h>
27 #include <sigc++/functors/ptr_fun.h>
30 #include "armyset-window.h"
31 #include "armyset-info-dialog.h"
32 #include "masked-image-editor-dialog.h"
34 #include "image-helpers.h"
35 #include "input-helpers.h"
36 #include "error-utils.h"
39 #include "Configuration.h"
40 #include "GraphicsCache.h"
41 #include "armysetlist.h"
45 #include "shieldsetlist.h"
47 #include "ucompose.hpp"
49 #include "glade-helpers.h"
50 #include "image-editor-dialog.h"
53 ArmySetWindow::ArmySetWindow(std::string load_filename)
57 Glib::RefPtr<Gtk::Builder> xml
58 = Gtk::Builder::create_from_file(get_glade_path() + "/armyset-window.ui");
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));
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));
284 window->signal_delete_event().connect(
285 sigc::mem_fun(*this, &ArmySetWindow::on_delete_event));
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);
296 update_armyset_buttons();
298 update_armyset_buttons();
299 update_armyset_menuitems();
301 if (load_filename.empty() == false)
303 load_armyset (load_filename);
304 update_armyset_buttons();
305 update_armyset_menuitems();
311 ArmySetWindow::update_armyset_menuitems()
313 if (d_armyset == NULL)
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);
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);
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);
338 ArmySetWindow::update_armyset_buttons()
340 if (!armies_treeview->get_selection()->get_selected())
341 remove_army_button->set_sensitive(false);
343 remove_army_button->set_sensitive(true);
344 if (d_armyset == NULL)
345 add_army_button->set_sensitive(false);
347 add_army_button->set_sensitive(true);
351 ArmySetWindow::update_army_panel()
353 //if nothing selected in the treeview, then we don't show anything in
355 if (armies_treeview->get_selection()->get_selected() == 0)
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();
396 dark_blue_image->clear();
397 orange_image->clear();
398 black_image->clear();
399 neutral_image->clear();
400 army_vbox->set_sensitive(false);
403 army_vbox->set_sensitive(true);
404 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
405 Gtk::TreeModel::iterator iterrow = selection->get_selected();
410 Gtk::TreeModel::Row row = *iterrow;
412 ArmyProto *a = row[armies_columns.army];
416 ArmySetWindow::~ArmySetWindow()
421 void ArmySetWindow::show()
426 void ArmySetWindow::hide()
431 bool ArmySetWindow::on_delete_event(GdkEventAny *e)
438 void ArmySetWindow::on_new_armyset_activated()
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)
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();
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);
472 update_armyset_buttons();
473 update_armyset_menuitems();
475 XML_Helper helper(current_save_filename, std::ios::out, false);
476 d_armyset->save(&helper);
481 void ArmySetWindow::update_filechooserbutton(Gtk::FileChooserButton *b, ArmyProto *a, Shield::Colour c)
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);
489 b->set_sensitive(true);
491 void ArmySetWindow::on_load_armyset_activated()
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());
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);
505 int res = chooser.run();
507 if (res == Gtk::RESPONSE_ACCEPT)
509 load_armyset(chooser.get_filename());
513 update_armyset_buttons();
514 update_armyset_menuitems();
518 void ArmySetWindow::on_validate_armyset_activated()
520 std::list<std::string> msgs;
521 if (d_armyset == NULL)
524 valid = d_armyset->validateSize();
526 msgs.push_back(_("There must be at least one army unit in the armyset."));
527 valid = d_armyset->validateHero();
529 msgs.push_back(_("There must be at least one hero in the armyset."));
530 valid = d_armyset->validatePurchasables();
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();
535 msgs.push_back(_("There must be at least one army unit than can defend a ruin."));
536 valid = d_armyset->validateAwardables();
538 msgs.push_back(_("There must be at least one army unit than can be awarded to a hero."));
539 valid = d_armyset->validateShip();
541 msgs.push_back(_("The ship image must be set."));
542 valid = d_armyset->validateStandard();
544 msgs.push_back(_("The hero's standard (the flag) image must be set."));
545 valid = d_armyset->validateBag();
547 msgs.push_back(_("The picture for the bag of items must be set."));
549 for (Armyset::iterator it = d_armyset->begin(); it != d_armyset->end(); it++)
552 bool valid = d_armyset->validateArmyUnitImage(*it, c);
555 msgs.push_back(String::ucompose(_("%1 does not have an image set for the %2 player"), (*it)->getName(), Shield::colourToString(c)));
560 valid = d_armyset->validateArmyUnitNames();
562 msgs.push_back(_("An army unit does not have a name."));
564 std::string msg = "";
565 for (std::list<std::string>::iterator it = msgs.begin(); it != msgs.end();
571 Gtk::MessageDialog dialog(*window, msg);
578 void ArmySetWindow::on_save_armyset_activated()
580 if (current_save_filename.empty())
581 current_save_filename = d_armyset->getConfigurationFile();
583 //Reorder the armyset according to the treeview
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]);
589 XML_Helper helper(current_save_filename, std::ios::out, false);
590 d_armyset->save(&helper);
592 needs_saving = false;
595 void ArmySetWindow::on_edit_ship_picture_activated()
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"));
603 if (d.get_selected_filename() != "")
605 std::string file = File::get_basename(d.get_selected_filename());
606 if (d.get_selected_filename() != d_armyset->getFile(file))
608 //fixme:warn on overrwite.
609 File::copy (d.get_selected_filename(),
610 d_armyset->getFile(file));
612 d_armyset->setShipImageName(file);
616 void ArmySetWindow::on_edit_standard_picture_activated()
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"));
624 if (d.get_selected_filename() != "")
626 std::string file = File::get_basename(d.get_selected_filename());
627 if (d.get_selected_filename() != d_armyset->getFile(file))
629 //fixme:warn on overrwite.
630 File::copy (d.get_selected_filename(),
631 d_armyset->getFile(file));
633 d_armyset->setStandardImageName(file);
637 void ArmySetWindow::on_edit_bag_picture_activated()
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)
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);
655 void ArmySetWindow::on_edit_armyset_info_activated()
657 ArmySetInfoDialog d(d_armyset, true);
658 d.set_parent_window(*window);
659 int response = d.run();
660 if (response == Gtk::RESPONSE_ACCEPT)
664 void ArmySetWindow::on_help_about_activated()
666 Gtk::AboutDialog* dialog;
668 Glib::RefPtr<Gtk::Builder> xml
669 = Gtk::Builder::create_from_file(get_glade_path() + "/../about-dialog.ui");
671 xml->get_widget("dialog", dialog);
672 dialog->set_transient_for(*window);
673 dialog->set_icon_from_file(File::getMiscFile("various/castle_icon.png"));
675 dialog->set_version(PACKAGE_VERSION);
676 dialog->set_logo(GraphicsCache::getMiscPicture("castle_icon.png")->to_pixbuf());
684 void ArmySetWindow::addArmyType(guint32 army_type)
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;
694 void ArmySetWindow::on_army_selected()
697 update_armyset_buttons();
700 void ArmySetWindow::fill_army_image(Gtk::FileChooserButton *button, Gtk::Image *image, Shield::Colour c, ArmyProto *army)
702 if (army->getImageName(c) != "")
704 image->property_pixbuf() = army->getImage(c)->to_pixbuf();
706 std::string path = d_armyset->getFile(army->getImageName(c));
707 button->set_filename(path);
711 std::string imgpath = d_armyset->getDirectory();
712 button->set_filename("");
713 button->set_current_folder(imgpath);
718 void ArmySetWindow::fill_army_info(ArmyProto *army)
720 fill_army_image(white_image_filechooserbutton, white_image, Shield::WHITE,
722 fill_army_image(green_image_filechooserbutton, green_image, Shield::GREEN,
724 fill_army_image(yellow_image_filechooserbutton, yellow_image, Shield::YELLOW,
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,
733 fill_army_image(black_image_filechooserbutton, black_image, Shield::BLACK,
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())
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;
753 awardable_checkbutton->set_active(army->getAwardable());
754 defends_ruins_checkbutton->set_active(army->getDefendsRuins());
755 sight_spinbutton->set_value(army->getSight());
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)
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);
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);
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);
809 void ArmySetWindow::on_name_changed()
811 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
812 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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();
824 void ArmySetWindow::on_description_changed()
826 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
827 Gtk::TreeModel::iterator iterrow = selection->get_selected();
831 Gtk::TreeModel::Row row = *iterrow;
832 ArmyProto *a = row[armies_columns.army];
833 a->setDescription(description_textview->get_buffer()->get_text());
838 void ArmySetWindow::on_image_changed(Gtk::FileChooserButton *button, Gtk::Image *image, Shield::Colour c)
840 if (button->get_filename().empty())
846 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
847 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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))
856 //fixme:warn on overrwite.
857 File::copy (button->get_filename(), d_armyset->getFile(file));
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)
865 PixMask *army_image = GraphicsCache::applyMask(a->getImage(c),
868 image->property_pixbuf() = army_image->to_pixbuf();
872 image->property_pixbuf() = a->getImage(c)->to_pixbuf();
877 void ArmySetWindow::on_white_image_changed()
879 on_image_changed(white_image_filechooserbutton, white_image, Shield::WHITE);
881 void ArmySetWindow::on_green_image_changed()
883 on_image_changed(green_image_filechooserbutton, green_image, Shield::GREEN);
885 void ArmySetWindow::on_yellow_image_changed()
887 on_image_changed(yellow_image_filechooserbutton, yellow_image,
890 void ArmySetWindow::on_light_blue_image_changed()
892 on_image_changed(light_blue_image_filechooserbutton, light_blue_image,
895 void ArmySetWindow::on_red_image_changed()
897 on_image_changed(red_image_filechooserbutton, red_image, Shield::RED);
899 void ArmySetWindow::on_dark_blue_image_changed()
901 on_image_changed(dark_blue_image_filechooserbutton, dark_blue_image,
904 void ArmySetWindow::on_orange_image_changed()
906 on_image_changed(orange_image_filechooserbutton, orange_image,
909 void ArmySetWindow::on_black_image_changed()
911 on_image_changed(black_image_filechooserbutton, black_image,
914 void ArmySetWindow::on_neutral_image_changed()
916 on_image_changed(neutral_image_filechooserbutton, neutral_image,
920 void ArmySetWindow::on_production_text_changed(const Glib::ustring &s, int* p)
922 production_spinbutton->set_value(atoi(production_spinbutton->get_text().c_str()));
923 on_production_changed();
925 void ArmySetWindow::on_production_changed()
927 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
928 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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);
941 a->setProduction(int(production_spinbutton->get_value()));
946 void ArmySetWindow::on_cost_text_changed(const Glib::ustring &s, int* p)
948 cost_spinbutton->set_value(atoi(cost_spinbutton->get_text().c_str()));
951 void ArmySetWindow::on_cost_changed()
953 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
954 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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);
965 a->setProductionCost(int(cost_spinbutton->get_value()));
971 void ArmySetWindow::on_new_cost_text_changed(const Glib::ustring &s, int* p)
973 new_cost_spinbutton->set_value(atoi(new_cost_spinbutton->get_text().c_str()));
974 on_new_cost_changed();
976 void ArmySetWindow::on_new_cost_changed()
978 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
979 Gtk::TreeModel::iterator iterrow = selection->get_selected();
983 Gtk::TreeModel::Row row = *iterrow;
984 ArmyProto *a = row[armies_columns.army];
985 a->setNewProductionCost(int(new_cost_spinbutton->get_value()));
990 void ArmySetWindow::on_upkeep_text_changed(const Glib::ustring &s, int* p)
992 upkeep_spinbutton->set_value(atoi(upkeep_spinbutton->get_text().c_str()));
995 void ArmySetWindow::on_upkeep_changed()
997 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
998 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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);
1009 a->setUpkeep(int(upkeep_spinbutton->get_value()));
1010 needs_saving = true;
1014 void ArmySetWindow::on_strength_text_changed(const Glib::ustring &s, int* p)
1016 strength_spinbutton->set_value(atoi(strength_spinbutton->get_text().c_str()));
1017 on_strength_changed();
1019 void ArmySetWindow::on_strength_changed()
1021 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1022 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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);
1033 a->setStrength(int(strength_spinbutton->get_value()));
1034 needs_saving = true;
1038 void ArmySetWindow::on_moves_text_changed(const Glib::ustring &s, int* p)
1040 moves_spinbutton->set_value(atoi(moves_spinbutton->get_text().c_str()));
1043 void ArmySetWindow::on_moves_changed()
1045 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1046 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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);
1057 a->setMaxMoves(int(moves_spinbutton->get_value()));
1058 needs_saving = true;
1062 void ArmySetWindow::on_exp_text_changed(const Glib::ustring &s, int* p)
1064 exp_spinbutton->set_value(atoi(exp_spinbutton->get_text().c_str()));
1067 void ArmySetWindow::on_exp_changed()
1069 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1070 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1081 void ArmySetWindow::on_sight_text_changed(const Glib::ustring &s, int* p)
1083 sight_spinbutton->set_value(atoi(sight_spinbutton->get_text().c_str()));
1086 void ArmySetWindow::on_sight_changed()
1088 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1089 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1100 void ArmySetWindow::on_gender_none_toggled()
1102 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1103 Gtk::TreeModel::iterator iterrow = selection->get_selected();
1107 Gtk::TreeModel::Row row = *iterrow;
1108 ArmyProto *a = row[armies_columns.army];
1109 a->setGender(Hero::NONE);
1110 needs_saving = true;
1114 void ArmySetWindow::on_gender_male_toggled()
1116 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1117 Gtk::TreeModel::iterator iterrow = selection->get_selected();
1121 Gtk::TreeModel::Row row = *iterrow;
1122 ArmyProto *a = row[armies_columns.army];
1123 a->setGender(Hero::MALE);
1124 needs_saving = true;
1128 void ArmySetWindow::on_gender_female_toggled()
1130 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1131 Gtk::TreeModel::iterator iterrow = selection->get_selected();
1135 Gtk::TreeModel::Row row = *iterrow;
1136 ArmyProto *a = row[armies_columns.army];
1137 a->setGender(Hero::FEMALE);
1138 needs_saving = true;
1142 void ArmySetWindow::on_awardable_toggled()
1144 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1145 Gtk::TreeModel::iterator iterrow = selection->get_selected();
1149 Gtk::TreeModel::Row row = *iterrow;
1150 ArmyProto *a = row[armies_columns.army];
1151 a->setAwardable(awardable_checkbutton->get_active());
1152 needs_saving = true;
1156 void ArmySetWindow::on_defends_ruins_toggled()
1158 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1159 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1170 void ArmySetWindow::on_move_forests_toggled()
1172 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1173 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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)
1182 //if (can_fly_checkbutton->get_active())
1183 //can_fly_checkbutton->set_active(false);
1184 bonus |= Tile::FOREST;
1188 if (bonus & Tile::FOREST)
1189 bonus ^= Tile::FOREST;
1191 a->setMoveBonus(bonus);
1192 needs_saving = true;
1196 void ArmySetWindow::on_move_marshes_toggled()
1198 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1199 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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)
1208 //if (can_fly_checkbutton->get_active())
1209 //can_fly_checkbutton->set_active(false);
1210 bonus |= Tile::SWAMP;
1214 if (bonus & Tile::SWAMP)
1215 bonus ^= Tile::SWAMP;
1217 a->setMoveBonus(bonus);
1218 needs_saving = true;
1222 void ArmySetWindow::on_move_hills_toggled()
1224 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1225 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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)
1234 //if (can_fly_checkbutton->get_active())
1235 //can_fly_checkbutton->set_active(false);
1236 bonus |= Tile::HILLS;
1240 if (bonus & Tile::HILLS)
1241 bonus ^= Tile::HILLS;
1243 a->setMoveBonus(bonus);
1244 needs_saving = true;
1248 void ArmySetWindow::on_move_mountains_toggled()
1250 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1251 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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)
1260 //if (can_fly_checkbutton->get_active())
1261 //can_fly_checkbutton->set_active(false);
1262 bonus |= Tile::MOUNTAIN;
1266 if (bonus & Tile::MOUNTAIN)
1267 bonus ^= Tile::MOUNTAIN;
1269 a->setMoveBonus(bonus);
1270 needs_saving = true;
1274 void ArmySetWindow::on_can_fly_toggled()
1276 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1277 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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)
1286 bonus = (Tile::GRASS | Tile::WATER | Tile::FOREST | Tile::HILLS |
1287 Tile::MOUNTAIN | Tile::SWAMP);
1293 a->setMoveBonus(bonus);
1294 needs_saving = true;
1298 void ArmySetWindow::on_add1strinopen_toggled()
1300 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1301 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1312 if (bonus & Army::ADD1STRINOPEN)
1313 bonus ^= Army::ADD1STRINOPEN;
1315 a->setArmyBonus(bonus);
1316 needs_saving = true;
1320 void ArmySetWindow::on_add2strinopen_toggled()
1322 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1323 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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 ;
1334 if (bonus & Army::ADD2STRINOPEN)
1335 bonus ^= Army::ADD2STRINOPEN;
1337 a->setArmyBonus(bonus);
1338 needs_saving = true;
1342 void ArmySetWindow::on_add1strinforest_toggled()
1344 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1345 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1356 if (bonus & Army::ADD1STRINFOREST)
1357 bonus ^= Army::ADD1STRINFOREST;
1359 a->setArmyBonus(bonus);
1360 needs_saving = true;
1364 void ArmySetWindow::on_add1strinhills_toggled()
1366 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1367 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1378 if (bonus & Army::ADD1STRINHILLS)
1379 bonus ^= Army::ADD1STRINHILLS;
1381 a->setArmyBonus(bonus);
1382 needs_saving = true;
1386 void ArmySetWindow::on_add1strincity_toggled()
1388 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1389 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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 ;
1400 if (bonus & Army::ADD1STRINCITY)
1401 bonus ^= Army::ADD1STRINCITY;
1403 a->setArmyBonus(bonus);
1404 needs_saving = true;
1408 void ArmySetWindow::on_add2strincity_toggled()
1410 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1411 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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 ;
1422 if (bonus & Army::ADD2STRINCITY)
1423 bonus ^= Army::ADD2STRINCITY;
1425 a->setArmyBonus(bonus);
1426 needs_saving = true;
1430 void ArmySetWindow::on_add1stackinhills_toggled()
1432 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1433 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1444 if (bonus & Army::ADD1STACKINHILLS)
1445 bonus ^= Army::ADD1STACKINHILLS;
1447 a->setArmyBonus(bonus);
1448 needs_saving = true;
1452 void ArmySetWindow::on_suballcitybonus_toggled()
1454 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1455 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1466 if (bonus & Army::SUBALLCITYBONUS)
1467 bonus ^= Army::SUBALLCITYBONUS;
1469 a->setArmyBonus(bonus);
1470 needs_saving = true;
1474 void ArmySetWindow::on_sub1enemystack_toggled()
1476 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1477 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1488 if (bonus & Army::SUB1ENEMYSTACK)
1489 bonus ^= Army::SUB1ENEMYSTACK;
1491 a->setArmyBonus(bonus);
1492 needs_saving = true;
1496 void ArmySetWindow::on_add1stack_toggled()
1498 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1499 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1510 if (bonus & Army::ADD1STACK)
1511 bonus ^= Army::ADD1STACK;
1513 a->setArmyBonus(bonus);
1514 needs_saving = true;
1518 void ArmySetWindow::on_add2stack_toggled()
1520 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1521 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1532 if (bonus & Army::ADD2STACK)
1533 bonus ^= Army::ADD2STACK;
1535 a->setArmyBonus(bonus);
1536 needs_saving = true;
1540 void ArmySetWindow::on_suballnonherobonus_toggled()
1542 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1543 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1554 if (bonus & Army::SUBALLNONHEROBONUS)
1555 bonus ^= Army::SUBALLNONHEROBONUS;
1557 a->setArmyBonus(bonus);
1558 needs_saving = true;
1562 void ArmySetWindow::on_suballherobonus_toggled()
1564 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1565 Gtk::TreeModel::iterator iterrow = selection->get_selected();
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;
1576 if (bonus & Army::SUBALLHEROBONUS)
1577 bonus ^= Army::SUBALLHEROBONUS;
1579 a->setArmyBonus(bonus);
1580 needs_saving = true;
1584 void ArmySetWindow::on_add_army_clicked()
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;
1598 void ArmySetWindow::on_remove_army_clicked()
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();
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;
1615 void ArmySetWindow::load_armyset(std::string filename)
1617 current_save_filename = filename;
1619 std::string name = File::get_basename(filename);
1621 Armyset *armyset = Armyset::create(filename);
1622 if (armyset == NULL)
1625 msg = "Error! Armyset could not be loaded.";
1626 Gtk::MessageDialog dialog(*window, msg);
1631 armies_list->clear();
1634 d_armyset = armyset;
1636 d_armyset->setSubDir(name);
1637 d_armyset->instantiateImages();
1638 guint32 max = d_armyset->getSize();
1639 for (unsigned int i = 0; i < max; i++)
1643 Gtk::TreeModel::Row row;
1644 row = armies_treeview->get_model()->children()[0];
1646 armies_treeview->get_selection()->select(row);
1649 Glib::RefPtr<Gtk::TreeSelection> selection = armies_treeview->get_selection();
1650 Gtk::TreeModel::iterator iterrow = selection->get_selected();
1653 Gtk::TreeModel::Row row = *iterrow;
1654 ArmyProto *a = row[armies_columns.army];
1655 update_filechooserbutton(white_image_filechooserbutton, a,
1657 update_filechooserbutton(yellow_image_filechooserbutton, a,
1659 update_filechooserbutton(green_image_filechooserbutton, a,
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,
1666 update_filechooserbutton(orange_image_filechooserbutton, a,
1668 update_filechooserbutton(black_image_filechooserbutton, a,
1670 update_filechooserbutton(neutral_image_filechooserbutton, a,
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);
1684 bool ArmySetWindow::quit()
1686 if (needs_saving == true)
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();
1698 if (response == Gtk::RESPONSE_CANCEL) //we don't want to quit
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
1710 bool ArmySetWindow::on_window_closed(GdkEventAny*)
1714 void ArmySetWindow::on_quit_activated()