diff options
author | Max Horn | 2007-06-23 10:38:03 +0000 |
---|---|---|
committer | Max Horn | 2007-06-23 10:38:03 +0000 |
commit | 4e4358e8c33bfcf8213c5b9938551835d583f747 (patch) | |
tree | b6e4f2998b02519adca41d1be98f545a037a7641 /engines/scumm/input.cpp | |
parent | 2bbe67afdf4d4df36fc100690cf87c8a75d5a354 (diff) | |
download | scummvm-rg350-4e4358e8c33bfcf8213c5b9938551835d583f747.tar.gz scummvm-rg350-4e4358e8c33bfcf8213c5b9938551835d583f747.tar.bz2 scummvm-rg350-4e4358e8c33bfcf8213c5b9938551835d583f747.zip |
Made SCUMM use Common::KeyState, too (but implemented almost no fixes/optimizations based on this)
svn-id: r27655
Diffstat (limited to 'engines/scumm/input.cpp')
-rw-r--r-- | engines/scumm/input.cpp | 185 |
1 files changed, 102 insertions, 83 deletions
diff --git a/engines/scumm/input.cpp b/engines/scumm/input.cpp index 4d390517a1..dce0340018 100644 --- a/engines/scumm/input.cpp +++ b/engines/scumm/input.cpp @@ -85,17 +85,21 @@ void ScummEngine::parseEvents() { else if (event.kbd.keycode == 's') _res->resourceStats(); else - _keyPressed = event.kbd.ascii; // Normal key press, pass on to the game. + _keyPressed = event.kbd; // Normal key press, pass on to the game. } else if (event.kbd.flags & Common::KBD_ALT) { // The result must be 273 for Alt-W // because that's what MI2 looks for in // its "instant win" cheat. - _keyPressed = event.kbd.keycode + 154; - } else if (event.kbd.ascii == Common::ASCII_F1 && (_game.id == GID_CMI && !(_game.features & GF_DEMO))) { + // FIXME: Handle this specific property inside processKeyboard ? + _keyPressed = event.kbd; + _keyPressed.ascii = event.kbd.keycode + 154; + } else if (event.kbd.ascii == Common::KEYCODE_F1 && (_game.id == GID_CMI && !(_game.features & GF_DEMO))) { // FIXME: support in-game menu screen. For now, this remaps F1 to F5 in COMI - _keyPressed = Common::ASCII_F5; - } else if (event.kbd.ascii < Common::KEYCODE_UP || event.kbd.ascii > Common::KEYCODE_LEFT || _game.version >= 7) { -// FIXME: Don't use ASCII value to detect arrow keys, rather, use keycode! + // FIXME: Handle this specific property inside processKeyboard ? + _keyPressed = Common::KeyState(Common::KEYCODE_F5, Common::ASCII_F5); + } else if (event.kbd.keycode < Common::KEYCODE_UP || event.kbd.keycode > Common::KEYCODE_LEFT || _game.version >= 7) { + // FIXME: Handle this specific property inside processKeyboard ? + // don't let game have arrow keys as we currently steal them // for keyboard cursor control // this fixes bug with up arrow (273) corresponding to @@ -103,12 +107,13 @@ void ScummEngine::parseEvents() { // // This is not applicable to Full Throttle as it processes keyboard // cursor control by itself. Also it fixes derby scene - _keyPressed = event.kbd.ascii; // Normal key press, pass on to the game. + _keyPressed = event.kbd; // Normal key press, pass on to the game. } if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD) { - if (event.kbd.ascii >= Common::KEYCODE_UP && event.kbd.ascii <= Common::KEYCODE_LEFT) { - _keyPressed = event.kbd.ascii - Common::KEYCODE_UP + 54; + if (event.kbd.keycode >= Common::KEYCODE_UP && event.kbd.keycode <= Common::KEYCODE_LEFT) { + _keyPressed = event.kbd; + _keyPressed.ascii = event.kbd.ascii - Common::KEYCODE_UP + 54; } } @@ -116,16 +121,16 @@ void ScummEngine::parseEvents() { // Keyboard is controlled via variable int _keyState = 0; - if (event.kbd.ascii == Common::KEYCODE_LEFT) // Left + if (event.kbd.keycode == Common::KEYCODE_LEFT) // Left _keyState = 1; - if (event.kbd.ascii == Common::KEYCODE_RIGHT) // Right + if (event.kbd.keycode == Common::KEYCODE_RIGHT) // Right _keyState |= 2; - if (event.kbd.ascii == Common::KEYCODE_UP) // Up + if (event.kbd.keycode == Common::KEYCODE_UP) // Up _keyState |= 4; - if (event.kbd.ascii == Common::KEYCODE_DOWN) // Down + if (event.kbd.keycode == Common::KEYCODE_DOWN) // Down _keyState |= 8; if (event.kbd.flags == Common::KBD_SHIFT) @@ -137,10 +142,10 @@ void ScummEngine::parseEvents() { VAR(VAR_KEY_STATE) = _keyState; } - if (_keyPressed >= 512) - debugC(DEBUG_GENERAL, "_keyPressed > 512 (%d)", _keyPressed); + if (_keyPressed.ascii >= 512) + debugC(DEBUG_GENERAL, "_keyPressed > 512 (%d)", _keyPressed.ascii); else - _keyDownMap[_keyPressed] = true; + _keyDownMap[_keyPressed.ascii] = true; break; case Common::EVENT_KEYUP: @@ -195,11 +200,11 @@ void ScummEngine::parseEvents() { // checking the gameid. Values are taken from script-14. case Common::EVENT_WHEELDOWN: - _keyPressed = 55; + _keyPressed = Common::KeyState(Common::KEYCODE_7, 55); // '7' break; case Common::EVENT_WHEELUP: - _keyPressed = 54; + _keyPressed = Common::KeyState(Common::KEYCODE_6, 54); // '6' break; case Common::EVENT_QUIT: @@ -219,20 +224,20 @@ void ScummEngine::parseEvents() { void ScummEngine_v90he::clearClickedStatus() { ScummEngine::clearClickedStatus(); if (_game.heversion >= 98) { - _logicHE->processKeyStroke(_keyPressed); + _logicHE->processKeyStroke(_keyPressed.ascii); } } void ScummEngine_v90he::processInput() { if (_game.heversion >= 98) { - _logicHE->processKeyStroke(_keyPressed); + _logicHE->processKeyStroke(_keyPressed.ascii); } ScummEngine::processInput(); } #endif void ScummEngine::clearClickedStatus() { - _keyPressed = 0; + _keyPressed.reset(); _mouseAndKeyboardStat = 0; _leftBtnPressed &= ~msClicked; @@ -241,15 +246,16 @@ void ScummEngine::clearClickedStatus() { void ScummEngine_v0::processInput() { // F1 - F3 - if (_keyPressed >= Common::ASCII_F1 && _keyPressed <= Common::ASCII_F3) { - switchActor(_keyPressed - Common::ASCII_F1); + if (_keyPressed.ascii >= Common::ASCII_F1 && _keyPressed.ascii <= Common::ASCII_F3) { + switchActor(_keyPressed.ascii - Common::ASCII_F1); } ScummEngine::processInput(); } + void ScummEngine::processInput() { - int lastKeyHit = _keyPressed; - _keyPressed = 0; + Common::KeyState lastKeyHit = _keyPressed; + _keyPressed.reset(); // // Clip the mouse coordinates, and compute _virtualMouse.x (and clip it, too) @@ -279,30 +285,36 @@ void ScummEngine::processInput() { _mouseAndKeyboardStat = 0; // Interpret 'return' as left click and 'tab' as right click - if (lastKeyHit && _cursor.state > 0) { - if (lastKeyHit == 9) { + if (lastKeyHit.keycode && _cursor.state > 0) { + if (lastKeyHit.keycode == Common::KEYCODE_TAB) { _mouseAndKeyboardStat = MBS_RIGHT_CLICK; - lastKeyHit = 0; - } else if (lastKeyHit == 13) { + lastKeyHit.reset(); + } else if (lastKeyHit.keycode == Common::KEYCODE_RETURN) { _mouseAndKeyboardStat = MBS_LEFT_CLICK; - lastKeyHit = 0; + lastKeyHit.reset(); } } - if (_leftBtnPressed & msClicked && _rightBtnPressed & msClicked && _game.version >= 4) { + if ((_leftBtnPressed & msClicked) && (_rightBtnPressed & msClicked) && _game.version >= 4) { // Pressing both mouse buttons is treated as if you pressed // the cutscene exit key (i.e. ESC in most games). That mimicks // the behaviour of the original engine where pressing both // mouse buttons also skips the current cutscene. _mouseAndKeyboardStat = 0; - lastKeyHit = (uint)VAR(VAR_CUTSCENEEXIT_KEY); - } else if (_rightBtnPressed & msClicked && (_game.version <= 3 && _game.id != GID_LOOM)) { + lastKeyHit.ascii = (uint)VAR(VAR_CUTSCENEEXIT_KEY); + lastKeyHit.keycode = (Common::KeyCode)lastKeyHit.ascii; + lastKeyHit.flags = 0; + //FIXME: lastKeyHit.keycode = ???; proper value??? + } else if ((_rightBtnPressed & msClicked) && (_game.version <= 3 && _game.id != GID_LOOM)) { // Pressing right mouse button is treated as if you pressed // the cutscene exit key (i.e. ESC in most games). That mimicks // the behaviour of the original engine where pressing right // mouse button also skips the current cutscene. _mouseAndKeyboardStat = 0; - lastKeyHit = (VAR_CUTSCENEEXIT_KEY != 0xFF) ? (uint)VAR(VAR_CUTSCENEEXIT_KEY) : 27; + lastKeyHit.ascii = (VAR_CUTSCENEEXIT_KEY != 0xFF) ? (uint)VAR(VAR_CUTSCENEEXIT_KEY) : 27; + lastKeyHit.keycode = (Common::KeyCode)lastKeyHit.ascii; + lastKeyHit.flags = 0; + //FIXME: lastKeyHit.keycode = ???; proper value??? } else if (_leftBtnPressed & msClicked) { _mouseAndKeyboardStat = MBS_LEFT_CLICK; } else if (_rightBtnPressed & msClicked) { @@ -323,33 +335,36 @@ void ScummEngine::processInput() { _rightBtnPressed &= ~msClicked; #ifdef _WIN32_WCE - if (lastKeyHit == KEY_ALL_SKIP) { + if (lastKeyHit.ascii == KEY_ALL_SKIP) { // Skip talk - if (VAR_TALKSTOP_KEY != 0xFF && _talkDelay > 0) - lastKeyHit = (uint)VAR(VAR_TALKSTOP_KEY); - else - // Escape - lastKeyHit = 27; + if (VAR_TALKSTOP_KEY != 0xFF && _talkDelay > 0) { + lastKeyHit.ascii = (uint)VAR(VAR_TALKSTOP_KEY); + lastKeyHit.keycode = (Common::KeyCode)lastKeyHit.ascii; + lastKeyHit.flags = 0; + //FIXME: lastKeyHit.keycode = ???; proper value??? + } else { + lastKeyHit = Common::KeySate(Common::KEYCODE_ESCAPE); + } } #endif - if (!lastKeyHit) + if (!lastKeyHit.ascii) return; processKeyboard(lastKeyHit); } #ifndef DISABLE_SCUMM_7_8 -void ScummEngine_v8::processKeyboard(int lastKeyHit) { +void ScummEngine_v8::processKeyboard(Common::KeyState lastKeyHit) { // Alt-F5 brings up the original save/load dialog - if (lastKeyHit == 440 && !(_game.features & GF_DEMO)) { - lastKeyHit = Common::ASCII_F1; + if (lastKeyHit.ascii == 440 && !(_game.features & GF_DEMO)) { + lastKeyHit = Common::KeyState(Common::KEYCODE_F1, Common::ASCII_F1); } // If a key script was specified (a V8 feature), and it's trigger // key was pressed, run it. - if (_keyScriptNo && (_keyScriptKey == lastKeyHit)) { + if (_keyScriptNo && (_keyScriptKey == lastKeyHit.ascii)) { runScript(_keyScriptNo, 0, 0, 0); return; } @@ -358,18 +373,18 @@ void ScummEngine_v8::processKeyboard(int lastKeyHit) { ScummEngine_v7::processKeyboard(lastKeyHit); } -void ScummEngine_v7::processKeyboard(int lastKeyHit) { +void ScummEngine_v7::processKeyboard(Common::KeyState lastKeyHit) { // COMI version string is hard coded in the engine, hence we don't // invoke versionDialog here (it would only show nonsense). // Dig/FT version strings are partly hard coded, too. - if (_game.version == 7 && lastKeyHit == VAR(VAR_VERSION_KEY)) { + if (_game.version == 7 && lastKeyHit.ascii == VAR(VAR_VERSION_KEY)) { versionDialog(); return; } #ifndef _WIN32_WCE - if (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit == VAR(VAR_CUTSCENEEXIT_KEY)) { + if (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_CUTSCENEEXIT_KEY)) { // Skip cutscene (or active SMUSH video). if (_smushActive) { if (_game.id == GID_FT) @@ -380,14 +395,14 @@ void ScummEngine_v7::processKeyboard(int lastKeyHit) { if (!_smushActive || _smushVideoShouldFinish) abortCutscene(); - _mouseAndKeyboardStat = lastKeyHit; + _mouseAndKeyboardStat = lastKeyHit.ascii; return; } #else // On WinCE we've also got one special for skipping cutscenes or dialog, whatever is appropriate // Since _smushActive is not a member of the base case class ScummEngine::, we detect here if we're // playing a cutscene and skip it; else we forward the keystroke through to ScummEngine::processInput. - if (lastKeyHit == KEY_ALL_SKIP || (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit == VAR(VAR_CUTSCENEEXIT_KEY))) { + if (lastKeyHit.ascii == KEY_ALL_SKIP || (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_CUTSCENEEXIT_KEY))) { int bail = 1; if (_smushActive) { if (_game.id == GID_FT) { @@ -413,8 +428,9 @@ void ScummEngine_v7::processKeyboard(int lastKeyHit) { } #endif -void ScummEngine_v6::processKeyboard(int lastKeyHit) { - if (lastKeyHit == 20) { +void ScummEngine_v6::processKeyboard(Common::KeyState lastKeyHit) { +printf("lastKeyHit ascii %d, keycode %d, flags %d\n", lastKeyHit.ascii, lastKeyHit.keycode, lastKeyHit.flags); + if (lastKeyHit.ascii == 20) { // FIXME: The 20 seems to indicate Ctrl-T. Of course this is a // rather ugly way to detect it -- modifier + ascii code would // be a *lot* cleaner... @@ -447,17 +463,17 @@ void ScummEngine_v6::processKeyboard(int lastKeyHit) { ScummEngine::processKeyboard(lastKeyHit); } -void ScummEngine_v2::processKeyboard(int lastKeyHit) { - if (lastKeyHit == ' ') { // space +void ScummEngine_v2::processKeyboard(Common::KeyState lastKeyHit) { + if (lastKeyHit.ascii == ' ') { // space pauseGame(); - } else if (lastKeyHit == Common::ASCII_F5) { + } else if (lastKeyHit.ascii == Common::ASCII_F5) { mainMenuDialog(); - } else if (lastKeyHit == Common::ASCII_F8) { + } else if (lastKeyHit.ascii == Common::ASCII_F8) { confirmRestartDialog(); } else { - if ((_game.version == 0 && lastKeyHit == 27) || - (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit == Common::ASCII_F1-1+VAR(VAR_CUTSCENEEXIT_KEY))) { + if ((_game.version == 0 && lastKeyHit.ascii == 27) || + (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit.ascii == Common::ASCII_F1-1+VAR(VAR_CUTSCENEEXIT_KEY))) { abortCutscene(); } else { // Fall back to default behavior @@ -466,8 +482,9 @@ void ScummEngine_v2::processKeyboard(int lastKeyHit) { // Alt-F5 brings up the original save/load dialog - if (lastKeyHit == 440) { - lastKeyHit = Common::ASCII_F5; + // FIXME -- use keycode + flags instead + if (lastKeyHit.ascii == 440) { + lastKeyHit = Common::KeyState(Common::KEYCODE_F5, Common::ASCII_F5); } // Store the input type. So far we can't distinguish @@ -475,19 +492,19 @@ void ScummEngine_v2::processKeyboard(int lastKeyHit) { // 1) Verb 2) Scene 3) Inv. 4) Key // 5) Sentence Bar - if (VAR_KEYPRESS != 0xFF && lastKeyHit) { // Key Input - if (Common::ASCII_F1 <= lastKeyHit && lastKeyHit <= Common::ASCII_F9) { + if (VAR_KEYPRESS != 0xFF && lastKeyHit.ascii) { // Key Input + if (Common::ASCII_F1 <= lastKeyHit.ascii && lastKeyHit.ascii <= Common::ASCII_F9) { // Convert F-Keys for V1/V2 games (they start at 1 instead of at ASCII_F1) - VAR(VAR_KEYPRESS) = lastKeyHit - Common::ASCII_F1 + 1; + VAR(VAR_KEYPRESS) = lastKeyHit.ascii - Common::ASCII_F1 + 1; } else { - VAR(VAR_KEYPRESS) = lastKeyHit; + VAR(VAR_KEYPRESS) = lastKeyHit.ascii; } } } } -void ScummEngine_v3::processKeyboard(int lastKeyHit) { - if (_game.platform == Common::kPlatformFMTowns && lastKeyHit == Common::ASCII_F8) { +void ScummEngine_v3::processKeyboard(Common::KeyState lastKeyHit) { + if (_game.platform == Common::kPlatformFMTowns && lastKeyHit.ascii == Common::ASCII_F8) { confirmRestartDialog(); } else { // Fall back to default behavior @@ -496,7 +513,7 @@ void ScummEngine_v3::processKeyboard(int lastKeyHit) { // i brings up an IQ dialog in Indy3 - if (lastKeyHit == 'i' && _game.id == GID_INDY3) { + if (lastKeyHit.ascii == 'i' && _game.id == GID_INDY3) { // SCUMM var 244 is the episode score // and var 245 is the series score char text[50]; @@ -515,7 +532,7 @@ void ScummEngine_v3::processKeyboard(int lastKeyHit) { } } -void ScummEngine::processKeyboard(int lastKeyHit) { +void ScummEngine::processKeyboard(Common::KeyState lastKeyHit) { int saveloadkey; if ((_game.version <= 3) || (_game.id == GID_SAMNMAX) || (_game.id == GID_CMI) || (_game.heversion >= 72)) @@ -525,12 +542,14 @@ void ScummEngine::processKeyboard(int lastKeyHit) { // Alt-F5 brings up the original save/load dialog. - if (lastKeyHit == 440 && _game.version > 2 && _game.version < 8) { - lastKeyHit = saveloadkey; + if (lastKeyHit.ascii == 440 && _game.version > 2 && _game.version < 8) { + // FIXME + lastKeyHit = Common::KeyState((Common::KeyCode)saveloadkey); + saveloadkey = -1; } - if (lastKeyHit == saveloadkey) { + if (lastKeyHit.ascii == saveloadkey) { if (VAR_SAVELOAD_SCRIPT != 0xFF && _currentRoom != 0) runScript(VAR(VAR_SAVELOAD_SCRIPT), 0, 0, 0); @@ -539,25 +558,25 @@ void ScummEngine::processKeyboard(int lastKeyHit) { if (VAR_SAVELOAD_SCRIPT != 0xFF && _currentRoom != 0) runScript(VAR(VAR_SAVELOAD_SCRIPT2), 0, 0, 0); - } else if (VAR_RESTART_KEY != 0xFF && lastKeyHit == VAR(VAR_RESTART_KEY)) { + } else if (VAR_RESTART_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_RESTART_KEY)) { confirmRestartDialog(); - } else if (VAR_PAUSE_KEY != 0xFF && lastKeyHit == VAR(VAR_PAUSE_KEY)) { + } else if (VAR_PAUSE_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_PAUSE_KEY)) { pauseGame(); - } else if (VAR_TALKSTOP_KEY != 0xFF && lastKeyHit == VAR(VAR_TALKSTOP_KEY)) { + } else if (VAR_TALKSTOP_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_TALKSTOP_KEY)) { _talkDelay = 0; if (_sound->_sfxMode & 2) stopTalk(); } else { - if (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit == VAR(VAR_CUTSCENEEXIT_KEY)) { + if (VAR_CUTSCENEEXIT_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_CUTSCENEEXIT_KEY)) { abortCutscene(); - } else if (lastKeyHit == '[' || lastKeyHit == ']') { // Change music volume + } else if (lastKeyHit.ascii == '[' || lastKeyHit.ascii == ']') { // Change music volume int vol = ConfMan.getInt("music_volume") / 16; - if (lastKeyHit == ']' && vol < 16) + if (lastKeyHit.ascii == ']' && vol < 16) vol++; - else if (lastKeyHit == '[' && vol > 0) + else if (lastKeyHit.ascii == '[' && vol > 0) vol--; // Display the music volume @@ -570,10 +589,10 @@ void ScummEngine::processKeyboard(int lastKeyHit) { ConfMan.setInt("music_volume", vol); updateSoundSettings(); - } else if (lastKeyHit == '-' || lastKeyHit == '+') { // Change text speed - if (lastKeyHit == '+' && _defaultTalkDelay > 0) + } else if (lastKeyHit.ascii == '-' || lastKeyHit.ascii == '+') { // Change text speed + if (lastKeyHit.ascii == '+' && _defaultTalkDelay > 0) _defaultTalkDelay--; - else if (lastKeyHit == '-' && _defaultTalkDelay < 9) + else if (lastKeyHit.ascii == '-' && _defaultTalkDelay < 9) _defaultTalkDelay++; // Display the talk speed @@ -585,11 +604,11 @@ void ScummEngine::processKeyboard(int lastKeyHit) { if (VAR_CHARINC != 0xFF) VAR(VAR_CHARINC) = _defaultTalkDelay; - } else if (lastKeyHit == '~' || lastKeyHit == '#') { // Debug console + } else if (lastKeyHit.ascii == '~' || lastKeyHit.ascii == '#') { // Debug console _debugger->attach(); } - _mouseAndKeyboardStat = lastKeyHit; + _mouseAndKeyboardStat = lastKeyHit.ascii; } } |