39
39
#include "ar-string-utils.h"
40
40
#include "ar-gsettings.h"
43
#include "ar-clutter-embed.h"
48
42
#include "board-noclutter.h"
51
44
#include "ar-card-theme.h"
52
45
#include "ar-card-themes.h"
187
174
aisleriot_game_restart_game (priv->game);
189
176
case RESPONSE_NEW_GAME:
190
aisleriot_game_new_game (priv->game, NULL);
177
aisleriot_game_new_game (priv->game);
192
179
case GTK_RESPONSE_CLOSE:
193
180
gtk_widget_destroy (GTK_WIDGET (window)); /* this will quit */
322
309
AisleriotWindowPrivate *priv = window->priv;
324
aisleriot_game_new_game (priv->game, NULL);
311
aisleriot_game_new_game (priv->game);
326
313
gtk_widget_grab_focus (GTK_WIDGET (priv->board));
333
320
AisleriotWindowPrivate *priv = window->priv;
335
322
/* If a move is in progress, cancel it before changing the game! */
337
aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
339
323
aisleriot_board_abort_move (priv->board);
342
325
aisleriot_game_undo_move (priv->game);
650
630
game_file = data->current_game->data;
651
aisleriot_window_set_game (data->window, game_file, 0);
631
aisleriot_window_set_game (data->window, game_file, NULL);
745
726
seed = g_ascii_strtoull (text, &endptr, 10);
746
727
if (errno == 0 && endptr != text) {
747
aisleriot_game_new_game (priv->game, &seed);
728
rand = g_rand_new_with_seed (seed);
730
aisleriot_game_new_game_with_rand (priv->game, rand /* adopts */);
749
732
gtk_widget_grab_focus (GTK_WIDGET (priv->board));
757
740
debug_choose_seed_cb (GtkAction *action,
758
741
AisleriotWindow *window)
760
AisleriotWindowPrivate *priv = window->priv;
761
743
GtkWidget *dialog, *entry;
764
745
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
765
746
GTK_DIALOG_DESTROY_WITH_PARENT |
771
752
G_CALLBACK (debug_choose_seed_response_cb), window);
772
753
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
755
entry = gtk_entry_new ();
774
760
g_snprintf (str, sizeof (str), "%u", aisleriot_game_get_seed (priv->game));
775
entry = gtk_entry_new ();
776
761
gtk_entry_set_text (GTK_ENTRY (entry), str);
777
765
gtk_box_pack_end (GTK_BOX (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog))), entry, FALSE, FALSE, 0);
778
766
gtk_widget_show (entry);
779
767
g_object_set_data (G_OBJECT (dialog), "entry", entry);
959
947
#endif /* ENABLE_SOUND */
964
animations_toggle_cb (GtkToggleAction *action,
965
AisleriotWindow *window)
967
AisleriotWindowPrivate *priv = window->priv;
970
enabled = gtk_toggle_action_get_active (action);
972
ar_style_set_enable_animations (priv->board_style, enabled);
974
ar_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), enabled);
977
#endif /* HAVE_CLUTTER */
980
950
show_hint_cb (GtkAction *action,
981
951
AisleriotWindow *window)
1096
1066
aisleriot_conf_set_options (aisleriot_game_get_game_file (priv->game), (int) value);
1098
1068
/* Now re-deal, so the option is applied */
1099
aisleriot_game_new_game (priv->game, NULL);
1069
aisleriot_game_new_game (priv->game);
1249
1219
game_file = g_object_get_data (G_OBJECT (action), "game");
1250
1220
g_return_if_fail (game_file != NULL);
1252
aisleriot_window_set_game (window, game_file, 0);
1222
aisleriot_window_set_game (window, game_file, NULL);
1254
1224
ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), game_file);
1735
1705
gtk_widget_destroy (dialog);
1737
1707
/* Start a new game */
1738
aisleriot_game_new_game (priv->game, NULL);
1708
aisleriot_game_new_game (priv->game);
1740
1710
gtk_widget_grab_focus (GTK_WIDGET (priv->board));
1780
1750
gtk_widget_show (dialog);
1783
#if defined(HAVE_CLUTTER) || defined(ENABLE_SOUND)
1753
#if defined(ENABLE_SOUND)
1786
1756
settings_changed_cb (GtkSettings *settings,
1801
if (name == NULL || strcmp (name, "gtk-enable-animations") == 0) {
1802
g_object_get (settings, "gtk-enable-animations", &enabled, NULL);
1804
action = gtk_action_group_get_action (priv->action_group, "Animations");
1805
gtk_action_set_visible (action, enabled);
1807
#endif /* HAVE_CLUTTER */
1809
#if defined(ENABLE_SOUND)
1810
1770
if (name == NULL || strcmp (name, "gtk-enable-event-sounds") == 0) {
1811
1771
g_object_get (settings, "gtk-enable-event-sounds", &enabled, NULL);
1813
1773
action = gtk_action_group_get_action (priv->action_group, "Sound");
1814
1774
gtk_action_set_visible (action, enabled);
1816
#endif /* ENABLE_SOUND */
1842
1801
settings = gtk_widget_get_settings (widget);
1843
1802
settings_changed_cb (settings, NULL, window);
1845
g_signal_connect (settings, "notify::gtk-enable-animations",
1846
G_CALLBACK (settings_changed_cb), window);
1848
#if defined (ENABLE_SOUND)
1849
1803
g_signal_connect (settings, "notify::gtk-enable-event-sounds",
1850
1804
G_CALLBACK (settings_changed_cb), window);
1854
#endif /* HAVE_CLUTTER || ENABLE_SOUND */
1807
#endif /* ENABLE_SOUND */
1857
1810
* aisleriot_window_set_freecell_mode:
1903
board_cursor_cb (AisleriotBoard *board,
1905
ArClutterEmbed *embed)
1907
ar_clutter_embed_set_cursor (embed, (ArCursorType) cursor_type);
1911
board_error_bell_cb (AisleriotBoard *board,
1912
ArClutterEmbed *embed)
1914
gtk_widget_error_bell (GTK_WIDGET (embed));
1918
embed_size_allocate_cb (ArClutterEmbed *embed,
1919
GtkAllocation *allocation,
1920
AisleriotWindow *window)
1922
AisleriotWindowPrivate *priv = window->priv;
1924
clutter_actor_set_size (priv->board_actor, allocation->width, allocation->height);
1927
#endif /* HAVE_CLUTTER */
1929
1853
/* Class implementation */
1931
1855
G_DEFINE_TYPE (AisleriotWindow, aisleriot_window, GTK_TYPE_WINDOW)
2105
2029
G_CALLBACK (sound_toggle_cb),
2106
2030
FALSE /* not active by default */ },
2107
2031
#endif /* ENABLE_SOUND */
2109
{ "Animations", NULL, N_("_Animations"), NULL,
2110
N_("Whether or not to animate card moves"),
2111
G_CALLBACK (animations_toggle_cb),
2112
FALSE /* not active by default */ },
2113
#endif /* HAVE_CLUTTER */
2116
2034
static const char names[][16] = {
2234
2146
priv->board_style = ar_style_new ();
2237
priv->board = ar_clutter_embed_new (priv->board_style);
2239
priv->baize_actor = aisleriot_baize_new ();
2241
stage = CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->board)));
2242
clutter_container_add (stage, priv->baize_actor, NULL);
2243
/* FIXMEchpe: how to ensure this is ALWAYS the lowest actor? */
2244
clutter_actor_lower_bottom (priv->baize_actor);
2246
priv->board_actor = aisleriot_board_new (priv->board_style, priv->game);
2247
clutter_container_add (stage, priv->board_actor, NULL);
2250
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), priv->board_actor);
2252
g_signal_connect_after (priv->board, "size-allocate",
2253
G_CALLBACK (embed_size_allocate_cb), window);
2255
g_signal_connect (priv->board_actor, "request-cursor",
2256
G_CALLBACK (board_cursor_cb), priv->board);
2257
g_signal_connect (priv->board_actor, "error-bell",
2258
G_CALLBACK (board_error_bell_cb), priv->board);
2260
/* FIXMEchpe: unref baize & board_actor here? */
2262
2148
priv->board = AISLERIOT_BOARD (aisleriot_board_new (priv->board_style, priv->game));
2263
#endif /* HAVE_CLUTTER */
2265
2150
theme_name = ar_conf_get_string (NULL, aisleriot_conf_get_key (CONF_THEME), NULL);
2266
2151
theme = ar_card_themes_get_theme_by_name (priv->theme_manager, theme_name);
2312
2197
priv->game_message_id = gtk_statusbar_get_context_id (priv->statusbar, "board-message");
2315
g_signal_connect (priv->board_actor, "status-message",
2316
G_CALLBACK (board_status_message_cb), window);
2318
2199
g_signal_connect (priv->board, "status-message",
2319
2200
G_CALLBACK (board_status_message_cb), window);
2322
2202
gtk_window_set_has_resize_grip (GTK_WINDOW (window), TRUE);
2414
2294
set_fullscreen_actions (window, FALSE);
2417
action = gtk_action_group_get_action (priv->action_group, "Animations");
2418
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2419
ar_conf_get_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), NULL));
2421
#endif /* HAVE_CLUTTER */
2423
#if defined(HAVE_CLUTTER) || defined(ENABLE_SOUND)
2296
#if defined(ENABLE_SOUND)
2424
2297
/* Set the action visibility and listen for animation and sound mode changes */
2425
2298
screen_changed_cb (GTK_WIDGET (window), NULL, window);
2426
2299
g_signal_connect (window, "screen-changed",
2427
2300
G_CALLBACK (screen_changed_cb), window);
2428
#endif /* HAVE_CLUTTER || ENABLE_SOUND */
2301
#endif /* ENABLE_SOUND */
2430
2303
/* Now set up the widgets */
2431
2304
main_vbox = gtk_vbox_new (FALSE, 0);
2482
2355
AisleriotWindow *window = AISLERIOT_WINDOW (object);
2483
2356
AisleriotWindowPrivate *priv = window->priv;
2486
2359
g_signal_handlers_disconnect_by_func (gtk_widget_get_settings (GTK_WIDGET (window)),
2487
2360
G_CALLBACK (settings_changed_cb),
2489
#endif /* HAVE_CLUTTER */
2362
#endif /* ENABLE_SOUND */
2491
2364
if (priv->hint_dialog) {
2492
2365
gtk_widget_destroy (priv->hint_dialog);
2526
2399
AisleriotWindow *window = AISLERIOT_WINDOW (object);
2527
2400
AisleriotWindowPrivate *priv = window->priv;
2530
g_object_unref (priv->board_style);
2531
#endif /* HAVE_CLUTTER */
2533
2402
if (priv->theme) {
2534
2403
g_object_unref (priv->theme);
2618
2487
AisleriotWindow *window)
2620
2489
/* Load the default game */
2621
aisleriot_window_set_game (window, DEFAULT_VARIATION, 0);
2490
aisleriot_window_set_game (window, DEFAULT_VARIATION, NULL);
2623
2492
gtk_widget_destroy (dialog);
2678
2548
ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), data->game_file);
2681
aisleriot_game_new_game (priv->game, data->seed != 0 ? &data->seed : NULL);
2554
aisleriot_game_new_game_with_rand (priv->game, rand /* adopted */);
2683
2556
gtk_widget_grab_focus (GTK_WIDGET (priv->board));
2691
2564
data->window->priv->load_idle_id = 0;
2567
g_rand_free (data->rand);
2693
2569
g_free (data->game_file);
2694
2570
g_slice_free (LoadIdleData, data);
2698
2574
* aisleriot_window_set_game:
2700
2576
* @game_file: a UTF-8 string
2577
* @rand: (allow-none) (transfer full): a #GRand, or %NULL
2703
2579
* Loads the game variation defined in the @game_file file.
2704
2580
* Note that even though @game_file is used as a filename,
2720
2596
data = g_slice_new (LoadIdleData);
2721
2597
data->window = window;
2722
2598
data->game_file = g_strdup (game_file);
2599
data->rand = rand; /* adopted */
2725
2601
priv->load_idle_id = g_idle_add_full (G_PRIORITY_LOW,
2726
2602
(GSourceFunc) load_idle_cb,