(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
authorrubidium
Tue, 04 Dec 2007 22:50:07 +0000
changeset 8013 82001acdb8d0
parent 8012 5faf4ff3b4d2
child 8014 4a732fc3aade
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
src/lang/english.txt
src/misc_cmd.cpp
src/openttd.cpp
--- a/src/lang/english.txt	Tue Dec 04 22:22:50 2007 +0000
+++ b/src/lang/english.txt	Tue Dec 04 22:50:07 2007 +0000
@@ -3116,6 +3116,8 @@
 STR_NEWGRF_COMPATIBLE_LOAD_WARNING                              :{WHITE}Compatible GRF(s) loaded for missing files
 STR_NEWGRF_DISABLED_WARNING                                     :{WHITE}Missing GRF file(s) have been disabled
 STR_NEWGRF_NOT_FOUND_WARNING                                    :{WHITE}Missing GRF file(s) to be able to load game
+STR_NEWGRF_UNPAUSE_WARNING_TITLE                                :{YELLOW}Missing GRF file(s)
+STR_NEWGRF_UNPAUSE_WARNING                                      :{WHITE}Unpausing can crash OpenTTD. Do not file bug reports for subsequent crashes.{}Do you really want to unpause?
 
 STR_CURRENCY_WINDOW                                             :{WHITE}Custom currency
 STR_CURRENCY_EXCHANGE_RATE                                      :{LTBLUE}Exchange rate: {ORANGE}{CURRENCY} = £ {COMMA}
--- a/src/misc_cmd.cpp	Tue Dec 04 22:22:50 2007 +0000
+++ b/src/misc_cmd.cpp	Tue Dec 04 22:50:07 2007 +0000
@@ -294,6 +294,17 @@
 	return CommandCost();
 }
 
+/**
+ * In case of an unsafe unpause, we want the
+ * user to confirm that it might crash.
+ * @param w         unused
+ * @param confirmed whether the user confirms his/her action
+ */
+static void AskUnsafeUnpauseCallback(Window *w, bool confirmed)
+{
+	DoCommandP(0, confirmed ? 0 : 1, 0, NULL, CMD_PAUSE);
+}
+
 /** Pause/Unpause the game (server-only).
  * Increase or decrease the pause counter. If the counter is zero,
  * the game is unpaused. A counter is used instead of a boolean value
@@ -307,7 +318,24 @@
 {
 	if (flags & DC_EXEC) {
 		_pause_game += (p1 == 1) ? 1 : -1;
-		if (_pause_game == (byte)-1) _pause_game = 0;
+
+		switch (_pause_game) {
+			case (byte)-4:
+			case (byte)-1:
+				_pause_game = 0;
+				break;
+			case (byte)-3:
+				ShowQuery(
+					STR_NEWGRF_UNPAUSE_WARNING_TITLE,
+					STR_NEWGRF_UNPAUSE_WARNING,
+					NULL,
+					AskUnsafeUnpauseCallback
+				);
+				break;
+
+			default: break;
+		}
+
 		InvalidateWindow(WC_STATUS_BAR, 0);
 		InvalidateWindow(WC_MAIN_TOOLBAR, 0);
 	}
--- a/src/openttd.cpp	Tue Dec 04 22:22:50 2007 +0000
+++ b/src/openttd.cpp	Tue Dec 04 22:50:07 2007 +0000
@@ -1357,7 +1357,7 @@
 
 	switch (gcf_res) {
 		case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
-		case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break;
+		case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; _pause_game = (byte)-1; break;
 		default: break;
 	}