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 "quest-completed-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
34 QuestCompletedDialog::QuestCompletedDialog(Quest *q, Reward *r)
39 Glib::RefPtr<Gtk::Builder> xml
40 = Gtk::Builder::create_from_file(get_glade_path()
41 + "/quest-assigned-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 questmap = new QuestMap(quest);
50 questmap->map_changed.connect(
51 sigc::mem_fun(this, &QuestCompletedDialog::on_map_changed));
53 Gtk::EventBox *map_eventbox;
54 xml->get_widget("map_eventbox", map_eventbox);
56 set_title(String::ucompose(_("Quest for %1"),
57 quest->getHero()->getName()));
59 xml->get_widget("label", label);
61 s += String::ucompose(_("%1 completed the quest!"),
62 quest->getHero()->getName());
64 // add messages from the quest
65 std::queue<std::string> msgs;
66 quest->getSuccessMsg(msgs);
73 if (reward->getType() == Reward::GOLD)
75 guint32 gold = dynamic_cast<Reward_Gold*>(reward)->getGold();
76 s += String::ucompose(
77 ngettext("You have been rewarded with %1 gold piece.",
78 "You have been rewarded with %1 gold pieces.",
81 else if (reward->getType() == Reward::ALLIES)
83 guint32 num = dynamic_cast<Reward_Allies*>(reward)->getNoOfAllies();
84 s += String::ucompose(
85 ngettext("You have been rewarded with %1 ally.",
86 "You have been rewarded with %1 allies.",
89 else if (reward->getType() == Reward::ITEM)
91 Item *item = dynamic_cast<Reward_Item*>(reward)->getItem();
92 s += String::ucompose("You have been rewarded with the %1.",
95 else if (reward->getType() == Reward::RUIN)
97 Ruin *ruin = dynamic_cast<Reward_Ruin*>(reward)->getRuin();
98 s += String::ucompose("You are shown the site of %1\n",
100 questmap->set_target(ruin->getPos());
101 if (ruin->getReward() == NULL)
102 ruin->populateWithRandomReward();
103 Reward *ruin_reward = ruin->getReward();
104 if (ruin_reward->getType() == Reward::ALLIES)
105 s += _("where powerful allies can be found!");
106 else if (ruin_reward->getType() == Reward::ITEM)
108 Item *item = dynamic_cast<Reward_Item*>(ruin_reward)->getItem();
109 s += String::ucompose(_("where the %1 can be found!"),
112 else if (ruin_reward->getType() == Reward::MAP)
113 s += _("where a map can be found!");
114 else if (ruin_reward->getType() == Reward::RUIN)
115 s += _("where nothing can be found!");
116 else if (ruin_reward->getType() == Reward::GOLD)
117 s += _("where gold can be found!");
118 else //this one shouldn't happen
119 s += _("where something important can be found!");
126 QuestCompletedDialog::~QuestCompletedDialog()
131 void QuestCompletedDialog::set_parent_window(Gtk::Window &parent)
133 dialog->set_transient_for(parent);
134 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
137 void QuestCompletedDialog::hide()
142 void QuestCompletedDialog::run()
145 questmap->draw(quest->getHero()->getOwner());
151 void QuestCompletedDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
153 map_image->property_pixmap() = map;