initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / quest-assigned-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 "quest-assigned-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 "GameMap.h"
31
32 QuestAssignedDialog::QuestAssignedDialog(Hero *h, Quest *q)
33 {
34   hero = h;
35   quest = q;
36     
37   Glib::RefPtr<Gtk::Builder> xml
38       = Gtk::Builder::create_from_file(get_glade_path()
39                                   + "/quest-assigned-dialog.ui");
40
41     xml->get_widget("dialog", dialog);
42     decorate(dialog);
43     window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
44
45     xml->get_widget("map_image", map_image);
46
47     questmap = new QuestMap(quest);
48     questmap->map_changed.connect(
49         sigc::mem_fun(this, &QuestAssignedDialog::on_map_changed));
50
51     Gtk::EventBox *map_eventbox;
52     xml->get_widget("map_eventbox", map_eventbox);
53
54     set_title(String::ucompose(_("Quest for %1"), hero->getName()));
55
56     xml->get_widget("label", label);
57     Glib::ustring s;
58     if (quest)
59         s = quest->getDescription();
60     else
61         s = _("This hero already has a quest.");
62     label->set_text(s);
63     
64 }
65
66 QuestAssignedDialog::~QuestAssignedDialog()
67 {
68   delete dialog;
69   delete questmap;
70 }
71 void QuestAssignedDialog::set_parent_window(Gtk::Window &parent)
72 {
73     dialog->set_transient_for(parent);
74     //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
75 }
76
77 void QuestAssignedDialog::hide()
78 {
79   dialog->hide();
80 }
81
82 void QuestAssignedDialog::run()
83 {
84     questmap->resize();
85     questmap->draw(Playerlist::getActiveplayer());
86
87     dialog->show_all();
88     dialog->run();
89 }
90
91 void QuestAssignedDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
92 {
93     map_image->property_pixmap() = map;
94 }
95