(svn r6380) -Codechange: unify all ways to quit OTTD.
authorrubidium
Mon, 04 Sep 2006 17:30:30 +0000
changeset 4548 23b56455df33
parent 4547 9786a24c4102
child 4549 60410aa1aa88
(svn r6380) -Codechange: unify all ways to quit OTTD.
This means that in the intro menu the 'Quit' button immediatelly quits
and the 'Quit' in the menu of the normal game and scenario editor
immediatelly quits when the 'autosave_on_exit' patch is turned on.
This is the same way as the OS/window manager initiated quits, like
alt-F4 and the 'x' in the (OS/window manager drawn) title bar of OTTD.
functions.h
intro_gui.c
main_gui.c
openttd.c
saveload.h
video/cocoa_v.m
video/sdl_v.c
video/win32_v.c
--- a/functions.h	Mon Sep 04 15:44:28 2006 +0000
+++ b/functions.h	Mon Sep 04 17:30:30 2006 +0000
@@ -233,6 +233,7 @@
 void SaveToConfig(void);
 void CheckConfig(void);
 int ttd_main(int argc, char* argv[]);
+void HandleExitGameRequest(void);
 
 void DeterminePaths(void);
 
--- a/intro_gui.c	Mon Sep 04 15:44:28 2006 +0000
+++ b/intro_gui.c	Mon Sep 04 17:30:30 2006 +0000
@@ -77,7 +77,7 @@
 		case 12: ShowGameOptions(); break;
 		case 13: ShowGameDifficulty(); break;
 		case 14: ShowPatchesSelection(); break;
-		case 15: AskExitGame(); break;
+		case 15: HandleExitGameRequest(); break;
 		}
 		break;
 
--- a/main_gui.c	Mon Sep 04 15:44:28 2006 +0000
+++ b/main_gui.c	Mon Sep 04 17:30:30 2006 +0000
@@ -170,14 +170,14 @@
 			case 0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break;
 			case 1: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
 			case 2: AskExitToGameMenu();                   break;
-			case 4: AskExitGame();                         break;
+			case 4: HandleExitGameRequest();               break;
 		}
 	} else {
 		switch (index) {
 			case 0: ShowSaveLoadDialog(SLD_SAVE_GAME); break;
 			case 1: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
 			case 2: AskExitToGameMenu();               break;
-			case 3: AskExitGame();                     break;
+			case 3: HandleExitGameRequest();           break;
 		}
 	}
 }
@@ -2226,7 +2226,7 @@
 		switch (e->keypress.keycode) {
 			case 'Q' | WKC_CTRL:
 			case 'Q' | WKC_META:
-				AskExitGame();
+				HandleExitGameRequest();
 				break;
 		}
 
--- a/openttd.c	Mon Sep 04 15:44:28 2006 +0000
+++ b/openttd.c	Mon Sep 04 17:30:30 2006 +0000
@@ -537,6 +537,19 @@
 	return 0;
 }
 
+void HandleExitGameRequest(void)
+{
+	if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
+		_exit_game = true;
+	} else if (_patches.autosave_on_exit) {
+		DoExitSave();
+		_exit_game = true;
+	} else {
+		AskExitGame();
+	}
+}
+
+
 /** Mutex so that only one thread can communicate with the main program
  * at any given time */
 static ThreadMsg _message = MSG_OTTD_NO_MESSAGE;
--- a/saveload.h	Mon Sep 04 15:44:28 2006 +0000
+++ b/saveload.h	Mon Sep 04 17:30:30 2006 +0000
@@ -20,6 +20,7 @@
 
 SaveOrLoadResult SaveOrLoad(const char *filename, int mode);
 void WaitTillSaved(void);
+void DoExitSave(void);
 
 
 typedef void ChunkSaveLoadProc(void);
--- a/video/cocoa_v.m	Mon Sep 04 15:44:28 2006 +0000
+++ b/video/cocoa_v.m	Mon Sep 04 17:30:30 2006 +0000
@@ -197,22 +197,6 @@
 
 
 
-extern void DoExitSave(void);
-
-static void QZ_AskQuit(void)
-{
-	if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
-		_exit_game = true;
-	} else if (_patches.autosave_on_exit) {
-		DoExitSave();
-		_exit_game = true;
-	} else {
-		AskExitGame();
-	}
-}
-
-
-
 typedef struct VkMapping {
 	unsigned short vk_from;
 	byte map_to;
@@ -921,7 +905,7 @@
 @implementation OTTD_QuartzWindowDelegate
 - (BOOL)windowShouldClose:(id)sender
 {
-	QZ_AskQuit();
+	HandleExitGameRequest();
 
 	return NO;
 }
--- a/video/sdl_v.c	Mon Sep 04 15:44:28 2006 +0000
+++ b/video/sdl_v.c	Mon Sep 04 17:30:30 2006 +0000
@@ -303,8 +303,6 @@
 	return (key << 16) + sym->unicode;
 }
 
-extern void DoExitSave(void);
-
 static int PollEvent(void)
 {
 	SDL_Event ev;
@@ -376,21 +374,9 @@
 			}
 			break;
 
-		case SDL_QUIT:
-			// do not ask to quit on the main screen
-			if (_game_mode != GM_MENU) {
-				if (_patches.autosave_on_exit) {
-					DoExitSave();
-					return 0;
-				} else {
-					AskExitGame();
-				}
-			} else {
-				return 0;
-			}
-			break;
+		case SDL_QUIT: HandleExitGameRequest(); break;
 
-			case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */
+		case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */
 			if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) &&
 					(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) {
 				ToggleFullScreen(!_fullscreen);
@@ -448,8 +434,6 @@
 		InteractiveRandom(); // randomness
 
 		while ((i = PollEvent()) == -1) {}
-		if (i >= 0) return;
-
 		if (_exit_game) return;
 
 		mod = SDL_CALL SDL_GetModState();
--- a/video/win32_v.c	Mon Sep 04 15:44:28 2006 +0000
+++ b/video/win32_v.c	Mon Sep 04 17:30:30 2006 +0000
@@ -151,8 +151,6 @@
 	}
 }
 
-extern void DoExitSave(void);
-
 #ifdef _DEBUG
 // Keep this function here..
 // It allows you to redraw the screen from within the MSVC debugger
@@ -256,14 +254,7 @@
 		}
 
 		case WM_CLOSE:
-			if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
-				_exit_game = true;
-			} else if (_patches.autosave_on_exit) {
-				DoExitSave();
-				_exit_game = true;
-			} else {
-				AskExitGame();
-			}
+			HandleExitGameRequest();
 			_window_maximize = IsZoomed(_wnd.main_wnd);
 			return 0;