Ticket #8194: quitdialog.diff

File quitdialog.diff, 6.2 KB (added by Deledrius, 21 years ago)

Patch against 2003-05-03 CVS to add Exit Confirmation

Line 
1Index: dialogs.cpp
2===================================================================
3RCS file: /cvsroot/scummvm/scummvm/scumm/dialogs.cpp,v
4retrieving revision 1.43
5diff -u -r1.43 dialogs.cpp
6--- dialogs.cpp 30 Apr 2003 13:23:26 -0000 1.43
7+++ dialogs.cpp 4 May 2003 01:00:47 -0000
8@@ -662,6 +662,10 @@
9 : InfoDialog(gui, scumm, 10) {
10 }
11
12+ConfirmExitDialog::ConfirmExitDialog(NewGui *gui, Scumm *scumm)
13+ : InfoDialog(gui, scumm, "Are you sure you want to quit (y/n)?") {
14+}
15+
16 #ifdef _WIN32_WCE
17
18 #pragma mark -
19Index: dialogs.h
20===================================================================
21RCS file: /cvsroot/scummvm/scummvm/scumm/dialogs.h,v
22retrieving revision 1.17
23diff -u -r1.17 dialogs.h
24--- dialogs.h 25 Mar 2003 15:32:36 -0000 1.17
25+++ dialogs.h 4 May 2003 01:00:47 -0000
26@@ -137,6 +137,27 @@
27 }
28 };
29
30+class ConfirmExitDialog : public InfoDialog {
31+public:
32+ ConfirmExitDialog(NewGui *gui, Scumm *scumm);
33+ virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers) {
34+ if (tolower(ascii) == 'n') { // Close exit dialog if n key is pressed
35+ result = ascii;
36+ close();
37+ }
38+ if (tolower(ascii) == 'y') { // Quit engine if y key is pressed
39+ result = ascii;
40+ close();
41+ }
42+ else
43+ ScummDialog::handleKeyDown(ascii, keycode, modifiers);
44+ }
45+
46+ int getResult() {return result;};
47+private:
48+ int result;
49+};
50+
51 #ifdef _WIN32_WCE
52
53 class KeysDialog : public ScummDialog {
54Index: scumm.h
55===================================================================
56RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
57retrieving revision 1.177
58diff -u -r1.177 scumm.h
59--- scumm.h 3 May 2003 20:49:53 -0000 1.177
60+++ scumm.h 4 May 2003 01:00:48 -0000
61@@ -359,6 +359,7 @@
62 Dialog *_pauseDialog;
63 Dialog *_optionsDialog;
64 Dialog *_saveLoadDialog;
65+ Dialog *_confirmExitDialog;
66 // Debugger access this one, too...
67 ConsoleDialog *_debuggerDialog;
68
69@@ -366,6 +367,7 @@
70 void pauseDialog();
71 void saveloadDialog();
72 void optionsDialog();
73+ void confirmexitDialog();
74 char displayError(bool showCancel, const char *message, ...);
75
76 protected:
77@@ -999,6 +1001,7 @@
78 byte _charsetBuffer[512];
79
80 bool _noSubtitles; // Skip all subtitles?
81+ bool _confirm_on_exit;
82
83 void initCharset(int charset);
84 void restoreCharsetBg();
85Index: scummvm.cpp
86===================================================================
87RCS file: /cvsroot/scummvm/scummvm/scumm/scummvm.cpp,v
88retrieving revision 2.122
89diff -u -r2.122 scummvm.cpp
90--- scummvm.cpp 3 May 2003 21:15:24 -0000 2.122
91+++ scummvm.cpp 4 May 2003 01:00:49 -0000
92@@ -385,6 +385,7 @@
93 _charsetBufPos = 0;
94 memset(_charsetBuffer,0,sizeof(_charsetBuffer));
95 _noSubtitles = false;
96+ _confirm_on_exit = false;
97 _numInMsgStack = 0;
98 _msgPtrToAdd = NULL;
99 _messagePtr = NULL;
100@@ -410,6 +411,7 @@
101 _gameId = detector->_gameId;
102 _features = detector->_features;
103 _noSubtitles = detector->_noSubtitles;
104+ _confirm_on_exit = detector->_confirm_on_exit;
105 _defaultTalkDelay = detector->_talkSpeed;
106 _use_adlib = detector->_use_adlib;
107 _language = detector->_language;
108@@ -1547,6 +1549,17 @@
109 runDialog(_optionsDialog);
110 }
111
112+void Scumm::confirmexitDialog() {
113+ if (!_confirmExitDialog)
114+ _confirmExitDialog = new ConfirmExitDialog(_newgui, this);
115+ runDialog(_confirmExitDialog);
116+
117+ if (tolower(((ConfirmExitDialog*)_confirmExitDialog)->getResult()) == 'y') {
118+ shutDown(0);
119+ _system->quit(); // TODO: This can be removed when shutDown is implemented
120+ }
121+}
122+
123 char Scumm::displayError(bool showCancel, const char *message, ...) {
124 #ifdef __PALM_OS__
125 char buf[256], result; // 1024 is too big overflow the stack
126@@ -1916,9 +1929,21 @@
127 g_debugger->attach(this, NULL);
128 else if (event.kbd.keycode == 's')
129 resourceStats();
130+ else if (event.kbd.keycode == 'z') {
131+ if(_confirm_on_exit)
132+ confirmexitDialog();
133+ else
134+ _system->quit(); // TODO: change to shutDown() when implemented
135+ }
136 else
137Index: sdl/sdl-common.cpp
138===================================================================
139RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.cpp,v
140retrieving revision 1.45
141diff -u -r1.45 sdl-common.cpp
142--- sdl/sdl-common.cpp 1 May 2003 12:42:46 -0000 1.45
143+++ sdl/sdl-common.cpp 4 May 2003 01:03:42 -0000
144@@ -532,15 +532,23 @@
145 }
146
147 // Ctrl-z and Alt-X quit
148+ // Let the game loop quit, without pulling the rug out from under it using quit()
149 if ((b == KBD_CTRL && ev.key.keysym.sym=='z') || (b == KBD_ALT && ev.key.keysym.sym=='x')) {
150- quit();
151+ event->event_code = EVENT_KEYDOWN;
152+ event->kbd.flags = b;
153+ event->kbd.keycode = ev.key.keysym.sym;
154+ return true;
155 break;
156 }
157
158 #ifdef MACOSX
159 // On Macintosh', Cmd-Q quits
160+ // (re-map to alt-x, and sent it back)
161 if ((ev.key.keysym.mod & KMOD_META) && ev.key.keysym.sym=='q') {
162- quit();
163+ event->event_code = EVENT_KEYDOWN;
164+ event->kbd.flags = KBD_ALT;
165+ event->kbd.keycode = 'x';
166+ return true;
167 break;
168 }
169 #endif
170Index: gameDetector.cpp
171===================================================================
172RCS file: /cvsroot/scummvm/scummvm/common/gameDetector.cpp,v
173retrieving revision 1.88
174diff -u -r1.88 gameDetector.cpp
175--- gameDetector.cpp 30 Apr 2003 12:43:54 -0000 1.88
176+++ gameDetector.cpp 4 May 2003 01:07:41 -0000
177@@ -165,6 +165,7 @@
178 _save_slot = 0;
179
180 _saveconfig = false;
181+ _confirm_on_exit = false;
182
183 #ifndef _WIN32_WCE
184 _gfx_mode = GFX_DOUBLESIZE;
185@@ -270,6 +271,8 @@
186 _gameTempo = strtol(val, NULL, 0);
187
188 _talkSpeed = g_config->getInt("talkspeed", _talkSpeed);
189+
190+ _confirm_on_exit = g_config->getBool("confirm_on_exit", _confirm_on_exit ? true : false);
191 }
192
193 void GameDetector::list_games() {
194Index: gameDetector.h
195===================================================================
196RCS file: /cvsroot/scummvm/scummvm/common/gameDetector.h,v
197retrieving revision 1.36
198diff -u -r1.36 gameDetector.h
199--- gameDetector.h 6 Apr 2003 19:41:34 -0000 1.36
200+++ gameDetector.h 4 May 2003 01:07:41 -0000
201@@ -174,6 +174,7 @@
202 int _save_slot;
203
204 bool _saveconfig;
205+ bool _confirm_on_exit;
206
207 public:
208 OSystem *createSystem();