~ubuntu-branches/ubuntu/trusty/lordsawar/trusty

« back to all changes in this revision

Viewing changes to src/editor/temple-editor-dialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2009-10-21 08:02:12 UTC
  • mfrom: (1.1.8 upstream) (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091021080212-wpmd6xdaxrgnn63y
Tags: 0.1.6-1
[ Barry deFreese ]
* New upstream release.
  + Drop libsdl-image1.2 from build-deps, no longer needed.
* Add README.source for quilt patch system.
* Clean up debian/copyright some.
* Bump Standards Version to 3.8.3. (No changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (C) 2007 Ole Laursen
 
2
//  Copyright (C) 2007, 2008, 2009 Ben Asselstine
 
3
//
 
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.
 
8
//
 
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.
 
13
//
 
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 
 
17
//  02110-1301, USA.
 
18
 
 
19
#include <config.h>
 
20
 
 
21
#include <gtkmm.h>
 
22
#include <sigc++/functors/mem_fun.h>
 
23
 
 
24
#include "temple-editor-dialog.h"
 
25
 
 
26
#include "glade-helpers.h"
 
27
#include "ucompose.hpp"
 
28
#include "CreateScenarioRandomize.h"
 
29
#include "defs.h"
 
30
#include "temple.h"
 
31
#include "RenamableLocation.h"
 
32
 
 
33
TempleEditorDialog::TempleEditorDialog(Temple *t, CreateScenarioRandomize *randomizer)
 
34
{
 
35
    d_randomizer = randomizer;
 
36
    temple = t;
 
37
    
 
38
    Glib::RefPtr<Gtk::Builder> xml
 
39
        = Gtk::Builder::create_from_file(get_glade_path()
 
40
                                    + "/temple-editor-dialog.ui");
 
41
 
 
42
    xml->get_widget("dialog", dialog);
 
43
 
 
44
    xml->get_widget("name_entry", name_entry);
 
45
    name_entry->set_text(temple->getName());
 
46
 
 
47
    xml->get_widget("description_entry", description_entry);
 
48
    description_entry->set_text(temple->getDescription());
 
49
 
 
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));
 
55
}
 
56
 
 
57
TempleEditorDialog::~TempleEditorDialog()
 
58
{
 
59
  delete dialog;
 
60
}
 
61
void TempleEditorDialog::set_parent_window(Gtk::Window &parent)
 
62
{
 
63
    dialog->set_transient_for(parent);
 
64
    //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
 
65
}
 
66
 
 
67
void TempleEditorDialog::run()
 
68
{
 
69
    dialog->show_all();
 
70
    int response = dialog->run();
 
71
 
 
72
    if (response == Gtk::RESPONSE_ACCEPT)       // accepted
 
73
    {
 
74
      Location *l = temple;
 
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());
 
79
    }
 
80
    else
 
81
      {
 
82
        if (name_entry->get_text() != Temple::getDefaultName())
 
83
          d_randomizer->pushRandomTempleName(name_entry->get_text());
 
84
      }
 
85
}
 
86
 
 
87
void TempleEditorDialog::on_randomize_name_clicked()
 
88
{
 
89
  std::string existing_name = name_entry->get_text();
 
90
  if (existing_name == Temple::getDefaultName())
 
91
    name_entry->set_text(d_randomizer->popRandomTempleName());
 
92
  else
 
93
    {
 
94
      name_entry->set_text(d_randomizer->popRandomTempleName());
 
95
      d_randomizer->pushRandomTempleName(existing_name);
 
96
    }
 
97
}