-
Notifications
You must be signed in to change notification settings - Fork 125
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
Show date and time of savegame in Save/Load menu #1200
Changes from all commits
a52d427
3d71694
dab79ab
298f298
24bb661
23eb674
484613f
f44f1ef
d032b08
e40efb2
ffab5c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
#include <stdlib.h> | ||
#include <ctype.h> | ||
#include <time.h> // [crispy] strftime, localtime | ||
|
||
#include "deh_str.h" | ||
#include "doomdef.h" | ||
|
@@ -261,7 +262,7 @@ static MenuItem_t LoadItems[] = { | |
}; | ||
|
||
static Menu_t LoadMenu = { | ||
70, 27, | ||
70, 27-9, // [crispy] moved up, so two lines of save pages and file date will fit | ||
DrawLoadMenu, | ||
SAVES_PER_PAGE, LoadItems, | ||
0, | ||
|
@@ -278,7 +279,7 @@ static MenuItem_t SaveItems[] = { | |
}; | ||
|
||
static Menu_t SaveMenu = { | ||
70, 27, | ||
70, 27-9, // [crispy] moved up, so two lines of save pages and file date will fit | ||
DrawSaveMenu, | ||
SAVES_PER_PAGE, SaveItems, | ||
0, | ||
|
@@ -626,7 +627,7 @@ void MN_DrTextA(const char *text, int x, int y) | |
|
||
while ((c = *text++) != 0) | ||
{ | ||
if (c < 33) | ||
if (c < 33 || c > 91) // [crispy] fail-safe: draw patches above FONTA59 as spaces | ||
{ | ||
x += 5; | ||
} | ||
|
@@ -656,7 +657,7 @@ int MN_TextAWidth(const char *text) | |
width = 0; | ||
while ((c = *text++) != 0) | ||
{ | ||
if (c < 33) | ||
if (c < 33 || c > 91) // [crispy] fail-safe: consider patches above FONTA59 as spaces | ||
{ | ||
width += 5; | ||
} | ||
|
@@ -684,7 +685,7 @@ void MN_DrTextB(const char *text, int x, int y) | |
|
||
while ((c = *text++) != 0) | ||
{ | ||
if (c < 33) | ||
if (c < 33 || c > 90) // [crispy] fail-safe: draw patches above FONTB58 as spaces | ||
{ | ||
x += 8; | ||
} | ||
|
@@ -714,7 +715,7 @@ int MN_TextBWidth(const char *text) | |
width = 0; | ||
while ((c = *text++) != 0) | ||
{ | ||
if (c < 33) | ||
if (c < 33 || c > 90) // [crispy] fail-safe: consider patches above FONTB58 as spaces | ||
{ | ||
width += 5; | ||
} | ||
|
@@ -933,6 +934,25 @@ static void DrawSaveLoadBottomLine(const Menu_t *menu) | |
M_snprintf(pagestr, sizeof(pagestr), "PAGE %d/%d", savepage + 1, SAVEPAGE_MAX + 1); | ||
MN_DrTextA(pagestr, ORIGWIDTH / 2 - MN_TextAWidth(pagestr) / 2, y); | ||
|
||
// [crispy] print "modified" (or created initially) time of savegame file | ||
if (SlotStatus[CurrentItPos] && !FileMenuKeySteal) | ||
{ | ||
struct stat st; | ||
char filedate[32]; | ||
|
||
stat(SV_Filename(CurrentItPos), &st); | ||
// [FG] suppress the most useless compiler warning ever | ||
#if defined(__GNUC__) | ||
# pragma GCC diagnostic push | ||
# pragma GCC diagnostic ignored "-Wformat-y2k" | ||
#endif | ||
strftime(filedate, sizeof(filedate), "%x %X", localtime(&st.st_mtime)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woke up with a bad feeling, that it can be unsafe since Raven's font set doesn't have a backslash symbol, and attempt to draw non existing symbol is a direct path to program crash. But looks likes it is safe all around, none of existing date formats are using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could just fix font drawing to skip non-existent character patches. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat idea, even outside of this PR, this can potentially improve compatibility with custom texts. For small font drawing, it should be something like this: +++ crispy-doom/src/heretic/mn_menu.c Tue Apr 23 10:24:01 2024
@@ -631,6 +631,10 @@ void MN_DrTextA(const char *text, int x, int y)
{
x += 5;
}
+ else if (c > 91)
+ {
+ continue;
+ }
else
{
p = W_CacheLumpNum(FontABaseLump + c - 33, PU_CACHE);
Why exactly Hopefully. 🙂 At least this way I no longer have crashes by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Heretic's A-font does only have 59 characters, so everything after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡! True, patch drawing is guarded by following
Worth to do same trick with big font There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please. And I think it belongs into this bug report, because the time and date string is not under our control. |
||
#if defined(__GNUC__) | ||
# pragma GCC diagnostic pop | ||
#endif | ||
MN_DrTextA(filedate, ORIGWIDTH / 2 - MN_TextAWidth(pagestr), y + 10); | ||
} | ||
|
||
dp_translation = NULL; | ||
} | ||
|
||
|
@@ -948,12 +968,13 @@ static void DrawLoadMenu(void) | |
|
||
title = DEH_String("LOAD GAME"); | ||
|
||
MN_DrTextB(title, 160 - MN_TextBWidth(title) / 2, 7); | ||
if (!slottextloaded) | ||
{ | ||
MN_LoadSlotText(); | ||
} | ||
DrawFileSlots(&LoadMenu); | ||
// [crispy] moved here, draw title on top of file slots | ||
MN_DrTextB(title, 160 - MN_TextBWidth(title) / 2, 1); | ||
DrawSaveLoadBottomLine(&LoadMenu); | ||
} | ||
|
||
|
@@ -969,12 +990,13 @@ static void DrawSaveMenu(void) | |
|
||
title = DEH_String("SAVE GAME"); | ||
|
||
MN_DrTextB(title, 160 - MN_TextBWidth(title) / 2, 7); | ||
if (!slottextloaded) | ||
{ | ||
MN_LoadSlotText(); | ||
} | ||
DrawFileSlots(&SaveMenu); | ||
// [crispy] moved here, draw title on top of file slots | ||
MN_DrTextB(title, 160 - MN_TextBWidth(title) / 2, 1); | ||
DrawSaveLoadBottomLine(&SaveMenu); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a Right Thing to do in terms of fail-safe, but there is still some potential for improvement. Small example, I'm using British Antigua and Barbuda locale, which is using lowercase for
am/pm
designation. Unlike Doom, Heretic can't handle lowercase characters, that's why all game strings are always uppercased. In this case, designation can't appear:Possible solution is to forcefully convert lower case chars to uppercase, this will do the trick:
But how to properly make this condition friendly with newly introduced
|| c > 91)
and avoid messy maze of conditions, that's a good question. 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this, but needs support for big font (it doesn't have
[
symbol (№59) which is a cursor) and probably smarter conditions for indexes checking.This way, even such messy string will work:
E1M1: THE \\ {|} ~ dOcKs