File: loadsave.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (636 lines) | stat: -rw-r--r-- 20,278 bytes parent folder | download | duplicates (2)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "engines/nancy/nancy.h"
#include "engines/nancy/cursor.h"
#include "engines/nancy/sound.h"
#include "engines/nancy/input.h"
#include "engines/nancy/util.h"
#include "engines/nancy/resource.h"
#include "engines/nancy/graphics.h"

#include "engines/nancy/state/loadsave.h"
#include "engines/nancy/state/scene.h"
#include "engines/nancy/ui/button.h"

#include "common/config-manager.h"

namespace Common {
DECLARE_SINGLETON(Nancy::State::LoadSaveMenu);
}

namespace Nancy {
namespace State {

LoadSaveMenu::~LoadSaveMenu() {
	for (auto *tb : _textboxes) {
		delete tb;
	}

	for (auto *button : _loadButtons) {
		delete button;
	}

	for (auto *button : _saveButtons) {
		delete button;
	}

	for (auto *overlay : _cancelButtonOverlays) {
		delete overlay;
	}

	delete _exitButton;
	delete _cancelButton;

	g_nancy->_input->setVKEnabled(false);
}

void LoadSaveMenu::process() {
	if (g_nancy->_sound->isSoundPlaying("BUOK") || g_nancy->_sound->isSoundPlaying("BULS") || g_nancy->_sound->isSoundPlaying("BUDE")) {
		return;
	}

	switch (_state) {
	case kInit:
		init();
		// fall through
	case kRun:
		run();
		break;
	case kEnterFilename:
		enterFilename();
		break;
	case kSave:
		save();
		break;
	case kLoad:
		load();
		break;
	case kSuccess:
		success();
		break;
	default:
		break;
	}

	// Make sure stop runs on the same frame
	if (_state == kStop) {
		stop();
	}

	g_nancy->_cursor->setCursorType(CursorManager::kNormalArrow);
}

void LoadSaveMenu::onStateEnter(const NancyState::NancyState prevState) {
	if (_state == kEnterFilename) {
		g_nancy->_input->setVKEnabled(true);
	}
	registerGraphics();
}

bool LoadSaveMenu::onStateExit(const NancyState::NancyState nextState) {
	g_nancy->_input->setVKEnabled(false);
	return _destroyOnExit;
}

void LoadSaveMenu::registerGraphics() {
	_background.registerGraphics();

	for (auto *button : _loadButtons) {
		button->registerGraphics();
	}

	for (auto *button : _saveButtons) {
		button->registerGraphics();
	}

	for (auto *overlay : _cancelButtonOverlays) {
		overlay->registerGraphics();
	}

	for (auto *tb : _textboxes) {
		tb->registerGraphics();
	}

	if (_exitButton) {
		_exitButton->registerGraphics();
	}

	if (_cancelButton) {
		_cancelButton->registerGraphics();
	}

	_blinkingCursorOverlay.registerGraphics();
	_successOverlay.registerGraphics();

	g_nancy->_graphics->redrawAll();
}

void LoadSaveMenu::init() {
	_loadSaveData = GetEngineData(LOAD);
	assert(_loadSaveData);

	_background.init(_loadSaveData->_image1Name);

	_baseFont = g_nancy->_graphics->getFont(_loadSaveData->_mainFontID);

	if (_loadSaveData->_highlightFontID != -1) {
		_highlightFont = g_nancy->_graphics->getFont(_loadSaveData->_highlightFontID);
		_disabledFont = g_nancy->_graphics->getFont(_loadSaveData->_disabledFontID);
	} else {
		_highlightFont = _disabledFont = _baseFont;
	}

	_filenameStrings.resize(_loadSaveData->_textboxBounds.size());
	_saveExists.resize(_filenameStrings.size(), false);
	_textboxes.resize(_filenameStrings.size());
	for (uint i = 0; i < _textboxes.size(); ++i) {
		// Load textbox objects
		RenderObject *newTb = new RenderObject(5);
		_textboxes[i] = newTb;
		const Common::Rect &bounds = _loadSaveData->_textboxBounds[i];
		newTb->_drawSurface.create(bounds.width(), bounds.height(), g_nancy->_graphics->getScreenPixelFormat());
		newTb->_drawSurface.clear(g_nancy->_graphics->getTransColor());
		newTb->moveTo(bounds);
		newTb->setTransparent(true);
		newTb->setVisible(true);
		newTb->init();

		// Check for valid save and write its name in the textbox
		SaveStateDescriptor desc = g_nancy->getMetaEngine()->querySaveMetaInfos(ConfMan.getActiveDomainName().c_str(), i + 1);
		if (desc.isValid()) {
			_saveExists[i] = true;
			_filenameStrings[i] = desc.getDescription();
		} else {
			// If no valid save, copy over the empty save string
			if (_loadSaveData->_emptySaveText.size()) {
				_filenameStrings[i] = _loadSaveData->_emptySaveText;
			} else {
				_filenameStrings[i] = g_nancy->getStaticData().emptySaveText;
			}
		}
	}

	bool hasHighlights = _loadSaveData->_loadButtonHighlightSrcs.size();

	_loadButtons.resize(_textboxes.size());
	_saveButtons.resize(_textboxes.size());
	_cancelButtonOverlays.resize(_textboxes.size());
	for (uint i = 0; i < _loadButtons.size(); ++i) {
		// Load Save and Load buttons, and Cancel overlays
		_loadButtons[i] = new UI::Button(1, _background._drawSurface,
			_loadSaveData->_loadButtonDownSrcs[i], _loadSaveData->_loadButtonDests[i],
			hasHighlights ? _loadSaveData->_loadButtonHighlightSrcs[i] : Common::Rect(),
			hasHighlights ? _loadSaveData->_loadButtonDisabledSrcs[i] : Common::Rect());

		_saveButtons[i] = new UI::Button(1, _background._drawSurface,
			_loadSaveData->_saveButtonDownSrcs[i], _loadSaveData->_saveButtonDests[i],
			hasHighlights ? _loadSaveData->_saveButtonHighlightSrcs[i] : Common::Rect(),
			hasHighlights ? _loadSaveData->_saveButtonDisabledSrcs[i] : Common::Rect());

		_cancelButtonOverlays[i] = new RenderObject(2, _background._drawSurface,
			_loadSaveData->_cancelButtonSrcs[i], _loadSaveData->_cancelButtonDests[i]);

		_loadButtons[i]->init();
		_saveButtons[i]->init();
		_cancelButtonOverlays[i]->init();
	}

	// Load exit button
	_exitButton = new UI::Button(3, _background._drawSurface,
			_loadSaveData->_doneButtonDownSrc, _loadSaveData->_doneButtonDest,
			hasHighlights ? _loadSaveData->_doneButtonHighlightSrc : Common::Rect(),
			hasHighlights ? _loadSaveData->_doneButtonDisabledSrc : Common::Rect());

	// Load Cancel button that activates when typing a filename
	// Note: this is only responsible for the hover/mouse down/disabled graphic;
	// the graphics that replace the Save buttons with Cancel are their own RenderObject.
	// We also make sure this has an invalid position until we need it.
	Common::Rect pos = _loadSaveData->_cancelButtonDests[0];
	pos.moveTo(-500, 0);
	_cancelButton = new UI::Button(3, _background._drawSurface,
		_loadSaveData->_cancelButtonDownSrc, Common::Rect(),
		_loadSaveData->_cancelButtonHighlightSrc, _loadSaveData->_cancelButtonDisabledSrc);

	// Load the blinking cursor graphic that appears while typing a filename
	_blinkingCursorOverlay._drawSurface.create(_loadSaveData->_blinkingCursorSrc.width(),
		_loadSaveData->_blinkingCursorSrc.height(),
		g_nancy->_graphics->getScreenPixelFormat());
	_blinkingCursorOverlay.setTransparent(true);
	_blinkingCursorOverlay.setVisible(false);
	_blinkingCursorOverlay._drawSurface.clear(_blinkingCursorOverlay._drawSurface.getTransparentColor());
	_blinkingCursorOverlay._drawSurface.transBlitFrom(_highlightFont->getImageSurface(), _loadSaveData->_blinkingCursorSrc,
		Common::Point(), g_nancy->_graphics->getTransColor());

	// Load the "Your game has been saved" popup graphic
	if (!_loadSaveData->_gameSavedPopup.empty()) {
		g_nancy->_resource->loadImage(_loadSaveData->_gameSavedPopup, _successOverlay._drawSurface);
		Common::Rect destBounds = Common::Rect(0,0, _successOverlay._drawSurface.w, _successOverlay._drawSurface.h);
		destBounds.moveTo(640 / 2 - destBounds.width() / 2,
			480 / 2 - destBounds.height() / 2);
		_successOverlay.moveTo(destBounds);
		_successOverlay.setVisible(false);
	}

	registerGraphics();

	_state = kRun;
	_enteringNewState = true;
}

void LoadSaveMenu::run() {
	if (_enteringNewState) {
		// State has changed, revert all relevant objects to an appropriate state
		for (uint i = 0; i < _textboxes.size(); ++i) {
			writeToTextbox(i, _filenameStrings[i], Nancy::State::Scene::hasInstance() ? _baseFont : _disabledFont);

			// Set load button state depending on whether there exists a save in the corresponding slot
			// Save buttons are always active
			_loadButtons[i]->setDisabled(_saveExists[i] == false);
			_saveButtons[i]->setDisabled(!Nancy::State::Scene::hasInstance());
			_cancelButtonOverlays[i]->setVisible(false);

			_loadButtons[i]->_isClicked = false;
			_saveButtons[i]->_isClicked = false;
		}

		if (_cancelButton) {
			_cancelButton->_isClicked = false;
			_cancelButton->setDisabled(true);
			_cancelButton->moveTo(Common::Point(-500, 0));
		}

		_blinkingCursorOverlay.setVisible(false);
		_exitButton->setDisabled(false);
		_enteredString.clear();
		_successOverlay.setVisible(false);

		_selectedSave = -1;
		_enteringNewState = false;
	}

	// Handle input
	NancyInput input = g_nancy->_input->getInput();

	for (uint i = 0; i < _loadButtons.size(); ++i) {
		_loadButtons[i]->handleInput(input);

		if (_loadButtons[i]->_isClicked) {
			if (_saveExists[i]) {
				_state = kLoad;
				_enteringNewState = true;
				_selectedSave = i;
				g_nancy->_sound->playSound("BULS");
			} else if (!_loadSaveData->_saveButtonHighlightSrcs.size()) {
				// TVD and nancy1 buttons get pushed and play error sound
				_loadButtons[i]->setVisible(true);
				g_nancy->_sound->playSound("BUDE");
				_enteringNewState = true;
			}

			return;
		}
	}

	for (uint i = 0; i < _saveButtons.size(); ++i) {
		_saveButtons[i]->handleInput(input);

		if (_saveButtons[i]->_isClicked) {
			if (Nancy::State::Scene::hasInstance()) {
				_state = kSave;
				_enteringNewState = true;
				_selectedSave = i;
				g_nancy->_sound->playSound("BULS");
			} else if (!_loadSaveData->_saveButtonHighlightSrcs.size()) {
				// TVD and nancy1 buttons get pushed and play error sound
				_saveButtons[i]->setVisible(true);
				g_nancy->_sound->playSound("BUDE");
				_enteringNewState = true;
			}

			return;
		}
	}

	// Handle textbox hovering
	bool hoversOverTextbox = false;
	for (int i = 0; i < (int)_textboxes.size(); ++i) {
		if (_textboxes[i]->getScreenPosition().contains(input.mousePos)) {
			if (Nancy::State::Scene::hasInstance()) {
				hoversOverTextbox = true;
				if (_selectedSave != i) {
					if (_selectedSave != -1) {
						writeToTextbox(_selectedSave, _filenameStrings[_selectedSave], _baseFont);
					}

					_selectedSave = i;
					writeToTextbox(_selectedSave, _filenameStrings[_selectedSave], _highlightFont);
				}

				if (input.input & NancyInput::kLeftMouseButtonUp) {
					_state = kEnterFilename;
					_enteringNewState = true;
					g_nancy->_sound->playSound("BUOK");
					_selectedSave = i;
					return;
				}

				break;
			} else if (!_loadSaveData->_saveButtonHighlightSrcs.size()) {
				if (input.input & NancyInput::kLeftMouseButtonUp) {
					// TVD and nancy1 textboxes play error sound when no Scene is active
					g_nancy->_sound->playSound("BUDE");
				}
			}
		}
	}

	if (!hoversOverTextbox && _selectedSave != -1) {
		writeToTextbox(_selectedSave, _filenameStrings[_selectedSave], _baseFont);
		_selectedSave = -1;
	}

	// Check Done button
	if (_exitButton) {
		_exitButton->handleInput(input);

		if (_exitButton->_isClicked) {
			_state = kStop;
			g_nancy->_sound->playSound("BUOK");
			return;
		}
	}
}

void LoadSaveMenu::enterFilename() {
	if (_enteringNewState) {
		// State has changed, revert all relevant objects to an appropriate state
		if (_cancelButton) {
			_cancelButton->setDisabled(false);
			_cancelButton->moveTo(_loadSaveData->_cancelButtonDests[_selectedSave]);
		}

		for (int i = 0; i < (int)_textboxes.size(); ++i) {
			bool sel = i == _selectedSave;
			writeToTextbox(i, sel ? Common::String() : _filenameStrings[i], sel ? _highlightFont : _disabledFont);
			_loadButtons[i]->setDisabled(true);

			if (i != _selectedSave) {
				_saveButtons[i]->setDisabled(true);
			}
		}

		_exitButton->setDisabled(true);
		_cancelButtonOverlays[_selectedSave]->setVisible(true);

		// Set up blinking cursor (doesn't blink in TVD)
		Common::Rect tbPosition = _textboxes[_selectedSave]->getScreenPosition();
		Common::Rect cursorRect = _blinkingCursorOverlay._drawSurface.getBounds();
		cursorRect.moveTo(tbPosition.left, tbPosition.bottom - _blinkingCursorOverlay._drawSurface.h + _loadSaveData->_fontYOffset);
		_blinkingCursorOverlay.moveTo(cursorRect);
		_blinkingCursorOverlay.setVisible(true);
		_nextBlink = g_nancy->getTotalPlayTime() + _loadSaveData->_blinkingTimeDelay;
		_enteringNewState = false;
		g_nancy->_input->setVKEnabled(true);
	}

	// Perform cursor blinking
	uint32 gameTime = g_nancy->getTotalPlayTime();
	if (_loadSaveData->_blinkingTimeDelay != 0 && gameTime > _nextBlink) {
		_blinkingCursorOverlay.setVisible(!_blinkingCursorOverlay.isVisible());
		_nextBlink = gameTime + _loadSaveData->_blinkingTimeDelay;
	}

	// Handle input
	NancyInput input = g_nancy->_input->getInput();

	// Improvement: we allow the enter key to sumbit
	bool enterKeyPressed = false;
	for (uint i = 0; i < input.otherKbdInput.size(); ++i) {
		Common::KeyState &key = input.otherKbdInput[i];
		if (key.keycode == Common::KEYCODE_BACKSPACE) {
			if (_enteredString.size()) {
				_enteredString.deleteLastChar();
			}
		} else if (key.keycode == Common::KEYCODE_RETURN || key.keycode == Common::KEYCODE_KP_ENTER) {
			enterKeyPressed = true;
		} else if (Common::isAlnum(key.ascii) || Common::isSpace(key.ascii)) {
			_enteredString += key.ascii;
		}

		uint16 textWidthInPixels = writeToTextbox(_selectedSave, _enteredString, _highlightFont);
		Common::Rect tbPosition = _textboxes[_selectedSave]->getScreenPosition();
		_blinkingCursorOverlay.moveTo(Common::Point(tbPosition.left + textWidthInPixels,
			tbPosition.bottom - _blinkingCursorOverlay._drawSurface.h + _loadSaveData->_fontYOffset));
	}

	_cancelButton->handleInput(input);
	if (_cancelButton->_isClicked) {
		_state = kRun;
		_enteringNewState = true;
		g_nancy->_sound->playSound("BULS");
		g_nancy->_input->setVKEnabled(false);
		return;
	}

	_saveButtons[_selectedSave]->handleInput(input);
	if (_saveButtons[_selectedSave]->_isClicked || enterKeyPressed) {
		_state = kSave;
		_enteringNewState = true;
		g_nancy->_sound->playSound("BULS");
		g_nancy->_input->setVKEnabled(false);
		return;
	}
}

void LoadSaveMenu::save() {
	auto *sdlg = GetEngineData(SDLG);

	if (sdlg && sdlg->dialogs.size() > 1) {
		// nancy6 added a "Do you want to overwrite this save" dialog.
		// First, check if we are actually overwriting
		SaveStateDescriptor desc = g_nancy->getMetaEngine()->querySaveMetaInfos(ConfMan.getActiveDomainName().c_str(), _selectedSave + 1);
		if (desc.isValid()) {
			if (!ConfMan.hasKey("sdlg_return", Common::ConfigManager::kTransientDomain)) {
				// Request the dialog
				ConfMan.setInt("sdlg_id", 1, Common::ConfigManager::kTransientDomain);
				_destroyOnExit = false;
				g_nancy->setState(NancyState::kSaveDialog);
				return;
			} else {
				// Dialog has returned
				g_nancy->_graphics->suppressNextDraw();
				_destroyOnExit = true;
				uint ret = ConfMan.getInt("sdlg_return", Common::ConfigManager::kTransientDomain);
				ConfMan.removeKey("sdlg_return", Common::ConfigManager::kTransientDomain);
				switch (ret) {
				case 1 :
					// "No" keeps us in the LoadSave state but doesn't save
					_state = kRun;
					return;
				case 2 :
					// "Cancel" returns to the main menu
					g_nancy->setState(NancyState::kMainMenu);
					return;
				default:
					// "Yes" actually saves
					break;
				}
			}
		}
	}

	// Improvement: not providing a name doesn't result in the
	// savefile being named "--- Empty ---" or "Nothing Saved Here".
	// Instead, we use ScummVM's built-in save name generator

	// This does not apply to nancy7, where a default name is provided in
	// the LOAD chunk, and has a number appended to the end

	Common::String finalDesc = _enteredString;
	if (!finalDesc.size()) {
		if (_loadSaveData->_defaultSaveNamePrefix.size()) {
			if (_filenameStrings[_selectedSave].equals(_loadSaveData->_emptySaveText)) {
				uint suffixNum = 1;
				for (int i = 1; i < g_nancy->getMetaEngine()->getMaximumSaveSlot(); ++i) {
					if (i == _selectedSave + 1) {
						continue;
					}

					SaveStateDescriptor desc = g_nancy->getMetaEngine()->querySaveMetaInfos(ConfMan.getActiveDomainName().c_str(), i);
					if (desc.getDescription().substr(0, _loadSaveData->_defaultSaveNamePrefix.size()).equals(Common::U32String(_loadSaveData->_defaultSaveNamePrefix))) {
						if (desc.getDescription().substr(_loadSaveData->_defaultSaveNamePrefix.size(), 1).asUint64() == suffixNum) {
							++suffixNum;
						} else {
							break;
						}
					}
				}

				finalDesc = _loadSaveData->_defaultSaveNamePrefix + ('0' + suffixNum);
			} else {
				finalDesc = _filenameStrings[_selectedSave];
			}
		} else {
			if (!_filenameStrings[_selectedSave].equals(g_nancy->getStaticData().emptySaveText)) {
				finalDesc = _filenameStrings[_selectedSave];
			}
		}
	}

	g_nancy->saveGameState(_selectedSave + 1, finalDesc, false);

	// Feed the new name back into the list of saves
	SaveStateDescriptor desc = g_nancy->getMetaEngine()->querySaveMetaInfos(ConfMan.getActiveDomainName().c_str(), _selectedSave + 1);
	if (desc.isValid()) {
		_filenameStrings[_selectedSave] = desc.getDescription();
	}

	if (_successOverlay._drawSurface.empty()) {
		_state = kRun;
		_enteringNewState = true;
	} else {
		_state = kSuccess;
		_enteringNewState = true;
	}

	_saveExists[_selectedSave] = true;
	g_nancy->_hasJustSaved = true;
}

void LoadSaveMenu::load() {
	auto *sdlg = GetEngineData(SDLG);

	if (sdlg && sdlg->dialogs.size() > 1 && Nancy::State::Scene::hasInstance() && !g_nancy->_hasJustSaved) {
		// nancy6 added a "Do you want load without saving" dialog.
		if (!ConfMan.hasKey("sdlg_return", Common::ConfigManager::kTransientDomain)) {
			// Request the dialog
			ConfMan.setInt("sdlg_id", 2, Common::ConfigManager::kTransientDomain);
			_destroyOnExit = false;
			g_nancy->setState(NancyState::kSaveDialog);
			return;
		} else {
			// Dialog has returned
			_destroyOnExit = true;
			g_nancy->_graphics->suppressNextDraw();
			uint ret = ConfMan.getInt("sdlg_return", Common::ConfigManager::kTransientDomain);
			ConfMan.removeKey("sdlg_return", Common::ConfigManager::kTransientDomain);
			switch (ret) {
			case 1 :
				// "No" keeps us in the LoadSave state but doesn't load
				_state = kRun;
				return;
			case 2 :
				// "Cancel" returns to the main menu
				g_nancy->setState(NancyState::kMainMenu);
				return;
			default:
				// "Yes" actually loads
				break;
			}
		}
	}

	if (Nancy::State::Scene::hasInstance()) {
		Nancy::State::Scene::destroy();
	}

	ConfMan.setInt("save_slot", _selectedSave + 1, Common::ConfigManager::kTransientDomain);

	_state = kStop;
	_enteringNewState = true;
}

void LoadSaveMenu::success() {
	// The original engine still lets the cursor blink in the background, but implementing that is completely unnecessary
	if (_enteringNewState) {
		_nextBlink = g_nancy->getTotalPlayTime() + 2000; // Hardcoded
		_successOverlay.setVisible(true);
		_enteringNewState = false;
	}

	if (g_nancy->getTotalPlayTime() > _nextBlink) {
		_state = kRun;
		_enteringNewState = true;
	}
}

void LoadSaveMenu::stop() {
	if (_selectedSave != -1) {
		g_nancy->setState(NancyState::kScene);
	} else {
		g_nancy->setState(NancyState::kMainMenu);
	}
}

uint16 LoadSaveMenu::writeToTextbox(uint textboxID, const Common::String &text, const Font *font) {
	assert(font);

	_textboxes[textboxID]->_drawSurface.clear(g_nancy->_graphics->getTransColor());
	Common::Point destPoint(_loadSaveData->_fontXOffset, _loadSaveData->_fontYOffset + _textboxes[textboxID]->_drawSurface.h - font->getFontHeight());
	font->drawString(&_textboxes[textboxID]->_drawSurface, text, destPoint.x, destPoint.y, _textboxes[textboxID]->_drawSurface.w, 0);
	_textboxes[textboxID]->setVisible(true);

	return font->getStringWidth(text);
}

} // End of namespace State
} // End of namespace Nancy