]> granicus.if.org Git - nethack/commitdiff
SELECTSAVED handling
authorPatR <rankin@nethack.org>
Sat, 23 Jan 2021 23:02:11 +0000 (15:02 -0800)
committerPatR <rankin@nethack.org>
Sat, 23 Jan 2021 23:02:11 +0000 (15:02 -0800)
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.

include/config.h
include/extern.h
include/ntconf.h
src/files.c
win/Qt/qt_bind.cpp
win/Qt/qt_svsel.cpp

index 9aa89d5c7b6bb3cc1a5c4c8323368367b2642961..2abb503bc3b4c0921cccc3d1236bf30994efd594 100644 (file)
@@ -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 */
index 931d5b792394da74cf79899f1ae14b253a571090..8df78d7207d4c740412d84c3d3c052066b263e2c 100644 (file)
@@ -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);
index 711c839149ca7a00421141d69b08711a4af1c3db..67e6753982dc3c3e4124259b55ae6ae471eb45ba 100644 (file)
@@ -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' */
 
index a8c9b39be7e72437c84ab9475b155b0cccea7d20..5f85fc3d8d27a671100861caa48d023e6c6e8716 100644 (file)
@@ -42,7 +42,7 @@ const
 #endif
 #endif
 
-#if defined(UNIX) && defined(QT_GRAPHICS)
+#if defined(UNIX) && defined(SELECTSAVED)
 #include <sys/types.h>
 #include <dirent.h>
 #include <stdlib.h>
@@ -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;
index 78c5df7ce1a6ecb7dc8642d73238dabb499d8127..96b308f90965d06d09315693836c1189c4bbce78 100644 (file)
@@ -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
index 219fa7d5b30497102768bacc5288af27ad96d665..a36d6eb446174eb1cfc77b61db789f3eddcb54d7 100644 (file)
 //  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"