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-rewarded-dialog.h"
24
25 #include "ucompose.hpp"
26 #include "defs.h"
27 #include "GameMap.h"
28 #include "SightMap.h"
29 #include "reward.h"
30 #include "ruin.h"
31 #include "playerlist.h"
32 #include "Item.h"
33
34 #define method(x) sigc::mem_fun(*this, &RuinRewardedDialog::x)
35
RuinRewardedDialog(Gtk::Window & parent,Reward_Ruin * reward)36 RuinRewardedDialog::RuinRewardedDialog(Gtk::Window &parent, Reward_Ruin *reward)
37 : LwDialog(parent, "ruin-rewarded-dialog.ui")
38 {
39 xml->get_widget("map_image", map_image);
40
41 ruinmap = new RuinMap(reward->getRuin(),
42 Playerlist::getActiveplayer()->getActivestack());
43 ruinmap->map_changed.connect (method(on_map_changed));
44
45 Gtk::EventBox *map_eventbox;
46 xml->get_widget("map_eventbox", map_eventbox);
47
48 xml->get_widget("label", label);
49 dialog->set_title(_("A Sage!"));
50
51 d_reward = reward;
52 }
53
run()54 void RuinRewardedDialog::run()
55 {
56 ruinmap->resize();
57 ruinmap->draw();
58
59 Glib::ustring s =
60 String::ucompose(_("The sages show thee the site of %1\n"),
61 d_reward->getRuin()->getName());
62 Reward *reward = d_reward->getRuin()->getReward();
63 if (reward->getType() == Reward::ALLIES)
64 s += _("where powerful allies can be found!");
65 else if (reward->getType() == Reward::ITEM)
66 {
67 Item *item = static_cast<Reward_Item*>(reward)->getItem();
68 s += String::ucompose(_("where the %1 can be found!"), item->getName());
69 }
70 else if (reward->getType() == Reward::MAP)
71 s += _("where a map can be found!");
72 else if (reward->getType() == Reward::RUIN)
73 s += _("where the location of a special place can be found!");
74 else if (reward->getType() == Reward::GOLD)
75 s += _("where gold can be found!");
76 else //this one shouldn't happen
77 s += _("where something important can be found!");
78
79 label->set_text(s);
80
81 dialog->show_all();
82 dialog->run();
83 }
84
on_map_changed(Cairo::RefPtr<Cairo::Surface> map)85 void RuinRewardedDialog::on_map_changed(Cairo::RefPtr<Cairo::Surface> map)
86 {
87 map_image->property_pixbuf() =
88 Gdk::Pixbuf::create(map, 0, 0, ruinmap->get_width(), ruinmap->get_height());
89 }
90