initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / item-bonus-dialog.cpp
1 //  Copyright (C) 2007, 2008, 2009 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 3 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 <gtkmm.h>
21 #include <sigc++/functors/mem_fun.h>
22
23 #include "item-bonus-dialog.h"
24
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "ucompose.hpp"
28 #include "defs.h"
29 #include "ItemProto.h"
30 #include "Itemlist.h"
31
32 ItemBonusDialog::ItemBonusDialog()
33 {
34     Glib::RefPtr<Gtk::Builder> xml
35         = Gtk::Builder::create_from_file(get_glade_path()
36                                     + "/item-bonus-dialog.ui");
37
38     xml->get_widget("dialog", dialog);
39     decorate(dialog);
40     window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
41
42     items_list = Gtk::ListStore::create(items_columns);
43     xml->get_widget("treeview", items_treeview);
44     items_treeview->set_model(items_list);
45     items_treeview->append_column("", items_columns.name);
46     items_treeview->append_column("Bonus", items_columns.bonus);
47
48     Itemlist::iterator iter = Itemlist::getInstance()->begin();
49     for (;iter != Itemlist::getInstance()->end(); iter++)
50       addItemProto((*iter).second);
51 }
52
53 ItemBonusDialog::~ItemBonusDialog()
54 {
55   delete dialog;
56 }
57 void ItemBonusDialog::set_parent_window(Gtk::Window &parent)
58 {
59     dialog->set_transient_for(parent);
60     //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
61 }
62
63 void ItemBonusDialog::hide()
64 {
65   dialog->hide();
66 }
67 void ItemBonusDialog::run()
68 {
69     static int width = -1;
70     static int height = -1;
71
72     if (width != -1 && height != -1)
73         dialog->set_default_size(width, height);
74     
75     dialog->show();
76     dialog->run();
77
78     dialog->get_size(width, height);
79
80 }
81
82 void ItemBonusDialog::addItemProto(ItemProto *itemproto)
83 {
84     Gtk::TreeIter i = items_list->append();
85     (*i)[items_columns.name] = itemproto->getName();
86     (*i)[items_columns.bonus] = itemproto->getBonusDescription();
87 }