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
23 #include "army-info-tip.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
28 #include "ucompose.hpp"
32 #include "armyprodbase.h"
33 #include "armyproto.h"
34 #include "GraphicsCache.h"
35 #include "playerlist.h"
37 #include "decorated.h"
41 ArmyInfoTip::ArmyInfoTip(Gtk::Widget *target, const Army *army)
43 Glib::RefPtr<Gtk::Builder> xml
44 = Gtk::Builder::create_from_file(get_glade_path()
45 + "/army-info-window.ui");
47 xml->get_widget("window", window);
49 decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
51 Gtk::Image *army_image;
52 xml->get_widget("army_image", army_image);
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();
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();
69 Gtk::Label *info_label;
70 xml->get_widget("info_label", info_label);
74 // note to translators: %1 is ranged strength
75 s += String::ucompose(_("Strength: %1"),
76 army->getStat(Army::STRENGTH));
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));
83 s += String::ucompose(_("Upkeep: %1"), army->getUpkeep());
84 info_label->set_text(s);
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())
92 Gtk::Allocation a = target->get_allocation();
96 Vector<int> size(0, 0);
97 window->get_size(size.x, size.y);
98 window->set_gravity(Gdk::GRAVITY_SOUTH);
101 window->move(pos.x, pos.y);
105 ArmyInfoTip::ArmyInfoTip(Gtk::Widget *target, const ArmyProdBase *army,
108 Glib::RefPtr<Gtk::Builder> xml
109 = Gtk::Builder::create_from_file(get_glade_path()
110 + "/army-info-window.ui");
112 xml->get_widget("window", window);
114 decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
116 Gtk::Image *army_image;
117 xml->get_widget("army_image", army_image);
118 Player *p = city->getOwner();
120 armyset = army->getArmyset();
121 GraphicsCache *gc = GraphicsCache::getInstance();
122 army_image->property_pixbuf() = gc->getArmyPic(armyset, army->getTypeId(),
123 p, NULL)->to_pixbuf();
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();
132 Gtk::Label *info_label;
133 xml->get_widget("info_label", info_label);
135 s += army->getName();
137 // note to translators: %1 is melee strength
138 s += String::ucompose(_("Strength: %1"),
139 army->getStrength());
141 // note to translators: %1 is total moves
142 s += String::ucompose(_("Moves: %1"), army->getMaxMoves());
144 s += String::ucompose(_("Time: %1"), army->getProduction());
146 s += String::ucompose(_("Cost: %1"), army->getProductionCost());
147 info_label->set_text(s);
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())
155 Gtk::Allocation a = target->get_allocation();
159 Vector<int> size(0, 0);
160 window->get_size(size.x, size.y);
161 window->set_gravity(Gdk::GRAVITY_SOUTH);
164 window->move(pos.x, pos.y);
168 ArmyInfoTip::ArmyInfoTip(Gtk::Widget *target, const ArmyProto *army)
170 Glib::RefPtr<Gtk::Builder> xml
171 = Gtk::Builder::create_from_file(get_glade_path()
172 + "/army-info-window.ui");
174 xml->get_widget("window", window);
176 decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
178 Gtk::Image *army_image;
179 xml->get_widget("army_image", army_image);
180 Player *p = Playerlist::getInstance()->getActiveplayer();
182 armyset = army->getArmyset();
183 GraphicsCache *gc = GraphicsCache::getInstance();
184 army_image->property_pixbuf() = gc->getArmyPic(armyset, army->getTypeId(),
185 p, NULL)->to_pixbuf();
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();
194 Gtk::Label *info_label;
195 xml->get_widget("info_label", info_label);
197 s += army->getName();
199 // note to translators: %1 is melee strength, %2 is ranged strength
200 s += String::ucompose(_("Strength: %1"),
201 army->getStrength());
203 // note to translators: %1 is remaining moves, %2 is total moves
204 s += String::ucompose(_("Movement: %1"), army->getMaxMoves());
206 s += String::ucompose(_("Time: %1"), army->getProduction());
208 s += String::ucompose(_("Cost: %1"), army->getUpkeep());
209 info_label->set_text(s);
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())
217 Gtk::Allocation a = target->get_allocation();
221 Vector<int> size(0, 0);
222 window->get_size(size.x, size.y);
223 window->set_gravity(Gdk::GRAVITY_SOUTH);
226 window->move(pos.x, pos.y);
230 ArmyInfoTip::~ArmyInfoTip()