Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a dialog window when saving a game or recording #638

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/brogue/IO.c
Original file line number Diff line number Diff line change
Expand Up @@ -2739,16 +2739,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;
screenDisplayBuffer 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;
Expand Down Expand Up @@ -2807,8 +2814,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++;
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/brogue/Recordings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -1212,11 +1213,10 @@ void saveGame() {
getAvailableFilePath(filePathWithoutSuffix, defaultPath, GAME_SUFFIX);
filePath[0] = '\0';

deleteMessages();
do {
askAgain = false;
if (getInputTextString(filePathWithoutSuffix, "Save game as (<esc> 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)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: personally I like the prompt matching the UI of the messages on the post-game screen (I put effort in the past to preserve this), is there any functionality downside to leaving this one false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure what you mean by the "prompt matching the UI of the messages".

the genesis of this change is from the feats/achievements rework (which is pretty much done). i'll try to recall my thinking as it relates to the save dialog. in my current implementation, feats have a score value, so that required shifting the list of achievements to the left. that resulted in the save dialog looking out of place but getInputTextString doesn't allow for granular placement of the prompt. also, i wasn't sure how many feats might need to be displayed so i thought it might be better to move the save to a new screen entirely.

it might be worth doing a quick discord call to talk through (with screen share).

snprintf(filePath, BROGUE_FILENAME_MAX, "%s%s", filePathWithoutSuffix, GAME_SUFFIX);
if (!fileExists(filePath) || confirm("File of that name already exists. Overwrite?", true)) {
remove(filePath);
Expand All @@ -1232,7 +1232,6 @@ void saveGame() {
}
}
} while (askAgain);
displayRecentMessages();
}

void saveRecordingNoPrompt(char *filePath) {
Expand Down Expand Up @@ -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 (<esc> 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)) {
Expand All @@ -1283,7 +1281,6 @@ void saveRecording(char *filePathWithoutSuffix) {
rogue.recording = false;
}
} while (askAgain);
deleteMessages();
}

static void copyFile(char *fromFilePath, char *toFilePath, unsigned long fromFileLength) {
Expand Down
2 changes: 1 addition & 1 deletion src/brogue/Rogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,7 @@ extern "C" {
boolean getInputTextString(char *inputText,
const char *prompt,
short maxLength,
const char *defaultEntry,
char *defaultEntry,
const char *promptSuffix,
short textEntryType,
boolean useDialogBox);
Expand Down
5 changes: 3 additions & 2 deletions src/brogue/RogueMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,11 +1323,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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so when we get a "supervictory" (mastery) does it snap to black and show dialog? oh wait it fades back to black beforehand doesn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wasn't sure so i just checked in wizard mode. it's a "snap", not a fade. so the achievements screen gets blacked out, the the save dialog is presented, then the high scores, and then back to the title menu.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I just tested this. I misunderstood what was going on - this new version is a-ok

saveRecording(recordingFilename);
printHighScores(qualified);
}
Expand Down