1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <sigc++/functors/mem_fun.h>
24 #include "hero-offer-dialog.h"
26 #include "glade-helpers.h"
27 #include "image-helpers.h"
28 #include "input-helpers.h"
29 #include "ucompose.hpp"
36 HeroOfferDialog::HeroOfferDialog(Player *player, HeroProto *h, City *c, int gold)
41 Glib::RefPtr<Gtk::Builder> xml
42 = Gtk::Builder::create_from_file(get_glade_path()
43 + "/hero-offer-dialog.ui");
45 xml->get_widget("dialog", dialog);
48 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
50 xml->get_widget("map_image", map_image);
52 heromap = new HeroMap(city);
53 heromap->map_changed.connect(
54 sigc::mem_fun(this, &HeroOfferDialog::on_map_changed));
56 set_title(String::ucompose(_("Hero offer for %1"),
59 xml->get_widget("hero_image", hero_image);
60 xml->get_widget("hero_male", male_radiobutton);
61 male_radiobutton->signal_clicked().connect(
62 sigc::mem_fun(this, &HeroOfferDialog::on_male_toggled));
64 male_radiobutton->set_active(hero->getGender() == Hero::MALE);
67 xml->get_widget("name", name_entry);
68 name_entry->set_text(hero->getName());
71 xml->get_widget("label", label);
76 ngettext("A hero in %2 wants to join you for %1 gold piece!",
77 "A hero in %2 wants to join you for %1 gold pieces!",
78 gold), gold, city->getName());
80 s = String::ucompose(_("A hero in %1 wants to join you!"), city->getName());
84 HeroOfferDialog::~HeroOfferDialog()
89 void HeroOfferDialog::on_male_toggled()
91 if (male_radiobutton->get_active())
92 hero_image->property_file()
93 = File::getMiscFile("various/recruit_male.png");
95 hero_image->property_file()
96 = File::getMiscFile("various/recruit_female.png");
99 void HeroOfferDialog::set_parent_window(Gtk::Window &parent)
101 dialog->set_transient_for(parent);
102 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
105 void HeroOfferDialog::hide()
110 bool HeroOfferDialog::run()
113 heromap->draw(Playerlist::getActiveplayer());
115 Sound::getInstance()->playMusic("hero", 1);
117 int response = dialog->run();
118 Sound::getInstance()->haltMusic();
120 if (response == Gtk::RESPONSE_ACCEPT) // accepted
122 hero->setName(name_entry->get_text());
123 if (male_radiobutton->get_active() == true &&
124 hero->getGender() == Hero::FEMALE)
125 hero->setGender(Hero::MALE);
126 else if (male_radiobutton->get_active() == false &&
127 hero->getGender() == Hero::MALE)
128 hero->setGender(Hero::FEMALE);
135 void HeroOfferDialog::on_map_changed(Glib::RefPtr<Gdk::Pixmap> map)
137 map_image->property_pixmap() = map;