initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / ruin-rewarded-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-rewarded-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 "reward.h"
34 #include "ruin.h"
35
36
37 RuinRewardedDialog::RuinRewardedDialog(Reward_Ruin *reward)
38 {
39     Glib::RefPtr<Gtk::Builder> xml
40         = Gtk::Builder::create_from_file(get_glade_path()
41                                     + "/ruin-rewarded-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     ruinmap = new RuinMap(reward->getRuin());
50     ruinmap->map_changed.connect(
51         sigc::mem_fun(this, &RuinRewardedDialog::on_map_changed));
52
53     Gtk::EventBox *map_eventbox;
54     xml->get_widget("map_eventbox", map_eventbox);
55
56     xml->get_widget("label", label);
57     set_title(_("A Sage!"));
58
59     d_reward = reward;
60 }
61
62 RuinRewardedDialog::~RuinRewardedDialog()
63 {
64   delete ruinmap;
65   delete dialog;
66 }
67
68 void RuinRewardedDialog::set_parent_window(Gtk::Window &parent)
69 {
70     dialog->set_transient_for(parent);
71     //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
72 }
73
74 void RuinRewardedDialog::hide()
75 {
76   dialog->hide();
77 }
78
79 void RuinRewardedDialog::run()
80 {
81   ruinmap->resize();
82   ruinmap->draw(Playerlist::getActiveplayer());
83
84   Glib::ustring s;
85   s += String::ucompose(_("The sages show thee the site of %1\n"),
86                         d_reward->getRuin()->getName());
87   Reward *reward = d_reward->getRuin()->getReward();
88   if (reward->getType() == Reward::ALLIES)
89     s += _("where powerful allies can be found!");
90   else if (reward->getType() == Reward::ITEM)
91     {
92       Item *item = static_cast<Reward_Item*>(reward)->getItem();
93       s += String::ucompose(_("where the %1 can be found!"), item->getName());
94     }
95   else if (reward->getType() == Reward::MAP)
96     s += _("where a map can be found!");
97   else if (reward->getType() == Reward::RUIN)
98     s += _("where nothing can be found!");
99   else if (reward->getType() == Reward::GOLD)
100     s += _("where gold can be found!");
101   else //this one shouldn't happen
102     s += _("where something important can be found!");
103
104   label->set_text(s);
105
106   dialog->show_all();
107   dialog->run();
108 }
109
110 void RuinRewardedDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
111 {
112   map_image->property_pixmap() = map;
113 }