1 // Copyright (C) 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 "hero-editor-dialog.h"
25 #include "glade-helpers.h"
26 #include "ucompose.hpp"
29 #include "backpack-editor-dialog.h"
32 HeroEditorDialog::HeroEditorDialog(Hero *hero)
36 Glib::RefPtr<Gtk::Builder> xml
37 = Gtk::Builder::create_from_file(get_glade_path()
38 + "/hero-editor-dialog.ui");
40 xml->get_widget("dialog", dialog);
42 xml->get_widget("edit_backpack_button", edit_backpack_button);
43 edit_backpack_button->signal_clicked().connect(
44 sigc::mem_fun(this, &HeroEditorDialog::on_edit_backpack_clicked));
45 xml->get_widget("male_radiobutton", male_radiobutton);
46 xml->get_widget("female_radiobutton", female_radiobutton);
47 xml->get_widget("name_entry", name_entry);
48 name_entry->set_text(d_hero->getName());
49 if (d_hero->getGender() == Hero::FEMALE)
50 female_radiobutton->set_active(true);
52 male_radiobutton->set_active(true);
55 HeroEditorDialog::~HeroEditorDialog()
59 void HeroEditorDialog::set_parent_window(Gtk::Window &parent)
61 dialog->set_transient_for(parent);
62 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
65 void HeroEditorDialog::run()
68 Backpack *original_backpack = new Backpack(*d_hero->getBackpack());
69 int response = dialog->run();
71 if (response == Gtk::RESPONSE_ACCEPT) // accepted
73 d_hero->setName(name_entry->get_text());
74 if (male_radiobutton->get_active() == true)
75 d_hero->setGender(Hero::MALE);
77 d_hero->setGender(Hero::FEMALE);
81 d_hero->getBackpack()->removeAllFromBackpack();
82 d_hero->getBackpack()->add(original_backpack);
86 void HeroEditorDialog::on_edit_backpack_clicked()
88 BackpackEditorDialog d(d_hero->getBackpack());