[Add] Prompt before overwriting pilot's save.

This commit is contained in:
Allanis 2013-05-16 15:18:12 +01:00
parent 2034a02f74
commit 856ea04d8d
5 changed files with 45 additions and 1 deletions

View File

@ -241,7 +241,7 @@ void main_loop(void) {
fps_control(); // Everyone loves fps control..
if(toolkit) toolkit_update(); // To simulate key repetition.
if(!menu_isOpen(MENU_MAIN)) {
if(!paused && !toolkit) update_all(); // Update game.
if(!paused) update_all(); // Update game.
render_all();
}
if(toolkit) toolkit_render();

View File

@ -1,4 +1,5 @@
#include <string.h>
#include <stdarg.h>
#ifdef LINUX
#include <stdlib.h>
#include <sys/types.h>
@ -51,6 +52,31 @@ int lfile_dirMakeExist(char* path) {
return 0;
}
// Check if a file exists.
int lfile_fileExists(char* path, ...) {
char file[PATH_MAX], name[PATH_MAX];
va_list ap;
size_t l;
l = 0;
if(path == NULL) return -1;
else { // Get the message.
va_start(ap, path);
vsnprintf(name, PATH_MAX-l, path, ap);
l = strlen(name);
va_end(ap);
}
snprintf(file, PATH_MAX, "%s%s", lfile_basePath(), name);
#ifdef LINUX
struct stat buf;
if(stat(file, &buf)==0) // Stat worked, file must exist.
return 1;
#endif
return 0;
}
// List all the files in a dir (besides . and ..).
char** lfile_readDir(int* lfiles, char* path) {
char file[PATH_MAX];

View File

@ -2,5 +2,6 @@
char* lfile_basePath(void);
int lfile_dirMakeExist(char* path);
int lfile_fileExists(char* path, ...);
char** lfile_readDir(int* lfiles, char* path);

View File

@ -150,7 +150,9 @@ int player_save(xmlTextWriterPtr writer);
// Prompt player name.
void player_new(void) {
int r;
// Let's not seg fault due to a lack of environment.
player_flags = 0;
player_setFlag(PLAYER_DESTROYED);
vectnull(&player_cam);
gl_bindCamera(&player_cam);
@ -163,6 +165,17 @@ void player_new(void) {
player_name = dialogue_input("Player Name", 3, 20,
"Please tell me your name:");
if(lfile_fileExists("saves/%s.ls", player_name)) {
r = dialogue_YesNo("Overwrite",
"You already have a pilot named %s. Overwrite?", player_name);
if(r == 0) {
// Nupe.
player_new();
return;
}
}
player_newMake();
}
@ -473,6 +486,8 @@ void player_render(void) {
glColour* c;
glFont* f;
if(player == NULL) return;
if(player_isFlag(PLAYER_DESTROYED) || pilot_isFlag(player, PILOT_DEAD)) {
if(player_isFlag(PLAYER_DESTROYED)) {
if(!toolkit && (SDL_GetTicks() > player_timer))

View File

@ -501,6 +501,8 @@ void space_update(const double dt) {
(void)dt; // Don't need it right now.
if(cur_system == NULL) return; // Can't update a null system.
t = SDL_GetTicks();
if(cur_system->nfleets == 0)