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 "ruin-report-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
35 #include "templelist.h"
37 RuinReportDialog::RuinReportDialog(Vector<int> pos)
39 Glib::RefPtr<Gtk::Builder> xml
40 = Gtk::Builder::create_from_file(get_glade_path()
41 + "/ruin-report-dialog.ui");
43 xml->get_widget("dialog", dialog);
45 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
47 xml->get_widget("map_image", map_image);
49 NamedLocation *l = NULL;
50 Ruin *ruin = Ruinlist::getInstance()->getNearestRuin(pos);
51 Temple *temple = Templelist::getInstance()->getNearestObject(pos);
54 else if (ruin && !temple)
56 else if (!temple && !ruin)
58 else if (ruin->getPos() == pos)
60 else if (temple->getPos() == pos)
65 ruinmap = new RuinMap(l);
66 ruinmap->map_changed.connect(
67 sigc::mem_fun(this, &RuinReportDialog::on_map_changed));
69 Gtk::EventBox *map_eventbox;
70 xml->get_widget("map_eventbox", map_eventbox);
72 map_eventbox->add_events(Gdk::BUTTON_PRESS_MASK);
73 map_eventbox->signal_button_press_event().connect(
74 sigc::mem_fun(*this, &RuinReportDialog::on_map_mouse_button_event));
75 set_title(_("Ruins and Temples"));
77 xml->get_widget("name_label", name_label);
78 xml->get_widget("type_label", type_label);
79 xml->get_widget("explored_label", explored_label);
80 xml->get_widget("description_label", description_label);
85 RuinReportDialog::~RuinReportDialog()
90 void RuinReportDialog::set_parent_window(Gtk::Window &parent)
92 dialog->set_transient_for(parent);
93 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
96 void RuinReportDialog::hide()
101 void RuinReportDialog::run()
104 ruinmap->draw(Playerlist::getActiveplayer());
106 Sound::getInstance()->playMusic("hero", 1);
109 Sound::getInstance()->haltMusic();
112 void RuinReportDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
114 map_image->property_pixmap() = map;
118 bool RuinReportDialog::on_map_mouse_button_event(GdkEventButton *e)
120 if (e->type != GDK_BUTTON_PRESS)
121 return true; // useless event
123 ruinmap->mouse_button_event(to_input_event(e));
128 void RuinReportDialog::fill_in_ruin_info()
130 NamedLocation *l = ruinmap->getNamedLocation();
131 name_label->set_text(l->getName());
132 description_label->set_text(l->getDescription());
133 Ruin *ruin = GameMap::getRuin(l->getPos());
134 Temple *temple = GameMap::getTemple(l->getPos());
137 if (ruin->getType() == Ruin::RUIN)
138 type_label->set_text(_("Ruin"));
139 else if (ruin->getType() == Ruin::STRONGHOLD)
140 type_label->set_text(_("Stronghold"));
142 if (ruin->isSearched())
143 explored_label->set_text(_("Yes"));
146 std::string hint = " ";
147 explored_label->set_text(_("No"));
148 //add the difficulty hint.
149 if (ruin->getOccupant() != NULL)
151 Stack *s = ruin->getOccupant();
152 switch ((*s->front()).getStat(Army::STRENGTH))
155 hint += _("It is especially well-guarded."); break;
157 hint += _("Rumour speaks of a formidable force within.");
160 hint += _("Even heroes are wary of this site."); break;
162 hint += _("Bones litter this place."); break;
163 case 5: case 4: case 3: case 2: case 1:
164 hint += _("It is guarded."); break;
172 hint += _("Bones litter this place.");
173 description_label->set_text(description_label->get_text() + hint);
178 type_label->set_text(_("Temple"));
179 explored_label->set_text(_("No"));
182 type_label->set_text("");