SELECTSAVED handling

By default, enable the SELECTSAVED option for everyone instead
of just for Windows or Qt.  And make Qt obey the 'selectsaved'
run-time option.

It can be disabled in config.h if necessary.
This commit is contained in:
PatR
2021-01-23 15:02:11 -08:00
parent a1eb06b462
commit ab74ed2c20
6 changed files with 57 additions and 29 deletions
+21
View File
@@ -496,6 +496,25 @@ typedef unsigned char uchar;
* bugs left here. * bugs left here.
*/ */
/* SELECTSAVED: Enable the 'selectsaved' run-time option, allowing it
* to be set in user's config file or NETHACKOPTIONS. When set, if
* player is about to be given the "who are you?" prompt, check for
* save files and if any are found, put up a menu of them for choosing
* one to restore (plus extra menu entries "new game" and "quit").
*
* Not useful if players are forced to use a specific character name
* such as their user name. However in some cases, players can set
* their character name to one which is classified as generic in the
* sysconf file (such as "player" or "games")
* nethack -u player
* to force the "who are you?" prompt in which case 'selectsaved' will
* be honored.
*
* Comment out if the wildcard file name lookup in files.c doesn't
* compile or doesn't work as intended.
*/
#define SELECTSAVED /* support for restoring via menu */
/* TTY_TILES_ESCCODES: Enable output of special console escape codes /* TTY_TILES_ESCCODES: Enable output of special console escape codes
* which act as hints for external programs such as EbonHack, or hterm. * which act as hints for external programs such as EbonHack, or hterm.
* *
@@ -535,6 +554,8 @@ typedef unsigned char uchar;
* Only available with POSIX_TYPES or GNU C */ * Only available with POSIX_TYPES or GNU C */
/* #define MSGHANDLER */ /* #define MSGHANDLER */
/* enable status highlighting via STATUS_HILITE directives in run-time
config file and the 'statushilites' option */
#define STATUS_HILITES /* support hilites of status fields */ #define STATUS_HILITES /* support hilites of status fields */
/* #define WINCHAIN */ /* stacked window systems */ /* #define WINCHAIN */ /* stacked window systems */
+1 -1
View File
@@ -804,7 +804,7 @@ E int FDECL(parse_sym_line, (char *, int));
E void FDECL(paniclog, (const char *, const char *)); E void FDECL(paniclog, (const char *, const char *));
E void FDECL(testinglog, (const char *, const char *, const char *)); E void FDECL(testinglog, (const char *, const char *, const char *));
E int FDECL(validate_prefix_locations, (char *)); E int FDECL(validate_prefix_locations, (char *));
#if defined(SELECTSAVED) || (defined(UNIX) && defined(QT_GRAPHICS)) #ifdef SELECTSAVED
E char *FDECL(plname_from_file, (const char *)); E char *FDECL(plname_from_file, (const char *));
#endif #endif
E char **NDECL(get_saved_games); E char **NDECL(get_saved_games);
-1
View File
@@ -32,7 +32,6 @@
#define TTY_SOUND_ESCCODES #define TTY_SOUND_ESCCODES
/*#define CHANGE_COLOR*/ /* allow palette changes */ /*#define CHANGE_COLOR*/ /* allow palette changes */
#define SELECTSAVED /* Provide menu of saved games to choose from at start */
#define QWERTZ_SUPPORT /* when swap_yz is True, numpad 7 is 'z' not 'y' */ #define QWERTZ_SUPPORT /* when swap_yz is True, numpad 7 is 'z' not 'y' */
+2 -8
View File
@@ -42,7 +42,7 @@ const
#endif #endif
#endif #endif
#if defined(UNIX) && defined(QT_GRAPHICS) #if defined(UNIX) && defined(SELECTSAVED)
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <stdlib.h> #include <stdlib.h>
@@ -123,12 +123,6 @@ extern char *FDECL(translate_path_variables, (const char *, char *));
extern char *sounddir; /* defined in sounds.c */ extern char *sounddir; /* defined in sounds.c */
#endif #endif
#if defined(UNIX) && defined(QT_GRAPHICS)
#ifndef SELECTSAVED
#define SELECTSAVED
#endif
#endif
static NHFILE *NDECL(new_nhfile); static NHFILE *NDECL(new_nhfile);
static void FDECL(free_nhfile, (NHFILE *)); static void FDECL(free_nhfile, (NHFILE *));
#ifdef SELECTSAVED #ifdef SELECTSAVED
@@ -1275,7 +1269,7 @@ get_saved_games()
} }
#endif #endif
#if defined(UNIX) && defined(QT_GRAPHICS) #ifdef UNIX
/* posixly correct version */ /* posixly correct version */
int myuid = getuid(); int myuid = getuid();
DIR *dir; DIR *dir;
+25 -17
View File
@@ -191,6 +191,7 @@ void NetHackQtBind::qt_player_selection()
void NetHackQtBind::qt_askname() void NetHackQtBind::qt_askname()
{ {
char default_plname[PL_NSIZ]; char default_plname[PL_NSIZ];
int ch = -1; // -1 => new game
have_asked = true; have_asked = true;
str_copy(default_plname, g.plname, PL_NSIZ); str_copy(default_plname, g.plname, PL_NSIZ);
@@ -198,19 +199,23 @@ void NetHackQtBind::qt_askname()
// We do it all here (plus qt_plsel.cpp and qt_svsel.cpp), // We do it all here (plus qt_plsel.cpp and qt_svsel.cpp),
// nothing in player_selection(). // nothing in player_selection().
char** saved = get_saved_games(); #ifdef SELECTSAVED
int ch = -1; // -1 => new game char **saved = 0;
if ( saved && *saved ) { if (::iflags.wc2_selectsaved)
if ( splash ) splash->hide(); saved = get_saved_games();
NetHackQtSavedGameSelector sgsel((const char**)saved); if (saved && *saved) {
if (splash)
splash->hide();
NetHackQtSavedGameSelector sgsel((const char **) saved);
ch = sgsel.choose(); ch = sgsel.choose();
if ( ch >= 0 ) if (ch >= 0)
str_copy(g.plname, saved[ch], SIZE(g.plname)); str_copy(g.plname, saved[ch], SIZE(g.plname));
// caller needs new lock name even if plname[] hasn't changed // caller needs new lock name even if plname[] hasn't changed
// because successful get_saved_games() clobbers g.SAVEF[] // because successful get_saved_games() clobbers g.SAVEF[]
::iflags.renameinprogress = TRUE; ::iflags.renameinprogress = TRUE;
} }
free_saved_games(saved); free_saved_games(saved);
#endif
switch (ch) { switch (ch) {
case -1: case -1:
@@ -981,7 +986,11 @@ struct window_procs Qt_procs = {
| WC_ASCII_MAP | WC_TILED_MAP | WC_ASCII_MAP | WC_TILED_MAP
| WC_FONT_MAP | WC_TILE_FILE | WC_TILE_WIDTH | WC_TILE_HEIGHT | WC_FONT_MAP | WC_TILE_FILE | WC_TILE_WIDTH | WC_TILE_HEIGHT
| WC_POPUP_DIALOG | WC_PLAYER_SELECTION | WC_SPLASH_SCREEN), | WC_POPUP_DIALOG | WC_PLAYER_SELECTION | WC_SPLASH_SCREEN),
(WC2_HITPOINTBAR | WC2_STATUSLINES), (WC2_HITPOINTBAR
#ifdef SELECTSAVED
| WC2_SELECTSAVED
#endif
| WC2_STATUSLINES),
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */
nethack_qt_::NetHackQtBind::qt_init_nhwindows, nethack_qt_::NetHackQtBind::qt_init_nhwindows,
nethack_qt_::NetHackQtBind::qt_player_selection, nethack_qt_::NetHackQtBind::qt_player_selection,
@@ -1002,7 +1011,7 @@ struct window_procs Qt_procs = {
nethack_qt_::NetHackQtBind::qt_add_menu, nethack_qt_::NetHackQtBind::qt_add_menu,
nethack_qt_::NetHackQtBind::qt_end_menu, nethack_qt_::NetHackQtBind::qt_end_menu,
nethack_qt_::NetHackQtBind::qt_select_menu, nethack_qt_::NetHackQtBind::qt_select_menu,
genl_message_menu, /* no need for X-specific handling */ genl_message_menu, /* no need for Qt-specific handling */
nethack_qt_::NetHackQtBind::qt_update_inventory, nethack_qt_::NetHackQtBind::qt_update_inventory,
nethack_qt_::NetHackQtBind::qt_mark_synch, nethack_qt_::NetHackQtBind::qt_mark_synch,
nethack_qt_::NetHackQtBind::qt_wait_synch, nethack_qt_::NetHackQtBind::qt_wait_synch,
@@ -1053,16 +1062,15 @@ struct window_procs Qt_procs = {
}; };
#ifndef WIN32 #ifndef WIN32
#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND) extern "C" void
extern "C" void play_usersound(const char* filename, int volume UNUSED) play_usersound(const char *filename, int volume UNUSED)
#else
extern "C" void play_usersound(const char* filename UNUSED, int volume UNUSED)
#endif
{ {
#ifdef USER_SOUNDS #if defined(USER_SOUNDS) && !defined(QT_NO_SOUND)
#ifndef QT_NO_SOUND
QSound::play(filename); QSound::play(filename);
#endif #else
nhUse(filename);
#endif #endif
} }
#endif #endif /*!WIN32*/
//qt_bind.cpp
+6
View File
@@ -31,6 +31,12 @@
// enchancement: instead of just showing the character name, show // enchancement: instead of just showing the character name, show
// "name-role-race-gender-alignment". // "name-role-race-gender-alignment".
// //
// Note:
// The code in this file is not used if the program is built without
// having SELECTSAVED defined or if the run-time option 'selectsaved'
// is False. SELECTSAVED used to be forced for Qt but isn't any more.
// Howver, we include this code unconditionally.
//
extern "C" { extern "C" {
#include "hack.h" #include "hack.h"