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 "army-gains-level-dialog.h"
26 #include "glade-helpers.h"
27 #include "image-helpers.h"
28 #include "ucompose.hpp"
31 #include "GraphicsCache.h"
34 //give a hero some more abilities
35 ArmyGainsLevelDialog::ArmyGainsLevelDialog(Hero *a, bool show_sight_stat)
37 GraphicsCache *gc = GraphicsCache::getInstance();
40 Glib::RefPtr<Gtk::Builder> xml
41 = Gtk::Builder::create_from_file(get_glade_path()
42 + "/army-gains-level-dialog.ui");
44 xml->get_widget("dialog", dialog);
46 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
49 xml->get_widget("image", image);
50 image->property_pixbuf() = gc->getArmyPic(hero)->to_pixbuf();
51 Gtk::Image *hero_image;
52 xml->get_widget("hero_image", hero_image);
53 hero_image->property_pixbuf() =
54 gc->getNewLevelPic(Playerlist::getActiveplayer(),
55 dynamic_cast<Hero*>(a)->getGender())->to_pixbuf();
58 xml->get_widget("label", label);
60 s = String::ucompose(_("%1 has advanced to level %2!"), a->getName(),
64 s += _("Choose an attribute to improve:");
67 xml->get_widget("stats_vbox", stats_vbox);
69 add_item(Army::MOVES, _("Moves: %1"));
70 if (show_sight_stat == true)
71 add_item(Army::SIGHT, _("Sight: %1"));
72 if (a->getStat(Army::STRENGTH, false) < MAX_ARMY_STRENGTH)
73 add_item(Army::STRENGTH, _("Strength: %1"));
75 stat_items[0].radio->set_active(true);
79 ArmyGainsLevelDialog::~ArmyGainsLevelDialog()
84 void ArmyGainsLevelDialog::set_parent_window(Gtk::Window &parent)
86 dialog->set_transient_for(parent);
87 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
90 void ArmyGainsLevelDialog::hide()
95 void ArmyGainsLevelDialog::run()
101 void ArmyGainsLevelDialog::add_item(Army::Stat stat, Glib::ustring desc)
106 if (stat_items.empty())
107 item.radio = manage(new Gtk::RadioButton);
110 Gtk::RadioButton::Group group = stat_items[0].radio->get_group();
111 item.radio = manage(new Gtk::RadioButton(group));
114 stat_items.push_back(item);
116 item.radio->signal_toggled().connect(
117 sigc::mem_fun(this, &ArmyGainsLevelDialog::on_stat_toggled));
119 stats_vbox->pack_start(*item.radio, Gtk::PACK_SHRINK);
122 void ArmyGainsLevelDialog::on_stat_toggled()
124 for (unsigned int i = 0; i < stat_items.size(); ++i)
125 if (stat_items[i].radio->get_active())
127 selected_stat = stat_items[i].stat;
131 fill_in_descriptions();
134 void ArmyGainsLevelDialog::fill_in_descriptions()
136 for (unsigned int i = 0; i < stat_items.size(); ++i)
138 StatItem &item = stat_items[i];
140 int v = hero->getStat(item.stat, false);
142 if (item.radio->get_active())
143 v += hero->computeLevelGain(item.stat);
145 item.radio->set_label(String::ucompose(item.desc, v));