Skip to content

Commit

Permalink
Ask player whether to resume last game after crash
Browse files Browse the repository at this point in the history
  • Loading branch information
nextghost committed Feb 5, 2022
1 parent cb55f1d commit 4780a15
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion signus-data/data/cs/texts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ texts_src = brief1.txt brief10.txt brief11.txt brief12.txt brief13.txt \
txt67.txt txt68.txt txt69.txt txt7.txt txt70.txt txt71.txt txt73.txt \
txt74.txt txt75.txt txt76.txt txt77.txt txt78.txt txt79.txt txt8.txt \
txt80.txt txt81.txt txt82.txt txt83.txt txt84.txt txt85.txt txt86.txt \
txt9.txt udes1.txt \
txt87.txt txt88.txt txt89.txt txt9.txt udes1.txt \
udes10.txt udes11.txt udes12.txt udes13.txt udes14.txt udes15.txt \
udes16.txt udes17.txt udes18.txt udes19.txt udes2.txt udes20.txt \
udes21.txt udes22.txt udes23.txt udes24.txt udes25.txt udes26.txt \
Expand Down
1 change: 1 addition & 0 deletions signus-data/data/cs/texts/txt87.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Signus nebyl řádně ukončen. Obnovit předchozí hru?
1 change: 1 addition & 0 deletions signus-data/data/cs/texts/txt88.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Obnovit
1 change: 1 addition & 0 deletions signus-data/data/cs/texts/txt89.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hlavní menu
2 changes: 1 addition & 1 deletion signus-data/data/en/texts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ texts_src = brief1.txt brief10.txt brief11.txt brief12.txt brief13.txt \
txt67.txt txt68.txt txt69.txt txt7.txt txt70.txt txt71.txt txt73.txt \
txt74.txt txt75.txt txt76.txt txt77.txt txt78.txt txt79.txt txt8.txt \
txt80.txt txt81.txt txt82.txt txt83.txt txt84.txt txt85.txt txt86.txt \
txt9.txt udes1.txt \
txt87.txt txt88.txt txt89.txt txt9.txt udes1.txt \
udes10.txt udes11.txt udes12.txt udes13.txt udes14.txt udes15.txt \
udes16.txt udes17.txt udes18.txt udes19.txt udes2.txt udes20.txt \
udes21.txt udes22.txt udes23.txt udes24.txt udes25.txt udes26.txt \
Expand Down
1 change: 1 addition & 0 deletions signus-data/data/en/texts/txt87.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Signus previously crashed. Resume last game?
1 change: 1 addition & 0 deletions signus-data/data/en/texts/txt88.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resume
1 change: 1 addition & 0 deletions signus-data/data/en/texts/txt89.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main menu
7 changes: 5 additions & 2 deletions signus/src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


// Konstanty textu (tlacitka, menu, hlasky) (pole SigText):
#define TXT_COUNT 87
#define TXT_COUNT 90

#define TXT_ALWAYS 0
#define TXT_READYSHOOT 1
Expand Down Expand Up @@ -129,7 +129,10 @@
#define TXT_FUEL_WARN_CBOX 83
#define TXT_FUEL_WARN_MSG 84
#define TXT_ALT_ENEMY_COLORS 85
#define TXT_PLAY_INTROS 86
#define TXT_PLAY_INTROS 86
#define TXT_POSTCRASH 87
#define TXT_CRASH_LOAD 88
#define TXT_CRASH_MENU 89



Expand Down
12 changes: 4 additions & 8 deletions signus/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,14 @@ extern void DoneSignus();


static void finiObjects() {
char *path;

allow_mouse = FALSE;
if (signus_inited) DoneSignus();
signus_inited = FALSE;
path = signus_config_path("crashguard_saved_state");

if (path) {
remove(path);
memfree(path);
if (signus_inited) {
DoneSignus();
}

signus_inited = FALSE;

if (SDL_inited) {
SDL_Quit();
}
Expand Down
44 changes: 41 additions & 3 deletions signus/src/signus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,29 @@ int InitSignus()
extern int WC_On;
extern void *WorkingControl[3];

int postcrash_ask(void) {
int x, width;
TDialog dlg((RES_X-380) / 2, (RES_Y-160) / 2, 380, 160, "dlgprbx");

width = GetStrWidth(SigText[TXT_POSTCRASH], NormalFont);
x = (380 - width) / 2;
dlg.Insert(new TStaticText(x, 30, width, 40, SigText[TXT_POSTCRASH]));
dlg.Insert(new TButton(50, 60, SigText[TXT_CRASH_LOAD], cmYes, TRUE));
dlg.Insert(new TButton(200, 60, SigText[TXT_CRASH_MENU], cmNo));
dlg.Insert(new TButton(50, 100, SigText[TXT_END_GAME], cmCancel));
return dlg.Exec();
}

void delete_crashsave(void) {
char *path;

path = signus_config_path("crashguard_saved_state");

if (path) {
remove(path);
memfree(path);
}
}

void CrashSave() {
File stream;
Expand All @@ -1040,6 +1063,7 @@ void CrashSave() {

int CrashLoad() {
File stream;
int ret;
char *path;

path = signus_config_path("crashguard_saved_state");
Expand All @@ -1053,9 +1077,14 @@ int CrashLoad() {
return FALSE;
}

// No events have been processed so far, flush them so that video
// backend can properly resize the window, etc.
ClearEvent();
ret = postcrash_ask();

if (ret == cmNo) {
return FALSE; // Ignore crashsave and go to main menu
} else if (ret == cmCancel) {
return -1; // Exit Signus without deleting crashsave
}

LoadGameState(stream);
return TRUE;
}
Expand Down Expand Up @@ -1318,6 +1347,12 @@ void signus_main() {
int crash = CrashLoad();
int fs = TRUE;

// Game previously crashed, player chose to quit in popup dialog
// Do *NOT* delete crashsave here!
if (crash < 0) {
return;
}

if (iniPlayIntros && !crash) {
PlayAnimation("present2");
PlayAnimation("present1");
Expand Down Expand Up @@ -1378,4 +1413,7 @@ void signus_main() {
break;
}
}

// Clean exit => remove crashsave
delete_crashsave();
}

0 comments on commit 4780a15

Please sign in to comment.