2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
/*
|
|
|
|
* loadsave.c
|
|
|
|
* load and save Popup screens.
|
|
|
|
*
|
|
|
|
* these don't actually do any loading or saving, but just
|
|
|
|
* return a filename to use for the ops.
|
|
|
|
*/
|
|
|
|
|
2007-02-19 06:10:44 -08:00
|
|
|
#include <ctype.h>
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <physfs.h>
|
|
|
|
|
2006-05-27 09:37:17 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2006-09-23 10:24:55 -07:00
|
|
|
#include "lib/framework/strres.h"
|
2006-05-27 09:37:17 -07:00
|
|
|
#include "lib/widget/widget.h"
|
|
|
|
#include "lib/ivis_common/piepalette.h" // for predefined colours.
|
|
|
|
#include "lib/ivis_common/rendmode.h" // for boxfill
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "hci.h"
|
|
|
|
#include "loadsave.h"
|
|
|
|
#include "multiplay.h"
|
|
|
|
#include "game.h"
|
2007-03-27 11:59:03 -07:00
|
|
|
#include "lib/sound/audio_id.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "frontend.h"
|
|
|
|
#include "winmain.h"
|
|
|
|
#include "display3d.h"
|
|
|
|
#include "display.h"
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2006-05-27 09:37:17 -07:00
|
|
|
#include "lib/netplay/netplay.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "loop.h"
|
|
|
|
#include "intdisplay.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "mission.h"
|
2006-05-27 09:37:17 -07:00
|
|
|
#include "lib/gamelib/gtime.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
//======================================================================================
|
|
|
|
//--------------------------------
|
|
|
|
#define totalslots 20 //saves slots.. was 10 , now 20 *Away with hard coding values!* -Q
|
|
|
|
#define totalslotspace 64 //guessing 64 max chars for filename.
|
|
|
|
//--------------------------------
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define LOADSAVE_X 130 + D_W
|
|
|
|
#define LOADSAVE_Y 30 + D_H //was 170 -Q
|
|
|
|
#define LOADSAVE_W 380
|
|
|
|
#define LOADSAVE_H 240 //was 200 -Q
|
|
|
|
|
|
|
|
#define MAX_SAVE_NAME 60
|
|
|
|
|
|
|
|
|
|
|
|
#define LOADSAVE_HGAP 9 //from 5 to 9 -Q
|
|
|
|
#define LOADSAVE_VGAP 9 //from 5 to 9 -Q
|
|
|
|
#define LOADSAVE_BANNER_DEPTH 40 //was 25 top banner which displays either load or save
|
|
|
|
|
|
|
|
|
|
|
|
#define LOADENTRY_W (LOADSAVE_W -(3 * LOADSAVE_HGAP)) /2
|
|
|
|
#define LOADENTRY_H (LOADSAVE_H -(6 * LOADSAVE_VGAP )- (LOADSAVE_BANNER_DEPTH+LOADSAVE_VGAP) ) /5
|
|
|
|
|
|
|
|
#define ID_LOADSAVE 21000
|
|
|
|
#define LOADSAVE_FORM ID_LOADSAVE+1 // back form.
|
|
|
|
#define LOADSAVE_CANCEL ID_LOADSAVE+2 // cancel but.
|
|
|
|
#define LOADSAVE_LABEL ID_LOADSAVE+3 // load/save
|
|
|
|
#define LOADSAVE_BANNER ID_LOADSAVE+4 // banner.
|
|
|
|
|
2006-05-27 09:37:17 -07:00
|
|
|
#define LOADENTRY_START ID_LOADSAVE+10 // each of the buttons.
|
|
|
|
#define LOADENTRY_END ID_LOADSAVE+10 +totalslots // must have unique ID hmm -Q
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
#define SAVEENTRY_EDIT ID_LOADSAVE+50 // save edit box. must be highest value possible I guess. -Q
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
void drawBlueBox (UDWORD x,UDWORD y, UDWORD w, UDWORD h);
|
2006-09-13 05:58:32 -07:00
|
|
|
BOOL closeLoadSave (void);
|
2007-06-28 10:47:08 -07:00
|
|
|
BOOL runLoadSave (BOOL bResetMissionWidgets);
|
2006-09-13 05:58:32 -07:00
|
|
|
BOOL displayLoadSave (void);
|
2007-04-09 15:09:27 -07:00
|
|
|
static BOOL _addLoadSave (BOOL bLoad, const char *sSearchPath, const char *sExtension, const char *title);
|
2007-06-28 10:47:08 -07:00
|
|
|
static BOOL _runLoadSave (BOOL bResetMissionWidgets);
|
2006-12-02 06:38:09 -08:00
|
|
|
static void displayLoadBanner (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UDWORD *pColours);
|
|
|
|
static void displayLoadSlot (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UDWORD *pColours);
|
|
|
|
static void displayLoadSaveEdit (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UDWORD *pColours);
|
2007-06-28 10:47:08 -07:00
|
|
|
void removeWildcards (char *pStr);
|
|
|
|
|
|
|
|
static W_SCREEN *psRequestScreen; // Widget screen for requester
|
|
|
|
static BOOL mode;
|
|
|
|
static UDWORD chosenSlotId;
|
|
|
|
|
|
|
|
BOOL bLoadSaveUp = FALSE; // true when interface is up and should be run.
|
2006-11-03 13:35:50 -08:00
|
|
|
char saveGameName[256]; //the name of the save game to load from the front end
|
|
|
|
char sRequestResult[255]; // filename returned;
|
|
|
|
char sDelete[MAX_STR_LENGTH];
|
2007-06-28 10:47:08 -07:00
|
|
|
BOOL bRequestLoad = FALSE;
|
|
|
|
LOADSAVE_MODE bLoadSaveMode;
|
|
|
|
|
2006-11-03 17:11:26 -08:00
|
|
|
static char sPath[255];
|
|
|
|
static char sExt[4];
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// return whether the save screen was displayed in the mission results screen
|
|
|
|
BOOL saveInMissionRes(void)
|
|
|
|
{
|
|
|
|
return bLoadSaveMode == SAVE_MISSIONEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// return whether the save screen was displayed in the middle of a mission
|
|
|
|
BOOL saveMidMission(void)
|
|
|
|
{
|
|
|
|
return bLoadSaveMode == SAVE_INGAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
2007-04-09 15:09:27 -07:00
|
|
|
BOOL addLoadSave(LOADSAVE_MODE mode, const char *sSearchPath, const char *sExtension, const char *title)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
BOOL bLoad;
|
|
|
|
|
|
|
|
bLoadSaveMode = mode;
|
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case LOAD_FRONTEND:
|
|
|
|
case LOAD_MISSIONEND:
|
|
|
|
case LOAD_INGAME:
|
|
|
|
case LOAD_FORCE:
|
|
|
|
bLoad = TRUE;
|
|
|
|
break;
|
|
|
|
case SAVE_MISSIONEND:
|
|
|
|
case SAVE_INGAME:
|
|
|
|
case SAVE_FORCE:
|
|
|
|
default:
|
|
|
|
bLoad = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _addLoadSave(bLoad,sSearchPath,sExtension,title);
|
|
|
|
}
|
|
|
|
//****************************************************************************************
|
|
|
|
// Load menu/save menu?
|
|
|
|
//*****************************************************************************************
|
2007-04-09 15:09:27 -07:00
|
|
|
static BOOL _addLoadSave(BOOL bLoad, const char *sSearchPath, const char *sExtension, const char *title)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
W_FORMINIT sFormInit;
|
|
|
|
W_BUTINIT sButInit;
|
|
|
|
W_LABINIT sLabInit;
|
|
|
|
UDWORD slotCount;
|
|
|
|
// removed hardcoded values! change with the defines above! -Q
|
2006-11-03 13:35:50 -08:00
|
|
|
static char sSlots[totalslots][totalslotspace];
|
2007-06-28 10:47:08 -07:00
|
|
|
char **i, **files;
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
mode = bLoad;
|
2006-08-06 03:23:39 -07:00
|
|
|
debug(LOG_WZ, "_addLoadSave(%d, %s, %s, %s)", bLoad, sSearchPath, sExtension, title);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME))
|
|
|
|
{
|
|
|
|
if (!bMultiPlayer || (NetPlay.bComms ==0))
|
|
|
|
{
|
|
|
|
gameTimeStop();
|
|
|
|
if(GetGameMode() == GS_NORMAL)
|
2006-05-27 09:37:17 -07:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
BOOL radOnScreen = radarOnScreen; // Only do this in main game.
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
bRender3DOnly = TRUE;
|
|
|
|
radarOnScreen = FALSE;
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
displayWorld(); // Just display the 3d, no interface
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_UploadDisplayBuffer(DisplayBuffer); // Upload the current display back buffer into system memory.
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
radarOnScreen = radOnScreen;
|
|
|
|
bRender3DOnly = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
setGamePauseStatus( TRUE );
|
|
|
|
setGameUpdatePause(TRUE);
|
|
|
|
setScriptPause(TRUE);
|
|
|
|
setScrollPause(TRUE);
|
|
|
|
setConsolePause(TRUE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
forceHidePowerBar();
|
|
|
|
intRemoveReticule();
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) PHYSFS_mkdir(sSearchPath); // just in case
|
|
|
|
|
|
|
|
widgCreateScreen(&psRequestScreen); // init the screen.
|
|
|
|
widgSetTipFont(psRequestScreen,WFont);
|
|
|
|
|
|
|
|
/* add a form to place the tabbed form on */
|
|
|
|
memset(&sFormInit, 0, sizeof(W_FORMINIT));
|
|
|
|
sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q
|
|
|
|
sFormInit.id = LOADSAVE_FORM;
|
|
|
|
sFormInit.style = WFORM_PLAIN;
|
|
|
|
sFormInit.x = (SWORD)(LOADSAVE_X);
|
|
|
|
sFormInit.y = (SWORD)(LOADSAVE_Y);
|
|
|
|
sFormInit.width = LOADSAVE_W;
|
|
|
|
sFormInit.height = (LOADSAVE_H*2)-46; // hmm..the bottom of the box.... -Q
|
|
|
|
sFormInit.disableChildren = TRUE;
|
|
|
|
sFormInit.pDisplay = intOpenPlainForm;
|
|
|
|
widgAddForm(psRequestScreen, &sFormInit);
|
|
|
|
|
|
|
|
// Add Banner
|
|
|
|
sFormInit.formID = LOADSAVE_FORM;
|
|
|
|
sFormInit.id = LOADSAVE_BANNER;
|
|
|
|
sFormInit.x = LOADSAVE_HGAP;
|
|
|
|
sFormInit.y = LOADSAVE_VGAP;
|
|
|
|
sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP);
|
|
|
|
sFormInit.height = LOADSAVE_BANNER_DEPTH;
|
|
|
|
sFormInit.disableChildren = FALSE;
|
|
|
|
sFormInit.pDisplay = displayLoadBanner;
|
2006-09-13 02:09:05 -07:00
|
|
|
sFormInit.pUserData = (void *)bLoad;
|
2007-06-28 10:47:08 -07:00
|
|
|
widgAddForm(psRequestScreen, &sFormInit);
|
|
|
|
|
|
|
|
|
|
|
|
// Add Banner Label
|
|
|
|
memset(&sLabInit, 0, sizeof(W_LABINIT));
|
|
|
|
sLabInit.formID = LOADSAVE_BANNER;
|
|
|
|
sLabInit.id = LOADSAVE_LABEL;
|
|
|
|
sLabInit.style = WLAB_ALIGNCENTRE;
|
|
|
|
sLabInit.x = 0;
|
|
|
|
sLabInit.y = 3;
|
|
|
|
sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W;
|
|
|
|
sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q
|
|
|
|
sLabInit.pText = title;
|
|
|
|
sLabInit.FontID = WFont;
|
|
|
|
widgAddLabel(psRequestScreen, &sLabInit);
|
|
|
|
|
|
|
|
|
|
|
|
// add cancel.
|
|
|
|
memset(&sButInit, 0, sizeof(W_BUTINIT));
|
|
|
|
sButInit.formID = LOADSAVE_BANNER;
|
|
|
|
sButInit.x = 8;
|
|
|
|
sButInit.y = 8;
|
|
|
|
sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER);
|
|
|
|
sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER);
|
|
|
|
sButInit.pUserData = (void*)PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER);
|
|
|
|
|
|
|
|
sButInit.id = LOADSAVE_CANCEL;
|
|
|
|
sButInit.style = WBUT_PLAIN;
|
2007-04-01 13:15:46 -07:00
|
|
|
sButInit.pTip = _("Close");
|
2007-06-28 10:47:08 -07:00
|
|
|
sButInit.FontID = WFont;
|
|
|
|
sButInit.pDisplay = intDisplayImageHilight;
|
|
|
|
widgAddButton(psRequestScreen, &sButInit);
|
|
|
|
|
|
|
|
// add slots
|
|
|
|
memset(&sButInit, 0, sizeof(W_BUTINIT));
|
|
|
|
sButInit.formID = LOADSAVE_FORM;
|
|
|
|
sButInit.style = WBUT_PLAIN;
|
|
|
|
sButInit.width = LOADENTRY_W;
|
|
|
|
sButInit.height = LOADENTRY_H;
|
|
|
|
sButInit.pDisplay = displayLoadSlot;
|
|
|
|
sButInit.FontID = WFont;
|
|
|
|
|
|
|
|
for(slotCount = 0; slotCount< totalslots; slotCount++)
|
|
|
|
{
|
|
|
|
sButInit.id = slotCount+LOADENTRY_START;
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
if(slotCount<(totalslots/2))
|
|
|
|
{
|
|
|
|
sButInit.x = LOADSAVE_HGAP;
|
|
|
|
sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + (
|
|
|
|
slotCount*(LOADSAVE_VGAP+LOADENTRY_H)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sButInit.x = (2*LOADSAVE_HGAP)+LOADENTRY_W;
|
|
|
|
sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + (
|
|
|
|
(slotCount-(totalslots/2)) *(LOADSAVE_VGAP+LOADENTRY_H)));
|
|
|
|
}
|
|
|
|
widgAddButton(psRequestScreen, &sButInit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// fill slots.
|
|
|
|
slotCount = 0;
|
|
|
|
|
|
|
|
strcpy(sPath,sSearchPath); // setup locals.
|
|
|
|
strcpy(sExt,sExtension);
|
|
|
|
|
|
|
|
debug(LOG_WZ, "_addLoadSave: Searching \"%s\" for savegames", sSearchPath);
|
|
|
|
|
|
|
|
// add savegame filenames minus extensions to buttons (up to max 10)
|
|
|
|
files = PHYSFS_enumerateFiles(sSearchPath);
|
|
|
|
for (i = files; *i != NULL; i++) {
|
|
|
|
W_BUTTON *button;
|
|
|
|
|
2006-08-06 03:23:39 -07:00
|
|
|
if (!strstr(*i, sExtension)) {
|
2007-06-28 10:47:08 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount);
|
|
|
|
|
|
|
|
debug(LOG_WZ, "_addLoadSave: We found [%s]", *i);
|
|
|
|
/* Set the tip and add the button */
|
|
|
|
(*i)[strlen(*i) - 4] = '\0'; // remove .gam extension
|
|
|
|
strcpy(sSlots[slotCount], *i); //store it!
|
|
|
|
button->pTip = sSlots[slotCount];
|
|
|
|
button->pText = sSlots[slotCount];
|
|
|
|
slotCount++; // goto next but...
|
|
|
|
if (slotCount == totalslots) {
|
|
|
|
break; // only show up to 10 entries
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PHYSFS_freeList(files);
|
|
|
|
|
|
|
|
bLoadSaveUp = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL closeLoadSave(void)
|
|
|
|
{
|
|
|
|
widgDelete(psRequestScreen,LOADSAVE_FORM);
|
|
|
|
bLoadSaveUp = FALSE;
|
|
|
|
|
|
|
|
if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!bMultiPlayer || (NetPlay.bComms == 0))
|
|
|
|
{
|
|
|
|
gameTimeStart();
|
|
|
|
setGamePauseStatus( FALSE );
|
|
|
|
setGameUpdatePause(FALSE);
|
|
|
|
setScriptPause(FALSE);
|
|
|
|
setScrollPause(FALSE);
|
|
|
|
setConsolePause(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
intAddReticule();
|
|
|
|
intShowPowerBar();
|
|
|
|
|
|
|
|
}
|
|
|
|
widgReleaseScreen(psRequestScreen);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL runLoadSave(BOOL bResetMissionWidgets)
|
|
|
|
{
|
|
|
|
return _runLoadSave(bResetMissionWidgets);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
Delete a savegame. saveGameName should be a .gam extension save game
|
2006-05-27 09:37:17 -07:00
|
|
|
filename reference. We delete this file, any .es file with the same
|
2007-06-28 10:47:08 -07:00
|
|
|
name, and any files in the directory with the same name.
|
|
|
|
***************************************************************************/
|
|
|
|
void deleteSaveGame(char* saveGameName)
|
|
|
|
{
|
|
|
|
char **files, **i;
|
|
|
|
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( strlen(saveGameName) < MAX_STR_LENGTH,"deleteSaveGame; save game name too long" );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-05-27 09:37:17 -07:00
|
|
|
PHYSFS_delete(saveGameName);
|
2007-06-28 10:47:08 -07:00
|
|
|
saveGameName[strlen(saveGameName)-4] = '\0';// strip extension
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
strcat(saveGameName,".es"); // remove script data if it exists.
|
2006-05-27 09:37:17 -07:00
|
|
|
PHYSFS_delete(saveGameName);
|
2007-06-28 10:47:08 -07:00
|
|
|
saveGameName[strlen(saveGameName)-3] = '\0';// strip extension
|
|
|
|
|
|
|
|
// check for a directory and remove that too.
|
|
|
|
files = PHYSFS_enumerateFiles(saveGameName);
|
|
|
|
for (i = files; *i != NULL; i++) {
|
|
|
|
debug(LOG_WZ, "Deleting [%s].", *i);
|
|
|
|
PHYSFS_delete(*i);
|
|
|
|
}
|
|
|
|
PHYSFS_freeList(files);
|
|
|
|
PHYSFS_delete(saveGameName); // now empty directory
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Returns TRUE if cancel pressed or a valid game slot was selected.
|
|
|
|
// if when returning TRUE strlen(sRequestResult) != 0 then a valid game
|
|
|
|
// slot was selected otherwise cancel was selected..
|
|
|
|
static BOOL _runLoadSave(BOOL bResetMissionWidgets)
|
|
|
|
{
|
|
|
|
UDWORD id=0;
|
|
|
|
W_EDBINIT sEdInit;
|
2006-11-03 17:11:26 -08:00
|
|
|
char sTemp[MAX_STR_LENGTH];
|
2006-07-20 14:04:01 -07:00
|
|
|
UDWORD i;
|
2007-06-28 10:47:08 -07:00
|
|
|
W_CONTEXT context;
|
|
|
|
BOOL bSkipCD = FALSE;
|
|
|
|
|
|
|
|
id = widgRunScreen(psRequestScreen);
|
|
|
|
|
|
|
|
strcpy(sRequestResult,""); // set returned filename to null;
|
|
|
|
|
|
|
|
// cancel this operation...
|
|
|
|
if(id == LOADSAVE_CANCEL || CancelPressed() )
|
|
|
|
{
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
// clicked a load entry
|
|
|
|
if( id >= LOADENTRY_START && id <= LOADENTRY_END )
|
|
|
|
{
|
|
|
|
|
|
|
|
if(mode) // Loading, return that entry.
|
|
|
|
{
|
|
|
|
if( ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText )
|
|
|
|
{
|
|
|
|
sprintf(sRequestResult,"%s%s.%s",sPath, ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText ,sExt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto failure; // clicked on an empty box
|
|
|
|
}
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
if( bLoadSaveMode == LOAD_FORCE || bLoadSaveMode ==SAVE_FORCE )
|
2006-05-27 09:37:17 -07:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
goto successforce; // it's a force, dont check the cd.
|
|
|
|
}
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
else // SAVING!add edit box at that position.
|
|
|
|
{
|
|
|
|
|
|
|
|
if( ! widgGetFromID(psRequestScreen,SAVEENTRY_EDIT))
|
|
|
|
{
|
|
|
|
// add blank box.
|
|
|
|
memset(&sEdInit, 0, sizeof(W_EDBINIT));
|
|
|
|
sEdInit.formID= LOADSAVE_FORM;
|
|
|
|
sEdInit.id = SAVEENTRY_EDIT;
|
|
|
|
sEdInit.style = WEDB_PLAIN;
|
|
|
|
sEdInit.x = widgGetFromID(psRequestScreen,id)->x;
|
|
|
|
sEdInit.y = widgGetFromID(psRequestScreen,id)->y;
|
|
|
|
sEdInit.width = widgGetFromID(psRequestScreen,id)->width;
|
|
|
|
sEdInit.height= widgGetFromID(psRequestScreen,id)->height;
|
2006-05-27 09:37:17 -07:00
|
|
|
sEdInit.pText = ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText;
|
2007-06-28 10:47:08 -07:00
|
|
|
sEdInit.FontID= WFont;
|
|
|
|
sEdInit.pBoxDisplay = displayLoadSaveEdit;
|
|
|
|
widgAddEditBox(psRequestScreen, &sEdInit);
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
sprintf(sTemp,"%s%s.%s",
|
|
|
|
sPath,
|
|
|
|
((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText ,
|
|
|
|
sExt);
|
|
|
|
|
|
|
|
widgHide(psRequestScreen,id); // hide the old button
|
2006-05-27 09:37:17 -07:00
|
|
|
chosenSlotId = id;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
strcpy(sDelete,sTemp); // prepare the savegame name.
|
|
|
|
sTemp[strlen(sTemp)-4] = '\0'; // strip extension
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
// auto click in the edit box we just made.
|
|
|
|
context.psScreen = psRequestScreen;
|
|
|
|
context.psForm = (W_FORM *)psRequestScreen->psForm;
|
|
|
|
context.xOffset = 0;
|
|
|
|
context.yOffset = 0;
|
|
|
|
context.mx = mouseX();
|
|
|
|
context.my = mouseY();
|
|
|
|
editBoxClicked((W_EDITBOX*)widgGetFromID(psRequestScreen,SAVEENTRY_EDIT), &context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// clicked in a different box. shouldnt be possible!(since we autoclicked in editbox)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finished entering a name.
|
2006-05-27 09:37:17 -07:00
|
|
|
if( id == SAVEENTRY_EDIT)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2006-05-27 09:37:17 -07:00
|
|
|
if(!keyPressed(KEY_RETURN)) // enter was not pushed, so not a vaild entry.
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back ..
|
|
|
|
widgReveal(psRequestScreen,chosenSlotId);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// scan to see if that game exists in another slot, if
|
|
|
|
// so then fail.
|
|
|
|
strcpy(sTemp,((W_EDITBOX *)widgGetFromID(psRequestScreen,id))->aText);
|
|
|
|
|
|
|
|
for(i=LOADENTRY_START;i<LOADENTRY_END;i++)
|
|
|
|
{
|
|
|
|
if( i != chosenSlotId)
|
|
|
|
{
|
2006-05-27 09:37:17 -07:00
|
|
|
|
|
|
|
if( ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText
|
2007-06-28 10:47:08 -07:00
|
|
|
&& strcmp( sTemp, ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText ) ==0)
|
2006-05-27 09:37:17 -07:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back ..
|
|
|
|
widgReveal(psRequestScreen,chosenSlotId);
|
|
|
|
// move mouse to same box..
|
|
|
|
// SetMousePos(widgGetFromID(psRequestScreen,i)->x ,widgGetFromID(psRequestScreen,i)->y);
|
|
|
|
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return with this name, as we've edited it.
|
|
|
|
if (strlen(((W_EDITBOX *)widgGetFromID(psRequestScreen,id))->aText))
|
|
|
|
{
|
|
|
|
strcpy(sTemp,((W_EDITBOX *)widgGetFromID(psRequestScreen,id))->aText);
|
|
|
|
removeWildcards(sTemp);
|
|
|
|
sprintf(sRequestResult,"%s%s.%s",
|
|
|
|
sPath,
|
|
|
|
sTemp,
|
|
|
|
sExt);
|
|
|
|
deleteSaveGame(sDelete); //only delete game if a new game fills the slot
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto failure; // we entered a blank name..
|
|
|
|
}
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
// we're done. saving.
|
|
|
|
closeLoadSave();
|
|
|
|
bRequestLoad = FALSE;
|
2007-02-10 08:39:39 -08:00
|
|
|
if (bResetMissionWidgets && widgGetFromID(psWScreen,IDMISSIONRES_FORM) == NULL)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
resetMissionWidgets(); //reset the mission widgets here if necessary
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// failed and/or cancelled..
|
|
|
|
failure:
|
|
|
|
closeLoadSave();
|
|
|
|
bRequestLoad = FALSE;
|
2007-02-10 08:39:39 -08:00
|
|
|
if (bResetMissionWidgets && widgGetFromID(psWScreen,IDMISSIONRES_FORM) == NULL)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
resetMissionWidgets();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// success on load.
|
|
|
|
success:
|
|
|
|
setCampaignNumber( getCampaign(sRequestResult,&bSkipCD) );
|
|
|
|
successforce:
|
2006-05-27 09:37:17 -07:00
|
|
|
closeLoadSave();
|
2007-06-28 10:47:08 -07:00
|
|
|
bRequestLoad = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// should be done when drawing the other widgets.
|
|
|
|
BOOL displayLoadSave(void)
|
|
|
|
{
|
|
|
|
widgDisplayScreen(psRequestScreen); // display widgets.
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
2006-11-03 13:35:50 -08:00
|
|
|
// char HANDLER, replaces dos wildcards in a string with harmless chars.
|
2007-06-28 10:47:08 -07:00
|
|
|
void removeWildcards(char *pStr)
|
|
|
|
{
|
|
|
|
UDWORD i;
|
|
|
|
|
|
|
|
for(i=0;i<strlen(pStr);i++)
|
|
|
|
{
|
2006-05-27 09:37:17 -07:00
|
|
|
/* if( pStr[i] == '?'
|
2007-06-28 10:47:08 -07:00
|
|
|
|| pStr[i] == '*'
|
|
|
|
|| pStr[i] == '"'
|
2006-05-27 09:37:17 -07:00
|
|
|
|| pStr[i] == '.'
|
|
|
|
|| pStr[i] == '/'
|
2007-06-28 10:47:08 -07:00
|
|
|
|| pStr[i] == '\\'
|
|
|
|
|| pStr[i] == '|' )
|
|
|
|
{
|
|
|
|
pStr[i] = '_';
|
|
|
|
}
|
|
|
|
*/
|
2006-05-27 09:37:17 -07:00
|
|
|
if( !isalnum(pStr[i])
|
2007-06-28 10:47:08 -07:00
|
|
|
&& pStr[i] != ' '
|
|
|
|
&& pStr[i] != '-'
|
|
|
|
&& pStr[i] != '+'
|
|
|
|
&& pStr[i] != '!'
|
|
|
|
)
|
|
|
|
{
|
|
|
|
pStr[i] = '_';
|
|
|
|
}
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(pStr) >= MAX_SAVE_NAME)
|
|
|
|
{
|
|
|
|
pStr[MAX_SAVE_NAME - 1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
// DISPLAY FUNCTIONS
|
|
|
|
|
2006-12-02 06:38:09 -08:00
|
|
|
static void displayLoadBanner(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UDWORD *pColours)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//UDWORD col;
|
|
|
|
UBYTE col;
|
|
|
|
UDWORD x = xOffset+psWidget->x;
|
|
|
|
UDWORD y = yOffset+psWidget->y;
|
|
|
|
|
|
|
|
if(psWidget->pUserData)
|
|
|
|
{
|
|
|
|
col = COL_GREEN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
col = COL_RED;
|
|
|
|
}
|
|
|
|
|
|
|
|
iV_BoxFill(x,y,x+psWidget->width,y+psWidget->height,col);
|
|
|
|
iV_BoxFill(x+2,y+2,x+psWidget->width-2,y+psWidget->height-2,COL_BLUE);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
2006-12-02 06:38:09 -08:00
|
|
|
static void displayLoadSlot(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UDWORD *pColours)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD x = xOffset+psWidget->x;
|
|
|
|
UDWORD y = yOffset+psWidget->y;
|
|
|
|
// UWORD im = (UWORD)UNPACKDWORD_TRI_B((UDWORD)psWidget->pUserData);
|
|
|
|
// UWORD im2= (UWORD)(UNPACKDWORD_TRI_C((UDWORD)psWidget->pUserData));
|
2006-11-03 13:35:50 -08:00
|
|
|
char butString[64];
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
drawBlueBox(x,y,psWidget->width,psWidget->height); //draw box
|
|
|
|
|
|
|
|
if(((W_BUTTON *)psWidget)->pTip )
|
|
|
|
{
|
|
|
|
strcpy(butString,((W_BUTTON *)psWidget)->pTip);
|
2006-05-27 09:37:17 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
iV_SetFont(WFont); // font
|
|
|
|
iV_SetTextColour(-1); //colour
|
|
|
|
|
|
|
|
while(iV_GetTextWidth(butString) > psWidget->width)
|
|
|
|
{
|
|
|
|
butString[strlen(butString)-1]='\0';
|
|
|
|
}
|
|
|
|
|
2006-05-27 09:37:17 -07:00
|
|
|
//draw text
|
2007-06-28 10:47:08 -07:00
|
|
|
iV_DrawText( butString, x+4, y+17);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
2006-12-02 06:38:09 -08:00
|
|
|
static void displayLoadSaveEdit(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UDWORD *pColours)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
UDWORD x = xOffset+psWidget->x;
|
|
|
|
UDWORD y = yOffset+psWidget->y;
|
|
|
|
UDWORD w = psWidget->width;
|
|
|
|
UDWORD h = psWidget->height;
|
|
|
|
|
|
|
|
iV_BoxFill(x,y,x+w,y+h,COL_RED);
|
|
|
|
iV_BoxFill(x+1,y+1,x+w-1,y+h-1,COL_BLUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
|
|
void drawBlueBox(UDWORD x,UDWORD y, UDWORD w, UDWORD h)
|
|
|
|
{
|
|
|
|
UBYTE dark = COL_BLUE;
|
|
|
|
UBYTE light = COL_LIGHTBLUE;
|
|
|
|
|
|
|
|
// box
|
2006-05-27 09:37:17 -07:00
|
|
|
pie_BoxFillIndex(x-1,y-1,x+w+1,y+h+1,light);
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_BoxFillIndex(x,y,x+w,y+h,dark);
|
|
|
|
}
|
|
|
|
|
2006-08-23 05:58:48 -07:00
|
|
|
|
|
|
|
|
2007-02-10 08:39:39 -08:00
|
|
|
|