From: PatR Date: Sat, 23 Jan 2021 23:02:11 +0000 (-0800) Subject: SELECTSAVED handling X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab74ed2c2020a567e950e36fb7ecade6a6cf19e6;p=nethack 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. --- diff --git a/include/config.h b/include/config.h index 9aa89d5c7..2abb503bc 100644 --- a/include/config.h +++ b/include/config.h @@ -496,6 +496,25 @@ typedef unsigned char uchar; * 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 * 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 */ /* #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 WINCHAIN */ /* stacked window systems */ diff --git a/include/extern.h b/include/extern.h index 931d5b792..8df78d720 100644 --- a/include/extern.h +++ b/include/extern.h @@ -804,7 +804,7 @@ E int FDECL(parse_sym_line, (char *, int)); E void FDECL(paniclog, (const char *, const char *)); E void FDECL(testinglog, (const char *, const char *, const 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 *)); #endif E char **NDECL(get_saved_games); diff --git a/include/ntconf.h b/include/ntconf.h index 711c83914..67e675398 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -32,7 +32,6 @@ #define TTY_SOUND_ESCCODES /*#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' */ diff --git a/src/files.c b/src/files.c index a8c9b39be..5f85fc3d8 100644 --- a/src/files.c +++ b/src/files.c @@ -42,7 +42,7 @@ const #endif #endif -#if defined(UNIX) && defined(QT_GRAPHICS) +#if defined(UNIX) && defined(SELECTSAVED) #include #include #include @@ -123,12 +123,6 @@ extern char *FDECL(translate_path_variables, (const char *, char *)); extern char *sounddir; /* defined in sounds.c */ #endif -#if defined(UNIX) && defined(QT_GRAPHICS) -#ifndef SELECTSAVED -#define SELECTSAVED -#endif -#endif - static NHFILE *NDECL(new_nhfile); static void FDECL(free_nhfile, (NHFILE *)); #ifdef SELECTSAVED @@ -1275,7 +1269,7 @@ get_saved_games() } #endif -#if defined(UNIX) && defined(QT_GRAPHICS) +#ifdef UNIX /* posixly correct version */ int myuid = getuid(); DIR *dir; diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index 78c5df7ce..96b308f90 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -191,6 +191,7 @@ void NetHackQtBind::qt_player_selection() void NetHackQtBind::qt_askname() { char default_plname[PL_NSIZ]; + int ch = -1; // -1 => new game have_asked = true; 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), // nothing in player_selection(). - char** saved = get_saved_games(); - int ch = -1; // -1 => new game - if ( saved && *saved ) { - if ( splash ) splash->hide(); - NetHackQtSavedGameSelector sgsel((const char**)saved); - ch = sgsel.choose(); - if ( ch >= 0 ) - str_copy(g.plname, saved[ch], SIZE(g.plname)); +#ifdef SELECTSAVED + char **saved = 0; + if (::iflags.wc2_selectsaved) + saved = get_saved_games(); + if (saved && *saved) { + if (splash) + splash->hide(); + NetHackQtSavedGameSelector sgsel((const char **) saved); + ch = sgsel.choose(); + if (ch >= 0) + str_copy(g.plname, saved[ch], SIZE(g.plname)); // caller needs new lock name even if plname[] hasn't changed // because successful get_saved_games() clobbers g.SAVEF[] ::iflags.renameinprogress = TRUE; } free_saved_games(saved); +#endif switch (ch) { case -1: @@ -981,7 +986,11 @@ struct window_procs Qt_procs = { | WC_ASCII_MAP | WC_TILED_MAP | WC_FONT_MAP | WC_TILE_FILE | WC_TILE_WIDTH | WC_TILE_HEIGHT | 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 */ nethack_qt_::NetHackQtBind::qt_init_nhwindows, 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_end_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_mark_synch, nethack_qt_::NetHackQtBind::qt_wait_synch, @@ -1053,16 +1062,15 @@ struct window_procs Qt_procs = { }; #ifndef WIN32 -#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND) -extern "C" void play_usersound(const char* filename, int volume UNUSED) -#else -extern "C" void play_usersound(const char* filename UNUSED, int volume UNUSED) -#endif +extern "C" void +play_usersound(const char *filename, int volume UNUSED) { -#ifdef USER_SOUNDS -#ifndef QT_NO_SOUND +#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND) QSound::play(filename); -#endif +#else + nhUse(filename); #endif } -#endif +#endif /*!WIN32*/ + +//qt_bind.cpp diff --git a/win/Qt/qt_svsel.cpp b/win/Qt/qt_svsel.cpp index 219fa7d5b..a36d6eb44 100644 --- a/win/Qt/qt_svsel.cpp +++ b/win/Qt/qt_svsel.cpp @@ -31,6 +31,12 @@ // enchancement: instead of just showing the character name, show // "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" { #include "hack.h"