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 "temple-editor-dialog.h"
26
#include "glade-helpers.h"
27
#include "ucompose.hpp"
28
#include "CreateScenarioRandomize.h"
31
#include "RenamableLocation.h"
33
TempleEditorDialog::TempleEditorDialog(Temple *t, CreateScenarioRandomize *randomizer)
35
d_randomizer = randomizer;
38
Glib::RefPtr<Gtk::Builder> xml
39
= Gtk::Builder::create_from_file(get_glade_path()
40
+ "/temple-editor-dialog.ui");
42
xml->get_widget("dialog", dialog);
44
xml->get_widget("name_entry", name_entry);
45
name_entry->set_text(temple->getName());
47
xml->get_widget("description_entry", description_entry);
48
description_entry->set_text(temple->getDescription());
50
xml->get_widget("type_entry", type_entry);
51
type_entry->set_value(temple->getType());
52
xml->get_widget("randomize_name_button", randomize_name_button);
53
randomize_name_button->signal_clicked().connect(
54
sigc::mem_fun(this, &TempleEditorDialog::on_randomize_name_clicked));
57
TempleEditorDialog::~TempleEditorDialog()
61
void TempleEditorDialog::set_parent_window(Gtk::Window &parent)
63
dialog->set_transient_for(parent);
64
//dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
67
void TempleEditorDialog::run()
70
int response = dialog->run();
72
if (response == Gtk::RESPONSE_ACCEPT) // accepted
75
RenamableLocation *renamable_temple = static_cast<RenamableLocation*>(l);
76
renamable_temple->setName(name_entry->get_text());
77
temple->setType(type_entry->get_value_as_int());
78
renamable_temple->setDescription(description_entry->get_text());
82
if (name_entry->get_text() != Temple::getDefaultName())
83
d_randomizer->pushRandomTempleName(name_entry->get_text());
87
void TempleEditorDialog::on_randomize_name_clicked()
89
std::string existing_name = name_entry->get_text();
90
if (existing_name == Temple::getDefaultName())
91
name_entry->set_text(d_randomizer->popRandomTempleName());
94
name_entry->set_text(d_randomizer->popRandomTempleName());
95
d_randomizer->pushRandomTempleName(existing_name);