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
20 #include <sigc++/functors/mem_fun.h>
22 #include "fight-order-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "ucompose.hpp"
29 #include "playerlist.h"
32 #include "armysetlist.h"
33 #include "GraphicsCache.h"
35 FightOrderDialog::FightOrderDialog(Player *theplayer)
39 Glib::RefPtr<Gtk::Builder> xml
40 = Gtk::Builder::create_from_file(get_glade_path()
41 + "/fight-order-dialog.ui");
43 xml->get_widget("dialog", dialog);
45 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
47 armies_list = Gtk::ListStore::create(armies_columns);
48 xml->get_widget("treeview", armies_treeview);
49 armies_treeview->set_model(armies_list);
50 armies_treeview->append_column("", armies_columns.image);
51 armies_treeview->append_column("", armies_columns.name);
53 std::list<guint32> fight_order = theplayer->getFightOrder();
54 std::list<guint32>::iterator it = fight_order.begin();
55 for (; it != fight_order.end(); it++)
59 armies_treeview->set_reorderable(true);
60 xml->get_widget("reverse_button", reverse_button);
61 reverse_button->signal_clicked().connect
62 (sigc::mem_fun (*this, &FightOrderDialog::on_reverse_button_clicked));
64 FightOrderDialog::~FightOrderDialog()
69 void FightOrderDialog::set_parent_window(Gtk::Window &parent)
71 dialog->set_transient_for(parent);
72 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
75 void FightOrderDialog::hide()
80 void FightOrderDialog::run()
82 static int width = -1;
83 static int height = -1;
85 if (width != -1 && height != -1)
86 dialog->set_default_size(width, height);
89 int response = dialog->run();
91 dialog->get_size(width, height);
93 if (response == Gtk::RESPONSE_ACCEPT)
95 std::list<guint32> fight_order;
96 for (Gtk::TreeIter i = armies_list->children().begin(),
97 end = armies_list->children().end(); i != end; ++i)
98 fight_order.push_back((*i)[armies_columns.army_type]);
99 player->setFightOrder(fight_order);
104 void FightOrderDialog::addArmyType(guint32 army_type)
106 GraphicsCache *gc = GraphicsCache::getInstance();
107 Gtk::TreeIter i = armies_list->append();
108 Armysetlist *alist = Armysetlist::getInstance();
109 const ArmyProto *a = alist->getArmy(player->getArmyset(), army_type);
110 (*i)[armies_columns.name] = a->getName();
111 (*i)[armies_columns.image] = gc->getArmyPic(player->getArmyset(),
112 army_type, player, NULL)->to_pixbuf();
113 (*i)[armies_columns.army_type] = a->getTypeId();
116 void FightOrderDialog::on_reverse_button_clicked()
118 std::list<int> new_order;
119 Gtk::TreeModel::Children kids = armies_list->children();
120 for (unsigned int i = 0; i < kids.size(); i++)
121 new_order.push_back(kids.size() - i - 1);
122 armies_list->reorder(new_order);