~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (C) 2008, Ben Asselstine
 
2
//
 
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 2 of the License, or
 
6
//  (at your option) any later version.
 
7
//
 
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.
 
12
//
 
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 
 
16
//  02110-1301, USA.
 
17
 
 
18
#include <config.h>
 
19
 
 
20
#include <iostream>
 
21
#include <iomanip>
 
22
#include <assert.h>
 
23
#include <libgen.h>
 
24
 
 
25
#include <sigc++/functors/mem_fun.h>
 
26
#include <sigc++/functors/ptr_fun.h>
 
27
 
 
28
#include <gtkmm/widget.h>
 
29
#include <gtkmm/eventbox.h>
 
30
#include <gtkmm/image.h>
 
31
#include <gtkmm/box.h>
 
32
#include <gtkmm/dialog.h>
 
33
 
 
34
#include "rewardlist-dialog.h"
 
35
 
 
36
#include "../gui/input-helpers.h"
 
37
#include "../gui/error-utils.h"
 
38
 
 
39
#include "../defs.h"
 
40
#include "../Configuration.h"
 
41
#include "../rewardlist.h"
 
42
 
 
43
#include "../ucompose.hpp"
 
44
#include "../playerlist.h"
 
45
 
 
46
#include "glade-helpers.h"
 
47
#include "reward-dialog.h"
 
48
 
 
49
 
 
50
RewardlistDialog::RewardlistDialog()
 
51
{
 
52
    Glib::RefPtr<Gnome::Glade::Xml> xml
 
53
        = Gnome::Glade::Xml::create(get_glade_path() + 
 
54
                                    "/reward-list-dialog.glade");
 
55
 
 
56
    Gtk::Dialog *d = 0;
 
57
    xml->get_widget("dialog", d);
 
58
    dialog.reset(d);
 
59
 
 
60
    xml->get_widget("rewards_treeview", rewards_treeview);
 
61
    xml->get_widget("add_button", add_button);
 
62
    add_button->signal_clicked().connect
 
63
      (sigc::mem_fun(this, &RewardlistDialog::on_add_clicked));
 
64
    xml->get_widget("remove_button", remove_button);
 
65
    remove_button->signal_clicked().connect
 
66
      (sigc::mem_fun(this, &RewardlistDialog::on_remove_clicked));
 
67
    xml->get_widget("edit_button", edit_button);
 
68
    edit_button->signal_clicked().connect
 
69
      (sigc::mem_fun(this, &RewardlistDialog::on_edit_clicked));
 
70
 
 
71
    rewards_list = Gtk::ListStore::create(rewards_columns);
 
72
    rewards_treeview->set_model(rewards_list);
 
73
    rewards_treeview->append_column("", rewards_columns.name);
 
74
    rewards_treeview->set_headers_visible(false);
 
75
 
 
76
    Rewardlist *rewardlist = Rewardlist::getInstance();
 
77
    Rewardlist::iterator iter = rewardlist->begin();
 
78
    for (;iter != rewardlist->end(); iter++)
 
79
      addReward(*iter);
 
80
      
 
81
    Uint32 max = rewardlist->size();
 
82
    if (max)
 
83
      {
 
84
        Gtk::TreeModel::Row row;
 
85
        row = rewards_treeview->get_model()->children()[0];
 
86
        if(row)
 
87
          rewards_treeview->get_selection()->select(row);
 
88
      }
 
89
 
 
90
 
 
91
    update_rewardlist_buttons();
 
92
    rewards_treeview->get_selection()->signal_changed().connect
 
93
      (sigc::mem_fun(*this, &RewardlistDialog::on_reward_selected));
 
94
}
 
95
 
 
96
void
 
97
RewardlistDialog::update_rewardlist_buttons()
 
98
{
 
99
  if (!rewards_treeview->get_selection()->get_selected())
 
100
    {
 
101
      remove_button->set_sensitive(false);
 
102
      edit_button->set_sensitive(false);
 
103
    }
 
104
  else
 
105
    {
 
106
      remove_button->set_sensitive(true);
 
107
      edit_button->set_sensitive(true);
 
108
    }
 
109
}
 
110
 
 
111
RewardlistDialog::~RewardlistDialog()
 
112
{
 
113
}
 
114
 
 
115
void RewardlistDialog::addReward(Reward *reward)
 
116
{
 
117
  Gtk::TreeIter i = rewards_list->append();
 
118
  (*i)[rewards_columns.name] = reward->getName();
 
119
  (*i)[rewards_columns.reward] = reward;
 
120
}
 
121
 
 
122
void RewardlistDialog::on_reward_selected()
 
123
{
 
124
  update_rewardlist_buttons();
 
125
}
 
126
 
 
127
void RewardlistDialog::on_add_clicked()
 
128
{
 
129
  Player *neutral = Playerlist::getInstance()->getNeutral();
 
130
  RewardDialog d(neutral, true, NULL);
 
131
  d.run();
 
132
  if (d.get_reward())
 
133
    {
 
134
      Reward *reward = d.get_reward();
 
135
      Gtk::TreeIter i = rewards_list->append();
 
136
      (*i)[rewards_columns.name] = reward->getName();
 
137
      (*i)[rewards_columns.reward] = reward;
 
138
      Rewardlist::getInstance()->push_back(reward);
 
139
    }
 
140
 
 
141
}
 
142
 
 
143
void RewardlistDialog::on_remove_clicked()
 
144
{
 
145
  //erase the selected row from the treeview
 
146
  //remove the reward from the rewardlist
 
147
  Glib::RefPtr<Gtk::TreeSelection> selection = rewards_treeview->get_selection();
 
148
  Gtk::TreeModel::iterator iterrow = selection->get_selected();
 
149
 
 
150
  if (iterrow) 
 
151
    {
 
152
      Gtk::TreeModel::Row row = *iterrow;
 
153
      Reward *a = row[rewards_columns.reward];
 
154
      rewards_list->erase(iterrow);
 
155
      Rewardlist::getInstance()->remove(a);
 
156
    }
 
157
}
 
158
 
 
159
void RewardlistDialog::on_edit_clicked()
 
160
{
 
161
  Glib::RefPtr<Gtk::TreeSelection> selection = 
 
162
    rewards_treeview->get_selection();
 
163
  Gtk::TreeModel::iterator iterrow = selection->get_selected();
 
164
 
 
165
  if (iterrow) 
 
166
    {
 
167
      Gtk::TreeModel::Row row = *iterrow;
 
168
      Reward *reward = row[rewards_columns.reward];
 
169
      Player *neutral = Playerlist::getInstance()->getNeutral();
 
170
      RewardDialog d(neutral, true, reward);
 
171
      d.run();
 
172
      if (d.get_reward())
 
173
        {
 
174
          Rewardlist::getInstance()->remove(reward);
 
175
          reward = d.get_reward();
 
176
          (*iterrow)[rewards_columns.name] = reward->getName();
 
177
          (*iterrow)[rewards_columns.reward] = reward;
 
178
          Rewardlist::getInstance()->push_back(reward);
 
179
        }
 
180
      else
 
181
        {
 
182
          rewards_list->erase(iterrow);
 
183
          Rewardlist::getInstance()->remove(reward);
 
184
        }
 
185
    }
 
186
 
 
187
}
 
188
 
 
189
void RewardlistDialog::set_parent_window(Gtk::Window &parent)
 
190
{
 
191
    dialog->set_transient_for(parent);
 
192
    //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
 
193
}
 
194
 
 
195
void RewardlistDialog::run()
 
196
{
 
197
    dialog->show_all();
 
198
    int response = dialog->run();
 
199
}
 
200