initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / quest-completed-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 "quest-completed-dialog.h"
24
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "input-helpers.h"
28 #include "ucompose.hpp"
29 #include "hero.h"
30 #include "defs.h"
31 #include "ruin.h"
32 #include "GameMap.h"
33
34 QuestCompletedDialog::QuestCompletedDialog(Quest *q, Reward *r)
35 {
36   reward = r;
37   quest = q;
38     
39   Glib::RefPtr<Gtk::Builder> xml
40       = Gtk::Builder::create_from_file(get_glade_path()
41                                   + "/quest-assigned-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     questmap = new QuestMap(quest);
50     questmap->map_changed.connect(
51         sigc::mem_fun(this, &QuestCompletedDialog::on_map_changed));
52
53     Gtk::EventBox *map_eventbox;
54     xml->get_widget("map_eventbox", map_eventbox);
55
56     set_title(String::ucompose(_("Quest for %1"), 
57                                quest->getHero()->getName()));
58
59     xml->get_widget("label", label);
60     Glib::ustring s;
61     s += String::ucompose(_("%1 completed the quest!"),
62                           quest->getHero()->getName());
63     s += "\n\n";
64     // add messages from the quest
65     std::queue<std::string> msgs;
66     quest->getSuccessMsg(msgs);
67     while (!msgs.empty())
68     {
69         s += msgs.front();
70         s += "\n\n";
71         msgs.pop();
72     }
73     if (reward->getType() == Reward::GOLD)
74       {
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.",
79                      gold), gold);
80       }
81     else if (reward->getType() == Reward::ALLIES)
82       {
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.",
87                      num), num);
88       }
89     else if (reward->getType() == Reward::ITEM)
90       {
91         Item *item = dynamic_cast<Reward_Item*>(reward)->getItem();
92         s += String::ucompose("You have been rewarded with the %1.", 
93                               item->getName());
94       }
95     else if (reward->getType() == Reward::RUIN)
96       {
97         Ruin *ruin = dynamic_cast<Reward_Ruin*>(reward)->getRuin();
98         s += String::ucompose("You are shown the site of %1\n", 
99                               ruin->getName());
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)
107           {
108             Item *item = dynamic_cast<Reward_Item*>(ruin_reward)->getItem();
109             s += String::ucompose(_("where the %1 can be found!"), 
110                                   item->getName());
111           }
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!");
120       }
121
122     label->set_text(s);
123
124 }
125
126 QuestCompletedDialog::~QuestCompletedDialog()
127 {
128   delete dialog;
129   delete questmap;
130 }
131 void QuestCompletedDialog::set_parent_window(Gtk::Window &parent)
132 {
133   dialog->set_transient_for(parent);
134   //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
135 }
136
137 void QuestCompletedDialog::hide()
138 {
139   dialog->hide();
140 }
141
142 void QuestCompletedDialog::run()
143 {
144   questmap->resize();
145   questmap->draw(quest->getHero()->getOwner());
146
147   dialog->show_all();
148   dialog->run();
149 }
150
151 void QuestCompletedDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
152 {
153   map_image->property_pixmap() = map;
154 }
155