- improve replay saving prompt

This commit is contained in:
Ilya Shurumov 2021-02-26 23:37:08 +06:00
parent 642eba4348
commit c164a6d2de
10 changed files with 122 additions and 86 deletions

View File

@ -1647,9 +1647,7 @@ void ControlReplay(void)
case 7:
if (move == 5)
{
//SetDispMask(0); // [A]
SpoolSYNC();
//CallMemoryCard(0x10, 1);
SaveReplay(0);
break;
}

View File

@ -258,6 +258,8 @@ void SaveCurrentGame()
}
}
char gCurrentReplayFilename[64] = { 0 };
int LoadReplayFromFile(char* fileName)
{
FILE* fp = fopen(fileName, "rb");
@ -273,6 +275,23 @@ int LoadReplayFromFile(char* fileName)
if (LoadReplayFromBuffer(_other_buffer))
{
char* sub, *tmp;
// only filename
sub = fileName;
do
{
tmp = strchr(sub+1, '/');
if (tmp)
sub = tmp+1;
}while(tmp);
strcpy(gCurrentReplayFilename, sub);
sub = strchr(gCurrentReplayFilename, '.');
if (sub)
*sub = 0;
return 1;
}
else
@ -289,6 +308,21 @@ int LoadReplayFromFile(char* fileName)
return 0;
}
int SaveReplayToFile(char* filename)
{
int size = SaveReplayToBuffer(_other_buffer);
FILE* fp = fopen(filename, "wb");
if (fp)
{
fwrite(_other_buffer, 1, size, fp);
fclose(fp);
return 1;
}
return 0;
}
#endif
// [D] [T]

View File

@ -1,11 +1,18 @@
#ifndef LOADSAVE_H
#define LOADSAVE_H
extern char gCurrentReplayFilename[64];
extern void LoadCurrentProfile();
extern void SaveCurrentProfile();
extern int LoadCurrentGame();
extern void SaveCurrentGame();
extern int LoadReplayFromFile(char* fileName);
extern int SaveReplayToFile(char* filename);
//--------
extern int CalcReplayDataSize(); // 0x00057FD4
extern int SaveReplayData(char *buffer); // 0x00057FF4

View File

@ -692,7 +692,6 @@ void SaveReplay(int direction)
#ifdef PSX
CallMemoryCard(0x10, 1);
#else
int size = SaveReplayToBuffer(_other_buffer);
#ifdef CUTSCENE_RECORDER
extern int gCutsceneAsReplay;
@ -710,8 +709,7 @@ void SaveReplay(int direction)
{
sprintf(filename, "CUT%d/CUT%d_%d.D2RP", gCutsceneAsReplay, gCutsceneAsReplay, cnt);
temp = fopen(filename, "rb");
if (temp)
if ((temp = fopen(filename, "rb")) != NULL)
{
fclose(temp);
cnt++;
@ -720,23 +718,57 @@ void SaveReplay(int direction)
break;
}
FILE* fp = fopen(filename, "wb");
if (fp)
if (SaveReplayToFile(filename))
{
printInfo("Saving chase replay '%s'\n", filename);
fwrite(_other_buffer, 1, size, fp);
fclose(fp);
printInfo("Chase replay '%s' saved\n", filename);
gDisplayedMessage.header = G_LTXT(GTXT_SaveReplay);
gDisplayedMessage.text = G_LTXT(GTXT_OK);
gDisplayedMessage.show = 25;
}
else
{
gDisplayedMessage.header = G_LTXT(GTXT_SaveReplay);
gDisplayedMessage.text = G_LTXT(GTXT_SavingError);
gDisplayedMessage.show = 15;
}
}
else
#endif // CUTSCENE_RECORDER
{
int cnt;
FILE* temp;
_mkdir("Replays");
ClearMem(EnterNameText, REPLAY_NAME_LEN);
// detect the best file name
// TODO: if replay is loaded - set the loaded replay filename
if (gLoadedReplay)
{
strcpy(EnterNameText, gCurrentReplayFilename);
}
else
{
cnt = 1;
while (cnt < 1000)
{
sprintf(EnterNameText, "Chase%d", cnt);
sprintf(filename, "Replays/%s.D2RP", EnterNameText);
if ((temp = fopen(filename, "r")) != NULL)
{
fclose(temp);
cnt++;
}
else
break;
}
}
gDisplayedMessage.header = G_LTXT(GTXT_EnterName);
gDisplayedMessage.text = EnterNameText;
gDisplayedMessage.show = -1;
ClearMem(EnterNameText, REPLAY_NAME_LEN);
strcpy(EnterNameText, "Chase");
// wait for user input the replay name
result = WaitForTextEntry(EnterNameText, REPLAY_NAME_LEN);
@ -744,16 +776,10 @@ void SaveReplay(int direction)
if (result)
{
sprintf(filename, "%s.D2RP", result);
sprintf(filename, "Replays/%s.D2RP", result);
FILE* fp = fopen(filename, "wb");
if (fp)
if (SaveReplayToFile(filename))
{
printInfo("Saving replay '%s'\n", filename);
fwrite(_other_buffer, 1, size, fp);
fclose(fp);
gDisplayedMessage.header = G_LTXT(GTXT_SaveReplay);
gDisplayedMessage.text = G_LTXT(GTXT_OK);
gDisplayedMessage.show = 15;
@ -765,6 +791,7 @@ void SaveReplay(int direction)
gDisplayedMessage.show = 15;
}
}
}
#endif // PSX
}

View File

@ -256,7 +256,7 @@ int Loadfile(char* name, char* addr)
int fileSize;
sprintf(namebuffer, "%s%s", gDataFolder, name);
FixPathSlashes(namebuffer);
FS_FixPathSlashes(namebuffer);
FILE* fptr = fopen(namebuffer, "rb");
if (!fptr)
@ -311,7 +311,7 @@ int LoadfileSeg(char* name, char* addr, int offset, int loadsize)
int fileSize;
sprintf(namebuffer, "%s%s", gDataFolder, name);
FixPathSlashes(namebuffer);
FS_FixPathSlashes(namebuffer);
FILE* fptr = fopen(namebuffer, "rb");
if (!fptr)
@ -539,7 +539,7 @@ void loadsectorsPC(char* filename, char* addr, int sector, int nsectors)
{
char namebuffer[64];
strcpy(namebuffer, filename);
FixPathSlashes(namebuffer);
FS_FixPathSlashes(namebuffer);
FILE* fp = fopen(namebuffer, "rb");
@ -859,7 +859,7 @@ void SetCityType(CITYTYPE type)
}
sprintf(filename, format, gDataFolder, LevelFiles[GameLevel]);
FixPathSlashes(filename);
FS_FixPathSlashes(filename);
FILE* levFp = fopen(filename, "rb");
@ -967,7 +967,7 @@ int FileExists(char* filename)
char namebuffer[128];
sprintf(namebuffer, "%s%s", gDataFolder, filename);
FixPathSlashes(namebuffer);
FS_FixPathSlashes(namebuffer);
FILE* fp = fopen(namebuffer, "rb");
if (fp)

View File

@ -79,14 +79,14 @@ void StoreXASubtitles()
for (j = 0; j < 8; j++)
{
sprintf(fileName, XANameFormat, gDataFolder, i+1, j);
FixPathSlashes(fileName);
FS_FixPathSlashes(fileName);
CSoundSource_WaveCache tmpWav;
if (tmpWav.Load(fileName))
{
// Save subtitles file
sprintf(fileName, "%sXA\\XABNK0%d.XA[%d].SBN", gDataFolder, i+1, j);
FixPathSlashes(fileName);
FS_FixPathSlashes(fileName);
FILE* fp = fopen(fileName, "wb");
@ -283,7 +283,7 @@ void PlayXA(int num, int index)
{
char fileName[250];
sprintf(fileName, XANameFormat, gDataFolder, num+1, index);
FixPathSlashes(fileName);
FS_FixPathSlashes(fileName);
g_wavData = new CSoundSource_WaveCache();
@ -291,7 +291,7 @@ void PlayXA(int num, int index)
{
// Load subtitles for XA
sprintf(fileName, "%sXA\\XABNK0%d.XA[%d].SBN", gDataFolder, num + 1, index);
FixPathSlashes(fileName);
FS_FixPathSlashes(fileName);
FILE* fp = fopen(fileName, "rb");

View File

@ -478,7 +478,7 @@ void SetVariable(int var)
{
// [A] temporary
// TODO: Do menu with the replays
if(LoadReplayFromFile("CHASE.D2RP") == 0)
if(LoadReplayFromFile("Replays/CHASE.D2RP") == 0)
{
ReInitFrontend();
}

View File

@ -34,13 +34,13 @@ int InitStringMng()
gUserLanguage = 0;
sprintf(filename, "%sLANG\\%s_GAME.LTXT", gDataFolder, LanguageNames[gUserLanguage]);
FixPathSlashes(filename);
FS_FixPathSlashes(filename);
if(InitStringLanguage(filename, 0) == -1)
return 0;
sprintf(filename, "%sLANG\\%s_MISSION.LTXT", gDataFolder, LanguageNames[gUserLanguage]);
FixPathSlashes(filename);
FS_FixPathSlashes(filename);
if(InitStringLanguage(filename, 1) == -1)
return 0;

View File

@ -3,38 +3,8 @@
#include "STRINGS.H"
#ifdef _WIN32
#include <direct.h>
#define HOME_ENV "USERPROFILE"
inline void FixPathSlashes(char* pathbuff)
{
while (*pathbuff)
{
if (*pathbuff == '/') // make windows-style path
*pathbuff = '\\';
pathbuff++;
}
}
#elif defined (__unix__)
#include <sys/stat.h>
#define HOME_ENV "HOME"
#define _mkdir(str) mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
inline void FixPathSlashes(char* pathbuff)
{
while (*pathbuff)
{
if (*pathbuff == '\\') // make unix-style path
*pathbuff = '/';
pathbuff++;
}
}
#ifndef PSX
#include "../utils/fs.h"
#endif
#ifdef __GNUC__

View File

@ -494,7 +494,7 @@ void DoPlayFMV(RENDER_ARG* arg, int subtitles)
char filename[250];
sprintf(filename, "%sFMV\\%d\\RENDER%d.STR[0].avi", gDataFolder, fd, arg->render);
FixPathSlashes(filename);
FS_FixPathSlashes(filename);
ReadAVI readAVI(filename);
@ -502,7 +502,7 @@ void DoPlayFMV(RENDER_ARG* arg, int subtitles)
if (subtitles)
{
sprintf(filename, "%sFMV\\%d\\RENDER%d.SBN", gDataFolder, fd, arg->render);
FixPathSlashes(filename);
FS_FixPathSlashes(filename);
InitSubtitles(filename);
}
@ -514,7 +514,7 @@ void DoPlayFMV(RENDER_ARG* arg, int subtitles)
if(arg->credits)
{
sprintf(filename, "%sDATA\\CREDITS.ENG", gDataFolder);
FixPathSlashes(filename);
FS_FixPathSlashes(filename);
InitCredits(filename);
}