Skip to content

Commit

Permalink
Show date and time of savegame in Save/Load menu (#1200)
Browse files Browse the repository at this point in the history
* Doom: first working implementation

* Use parametrized y coord

Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>

* Correct comment

Better do not remove it, so the purpose of "-15" will be clear.

* For Heretic

* For Hexen

* For Strife (WIP)

Working, but needs pixel perfection.

* Doom: make M_DrawSaveLoadBottomLine static

* For Strife (done)

Strife using spaces, not tabs. ;)

* Doom: inhelpscreens no longer needed for M_DrawSaveLoadBottomLine

Since everything is moved slightly up and no extra file slot is being drawed over status bar, "inhelpscreens" is now redundant.

Save date should not appear on status bar, since it's using same Y-coords as KIS stats.

Also, this making Save/Load menu slightly less expensive in terms of CPU usage, but fortunately, we are still on capped framerate while active menu.

* Remove copy-pasta remaining from ID

* Heretic & Hexen: fail-safe conditions for font drawing functions

Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>

---------

Co-authored-by: Fabian Greffrath <fabian@greffrath.com>
  • Loading branch information
JNechaevsky and fabiangreffrath committed Apr 23, 2024
1 parent d4747e4 commit 4c658f2
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 27 deletions.
32 changes: 24 additions & 8 deletions src/doom/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <stdlib.h>
#include <ctype.h>
#include <time.h> // [crispy] strftime, localtime


#include "doomdef.h"
Expand Down Expand Up @@ -851,15 +852,10 @@ void M_ReadSaveStrings(void)
}

// [FG] support up to 8 pages of savegames
void M_DrawSaveLoadBottomLine(void)
static void M_DrawSaveLoadBottomLine(void)
{
char pagestr[16];
const int y = LoadDef.y+LINEHEIGHT*load_end;

// [crispy] force status bar refresh
inhelpscreens = true;

M_DrawSaveLoadBorder(LoadDef.x,y);
const int y = 152;

dp_translation = cr[CR_GOLD];

Expand All @@ -871,6 +867,26 @@ void M_DrawSaveLoadBottomLine(void)
M_snprintf(pagestr, sizeof(pagestr), "page %d/%d", savepage + 1, savepage_max + 1);
M_WriteText(ORIGWIDTH/2-M_StringWidth(pagestr)/2, y, pagestr);

// [crispy] print "modified" (or created initially) time of savegame file
if (LoadMenu[itemOn].status)
{
struct stat st;
char filedate[32];

stat(P_SaveGameFile(itemOn), &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));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
M_WriteText(ORIGWIDTH/2-M_StringWidth(filedate)/2, y + 8, filedate);
}

dp_translation = NULL;
}

Expand Down Expand Up @@ -3457,7 +3473,7 @@ void M_Init (void)
{
LoadDef_y = vstep + captionheight - SHORT(patchl->height) + SHORT(patchl->topoffset);
SaveDef_y = vstep + captionheight - SHORT(patchs->height) + SHORT(patchs->topoffset);
LoadDef.y = SaveDef.y = vstep + captionheight + vstep + SHORT(patchm->topoffset) - 7; // [crispy] see M_DrawSaveLoadBorder()
LoadDef.y = SaveDef.y = vstep + captionheight + vstep + SHORT(patchm->topoffset) - 15; // [crispy] moved up, so savegame date/time may appear above status bar
MouseDef.y = LoadDef.y;
}
}
Expand Down
38 changes: 30 additions & 8 deletions src/heretic/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <stdlib.h>
#include <ctype.h>
#include <time.h> // [crispy] strftime, localtime

#include "deh_str.h"
#include "doomdef.h"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
MN_DrTextA(filedate, ORIGWIDTH / 2 - MN_TextAWidth(pagestr), y + 10);
}

dp_translation = NULL;
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
42 changes: 33 additions & 9 deletions src/hexen/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// HEADER FILES ------------------------------------------------------------

#include <ctype.h>
#include <time.h> // [crispy] strftime, localtime
#include "h2def.h"
#include "doomkeys.h"
#include "i_input.h"
Expand Down Expand Up @@ -263,7 +264,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,
Expand All @@ -280,7 +281,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,
Expand Down Expand Up @@ -557,7 +558,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;
}
Expand All @@ -583,7 +584,7 @@ void MN_DrTextAYellow(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 FONTAY59 as spaces
{
x += 5;
}
Expand Down Expand Up @@ -613,7 +614,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 FONTA(Y)59 as spaces
{
width += 5;
}
Expand Down Expand Up @@ -641,7 +642,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;
}
Expand Down Expand Up @@ -671,7 +672,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;
}
Expand Down Expand Up @@ -907,6 +908,27 @@ 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];
char filename[100];

M_snprintf(filename, sizeof(filename), "%shex%d.hxs", SavePath, CurrentItPos + (savepage * 10));
stat(filename, &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));
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
MN_DrTextA(filedate, ORIGWIDTH / 2 - MN_TextAWidth(filedate) / 2, y + 10);
}

dp_translation = NULL;
}

Expand All @@ -918,12 +940,13 @@ static void DrawSaveLoadBottomLine(const Menu_t *menu)

static void DrawLoadMenu(void)
{
MN_DrTextB("LOAD GAME", 160 - MN_TextBWidth("LOAD GAME") / 2, 7);
if (!slottextloaded)
{
MN_LoadSlotText();
}
DrawFileSlots(&LoadMenu);
// [crispy] moved here, draw title on top of file slots
MN_DrTextB("LOAD GAME", 160 - MN_TextBWidth("LOAD GAME") / 2, 1);
DrawSaveLoadBottomLine(&LoadMenu);
}

Expand All @@ -935,12 +958,13 @@ static void DrawLoadMenu(void)

static void DrawSaveMenu(void)
{
MN_DrTextB("SAVE GAME", 160 - MN_TextBWidth("SAVE GAME") / 2, 7);
if (!slottextloaded)
{
MN_LoadSlotText();
}
DrawFileSlots(&SaveMenu);
// [crispy] moved here, draw title on top of file slots
MN_DrTextB("SAVE GAME", 160 - MN_TextBWidth("SAVE GAME") / 2, 1);
DrawSaveLoadBottomLine(&SaveMenu);
}

Expand Down
4 changes: 4 additions & 0 deletions src/i_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h> // [crispy] setlocale

#include "SDL.h"

Expand Down Expand Up @@ -52,6 +53,9 @@ int main(int argc, char **argv)
myargv[i] = M_StringDuplicate(argv[i]);
}

// [crispy] Print date and time in the Load/Save Game menus in the current locale
setlocale(LC_TIME, "");

//!
// Print the program version and exit.
//
Expand Down
Loading

0 comments on commit 4c658f2

Please sign in to comment.