/** * fill_typemenu * @menu: listbox menu * * Description: * fills the listbox with configuration names **/ static void fill_typemenu (GtkWidget * menu) { gint i; gchar *config; for (i = 0; i < num_game_configs (); ++i) { config = game_config_name (i); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (menu), _(config)); g_free (config); } gtk_combo_box_set_active (GTK_COMBO_BOX (menu), properties.selected_config); }
/** * load_properties * * Description: * loads the game properties from a file * * Returns: * TRUE if the properties can be loaded, FALSE otherwise **/ gboolean load_properties (void) { gchar *cname = NULL; gint i; gchar *bgcolour; load_keys (); bgcolour = games_conf_get_string_with_default (KEY_PREFERENCES_GROUP, KEY_BACKGROUND_COLOR, "#7590AE"); gdk_color_parse (bgcolour, &properties.bgcolour); set_background_color (properties.bgcolour); properties.themename = games_conf_get_string_with_default (KEY_PREFERENCES_GROUP, KEY_THEME, "robots"); cname = games_conf_get_string_with_default (KEY_PREFERENCES_GROUP, KEY_CONFIGURATION, "classic_robots"); properties.selected_config = 0; for (i = 0; i < num_game_configs (); ++i) { if (!strcmp (cname, game_config_name (i))) { properties.selected_config = i; break; } } g_free (cname); properties.safe_moves = games_conf_get_boolean (KEY_PREFERENCES_GROUP, KEY_SAFE_MOVES, NULL); properties.super_safe_moves = games_conf_get_boolean (KEY_PREFERENCES_GROUP, KEY_SUPER_SAFE_MOVES, NULL); properties.sound = games_conf_get_boolean (KEY_PREFERENCES_GROUP, KEY_ENABLE_SOUND, NULL); properties.show_toolbar = games_conf_get_boolean (KEY_PREFERENCES_GROUP, KEY_SHOW_TOOLBAR, NULL); games_sound_enable (properties.sound); set_game_graphics (properties.themename); set_game_config (properties.selected_config); keyboard_set (properties.keys); return TRUE; }
/** * load_properties * * Description: * loads the game properties from a file * * Returns: * TRUE if the properties can be loaded, FALSE otherwise **/ gboolean load_properties (void) { gchar *cname = NULL; gint i; gchar *bgcolour, *config; load_keys (); bgcolour = g_settings_get_string (settings, KEY_BACKGROUND_COLOR); gdk_rgba_parse (&properties.bgcolour, bgcolour); set_background_color (properties.bgcolour); properties.themename = g_settings_get_string (settings, KEY_THEME); cname = g_settings_get_string (settings, KEY_CONFIGURATION); properties.selected_config = 0; for (i = 0; i < num_game_configs (); ++i) { config = game_config_name (i); if (!strcmp (cname, config)) { g_free (config); properties.selected_config = i; break; } g_free (config); } g_free (cname); properties.safe_moves = g_settings_get_boolean (settings, KEY_SAFE_MOVES); properties.super_safe_moves = g_settings_get_boolean (settings, KEY_SUPER_SAFE_MOVES); properties.sound = g_settings_get_boolean (settings, KEY_ENABLE_SOUND); properties.show_toolbar = g_settings_get_boolean (settings, KEY_SHOW_TOOLBAR); load_game_graphics (); set_game_config (properties.selected_config); keyboard_set (properties.keys); return TRUE; }
/** * fill_typemenu * @menu: listbox menu * * Description: * fills the listbox with configuration names **/ static void fill_typemenu (GtkWidget * menu) { gint i; #if 0 /* this is just a place holder so that xgettext can found the strings to * translate (those are the default games types) */ char *just_a_place_holder[] = { N_("classic robots"), N_("robots2"), N_("robots2 easy"), N_("robots with safe teleport"), N_("nightmare") }; #endif for (i = 0; i < num_game_configs (); ++i) { gtk_combo_box_append_text (GTK_COMBO_BOX (menu), _(game_config_name (i))); } gtk_combo_box_set_active (GTK_COMBO_BOX (menu), properties.selected_config); }
/** * main * @argc: number of arguments * @argv: arguments * * Description: * main * * Returns: * exit code **/ int main (int argc, char *argv[]) { GtkWidget *errordialog; GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe; GtkUIManager *ui_manager; GOptionContext *context; struct timeval tv; gint i; gchar *config; gboolean retval; GError *error = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); games_scores_startup (); gettimeofday (&tv, NULL); srand (tv.tv_usec); context = g_option_context_new (NULL); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); retval = g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (!retval) { g_print ("%s", error->message); g_error_free (error); exit (1); } g_set_application_name (_("Robots")); highscores = games_scores_new ("gnobots2", scorecats, G_N_ELEMENTS (scorecats), NULL, NULL, 0 /* default category */, GAMES_SCORES_STYLE_PLAIN_DESCENDING); settings = g_settings_new ("org.gnome.gnobots2"); gtk_window_set_default_icon_name ("gnobots2"); app = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (app), _("Robots")); g_signal_connect (GTK_WINDOW (app), "configure-event", G_CALLBACK (window_configure_event_cb), NULL); g_signal_connect (GTK_WINDOW (app), "window-state-event", G_CALLBACK (window_state_event_cb), NULL); gtk_window_set_default_size (GTK_WINDOW (app), g_settings_get_int (settings, "window-width"), g_settings_get_int (settings, "window-height")); if (g_settings_get_boolean (settings, "window-is-fullscreen")) gtk_window_fullscreen (GTK_WINDOW (app)); if (g_settings_get_boolean (settings, "window-is-maximized")) gtk_window_maximize (GTK_WINDOW (app)); g_signal_connect (G_OBJECT (app), "delete_event", G_CALLBACK (quit_game), NULL); statusbar = gnobots_statusbar_new (); ui_manager = gtk_ui_manager_new (); games_stock_prepare_for_statusbar_tooltips (ui_manager, statusbar); create_game_menus (ui_manager); gtk_window_add_accel_group (GTK_WINDOW (app), gtk_ui_manager_get_accel_group (ui_manager)); menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu"); toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar"); gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); make_cursors (); game_area = gtk_drawing_area_new (); gtk_widget_add_events (game_area, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); g_signal_connect (G_OBJECT (game_area), "button-press-event", G_CALLBACK (mouse_cb), NULL); g_signal_connect (G_OBJECT (game_area), "motion-notify-event", G_CALLBACK (move_cb), NULL); g_signal_connect (G_OBJECT (game_area), "configure-event", G_CALLBACK (resize_cb), NULL); g_signal_connect (G_OBJECT (game_area), "draw", G_CALLBACK (draw_cb), NULL); gridframe = games_grid_frame_new (GAME_WIDTH, GAME_HEIGHT); gtk_container_add (GTK_CONTAINER (gridframe), game_area); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), gridframe, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (app), vbox); gtk_widget_set_size_request (GTK_WIDGET (game_area), MINIMUM_TILE_WIDTH * GAME_WIDTH, MINIMUM_TILE_HEIGHT * GAME_HEIGHT); /* Set the window position if it was set by the session manager */ if (session_xpos >= 0 && session_ypos >= 0) { gtk_window_move (GTK_WINDOW (app), session_xpos, session_ypos); } gtk_widget_show_all (app); if (!load_game_configs ()) { /* Oops, no configs, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _("No game data could be found."), _ ("The program Robots was unable to find any valid game configuration files. Please check that the program is installed correctly.")); gtk_window_set_resizable (GTK_WINDOW (errordialog), FALSE); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } load_properties (); if (!load_game_graphics ()) { /* Oops, no graphics, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _ ("Some graphics files are missing or corrupt."), _ ("The program Robots was unable to load all the necessary graphics files. Please check that the program is installed correctly.")); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } connect_toolbar_toggle (toolbar); init_sound (); init_game (); if (cmdline_scenario) { set_game_graphics (cmdline_scenario); } if (cmdline_config) { for (i = 0; i < num_game_configs (); ++i) { config = game_config_name (i); if (!strcmp (cmdline_config, config)) { properties_set_config (i); g_free (config); break; } g_free (config); } } gtk_main (); g_settings_sync(); return 0; }