initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / ruin-report-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 "ruin-report-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 #include "File.h"
32 #include "sound.h"
33 #include "ruin.h"
34 #include "ruinlist.h"
35 #include "templelist.h"
36
37 RuinReportDialog::RuinReportDialog(Vector<int> pos)
38 {
39   Glib::RefPtr<Gtk::Builder> xml
40     = Gtk::Builder::create_from_file(get_glade_path()
41                                   + "/ruin-report-dialog.ui");
42
43   xml->get_widget("dialog", dialog);
44   decorate(dialog);
45   window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
46
47   xml->get_widget("map_image", map_image);
48
49   NamedLocation *l = NULL;
50   Ruin *ruin = Ruinlist::getInstance()->getNearestRuin(pos);
51   Temple *temple = Templelist::getInstance()->getNearestObject(pos);
52   if (temple && !ruin)
53     l = temple;
54   else if (ruin && !temple)
55     l = ruin;
56   else if (!temple && !ruin)
57     return;
58   else if (ruin->getPos() == pos)
59     l = ruin;
60   else if (temple->getPos() == pos)
61     l = temple;
62   else
63     l = ruin;
64
65   ruinmap = new RuinMap(l);
66   ruinmap->map_changed.connect(
67     sigc::mem_fun(this, &RuinReportDialog::on_map_changed));
68
69   Gtk::EventBox *map_eventbox;
70   xml->get_widget("map_eventbox", map_eventbox);
71
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"));
76
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);
81
82   fill_in_ruin_info();
83 }
84
85 RuinReportDialog::~RuinReportDialog()
86 {
87   delete dialog;
88   delete ruinmap;
89 }
90 void RuinReportDialog::set_parent_window(Gtk::Window &parent)
91 {
92   dialog->set_transient_for(parent);
93   //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
94 }
95
96 void RuinReportDialog::hide()
97 {
98   dialog->hide();
99 }
100
101 void RuinReportDialog::run()
102 {
103   ruinmap->resize();
104   ruinmap->draw(Playerlist::getActiveplayer());
105
106   Sound::getInstance()->playMusic("hero", 1);
107   dialog->show_all();
108   dialog->run();
109   Sound::getInstance()->haltMusic();
110 }
111
112 void RuinReportDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
113 {
114   map_image->property_pixmap() = map;
115   fill_in_ruin_info();
116 }
117
118 bool RuinReportDialog::on_map_mouse_button_event(GdkEventButton *e)
119 {
120   if (e->type != GDK_BUTTON_PRESS)
121     return true;        // useless event
122     
123   ruinmap->mouse_button_event(to_input_event(e));
124     
125   return true;
126 }
127
128 void RuinReportDialog::fill_in_ruin_info()
129 {
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());
135   if (ruin)
136     {
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"));
141
142       if (ruin->isSearched())
143         explored_label->set_text(_("Yes"));
144       else
145         {
146           std::string hint = "  ";
147           explored_label->set_text(_("No"));
148           //add the difficulty hint.
149           if (ruin->getOccupant() != NULL)
150             {
151               Stack *s = ruin->getOccupant();
152               switch ((*s->front()).getStat(Army::STRENGTH))
153                 {
154                 case 9: 
155                   hint += _("It is especially well-guarded."); break;
156                 case 8: 
157                   hint += _("Rumour speaks of a formidable force within."); 
158                   break;
159                 case 7: 
160                   hint += _("Even heroes are wary of this site."); break;
161                 case 6: 
162                   hint += _("Bones litter this place."); break;
163                 case 5: case 4: case 3: case 2: case 1: 
164                   hint += _("It is guarded."); break;
165                 case 0: 
166                   hint += ""; break;
167                 default: 
168                   hint += ""; break;
169                 }
170             }
171           else
172             hint += _("Bones litter this place.");
173           description_label->set_text(description_label->get_text() + hint);
174         }
175     }
176   else if (temple)
177     {
178       type_label->set_text(_("Temple"));
179       explored_label->set_text(_("No"));
180     }
181   else
182     type_label->set_text("");
183
184 }