Gnome player selection

- provide full 3.4-style player selection, based on tty_player_selection
- generalize selection dialog so it can be used for all 4 prompts
This commit is contained in:
cohrs
2002-03-19 08:27:55 +00:00
parent 49d84cffdb
commit bdfcd6915e
3 changed files with 231 additions and 60 deletions
+23 -21
View File
@@ -2,10 +2,10 @@
/* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
/* NetHack may be freely redistributed. See license for details. */
#include "gnplayer.h"
#include "gnmain.h"
#include <gnome.h>
#include <ctype.h>
#include "gnplayer.h"
#include "gnmain.h"
#include "hack.h"
static gint role_number;
@@ -13,15 +13,15 @@ static GtkWidget* clist;
static void
player_sel_key_hit (GtkWidget *widget, GdkEventKey *event, gpointer data)
{
const char** roles = data;
int i;
for (i = 0; roles[i] != 0; ++i) {
if (roles[i][0] == toupper(event->keyval)) {
role_number = i;
gtk_clist_select_row( GTK_CLIST (clist), i, 0);
}
}
{
const char** roles = data;
int i;
for (i = 0; roles[i] != 0; ++i) {
if (roles[i][0] == toupper(event->keyval)) {
role_number = i;
gtk_clist_select_row( GTK_CLIST (clist), i, 0);
}
}
}
static void
@@ -31,23 +31,25 @@ player_sel_row_selected (GtkCList *clist, int row, int col, GdkEvent *event)
}
int
ghack_player_sel_dialog( const char** roles)
ghack_player_sel_dialog(const char** choices,
const gchar* title,
const gchar* prompt)
{
int i;
static GtkWidget* dialog;
static GtkWidget* swin;
static GtkWidget* frame1;
dialog = gnome_dialog_new (_("Player selection"),
dialog = gnome_dialog_new(title,
GNOME_STOCK_BUTTON_OK,
_("Random role"),
_("Random"),
GNOME_STOCK_BUTTON_CANCEL,
NULL);
gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE);
gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
GTK_SIGNAL_FUNC (player_sel_key_hit), roles );
GTK_SIGNAL_FUNC (player_sel_key_hit), choices );
frame1 = gtk_frame_new (_("Choose one of the following roles:"));
frame1 = gtk_frame_new(prompt);
gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1);
gtk_widget_show (frame1);
gtk_container_border_width (GTK_CONTAINER (frame1), 3);
@@ -67,10 +69,10 @@ ghack_player_sel_dialog( const char** roles)
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1);
/* Add the roles into the list here... */
for (i=0; roles[i]; i++) {
for (i=0; choices[i]; i++) {
gchar accelBuf[BUFSZ];
const char *text[3]={accelBuf, roles[i],NULL};
sprintf( accelBuf, "%c ", tolower(roles[i][0]));
const char *text[3]={accelBuf, choices[i],NULL};
sprintf( accelBuf, "%c ", tolower(choices[i][0]));
gtk_clist_insert (GTK_CLIST (clist), i, (char**)text);
}
@@ -89,11 +91,11 @@ ghack_player_sel_dialog( const char** roles)
/* Quit on button 2 or error */
if (i < 0 || i > 1) {
return( -1);
return(ROLE_NONE);
}
/* Random is button 1*/
if (i == 1 ) {
return( -2);
return(ROLE_RANDOM);
}
return ( role_number);
}