From 2254028365cf5f162bd41cf0011b4475ec608f4c Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 19 Sep 2007 09:54:42 +0000 Subject: Merge several choice-related functions svn-id: r28967 --- engines/agi/preagi.h | 2 -- engines/agi/preagi_common.cpp | 72 ++++++------------------------------------- engines/agi/preagi_common.h | 4 ++- engines/agi/preagi_mickey.cpp | 18 +++++------ engines/agi/preagi_troll.cpp | 4 +-- engines/agi/preagi_winnie.cpp | 48 ++++++++++++++--------------- 6 files changed, 47 insertions(+), 101 deletions(-) diff --git a/engines/agi/preagi.h b/engines/agi/preagi.h index 7476dde3cf..c5812130b6 100644 --- a/engines/agi/preagi.h +++ b/engines/agi/preagi.h @@ -74,8 +74,6 @@ public: // Keyboard int getSelection(SelectionTypes type); - bool waitAnyKeyChoice(); - bool getSelOkBack(); int rnd(int hi) { return (_rnd->getRandomNumber(hi) + 1); } diff --git a/engines/agi/preagi_common.cpp b/engines/agi/preagi_common.cpp index b0dba6fb0c..190625bbdf 100644 --- a/engines/agi/preagi_common.cpp +++ b/engines/agi/preagi_common.cpp @@ -122,19 +122,16 @@ void PreAgiEngine::printStrXOR(char *szMsg) { int PreAgiEngine::getSelection(SelectionTypes type) { Common::Event event; - // Selection types: - // 0: Y/N - // 1: 1-9 for (;;) { while (_eventMan->pollEvent(event)) { switch(event.type) { case Common::EVENT_QUIT: _system->quit(); - case Common::EVENT_LBUTTONUP: - if (type == kSelYesNo) - return 1; case Common::EVENT_RBUTTONUP: return 0; + case Common::EVENT_LBUTTONUP: + if (type == kSelYesNo || type == kSelAnyKey) + return 1; case Common::EVENT_KEYDOWN: switch (event.kbd.keycode) { case Common::KEYCODE_y: @@ -144,7 +141,7 @@ int PreAgiEngine::getSelection(SelectionTypes type) { if (type == kSelYesNo) return 0; case Common::KEYCODE_ESCAPE: - if (type == kSelNumber) + if (type == kSelNumber || type == kSelAnyKey) return 0; case Common::KEYCODE_1: case Common::KEYCODE_2: @@ -160,11 +157,16 @@ int PreAgiEngine::getSelection(SelectionTypes type) { case Common::KEYCODE_SPACE: if (type == kSelSpace) return 1; + case Common::KEYCODE_BACKSPACE: + if (type == kSelBackspace) + return 0; default: if (type == kSelYesNo) { return 2; } else if (type == kSelNumber) { return 10; + } else if (type == kSelAnyKey || type == kSelBackspace) { + return 1; } } break; @@ -178,60 +180,4 @@ int PreAgiEngine::getSelection(SelectionTypes type) { return 0; } -bool PreAgiEngine::waitAnyKeyChoice() { - Common::Event event; - - for (;;) { - while (_eventMan->pollEvent(event)) { - switch(event.type) { - case Common::EVENT_QUIT: - _system->quit(); - case Common::EVENT_LBUTTONUP: - return true; - case Common::EVENT_RBUTTONUP: - return false; - case Common::EVENT_KEYDOWN: - switch (event.kbd.keycode) { - case Common::KEYCODE_ESCAPE: //Escape - return false; - default: - return true; - } - break; - default: - break; - } - } - _system->updateScreen(); - _system->delayMillis(10); - } -} - -bool PreAgiEngine::getSelOkBack() { - Common::Event event; - - for (;;) { - while (_eventMan->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_QUIT: - _system->quit(); - break; - case Common::EVENT_LBUTTONUP: - return true; - case Common::EVENT_RBUTTONUP: - return false; - case Common::EVENT_KEYDOWN: - switch (event.kbd.keycode) { - case Common::KEYCODE_BACKSPACE: - return false; - default: - return true; - } - default: - break; - } - } - } -} - } diff --git a/engines/agi/preagi_common.h b/engines/agi/preagi_common.h index 434bb685a6..1c8705d37b 100644 --- a/engines/agi/preagi_common.h +++ b/engines/agi/preagi_common.h @@ -41,7 +41,9 @@ namespace Agi { enum SelectionTypes { kSelYesNo, kSelNumber, - kSelSpace + kSelSpace, + kSelAnyKey, + kSelBackspace }; } // End of namespace Agi diff --git a/engines/agi/preagi_mickey.cpp b/engines/agi/preagi_mickey.cpp index 598938edd4..e911161f61 100644 --- a/engines/agi/preagi_mickey.cpp +++ b/engines/agi/preagi_mickey.cpp @@ -184,7 +184,7 @@ int Mickey::choose1to9(int ofsPrompt) { for (;;) { if (a == 10) { printExeStr(IDO_MSA_PRESS_1_TO_9); - if (!_vm->waitAnyKeyChoice()) + if (_vm->getSelection(kSelAnyKey) == 0) return 0; printExeStr(ofsPrompt); } else return a; @@ -956,7 +956,7 @@ bool Mickey::loadGame() { sprintf(szFile, "%s.s%2d", _vm->getTargetName().c_str(), sel); if (!(infile = _vm->getSaveFileMan()->openForLoading(szFile))) { printExeStr(IDO_MSA_CHECK_DISK_DRIVE); - if (!_vm->waitAnyKeyChoice()) + if (_vm->getSelection(kSelAnyKey) == 0) return false; } else { infile->read(&game, sizeof(MSA_GAME)); @@ -982,7 +982,7 @@ void Mickey::saveGame() { else printExeStr(IDO_MSA_SAVE_GAME[2]); - if (!_vm->waitAnyKeyChoice()) + if (_vm->getSelection(kSelAnyKey) == 0) return; while (diskerror) { @@ -995,14 +995,14 @@ void Mickey::saveGame() { else printExeStr(IDO_MSA_SAVE_GAME[4]); - if (!_vm->waitAnyKeyChoice()) + if (_vm->getSelection(kSelAnyKey) == 0) return; // save game sprintf(szFile, "%s.s%2d", _vm->getTargetName().c_str(), sel); if (!(outfile = _vm->getSaveFileMan()->openForSaving(szFile))) { printExeStr(IDO_MSA_CHECK_DISK_DRIVE); - if (!_vm->waitAnyKeyChoice()) + if (_vm->getSelection(kSelAnyKey) == 0) return; } else { outfile->write(&game, sizeof(MSA_GAME)); @@ -2082,10 +2082,8 @@ void Mickey::waitAnyKeyAnim() { void Mickey::waitAnyKey(bool anim) { Common::Event event; - if (!anim) { + if (!anim) _vm->_gfx->doUpdate(); - _vm->_system->updateScreen(); // TODO: this should go in the game's main loop - } for (;;) { while (_vm->_system->getEventManager()->pollEvent(event)) { @@ -2103,8 +2101,10 @@ void Mickey::waitAnyKey(bool anim) { if (anim) { animate(); _vm->_gfx->doUpdate(); - _vm->_system->updateScreen(); // TODO: this should go in the game's main loop } + + _vm->_system->updateScreen(); + _vm->_system->delayMillis(10); } } diff --git a/engines/agi/preagi_troll.cpp b/engines/agi/preagi_troll.cpp index d34286535b..817abbae46 100644 --- a/engines/agi/preagi_troll.cpp +++ b/engines/agi/preagi_troll.cpp @@ -42,7 +42,7 @@ Troll::Troll(PreAgiEngine* vm) : _vm(vm) { void Troll::pressAnyKey() { _vm->drawStr(24, 4, kColorDefault, IDS_TRO_PRESSANYKEY); _vm->_gfx->doUpdate(); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } void Troll::drawMenu(const char *szMenu, int iSel) { @@ -163,7 +163,7 @@ void Troll::inventory() { _vm->drawStr(24, 6, kColorDefault, IDS_TRO_PRESSANYKEY); _vm->_gfx->doUpdate(); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } void Troll::waitAnyKeyIntro() { diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp index 02682c92f4..85d1983e9e 100644 --- a/engines/agi/preagi_winnie.cpp +++ b/engines/agi/preagi_winnie.cpp @@ -218,7 +218,7 @@ int Winnie::parser(int pc, int index, uint8 *buffer) { default: // print description _vm->printStrXOR((char *)(buffer + pc)); - if (_vm->getSelOkBack()) + if (_vm->getSelection(kSelBackspace) == 1) return IDI_WTP_PAR_OK; else return IDI_WTP_PAR_BACK; @@ -277,7 +277,7 @@ int Winnie::parser(int pc, int index, uint8 *buffer) { iDir = iSel - IDI_WTP_SEL_NORTH; if (hdr.roomNew[iDir] == IDI_WTP_ROOM_NONE) { _vm->printStr(IDS_WTP_CANT_GO); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } else { room = hdr.roomNew[iDir]; return IDI_WTP_PAR_GOTO; @@ -310,7 +310,7 @@ int Winnie::parser(int pc, int index, uint8 *buffer) { case IDO_WTP_PRINT_MSG: opcode = *(buffer + pc++); printRoomStr(room, opcode); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); break; case IDO_WTP_PRINT_STR: opcode = *(buffer + pc++); @@ -377,9 +377,9 @@ int Winnie::parser(int pc, int index, uint8 *buffer) { void Winnie::keyHelp() { //Winnie_PlaySound(IDI_WTP_SND_KEYHELP); _vm->printStr(IDS_WTP_HELP_0); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); _vm->printStr(IDS_WTP_HELP_1); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } void Winnie::inventory() { @@ -396,7 +396,7 @@ void Winnie::inventory() { _vm->drawStr(IDI_WTP_ROW_OPTION_4, IDI_WTP_COL_MENU, IDA_DEFAULT, szMissing); _vm->_gfx->doUpdate(); _vm->_system->updateScreen(); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } void Winnie::printObjStr(int iObj, int iStr) { @@ -438,7 +438,7 @@ void Winnie::takeObj(int iRoom) { if (game.iObjHave) { // player is already carrying an object, can't take _vm->printStr(IDS_WTP_CANT_TAKE); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } else { // take object int iObj = getObjInRoom(iRoom); @@ -452,7 +452,7 @@ void Winnie::takeObj(int iRoom) { // print object "take" string printObjStr(game.iObjHave, IDI_WTP_OBJ_TAKE); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); // HACK WARNING if (iObj == 18) { @@ -467,7 +467,7 @@ void Winnie::dropObj(int iRoom) { if (getObjInRoom(iRoom)) { // there already is an object in the room, can't drop _vm->printStr(IDS_WTP_CANT_DROP); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } else { // HACK WARNING if (game.iObjHave == 18) { @@ -477,10 +477,10 @@ void Winnie::dropObj(int iRoom) { if (isRightObj(iRoom, game.iObjHave, &iCode)) { // object has been dropped in the right place _vm->printStr(IDS_WTP_OK); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); //Winnie_PlaySound(IDI_WTP_SND_DROP_OK); printObjStr(game.iObjHave, IDI_WTP_OBJ_DROP); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); // increase amount of objects returned, decrease amount of objects missing game.nObjMiss--; @@ -504,9 +504,9 @@ void Winnie::dropObj(int iRoom) { // all objects returned, tell player to find party //Winnie_PlaySound(IDI_WTP_SND_FANFARE); _vm->printStr(IDS_WTP_GAME_OVER_0); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); _vm->printStr(IDS_WTP_GAME_OVER_1); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } } else { // drop object in the given room @@ -514,15 +514,15 @@ void Winnie::dropObj(int iRoom) { // object has been dropped in the wrong place _vm->printStr(IDS_WTP_WRONG_PLACE); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); //Winnie_PlaySound(IDI_WTP_SND_DROP); drawRoomPic(); _vm->printStr(IDS_WTP_WRONG_PLACE); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); // print object description printObjStr(game.iObjHave, IDI_WTP_OBJ_DESC); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); game.iObjHave = 0; } @@ -563,10 +563,10 @@ void Winnie::wind() { _vm->printStr(IDS_WTP_WIND_0); //Winnie_PlaySound(IDI_WTP_SND_WIND_0); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); _vm->printStr(IDS_WTP_WIND_1); //Winnie_PlaySound(IDI_WTP_SND_WIND_0); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); dropObjRnd(); @@ -591,15 +591,15 @@ void Winnie::wind() { void Winnie::showOwlHelp() { if (game.iObjHave) { _vm->printStr(IDS_WTP_OWL_0); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); printObjStr(game.iObjHave, IDI_WTP_OBJ_HELP); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } if (getObjInRoom(room)) { _vm->printStr(IDS_WTP_OWL_0); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); printObjStr(getObjInRoom(room), IDI_WTP_OBJ_HELP); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } } @@ -927,7 +927,7 @@ phase0: phase1: if (getObjInRoom(room)) { printObjStr(getObjInRoom(room), IDI_WTP_OBJ_DESC); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } phase2: for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { @@ -1045,7 +1045,7 @@ void Winnie::gameOver() { //Winnie_PlaySound(IDI_WTP_SND_POOH_1); _vm->printStr(IDS_WTP_SONG_2); //Winnie_PlaySound(IDI_WTP_SND_POOH_2); - _vm->waitAnyKeyChoice(); + _vm->getSelection(kSelAnyKey); } } -- cgit v1.2.3