273
273
aisleriot_stats_dialog_set_name (priv->stats_dialog, game_name);
274
274
g_free (game_name);
276
aisleriot_conf_get_statistic (aisleriot_game_get_game_file (priv->game),
276
aisleriot_conf_get_statistic (aisleriot_game_get_game_module (priv->game),
279
279
aisleriot_stats_dialog_update (priv->stats_dialog, ¤t_stats);
289
289
if (response == GTK_RESPONSE_REJECT) {
290
290
AisleriotStatistic current_stats = { 0, 0, 0, 0 };
292
aisleriot_conf_set_statistic (aisleriot_game_get_game_file (priv->game),
292
aisleriot_conf_set_statistic (aisleriot_game_get_game_module (priv->game),
294
294
aisleriot_stats_dialog_update (priv->stats_dialog, ¤t_stats);
401
401
"card engine that allows many different "
402
402
"games to be played."),
403
403
"copyright", "Copyright © 1998-2006 Jonathan Blandford\n"
404
"Copyright © 2007, 2008, 2009, 2010, 2011 Christian Persch",
404
"Copyright © 2007, 2008, 2009, 2010, 2011, 2012 Christian Persch",
405
405
"license", licence,
406
406
"authors", authors,
407
407
"artists", artists,
455
455
AisleriotWindow *window)
457
457
AisleriotWindowPrivate *priv = window->priv;
458
const char *game_file;
458
const char *game_module;
460
game_file = aisleriot_game_get_game_file (priv->game);
461
aisleriot_show_help (GTK_WIDGET (window), game_file);
460
game_module = aisleriot_game_get_game_module (priv->game);
461
aisleriot_show_help (GTK_WIDGET (window), game_module);
497
497
AisleriotWindowPrivate *priv = window->priv;
499
499
ar_card_themes_install_themes (priv->theme_manager,
501
gtk_get_current_event_time ());
501
gtk_get_current_event_time ());
504
504
#ifdef ENABLE_DEBUG_UI
554
554
AisleriotWindow *window;
557
558
} DebugWindowData;
560
561
debug_data_free (DebugWindowData *data)
562
g_list_foreach (data->games_list, (GFunc) g_free, NULL);
563
g_list_free (data->games_list);
563
g_strfreev (data->games);
564
565
g_slice_free (DebugWindowData, data);
570
571
AisleriotWindowPrivate *priv = window->priv;
571
572
DebugWindowData *data;
574
const char *games_dir;
575
const char *current_game_module;
576
578
data = g_object_get_data (G_OBJECT (window), DEBUG_WINDOW_DATA_KEY);
577
579
if (data != NULL)
580
games_dir = ar_runtime_get_directory (AR_RUNTIME_GAMES_DIRECTORY);
581
dir = g_dir_open (games_dir, 0, NULL);
583
const char *game_file;
585
while ((game_file = g_dir_read_name (dir)) != NULL) {
586
if (!g_str_has_suffix (game_file, ".scm") ||
587
strcmp (game_file, "sol.scm") == 0)
590
list = g_list_prepend (list, g_strdup (game_file));
593
list = g_list_sort (list, (GCompareFunc) strcmp);
582
games = ar_get_game_modules ();
586
n_games = g_strv_length (games);
597
592
data = g_slice_new (DebugWindowData);
598
593
data->window = window;
599
data->games_list = list;
600
data->current_game = g_list_find_custom (data->games_list,
601
aisleriot_game_get_game_file (priv->game),
602
(GCompareFunc) strcmp);
595
data->n_games = n_games;
598
current_game_module = aisleriot_game_get_game_module (priv->game);
599
for (i = 0; data->games[i]; ++i) {
600
if (strcmp (data->games[i], current_game_module) == 0) {
604
606
g_object_set_data_full (G_OBJECT (window), DEBUG_WINDOW_DATA_KEY,
605
607
data, (GDestroyNotify) debug_data_free);
611
debug_cycle_timeout_cb (AisleriotWindow *window)
613
debug_cycle_timeout_cb (DebugWindowData *data)
613
DebugWindowData *data;
616
data = debug_ensure_game_list (window);
617
if (data->current_game != NULL) {
618
data->current_game = data->current_game->next;
620
if (!data->current_game)
623
if (!data->current_game) {
624
data->current_game = data->games_list;
626
if (!data->current_game)
629
game_file = data->current_game->data;
630
aisleriot_window_set_game (data->window, game_file, NULL);
615
if (data->current >= -1)
619
if (data->current >= data->n_games) {
620
data->current = data->n_games - 1;
621
return FALSE; /* don't run again */
624
aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
626
return TRUE; /* run again */
636
630
debug_cycle_cb (GtkAction *action,
637
631
AisleriotWindow *window)
639
g_timeout_add (500, (GSourceFunc) debug_cycle_timeout_cb, window);
633
DebugWindowData *data;
635
data = debug_ensure_game_list (window);
639
g_timeout_add (500, (GSourceFunc) debug_cycle_timeout_cb, data);
646
646
DebugWindowData *data;
648
648
data = debug_ensure_game_list (window);
649
data->current_game = data->games_list;
650
if (!data->current_game)
653
aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
653
aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
660
660
DebugWindowData *data;
662
662
data = debug_ensure_game_list (window);
663
data->current_game = g_list_last (data->games_list);
664
if (!data->current_game)
667
aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
666
data->current = data->n_games - 1;
667
aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
674
674
DebugWindowData *data;
676
676
data = debug_ensure_game_list (window);
677
if (data->current_game) {
678
data->current_game = data->current_game->next;
680
if (!data->current_game) {
681
data->current_game = data->games_list;
683
if (!data->current_game)
677
if (data == NULL || data->current + 1 == data->n_games)
686
aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
681
aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
693
688
DebugWindowData *data;
695
690
data = debug_ensure_game_list (window);
696
if (data->current_game) {
697
data->current_game = data->current_game->prev;
699
if (!data->current_game) {
700
data->current_game = data->games_list;
702
if (!data->current_game)
691
if (data == NULL || data->current == 0)
705
aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
695
aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
1063
1053
value = aisleriot_game_change_options (priv->game, changed_mask, changed_value);
1065
aisleriot_conf_set_options (aisleriot_game_get_game_file (priv->game), (int) value);
1055
aisleriot_conf_set_options (aisleriot_game_get_game_module (priv->game), (int) value);
1067
1057
/* Now re-deal, so the option is applied */
1068
1058
aisleriot_game_new_game (priv->game);
1093
1083
/* Only apply the options if they exist. Otherwise the options in the menu
1094
1084
* and the real game options are out of sync until first changed by the user.
1096
if (aisleriot_conf_get_options (aisleriot_game_get_game_file (priv->game), &options_value)) {
1086
if (aisleriot_conf_get_options (aisleriot_game_get_game_module (priv->game), &options_value)) {
1097
1087
aisleriot_game_change_options (priv->game, AISLERIOT_GAME_OPTIONS_MAX, options_value);
1168
1158
add_recently_played_game (AisleriotWindow *window,
1169
const char *game_file)
1159
const char *game_module)
1171
1161
AisleriotWindowPrivate *priv = window->priv;
1172
1162
char **recent_games, **new_recent;
1173
1163
gsize i, n_recent = 0, n_new_recent = 0;
1178
1168
/* Don't store the game type in freecell mode */
1184
1174
if (recent_games == NULL) {
1185
1175
new_recent = g_new (char *, 2);
1186
new_recent[0] = g_strdup (game_file);
1176
new_recent[0] = g_strdup (game_module);
1187
1177
new_recent[1] = NULL;
1188
1178
n_new_recent = 1;
1190
1180
new_recent = g_new (char *, MIN (n_recent + 1, MAX_RECENT) + 1);
1191
1181
n_new_recent = 0;
1193
new_recent[n_new_recent++] = g_strdup (game_file);
1183
new_recent[n_new_recent++] = g_strdup (game_module);
1195
1185
for (i = 0; i < n_recent && n_new_recent < MAX_RECENT; ++i) {
1196
if (g_ascii_strcasecmp (game_file, recent_games[i]) != 0) {
1186
if (g_ascii_strcasecmp (game_module, recent_games[i]) != 0) {
1197
1187
new_recent[n_new_recent++] = g_strdup (recent_games[i]);
1213
1203
recent_game_cb (GtkAction *action,
1214
1204
AisleriotWindow *window)
1216
const char *game_file;
1218
game_file = g_object_get_data (G_OBJECT (action), "game");
1219
g_return_if_fail (game_file != NULL);
1221
aisleriot_window_set_game (window, game_file, NULL);
1223
ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), game_file);
1206
const char *game_module;
1208
game_module = g_object_get_data (G_OBJECT (action), "game");
1209
g_return_if_fail (game_module != NULL);
1211
aisleriot_window_set_game_module (window, game_module, NULL);
1213
ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), game_module);
1262
1252
g_free (tooltip);
1264
1254
g_object_set_data_full (G_OBJECT (action), "game",
1265
recent_games[i], (GDestroyNotify) g_free);
1255
ar_filename_to_game_module (recent_games[i]),
1256
(GDestroyNotify) g_free);
1266
1257
g_signal_connect (action, "activate",
1267
1258
G_CALLBACK (recent_game_cb), window);
1268
1259
gtk_action_group_add_action (priv->recent_games_group, action);
1475
1466
AisleriotWindow *window)
1477
1468
AisleriotWindowPrivate *priv = window->priv;
1481
g_object_get (game, "score", &score, NULL);
1483
/* Translators: if you want to use localised digits for the game score,
1484
* then translate this string to "%I6d", else to "%6d".
1485
* Do not translate it to anything else!
1487
g_snprintf (str, sizeof (str), C_("score", "%6d"), score);
1488
gtk_label_set_text (GTK_LABEL (priv->score_label), str);
1470
gtk_label_set_text (GTK_LABEL (priv->score_label),
1471
aisleriot_game_get_score (game));
1883
1866
AisleriotWindowPrivate *priv = window->priv;
1885
1868
if (event->changed_mask & (GDK_WINDOW_STATE_FULLSCREEN | GDK_WINDOW_STATE_MAXIMIZED)) {
1886
gboolean is_fullscreen, is_maximised;
1869
gboolean is_fullscreen;
1888
1871
is_fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
1889
is_maximised = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
1891
1873
set_fullscreen_actions (window, is_fullscreen);
2482
2464
AisleriotWindow *window)
2484
2466
/* Load the default game */
2485
aisleriot_window_set_game (window, DEFAULT_VARIATION, NULL);
2467
aisleriot_window_set_game_module (window, DEFAULT_VARIATION, NULL);
2487
2469
gtk_widget_destroy (dialog);
2494
2476
GError *error = NULL;
2497
if (!aisleriot_game_load_game (priv->game, data->game_file, &error)) {
2479
if (!aisleriot_game_load_game (priv->game, data->game_module, &error)) {
2498
2480
GtkWidget *dialog;
2501
name = ar_filename_to_display_name (data->game_file);
2483
name = ar_filename_to_display_name (data->game_module);
2503
2485
dialog = gtk_message_dialog_new (GTK_WINDOW (data->window),
2504
2486
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
2511
2493
if (priv->freecell_mode ||
2512
strcmp (data->game_file, DEFAULT_VARIATION) == 0) {
2494
strcmp (data->game_module, DEFAULT_VARIATION) == 0) {
2513
2495
/* Loading freecell/the fallback game failed; all we can do is exit */
2514
2496
g_signal_connect_swapped (dialog, "response",
2515
2497
G_CALLBACK (gtk_widget_destroy), data->window);
2540
2522
* store it in conf, except when we're running in freecell mode.
2542
2524
if (!priv->freecell_mode) {
2543
ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), data->game_file);
2527
pref = g_strconcat (data->game_module, ".scm", NULL);
2528
ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), pref);
2546
2532
rand = data->rand;
2561
2547
if (data->rand)
2562
2548
g_rand_free (data->rand);
2564
g_free (data->game_file);
2550
g_free (data->game_module);
2565
2551
g_slice_free (LoadIdleData, data);
2569
2555
* aisleriot_window_set_game:
2571
* @game_file: a UTF-8 string
2557
* @game_module: a UTF-8 string
2572
2558
* @rand: (allow-none) (transfer full): a #GRand, or %NULL
2574
* Loads the game variation defined in the @game_file file.
2575
* Note that even though @game_file is used as a filename,
2560
* Loads the game variation defined in the @game_module file.
2561
* Note that even though @game_module is used as a filename,
2576
2562
* it must be in UTF-8!
2579
aisleriot_window_set_game (AisleriotWindow *window,
2580
const char *game_file,
2565
aisleriot_window_set_game_module (AisleriotWindow *window,
2566
const char *game_module,
2583
2569
AisleriotWindowPrivate *priv = window->priv;
2584
2570
LoadIdleData *data;
2591
2577
data = g_slice_new (LoadIdleData);
2592
2578
data->window = window;
2593
data->game_file = g_strdup (game_file);
2579
data->game_module = g_strdup (game_module);
2594
2580
data->rand = rand; /* adopted */
2596
2582
priv->load_idle_id = g_idle_add_full (G_PRIORITY_LOW,
2603
* aisleriot_window_get_game:
2589
* aisleriot_window_get_game_module:
2606
* Returns: the #AisleriotGame running in @window
2592
* Returns: the name of the game running in @window
2609
aisleriot_window_get_game (AisleriotWindow *window)
2595
aisleriot_window_get_game_module (AisleriotWindow *window)
2611
2597
AisleriotWindowPrivate *priv = window->priv;
2599
return aisleriot_game_get_game_module (priv->game);