void gnibbles_show_scores (GtkWidget * window, gint pos) { static GtkWidget *scoresdialog = NULL; gchar *message; if (!scoresdialog) { scoresdialog = games_scores_dialog_new (GTK_WINDOW (window), highscores, _("Nibbles Scores")); games_scores_dialog_set_category_description (GAMES_SCORES_DIALOG (scoresdialog), _("Speed:")); } if (pos > 0) { games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (scoresdialog), pos); message = g_strdup_printf ("<b>%s</b>\n\n%s", _("Congratulations!"), pos == 1 ? _("Your score is the best!") : _("Your score has made the top ten.")); games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog), message); g_free (message); } else { games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog), NULL); } gtk_dialog_run (GTK_DIALOG (scoresdialog)); gtk_widget_hide (scoresdialog); }
static void CheerWinner (void) { int winner; int i; gint pos; gchar *message; ShowoffPlayer (ScoreList, CurrentPlayer, 0); winner = FindWinner (); /* draw. The score is returned as a negative value */ if (winner < 0) { for (i = 0; i < NumberOfPlayers; i++) { if (total_score (i) == -winner) { ShowoffPlayer (ScoreList, i, 1); } } say (_("The game is a draw!")); return; } ShowoffPlayer (ScoreList, winner, 1); if (winner < NumberOfHumans) { pos = games_scores_add_plain_score (highscores, (guint32) WinningScore); if (pos > 0) { games_scores_update_score (highscores, players[winner].name); if (dialog) { gtk_window_present (GTK_WINDOW (dialog)); } else { dialog = games_scores_dialog_new (GTK_WINDOW (window), highscores, _("Tali Scores")); message = g_strdup_printf ("<b>%s</b>\n\n%s", _("Congratulations!"), pos == 1 ? _("Your score is the best!") : _("Your score has made the top ten.")); games_scores_dialog_set_message (GAMES_SCORES_DIALOG (dialog), message); g_free (message); } games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (dialog), pos); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_hide (dialog); } } if (players[winner].name) say (ngettext ("%s wins the game with %d point", "%s wins the game with %d points", WinningScore), players[winner].name, WinningScore); else say (_("Game over!")); }
static void games_scores_dialog_finalize (GObject *o) { GamesScoresDialog *dialog = GAMES_SCORES_DIALOG (o); if (dialog->priv->scores) g_object_unref (dialog->priv->scores); if (dialog->priv->categories) g_hash_table_destroy (dialog->priv->categories); if (dialog->priv->catindices) g_hash_table_destroy (dialog->priv->catindices); G_OBJECT_CLASS (games_scores_dialog_parent_class)->finalize (o); }
/** * new: * @domain: the scores domain to use, usually the application name * @title: the title for the dialog * * Creates a new high scores dialog. Use gtk_dialog_run and * gtk_widget_destroy to manage it. * * Returns: a new widget * **/ GtkWidget * games_scores_dialog_new (GtkWindow *parent_window, GamesScores *scores, const gchar *title) { GamesScoresDialog *dialog = GAMES_SCORES_DIALOG (g_object_new (GAMES_TYPE_SCORES_DIALOG, NULL)); dialog->priv->scores = g_object_ref (scores); games_scores_dialog_set_style (dialog, games_scores_get_style (scores)); dialog->priv->preservehilight = FALSE; gtk_window_set_title (GTK_WINDOW (dialog), title); gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent_window)); _games_scores_category_foreach (scores, (GamesScoresCategoryForeachFunc) games_scores_dialog_load_categories, dialog); if (dialog->priv->catcounter <= 1) { gtk_widget_hide (dialog->priv->catbar); } return (GtkWidget *)dialog; }