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
21 #include <sigc++/functors/mem_fun.h>
23 #include "quest-report-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
33 QuestReportDialog::QuestReportDialog(std::vector<Quest *>q, Hero *hero)
37 Glib::RefPtr<Gtk::Builder> xml
38 = Gtk::Builder::create_from_file(get_glade_path()
39 + "/quest-report-dialog.ui");
41 xml->get_widget("dialog", dialog);
43 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
45 xml->get_widget("map_image", map_image);
49 Gtk::EventBox *map_eventbox;
50 xml->get_widget("map_eventbox", map_eventbox);
52 xml->get_widget("label", label);
53 xml->get_widget("hero_label", hero_label);
56 heroes_list = Gtk::ListStore::create(heroes_columns);
57 xml->get_widget("heroes_treeview", heroes_treeview);
58 heroes_treeview->set_model(heroes_list);
59 heroes_treeview->append_column(_("Hero"), heroes_columns.hero_name);
60 heroes_treeview->set_headers_visible(false);
64 heroes_treeview->get_selection()->signal_changed()
65 .connect(sigc::mem_fun(this, &QuestReportDialog::on_hero_changed));
66 for (std::vector<Quest*>::iterator it = quests.begin(); it != quests.end();
69 add_questing_hero (*it, (*it)->getHero());
70 if ((*it)->getHero() == hero || count == 0)
72 Gtk::TreeModel::Row row;
73 row = heroes_treeview->get_model()->children()[count];
74 heroes_treeview->get_selection()->select(row);
79 if (quests.size() == 0)
80 fill_quest_info(NULL);
83 void QuestReportDialog::add_questing_hero(Quest *quest, Hero *h)
85 Gtk::TreeIter i = heroes_list->append();
86 (*i)[heroes_columns.hero_name] = h->getName();
87 (*i)[heroes_columns.quest] = quest;
90 void QuestReportDialog::fill_quest_info(Quest *q)
96 questmap = new QuestMap(q);
97 questmap->map_changed.connect
98 (sigc::mem_fun(this, &QuestReportDialog::on_map_changed));
99 if (dialog->is_realized() == true)
102 questmap->draw(Playerlist::getActiveplayer());
107 set_title(String::ucompose(_("Quest for %1"), q->getHero()->getName()));
109 s = q->getDescription();
111 s += q->getProgress();
116 set_title(_("No Quest"));
117 int num = rand() % 3;
121 s = _("Seek a quest in a temple!");
124 s = _("Quest? What Quest?");
127 s = _("Thou hast no quests!");
134 void QuestReportDialog::on_hero_changed()
136 Glib::RefPtr<Gtk::TreeSelection> selection = heroes_treeview->get_selection();
137 Gtk::TreeModel::iterator iterrow = selection->get_selected();
141 Gtk::TreeModel::Row row = *iterrow;
142 Quest *quest = row[heroes_columns.quest];
143 fill_quest_info(quest);
147 QuestReportDialog::~QuestReportDialog()
153 void QuestReportDialog::set_parent_window(Gtk::Window &parent)
155 dialog->set_transient_for(parent);
156 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
159 void QuestReportDialog::hide()
163 void QuestReportDialog::run()
166 questmap->draw(Playerlist::getActiveplayer());
169 if (quests.size() <= 1)
172 heroes_treeview->hide();
177 void QuestReportDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
179 map_image->property_pixmap() = map;