frontend: menu: show savestate date
[pcsx_rearmed.git] / frontend / common / menu.c
index d76eda4..9a6a47c 100644 (file)
@@ -12,6 +12,7 @@
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdarg.h>\r
+#include <time.h>\r
 \r
 #include "menu.h"\r
 #include "fonts.h"\r
@@ -965,7 +966,10 @@ rescan:
 \r
 // ------------ savestate loader ------------\r
 \r
+#define STATE_SLOT_COUNT 10\r
+\r
 static int state_slot_flags = 0;\r
+static int state_slot_times[STATE_SLOT_COUNT];\r
 \r
 static void state_check_slots(void)\r
 {\r
@@ -973,8 +977,9 @@ static void state_check_slots(void)
 \r
        state_slot_flags = 0;\r
 \r
-       for (slot = 0; slot < 10; slot++) {\r
-               if (emu_check_save_file(slot))\r
+       for (slot = 0; slot < STATE_SLOT_COUNT; slot++) {\r
+               state_slot_times[slot] = 0;\r
+               if (emu_check_save_file(slot, &state_slot_times[slot]))\r
                        state_slot_flags |= 1 << slot;\r
        }\r
 }\r
@@ -984,12 +989,13 @@ static void draw_savestate_bg(int slot);
 static void draw_savestate_menu(int menu_sel, int is_loading)\r
 {\r
        int i, x, y, w, h;\r
+       char time_buf[32];\r
 \r
        if (state_slot_flags & (1 << menu_sel))\r
                draw_savestate_bg(menu_sel);\r
 \r
        w = (13 + 2) * me_mfont_w;\r
-       h = (1+2+10+1) * me_mfont_h;\r
+       h = (1+2+STATE_SLOT_COUNT+1) * me_mfont_h;\r
        x = g_menuscreen_w / 2 - w / 2;\r
        if (x < 0) x = 0;\r
        y = g_menuscreen_h / 2 - h / 2;\r
@@ -1004,12 +1010,23 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
        text_out16(x, y, is_loading ? "Load state" : "Save state");\r
        y += 3 * me_mfont_h;\r
 \r
-       menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (13 + 2) * me_mfont_w + 4);\r
+       menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (23 + 2) * me_mfont_w + 4);\r
 \r
-       /* draw all 10 slots */\r
-       for (i = 0; i < 10; i++, y += me_mfont_h)\r
+       /* draw all slots */\r
+       for (i = 0; i < STATE_SLOT_COUNT; i++, y += me_mfont_h)\r
        {\r
-               text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
+               if (!(state_slot_flags & (1 << i)))\r
+                       strcpy(time_buf, "free");\r
+               else {\r
+                       strcpy(time_buf, "USED");\r
+                       if (state_slot_times[i] != 0) {\r
+                               time_t time = state_slot_times[i];\r
+                               struct tm *t = localtime(&time);\r
+                               strftime(time_buf, sizeof(time_buf), "%x %R", t);\r
+                       }\r
+               }\r
+\r
+               text_out16(x, y, "SLOT %i (%s)", i, time_buf);\r
        }\r
        text_out16(x, y, "back");\r
 \r
@@ -1018,8 +1035,8 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
 \r
 static int menu_loop_savestate(int is_loading)\r
 {\r
-       static int menu_sel = 10;\r
-       int menu_sel_max = 10;\r
+       static int menu_sel = STATE_SLOT_COUNT;\r
+       int menu_sel_max = STATE_SLOT_COUNT;\r
        unsigned long inp = 0;\r
        int ret = 0;\r
 \r
@@ -1047,7 +1064,7 @@ static int menu_loop_savestate(int is_loading)
                        } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
                }\r
                if (inp & PBTN_MOK) { // save/load\r
-                       if (menu_sel < 10) {\r
+                       if (menu_sel < STATE_SLOT_COUNT) {\r
                                state_slot = menu_sel;\r
                                if (emu_save_load_game(is_loading, 0)) {\r
                                        me_update_msg(is_loading ? "Load failed" : "Save failed");\r