I'll push a formatting guide at some point. There may still be outstanding changes, but please feel free to resolve those as you arrive a them. To the best of my knowledge, there is no changes to the actual code content, but the formatter does have the occasional bug. If you run into an issue, please fix it!
73 lines
2.6 KiB
C
73 lines
2.6 KiB
C
/* NetHack 3.6 gnyesno.c $NHDT-Date: 1431192773 2015/05/09 17:32:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
|
|
/* NetHack 3.6 gnyesno.c $Date: 2009/05/06 10:58:06 $ $Revision: 1.4 $ */
|
|
/* SCCS Id: @(#)gnyesno.c 3.5 2000/07/16 */
|
|
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
|
|
/* NetHack may be freely redistributed. See license for details. */
|
|
|
|
#include "gnbind.h"
|
|
#include "gnyesno.h"
|
|
|
|
int
|
|
ghack_yes_no_dialog(const char *question, const char *choices, int def)
|
|
{
|
|
int i = 0, ret;
|
|
gchar button_name[BUFSZ];
|
|
GtkWidget *box;
|
|
GtkWidget *mainWnd = NULL;
|
|
|
|
box = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION, NULL);
|
|
/* add buttons for each choice */
|
|
if (!strcmp(GNOME_STOCK_BUTTON_OK, choices)) {
|
|
gnome_dialog_append_button(GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK);
|
|
gnome_dialog_set_default(GNOME_DIALOG(box), 0);
|
|
gnome_dialog_set_accelerator(GNOME_DIALOG(box), 0, 'o', 0);
|
|
#if 0
|
|
g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
|
|
#endif
|
|
} else {
|
|
for (; choices[i] != '\0'; i++) {
|
|
if (choices[i] == 'y') {
|
|
sprintf(button_name, GNOME_STOCK_BUTTON_YES);
|
|
} else if (choices[i] == 'n') {
|
|
sprintf(button_name, GNOME_STOCK_BUTTON_NO);
|
|
} else if (choices[i] == 'q') {
|
|
sprintf(button_name, "Quit");
|
|
} else {
|
|
sprintf(button_name, "%c", choices[i]);
|
|
}
|
|
if (def == choices[i])
|
|
gnome_dialog_set_default(GNOME_DIALOG(box), i);
|
|
gnome_dialog_append_button(GNOME_DIALOG(box), button_name);
|
|
gnome_dialog_set_accelerator(GNOME_DIALOG(box), i, choices[i], 0);
|
|
#if 0
|
|
g_print("Setting accelerator '%c' for button %d\n", choices[i], i);
|
|
#endif
|
|
}
|
|
}
|
|
#if 0
|
|
/* Perhaps add in a quit game button, like this... */
|
|
gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_CLOSE);
|
|
gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
|
|
g_print("Setting accelerator '%c' for button %d\n", 'Q', i);
|
|
#endif
|
|
|
|
gnome_dialog_set_close(GNOME_DIALOG(box), TRUE);
|
|
mainWnd = ghack_get_main_window();
|
|
gtk_window_set_modal(GTK_WINDOW(box), TRUE);
|
|
gtk_window_set_title(GTK_WINDOW(box), "GnomeHack");
|
|
if (mainWnd != NULL) {
|
|
gnome_dialog_set_parent(GNOME_DIALOG(box), GTK_WINDOW(mainWnd));
|
|
}
|
|
|
|
ret = gnome_dialog_run_and_close(GNOME_DIALOG(box));
|
|
|
|
#if 0
|
|
g_print("You selected button %d\n", ret);
|
|
#endif
|
|
|
|
if (ret == -1)
|
|
return ('\033');
|
|
else
|
|
return (choices[ret]);
|
|
}
|