forked from yasumitsu/ja2-1.13-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveLoadScreen.cpp
3003 lines (2473 loc) · 86.4 KB
/
SaveLoadScreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef PRECOMPILEDHEADERS
#include "JA2 All.h"
#else
#include "Types.h"
#include "SaveLoadScreen.h"
#include "Video.h"
#include "Font Control.h"
#include "Game Clock.h"
#include "Render Dirty.h"
#include "Text Input.h"
#include "SaveLoadGame.h"
#include "Stdio.h"
#include "WordWrap.h"
#include "StrategicMap.h"
#include "Finances.h"
#include "WCheck.h"
#include "Utilities.h"
#include "Cursors.h"
#include "VObject.h"
#include "Merc Hiring.h"
#include "LaptopSave.h"
#include "Options Screen.h"
#include "GameVersion.h"
#include "SysUtil.h"
#include "Tactical Save.h"
#include "OverHead.h"
#include "gamescreen.h"
#include "GameSettings.h"
#include "fade screen.h"
#include "English.h"
#include "Gameloop.h"
#include "Game Init.h"
#include "Text.h"
#include "Message.h"
#include "Map Screen Interface.h"
#include "Multi Language Graphic Utils.h"
#include "Campaign Types.h"
#include "PostalService.h"
#endif
#include "connect.h"
#include "FileMan.h"
#include <vfs/Core/vfs.h>
#include <vfs/Core/vfs_file_raii.h>
#ifdef JA2UB
#include "Strategic Movement.h"
//#include "Strategic Movement Costs.h"
#include "LuaInitNPCs.h"
#endif
BOOLEAN gfSchedulesHosed = FALSE;
extern UINT32 guiBrokenSaveGameVersion;
UINT16 NUM_SLOT;
//////////////////////////////////////////////////////
//
// Defines
//
//////////////////////////////////////////////////////
#define SAVE_LOAD_TITLE_FONT FONT14ARIAL
#define SAVE_LOAD_TITLE_COLOR FONT_MCOLOR_WHITE
#define SAVE_LOAD_NORMAL_FONT FONT12ARIAL
#define SAVE_LOAD_NORMAL_COLOR FONT_GRAY2
#define SAVE_LOAD_NORMAL_SHADOW_COLOR FONT_NEARBLACK
#define SAVE_LOAD_QUICKSAVE_FONT FONT12ARIAL
#define SAVE_LOAD_QUICKSAVE_COLOR 2
#define SAVE_LOAD_QUICKSAVE_SHADOW_COLOR 189
#define SAVE_LOAD_EMPTYSLOT_FONT FONT12ARIAL
#define SAVE_LOAD_EMPTYSLOT_COLOR 2
#define SAVE_LOAD_EMPTYSLOT_SHADOW_COLOR 189
#define SAVE_LOAD_HIGHLIGHTED_FONT FONT12ARIAL
#define SAVE_LOAD_HIGHLIGHTED_COLOR FONT_MCOLOR_WHITE
#define SAVE_LOAD_HIGHLIGHTED_SHADOW_COLOR 2
#define SAVE_LOAD_SELECTED_FONT FONT12ARIAL
#define SAVE_LOAD_SELECTED_COLOR 2
#define SAVE_LOAD_SELECTED_SHADOW_COLOR 130
#define SAVE_LOAD_NUMBER_FONT FONT12ARIAL
#define SAVE_LOAD_NUMBER_COLOR FONT_MCOLOR_WHITE
#define SLG_SELECTED_COLOR FONT_MCOLOR_WHITE
#define SLG_UNSELECTED_COLOR FONT_MCOLOR_DKWHITE
#define SLG_SAVELOCATION_WIDTH 605
#define SLG_FIRST_SAVED_SPOT_X iScreenWidthOffset + 17
#define SLG_FIRST_SAVED_SPOT_Y iScreenHeightOffset + 49
#define SLG_DATE_OFFSET_X 13
#define SLG_SECTOR_OFFSET_X 95
#define SLG_SECTOR_OFFSET_Y SLG_DATE_OFFSET_Y
#define SLG_SECTOR_WIDTH 98
#define SLG_NUM_MERCS_OFFSET_X 196
#define SLG_NUM_MERCS_OFFSET_Y SLG_DATE_OFFSET_Y
#define SLG_BALANCE_OFFSET_X 260
#define SLG_BALANCE_OFFSET_Y SLG_DATE_OFFSET_Y
#define SLG_SAVE_GAME_DESC_X 318
#define SLG_SAVE_GAME_DESC_Y SLG_DATE_OFFSET_Y
#define SLG_TITLE_POS_X iScreenWidthOffset
#define SLG_TITLE_POS_Y iScreenHeightOffset
#define SLG_SAVE_CANCEL_POS_X iScreenWidthOffset + 226
#define SLG_LOAD_CANCEL_POS_X iScreenWidthOffset + 329
#define SLG_CANCEL_POS_Y iScreenHeightOffset + 438
#define SLG_SAVE_LOAD_BTN_POS_X iScreenWidthOffset + 123
#define SLG_SAVE_LOAD_BTN_POS_Y iScreenHeightOffset + 438
#define SLG_SAVE_LOAD_PAGE_POS_X SLG_SAVE_LOAD_BTN_POS_X + 195
#define SLG_SAVE_LOAD_PAGE_POS_Y SLG_SAVE_LOAD_BTN_POS_Y + 10
#define SLG_DOUBLE_CLICK_DELAY 500
//defines for saved game version status
enum
{
SLS_HEADER_OK,
SLS_SAVED_GAME_VERSION_OUT_OF_DATE,
SLS_GAME_VERSION_OUT_OF_DATE,
SLS_BOTH_SAVE_GAME_AND_GAME_VERSION_OUT_OF_DATE,
};
//////////////////////////////////////////////////////
//
// Global Variables
//
//////////////////////////////////////////////////////
extern void NextLoopCheckForEnoughFreeHardDriveSpace();
BOOLEAN gfSaveLoadScreenEntry = TRUE;
BOOLEAN gfSaveLoadScreenExit = FALSE;
BOOLEAN gfRedrawSaveLoadScreen = TRUE;
BOOLEAN gfExitAfterMessageBox = FALSE;
INT32 giSaveLoadMessageBox = -1; // SaveLoad pop up messages index value
UINT32 guiSaveLoadExitScreen = SAVE_LOAD_SCREEN;
//Contains the array of valid save game locations
BOOLEAN gbSaveGameArray[ NUM_SAVE_GAMES ];
// anv: read times of modification to show them later
SYSTEMTIME gstSaveGameCreationTimeArray[ NUM_SAVE_GAMES ];
BOOLEAN gfDoingQuickLoad = FALSE;
BOOLEAN gfFailedToSaveGameWhenInsideAMessageBox = FALSE;
//This flag is used to diferentiate between loading a game and saveing a game.
// gfSaveGame=TRUE For saving a game
// gfSaveGame=FALSE For loading a game
BOOLEAN gfSaveGame=TRUE;
BOOLEAN gfSaveLoadScreenButtonsCreated = FALSE;
INT8 gbSaveGameSelectedLocation[ NUM_SAVE_GAMES ];
INT32 gbSelectedSaveLocation=-1;
INT8 gbHighLightedLocation=-1;
INT8 gbLastHighLightedLocation=-1;
INT32 gbSetSlotToBeSelected=-1;
UINT32 guiSlgBackGroundImage;
UINT32 guiBackGroundAddOns;
UINT32 guiBackGroundAddOns_New;
UINT32 SLG_SAVELOCATION_HEIGHT;
UINT32 SLG_GAP_BETWEEN_LOCATIONS;
UINT32 SLG_DATE_OFFSET_Y;
UINT32 SLG_SELECTED_SLOT_GRAPHICS_NUMBER;
UINT32 SLG_UNSELECTED_SLOT_GRAPHICS_NUMBER;
// The string that will contain the game desc text
CHAR16 gzGameDescTextField[ SIZE_OF_SAVE_GAME_DESC ] = {0} ;
BOOLEAN gfUserInTextInputMode = FALSE;
UINT8 gubSaveGameNextPass=0;
BOOLEAN gfStartedFadingOut = FALSE;
BOOLEAN gfCameDirectlyFromGame = FALSE;
BOOLEAN gfLoadedGame = FALSE; //Used to know when a game has been loaded, the flag in gtacticalstatus might have been reset already
BOOLEAN gfLoadGameUponEntry = FALSE;
BOOLEAN gfGettingNameFromSaveLoadScreen = FALSE;
#ifdef JA2BETAVERSION
extern BOOLEAN gfDisplaySaveGamesNowInvalidatedMsg;
#endif
//
//Buttons
//
INT32 guiSlgButtonImage;
// Cancel Button
void BtnSlgCancelCallback(GUI_BUTTON *btn,INT32 reason);
UINT32 guiSlgCancelBtn;
// Save game Button
void BtnSlgSaveLoadCallback(GUI_BUTTON *btn,INT32 reason);
UINT32 guiSlgSaveLoadBtn;
INT32 guiSaveLoadImage;
INT32 guiNewButtonImage;
INT32 guiPrevButton, guiNextButton;
void BtnNewPrevButtonCallback(GUI_BUTTON *btn,INT32 reason);
void BtnNewNextButtonCallback(GUI_BUTTON *btn,INT32 reason);
UINT16 PAGE_SLOT = 0;
UINT16 VAL_SLOT_START = 0;
UINT16 VAL_SLOT_END = 0;
BOOLEAN RenderImage = TRUE;
BOOLEAN DoAutoSave( int ubSaveGameID, STR16 pGameDesc );
BOOLEAN AutoSaveToSlot[5];
// WANNE: Used For auto save games
UINT32 lastLoadedSaveGameDay = 0;
UINT8 lastLoadedSaveGameHour = 0;
#define MAX_PAGE_SLOT 12
//Mouse regions for the currently selected save game
MOUSE_REGION gSelectedSaveRegion[ NUM_SAVE_GAMES ];
void SelectedSaveRegionCallBack(MOUSE_REGION * pRegion, INT32 iReason );
void SelectedSaveRegionMovementCallBack(MOUSE_REGION * pRegion, INT32 reason );
MOUSE_REGION gSLSEntireScreenRegion;
void SelectedSLSEntireRegionCallBack(MOUSE_REGION * pRegion, INT32 iReason );
#ifdef JA2BETAVERSION
extern BOOLEAN ValidateSoldierInitLinks( UINT8 ubCode );
#endif
extern BOOLEAN fFirstTimeInGameScreen; // added by Flugente
//////////////////////////////////////////////////////
//
// Function Prototypes
//
//////////////////////////////////////////////////////
BOOLEAN EnterSaveLoadScreen();
void RenderSaveLoadScreen();
void ExitSaveLoadScreen();
void HandleSaveLoadScreen();
void GetSaveLoadScreenUserInput();
void SaveLoadGameNumber( INT32 bSaveGameID );
BOOLEAN LoadSavedGameHeader( INT32 bEntry, SAVED_GAME_HEADER *pSaveGameHeader );
BOOLEAN DisplaySaveGameEntry( INT32 bEntryID );//, UINT16 usPosY );
BOOLEAN DisplaySaveGameList();
void InitSaveLoadScreenTextInputBoxes();
void DestroySaveLoadTextInputBoxes();
void SetSelection( UINT8 ubNewSelection );
UINT8 CompareSaveGameVersion( INT32 bSaveGameID );
void LoadSavedGameWarningMessageBoxCallBack( UINT8 bExitValue );
void LoadSavedGameDeleteAllSaveGameMessageBoxCallBack( UINT8 bExitValue );
void DeleteAllSaveGameFile( );
void DisplayOnScreenNumber( BOOLEAN fErase );
void DisableSelectedSlot();
void ConfirmSavedGameMessageBoxCallBack( UINT8 bExitValue );
void ConfirmLoadSavedGameMessageBoxCallBack( UINT8 bExitValue );
void FailedLoadingGameCallBack( UINT8 bExitValue );
void SetSaveLoadExitScreen( UINT32 uiScreen );
void NotEnoughHardDriveSpaceForQuickSaveMessageBoxCallBack( UINT8 bExitValue );
void NotEnoughHardDriveSpaceForNormalSaveMessageBoxCallBack( UINT8 bExitValue );
void RedrawSaveLoadScreenAfterMessageBox( UINT8 bExitValue );
void ClearSelectedSaveSlot();
void MoveSelectionUpOrDown( BOOLEAN fUp );
void SaveGameToSlotNum();
void StartFadeOutForSaveLoadScreen();
#ifdef JA2UB
extern void MakeBadSectorListFromMapsOnHardDrive( BOOLEAN fDisplayMessages ); // ja25 UB
#endif
//////////////////////////////////////////////////////
//
// Code
//
//////////////////////////////////////////////////////
void LoadSaveGameOldOrNew()
{
if (gGameExternalOptions.fSaveGameSlot == TRUE)
{
NUM_SLOT = NUM_SAVE_GAMES_NEW;
SLG_SAVELOCATION_HEIGHT = 15;
SLG_GAP_BETWEEN_LOCATIONS = 20;
SLG_DATE_OFFSET_Y = 5;
SLG_SELECTED_SLOT_GRAPHICS_NUMBER = 1;
SLG_UNSELECTED_SLOT_GRAPHICS_NUMBER = 0;
}
else
{
NUM_SLOT = NUM_SAVE_GAMES_OLD;
SLG_SAVELOCATION_HEIGHT = 30;
SLG_GAP_BETWEEN_LOCATIONS = 35;
SLG_DATE_OFFSET_Y = 11;
SLG_SELECTED_SLOT_GRAPHICS_NUMBER = 3;
SLG_UNSELECTED_SLOT_GRAPHICS_NUMBER = 2;
}
}
UINT32 SaveLoadScreenInit()
{
//Set so next time we come in, we can set up
gfSaveLoadScreenEntry = TRUE;
memset( gbSaveGameArray, -1, NUM_SAVE_GAMES);
ClearSelectedSaveSlot();
gbHighLightedLocation=-1;
return( TRUE );
}
UINT32 SaveLoadScreenHandle()
{
StartFrameBufferRender();
if( gfSaveLoadScreenEntry )
{
EnterSaveLoadScreen();
gfSaveLoadScreenEntry = FALSE;
gfSaveLoadScreenExit = FALSE;
PauseGame();
//save the new rect
BlitBufferToBuffer(guiRENDERBUFFER, guiSAVEBUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
}
RestoreBackgroundRects();
//to guarentee that we do not accept input when we are fading out
if( !gfStartedFadingOut )
{
GetSaveLoadScreenUserInput();
}
else
gfRedrawSaveLoadScreen = FALSE;
//if we have exited the save load screen, exit
if( !gfSaveLoadScreenButtonsCreated )
return( guiSaveLoadExitScreen );
RenderAllTextFields();
HandleSaveLoadScreen();
if( gfRedrawSaveLoadScreen )
{
RenderSaveLoadScreen();
MarkButtonsDirty( );
RenderButtons();
gfRedrawSaveLoadScreen = FALSE;
}
if( gubSaveGameNextPass != 0 )
{
gubSaveGameNextPass++;
if( gubSaveGameNextPass == 5 )
{
gubSaveGameNextPass = 0;
SaveLoadGameNumber( gbSelectedSaveLocation );
}
}
//If we are not exiting the screen, render the buttons
if( !gfSaveLoadScreenExit && guiSaveLoadExitScreen == SAVE_LOAD_SCREEN )
{
// render buttons marked dirty
RenderButtons( );
}
// ATE: Put here to save RECTS before any fast help being drawn...
SaveBackgroundRects( );
RenderButtonsFastHelp();
ExecuteBaseDirtyRectQueue( );
EndFrameBufferRender( );
if ( HandleFadeOutCallback( ) )
{
return( guiSaveLoadExitScreen );
}
if ( HandleBeginFadeOut( SAVE_LOAD_SCREEN ) )
{
return( SAVE_LOAD_SCREEN );
}
if( gfSaveLoadScreenExit )
{
ExitSaveLoadScreen();
}
if ( HandleFadeInCallback( ) )
{
// Re-render the scene!
RenderSaveLoadScreen();
}
if ( HandleBeginFadeIn( SAVE_LOAD_SCREEN ) )
{
}
return( guiSaveLoadExitScreen );
}
UINT32 SaveLoadScreenShutdown()
{
return( TRUE );
}
void SetSaveLoadExitScreen( UINT32 uiScreen )
{
if( uiScreen == GAME_SCREEN )
{
EnterTacticalScreen( );
}
gfSaveLoadScreenExit = TRUE;
guiSaveLoadExitScreen = uiScreen;
SetPendingNewScreen( uiScreen );
ExitSaveLoadScreen();
DestroySaveLoadTextInputBoxes();
}
void InitMSysButtons(BOOLEAN delRegion)
{
UINT16 usPosX = SLG_FIRST_SAVED_SPOT_X;
UINT16 usPosY = SLG_FIRST_SAVED_SPOT_Y;
UINT8 i;
CHAR16 zString[512];
CHAR16 zString2[512];
CHAR16 zString3[512];
if ( delRegion == TRUE )
{
for(i=0; i<NUM_SLOT; i++)
{
MSYS_RemoveRegion( &gSelectedSaveRegion[i]);
}
}
usPosX = SLG_FIRST_SAVED_SPOT_X;
usPosY = SLG_FIRST_SAVED_SPOT_Y;
for(i=0; i<NUM_SLOT; i++)
{
MSYS_DefineRegion( &gSelectedSaveRegion[i], usPosX, usPosY, (UINT16)(usPosX+SLG_SAVELOCATION_WIDTH), (UINT16)(usPosY+SLG_SAVELOCATION_HEIGHT), MSYS_PRIORITY_HIGH,
CURSOR_NORMAL, SelectedSaveRegionMovementCallBack, SelectedSaveRegionCallBack );
MSYS_AddRegion(&gSelectedSaveRegion[i]);
MSYS_SetRegionUserData( &gSelectedSaveRegion[ i ], 0, i);
if ( PAGE_SLOT == 0 && i == 0 )
{
swprintf( zString, pMessageStrings[MSG_SAVE_QUICKSAVE_SLOT] );
}
else if ( PAGE_SLOT == 0 && i >= SAVE__TIMED_AUTOSAVE_SLOT1 && i <= SAVE__TIMED_AUTOSAVE_SLOT5 )
{
swprintf( zString, pMessageStrings[MSG_SAVE_AUTOSAVE_SLOT], VAL_SLOT_START + i );
}
else if ( PAGE_SLOT == 0 && i >= SAVE__END_TURN_NUM_1 && i <= SAVE__END_TURN_NUM_2 )
{
swprintf( zString, pMessageStrings[MSG_SAVE_AUTOSAVE_ENDTURN_SLOT], VAL_SLOT_START - SAVE__TIMED_AUTOSAVE_SLOT5 - 1 + i );
}
else
{
swprintf( zString, pMessageStrings[MSG_SAVE_NORMAL_SLOT], VAL_SLOT_START + i - SAVE__END_TURN_NUM_2 );
}
// anv: add modification date
if( gbSaveGameArray[ VAL_SLOT_START + i ] )
{
swprintf( zString2, L"%04d", gstSaveGameCreationTimeArray[ VAL_SLOT_START + i ].wYear );
wcscpy( zString3, zString2 );
swprintf( zString2, L"/%02d", gstSaveGameCreationTimeArray[ VAL_SLOT_START + i ].wMonth );
wcscat( zString3, zString2 );
swprintf( zString2, L"/%02d ", gstSaveGameCreationTimeArray[ VAL_SLOT_START + i ].wDay );
wcscat( zString3, zString2 );
swprintf( zString2, L"%02d", gstSaveGameCreationTimeArray[ VAL_SLOT_START + i ].wHour );
wcscat( zString3, zString2 );
swprintf( zString2, L":%02d ", gstSaveGameCreationTimeArray[ VAL_SLOT_START + i ].wMinute );
wcscat( zString3, zString2 );
wcscat( zString3, zString );
wcscpy( zString, zString3 );
}
wcscpy( zString2,zString );
SetRegionFastHelpText( &gSelectedSaveRegion[ i ], zString2 );
//if we are to Load a game
if( !gfSaveGame )
{
//We cannot load a game that hasnt been saved
if( !gbSaveGameArray[ VAL_SLOT_START + i ] )
MSYS_DisableRegion( &gSelectedSaveRegion[ i ] );
}
usPosY += SLG_GAP_BETWEEN_LOCATIONS;
}
}
BOOLEAN NewEnterSaveLoadScreen()
{
VOBJECT_DESC VObjectDesc;
UINT16 usPosX = SLG_FIRST_SAVED_SPOT_X;
UINT16 usPosY = SLG_FIRST_SAVED_SPOT_Y;
RenderImage = FALSE;
if (guiBackGroundAddOns_New != -1)
DeleteVideoObjectFromIndex( guiBackGroundAddOns_New );
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
FilenameForBPP("INTERFACE\\LOADSCREENADDONS_SAVEGAME.sti", VObjectDesc.ImageFile);
CHECKF(AddVideoObject(&VObjectDesc, &guiBackGroundAddOns_New));
//init the list
InitSaveGameArray();
//Clear out all the saved background rects
EmptyBackgroundRects( );
//if the user has asked to load the selected save
if( gfLoadGameUponEntry )
{
//make sure the save is valid
if( gGameSettings.bLastSavedGameSlot != -1 && gbSaveGameArray[ gGameSettings.bLastSavedGameSlot ] )
{
gbSelectedSaveLocation = gGameSettings.bLastSavedGameSlot;
//load the saved game
ConfirmLoadSavedGameMessageBoxCallBack( MSG_BOX_RETURN_YES );
}
else
{ //else the save isnt valid, so dont load it
gfLoadGameUponEntry = FALSE;
}
}
if (PAGE_SLOT == 0 || PAGE_SLOT < 0 )
DisableButton( guiPrevButton );
if (PAGE_SLOT == MAX_PAGE_SLOT || PAGE_SLOT > MAX_PAGE_SLOT )
DisableButton( guiNextButton );
SpecifyDisabledButtonStyle( guiSlgSaveLoadBtn, DISABLED_STYLE_HATCHED );
if( gbSetSlotToBeSelected == -1 )
DisableButton( guiSlgSaveLoadBtn );
InitMSysButtons(TRUE);
ClearSelectedSaveSlot();
//Reset the highlight
gbHighLightedLocation = -1;
gzGameDescTextField[0] = '\0';
SpecifyDisabledButtonStyle( guiSlgSaveLoadBtn, DISABLED_STYLE_HATCHED );
//if the last saved game slot is ok, set the selected slot to the last saved slot]
if( gGameSettings.bLastSavedGameSlot != -1 )
{
//if the slot is valid
if( gbSaveGameArray[ gGameSettings.bLastSavedGameSlot ] )
{
SAVED_GAME_HEADER SaveGameHeader;
memset( &SaveGameHeader, 0, sizeof( SAVED_GAME_HEADER ) );
//if it is not the Quick Save slot, and we are loading
if( !gfSaveGame || gfSaveGame && gGameSettings.bLastSavedGameSlot != 0 )
{
gbSelectedSaveLocation = gGameSettings.bLastSavedGameSlot%NUM_SLOT;
gbSaveGameSelectedLocation[ gbSelectedSaveLocation ] = SLG_SELECTED_SLOT_GRAPHICS_NUMBER;
//load the save gamed header string
//Get the heade for the saved game
if( !LoadSavedGameHeader( gbSelectedSaveLocation, &SaveGameHeader ) )
{
memset( &SaveGameHeader, 0, sizeof( SAVED_GAME_HEADER ) );
gbSaveGameSelectedLocation[ gbSelectedSaveLocation ] = SLG_UNSELECTED_SLOT_GRAPHICS_NUMBER;
if (gbSelectedSaveLocation != SAVE__END_TURN_NUM)
{
gbSaveGameArray[ gbSelectedSaveLocation ] = FALSE;
}
gbSelectedSaveLocation = gGameSettings.bLastSavedGameSlot = -1;
}
wcscpy( gzGameDescTextField, SaveGameHeader.sSavedGameDesc );
}
}
}
//if we are loading and the there is no slot selected
if( gbSelectedSaveLocation == -1 )
DisableButton( guiSlgSaveLoadBtn );
else
EnableButton( guiSlgSaveLoadBtn );
RenderSaveLoadScreen();
// Save load buttons are created
gfSaveLoadScreenButtonsCreated = TRUE;
gfDoingQuickLoad = FALSE;
//reset
gfStartedFadingOut = FALSE;
DisableScrollMessages();
gfLoadedGame = FALSE;
if( gfLoadGameUponEntry )
{
UINT32 uiDestPitchBYTES;
UINT8 *pDestBuf;
//unmark the 2 buttons from being dirty
ButtonList[ guiSlgCancelBtn ]->uiFlags |= BUTTON_FORCE_UNDIRTY;
ButtonList[ guiSlgSaveLoadBtn ]->uiFlags |= BUTTON_FORCE_UNDIRTY;
// CLEAR THE FRAME BUFFER
pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES );
memset(pDestBuf, 0, SCREEN_HEIGHT * uiDestPitchBYTES );
UnLockVideoSurface( FRAME_BUFFER );
// CLEAR THE guiRENDERBUFFER
pDestBuf = LockVideoSurface( guiRENDERBUFFER, &uiDestPitchBYTES );
memset(pDestBuf, 0, SCREEN_HEIGHT * uiDestPitchBYTES );
UnLockVideoSurface( guiRENDERBUFFER );
}
gfGettingNameFromSaveLoadScreen = FALSE;
return( TRUE );
}
BOOLEAN EnterSaveLoadScreen()
{
VOBJECT_DESC VObjectDesc;
UINT16 usPosX = SLG_FIRST_SAVED_SPOT_X;
UINT16 usPosY = SLG_FIRST_SAVED_SPOT_Y;
PAGE_SLOT = 0;
VAL_SLOT_START = 0;
RenderImage = TRUE;
// this is where we came from; if loading of resources fails, this is also where we go next/back
extern UINT32 guiPreviousScreen;
guiSaveLoadExitScreen = guiPreviousScreen;
//init the list
InitSaveGameArray();
//Clear out all the saved background rects
EmptyBackgroundRects( );
//if the user has asked to load the selected save
if( gfLoadGameUponEntry )
{
//make sure the save is valid
if( gGameSettings.bLastSavedGameSlot != -1 && gbSaveGameArray[ gGameSettings.bLastSavedGameSlot ] )
{
gbSelectedSaveLocation = gGameSettings.bLastSavedGameSlot;
//load the saved game
ConfirmLoadSavedGameMessageBoxCallBack( MSG_BOX_RETURN_YES );
}
else
{ //else the save isnt valid, so dont load it
gfLoadGameUponEntry = FALSE;
}
}
// load Main background graphic and add it
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
FilenameForBPP("INTERFACE\\LoadScreen.sti", VObjectDesc.ImageFile);
CHECKF(AddVideoObject(&VObjectDesc, &guiSlgBackGroundImage));
// load Load Screen Add ons graphic and add it
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
GetMLGFilename( VObjectDesc.ImageFile, MLG_LOADSAVEHEADER );
CHECKF(AddVideoObject(&VObjectDesc, &guiBackGroundAddOns));
if (gGameExternalOptions.fSaveGameSlot == TRUE)
{
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
FilenameForBPP("INTERFACE\\LOADSCREENADDONS_SAVEGAME.sti", VObjectDesc.ImageFile);
CHECKF(AddVideoObject(&VObjectDesc, &guiBackGroundAddOns_New));
}
guiSlgButtonImage = LoadButtonImage("INTERFACE\\LoadScreenAddOns.sti", -1,6,-1,9,-1 );
usPosX = SLG_LOAD_CANCEL_POS_X;
guiSlgCancelBtn = CreateIconAndTextButton( guiSlgButtonImage, zSaveLoadText[SLG_CANCEL], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
usPosX, SLG_CANCEL_POS_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnSlgCancelCallback );
//Either the save or load button
if( gfSaveGame )
{
//If we are saving, dont have the save game button
guiSaveLoadImage = UseLoadedButtonImage( guiSlgButtonImage, -1,5,-1,8,-1 );
guiSlgSaveLoadBtn = CreateIconAndTextButton( guiSaveLoadImage, zSaveLoadText[SLG_SAVE_GAME], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
SLG_SAVE_LOAD_BTN_POS_X, SLG_SAVE_LOAD_BTN_POS_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnSlgSaveLoadCallback );
}
else
{
guiSaveLoadImage = UseLoadedButtonImage( guiSlgButtonImage, -1,4,-1,7,-1 );
guiSlgSaveLoadBtn = CreateIconAndTextButton( guiSaveLoadImage, zSaveLoadText[SLG_LOAD_GAME], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
SLG_SAVE_LOAD_BTN_POS_X, SLG_SAVE_LOAD_BTN_POS_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnSlgSaveLoadCallback );
}
guiNewButtonImage = LoadButtonImage("INTERFACE\\LoadScreenButtons.sti", -1,0,-1,1,-1 );
guiPrevButton = CreateIconAndTextButton( guiNewButtonImage, zOptionsText[4], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
SLG_SAVE_LOAD_BTN_POS_X-105, SLG_SAVE_LOAD_BTN_POS_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnNewPrevButtonCallback );
guiNextButton = CreateIconAndTextButton( guiNewButtonImage, zOptionsText[3], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
SLG_SAVE_LOAD_BTN_POS_X+395, SLG_SAVE_LOAD_BTN_POS_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnNewNextButtonCallback );
if (PAGE_SLOT == 0 || PAGE_SLOT < 0 )
DisableButton( guiPrevButton );
if (PAGE_SLOT == MAX_PAGE_SLOT || PAGE_SLOT > MAX_PAGE_SLOT )
DisableButton( guiNextButton );
SpecifyDisabledButtonStyle( guiSlgSaveLoadBtn, DISABLED_STYLE_HATCHED );
if( gbSetSlotToBeSelected == -1 )
DisableButton( guiSlgSaveLoadBtn );
InitMSysButtons(FALSE);
//Create the screen mask to enable ability to righ click to cancel the sace game
MSYS_DefineRegion( &gSLSEntireScreenRegion, 0, 0, SCREEN_WIDTH , SCREEN_HEIGHT , MSYS_PRIORITY_HIGH-10,
CURSOR_NORMAL, MSYS_NO_CALLBACK, SelectedSLSEntireRegionCallBack );
MSYS_AddRegion(&gSLSEntireScreenRegion);
ClearSelectedSaveSlot();
//Remove the mouse region over the clock
RemoveMouseRegionForPauseOfClock( );
//Reset the highlight
gbHighLightedLocation = -1;
gzGameDescTextField[0] = '\0';
SpecifyDisabledButtonStyle( guiSlgSaveLoadBtn, DISABLED_STYLE_HATCHED );
//if the last saved game slot is ok, set the selected slot to the last saved slot]
if( gGameSettings.bLastSavedGameSlot != -1 )
{
//if the slot is valid
if( gbSaveGameArray[ gGameSettings.bLastSavedGameSlot ] )
{
SAVED_GAME_HEADER SaveGameHeader;
memset( &SaveGameHeader, 0, sizeof( SAVED_GAME_HEADER ) );
//if it is not the Quick Save slot, and we are loading
if( !gfSaveGame || gfSaveGame && gGameSettings.bLastSavedGameSlot != 0 )
{
gbSelectedSaveLocation = gGameSettings.bLastSavedGameSlot;
gbSaveGameSelectedLocation[ gbSelectedSaveLocation ] = SLG_SELECTED_SLOT_GRAPHICS_NUMBER;
//Get the heade for the saved game
if( !LoadSavedGameHeader( gbSelectedSaveLocation, &SaveGameHeader ) )
{
memset( &SaveGameHeader, 0, sizeof( SAVED_GAME_HEADER ) );
gbSaveGameSelectedLocation[ gbSelectedSaveLocation ] = SLG_UNSELECTED_SLOT_GRAPHICS_NUMBER;
if (gbSelectedSaveLocation != SAVE__END_TURN_NUM)
{
gbSaveGameArray[ gbSelectedSaveLocation ] = FALSE;
}
gbSelectedSaveLocation = gGameSettings.bLastSavedGameSlot = -1;
}
wcscpy( gzGameDescTextField, SaveGameHeader.sSavedGameDesc );
}
}
}
//if we are loading and the there is no slot selected
if( gbSelectedSaveLocation == -1 )
DisableButton( guiSlgSaveLoadBtn );
else
EnableButton( guiSlgSaveLoadBtn );
RenderSaveLoadScreen();
// Save load buttons are created
gfSaveLoadScreenButtonsCreated = TRUE;
// OK, loading of resources was successfull; time to enter the SAVE_LOAD screen
guiSaveLoadExitScreen = SAVE_LOAD_SCREEN;
gfDoingQuickLoad = FALSE;
//reset
gfStartedFadingOut = FALSE;
DisableScrollMessages();
gfLoadedGame = FALSE;
if( gfLoadGameUponEntry )
{
UINT32 uiDestPitchBYTES;
UINT8 *pDestBuf;
//unmark the 2 buttons from being dirty
ButtonList[ guiSlgCancelBtn ]->uiFlags |= BUTTON_FORCE_UNDIRTY;
ButtonList[ guiSlgSaveLoadBtn ]->uiFlags |= BUTTON_FORCE_UNDIRTY;
// CLEAR THE FRAME BUFFER
pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES );
memset(pDestBuf, 0, SCREEN_HEIGHT * uiDestPitchBYTES );
UnLockVideoSurface( FRAME_BUFFER );
// CLEAR THE guiRENDERBUFFER
pDestBuf = LockVideoSurface( guiRENDERBUFFER, &uiDestPitchBYTES );
memset(pDestBuf, 0, SCREEN_HEIGHT * uiDestPitchBYTES );
UnLockVideoSurface( guiRENDERBUFFER );
}
gfGettingNameFromSaveLoadScreen = FALSE;
//Go to page with last saved game
if ( gGameSettings.bLastSavedGameSlot >= NUM_SLOT)
{
PAGE_SLOT = gGameSettings.bLastSavedGameSlot/NUM_SLOT;
VAL_SLOT_START = (PAGE_SLOT * NUM_SLOT);
if ( PAGE_SLOT > 0 )
EnableButton( guiPrevButton );
if (PAGE_SLOT == MAX_PAGE_SLOT || PAGE_SLOT > MAX_PAGE_SLOT )
DisableButton( guiNextButton );
DestroySaveLoadTextInputBoxes();
NewEnterSaveLoadScreen();
}
return( TRUE );
}
void ExitSaveLoadScreen()
{
UINT8 i;
PAGE_SLOT = 0;
VAL_SLOT_START = 0;
RenderImage = TRUE;
gfLoadGameUponEntry = FALSE;
if( !gfSaveLoadScreenButtonsCreated )
return;
gfSaveLoadScreenExit = FALSE;
gfSaveLoadScreenEntry = TRUE;
gfExitAfterMessageBox = FALSE;
UnloadButtonImage( guiSlgButtonImage );
RemoveButton( guiSlgCancelBtn );
RemoveButton( guiNextButton );
RemoveButton( guiPrevButton );
UnloadButtonImage( guiNewButtonImage );
RemoveButton( guiSlgSaveLoadBtn );
UnloadButtonImage( guiSaveLoadImage );
for(i=0; i<NUM_SLOT; i++)
{
MSYS_RemoveRegion( &gSelectedSaveRegion[i]);
}
DeleteVideoObjectFromIndex( guiSlgBackGroundImage );
DeleteVideoObjectFromIndex( guiBackGroundAddOns );
if (gGameExternalOptions.fSaveGameSlot == TRUE)
{
DeleteVideoObjectFromIndex( guiBackGroundAddOns_New );
}
//Destroy the text fields ( if created )
DestroySaveLoadTextInputBoxes();
MSYS_RemoveRegion( &gSLSEntireScreenRegion );
gfSaveLoadScreenEntry = TRUE;
gfSaveLoadScreenExit = FALSE;
if( !gfLoadedGame )
{
UnLockPauseState( );
UnPauseGame();
}
gfSaveLoadScreenButtonsCreated = FALSE;
gfCameDirectlyFromGame = FALSE;
gfGettingNameFromSaveLoadScreen = FALSE;
}
void RenderSaveLoadScreen()
{
HVOBJECT hPixHandle;
CHAR16 sPage[60];
//if we are going to be instantly leaving the screen, dont draw the numbers
if( gfLoadGameUponEntry )
{
return;
}
if ( RenderImage == TRUE )
{
GetVideoObject(&hPixHandle, guiSlgBackGroundImage);
BltVideoObject(FRAME_BUFFER, hPixHandle, 0, iScreenWidthOffset, iScreenHeightOffset, VO_BLT_SRCTRANSPARENCY,NULL);
}
if( gfSaveGame )
{
if (RenderImage == TRUE)
{
GetVideoObject(&hPixHandle, guiBackGroundAddOns);
BltVideoObject(FRAME_BUFFER, hPixHandle, 1, SLG_TITLE_POS_X, SLG_TITLE_POS_Y, VO_BLT_SRCTRANSPARENCY,NULL);
}
}
else
{
//Display the Title
if ( RenderImage == TRUE )
{
GetVideoObject(&hPixHandle, guiBackGroundAddOns);
BltVideoObject(FRAME_BUFFER, hPixHandle, 0, SLG_TITLE_POS_X, SLG_TITLE_POS_Y, VO_BLT_SRCTRANSPARENCY,NULL);
}
}
DisplaySaveGameList();