Example #1
0
bool StarTrekEngine::showSaveMenu() {
	GUI::SaveLoadChooser *dialog;
	Common::String desc;
	int slot;

	dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);

	slot = dialog->runModalWithCurrentTarget();
	desc = dialog->getResultString();

	if (desc.empty()) {
		// create our own description for the saved game, the user didnt enter it
		desc = dialog->createDefaultSaveDescription(slot);
	}

	if (desc.size() > 28)
		desc = Common::String(desc.c_str(), 28);

	delete dialog;

	if (slot < 0)
		return true;

	return saveGame(slot, desc);
}
Example #2
0
bool Keyboard::getKey(Common::Event &event) {
	Common::KeyCode keycode = event.kbd.keycode;

	switch (keycode) {
	case Common::KEYCODE_F1:
		if (event.type == Common::EVENT_KEYUP)
			return false;
		// Display ScummVM version and translation strings
		for (int i = 0; i < 3; i++)
			_vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL);
		return false;
	case Common::KEYCODE_F5:
		if (_vm->canSaveGameStateCurrently()) {
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
			int16 savegameId = dialog->runModalWithCurrentTarget();
			Common::String savegameDescription = dialog->getResultString();
			delete dialog;

			if (savegameId != -1)
				_vm->saveGameState(savegameId, savegameDescription);
		}
		return false;
	case Common::KEYCODE_F7:
		if (_vm->canLoadGameStateCurrently()) {
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
			int16 savegameId = dialog->runModalWithCurrentTarget();
			delete dialog;

			if (savegameId != -1)
				_vm->loadGameState(savegameId);
		}
		return false;
	case Common::KEYCODE_d:
		if (event.kbd.flags & Common::KBD_CTRL) {
			// Start the debugger
			_vm->getDebugger()->attach();
			_vm->getDebugger()->onFrame();
			return false;
		}
		break;
	case Common::KEYCODE_x:
		if (event.kbd.flags & Common::KBD_ALT) {
			_vm->quit();
			return false;
		}
		break;
	case Common::KEYCODE_F10:
		if (_vm->_commandHandler->idle())
			_vm->switchScene(-1); // Exits the game.
		return false;
	default:
		break;
	}

	return true;
}
Example #3
0
void WidgetFiles::showScummVMRestoreDialog() {
	GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
	int slot = dialog->runModalWithCurrentTarget();
	close();
	delete dialog;

	if (slot >= 0) {
		_vm->loadGameState(slot);
	}
}
Example #4
0
bool SavesManager::loadGame() {
	GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false);
	int slotNum = dialog->runModalWithCurrentTarget();
	delete dialog;

	if (slotNum != -1) {
		loadGameState(slotNum);
		g_vm->_interface->drawParty(true);
	}

	return slotNum != -1;
}
Example #5
0
bool StarTrekEngine::showLoadMenu() {
	GUI::SaveLoadChooser *dialog;
	int slot;

	dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
	slot = dialog->runModalWithCurrentTarget();

	delete dialog;

	if (slot < 0)
		return true;

	return loadGame(slot);
}
Example #6
0
void RingworldGame::handleSaveLoad(bool saveFlag, int &saveSlot, Common::String &saveName) {
	const EnginePlugin *plugin = 0;
	EngineMan.findGame(_vm->getGameId(), &plugin);
	GUI::SaveLoadChooser *dialog;
	if (saveFlag)
		dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"));
	else
		dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"));

	dialog->setSaveMode(saveFlag);

	saveSlot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
	saveName = dialog->getResultString();

	delete dialog;
}
Example #7
0
void DMEngine::initializeGame() {
	initMemoryManager();
	_displayMan->loadGraphics();
	_displayMan->initializeGraphicData();
	_displayMan->loadFloorSet(k0_FloorSetStone);
	_displayMan->loadWallSet(k0_WallSetStone);

	_sound->loadSounds(); // @ F0506_AMIGA_AllocateData

	if (!ConfMan.hasKey("save_slot")) // skip drawing title if loading from launcher
		drawTittle();

	_textMan->initialize();
	_objectMan->loadObjectNames();
	_eventMan->initMouse();

	int16 saveSlot = -1;
	do {
		// if loading from the launcher
		if (ConfMan.hasKey("save_slot")) {
			saveSlot = ConfMan.getInt("save_slot");
		} else { // else show the entrance
			processEntrance();
			if (_engineShouldQuit)
				return;

			if (_newGameFl == k0_modeLoadSavedGame) { // if resume was clicked, bring up ScummVM load screen
				GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
				saveSlot = dialog->runModalWithCurrentTarget();
				delete dialog;
			}
		}
	} while (loadgame(saveSlot) != k1_LoadgameSuccess);

	_displayMan->loadIntoBitmap(k11_MenuSpellAreLinesIndice, _menuMan->_bitmapSpellAreaLines); // @ F0396_MENUS_LoadSpellAreaLinesBitmap

	// There was some memory wizardy for the Amiga platform, I skipped that part
	_displayMan->allocateFlippedWallBitmaps();

	startGame();
	if (_newGameFl)
		_moveSens->getMoveResult(Thing::_party, kM1_MapXNotOnASquare, 0, _dungeonMan->_partyMapX, _dungeonMan->_partyMapY);
	_eventMan->showMouse();
	_eventMan->discardAllInput();
}
Example #8
0
void WidgetFiles::showScummVMSaveDialog() {
	GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);

	int slot = dialog->runModalWithCurrentTarget();
	if (slot >= 0) {
		Common::String desc = dialog->getResultString();

		if (desc.empty()) {
			// create our own description for the saved game, the user didn't enter it
			desc = dialog->createDefaultSaveDescription(slot);
		}

		_vm->saveGameState(slot, desc);
	}

	close();
	delete dialog;
}
Example #9
0
bool SavesManager::saveGame() {
	Map &map = *g_vm->_map;

	if (map.mazeData()._mazeFlags & RESTRICTION_SAVE) {
		ErrorScroll::show(g_vm, Res.SAVE_OFF_LIMITS, WT_NONFREEZED_WAIT);
		return false;
	} else if (!g_vm->canSaveGameStateCurrently()) {
		return false;
	} else {
		GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
		int slotNum = dialog->runModalWithCurrentTarget();
		Common::String saveName = dialog->getResultString();
		delete dialog;

		if (slotNum != -1)
			saveGameState(slotNum, saveName);

		return slotNum != -1;
	}
}
Example #10
0
bool LabEngine::saveRestoreGame() {
	bool isOK = false;

	// The original had one screen for saving/loading. We have two.
	// Ask the user which screen to use.
	GUI::MessageDialog saveOrLoad(_("Would you like to save or restore a game?"), _("Save"), _("Restore"));

	int choice = saveOrLoad.runModal();
	if (choice == GUI::kMessageOK) {
		// Save
		GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
		int slot = dialog->runModalWithCurrentTarget();
		if (slot >= 0) {
			Common::String desc = dialog->getResultString();

			if (desc.empty()) {
				// create our own description for the saved game, the user didn't enter it
				desc = dialog->createDefaultSaveDescription(slot);
			}

			isOK = saveGame(slot, desc);
		}
		delete dialog;
	} else {
		// Restore
		GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
		int slot = dialog->runModalWithCurrentTarget();
		if (slot >= 0) {
			isOK = loadGame(slot);
		}
		delete dialog;
	}

	return isOK;
}
Example #11
0
bool Keyboard::getKey(Common::Event &event, int &cgeCode) {
	Common::KeyCode keycode = event.kbd.keycode;
	if ((keycode == Common::KEYCODE_LCTRL) || (keycode == Common::KEYCODE_RCTRL)) {
		cgeCode = kKeyCtrl;
		return true;
	}
	if ((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) {
		cgeCode = kKeyAlt;
		return true;
	}
	if (keycode == Common::KEYCODE_KP_ENTER) {
		cgeCode = 28;
		return true;
	}
	if (keycode == Common::KEYCODE_F5) {
		warning("keycode %d", event.kbd.ascii);
		if (_vm->canSaveGameStateCurrently()) {
			const EnginePlugin *plugin = NULL;
			EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);

			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save");
			dialog->setSaveMode(true);
			int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
			Common::String savegameDescription = dialog->getResultString();
			delete dialog;
			_vm->saveGameState(savegameId, savegameDescription);
		}
		return false;
	} else if (keycode == Common::KEYCODE_F7) {
		if (_vm->canLoadGameStateCurrently()) {
			const EnginePlugin *plugin = NULL;
			EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);

			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore");
			dialog->setSaveMode(false);
			int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
			delete dialog;
			_vm->loadGameState(savegameId);
		}
		return false;
	}

	// Scan through the ScummVM mapping list
	for (int idx = 0; idx < 0x60; idx++) {
		if (_scummVmCodes[idx] == event.kbd.ascii) {
			cgeCode = idx;
			return true;
		}
	}

	return false;
}
Example #12
0
bool SaveManager::scummVMSaveLoadDialog(bool isSave) {
	GUI::SaveLoadChooser *dialog;
	Common::String desc;
	int slot;

	if (isSave) {
		dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);

		slot = dialog->runModalWithCurrentTarget();
		desc = dialog->getResultString();

		if (desc.empty()) {
			// create our own description for the saved game, the user didnt enter it
			desc = dialog->createDefaultSaveDescription(slot);
		}

		if (desc.size() > 28)
			desc = Common::String(desc.c_str(), 28);
	} else {
		dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
		slot = dialog->runModalWithCurrentTarget();
	}

	delete dialog;

	if (slot < 0)
		return false;

	if (isSave) {
		saveGame(slot, desc, false);
		return true;
	} else {
		Common::ErrorCode result = loadGame(slot).getCode();
		return (result == Common::kNoError);
	}
}
Example #13
0
void DMEngine::saveGame() {
    _menuMan->drawDisabledMenu();
    _eventMan->showMouse();

    switch (getGameLanguage()) { // localized
    default:
    case Common::EN_ANY:
        _dialog->dialogDraw(nullptr, nullptr, "SAVE AND PLAY", "SAVE AND QUIT", "CANCEL", "LOAD", false, false, false);
        break;
    case Common::DE_DEU:
        _dialog->dialogDraw(nullptr, nullptr, "SICHERN/SPIEL", "SICHERN/ENDEN", "WIDERRUFEN", "LOAD", false, false, false);
        break;
    case Common::FR_FRA:
        _dialog->dialogDraw(nullptr, nullptr, "GARDER/JOUER", "GARDER/SORTIR", "ANNULLER", "LOAD", false, false, false);
        break;
    }

    enum SaveAndPlayChoice {
        kSaveAndPlay = 1,
        kSaveAndQuit = 2,
        kCancel = 3,
        kLoad = 4
    };

    SaveAndPlayChoice saveAndPlayChoice = (SaveAndPlayChoice)_dialog->getChoice(4, kDMDialogCommandSetViewport, 0, kDMDialogChoiceNone);

    if (saveAndPlayChoice == kLoad) {
        GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
        int loadSlot = dialog->runModalWithCurrentTarget();
        if (loadSlot >= 0) {
            _loadSaveSlotAtRuntime = loadSlot;
            return;
        }

        saveAndPlayChoice = kCancel;
    }

    if (saveAndPlayChoice == kSaveAndQuit || saveAndPlayChoice == kSaveAndPlay) {
        GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
        int16 saveSlot = dialog->runModalWithCurrentTarget();
        Common::String saveDescription = dialog->getResultString();
        if (saveDescription.empty())
            saveDescription = "Nice save ^^";
        delete dialog;

        if (saveSlot >= 0) {
            switch (getGameLanguage()) { // localized
            default:
            case Common::EN_ANY:
                _dialog->dialogDraw(nullptr, "SAVING GAME . . .", nullptr, nullptr, nullptr, nullptr, false, false, false);
                break;
            case Common::DE_DEU:
                _dialog->dialogDraw(nullptr, "SPIEL WIRD GESICHERT . . .", nullptr, nullptr, nullptr, nullptr, false, false, false);
                break;
            case Common::FR_FRA:
                _dialog->dialogDraw(nullptr, "UN MOMENT A SAUVEGARDER DU JEU...", nullptr, nullptr, nullptr, nullptr, false, false, false);
                break;
            }

            uint16 champHandObjWeight = 0;
            if (!_championMan->_leaderEmptyHanded) {
                champHandObjWeight = _dungeonMan->getObjectWeight(_championMan->_leaderHandObject);
                _championMan->_champions[_championMan->_leaderIndex]._load -= champHandObjWeight;
            }

            if (!writeCompleteSaveFile(saveSlot, saveDescription, saveAndPlayChoice)) {
                _dialog->dialogDraw(nullptr, "Unable to open file for saving", "OK", nullptr, nullptr, nullptr, false, false, false);
                _dialog->getChoice(1, kDMDialogCommandSetViewport, 0, kDMDialogChoiceNone);
            }

            if (!_championMan->_leaderEmptyHanded) {
                _championMan->_champions[_championMan->_leaderIndex]._load += champHandObjWeight;
            }
        } else
            saveAndPlayChoice = kCancel;
    }


    if (saveAndPlayChoice == kSaveAndQuit) {
        _eventMan->hideMouse();
        endGame(false);
    }

    _restartGameAllowed = true;
    _menuMan->drawEnabledMenus();
    _eventMan->hideMouse();
}
Example #14
0
/**
 * Restore game from supplied slot number
 */
bool FileManager::restoreGame(const int16 slot) {
	debugC(1, kDebugFile, "restoreGame(%d)", slot);

	int16 savegameId;

	if (slot == -1) {
		GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false);
		savegameId = dialog->runModalWithCurrentTarget();
		delete dialog;
	} else {
		savegameId = slot;
	}

	if (savegameId < 0)                             // dialog aborted
		return false;

	Common::String savegameFile = _vm->getSavegameFilename(savegameId);
	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
	Common::InSaveFile *in = saveMan->openForLoading(savegameFile);

	if (!in)
		return false;

	// Initialize new-game status
	_vm->initStatus();

	// Check version, can't restore from different versions
	int saveVersion = in->readByte();
	if (saveVersion != kSavegameVersion) {
		warning("Savegame of incompatible version");
		delete in;
		return false;
	}

	// Skip over description
	int32 saveGameNameSize = in->readSint16BE();
	in->skip(saveGameNameSize);

	Graphics::skipThumbnail(*in);

	in->skip(6);                                    // Skip date & time

	// If hero image is currently swapped, swap it back before restore
	if (_vm->_heroImage != kHeroIndex)
		_vm->_object->swapImages(kHeroIndex, _vm->_heroImage);

	_vm->_object->restoreObjects(in);

	_vm->_heroImage = in->readByte();

	// If hero swapped in saved game, swap it
	byte heroImg = _vm->_heroImage;
	if (heroImg != kHeroIndex)
		_vm->_object->swapImages(kHeroIndex, _vm->_heroImage);
	_vm->_heroImage = heroImg;

	Status &gameStatus = _vm->getGameStatus();

	int score = in->readSint16BE();
	_vm->setScore(score);

	gameStatus._storyModeFl = (in->readByte() == 1);
	_vm->_mouse->setJumpExitFl(in->readByte() == 1);
	gameStatus._gameOverFl = (in->readByte() == 1);
	for (int i = 0; i < _vm->_numStates; i++)
		_vm->_screenStates[i] = in->readByte();

	_vm->_scheduler->restoreSchedulerData(in);

	// Restore palette and change it if necessary
	_vm->_screen->restorePal(in);

	// Restore maze status
	_vm->_maze._enabledFl = (in->readByte() == 1);
	_vm->_maze._size = in->readByte();
	_vm->_maze._x1 = in->readSint16BE();
	_vm->_maze._y1 = in->readSint16BE();
	_vm->_maze._x2 = in->readSint16BE();
	_vm->_maze._y2 = in->readSint16BE();
	_vm->_maze._x3 = in->readSint16BE();
	_vm->_maze._x4 = in->readSint16BE();
	_vm->_maze._firstScreenIndex = in->readByte();

	_vm->_scheduler->restoreScreen(*_vm->_screenPtr);
	if ((_vm->getGameStatus()._viewState = (Vstate) in->readByte()) != kViewPlay)
		_vm->_screen->hideCursor();


	delete in;
	return true;
}
Example #15
0
/**
 * Save game to supplied slot
 */
bool FileManager::saveGame(const int16 slot, const Common::String &descrip) {
	debugC(1, kDebugFile, "saveGame(%d, %s)", slot, descrip.c_str());

	int16 savegameId;
	Common::String savegameDescription;

	if (slot == -1) {
		GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true);
		savegameId = dialog->runModalWithCurrentTarget();
		savegameDescription = dialog->getResultString();
		delete dialog;
	} else {
		savegameId = slot;
		if (!descrip.empty()) {
			savegameDescription = descrip;
		} else {
			savegameDescription = Common::String::format("Quick save #%d", slot);
		}
	}

	if (savegameId < 0)                             // dialog aborted
		return false;

	Common::String savegameFile = _vm->getSavegameFilename(savegameId);
	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
	Common::OutSaveFile *out = saveMan->openForSaving(savegameFile);

	if (!out) {
		warning("Can't create file '%s', game not saved", savegameFile.c_str());
		return false;
	}

	// Write version.  We can't restore from obsolete versions
	out->writeByte(kSavegameVersion);

	if (savegameDescription == "") {
		savegameDescription = "Untitled savegame";
	}

	out->writeSint16BE(savegameDescription.size() + 1);
	out->write(savegameDescription.c_str(), savegameDescription.size() + 1);

	Graphics::saveThumbnail(*out);

	TimeDate curTime;
	_vm->_system->getTimeAndDate(curTime);

	uint32 saveDate = (curTime.tm_mday & 0xFF) << 24 | ((curTime.tm_mon + 1) & 0xFF) << 16 | ((curTime.tm_year + 1900) & 0xFFFF);
	uint16 saveTime = (curTime.tm_hour & 0xFF) << 8 | ((curTime.tm_min) & 0xFF);

	out->writeUint32BE(saveDate);
	out->writeUint16BE(saveTime);

	_vm->_object->saveObjects(out);

	const Status &gameStatus = _vm->getGameStatus();

	// Save whether hero image is swapped
	out->writeByte(_vm->_heroImage);

	// Save score
	out->writeSint16BE(_vm->getScore());

	// Save story mode
	out->writeByte((gameStatus._storyModeFl) ? 1 : 0);

	// Save jumpexit mode
	out->writeByte((_vm->_mouse->getJumpExitFl()) ? 1 : 0);

	// Save gameover status
	out->writeByte((gameStatus._gameOverFl) ? 1 : 0);

	// Save screen states
	for (int i = 0; i < _vm->_numStates; i++)
		out->writeByte(_vm->_screenStates[i]);

	_vm->_scheduler->saveSchedulerData(out);
	// Save palette table
	_vm->_screen->savePal(out);

	// Save maze status
	out->writeByte((_vm->_maze._enabledFl) ? 1 : 0);
	out->writeByte(_vm->_maze._size);
	out->writeSint16BE(_vm->_maze._x1);
	out->writeSint16BE(_vm->_maze._y1);
	out->writeSint16BE(_vm->_maze._x2);
	out->writeSint16BE(_vm->_maze._y2);
	out->writeSint16BE(_vm->_maze._x3);
	out->writeSint16BE(_vm->_maze._x4);
	out->writeByte(_vm->_maze._firstScreenIndex);

	out->writeByte((byte)_vm->getGameStatus()._viewState);

	out->finalize();

	delete out;

	return true;
}
Example #16
0
reg_t kRestoreGame(EngineState *s, int argc, reg_t *argv) {
	Common::String game_id = !argv[0].isNull() ? s->_segMan->getString(argv[0]) : "";
	int16 savegameId = argv[1].toSint16();
	bool pausedMusic = false;

	debug(3, "kRestoreGame(%s,%d)", game_id.c_str(), savegameId);

	if (argv[0].isNull()) {
		// Direct call, either from launcher or from a patched Game::restore
		if (savegameId == -1) {
			// we are supposed to show a dialog for the user and let him choose a saved game
			g_sci->_soundCmd->pauseAll(true); // pause music
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
			savegameId = dialog->runModalWithCurrentTarget();
			delete dialog;
			if (savegameId < 0) {
				g_sci->_soundCmd->pauseAll(false); // unpause music
				return s->r_acc;
			}
			pausedMusic = true;
		}
		// don't adjust ID of the saved game, it's already correct
	} else {
		if (argv[2].isNull())
			error("kRestoreGame: called with parameter 2 being NULL");
		// Real call from script, we need to adjust ID
		if ((savegameId < SAVEGAMEID_OFFICIALRANGE_START) || (savegameId > SAVEGAMEID_OFFICIALRANGE_END)) {
			warning("Savegame ID %d is not allowed", savegameId);
			return TRUE_REG;
		}
		savegameId -= SAVEGAMEID_OFFICIALRANGE_START;
	}

	s->r_acc = NULL_REG; // signals success

	Common::Array<SavegameDesc> saves;
	listSavegames(saves);
	if (findSavegame(saves, savegameId) == -1) {
		s->r_acc = TRUE_REG;
		warning("Savegame ID %d not found", savegameId);
	} else {
		Common::SaveFileManager *saveFileMan = g_sci->getSaveFileManager();
		Common::String filename = g_sci->getSavegameName(savegameId);
		Common::SeekableReadStream *in;

		in = saveFileMan->openForLoading(filename);
		if (in) {
			// found a savegame file

			gamestate_restore(s, in);
			delete in;

			if (g_sci->getGameId() == GID_MOTHERGOOSE256) {
				// WORKAROUND: Mother Goose SCI1/SCI1.1 does some weird things for
				//  saving a previously restored game.
				// We set the current savedgame-id directly and remove the script
				//  code concerning this via script patch.
				s->variables[VAR_GLOBAL][0xB3].setOffset(SAVEGAMEID_OFFICIALRANGE_START + savegameId);
			}
		} else {
			s->r_acc = TRUE_REG;
			warning("Savegame #%d not found", savegameId);
		}
	}

	if (!s->r_acc.isNull()) {
		// no success?
		if (pausedMusic)
			g_sci->_soundCmd->pauseAll(false); // unpause music
	}

	return s->r_acc;
}
Example #17
0
reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
	Common::String game_id;
 	int16 virtualId = argv[1].toSint16();
	int16 savegameId = -1;
	Common::String game_description;
	Common::String version;

	if (argc > 3)
		version = s->_segMan->getString(argv[3]);

	// We check here, we don't want to delete a users save in case we are within a kernel function
	if (s->executionStackBase) {
		warning("kSaveGame - won't save from within kernel function");
		return NULL_REG;
	}

	if (argv[0].isNull()) {
		// Direct call, from a patched Game::save
		if ((argv[1] != SIGNAL_REG) || (!argv[2].isNull()))
			error("kSaveGame: assumed patched call isn't accurate");

		// we are supposed to show a dialog for the user and let him choose where to save
		g_sci->_soundCmd->pauseAll(true); // pause music
		GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
		savegameId = dialog->runModalWithCurrentTarget();
		game_description = dialog->getResultString();
		if (game_description.empty()) {
			// create our own description for the saved game, the user didnt enter it
			game_description = dialog->createDefaultSaveDescription(savegameId);
		}
		delete dialog;
		g_sci->_soundCmd->pauseAll(false); // unpause music ( we can't have it paused during save)
		if (savegameId < 0)
			return NULL_REG;

	} else {
		// Real call from script
		game_id = s->_segMan->getString(argv[0]);
		if (argv[2].isNull())
			error("kSaveGame: called with description being NULL");
		game_description = s->_segMan->getString(argv[2]);

		debug(3, "kSaveGame(%s,%d,%s,%s)", game_id.c_str(), virtualId, game_description.c_str(), version.c_str());

		Common::Array<SavegameDesc> saves;
		listSavegames(saves);

		if ((virtualId >= SAVEGAMEID_OFFICIALRANGE_START) && (virtualId <= SAVEGAMEID_OFFICIALRANGE_END)) {
			// savegameId is an actual Id, so search for it just to make sure
			savegameId = virtualId - SAVEGAMEID_OFFICIALRANGE_START;
			if (findSavegame(saves, savegameId) == -1)
				return NULL_REG;
		} else if (virtualId < SAVEGAMEID_OFFICIALRANGE_START) {
			// virtualId is low, we assume that scripts expect us to create new slot
			if (virtualId == s->_lastSaveVirtualId) {
				// if last virtual id is the same as this one, we assume that caller wants to overwrite last save
				savegameId = s->_lastSaveNewId;
			} else {
				uint savegameNr;
				// savegameId is in lower range, scripts expect us to create a new slot
				for (savegameId = 0; savegameId < SAVEGAMEID_OFFICIALRANGE_START; savegameId++) {
					for (savegameNr = 0; savegameNr < saves.size(); savegameNr++) {
						if (savegameId == saves[savegameNr].id)
							break;
					}
					if (savegameNr == saves.size())
						break;
				}
				if (savegameId == SAVEGAMEID_OFFICIALRANGE_START)
					error("kSavegame: no more savegame slots available");
			}
		} else {
			error("kSaveGame: invalid savegameId used");
		}

		// Save in case caller wants to overwrite last newly created save
		s->_lastSaveVirtualId = virtualId;
		s->_lastSaveNewId = savegameId;
	}

	s->r_acc = NULL_REG;

	Common::String filename = g_sci->getSavegameName(savegameId);
	Common::SaveFileManager *saveFileMan = g_sci->getSaveFileManager();
	Common::OutSaveFile *out;

	out = saveFileMan->openForSaving(filename);
	if (!out) {
		warning("Error opening savegame \"%s\" for writing", filename.c_str());
	} else {
		if (!gamestate_save(s, out, game_description, version)) {
			warning("Saving the game failed");
		} else {
			s->r_acc = TRUE_REG; // save successful
		}

		out->finalize();
		if (out->err()) {
			warning("Writing the savegame failed");
			s->r_acc = NULL_REG; // write failure
		}
		delete out;
	}

	return s->r_acc;
}
Example #18
0
bool Keyboard::getKey(Common::Event &event) {
	Common::KeyCode keycode = event.kbd.keycode;

	if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && event.type == Common::EVENT_KEYDOWN)
		_keyAlt = true;
	else
		_keyAlt = false;

	switch (keycode) {
	case Common::KEYCODE_F1:
		if (event.type == Common::EVENT_KEYUP)
			return false;
		// Display ScummVM version and translation strings
		for (int i = 0; i < 5; i++)
			_vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL);
		return false;
	case Common::KEYCODE_F5:
		if (_vm->canSaveGameStateCurrently()) {
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true);
			int16 savegameId = dialog->runModalWithCurrentTarget();
			Common::String savegameDescription = dialog->getResultString();
			delete dialog;

			if (savegameId != -1)
				_vm->saveGameState(savegameId, savegameDescription);
			}
		return false;
	case Common::KEYCODE_F7:
		if (_vm->canLoadGameStateCurrently()) {
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false);
			int16 savegameId = dialog->runModalWithCurrentTarget();
			delete dialog;

			if (savegameId != -1)
				_vm->loadGameState(savegameId);
		}
		return false;
	case Common::KEYCODE_d:
		if (event.kbd.flags & Common::KBD_CTRL) {
		// Start the debugger
			_vm->getDebugger()->attach();
			_vm->getDebugger()->onFrame();
			return false;
		}
		break;
	case Common::KEYCODE_x:
		if (event.kbd.flags & Common::KBD_ALT) {
			_vm->quit();
			return false;
		}
		break;
	case Common::KEYCODE_0:
	case Common::KEYCODE_1:
	case Common::KEYCODE_2:
	case Common::KEYCODE_3:
	case Common::KEYCODE_4:
		if (event.kbd.flags & Common::KBD_ALT) {
			_vm->_commandHandler->addCommand(kCmdLevel, -1, keycode - Common::KEYCODE_0, NULL);
			return false;
		}
		// Fallthrough intended
	case Common::KEYCODE_5:
	case Common::KEYCODE_6:
	case Common::KEYCODE_7:
	case Common::KEYCODE_8:
		if (event.type == Common::EVENT_KEYDOWN && !(event.kbd.flags & Common::KBD_ALT) && keycode != Common::KEYCODE_0) {
			_vm->selectPocket(keycode - Common::KEYCODE_1);
			return false;
		}
		break;
	default:
		break;
	}

	return true;
}
Example #19
0
bool Keyboard::getKey(Common::Event &event) {
	Common::KeyCode keycode = event.kbd.keycode;

	if ((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT))
		_keyAlt = true;
	else
		_keyAlt = false;

	switch (keycode) {
	case Common::KEYCODE_F1:
		if (event.type == Common::EVENT_KEYUP)
			return false;
		// Display ScummVM version and translation strings
		for (int i = 0; i < 5; i++)
			_vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL);
		return false;
	case Common::KEYCODE_F5:
		if (_vm->canSaveGameStateCurrently()) {
			const EnginePlugin *plugin = NULL;
			EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);

			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save");
			dialog->setSaveMode(true);
			int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
			Common::String savegameDescription = dialog->getResultString();
			delete dialog;

			if (savegameId != -1)
				_vm->saveGameState(savegameId, savegameDescription);
			}
		return false;
	case Common::KEYCODE_F7:
		if (_vm->canLoadGameStateCurrently()) {
			const EnginePlugin *plugin = NULL;
			EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);

			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore");
			dialog->setSaveMode(false);
			int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
			delete dialog;

			if (savegameId != -1)
				_vm->loadGameState(savegameId);
		}
		return false;
	case Common::KEYCODE_d:
		if (event.kbd.flags & Common::KBD_CTRL) {
		// Start the debugger
			_vm->getDebugger()->attach();
			_vm->getDebugger()->onFrame();
			return false;
		}
		break;
	case Common::KEYCODE_x:
		if (event.kbd.flags & Common::KBD_ALT) {
			_vm->quit();
			return false;
		}
		break;
	case Common::KEYCODE_0:
	case Common::KEYCODE_1:
	case Common::KEYCODE_2:
	case Common::KEYCODE_3:
	case Common::KEYCODE_4:
		if (event.kbd.flags & Common::KBD_ALT) {
			_vm->_commandHandler->addCommand(kCmdLevel, -1, keycode - '0', NULL);
			return false;
		}
	default:
		break;
	}

	return true;
}
Example #20
0
void MenuSystem::initMenu(MenuID menuID) {
	_items.clear();

	memcpy(_vm->_screen->_frontScreen, _background->getPixels(), 640 * 400);

	switch (menuID) {
	case kMenuIdMain:
		drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrWhatCanIDoForYou));
		addClickTextItem(kItemIdLoad, 0, 116, 320, 0, _vm->getSysString(kStrLoad), 253, 255);
		addClickTextItem(kItemIdSave, 0, 136, 320, 0, _vm->getSysString(kStrSave), 253, 255);
		addClickTextItem(kItemIdToggleText, 0, 166, 320, 0, _vm->getSysString(_vm->_cfgText ? kStrTextOn : kStrTextOff), 253, 255);
		addClickTextItem(kItemIdToggleVoices, 0, 186, 320, 0, _vm->getSysString(_vm->_cfgVoices ? kStrVoicesOn : kStrVoicesOff), 253, 255);
		addClickTextItem(kItemIdVolumesMenu, 0, 216, 320, 0, _vm->getSysString(kStrVolume), 253, 255);
		addClickTextItem(kItemIdPlay, 0, 246, 320, 0, _vm->getSysString(kStrPlay), 253, 255);
		addClickTextItem(kItemIdQuit, 0, 276, 320, 0, _vm->getSysString(kStrQuit), 253, 255);
		break;
	case kMenuIdLoad:
		if (ConfMan.getBool("originalsaveload")) {
			shadeRect(80, 92, 440, 141, 226, 225);
			drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrLoadGame));
			addClickTextItem(kItemIdSavegameUp, 0, 156, 545, 1, "^", 253, 255);
			addClickTextItem(kItemIdSavegameDown, 0, 196, 545, 1, "\\", 253, 255);
			addClickTextItem(kItemIdCancel, 0, 276, 320, 0, _vm->getSysString(kStrCancel), 253, 255);
			for (int i = 1; i <= 7; i++) {
				Common::String saveDesc = Common::String::format("SAVEGAME %d", i);
				addClickTextItem((ItemID)(kItemIdSavegame1 + i - 1), 0, 116 + 20 * (i - 1), 300, 0, saveDesc.c_str(), 231, 234);
			}
			loadSavegamesList();
			setSavegameCaptions(true);
		} else {
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
			int slot = dialog->runModalWithCurrentTarget();
			delete dialog;

			if (slot >= 0)
				_vm->requestLoadgame(slot);

			_running = false;
		}
		break;
	case kMenuIdSave:
		if (ConfMan.getBool("originalsaveload")) {
			shadeRect(80, 92, 440, 141, 226, 225);
			drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrSaveGame));
			addClickTextItem(kItemIdSavegameUp, 0, 156, 545, 1, "^", 253, 255);
			addClickTextItem(kItemIdSavegameDown, 0, 196, 545, 1, "\\", 253, 255);
			addClickTextItem(kItemIdCancel, 0, 276, 320, 0, _vm->getSysString(kStrCancel), 253, 255);
			for (int i = 1; i <= 7; i++) {
				Common::String saveDesc = Common::String::format("SAVEGAME %d", i);
				addClickTextItem((ItemID)(kItemIdSavegame1 + i - 1), 0, 116 + 20 * (i - 1), 300, 0, saveDesc.c_str(), 231, 234);
			}
			int newSlotNum = loadSavegamesList() + 1;
			_savegames.push_back(SavegameItem(newSlotNum, Common::String::format("GAME %04d", _savegames.size())));
			setSavegameCaptions(true);
		} else {
			GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
			int slot = dialog->runModalWithCurrentTarget();
			Common::String desc = dialog->getResultString();
			if (desc.empty()) {
				// Create our own description for the saved game, the user didn't enter one
				desc = dialog->createDefaultSaveDescription(slot);
			}

			if (slot >= 0)
				_vm->requestSavegame(slot, desc);

			_running = false;
		}
		break;
	case kMenuIdVolumes:
		drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrAdjustVolume));
		drawString(0, 131, 200, 0, 246, _vm->getSysString(kStrMaster));
		drawString(0, 156, 200, 0, 244, _vm->getSysString(kStrVoices));
		drawString(0, 181, 200, 0, 244, _vm->getSysString(kStrMusic));
		drawString(0, 206, 200, 0, 244, _vm->getSysString(kStrSoundFx));
		drawString(0, 231, 200, 0, 244, _vm->getSysString(kStrBackground));
		addClickTextItem(kItemIdDone, 0, 276, 200, 0, _vm->getSysString(kStrDone), 253, 255);
		addClickTextItem(kItemIdCancel, 0, 276, 440, 0, _vm->getSysString(kStrCancel), 253, 255);
		addClickTextItem(kItemIdMasterDown, 0, 131 + 25 * 0, 348, 1, "[", 243, 246);
		addClickTextItem(kItemIdVoicesDown, 0, 131 + 25 * 1, 348, 1, "[", 243, 246);
		addClickTextItem(kItemIdMusicDown, 0, 131 + 25 * 2, 348, 1, "[", 243, 246);
		addClickTextItem(kItemIdSoundFXDown, 0, 131 + 25 * 3, 348, 1, "[", 243, 246);
		addClickTextItem(kItemIdBackgroundDown, 0, 131 + 25 * 4, 348, 1, "[", 243, 246);
		addClickTextItem(kItemIdMasterUp, 0, 131 + 25 * 0, 372, 1, "]", 243, 246);
		addClickTextItem(kItemIdVoicesUp, 0, 131 + 25 * 1, 372, 1, "]", 243, 246);
		addClickTextItem(kItemIdMusicUp, 0, 131 + 25 * 2, 372, 1, "]", 243, 246);
		addClickTextItem(kItemIdSoundFXUp, 0, 131 + 25 * 3, 372, 1, "]", 243, 246);
		addClickTextItem(kItemIdBackgroundUp, 0, 131 + 25 * 4, 372, 1, "]", 243, 246);
		drawVolumeBar(kItemIdMaster);
		drawVolumeBar(kItemIdVoices);
		drawVolumeBar(kItemIdMusic);
		drawVolumeBar(kItemIdSoundFX);
		drawVolumeBar(kItemIdBackground);
		break;
	default:
		break;
	}

	for (Common::Array<Item>::iterator iter = _items.begin(); iter != _items.end(); ++iter) {
		if ((*iter).enabled)
			drawItem((*iter).id, false);
	}

	// Check if the mouse is already over an item
	_currItemID = kItemIdNone;
	Common::Point mousePos = _vm->_system->getEventManager()->getMousePos();
	handleMouseMove(mousePos.x, mousePos.y);
}