Make it possible to quit cutaways!

svn-id: r10952
This commit is contained in:
David Eriksson 2003-10-23 18:50:47 +00:00
parent 00e2ee13ff
commit 7772adbe1e
7 changed files with 147 additions and 78 deletions

View File

@ -20,13 +20,13 @@
*/
#include "stdafx.h"
#include "cutaway.h"
#include "display.h"
#include "graphics.h"
#include "input.h"
#include "sound.h"
#include "talk.h"
#include "walk.h"
#include "queen/cutaway.h"
#include "queen/display.h"
#include "queen/graphics.h"
#include "queen/input.h"
#include "queen/sound.h"
#include "queen/talk.h"
#include "queen/walk.h"
namespace Queen {
@ -82,8 +82,9 @@ Cutaway::Cutaway(
Resource *resource,
Sound *sound)
: _graphics(graphics), _input(input), _logic(logic), _resource(resource), _sound(sound), _walk(logic->walk()),
_quit(false), _personDataCount(0), _personFaceCount(0), _lastSong(0), _songBeforeComic(0) {
_personDataCount(0), _personFaceCount(0), _lastSong(0), _songBeforeComic(0) {
memset(&_bankNames, 0, sizeof(_bankNames));
_input->cutawayQuitReset();
load(filename);
}
@ -116,10 +117,10 @@ void Cutaway::load(const char *filename) {
if (_cutawayObjectCount < 0) {
_cutawayObjectCount = -_cutawayObjectCount;
_canQuit = false;
_input->canQuit(false);
}
else
_canQuit = true;
_input->canQuit(true);
int flags1 = READ_BE_UINT16(ptr);
ptr += 2;
@ -376,9 +377,8 @@ void Cutaway::actionSpecialMove(int index) {
_logic->update();
if (_quit)
if (_input->cutawayQuit())
return;
}
_input->fastMode(false);
@ -431,7 +431,7 @@ void Cutaway::actionSpecialMove(int index) {
_logic->update();
if (_quit)
if (_input->cutawayQuit())
return;
}
@ -470,7 +470,7 @@ void Cutaway::actionSpecialMove(int index) {
_logic->update();
if (_quit)
if (_input->cutawayQuit())
return;
}
@ -820,7 +820,7 @@ byte *Cutaway::handleAnimation(byte *ptr, CutawayObject &object) {
frameCount++;
if (_quit)
if (_input->cutawayQuit())
return NULL;
}
@ -933,7 +933,7 @@ byte *Cutaway::handleAnimation(byte *ptr, CutawayObject &object) {
_logic->update();
}
if (_quit)
if (_input->cutawayQuit())
return NULL;
if (objAnim[i].song > 0)
@ -963,8 +963,8 @@ byte *Cutaway::handleAnimation(byte *ptr, CutawayObject &object) {
}
}
if (_quit)
break;
if (_input->cutawayQuit())
return NULL;
}
return ptr;
@ -1016,7 +1016,7 @@ void Cutaway::handlePersonRecord(
);
}
if (_quit)
if (_input->cutawayQuit())
return;
if (0 != strcmp(sentence, "*")) {
@ -1050,7 +1050,7 @@ void Cutaway::handlePersonRecord(
}
if (_quit)
if (_input->cutawayQuit())
return;
}
@ -1059,6 +1059,8 @@ void Cutaway::run(char *nextFilename) {
byte *ptr = _objectData;
_input->cutawayRunning(true);
_initialRoom = _temporaryRoom = _logic->currentRoom();
// XXX if(COMPANEL==0 || COMPANEL==2) SCENE_START(0);
@ -1135,7 +1137,7 @@ void Cutaway::run(char *nextFilename) {
break;
}
if (_quit)
if (_input->cutawayQuit())
break;
// XXX
@ -1155,7 +1157,7 @@ void Cutaway::run(char *nextFilename) {
goToFinalRoom();
_quit = false;
_input->cutawayQuitReset();
updateGameState();
@ -1179,8 +1181,8 @@ void Cutaway::run(char *nextFilename) {
// Make sure Joe is clipped!
joeBob->box.y2 = 149;
// XXX CUTON=0;
_quit = false;
_input->cutawayRunning(false);
_input->cutawayQuitReset();
if (_songBeforeComic > 0)
/* XXX playsong(_songBeforeComic) */ ;
@ -1262,7 +1264,7 @@ void Cutaway::goToFinalRoom() {
uint16 joeX = READ_BE_UINT16(ptr); ptr += 2;
uint16 joeY = READ_BE_UINT16(ptr); ptr += 2;
if ((!_quit || (!_anotherCutaway && joeRoom == _finalRoom)) &&
if ((!_input->cutawayQuit() || (!_anotherCutaway && joeRoom == _finalRoom)) &&
joeRoom != _temporaryRoom &&
joeRoom != 0) {
@ -1273,7 +1275,7 @@ void Cutaway::goToFinalRoom() {
_logic->roomDisplay(_logic->roomName(_logic->currentRoom()), RDM_FADE_JOE_XY, 0, _comPanel, true);
}
if (_quit) {
if (_input->cutawayQuit()) {
// Lines 1927-2032 in cutaway.c
// Stop the credits from running
@ -1495,14 +1497,13 @@ void Cutaway::handleText(
// XXX: see if speaking is finished
}
if (_quit)
if (_input->cutawayQuit())
return;
if (_input->verbSkipText()) {
_input->clearKeyVerb();
break;
// XXX if(KEYVERB==101) {
// XXX KEYVERB=0;
// XXX break;
// XXX }
}
}
_graphics->textClear(0,198);

View File

@ -167,12 +167,6 @@ class Cutaway {
//! This cutaway is followed by another
bool _anotherCutaway;
//! Specify if the player can quit this cutaway or not
bool _canQuit;
//! Set to true to abort the cutaway
bool _quit;
//! Room before cutaway
int _initialRoom;

View File

@ -127,10 +127,10 @@ enum Verb {
VERB_SCROLL_DOWN = 12,
VERB_DIGIT_FIRST = 13,
VERB_KEY_1 = 13,
VERB_KEY_2 = 14,
VERB_KEY_3 = 15,
VERB_KEY_4 = 16,
VERB_DIGIT_1 = 13,
VERB_DIGIT_2 = 14,
VERB_DIGIT_3 = 15,
VERB_DIGIT_4 = 16,
VERB_DIGIT_LAST = 16,
VERB_USE_JOURNAL = 20,

View File

@ -29,7 +29,8 @@ namespace Queen {
Input::Input(OSystem *system) :
_system(system), _fastMode(false), _keyVerb(VERB_NONE),
_cutawayRunning(false), _cutQuit(false), _talkQuit(false) {
_cutawayRunning(false), _cutawayQuit(false), _talkQuit(false),
_inKey(0) {
}
void Input::delay() {
@ -42,34 +43,16 @@ void Input::delay(uint amount) {
uint32 start = _system->get_msecs();
uint32 cur = start;
_key_pressed = 0; //reset
do {
while (_system->poll_event(&event)) {
switch (event.event_code) {
case OSystem::EVENT_KEYDOWN:
#if 0
if (event.kbd.flags == OSystem::KBD_CTRL) {
if (event.kbd.keycode == 'f') {
_fastMode ^= 1;
break;
}
if (event.kbd.keycode == 'g') {
_fastMode ^= 2;
break;
}
}
#endif
debug(1, "event.kbd.keycode = %i (%c)",
event.kbd.keycode,
isprint(event.kbd.keycode) ? event.kbd.keycode : '.');
// Make sure backspace works right (this fixes a small issue on OS X)
if (event.kbd.keycode == 8)
_key_pressed = 8;
else
_key_pressed = (byte)event.kbd.ascii;
_inKey = event.kbd.keycode;
break;
case OSystem::EVENT_MOUSEMOVE:
@ -111,6 +94,70 @@ void Input::delay(uint amount) {
}
void Input::checkKeys() {
if (_inKey)
debug(0, "[Input::checkKeys] _inKey = %i", _inKey);
switch (_inKey) {
case KEY_SPACE:
_keyVerb = VERB_SKIP_TEXT;
break;
case KEY_COMMA:
_keyVerb = VERB_SCROLL_UP;
break;
case KEY_DOT:
_keyVerb = VERB_SCROLL_DOWN;
break;
case KEY_DIGIT_1:
_keyVerb = VERB_DIGIT_1;
break;
case KEY_DIGIT_2:
_keyVerb = VERB_DIGIT_2;
break;
case KEY_DIGIT_3:
_keyVerb = VERB_DIGIT_3;
break;
case KEY_DIGIT_4:
_keyVerb = VERB_DIGIT_4;
break;
case KEY_ESCAPE:
if (_canQuit) {
if (_cutawayRunning) {
debug(0, "[Input::checkKeys] Setting _cutawayQuit to true!");
_cutawayQuit = true;
}
// XXX if (_joeWalk == 3) // Dialogue
// XXX _talkQuit = true;
}
break;
case KEY_F1: // Use Journal
if (_cutawayRunning) {
if (_canQuit) {
_keyVerb = VERB_USE_JOURNAL;
_cutawayQuit = _talkQuit = true;
}
}
else {
_keyVerb = VERB_USE_JOURNAL;
if (_canQuit)
_talkQuit = true;
}
break;
default:
break;
}
_inKey = 0; //reset
}

View File

@ -76,8 +76,14 @@ class Input {
//! Returns 1-4 if keyDigit() is true, otherwise -1
int verbDigit();
bool cutQuit() { return _cutQuit; }
void cutQuitReset() { _cutQuit = false; }
bool verbSkipText() { return _keyVerb == VERB_SKIP_TEXT; }
void canQuit(bool cq) { _canQuit = cq; }
void cutawayRunning(bool running) { _cutawayRunning = running; }
bool cutawayQuit() { return _cutawayQuit; }
void cutawayQuitReset() { _cutawayQuit = false; }
bool talkQuit() { return _talkQuit; }
void talkQuitReset() { _talkQuit = false; }
@ -85,6 +91,21 @@ class Input {
void fastMode(bool fm) { _fastMode = fm; }
private:
enum KeyCode {
KEY_SPACE = ' ',
KEY_COMMA = ',',
KEY_DOT = '.',
KEY_DIGIT_1 = '1',
KEY_DIGIT_2 = '2',
KEY_DIGIT_3 = '3',
KEY_DIGIT_4 = '4',
KEY_ESCAPE = 27,
KEY_F1 = 282
};
//! Used to get keyboard and mouse events
OSystem *_system;
@ -98,14 +119,17 @@ class Input {
//! set if a cutaway is running
bool _cutawayRunning; // CUTON
//! set this if we can quit
bool _canQuit; // inverse of CANTQUIT
//! moved Cutaway::_quit here
bool _cutQuit; // CUTQUIT
bool _cutawayQuit; // cutawayQuit
//! moved Talk::_quit here
bool _talkQuit; // TALKQUIT
//! Set by delay();
int _key_pressed;
int _inKey;
//! Set by delay();
int _sdl_mouse_x, _sdl_mouse_y;

View File

@ -69,10 +69,12 @@ Talk::Talk(
Resource *resource,
Sound *sound) :
_graphics(graphics), _input(input), _logic(logic), _resource(resource),
_sound(sound), _fileData(NULL), _quit(false) {
_sound(sound), _fileData(NULL) {
//! TODO Move this to the Logic class later!
memset(_talkSelected, 0, sizeof(_talkSelected));
_input->talkQuitReset();
}
Talk::~Talk() {
@ -207,7 +209,7 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) {
if (speak(_talkString[0], &person, otherVoiceFilePrefix))
personWalking = true;
if (_quit)
if (_input->talkQuit())
break;
speak(_talkString[selectedSentence], &person, _joeVoiceFilePrefix[selectedSentence]);
@ -223,7 +225,7 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) {
}
}
if (_quit)
if (_input->talkQuit())
break;
retval = _dialogueTree[level][selectedSentence].dialogueNodeValue1;
@ -594,6 +596,9 @@ bool Talk::speak(const char *sentence, Person *person, const char *voiceFilePref
}
else
i++;
if (_input->cutawayQuit() || _input->talkQuit())
goto exit;
}
if (segmentStart != i) {
@ -651,7 +656,7 @@ void Talk::speakSegment(
switch (command) {
case SPEAK_PAUSE:
for (i = 0; i < 10; i++) {
if (_quit)
if (_input->talkQuit())
break;
_logic->update();
}
@ -870,13 +875,13 @@ void Talk::speakSegment(
_logic->update();
if (_logic->joeWalk() == 3) {
if (_quit)
if (_input->talkQuit())
break;
_logic->update();
}
else {
if (_quit)
if (_input->talkQuit())
break;
// XXX CHECK_PLAYER();
@ -1114,14 +1119,15 @@ int16 Talk::selectSentence() {
bob2->active = (yOffset > 4);
}
// XXX KEYVERB=0;
_input->clearKeyVerb();
if (sentenceCount > 0) {
int zone = 0;
int oldZone = 0;
while (0 == selectedSentence) {
if (_quit)
if (_input->talkQuit())
break;
_logic->update();

View File

@ -139,9 +139,6 @@ class Talk {
//! Data used if we haven't talked to the person before
byte *_joePtr;
//! Set to true to quit talking
bool _quit;
//! Is a talking head
bool _talkHead;