Qt: new game vs saved game selection

If player got Qt's saved game selection widget at startup but
picked "new game" there, the save file for the last character
in the list of saved games would be clobbered with the new
character's game if a save was performed.  It wasn't necessarily
easy to spot because saved game selection shows the character
name from inside the file rather than from the file name, so the
next restore would look normal except for one older character
missing.

Noticed while testing:  when you used the character selection
widget (either by picking "new game" in saved game selection or
because there aren't any save files), if you blanked out the
name field or it was already blanked because a generic name like
"player" had been specified, then clicked on "play", the program
would get stuck in a loop somewhere.  I didn't try to figure out
where, just changed qt_askname() to revert to original name if
it ended up with a blank one.
This commit is contained in:
PatR
2020-10-27 15:10:22 -07:00
parent 14ec98a241
commit 70e4f5b197
3 changed files with 34 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.343 $ $NHDT-Date: 1603777052 2020/10/27 05:37:32 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.344 $ $NHDT-Date: 1603836614 2020/10/27 22:10:14 $
General Fixes and Modified Features
-----------------------------------
@@ -462,6 +462,10 @@ Qt: handle '&' properly if it occurs as part of yn_function popup dialog
Qt: fix the display side of saved game selection; character names for
available save files are shown in a column of push buttons instead
of each button overwriting all the ones before it
Qt: don't clobber an existing save file after choosing "new game" in the
saved game selection widget
Qt: don't get stuck in a loop after choosing "play" while the character name
field is empty in the character selection widget
Qt+OSX: fix control key
Qt+OSX: rename menu entry "nethack->Preferences..." for invoking nethack's
'O' command to "Game->Run-time options" and entry "Game->Qt settings"

View File

@@ -44,15 +44,6 @@ On the map, ^V is a dead key (at least on OSX; all other ASCII control
characters from ^A through ^U, ^W through ^Z, and ^[, ^\, ^], ^^, ^_
work; no attempt to have ^@ generate NUL has been made).
The save file selection widget writes all the file name selection
buttons on top of each other, with the last one added being the only
one visible. Clicking on it seems to be picking the first one instead.
If you pick "new game" and use a different character name then
eventually save, it clobbers the last one in the list (rather, warns
the player that a save file exists and asks whether to overwrite it;
answering yes and then loading the file shows the new character, not
the original one even though the file is still named for that one).
Map column #0, which the core reserves for its own purposes and isn't
intended to be displayed, is displayed (as blank terrain).

View File

@@ -185,38 +185,57 @@ void NetHackQtBind::qt_player_selection()
void NetHackQtBind::qt_askname()
{
have_asked = true;
char default_plname[PL_NSIZ];
// We do it all here, and nothing in askname
have_asked = true;
str_copy(default_plname, g.plname, PL_NSIZ);
// 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;
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));
// 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);
switch (ch) {
case -1:
// New Game
if (splash)
splash->hide();
if (NetHackQtPlayerSelector(keybuffer).Choose())
return;
if (NetHackQtPlayerSelector(keybuffer).Choose()) {
// success; handle plname[] verification below prior to returning
break;
}
/*FALLTHRU*/
case -2:
// Quit
clearlocks();
qt_exit_nhwindows(0);
nh_terminate(0);
/*NOTREACHED*/
break;
default:
return;
// picked a character from the saved games list
break;
}
// Quit
clearlocks();
qt_exit_nhwindows(0);
nh_terminate(0);
if (!*g.plname)
// in case Choose() returns with plname[] empty
Strcpy(g.plname, default_plname);
else if (strcmp(g.plname, default_plname) != 0)
// caller needs to set new lock file name
::iflags.renameinprogress = TRUE;
return;
}
void NetHackQtBind::qt_get_nh_event()