menu: show savestate date

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@951 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2012-07-22 14:32:38 +00:00
parent 323db72934
commit 8b8d9463fa
3 changed files with 35 additions and 14 deletions

View file

@ -1012,7 +1012,7 @@ char *emu_get_save_fname(int load, int is_sram, int slot)
return NULL; return NULL;
} }
int emu_check_save_file(int slot) int emu_check_save_file(int slot, int *time)
{ {
return emu_get_save_fname(1, 0, slot) ? 1 : 0; return emu_get_save_fname(1, 0, slot) ? 1 : 0;
} }
@ -1239,7 +1239,7 @@ static void run_events_ui(unsigned int which)
if (which & (PEV_STATE_LOAD|PEV_STATE_SAVE)) if (which & (PEV_STATE_LOAD|PEV_STATE_SAVE))
{ {
int do_it = 1; int do_it = 1;
if ( emu_check_save_file(state_slot) && if ( emu_check_save_file(state_slot, NULL) &&
(((which & PEV_STATE_LOAD) && (currentConfig.confirm_save & EOPT_CONFIRM_LOAD)) || (((which & PEV_STATE_LOAD) && (currentConfig.confirm_save & EOPT_CONFIRM_LOAD)) ||
((which & PEV_STATE_SAVE) && (currentConfig.confirm_save & EOPT_CONFIRM_SAVE))) ) ((which & PEV_STATE_SAVE) && (currentConfig.confirm_save & EOPT_CONFIRM_SAVE))) )
{ {
@ -1292,7 +1292,7 @@ static void run_events_ui(unsigned int which)
} }
emu_status_msg("SAVE SLOT %i [%s]", state_slot, emu_status_msg("SAVE SLOT %i [%s]", state_slot,
emu_check_save_file(state_slot) ? "USED" : "FREE"); emu_check_save_file(state_slot, NULL) ? "USED" : "FREE");
} }
if (which & PEV_MENU) if (which & PEV_MENU)
engineState = PGS_Menu; engineState = PGS_Menu;

View file

@ -133,7 +133,7 @@ int emu_read_config(const char *rom_fname, int no_defaults);
int emu_write_config(int game); int emu_write_config(int game);
char *emu_get_save_fname(int load, int is_sram, int slot); char *emu_get_save_fname(int load, int is_sram, int slot);
int emu_check_save_file(int slot); int emu_check_save_file(int slot, int *time);
void emu_text_out8 (int x, int y, const char *text); void emu_text_out8 (int x, int y, const char *text);
void emu_text_out16(int x, int y, const char *text); void emu_text_out16(int x, int y, const char *text);

View file

@ -12,6 +12,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <time.h>
#include <locale.h> // savestate date
#include "menu.h" #include "menu.h"
#include "fonts.h" #include "fonts.h"
@ -309,6 +311,9 @@ void menu_init(void)
} }
fclose(f); fclose(f);
} }
// use user's locale for savestate date display
setlocale(LC_TIME, "");
} }
static void menu_draw_begin(int need_bg) static void menu_draw_begin(int need_bg)
@ -965,7 +970,10 @@ rescan:
// ------------ savestate loader ------------ // ------------ savestate loader ------------
#define STATE_SLOT_COUNT 10
static int state_slot_flags = 0; static int state_slot_flags = 0;
static int state_slot_times[STATE_SLOT_COUNT];
static void state_check_slots(void) static void state_check_slots(void)
{ {
@ -973,8 +981,9 @@ static void state_check_slots(void)
state_slot_flags = 0; state_slot_flags = 0;
for (slot = 0; slot < 10; slot++) { for (slot = 0; slot < STATE_SLOT_COUNT; slot++) {
if (emu_check_save_file(slot)) state_slot_times[slot] = 0;
if (emu_check_save_file(slot, &state_slot_times[slot]))
state_slot_flags |= 1 << slot; state_slot_flags |= 1 << slot;
} }
} }
@ -984,12 +993,13 @@ static void draw_savestate_bg(int slot);
static void draw_savestate_menu(int menu_sel, int is_loading) static void draw_savestate_menu(int menu_sel, int is_loading)
{ {
int i, x, y, w, h; int i, x, y, w, h;
char time_buf[32];
if (state_slot_flags & (1 << menu_sel)) if (state_slot_flags & (1 << menu_sel))
draw_savestate_bg(menu_sel); draw_savestate_bg(menu_sel);
w = (13 + 2) * me_mfont_w; w = (13 + 2) * me_mfont_w;
h = (1+2+10+1) * me_mfont_h; h = (1+2+STATE_SLOT_COUNT+1) * me_mfont_h;
x = g_menuscreen_w / 2 - w / 2; x = g_menuscreen_w / 2 - w / 2;
if (x < 0) x = 0; if (x < 0) x = 0;
y = g_menuscreen_h / 2 - h / 2; y = g_menuscreen_h / 2 - h / 2;
@ -1004,12 +1014,23 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
text_out16(x, y, is_loading ? "Load state" : "Save state"); text_out16(x, y, is_loading ? "Load state" : "Save state");
y += 3 * me_mfont_h; y += 3 * me_mfont_h;
menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (13 + 2) * me_mfont_w + 4); menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (23 + 2) * me_mfont_w + 4);
/* draw all 10 slots */ /* draw all slots */
for (i = 0; i < 10; i++, y += me_mfont_h) for (i = 0; i < STATE_SLOT_COUNT; i++, y += me_mfont_h)
{ {
text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free"); if (!(state_slot_flags & (1 << i)))
strcpy(time_buf, "free");
else {
strcpy(time_buf, "USED");
if (state_slot_times[i] != 0) {
time_t time = state_slot_times[i];
struct tm *t = localtime(&time);
strftime(time_buf, sizeof(time_buf), "%x %R", t);
}
}
text_out16(x, y, "SLOT %i (%s)", i, time_buf);
} }
text_out16(x, y, "back"); text_out16(x, y, "back");
@ -1018,8 +1039,8 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
static int menu_loop_savestate(int is_loading) static int menu_loop_savestate(int is_loading)
{ {
static int menu_sel = 10; static int menu_sel = STATE_SLOT_COUNT;
int menu_sel_max = 10; int menu_sel_max = STATE_SLOT_COUNT;
unsigned long inp = 0; unsigned long inp = 0;
int ret = 0; int ret = 0;
@ -1047,7 +1068,7 @@ static int menu_loop_savestate(int is_loading)
} while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
} }
if (inp & PBTN_MOK) { // save/load if (inp & PBTN_MOK) { // save/load
if (menu_sel < 10) { if (menu_sel < STATE_SLOT_COUNT) {
state_slot = menu_sel; state_slot = menu_sel;
if (emu_save_load_game(is_loading, 0)) { if (emu_save_load_game(is_loading, 0)) {
me_update_msg(is_loading ? "Load failed" : "Save failed"); me_update_msg(is_loading ? "Load failed" : "Save failed");