initial commit, lordsawar source, slightly modified
[lordsawar] / src / gui / army-info-tip.cpp
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
23 #include "army-info-tip.h"
24
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27
28 #include "ucompose.hpp"
29 #include "vector.h"
30 #include "defs.h"
31 #include "army.h"
32 #include "armyprodbase.h"
33 #include "armyproto.h"
34 #include "GraphicsCache.h"
35 #include "playerlist.h"
36 #include "city.h"
37 #include "decorated.h"
38 #include "File.h"
39
40
41 ArmyInfoTip::ArmyInfoTip(Gtk::Widget *target, const Army *army)
42 {
43     Glib::RefPtr<Gtk::Builder> xml
44         = Gtk::Builder::create_from_file(get_glade_path()
45                                     + "/army-info-window.ui");
46
47     xml->get_widget("window", window);
48     Decorated decorator;
49     decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
50
51     Gtk::Image *army_image;
52     xml->get_widget("army_image", army_image);
53     Player *p;
54     int armyset;
55     p = army->getOwner();
56     armyset = army->getArmyset();
57     GraphicsCache *gc = GraphicsCache::getInstance();
58     army_image->property_pixbuf() = 
59       gc->getArmyPic(armyset, army->getTypeId(), p, 
60                      army->getMedalBonuses())->to_pixbuf();
61
62     // fill in terrain image
63     Gtk::Image *terrain_image;
64     xml->get_widget("terrain_image", terrain_image);
65     terrain_image->property_pixbuf() = gc->getMoveBonusPic(army->getMoveBonus(), false)->to_pixbuf();
66     //terrain_image->hide();
67
68     // fill in info
69     Gtk::Label *info_label;
70     xml->get_widget("info_label", info_label);
71     Glib::ustring s;
72     s += army->getName();
73     s += "\n";
74     // note to translators: %1 is ranged strength
75     s += String::ucompose(_("Strength: %1"),
76                           army->getStat(Army::STRENGTH));
77     s += "\n";
78         
79     // note to translators: %1 is remaining moves, %2 is total moves
80     s += String::ucompose(_("Moves: %1/%2"),
81                           army->getMoves(), army->getStat(Army::MOVES));
82     s += "\n";
83     s += String::ucompose(_("Upkeep: %1"), army->getUpkeep());
84     info_label->set_text(s);
85
86     // move into correct position
87     window->get_child()->show();
88     Vector<int> pos(0, 0);
89     target->get_window()->get_origin(pos.x, pos.y);
90     if (target->has_no_window())
91       {
92         Gtk::Allocation a = target->get_allocation();
93         pos.x += a.get_x();
94         pos.y += a.get_y();
95       }
96     Vector<int> size(0, 0);
97     window->get_size(size.x, size.y);
98     window->set_gravity(Gdk::GRAVITY_SOUTH);
99     pos.y -= size.y + 2;
100
101     window->move(pos.x, pos.y);
102     window->show();
103 }
104
105 ArmyInfoTip::ArmyInfoTip(Gtk::Widget *target, const ArmyProdBase *army, 
106                          City *city)
107 {
108     Glib::RefPtr<Gtk::Builder> xml
109         = Gtk::Builder::create_from_file(get_glade_path()
110                                     + "/army-info-window.ui");
111
112     xml->get_widget("window", window);
113     Decorated decorator;
114     decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
115
116     Gtk::Image *army_image;
117     xml->get_widget("army_image", army_image);
118     Player *p = city->getOwner();
119     int armyset;
120     armyset = army->getArmyset();
121     GraphicsCache *gc = GraphicsCache::getInstance();
122     army_image->property_pixbuf() = gc->getArmyPic(armyset, army->getTypeId(), 
123                                                    p, NULL)->to_pixbuf();
124
125     // fill in terrain image
126     Gtk::Image *terrain_image;
127     xml->get_widget("terrain_image", terrain_image);
128     terrain_image->property_pixbuf() = gc->getMoveBonusPic(army->getMoveBonus(), false)->to_pixbuf();
129     //terrain_image->hide();
130
131     // fill in info
132     Gtk::Label *info_label;
133     xml->get_widget("info_label", info_label);
134     Glib::ustring s;
135     s += army->getName();
136     s += "\n";
137     // note to translators: %1 is melee strength
138     s += String::ucompose(_("Strength: %1"),
139                           army->getStrength());
140     s += "\n";
141     // note to translators: %1 is total moves
142     s += String::ucompose(_("Moves: %1"), army->getMaxMoves());
143     s += "\n";
144     s += String::ucompose(_("Time: %1"), army->getProduction());
145     s += "\n";
146     s += String::ucompose(_("Cost: %1"), army->getProductionCost());
147     info_label->set_text(s);
148
149     // move into correct position
150     window->get_child()->show();
151     Vector<int> pos(0, 0);
152     target->get_window()->get_origin(pos.x, pos.y);
153     if (target->has_no_window())
154       {
155         Gtk::Allocation a = target->get_allocation();
156         pos.x += a.get_x();
157         pos.y += a.get_y();
158       }
159     Vector<int> size(0, 0);
160     window->get_size(size.x, size.y);
161     window->set_gravity(Gdk::GRAVITY_SOUTH);
162     pos.y -= size.y + 2;
163
164     window->move(pos.x, pos.y);
165     window->show();
166 }
167
168 ArmyInfoTip::ArmyInfoTip(Gtk::Widget *target, const ArmyProto *army)
169 {
170     Glib::RefPtr<Gtk::Builder> xml
171         = Gtk::Builder::create_from_file(get_glade_path()
172                                     + "/army-info-window.ui");
173
174     xml->get_widget("window", window);
175     Decorated decorator;
176     decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
177
178     Gtk::Image *army_image;
179     xml->get_widget("army_image", army_image);
180     Player *p = Playerlist::getInstance()->getActiveplayer();
181     int armyset;
182     armyset = army->getArmyset();
183     GraphicsCache *gc = GraphicsCache::getInstance();
184     army_image->property_pixbuf() = gc->getArmyPic(armyset, army->getTypeId(), 
185                                                    p, NULL)->to_pixbuf();
186
187     // fill in terrain image
188     Gtk::Image *terrain_image;
189     xml->get_widget("terrain_image", terrain_image);
190     terrain_image->property_pixbuf() = gc->getMoveBonusPic(army->getMoveBonus(), false)->to_pixbuf();
191     //terrain_image->hide();
192
193     // fill in info
194     Gtk::Label *info_label;
195     xml->get_widget("info_label", info_label);
196     Glib::ustring s;
197     s += army->getName();
198     s += "\n";
199     // note to translators: %1 is melee strength, %2 is ranged strength
200     s += String::ucompose(_("Strength: %1"),
201                           army->getStrength());
202     s += "\n";
203     // note to translators: %1 is remaining moves, %2 is total moves
204     s += String::ucompose(_("Movement: %1"), army->getMaxMoves());
205     s += "\n";
206     s += String::ucompose(_("Time: %1"), army->getProduction());
207     s += "\n";
208     s += String::ucompose(_("Cost: %1"), army->getUpkeep());
209     info_label->set_text(s);
210
211     // move into correct position
212     window->get_child()->show();
213     Vector<int> pos(0, 0);
214     target->get_window()->get_origin(pos.x, pos.y);
215     if (target->has_no_window())
216       {
217         Gtk::Allocation a = target->get_allocation();
218         pos.x += a.get_x();
219         pos.y += a.get_y();
220       }
221     Vector<int> size(0, 0);
222     window->get_size(size.x, size.y);
223     window->set_gravity(Gdk::GRAVITY_SOUTH);
224     pos.y -= size.y + 2;
225
226     window->move(pos.x, pos.y);
227     window->show();
228 }
229
230 ArmyInfoTip::~ArmyInfoTip()
231 {
232   delete window;
233 }