1 // Copyright (C) 2007, 2008, 2009, 2012, 2014, 2017 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 "ruin-report-dialog.h"
24
25 #include "input-helpers.h"
26 #include "defs.h"
27 #include "GameMap.h"
28 #include "ruin.h"
29 #include "ruinlist.h"
30 #include "templelist.h"
31 #include "playerlist.h"
32 #include "keeper.h"
33
34 #define method(x) sigc::mem_fun(*this, &RuinReportDialog::x)
35
RuinReportDialog(Gtk::Window & parent,Vector<int> pos)36 RuinReportDialog::RuinReportDialog(Gtk::Window &parent, Vector<int> pos)
37 : LwDialog(parent, "ruin-report-dialog.ui")
38 {
39 xml->get_widget("map_image", map_image);
40
41 NamedLocation *l = NULL;
42 Ruin *ruin = Ruinlist::getInstance()->getNearestRuin(pos);
43 Temple *temple = Templelist::getInstance()->getNearestObject(pos);
44 if (temple && !ruin)
45 l = temple;
46 else if (ruin && !temple)
47 l = ruin;
48 else if (!temple && !ruin)
49 return;
50 else if (ruin->getPos() == pos)
51 l = ruin;
52 else if (temple->getPos() == pos)
53 l = temple;
54 else
55 l = ruin;
56
57 ruinmap = new RuinMap(l, NULL);
58 ruinmap->map_changed.connect(method(on_map_changed));
59
60 Gtk::EventBox *map_eventbox;
61 xml->get_widget("map_eventbox", map_eventbox);
62
63 map_eventbox->add_events(Gdk::BUTTON_PRESS_MASK);
64 map_eventbox->signal_button_press_event().connect
65 (method(on_map_mouse_button_event));
66 dialog->set_title(_("Ruins and Temples"));
67
68 xml->get_widget("name_label", name_label);
69 xml->get_widget("type_label", type_label);
70 xml->get_widget("explored_label", explored_label);
71 xml->get_widget("description_label", description_label);
72
73 fill_in_ruin_info();
74 }
75
run()76 void RuinReportDialog::run()
77 {
78 ruinmap->resize();
79 ruinmap->draw();
80
81 dialog->show_all();
82 dialog->run();
83 }
84
on_map_changed(Cairo::RefPtr<Cairo::Surface> map)85 void RuinReportDialog::on_map_changed(Cairo::RefPtr<Cairo::Surface> map)
86 {
87 map_image->property_pixbuf() =
88 Gdk::Pixbuf::create(map, 0, 0,
89 ruinmap->get_width(), ruinmap->get_height());
90 fill_in_ruin_info();
91 }
92
on_map_mouse_button_event(GdkEventButton * e)93 bool RuinReportDialog::on_map_mouse_button_event(GdkEventButton *e)
94 {
95 if (e->type != GDK_BUTTON_PRESS)
96 return true; // useless event
97
98 ruinmap->mouse_button_event(to_input_event(e));
99
100 return true;
101 }
102
fill_in_ruin_info()103 void RuinReportDialog::fill_in_ruin_info()
104 {
105 NamedLocation *l = ruinmap->getNamedLocation();
106 name_label->set_text(l->getName());
107 description_label->set_text(l->getDescription());
108 Ruin *ruin = GameMap::getRuin(l->getPos());
109 Temple *temple = GameMap::getTemple(l->getPos());
110 if (ruin)
111 {
112 switch (ruin->getType())
113 {
114 case Ruin::RUIN:
115 case Ruin::SAGE:
116 type_label->set_text(_("Ruin"));
117 break;
118 case Ruin::STRONGHOLD:
119 type_label->set_text(_("Stronghold"));
120 break;
121 }
122
123 if (ruin->isSearched())
124 explored_label->set_text(_("Yes"));
125 else
126 {
127 Glib::ustring hint = " ";
128 explored_label->set_text(_("No"));
129 //add the difficulty hint.
130 if (ruin->getOccupant() != NULL)
131 {
132 Keeper *keeper = ruin->getOccupant();
133 Stack *s = keeper->getStack ();
134 if (s)
135 {
136 switch ((*s->front()).getStat(Army::STRENGTH))
137 {
138 case 9:
139 hint += _("It is especially well-guarded."); break;
140 case 8:
141 hint += _("Rumour speaks of a formidable force within.");
142 break;
143 case 7:
144 hint += _("Even heroes are wary of this site."); break;
145 case 6:
146 hint += _("Bones litter this place."); break;
147 case 5: case 4: case 3: case 2: case 1:
148 hint += _("It is guarded."); break;
149 case 0:
150 hint += ""; break;
151 default:
152 hint += ""; break;
153 }
154 }
155 }
156 else
157 hint += _("Bones litter this place.");
158 description_label->set_text(description_label->get_text() + hint);
159 }
160 }
161 else if (temple)
162 {
163 type_label->set_text(_("Temple"));
164 explored_label->set_text(_("No"));
165 }
166 else
167 type_label->set_text("");
168 }
169