mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
Mapster32/Lunatic: ask when a <V10 map would be overwritten with a map-text one.
Also, clean up the saving/loading logic a bit: - On load failure, display message with purple color. - Take over the current file name ('boardfilename') only on success. - Check SaveBoard() return values in various places. git-svn-id: https://svn.eduke32.com/eduke32@3911 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
5ea2eee072
commit
b2c5e2d807
4 changed files with 70 additions and 28 deletions
|
@ -220,6 +220,7 @@ int32_t _getnumber16(const char *namestart, int32_t num, int32_t maxnumber, char
|
|||
#define getnumber16(namestart, num, maxnumber, sign) _getnumber16(namestart, num, maxnumber, sign, NULL)
|
||||
void printmessage256(int32_t x, int32_t y, const char *name);
|
||||
void message(const char *fmt, ...) ATTRIBUTE((format(printf,1,2)));
|
||||
extern int32_t AskIfSure(const char *text);
|
||||
|
||||
const char* getstring_simple(const char *querystr, const char *defaultstr, int32_t maxlen, int32_t completion);
|
||||
|
||||
|
@ -317,6 +318,13 @@ extern int32_t scripthistend;
|
|||
#define AIMING_AT_WALL_OR_MASK (AIMING_AT_WALL || AIMING_AT_MASKWALL)
|
||||
#define AIMING_AT_CEILING_OR_FLOOR (AIMING_AT_CEILING || AIMING_AT_FLOOR)
|
||||
|
||||
// SaveBoard flags.
|
||||
enum SaveBoardFlags
|
||||
{
|
||||
M32_SB_NOEXT = 1, // no ExtSaveMap (backup.map) and no taglabels saving
|
||||
M32_SB_ASKOV = 2, // for NEW_MAP_FORMAT build, ask whether write map if going from V7/8 to VX
|
||||
};
|
||||
|
||||
#ifdef EXTERNC
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -100,6 +100,7 @@ int32_t zoom = 768, gettilezoom = 1;
|
|||
int32_t lastpm16time = 0;
|
||||
|
||||
extern int32_t mapversion;
|
||||
extern int32_t g_loadedMapVersion;
|
||||
|
||||
int16_t highlight[MAXWALLS+MAXSPRITES];
|
||||
int16_t highlightsector[MAXSECTORS], highlightsectorcnt = -1;
|
||||
|
@ -187,6 +188,7 @@ char lastpm16buf[156];
|
|||
|
||||
//static int32_t checksectorpointer_warn = 0;
|
||||
static int32_t saveboard_savedtags, saveboard_fixedsprites;
|
||||
static int32_t saveboard_canceled;
|
||||
|
||||
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo);
|
||||
static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal);
|
||||
|
@ -431,6 +433,7 @@ static void reset_default_mapstate(void)
|
|||
#ifdef YAX_ENABLE
|
||||
yax_resetbunchnums();
|
||||
#endif
|
||||
g_loadedMapVersion = -1;
|
||||
}
|
||||
|
||||
static void m32_keypresscallback(int32_t code, int32_t downp)
|
||||
|
@ -804,7 +807,7 @@ CANCEL:
|
|||
{
|
||||
keystatus[0x15] = keystatus[0x1c] = 0;
|
||||
|
||||
SaveBoard(NULL, 0);
|
||||
SaveBoard(NULL, M32_SB_ASKOV);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -7693,7 +7696,7 @@ CANCEL:
|
|||
ret = LoadBoard(NULL, 4);
|
||||
if (ret)
|
||||
{
|
||||
message("Invalid map format, nothing loaded (code %d).", ret);
|
||||
message("^13Invalid map format, nothing loaded (code %d).", ret);
|
||||
if (bakstat==0)
|
||||
mapinfofull_free(&bakmap);
|
||||
}
|
||||
|
@ -7838,7 +7841,7 @@ CANCEL:
|
|||
int32_t corrupt = CheckMapCorruption(4, 0);
|
||||
|
||||
if (ask_if_sure(corrupt<4?"Save changes?":"Map corrupt. Save changes?", 2+(corrupt>=4)))
|
||||
SaveBoard(NULL, 0);
|
||||
SaveBoard(NULL, M32_SB_ASKOV);
|
||||
|
||||
while (keystatus[1] || keystatus[0x2e])
|
||||
{
|
||||
|
@ -7992,7 +7995,7 @@ static void SaveBoardAndPrintMessage(const char *fn)
|
|||
_printmessage16("Saving board...");
|
||||
showframe(1);
|
||||
|
||||
f = SaveBoard(fn, 0);
|
||||
f = SaveBoard(fn, M32_SB_ASKOV);
|
||||
|
||||
if (f)
|
||||
{
|
||||
|
@ -8004,11 +8007,14 @@ static void SaveBoardAndPrintMessage(const char *fn)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (saveboard_fixedsprites)
|
||||
message("^13SAVING BOARD FAILED (changed sectnums of %d sprites).",
|
||||
saveboard_fixedsprites);
|
||||
else
|
||||
message("^13SAVING BOARD FAILED.");
|
||||
if (!saveboard_canceled)
|
||||
{
|
||||
if (saveboard_fixedsprites)
|
||||
message("^13SAVING BOARD FAILED (changed sectnums of %d sprites).",
|
||||
saveboard_fixedsprites);
|
||||
else
|
||||
message("^13SAVING BOARD FAILED.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8026,17 +8032,36 @@ const char *GetSaveBoardFilename(const char *fn)
|
|||
return getbasefn(fn);
|
||||
}
|
||||
|
||||
// flags: 1:no ExtSaveMap (backup.map) and no taglabels saving
|
||||
// flags: see enum SaveBoardFlags.
|
||||
// returns: NULL on failure, file name on success.
|
||||
const char *SaveBoard(const char *fn, uint32_t flags)
|
||||
{
|
||||
int32_t ret;
|
||||
const char *f = GetSaveBoardFilename(fn);
|
||||
|
||||
saveboard_savedtags = 0;
|
||||
saveboard_canceled = 0;
|
||||
#ifdef NEW_MAP_FORMAT
|
||||
if ((flags&M32_SB_ASKOV) && mapversion>=10 &&
|
||||
g_loadedMapVersion != -1 && g_loadedMapVersion < mapversion)
|
||||
{
|
||||
char question[128];
|
||||
Bsnprintf(question, sizeof(question), "Are you sure to overwrite a version "
|
||||
"V%d map with a V%d map-text one?", g_loadedMapVersion, mapversion);
|
||||
|
||||
if (AskIfSure(question))
|
||||
{
|
||||
message("Cancelled saving board");
|
||||
saveboard_canceled = 1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
saveboard_savedtags = 0;
|
||||
saveboard_fixedsprites = ExtPreSaveMap();
|
||||
|
||||
ret = saveboard(f, &startpos, startang, startsectnum);
|
||||
if ((flags&1)==0)
|
||||
if ((flags&M32_SB_NOEXT)==0)
|
||||
{
|
||||
ExtSaveMap(f);
|
||||
saveboard_savedtags = !taglab_save(f);
|
||||
|
@ -8047,6 +8072,9 @@ const char *SaveBoard(const char *fn, uint32_t flags)
|
|||
|
||||
// flags: 1: for running on Mapster32 init
|
||||
// 4: passed to loadboard flags (no polymer_loadboard); implies no maphack loading
|
||||
// returns:
|
||||
// 0 on success,
|
||||
// <0 on failure.
|
||||
int32_t LoadBoard(const char *filename, uint32_t flags)
|
||||
{
|
||||
int32_t i, tagstat;
|
||||
|
@ -8055,9 +8083,6 @@ int32_t LoadBoard(const char *filename, uint32_t flags)
|
|||
if (!filename)
|
||||
filename = selectedboardfilename;
|
||||
|
||||
if (filename != boardfilename)
|
||||
Bstrcpy(boardfilename, filename);
|
||||
|
||||
editorzrange[0] = INT32_MIN;
|
||||
editorzrange[1] = INT32_MAX;
|
||||
|
||||
|
@ -8072,6 +8097,10 @@ int32_t LoadBoard(const char *filename, uint32_t flags)
|
|||
return i;
|
||||
}
|
||||
|
||||
// Success, so copy the file name.
|
||||
if (filename != boardfilename)
|
||||
Bstrcpy(boardfilename, filename);
|
||||
|
||||
mkonwinvalid();
|
||||
|
||||
highlightcnt = -1;
|
||||
|
@ -8099,7 +8128,8 @@ int32_t LoadBoard(const char *filename, uint32_t flags)
|
|||
else
|
||||
Bstrcpy(msgtail, "successfully");
|
||||
|
||||
message("Loaded V%d map %s%s %s", mapversion, boardfilename, tagstat==0?" w/tags":"", msgtail);
|
||||
message("Loaded V%d map %s%s %s", g_loadedMapVersion,
|
||||
boardfilename, tagstat==0?" w/tags":"", msgtail);
|
||||
}
|
||||
|
||||
startpos = pos; //this is same
|
||||
|
|
|
@ -80,6 +80,7 @@ float debug1, debug2;
|
|||
#endif
|
||||
|
||||
int32_t mapversion=7; // JBF 20040211: default mapversion to 7
|
||||
int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new)
|
||||
|
||||
static int32_t get_mapversion(void);
|
||||
|
||||
|
@ -10037,6 +10038,8 @@ skip_reading_mapbin:
|
|||
check_sprite(i);
|
||||
}
|
||||
|
||||
// Back up the map version of the *loaded* map. Must be before yax_update().
|
||||
g_loadedMapVersion = mapversion;
|
||||
#ifdef YAX_ENABLE
|
||||
yax_update(mapversion<9);
|
||||
if (editstatus)
|
||||
|
|
|
@ -2987,7 +2987,7 @@ static void m32_showmouse(void)
|
|||
pop_nofog();
|
||||
}
|
||||
|
||||
static int32_t AskIfSure(const char *text)
|
||||
int32_t AskIfSure(const char *text)
|
||||
{
|
||||
int32_t retval=1;
|
||||
|
||||
|
@ -3027,7 +3027,7 @@ static int32_t AskIfSure(const char *text)
|
|||
if (PRESSED_KEYSC(ESC))
|
||||
retval = 1;
|
||||
|
||||
return(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int32_t IsValidTile(int32_t idTile)
|
||||
|
@ -10513,7 +10513,7 @@ void app_crashhandler(void)
|
|||
if (levelname[0])
|
||||
{
|
||||
append_ext_UNSAFE(levelname, "_crash.map");
|
||||
SaveBoard(levelname, 1);
|
||||
SaveBoard(levelname, M32_SB_NOEXT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11099,11 +11099,12 @@ static void Keys2d3d(void)
|
|||
Bsprintf(tempbuf, "Save to %s?", levelname);
|
||||
if (!AskIfSure(tempbuf))
|
||||
{
|
||||
SaveBoard(levelname, 0);
|
||||
|
||||
message("Board saved to %s", levelname);
|
||||
asksave = 0;
|
||||
lastsave=totalclock;
|
||||
if (SaveBoard(levelname, M32_SB_ASKOV) != NULL)
|
||||
{
|
||||
message("Board saved to %s", levelname);
|
||||
asksave = 0;
|
||||
lastsave=totalclock;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -11284,13 +11285,13 @@ void ExtCheckKeys(void)
|
|||
{
|
||||
if (CheckMapCorruption(5, 0)>=4)
|
||||
{
|
||||
SaveBoard("autosave_corrupt.map", 1);
|
||||
message("Board autosaved to AUTOSAVE_CORRUPT.MAP");
|
||||
if (SaveBoard("autosave_corrupt.map", M32_SB_NOEXT) != NULL)
|
||||
message("Board autosaved to AUTOSAVE_CORRUPT.MAP");
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveBoard("autosave.map", 0);
|
||||
message("Board autosaved to AUTOSAVE.MAP");
|
||||
if (SaveBoard("autosave.map", 0) != NULL)
|
||||
message("Board autosaved to AUTOSAVE.MAP");
|
||||
}
|
||||
|
||||
asksave++;
|
||||
|
|
Loading…
Reference in a new issue