diff --git a/src/brogue/IO.c b/src/brogue/IO.c index 2e7ada8d..65cb5965 100644 --- a/src/brogue/IO.c +++ b/src/brogue/IO.c @@ -2726,16 +2726,23 @@ void executeKeystroke(signed long keystroke, boolean controlKey, boolean shiftKe boolean getInputTextString(char *inputText, const char *prompt, short maxLength, - const char *defaultEntry, + char *defaultEntry, const char *promptSuffix, short textEntryType, boolean useDialogBox) { - short charNum, i, x, y; + short charNum, i, x, y, promptSuffixLen, defaultEntrylengthOverflow; char keystroke, suffix[100]; const short textEntryBounds[TEXT_INPUT_TYPES][2] = {{' ', '~'}, {' ', '~'}, {'0', '9'}}; screenDisplayBuffer dbuf; SavedDisplayBuffer rbuf; + // handle defaultEntry values exceeding maxLength + promptSuffixLen = strlen(promptSuffix); + defaultEntrylengthOverflow = strlen(defaultEntry) + promptSuffixLen - maxLength; + if(defaultEntrylengthOverflow > 0) { + defaultEntry[strlen(defaultEntry) - defaultEntrylengthOverflow] = '\0'; + } + // x and y mark the origin for text entry. if (useDialogBox) { x = (COLS - max(maxLength, strLenWithoutEscapes(prompt))) / 2; @@ -2795,8 +2802,8 @@ boolean getInputTextString(char *inputText, inputText[charNum] = keystroke; plotCharWithColor(keystroke, (windowpos){ x + charNum, y }, &white, &black); - printString(suffix, charNum + x + 1, y, &gray, &black, 0); - if (charNum < maxLength) { + if (charNum < maxLength - promptSuffixLen) { + printString(suffix, charNum + x + 1, y, &gray, &black, 0); charNum++; } } diff --git a/src/brogue/Recordings.c b/src/brogue/Recordings.c index bfa4569d..a63306dc 100644 --- a/src/brogue/Recordings.c +++ b/src/brogue/Recordings.c @@ -1199,6 +1199,7 @@ void saveGameNoPrompt() { rogue.gameExitStatusCode = EXIT_STATUS_SUCCESS; rogue.recording = false; } +#define MAX_TEXT_INPUT_FILENAME_LENGTH (COLS - 12) // max length including the suffix void saveGame() { char filePathWithoutSuffix[BROGUE_FILENAME_MAX - sizeof(GAME_SUFFIX)], filePath[BROGUE_FILENAME_MAX], defaultPath[BROGUE_FILENAME_MAX]; @@ -1212,11 +1213,10 @@ void saveGame() { getAvailableFilePath(filePathWithoutSuffix, defaultPath, GAME_SUFFIX); filePath[0] = '\0'; - deleteMessages(); do { askAgain = false; if (getInputTextString(filePathWithoutSuffix, "Save game as ( to cancel): ", - BROGUE_FILENAME_MAX - strlen(GAME_SUFFIX), filePathWithoutSuffix, GAME_SUFFIX, TEXT_INPUT_FILENAME, false)) { + MAX_TEXT_INPUT_FILENAME_LENGTH, filePathWithoutSuffix, GAME_SUFFIX, TEXT_INPUT_FILENAME, true)) { snprintf(filePath, BROGUE_FILENAME_MAX, "%s%s", filePathWithoutSuffix, GAME_SUFFIX); if (!fileExists(filePath) || confirm("File of that name already exists. Overwrite?", true)) { remove(filePath); @@ -1232,7 +1232,6 @@ void saveGame() { } } } while (askAgain); - displayRecentMessages(); } void saveRecordingNoPrompt(char *filePath) { @@ -1260,11 +1259,10 @@ void saveRecording(char *filePathWithoutSuffix) { getAvailableFilePath(filePathWithoutSuffix, defaultPath, RECORDING_SUFFIX); filePath[0] = '\0'; - deleteMessages(); do { askAgain = false; if (getInputTextString(filePathWithoutSuffix, "Save recording as ( to cancel): ", - BROGUE_FILENAME_MAX - strlen(RECORDING_SUFFIX), filePathWithoutSuffix, RECORDING_SUFFIX, TEXT_INPUT_FILENAME, false)) { + MAX_TEXT_INPUT_FILENAME_LENGTH, filePathWithoutSuffix, RECORDING_SUFFIX, TEXT_INPUT_FILENAME, true)) { snprintf(filePath, BROGUE_FILENAME_MAX, "%s%s", filePathWithoutSuffix, RECORDING_SUFFIX); if (!fileExists(filePath) || confirm("File of that name already exists. Overwrite?", true)) { @@ -1283,7 +1281,6 @@ void saveRecording(char *filePathWithoutSuffix) { rogue.recording = false; } } while (askAgain); - deleteMessages(); } static void copyFile(char *fromFilePath, char *toFilePath, unsigned long fromFileLength) { diff --git a/src/brogue/Rogue.h b/src/brogue/Rogue.h index 7c880abd..d9921111 100644 --- a/src/brogue/Rogue.h +++ b/src/brogue/Rogue.h @@ -2985,7 +2985,7 @@ extern "C" { boolean getInputTextString(char *inputText, const char *prompt, short maxLength, - const char *defaultEntry, + char *defaultEntry, const char *promptSuffix, short textEntryType, boolean useDialogBox); diff --git a/src/brogue/RogueMain.c b/src/brogue/RogueMain.c index e3b322cf..e4daf90e 100644 --- a/src/brogue/RogueMain.c +++ b/src/brogue/RogueMain.c @@ -1324,11 +1324,12 @@ void victory(boolean superVictory) { rogue.playbackMode = false; rogue.playbackMode = isPlayback; + displayMoreSign(); + if (serverMode) { - // There's no save recording prompt, so let the player see achievements. - displayMoreSign(); saveRecordingNoPrompt(recordingFilename); } else { + blackOutScreen(); saveRecording(recordingFilename); printHighScores(qualified); }