111
114
xml->get_widget("window", w);
114
w->signal_delete_event().connect(
115
sigc::mem_fun(*this, &GameWindow::on_delete_event));
117
w->signal_delete_event().connect
118
(sigc::mem_fun(*this, &GameWindow::on_delete_event));
117
120
xml->get_widget("sdl_container", sdl_container);
118
121
xml->get_widget("stack_info_box", stack_info_box);
132
135
xml->get_widget("map_eventbox", map_eventbox);
133
136
map_eventbox->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
134
137
Gdk::POINTER_MOTION_MASK);
135
map_eventbox->signal_button_press_event().connect(
136
sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
137
map_eventbox->signal_button_release_event().connect(
138
sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
139
map_eventbox->signal_motion_notify_event().connect(
140
sigc::mem_fun(*this, &GameWindow::on_map_mouse_motion_event));
138
map_eventbox->signal_button_press_event().connect
139
(sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
140
map_eventbox->signal_button_release_event().connect
141
(sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
142
map_eventbox->signal_motion_notify_event().connect
143
(sigc::mem_fun(*this, &GameWindow::on_map_mouse_motion_event));
143
xml->get_widget("stats_label", stats_label);
144
stats_text = stats_label->get_text();
145
146
Gtk::Image *image;
146
147
xml->get_widget("cities_stats_image", image);
147
image->property_file() = File::getMiscFile("various/items.png");
148
image->property_file() = File::getMiscFile("various/smallcity.png");
148
149
xml->get_widget("gold_stats_image", image);
149
image->property_file() = File::getMiscFile("various/items.png");
150
image->property_file() = File::getMiscFile("various/smalltreasury.png");
150
151
xml->get_widget("income_stats_image", image);
151
image->property_file() = File::getMiscFile("various/items.png");
152
image->property_file() = File::getMiscFile("various/smallincome.png");
153
xml->get_widget("upkeep_stats_image", image);
154
image->property_file() = File::getMiscFile("various/smallupkeep.png");
153
156
xml->get_widget("cities_stats_label", cities_stats_label);
154
157
xml->get_widget("gold_stats_label", gold_stats_label);
155
158
xml->get_widget("income_stats_label", income_stats_label);
159
xml->get_widget("upkeep_stats_label", upkeep_stats_label);
156
160
xml->get_widget("turn_label", turn_label);
157
161
xml->get_widget("turn_hbox", turn_hbox);
158
162
xml->get_widget("shield_image_0", shield_image[0]);
169
173
xml->get_widget("center_button", center_button);
170
174
xml->get_widget("defend_button", defend_button);
171
175
xml->get_widget("park_button", park_button);
176
xml->get_widget("deselect_button", deselect_button);
172
177
xml->get_widget("search_button", search_button);
173
178
xml->get_widget("move_button", move_button);
174
179
xml->get_widget("move_all_button", move_all_button);
181
186
center_button->add(*manage(new Gtk::Image(button_images[5])));
182
187
defend_button->add(*manage(new Gtk::Image(button_images[6])));
183
188
park_button->add(*manage(new Gtk::Image(button_images[1])));
189
deselect_button->add(*manage(new Gtk::Image(button_images[7])));
184
190
search_button->add(*manage(new Gtk::Image(button_images[9])));
185
191
move_button->add(*manage(new Gtk::Image(button_images[3])));
186
192
move_all_button->add(*manage(new Gtk::Image(button_images[4])));
240
246
sigc::mem_fun(*this, &GameWindow::on_item_bonus_activated));
241
247
xml->connect_clicked("production_report_menuitem",
242
248
sigc::mem_fun(*this, &GameWindow::on_production_report_activated));
249
xml->connect_clicked("triumphs_menuitem",
250
sigc::mem_fun(*this, &GameWindow::on_triumphs_activated));
243
251
d_quick_fights = false;
246
254
GameWindow::~GameWindow()
256
std::list<sigc::connection>::iterator it = connections.begin();
257
for (; it != connections.end(); it++)
248
260
clear_army_buttons();
284
297
sdl_widget->set_flags(Gtk::CAN_FOCUS);
286
299
sdl_widget->grab_focus();
287
sdl_widget->add_events(Gdk::KEY_PRESS_MASK |
300
sdl_widget->add_events(Gdk::KEY_PRESS_MASK |
288
301
Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
289
302
Gdk::POINTER_MOTION_MASK);
304
sdl_widget->signal_key_press_event().connect(
305
sigc::mem_fun(*this, &GameWindow::on_sdl_key_event));
306
sdl_widget->signal_key_release_event().connect(
307
sigc::mem_fun(*this, &GameWindow::on_sdl_key_event));
291
308
sdl_widget->signal_button_press_event().connect(
292
309
sigc::mem_fun(*this, &GameWindow::on_sdl_mouse_button_event));
293
310
sdl_widget->signal_button_release_event().connect(
294
311
sigc::mem_fun(*this, &GameWindow::on_sdl_mouse_button_event));
295
312
sdl_widget->signal_motion_notify_event().connect(
296
313
sigc::mem_fun(*this, &GameWindow::on_sdl_mouse_motion_event));
297
sdl_widget->signal_key_press_event().connect(
298
sigc::mem_fun(*this, &GameWindow::on_sdl_key_event));
300
315
// connect to the special signal that signifies that a new surface has been
301
316
// generated and attached to the widget
313
328
// then fill the other players
315
int army_id = Armysetlist::getInstance()->file_names[g.army_theme];
330
int army_id = Armysetlist::getInstance()->getArmysetId(g.army_theme);
316
331
for (std::vector<GameParameters::Player>::const_iterator
317
332
i = g.players.begin(), end = g.players.end();
318
333
i != end; ++i, ++c) {
334
349
creator.addPlayer(i->name, army_id, Player::get_color_for_no(c), type);
337
// first insert the neutral player
352
// the neutral player must come last so it has the highest id among players
338
353
creator.addNeutral(_("Neutral"), army_id, Player::get_color_for_neutral(),
339
354
Player::AI_DUMMY);
432
447
setup_button(park_button,
433
448
sigc::mem_fun(game.get(), &Game::park_selected_stack),
434
449
game->can_park_selected_stack);
450
setup_button(deselect_button,
451
sigc::mem_fun(game.get(), &Game::deselect_selected_stack),
452
game->can_deselect_selected_stack);
435
453
setup_button(search_button,
436
454
sigc::mem_fun(game.get(), &Game::search_selected_stack),
437
455
game->can_search_selected_stack);
496
514
(game->smallmap_changed.connect
497
515
(sigc::mem_fun(*this, &GameWindow::on_smallmap_changed)));
498
516
connections.push_back
517
(game->get_smallmap().view_slid.connect
518
(sigc::mem_fun(*this, &GameWindow::on_smallmap_slid)));
519
connections.push_back
499
520
(game->stack_info_changed.connect
500
521
(sigc::mem_fun(*this, &GameWindow::on_stack_info_changed)));
501
522
connections.push_back
508
529
(game->ruin_searched.connect
509
530
(sigc::mem_fun(*this, &GameWindow::on_ruin_searched)));
510
531
connections.push_back
532
(game->sage_visited.connect
533
(sigc::mem_fun(*this, &GameWindow::on_sage_visited)));
534
connections.push_back
511
535
(game->fight_started.connect
512
536
(sigc::mem_fun(*this, &GameWindow::on_fight_started)));
513
537
connections.push_back
567
591
connections.push_back
568
592
(game->player_died.connect
569
593
(sigc::mem_fun(*this, &GameWindow::on_player_died)));
594
connections.push_back
595
(game->advice_asked.connect
596
(sigc::mem_fun(*this, &GameWindow::on_advice_asked)));
571
598
// misc callbacks
572
599
QuestsManager *q = QuestsManager::getInstance();
642
670
bool GameWindow::on_sdl_key_event(GdkEventKey *e)
645
// keypresses are not implemented in the bigmap at this point,
646
// to_input_event must also be defined to something sensible
648
game->get_bigmap().key_press_event(to_input_event(e));
672
static int left_shift_down = 0;
673
static int right_shift_down = 0;
674
if (e->keyval == GDK_Shift_L)
675
left_shift_down = !left_shift_down;
676
else if (e->keyval == GDK_Shift_R)
677
right_shift_down = !right_shift_down;
679
if (e->keyval == GDK_Shift_L || e->keyval == GDK_Shift_R)
680
game->get_bigmap().set_shift_key_down (right_shift_down || left_shift_down);
1053
1093
Gtk::Label *label;
1054
1094
xml->get_widget("label", label);
1055
1095
Glib::ustring s;
1056
s += String::ucompose(_("%1 has taken over the world!"), winner->getName());
1057
if (winner->getType() == Player::HUMAN)
1060
s += _("Congratulations!");
1096
s += String::ucompose(_("Congratulations to %1 for conquering the world!"),
1062
1098
label->set_text(s);
1064
1100
dialog->show_all();
1087
1123
Glib::ustring s;
1088
1124
s += String::ucompose(_("The rule of %1 has permanently ended!"),
1089
1125
player->getName());
1126
if (Playerlist::getInstance()->countHumanPlayersAlive() == 0 &&
1127
player->getType() == Player::HUMAN)
1130
s += _("No further human resistance is possible");
1132
s += _("but the battle will continue!");
1134
s += _("Press `CTRL-P' to stop the war");
1136
s += _("and visit the sites of thy old battles.");
1090
1138
label->set_text(s);
1092
1140
dialog->show_all();
1148
void GameWindow::on_army_button_has_size()
1150
// fix height to prevent flickering
1151
int height = stack_info_box->get_height();
1152
stack_info_box->property_height_request() = height;
1153
stats_box->property_height_request() = height;
1156
1196
void GameWindow::clear_army_buttons()
1158
1198
for (army_buttons_type::iterator i = army_buttons.begin(),
1196
1236
void GameWindow::on_sidebar_stats_changed(SidebarStats s)
1198
Glib::ustring n = String::ucompose(
1199
stats_text, s.name, s.gold, s.income, s.cities, s.units);
1201
stats_label->set_text(n);
1203
1238
cities_stats_label->set_text(String::ucompose("%1", s.cities));
1204
1239
gold_stats_label->set_text(String::ucompose("%1", s.gold));
1205
1240
income_stats_label->set_text(String::ucompose("%1", s.income));
1241
upkeep_stats_label->set_text(String::ucompose("%1", s.upkeep));
1206
1242
turn_label->set_text(String::ucompose("Turn %1", s.turns + 1));
1209
1245
void GameWindow::on_smallmap_changed(SDL_Surface *map)
1211
//while (g_main_context_iteration(NULL, FALSE)); //doEvents
1212
1247
map_image->property_pixbuf() = to_pixbuf(map);
1250
void GameWindow::on_smallmap_slid(Rectangle view)
1252
on_smallmap_changed(game->get_smallmap().get_surface());
1253
while (g_main_context_iteration(NULL, FALSE)); //doEvents
1215
1256
void GameWindow::on_stack_info_changed(Stack *s)
1217
1258
clear_army_buttons();
1232
1273
void GameWindow::show_stats()
1275
Armysetlist *al = Armysetlist::getInstance();
1276
int height = al->getTileSize(Playerlist::getActiveplayer()->getArmyset());
1277
height += turn_label->get_height();
1279
stack_info_box->get_parent()->property_height_request() = height;
1280
stats_box->get_parent()->property_height_request() = height;
1234
1281
stack_info_container->hide();
1235
1282
stats_box->show();
1241
1288
GraphicsCache *gc = GraphicsCache::getInstance();
1242
1289
SDL_Surface *terrain = gc->getMoveBonusPic(bonus, s->hasShip());
1243
1290
terrain_image->property_pixbuf() = to_pixbuf(terrain);
1244
group_moves_label->set_text(String::ucompose(_("Group\nMoves\n%1"),
1291
group_moves_label->set_text(String::ucompose("%1",
1245
1292
s->getGroupMoves()));
1246
1293
group_ungroup_toggle->set_active(s->isGrouped());
1279
1326
toggle->signal_button_release_event().connect(
1280
1327
sigc::bind(sigc::mem_fun(*this, &GameWindow::on_army_button_event),
1281
1328
toggle, army), false);
1282
toggle->signal_size_allocate().connect_notify(
1283
sigc::hide(sigc::mem_fun(*this, &GameWindow::on_army_button_has_size)));
1286
1330
stack_info_box->pack_start(*toggle, Gtk::PACK_SHRINK);
1287
1331
army_buttons.push_back(toggle);
1368
1412
SageDialog d(stack->getFirstHero()->getPlayer(),
1369
1413
static_cast<Hero*>(stack->getFirstHero()), ruin);
1370
1414
d.set_parent_window(*window.get());
1415
Reward *reward = d.run();
1416
ruin->setReward(reward);
1419
void GameWindow::on_ruin_rewarded (Reward_Ruin *reward)
1421
RuinRewardedDialog d(reward);
1422
d.set_parent_window(*window.get());
1376
1428
std::auto_ptr<Gtk::Dialog> dialog;
1377
1429
if (ruin->hasSage())
1378
return on_sage_visited (ruin, stack);
1431
if (reward->getType() == Reward::RUIN)
1432
return on_ruin_rewarded(static_cast<Reward_Ruin*>(reward));
1380
1435
Glib::RefPtr<Gnome::Glade::Xml> xml
1381
1436
= Gnome::Glade::Xml::create(get_glade_path() + "/ruin-searched-dialog.glade");
1398
1453
Glib::ustring s = label->get_text();
1455
s += String::ucompose("%1 finds ", stack->getFirstHero()->getName());
1400
1456
if (reward->getType() == Reward::GOLD)
1401
s += String::ucompose("%1 finds %2 gp.", stack->getFirstHero()->getName(),
1402
dynamic_cast<Reward_Gold*>(reward)->getGold());
1458
Reward_Gold *gold = dynamic_cast<Reward_Gold*>(reward);
1459
s += String::ucompose("%1 gold pieces.", gold->getGold());
1403
1461
else if (reward->getType() == Reward::ALLIES)
1404
s += String::ucompose("%1 gets %2 allies.", stack->getFirstHero()->getName(),
1405
dynamic_cast<Reward_Allies*>(reward)->getNoOfAllies());
1463
Reward_Allies *allies = dynamic_cast<Reward_Allies*>(reward);
1464
s += String::ucompose("%1 allies.", allies->getNoOfAllies());
1406
1466
else if (reward->getType() == Reward::ITEM)
1407
s += String::ucompose("%1 gets the %2.", stack->getFirstHero()->getName(),
1408
dynamic_cast<Reward_Item*>(reward)->getItem()->getName());
1468
Reward_Item *item = dynamic_cast<Reward_Item*>(reward);
1469
s += String::ucompose("the %1.", item->getItem()->getName());
1471
else if (reward->getType() == Reward::MAP)
1473
Reward_Map *map = dynamic_cast<Reward_Map*>(reward);
1474
s += String::ucompose("the %2.", map->getLocation()->getName());
1410
1477
label->set_text(s);
1807
= GraphicsCache::getInstance()->getArmyPic(as, 0, player, 1, NULL);
1874
= GraphicsCache::getInstance()->getArmyPic(as, 0, player, NULL);
1808
1875
Glib::RefPtr<Gdk::Pixbuf> empty_pic
1809
1876
= Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, s->w, s->h);
1810
1877
empty_pic->fill(0x00000000);
1816
1883
Glib::RefPtr<Gdk::Pixbuf> pic;
1817
pic = to_pixbuf(gc->getArmyPic(as, pillaged_army_type, player, 1, NULL));
1884
pic = to_pixbuf(gc->getArmyPic(as, pillaged_army_type, player, NULL));
1818
1885
pillaged_army_type_image->set(pic);
1819
1886
pillaged_army_type_cost_label->set_text(String::ucompose("%1 gp", gold));
1877
1944
Glib::RefPtr<Gdk::Pixbuf> pic;
1878
1945
SDL_Surface *surf
1879
= GraphicsCache::getInstance()->getArmyPic(as, 0, player, 1, NULL);
1946
= GraphicsCache::getInstance()->getArmyPic(as, 0, player, NULL);
1880
1947
Glib::RefPtr<Gdk::Pixbuf> empty_pic
1881
1948
= Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, surf->w, surf->h);
1882
1949
empty_pic->fill(0x00000000);
1900
1967
sack_image = sacked_army_3_image;
1903
pic = to_pixbuf(gc->getArmyPic(as, *it, player, 1, NULL));
1970
pic = to_pixbuf(gc->getArmyPic(as, *it, player, NULL));
1904
1971
sack_image->set(pic);
1905
1972
const Army *a =
1906
1973
Armysetlist::getInstance()->getArmy (player->getArmyset(), *it);
2149
2216
Playerlist::getActiveplayer()->heroPlantStandard(NULL);
2219
void GameWindow::on_advice_asked(float percent)
2221
//we asked for advice on a fight, and we're being told that we
2222
//have a PERCENT chance of winning the fight
2223
std::auto_ptr<Gtk::Dialog> dialog;
2225
Glib::RefPtr<Gnome::Glade::Xml> xml
2226
= Gnome::Glade::Xml::create(get_glade_path() + "/military-advisor-dialog.glade");
2229
xml->get_widget("dialog", d);
2231
dialog->set_transient_for(*window.get());
2233
dialog->set_title(_("Advisor!"));
2236
xml->get_widget("label", label);
2239
int num = rand() % 5;
2241
s += _("My Good Lord!");
2243
s += _("Great and Worthy Lord!");
2245
s += _("O Champion of Justice!");
2247
s += _("O Mighty Leader!");
2249
s += _("O Great Warlord!");
2254
s += _("This battle will surely be");
2256
s += _("A battle here would be");
2258
s += _("I believe this battle will surely be");
2260
s += _("This battle would be");
2262
s += _("A battle here would be");
2264
s += _("I believe this battle will be");
2266
s += _("This battle shall be");
2270
if (percent >= 90.0)
2271
s += _("as simple as butchering sleeping cattle!");
2272
else if (percent >= 80.0)
2273
s += _("an easy victory! We cannot lose!");
2274
else if (percent >= 70.0)
2275
s += _("a comfortable victory");
2276
else if (percent >= 60.0)
2277
s += _("a hard fought victory! But we shall win!");
2278
else if (percent >= 50.0)
2279
s += _("very evenly matched!");
2280
else if (percent >= 40.0)
2281
s += _("difficult but not impossible to win!");
2282
else if (percent >= 30.0)
2283
s += _("a brave choice! I leave it to thee!");
2284
else if (percent >= 20.0)
2285
s += _("a foolish decision!");
2286
else if (percent >= 10.0)
2287
s += _("sheerest folly! Thou shouldst not attack!");
2289
s += _("complete and utter suicide!");