Skip to content

Commit

Permalink
NEVERHOOD: Implement game-internal savegame overwrite query screen
Browse files Browse the repository at this point in the history
- Rename and reorder fields in the Klaymen class
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent 9ae1888 commit 65c6984
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 24 deletions.
8 changes: 4 additions & 4 deletions engines/neverhood/klaymen.cpp
Expand Up @@ -62,7 +62,7 @@ static const KlaymenIdleTableItem klaymenIdleTable1002[] = {

Klaymen::Klaymen(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, NRectArray *clipRects)
: AnimatedSprite(vm, 1000), _idleCounterMax(0), _idleCounter(0), _isMoveObjectRequested(false), _blinkCounterMax(0),
_isWalkingOpenDoorNotified(false), _countdown1(0), _tapesToInsert(0), _keysToInsert(0), _busyStatus(0), _acceptInput(true),
_isWalkingOpenDoorNotified(false), _spitOutCountdown(0), _tapesToInsert(0), _keysToInsert(0), _busyStatus(0), _acceptInput(true),
_attachedSprite(NULL), _isWalking(false), _actionStatus(1), _parentScene(parentScene), _isSneaking(false), _isLargeStep(false),
_doYHitIncr(false), _isLeverDown(false), _isSittingInTeleporter(false), _actionStatusChanged(false), _ladderStatus(0), _pathPoints(NULL), _soundFlag(false),
_idleTableNum(0), _otherSprite(NULL), _moveObjectCountdown(0), _readyToSpit(false), _walkResumeFrameIncr(0) {
Expand Down Expand Up @@ -2718,7 +2718,7 @@ void Klaymen::stCrashDownFinished() {

void Klaymen::upSpitOutFall() {
Klaymen::update();
if (_countdown1 != 0 && (--_countdown1 == 0)) {
if (_spitOutCountdown != 0 && (--_spitOutCountdown == 0)) {
_surface->setVisible(true);
SetUpdateHandler(&Klaymen::update);
}
Expand Down Expand Up @@ -2902,7 +2902,7 @@ void Klaymen::stStandIdleSpecial() {
}

void Klaymen::stSpitOutFall0() {
_countdown1 = 1;
_spitOutCountdown = 1;
_busyStatus = 0;
_acceptInput = false;
startAnimation(0x000BAB02, 0, -1);
Expand All @@ -2914,7 +2914,7 @@ void Klaymen::stSpitOutFall0() {
}

void Klaymen::stSpitOutFall2() {
_countdown1 = 1;
_spitOutCountdown = 1;
_busyStatus = 0;
_acceptInput = false;
startAnimation(0x9308C132, 0, -1);
Expand Down
8 changes: 5 additions & 3 deletions engines/neverhood/klaymen.h
Expand Up @@ -401,20 +401,24 @@ class Klaymen : public AnimatedSprite {
int16 _destX, _destY;
int16 _idleCounter, _idleCounterMax;
int16 _blinkCounter, _blinkCounterMax;
int16 _countdown1;
int16 _tapesToInsert, _keysToInsert;
bool _doYHitIncr;
bool _isLeverDown;
bool _isWalkingOpenDoorNotified;
int _busyStatus;
bool _actionStatusChanged;
int _actionStatus;

const KlaymenIdleTableItem *_idleTable;
uint _idleTableCount;
int _idleTableTotalWeight;
int _idleTableNum;

NPointArray *_pathPoints;
bool _soundFlag;

int16 _spitOutCountdown;

bool _isSittingInTeleporter;

bool _potionFlag1;
Expand All @@ -423,7 +427,6 @@ class Klaymen : public AnimatedSprite {
int16 _platformDeltaY;

Sprite *_otherSprite;
int _idleTableNum;

int16 _walkResumeFrameIncr;

Expand All @@ -437,7 +440,6 @@ class Klaymen : public AnimatedSprite {
uint32 _spitContDestPipeIndex;

virtual void xUpdate();
// TODO Check if this can be turned into a void result
virtual uint32 xHandleMessage(int messageNum, const MessageParam &param);

void startWalkToX(int16 x, bool walkExt);
Expand Down
84 changes: 68 additions & 16 deletions engines/neverhood/menumodule.cpp
Expand Up @@ -32,7 +32,8 @@ enum {
CREDITS_SCENE = 1,
MAKING_OF = 2,
LOAD_GAME_MENU = 3,
SAVE_GAME_MENU = 4
SAVE_GAME_MENU = 4,
QUERY_OVR_MENU = 5
};

enum {
Expand Down Expand Up @@ -109,6 +110,9 @@ void MenuModule::createScene(int sceneNum, int which) {
case SAVE_GAME_MENU:
createSaveGameMenu();
break;
case QUERY_OVR_MENU:
_childObject = new QueryOverwriteMenu(_vm, this, _savegameDescription);
break;
}
SetUpdateHandler(&MenuModule::updateScene);
_childObject->handleUpdate();
Expand Down Expand Up @@ -162,7 +166,10 @@ void MenuModule::updateScene() {
handleLoadGameMenuAction(_moduleResult != 1);
break;
case SAVE_GAME_MENU:
handleSaveGameMenuAction(_moduleResult != 1);
handleSaveGameMenuAction(_moduleResult != 1, true);
break;
case QUERY_OVR_MENU:
handleSaveGameMenuAction(_moduleResult != 1, false);
break;
default:
break;
Expand Down Expand Up @@ -199,16 +206,19 @@ void MenuModule::handleLoadGameMenuAction(bool doLoad) {
_savegameList = NULL;
}

void MenuModule::handleSaveGameMenuAction(bool doSave) {
createScene(MAIN_MENU, -1);
if (doSave && _savegameSlot >= 0) {
void MenuModule::handleSaveGameMenuAction(bool doSave, bool doQuery) {
if (doSave && doQuery && _savegameSlot >= 0 && _savegameSlot < (int)_savegameList->size()) {
createScene(QUERY_OVR_MENU, -1);
} else if (doSave && _savegameSlot >= 0) {
// Restore the scene palette and background so that the correct thumbnail is saved
byte *menuPaletteData = _vm->_screen->getPaletteData();
_vm->_screen->setPaletteData(_savedPaletteData);
_vm->_gameModule->redrawPrevChildObject();
_vm->saveGameState(_savegameSlot, _savegameDescription);
_vm->_screen->setPaletteData(menuPaletteData);
leaveModule(0);
createScene(MAIN_MENU, -1);
} else {
createScene(MAIN_MENU, -1);
}
delete _savegameList;
_savegameList = NULL;
Expand Down Expand Up @@ -1010,22 +1020,13 @@ void LoadGameMenu::handleEvent(int16 itemID, int eventType) {
uint32 LoadGameMenu::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
Scene::handleMessage(messageNum, param, sender);
switch (messageNum) {
#if 0
case 0x000A:
sendMessage(_textEditWidget, 0x000A, param.asInteger());
setCurrWidget(_textEditWidget);
break;
#endif
case 0x000B:
if (param.asInteger() == Common::KEYCODE_RETURN) {
((MenuModule*)_parentModule)->setLoadgameInfo(_listBox->getCurrIndex());
leaveScene(0);
} else if (param.asInteger() == Common::KEYCODE_ESCAPE) {
leaveScene(1);
}/* else {
sendMessage(_textEditWidget, 0x000B, param.asInteger());
setCurrWidget(_textEditWidget);
}*/
}
break;
case 0x2000:
// Handle menu button click
Expand Down Expand Up @@ -1056,4 +1057,55 @@ uint32 LoadGameMenu::handleMessage(int messageNum, const MessageParam &param, En
return 0;
}

QueryOverwriteMenu::QueryOverwriteMenu(NeverhoodEngine *vm, Module *parentModule, const Common::String &description)
: Scene(vm, parentModule) {

static const uint32 kQueryOverwriteMenuButtonFileHashes[] = {
0x90312400,
0x94C22A22
};

static const NRect kQueryOverwriteMenuCollisionBounds[] = {
NRect(145, 334, 260, 385),
NRect(365, 340, 477, 388)
};

setBackground(0x043692C4);
setPalette(0x043692C4);
insertScreenMouse(0x692C004B);
insertStaticSprite(0x08C0AC24, 200);

for (uint buttonIndex = 0; buttonIndex < 2; ++buttonIndex) {
Sprite *menuButton = insertSprite<MenuButton>(this, buttonIndex,
kQueryOverwriteMenuButtonFileHashes[buttonIndex], kQueryOverwriteMenuCollisionBounds[buttonIndex]);
addCollisionSprite(menuButton);
}

// Draw the query text to the background, each text line is centered
// NOTE The original had this in its own class
FontSurface *fontSurface = new FontSurface(_vm, calcHash("bgQueryTinyAlphabet"), 32, 7, 32, 11, 17);
Common::StringArray textLines;
textLines.push_back(description);
textLines.push_back("Game exists.");
textLines.push_back("Overwrite it?");
for (uint i = 0; i < textLines.size(); ++i)
fontSurface->drawString(_background->getSurface(), 106 + (423 - textLines[i].size() * 11) / 2,
127 + 31 + i * 17, (const byte*)textLines[i].c_str());
delete fontSurface;

SetUpdateHandler(&Scene::update);
SetMessageHandler(&QueryOverwriteMenu::handleMessage);
}

uint32 QueryOverwriteMenu::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
Scene::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x2000:
// Handle menu button click
leaveScene(param.asInteger());
break;
}
return 0;
}

} // End of namespace Neverhood
9 changes: 8 additions & 1 deletion engines/neverhood/menumodule.h
Expand Up @@ -49,7 +49,7 @@ class MenuModule : public Module {
void createLoadGameMenu();
void createSaveGameMenu();
void handleLoadGameMenuAction(bool doLoad);
void handleSaveGameMenuAction(bool doSave);
void handleSaveGameMenuAction(bool doSave, bool doQuery);
void loadSavegameList();
};

Expand Down Expand Up @@ -235,6 +235,13 @@ class LoadGameMenu : public WidgetScene {
SavegameListBox *_listBox;
TextEditWidget *_textEditWidget;
Common::String _savegameDescription;
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
};

class QueryOverwriteMenu : public Scene {
public:
QueryOverwriteMenu(NeverhoodEngine *vm, Module *parentModule, const Common::String &description);
protected:
void update();
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
};
Expand Down

0 comments on commit 65c6984

Please sign in to comment.