ASYLUM: Unify cancel event handling for puzzles and encounters

This commit is contained in:
Cameron Cawley 2024-06-16 15:02:36 +01:00 committed by Alexander Panov
parent 3922c71287
commit c08d7e3193
32 changed files with 55 additions and 103 deletions

View File

@ -136,7 +136,7 @@ void PuzzleBoard::updateScreen() {
}
}
bool PuzzleBoard::mouseRightDown(const AsylumEvent &) {
bool PuzzleBoard::exitPuzzle() {
if (!stopSound()) {
getScreen()->clear();
_vm->switchEventHandler(getScene());

View File

@ -78,14 +78,14 @@ protected:
bool stopSound();
void checkSlots();
private:
//////////////////////////////////////////////////////////////////////////
// Event Handling
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
bool activate(const AsylumEvent &evt) { return updateScreen(), true; }
virtual bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
private:
//////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////

View File

@ -203,11 +203,10 @@ bool PuzzleBoardSalvation::mouseLeftDown(const AsylumEvent &) {
return true;
}
bool PuzzleBoardSalvation::mouseRightDown(const AsylumEvent &) {
bool PuzzleBoardSalvation::exitPuzzle() {
if (!stopSound()) {
checkANALText();
getScreen()->clear();
_vm->switchEventHandler(getScene());
return PuzzleBoard::exitPuzzle();
}
return true;

View File

@ -40,7 +40,7 @@ private:
// Event Handling
//////////////////////////////////////////////////////////////////////////
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -112,8 +112,7 @@ void PuzzleClock::updateScreen() {
_vm->switchEventHandler(getScene());
} else {
if (_vm->isGameFlagSet(kGameFlag511)) {
AsylumEvent evt;
mouseRightDown(evt);
exitPuzzle();
}
}
}
@ -134,7 +133,7 @@ bool PuzzleClock::mouseLeftDown(const AsylumEvent &) {
return true;
}
bool PuzzleClock::mouseRightDown(const AsylumEvent &) {
bool PuzzleClock::exitPuzzle() {
setFlag();
_rightButtonClicked = true;

View File

@ -49,7 +49,7 @@ private:
bool init(const AsylumEvent &evt);
void updateScreen();
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -165,7 +165,7 @@ bool PuzzleFisherman::mouseLeftDown(const AsylumEvent &evt) {
return true;
}
bool PuzzleFisherman::mouseRightDown(const AsylumEvent &) {
bool PuzzleFisherman::exitPuzzle() {
getCursor()->hide();
getSharedData()->setFlag(kFlag1, true);
getScreen()->stopPaletteFade(0, 0, 0);

View File

@ -49,9 +49,8 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
void updateScreen();
bool key(const AsylumEvent &evt) { return keyExit(evt); }
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -274,7 +274,7 @@ bool PuzzleHiveControl::mouseLeftDown(const AsylumEvent &) {
return true;
}
bool PuzzleHiveControl::mouseRightDown(const AsylumEvent &) {
bool PuzzleHiveControl::exitPuzzle() {
if (_leverDelta) {
_leverDelta = 0;
_prevLeverPosition = _leverPosition;
@ -451,8 +451,7 @@ void PuzzleHiveControl::updateScreen() {
if (_counter < 30 || getSound()->isPlaying(getWorld()->graphicResourceIds[83])) {
++_counter;
} else {
AsylumEvent evt;
mouseRightDown(evt);
exitPuzzle();
getCursor()->show();
}
}

View File

@ -104,7 +104,7 @@ private:
bool init(const AsylumEvent &evt);
void updateScreen();
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -94,7 +94,7 @@ bool PuzzleHiveMachine::mouseLeftDown(const AsylumEvent &) {
return true;
}
bool PuzzleHiveMachine::mouseRightDown(const AsylumEvent &) {
bool PuzzleHiveMachine::exitPuzzle() {
_notesNumber = 0;
_melody.clear();

View File

@ -58,7 +58,7 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -220,8 +220,10 @@ bool PuzzleLock::mouseLeftDown(const AsylumEvent &evt) {
return true;
}
bool PuzzleLock::mouseRightDown(const AsylumEvent &) {
exitPuzzle();
bool PuzzleLock::exitPuzzle() {
getScreen()->clear();
_vm->switchEventHandler(getScene());
return true;
}

View File

@ -47,9 +47,8 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
bool update(const AsylumEvent &evt);
bool key(const AsylumEvent &evt) { return keyExit(evt); }
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -205,7 +205,7 @@ bool PuzzleMorgueDoor::mouseLeftDown(const AsylumEvent &evt) {
return true;
}
bool PuzzleMorgueDoor::mouseRightUp(const AsylumEvent &) {
bool PuzzleMorgueDoor::exitPuzzle() {
getCursor()->hide();
getSharedData()->setFlag(kFlag1, true);
getScreen()->stopPaletteFade(0, 0, 0);

View File

@ -75,9 +75,8 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
void updateScreen();
bool key(const AsylumEvent &evt) { return keyExit(evt); }
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightUp(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -462,7 +462,7 @@ bool PuzzlePipes::mouseLeftDown(const AsylumEvent &) {
return true;
}
bool PuzzlePipes::mouseRightDown(const AsylumEvent &) {
bool PuzzlePipes::exitPuzzle() {
getScreen()->clear();
getSound()->stop(getWorld()->graphicResourceIds[41]);
getSound()->setMusicVolume(_previousMusicVolume);

View File

@ -187,7 +187,7 @@ private:
bool init(const AsylumEvent &evt);
void updateScreen();
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -58,9 +58,6 @@ bool Puzzle::handleEvent(const AsylumEvent &evt) {
case EVENT_ASYLUM_UPDATE:
return update(evt);
case Common::EVENT_KEYDOWN:
return key(evt);
case Common::EVENT_LBUTTONDOWN:
return mouseLeftDown(evt);
@ -68,13 +65,8 @@ bool Puzzle::handleEvent(const AsylumEvent &evt) {
return mouseLeftUp(evt);
case Common::EVENT_RBUTTONDOWN:
return mouseRightDown(evt);
case Common::EVENT_RBUTTONUP:
return mouseRightUp(evt);
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
return keyExit(evt);
return exitPuzzle();
}
return false;
@ -107,19 +99,6 @@ bool Puzzle::update(const AsylumEvent &evt) {
return true;
}
bool Puzzle::keyExit(const AsylumEvent &evt) {
_vm->switchEventHandler(getScene());
return true;
}
void Puzzle::exitPuzzle() {
getScreen()->clear();
_vm->switchEventHandler(getScene());
}
//////////////////////////////////////////////////////////////////////////
// Hit test functions
//////////////////////////////////////////////////////////////////////////

View File

@ -59,14 +59,10 @@ protected:
virtual void updateScreen() {};
virtual void updateCursor() {};
virtual bool activate(const AsylumEvent &evt) { return true; }
virtual bool key(const AsylumEvent &evt) { return true; }
virtual bool mouseLeftUp(const AsylumEvent &evt) { return true; }
virtual bool mouseLeftDown(const AsylumEvent &evt) { return true; }
virtual bool mouseRightUp(const AsylumEvent &evt) { return true; }
virtual bool mouseRightDown(const AsylumEvent &evt) { return true; }
bool keyExit(const AsylumEvent &evt);
void exitPuzzle();
virtual bool exitPuzzle() = 0;
//////////////////////////////////////////////////////////////////////////
// Hit test functions

View File

@ -171,8 +171,10 @@ bool PuzzleTicTacToe::mouseLeftDown(const AsylumEvent &evt) {
return true;
}
bool PuzzleTicTacToe::mouseRightDown(const AsylumEvent &) {
exitPuzzle();
bool PuzzleTicTacToe::exitPuzzle() {
getScreen()->clear();
_vm->switchEventHandler(getScene());
return true;
}

View File

@ -59,9 +59,8 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
void updateScreen();
bool key(const AsylumEvent &evt) { return keyExit(evt); }
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Init & update

View File

@ -231,7 +231,7 @@ bool PuzzleTimeMachine::mouseLeftDown(const AsylumEvent &evt) {
return true;
}
bool PuzzleTimeMachine::mouseRightDown(const AsylumEvent &) {
bool PuzzleTimeMachine::exitPuzzle() {
getCursor()->hide();
getSharedData()->setFlag(kFlag1, true);
getScreen()->stopPaletteFade(0, 0, 0);

View File

@ -60,9 +60,8 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
void updateScreen();
bool key(const AsylumEvent &evt) { return keyExit(evt); }
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -85,16 +85,6 @@ bool PuzzleVCR::init(const AsylumEvent &) {
return true;
}
bool PuzzleVCR::key(const AsylumEvent &evt) {
getSound()->stop(getWorld()->graphicResourceIds[47]);
getScreen()->clearGraphicsInQueue();
getScreen()->clear();
_vm->switchEventHandler(getScene());
return true;
}
bool PuzzleVCR::mouseLeftDown(const AsylumEvent &evt) {
if (_isAccomplished)
return true;
@ -259,12 +249,11 @@ bool PuzzleVCR::mouseLeftUp(const AsylumEvent &) {
return true;
}
bool PuzzleVCR::mouseRightDown(const AsylumEvent &) {
bool PuzzleVCR::exitPuzzle() {
getSound()->stop(getWorld()->graphicResourceIds[47]);
getScreen()->clearGraphicsInQueue();
getScreen()->clear();
getSound()->stop(getWorld()->graphicResourceIds[47]);
_vm->switchEventHandler(getScene());
return true;

View File

@ -105,10 +105,9 @@ private:
// Event Handling
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
bool key(const AsylumEvent &evt);
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseLeftUp(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Drawing

View File

@ -286,7 +286,7 @@ bool PuzzleWheel::mouseLeftDown(const AsylumEvent &) {
return true;
}
bool PuzzleWheel::mouseRightDown(const AsylumEvent &) {
bool PuzzleWheel::exitPuzzle() {
getScreen()->clear();
_vm->switchEventHandler(getScene());

View File

@ -56,7 +56,7 @@ private:
bool init(const AsylumEvent &evt);
void updateScreen();
bool mouseLeftDown(const AsylumEvent &evt);
bool mouseRightDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers

View File

@ -154,7 +154,7 @@ bool PuzzleWritings::update(const AsylumEvent &) {
return true;
}
bool PuzzleWritings::mouseRightUp(const AsylumEvent &) {
bool PuzzleWritings::exitPuzzle() {
getCursor()->hide();
getSharedData()->setFlag(kFlag1, true);
getScreen()->stopPaletteFade(0, 0, 0);

View File

@ -45,8 +45,7 @@ private:
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
bool update(const AsylumEvent &evt);
bool key(const AsylumEvent &evt) { return keyExit(evt); }
bool mouseRightUp(const AsylumEvent &evt);
bool exitPuzzle();
};
} // End of namespace Asylum

View File

@ -366,22 +366,16 @@ bool Encounter::handleEvent(const AsylumEvent &evt) {
case EVENT_ASYLUM_UPDATE:
return update();
case Common::EVENT_KEYDOWN:
return key(evt);
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
return mouse(evt);
case Common::EVENT_RBUTTONDOWN:
return cancel(evt);
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
if ((AsylumAction)evt.customType == kAsylumActionShowMenu) {
if (!isSpeaking()
&& _isDialogOpen
&& !getSpeech()->getTextData()
&& !getSpeech()->getTextDataPos())
_shouldCloseDialog = true;
return cancel(evt);
}
return true;
}
@ -553,20 +547,20 @@ bool Encounter::mouse(const AsylumEvent &evt) {
_data_455BD8 = false;
}
break;
case Common::EVENT_RBUTTONDOWN:
if (!isSpeaking()
&& _isDialogOpen
&& !getSpeech()->getTextData()
&& !getSpeech()->getTextDataPos())
_shouldCloseDialog = true;
break;
}
return true;
}
bool Encounter::cancel(const AsylumEvent &evt) {
if (!isSpeaking()
&& _isDialogOpen
&& !getSpeech()->getTextData()
&& !getSpeech()->getTextDataPos())
_shouldCloseDialog = true;
return true;
}
//////////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////////

View File

@ -212,8 +212,8 @@ private:
// Message handling
bool init();
bool update();
bool key(const AsylumEvent &evt) { return true; }
bool mouse(const AsylumEvent &evt);
bool cancel(const AsylumEvent &evt);
//////////////////////////////////////////////////////////////////////////
// Variables