initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / surrender-dialog.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 <gtkmm.h>
21 #include <sigc++/functors/mem_fun.h>
22
23 #include "surrender-dialog.h"
24
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
29 #include "defs.h"
30 #include "File.h"
31
32 SurrenderDialog::SurrenderDialog(int numEnemies)
33 {
34     Glib::RefPtr<Gtk::Builder> xml
35         = Gtk::Builder::create_from_file(get_glade_path()
36                                     + "/surrender-dialog.ui");
37
38     xml->get_widget("dialog", dialog);
39     decorate(dialog);
40     window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
41
42     Gtk::Label *label;
43     xml->get_widget("label", label);
44     xml->get_widget("image", image);
45     
46     Glib::ustring s;
47     s = ngettext("Your enemy grudgingly surrenders!\n",
48                  "Your enemies respectfully surrender!\n",
49                  numEnemies);
50     s += _("Do you accept?");
51     label->set_text(s);
52     image->property_file()
53       = File::getMiscFile("various/parley_offered.png");
54 }
55
56 SurrenderDialog::~SurrenderDialog()
57 {
58   delete dialog;
59 }
60
61 void SurrenderDialog::set_parent_window(Gtk::Window &parent)
62 {
63   dialog->set_transient_for(parent);
64   //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
65 }
66
67 void SurrenderDialog::hide()
68 {
69   dialog->hide();
70 }
71 bool SurrenderDialog::run()
72 {
73   return dialog->run() == Gtk::RESPONSE_ACCEPT;
74 }