Skip to content

Commit

Permalink
NEVERHOOD: Use the ScummVM dialogs for saving/loading
Browse files Browse the repository at this point in the history
An option has been added to use the original ones, if needed
  • Loading branch information
bluegr committed Jun 28, 2013
1 parent 5a8aa67 commit 9f70331
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 11 deletions.
16 changes: 15 additions & 1 deletion engines/neverhood/detection.cpp
Expand Up @@ -24,6 +24,7 @@

#include "engines/advancedDetector.h"
#include "common/file.h"
#include "common/translation.h"

#include "neverhood/neverhood.h"

Expand Down Expand Up @@ -143,6 +144,13 @@ static const NeverhoodGameDescription gameDescriptions[] = {

} // End of namespace Neverhood

static const ExtraGuiOption neverhoodExtraGuiOption = {
_s("Use original save/load screens"),
_s("Use the original save/load screens, instead of the ScummVM ones"),
"originalsaveload",
false
};

class NeverhoodMetaEngine : public AdvancedMetaEngine {
public:
NeverhoodMetaEngine() : AdvancedMetaEngine(Neverhood::gameDescriptions, sizeof(Neverhood::NeverhoodGameDescription), neverhoodGames) {
Expand All @@ -160,7 +168,7 @@ class NeverhoodMetaEngine : public AdvancedMetaEngine {

virtual bool hasFeature(MetaEngineFeature f) const;
virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;

virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const;
SaveStateList listSaves(const char *target) const;
virtual int getMaximumSaveSlot() const;
void removeSaveState(const char *target, int slot) const;
Expand Down Expand Up @@ -194,6 +202,12 @@ bool NeverhoodMetaEngine::createInstance(OSystem *syst, Engine **engine, const A
return gd != 0;
}

const ExtraGuiOptions NeverhoodMetaEngine::getExtraGuiOptions(const Common::String &target) const {
ExtraGuiOptions options;
options.push_back(neverhoodExtraGuiOption);
return options;
}

SaveStateList NeverhoodMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Neverhood::NeverhoodEngine::SaveHeader header;
Expand Down
77 changes: 67 additions & 10 deletions engines/neverhood/menumodule.cpp
Expand Up @@ -20,6 +20,11 @@
*
*/

#include "common/config-manager.h"
#include "common/translation.h"

#include "gui/saveload.h"

#include "neverhood/menumodule.h"
#include "neverhood/gamemodule.h"

Expand Down Expand Up @@ -193,24 +198,26 @@ uint32 MenuModule::handleMessage(int messageNum, const MessageParam &param, Enti
}

void MenuModule::createLoadGameMenu() {
_savegameSlot = -1;
_savegameList = new SavegameList();
loadSavegameList();
refreshSaveGameList();
_childObject = new LoadGameMenu(_vm, this, _savegameList);
}

void MenuModule::createSaveGameMenu() {
_savegameSlot = -1;
_savegameList = new SavegameList();
loadSavegameList();
refreshSaveGameList();
_childObject = new SaveGameMenu(_vm, this, _savegameList);
}

void MenuModule::createDeleteGameMenu() {
refreshSaveGameList();
_childObject = new DeleteGameMenu(_vm, this, _savegameList);
}

void MenuModule::refreshSaveGameList() {
_savegameSlot = -1;
delete _savegameList;
_savegameList = NULL;
_savegameList = new SavegameList();
loadSavegameList();
_childObject = new DeleteGameMenu(_vm, this, _savegameList);
}

void MenuModule::handleLoadGameMenuAction(bool doLoad) {
Expand Down Expand Up @@ -848,6 +855,36 @@ void SavegameListBox::pageDown() {
}
}

int GameStateMenu::scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc) {
const EnginePlugin *plugin = NULL;
EngineMan.findGame(ConfMan.get("gameid"), &plugin);
GUI::SaveLoadChooser *dialog;
Common::String desc;
int slot;

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

slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
desc = dialog->getResultString();

if (desc.empty())
desc = dialog->createDefaultSaveDescription(slot);

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

saveDesc = desc;
} else {
dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
}

delete dialog;

return slot;
}

GameStateMenu::GameStateMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList,
const uint32 *buttonFileHashes, const NRect *buttonCollisionBounds,
uint32 backgroundFileHash, uint32 fontFileHash,
Expand All @@ -857,8 +894,29 @@ GameStateMenu::GameStateMenu(NeverhoodEngine *vm, Module *parentModule, Savegame
uint32 textFileHash1, uint32 textFileHash2)
: Scene(vm, parentModule), _currWidget(NULL), _savegameList(savegameList) {

bool isSave = (textEditCursorFileHash != 0);

_fontSurface = new FontSurface(_vm, fontFileHash, 32, 7, 32, 11, 17);


if (!ConfMan.getBool("originalsaveload")) {
Common::String saveDesc;
int saveCount = savegameList->size();
int slot = scummVMSaveLoadDialog(isSave, saveDesc);

if (slot >= 0) {
if (!isSave) {
((MenuModule*)_parentModule)->setLoadgameInfo(slot);
} else {
((MenuModule*)_parentModule)->setSavegameInfo(saveDesc,
slot, slot >= saveCount);
}
leaveScene(0);
} else {
leaveScene(1);
}
return;
}

setBackground(backgroundFileHash);
setPalette(backgroundFileHash);
insertScreenMouse(mouseFileHash, mouseRect);
Expand All @@ -871,7 +929,7 @@ GameStateMenu::GameStateMenu(NeverhoodEngine *vm, Module *parentModule, Savegame

_textEditWidget = new TextEditWidget(_vm, textEditX, textEditY, this, 29,
_fontSurface, textEditBackgroundFileHash, textEditRect);
if (textEditCursorFileHash != 0)
if (isSave)
_textEditWidget->setCursor(textEditCursorFileHash, 2, 13);
else
_textEditWidget->setReadOnly(true);
Expand All @@ -886,7 +944,6 @@ GameStateMenu::GameStateMenu(NeverhoodEngine *vm, Module *parentModule, Savegame

SetUpdateHandler(&Scene::update);
SetMessageHandler(&GameStateMenu::handleMessage);

}

GameStateMenu::~GameStateMenu() {
Expand Down
2 changes: 2 additions & 0 deletions engines/neverhood/menumodule.h
Expand Up @@ -45,6 +45,7 @@ class MenuModule : public Module {
void setLoadgameInfo(uint index);
void setSavegameInfo(const Common::String &description, uint index, bool newSavegame);
void setDeletegameInfo(uint index);
void refreshSaveGameList();
protected:
int _sceneNum;
byte *_savedPaletteData;
Expand Down Expand Up @@ -229,6 +230,7 @@ class GameStateMenu : public Scene {
Common::String _savegameDescription;
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
virtual void performAction();
int scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc);
};

class SaveGameMenu : public GameStateMenu {
Expand Down
3 changes: 3 additions & 0 deletions engines/neverhood/neverhood.cpp
Expand Up @@ -77,6 +77,9 @@ Common::Error NeverhoodEngine::run() {
_gameState.sceneNum = 0;
_gameState.which = 0;

// Assign default values to the config manager, in case settings are missing
ConfMan.registerDefault("originalsaveload", "false");

_staticData = new StaticData();
_staticData->load("neverhood.dat");
_gameVars = new GameVars();
Expand Down
2 changes: 2 additions & 0 deletions po/POTFILES
Expand Up @@ -48,6 +48,8 @@ engines/groovie/script.cpp
engines/kyra/detection.cpp
engines/kyra/lol.cpp
engines/kyra/sound_midi.cpp
engines/neverhood/detection.cpp
engines/neverhood/menumodule.cpp
engines/queen/queen.cpp
engines/sky/compact.cpp
engines/sky/detection.cpp
Expand Down

0 comments on commit 9f70331

Please sign in to comment.