1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/config-manager.h"
#include "common/events.h"
#include "common/system.h"
#include "common/translation.h"
#include "audio/mixer.h"
#include "backends/keymapper/keymapper.h"
#include "scumm/debugger.h"
#include "scumm/dialogs.h"
#include "scumm/insane/insane.h"
#include "scumm/imuse/imuse.h"
#include "scumm/imuse_digi/dimuse_engine.h"
#ifdef ENABLE_HE
#include "scumm/he/intern_he.h"
#include "scumm/he/logic_he.h"
#endif
#include "scumm/macgui/macgui.h"
#include "scumm/resource.h"
#include "scumm/scumm_v0.h"
#include "scumm/scumm_v6.h"
#include "scumm/scumm_v8.h"
#include "scumm/sound.h"
#include "scumm/dialogs.h"
#include "graphics/cursorman.h"
#include "graphics/thumbnail.h"
namespace Scumm {
enum MouseButtonStatus {
msDown = 1,
msClicked = 2
};
#ifdef ENABLE_HE
void ScummEngine_v80he::parseEvent(Common::Event event) {
ScummEngine::parseEvent(event);
// Keyboard is controlled via variable
switch (event.type) {
case Common::EVENT_KEYDOWN:
if (event.kbd.keycode == Common::KEYCODE_LEFT)
VAR(VAR_KEY_STATE) |= 1;
if (event.kbd.keycode == Common::KEYCODE_RIGHT)
VAR(VAR_KEY_STATE) |= 2;
if (event.kbd.keycode == Common::KEYCODE_UP)
VAR(VAR_KEY_STATE) |= 4;
if (event.kbd.keycode == Common::KEYCODE_DOWN)
VAR(VAR_KEY_STATE) |= 8;
if (event.kbd.keycode == Common::KEYCODE_LSHIFT || event.kbd.keycode == Common::KEYCODE_RSHIFT)
VAR(VAR_KEY_STATE) |= 16;
if (event.kbd.keycode == Common::KEYCODE_LCTRL || event.kbd.keycode == Common::KEYCODE_RCTRL)
VAR(VAR_KEY_STATE) |= 32;
break;
case Common::EVENT_KEYUP:
if (event.kbd.keycode == Common::KEYCODE_LEFT)
VAR(VAR_KEY_STATE) &= ~1;
if (event.kbd.keycode == Common::KEYCODE_RIGHT)
VAR(VAR_KEY_STATE) &= ~2;
if (event.kbd.keycode == Common::KEYCODE_UP)
VAR(VAR_KEY_STATE) &= ~4;
if (event.kbd.keycode == Common::KEYCODE_DOWN)
VAR(VAR_KEY_STATE) &= ~8;
if (event.kbd.keycode == Common::KEYCODE_LSHIFT || event.kbd.keycode == Common::KEYCODE_RSHIFT)
VAR(VAR_KEY_STATE) &= ~16;
if (event.kbd.keycode == Common::KEYCODE_LCTRL || event.kbd.keycode == Common::KEYCODE_RCTRL)
VAR(VAR_KEY_STATE) &= ~32;
break;
default:
break;
}
}
#endif
void ScummEngine::parseEvent(Common::Event event) {
// Handle Macintosh events before scaling the mouse coordinates.
//
// TODO: Don't allow menu while message banner is active. Don't allow
// message banner while menu is active.
if (_macGui && _macGui->handleEvent(event))
return;
switch (event.type) {
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
if (event.customType >= kScummActionCount) {
debugC(DEBUG_GENERAL, "customType >= kScummActionCount (%d)", event.customType);
} else {
_actionMap[event.customType] = true;
}
break;
case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
if (event.customType >= kScummActionCount) {
debugC(DEBUG_GENERAL, "customType >= kScummActionCount (%d)", event.customType);
} else {
_actionMap[event.customType] = false;
}
break;
case Common::EVENT_KEYDOWN:
if (event.kbd.keycode >= Common::KEYCODE_0 && event.kbd.keycode <= Common::KEYCODE_9 &&
((event.kbd.hasFlags(Common::KBD_ALT) && canSaveGameStateCurrently()) ||
(event.kbd.hasFlags(Common::KBD_CTRL) && canLoadGameStateCurrently()))) {
_saveLoadSlot = event.kbd.keycode - Common::KEYCODE_0;
// don't overwrite autosave (slot 0)
if (_saveLoadSlot == 0)
_saveLoadSlot = 10;
_saveLoadDescription = Common::String::format("Quicksave %d", _saveLoadSlot);
_saveLoadFlag = (event.kbd.hasFlags(Common::KBD_ALT)) ? 1 : 2;
_saveTemporaryState = false;
} else if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_f) {
_fastMode ^= 1;
} else if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_g) {
_fastMode ^= 2;
} else if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_s) {
_res->resourceStats();
} else if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_x) {
if (isUsingOriginalGUI()) {
_keyPressed = event.kbd;
} else {
quitGame();
}
} else if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_q) {
if (_game.version > 4 && _game.heversion == 0) {
quitGame();
}
} else {
// Normal key press, pass on to the game.
_keyPressed = event.kbd;
}
// HACK: Because we use ASCII values here, it's necessary to
// remap keypad keys to always have a corresponding ASCII value.
// Normally, keypad keys would only have an ASCII value when
// NumLock is enabled. This fixes fighting in Indy 3 (Trac #11227)
if (_keyPressed.keycode >= Common::KEYCODE_KP0 && _keyPressed.keycode <= Common::KEYCODE_KP9) {
_keyPressed.ascii = (_keyPressed.keycode - Common::KEYCODE_KP0) + '0';
}
// FIXME: We are using ASCII values to index the _keyDownMap here,
// yet later one code which checks _keyDownMap will use KEYCODEs
// to do so. That is, we are mixing ascii and keycode values here,
// which is bad. We probably should be only using keycodes, however,
// since getKeyState() is called by scripts, we have to be careful with
// semantic changes.
if (_keyPressed.ascii >= 512)
debugC(DEBUG_GENERAL, "_keyPressed > 512 (%d)", _keyPressed.ascii);
else
_keyDownMap[_keyPressed.ascii] = true;
break;
case Common::EVENT_KEYUP:
// HACK: Because we use ASCII values here, it's necessary to
// remap keypad keys to always have a corresponding ASCII value.
// Normally, keypad keys would only have an ASCII value when
// NumLock is enabled. This fixes fighting in Indy 3 (Trac #11227)
if (event.kbd.keycode >= Common::KEYCODE_KP0 && event.kbd.keycode <= Common::KEYCODE_KP9) {
event.kbd.ascii = (event.kbd.keycode - Common::KEYCODE_KP0) + '0';
event.kbd.flags = Common::KBD_NUM;
}
if (event.kbd.ascii >= 512) {
debugC(DEBUG_GENERAL, "keyPressed > 512 (%d)", event.kbd.ascii);
} else {
_keyDownMap[event.kbd.ascii] = false;
// Due to some weird bug with capslock key pressed
// generated keydown event is for lower letter but
// keyup is for upper letter
// On most (all?) keyboards it is safe to assume that
// both upper and lower letters are unpressed on keyup event
//
// Fixes bug #3173: "FT: CAPSLOCK + V enables cheating for all fights"
//
// Fingolfin remarks: This wouldn't be a problem if we used keycodes.
//
// TODO: Is this still needed now that INSANE uses keymapper actions?
_keyDownMap[toupper(event.kbd.ascii)] = false;
}
break;
// We update the mouse position whenever the mouse moves or a click occurs.
// The latter is done to accommodate systems with a touchpad / pen controller.
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_MOUSEMOVE:
if (event.type == Common::EVENT_LBUTTONDOWN)
_leftBtnPressed |= msClicked|msDown;
else if (event.type == Common::EVENT_RBUTTONDOWN)
_rightBtnPressed |= msClicked|msDown;
_mouse.x = event.mouse.x;
_mouse.y = event.mouse.y;
if (_renderMode == Common::kRenderHercA || _renderMode == Common::kRenderHercG) {
_mouse.x -= (kHercWidth - _screenWidth * 2) / 2;
_mouse.x >>= 1;
if (_game.version < 3) {
// MM/ZAK v1/v2
if (_mouse.y >= (_virtscr[kVerbVirtScreen].topline - _virtscr[kMainVirtScreen].topline) * 2 + _virtscr[kMainVirtScreen].topline)
_mouse.y -= (_virtscr[kVerbVirtScreen].topline - _virtscr[kMainVirtScreen].topline);
else if (_mouse.y >= _virtscr[kMainVirtScreen].topline)
_mouse.y = (_mouse.y - _virtscr[kMainVirtScreen].topline) / 2 + _virtscr[kMainVirtScreen].topline;
} else {
// MI1
_mouse.y = _mouse.y * 4 / 7;
}
} else if ((_textSurfaceMultiplier == 2 || _macScreen) || _renderMode == Common::kRenderCGA_BW || _enableEGADithering) {
_mouse.x >>= 1;
_mouse.y >>= 1;
}
if (_useMacScreenCorrectHeight && _macScreen) {
_mouse.y -= _macScreenDrawOffset;
}
break;
case Common::EVENT_LBUTTONUP:
_leftBtnPressed &= ~msDown;
break;
case Common::EVENT_RBUTTONUP:
_rightBtnPressed &= ~msDown;
break;
// The following two cases enable dialog choices to be scrolled
// through in the SegaCD version of MI. Values are taken from script-14.
// See bug report #2013 for details.
case Common::EVENT_WHEELDOWN:
if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD)
_keyPressed = Common::KeyState(Common::KEYCODE_7, 55); // '7'
if (_mainMenuIsActive)
_mouseWheelFlag = Common::EVENT_WHEELDOWN;
break;
case Common::EVENT_WHEELUP:
if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD)
_keyPressed = Common::KeyState(Common::KEYCODE_6, 54); // '6'
if (_mainMenuIsActive)
_mouseWheelFlag = Common::EVENT_WHEELUP;
break;
case Common::EVENT_MAINMENU:
// Let the user open the GMM when the menu is active.
if (isUsingOriginalGUI() && _mainMenuIsActive)
openMainMenuDialog();
break;
case Common::EVENT_RETURN_TO_LAUNCHER:
case Common::EVENT_QUIT:
{
// Some backends send a key stroke event and the quit
// event which was triggered by the keystroke. Clear the key.
clearClickedStatus();
if (isUsingOriginalGUI() &&
_game.platform != Common::kPlatformSegaCD &&
_game.platform != Common::kPlatformNES) {
if (!_quitByGUIPrompt && !_mainMenuIsActive) {
bool exitType = (event.type == Common::EVENT_RETURN_TO_LAUNCHER);
// If another message banner is currently on the screen, close it
// and then execute the quit prompt. Otherwise, prompt the user.
getEventManager()->resetQuit();
getEventManager()->resetReturnToLauncher();
if (!_messageBannerActive) {
if (_macGui) {
if (!(ConfMan.hasKey("confirm_exit") && ConfMan.getBool("confirm_exit")) ||
_macGui->runQuitDialog()) {
_quitByGUIPrompt = true;
if (exitType) {
Common::Event fakeEvent;
fakeEvent.type = Common::EVENT_RETURN_TO_LAUNCHER;
getEventManager()->pushEvent(fakeEvent);
} else {
quitGame();
}
}
} else {
queryQuit(exitType);
}
_closeBannerAndQueryQuitFlag = false;
} else {
_closeBannerAndQueryQuitFlag = true;
}
} else if (_quitByGUIPrompt) {
if (!getEventManager()->shouldReturnToLauncher())
quitGame();
}
}
break;
}
default:
break;
}
}
void ScummEngine::beginTextInput() {
Common::Keymapper *keymapper = _system->getEventManager()->getKeymapper();
Common::Keymap *engineDefault = keymapper->getKeymap("engine-default");
engineDefault->setEnabled(false);
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
}
void ScummEngine::endTextInput() {
Common::Keymapper *keymapper = _system->getEventManager()->getKeymapper();
Common::Keymap *engineDefault = keymapper->getKeymap("engine-default");
engineDefault->setEnabled(true);
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
}
void ScummEngine::parseEvents() {
Common::Event event;
while (_eventMan->pollEvent(event)) {
parseEvent(event);
}
}
#ifdef ENABLE_HE
void ScummEngine_v90he::clearClickedStatus() {
ScummEngine::clearClickedStatus();
if (_game.heversion >= 98) {
_logicHE->processKeyStroke(_keyPressed.ascii);
}
}
void ScummEngine_v90he::processInput() {
if (_game.heversion >= 98) {
_logicHE->processKeyStroke(_keyPressed.ascii);
}
ScummEngine::processInput();
}
#endif
void ScummEngine::clearClickedStatus() {
_keyPressed.reset();
_mouseAndKeyboardStat = 0;
_leftBtnPressed &= ~msClicked;
_rightBtnPressed &= ~msClicked;
_mouseWheelFlag = 0;
}
void ScummEngine_v0::processInput() {
// F1 - F3
if (_keyPressed.keycode >= Common::KEYCODE_F1 && _keyPressed.keycode <= Common::KEYCODE_F3) {
switchActor(_keyPressed.keycode - Common::KEYCODE_F1);
}
ScummEngine::processInput();
}
#ifdef ENABLE_SCUMM_7_8
void ScummEngine_v7::processInput() {
ScummEngine::processInput();
if (_skipVideo && !_smushActive) {
abortCutscene();
_mouseAndKeyboardStat = Common::ASCII_ESCAPE;
_skipVideo = false;
}
}
#endif
void ScummEngine::processInput() {
Common::KeyState lastKeyHit = _keyPressed;
_keyPressed.reset();
//
// Clip the mouse coordinates, and compute _virtualMouse.x (and clip it, too)
//
if (_mouse.x < 0)
_mouse.x = 0;
if (_mouse.x > _screenWidth-1)
_mouse.x = _screenWidth-1;
if (_mouse.y < 0)
_mouse.y = 0;
if (_mouse.y > _screenHeight-1)
_mouse.y = _screenHeight-1;
VirtScreen *vs = &_virtscr[kMainVirtScreen];
_virtualMouse.x = _mouse.x + vs->xstart;
_virtualMouse.y = _mouse.y - vs->topline;
if (_game.version >= 7)
_virtualMouse.y += _screenTop;
if (_virtualMouse.y < 0)
_virtualMouse.y = -1;
if (_virtualMouse.y >= vs->h)
_virtualMouse.y = -1;
//
// Determine the mouse button state.
//
_mouseAndKeyboardStat = 0;
if ((_leftBtnPressed & msClicked) && (_rightBtnPressed & msClicked) && _game.version >= 4) {
// Pressing both mouse buttons is treated as if you pressed
// the cutscene exit key (ESC) in V4+ games. That mimicks
// the behavior of the original engine where pressing both
// mouse buttons also skips the current cutscene.
_mouseAndKeyboardStat = 0;
lastKeyHit = Common::KeyState(Common::KEYCODE_ESCAPE);
} 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 (ESC) in V0-V3 games. That mimicks
// the behavior of the original engine where pressing right
// mouse button also skips the current cutscene.
_mouseAndKeyboardStat = 0;
lastKeyHit = Common::KeyState(Common::KEYCODE_ESCAPE);
} else if (_leftBtnPressed & msClicked) {
_mouseAndKeyboardStat = MBS_LEFT_CLICK;
} else if (_rightBtnPressed & msClicked) {
_mouseAndKeyboardStat = MBS_RIGHT_CLICK;
}
if (_game.version >= 6) {
VAR(VAR_LEFTBTN_HOLD) = (_leftBtnPressed & msDown) != 0;
VAR(VAR_RIGHTBTN_HOLD) = (_rightBtnPressed & msDown) != 0;
if (_game.heversion >= 72) {
// HE72 introduced a flag for whether or not this is a click
// or the player is continuing to hold the button down.
// 0x80 signifies that the button is continuing to be held down
// Backyard Soccer needs this in order to function
if (VAR(VAR_LEFTBTN_HOLD) && !(_leftBtnPressed & msClicked))
VAR(VAR_LEFTBTN_HOLD) |= 0x80;
if (VAR(VAR_RIGHTBTN_HOLD) && !(_rightBtnPressed & msClicked))
VAR(VAR_RIGHTBTN_HOLD) |= 0x80;
} else if (_game.version >= 7) {
VAR(VAR_LEFTBTN_DOWN) = (_leftBtnPressed & msClicked) != 0;
VAR(VAR_RIGHTBTN_DOWN) = (_rightBtnPressed & msClicked) != 0;
// Full Throttle in its interpreter has two separate input handlers, in order to handle:
// - The SCUMM system;
// - The INSANE/SMUSH system.
//
// We currently fetch all input events in ScummEngine::parseEvents() and then
// handle them in this function, and this seems to be working fine nonetheless;
// unfortunately there is at least one situation in which a mouse button press
// can become "sticky" because of this: the mineroad sequence executed on the INSANE system.
//
// If we press one of the mouse buttons at the wrong time, we end up losing the corresponding
// BUTTONUP event, and said button will remain registered as pressed until we press and release
// it again.
//
// Since the SMUSH input handler in the original interpreter gets the input events right at the
// source (i.e. the OS), I guess there is no harm in doing the same thing in our code,
// fetching the correct state for the mouse buttons right from the event manager, only when
// the INSANE/SMUSH system is active.
//
// TODO: Is this still needed now that INSANE uses keymapper actions?
if (_game.id == GID_FT && isInsaneActive()) {
VAR(VAR_LEFTBTN_HOLD) = (getEventManager()->getButtonState() & 0x1) != 0 ? 1 : 0;
VAR(VAR_RIGHTBTN_HOLD) = (getEventManager()->getButtonState() & 0x2) != 0 ? 1 : 0;
// Also, fix the state of these two variables, which might still be out of sync...
if ((getEventManager()->getButtonState() & 0x1) != 0)
_leftBtnPressed &= ~msDown;
if ((getEventManager()->getButtonState() & 0x2) != 0)
_rightBtnPressed &= ~msDown;
}
// WORKAROUND: In COMI main menu, sometimes clicks are not registered
// correctly; in particular there usually a situation in which both
// states for a mouse button (msClicked and msDown) are being captured.
// Apparently this is not what the script expects: it asks for the
// mouse button being held down (why?) but not clicked (again, why?).
//
// Instead of mangling our very sturdy input system just for this use
// case, we just insert this little hack to make sure that the menu
// works as intended. After all, this all just might be caused by the
// difference between the (very slow...) mouse polling rate of the original
// and ours.
if (isUsingOriginalGUI() && _game.id == GID_CMI && _currentRoom == 92) {
VAR(VAR_LEFTBTN_HOLD) = (_leftBtnPressed & msDown) != 0;
VAR(VAR_RIGHTBTN_HOLD) = (_rightBtnPressed & msDown) != 0;
VAR(VAR_LEFTBTN_DOWN) = 0;
VAR(VAR_RIGHTBTN_DOWN) = 0;
}
}
}
_leftBtnPressed &= ~msClicked;
_rightBtnPressed &= ~msClicked;
if (!lastKeyHit.ascii)
return;
processKeyboard(lastKeyHit);
}
#ifdef ENABLE_SCUMM_7_8
void ScummEngine_v8::processKeyboard(Common::KeyState lastKeyHit) {
if (isUsingOriginalGUI()) {
if (lastKeyHit.keycode == Common::KEYCODE_INVALID)
return;
// Main menu (allow both F1 and F5) mapping; unlike in
// the past we choose not to enable it without the
// original GUI selected as an option
if (!(_game.features & GF_DEMO) &&
(lastKeyHit.keycode == Common::KEYCODE_F1 || lastKeyHit.keycode == Common::KEYCODE_F5) &&
lastKeyHit.hasFlags(0)) {
lastKeyHit = Common::KeyState(Common::KEYCODE_F1, 315);
}
// Actually show the main menu screen...
if (!(_game.features & GF_DEMO) && _keyScriptNo && (_keyScriptKey == lastKeyHit.ascii)) {
if (!isSmushActive())
runScript(_keyScriptNo, 0, 0, 0);
return;
}
}
// F1 (the trigger for the original save/load dialog) is mapped to F5
if (!(_game.features & GF_DEMO) && lastKeyHit.keycode == Common::KEYCODE_F1 && lastKeyHit.hasFlags(0)) {
lastKeyHit = Common::KeyState(Common::KEYCODE_F5, 319);
}
// Fall back to V7 behavior...
ScummEngine_v7::processKeyboard(lastKeyHit);
}
void ScummEngine_v7::processKeyboard(Common::KeyState lastKeyHit) {
if (isUsingOriginalGUI()) {
if (lastKeyHit.keycode == Common::KEYCODE_b &&
((lastKeyHit.hasFlags(Common::KBD_CTRL) && _game.id != GID_DIG) || lastKeyHit.hasFlags(Common::KBD_SHIFT))) {
int curBufferCount = _imuseDigital->roundRobinSetBufferCount();
// "iMuse buffer count changed to %d"
showBannerAndPause(0, 90, getGUIString(gsIMuseBuffer), curBufferCount);
return;
}
}
const bool cutsceneExitKeyEnabled = (VAR_CUTSCENEEXIT_KEY == 0xFF || VAR(VAR_CUTSCENEEXIT_KEY) != 0);
// VAR_VERSION_KEY (usually ctrl-v) is used in COMI, Dig and FT to trigger
// a version dialog, unless VAR_VERSION_KEY is set to 0. However, the COMI
// version string is hard coded in the engine, hence we don't invoke
// versionDialog for it. Dig/FT version strings are partly hard coded, too.
if (!isUsingOriginalGUI() && _game.id != GID_CMI && 0 != VAR(VAR_VERSION_KEY) &&
lastKeyHit.keycode == Common::KEYCODE_v && lastKeyHit.hasFlags(Common::KBD_CTRL)) {
versionDialog();
} else if (cutsceneExitKeyEnabled && lastKeyHit.keycode == Common::KEYCODE_ESCAPE) {
// Skip cutscene (or active SMUSH video).
if (_smushActive) {
if (_game.id == GID_FT)
_insane->escapeKeyHandler();
else
_smushVideoShouldFinish = true;
// WORKAROUND bug #12022: For some reason, skipping the cutscene in which Ben fires up
// his bike (after retrieving the keys from the bartender), will outright skip the first
// bike fight sequence. Because of this, the script which handles playing ambient and wind SFX
// outside the bar is never stopped, so those SFX are unintentionally played throughout the
// rest of the game.
// This fix produces the intended behaviour from the original interpreter.
if (_game.id == GID_FT && _currentRoom == 6
&& (vm.slot[_currentScript].number == 65 || vm.slot[_currentScript].number == 64)) {
_skipVideo = false;
} else {
_skipVideo = true;
}
} else {
abortCutscene();
}
_mouseAndKeyboardStat = Common::ASCII_ESCAPE;
} else {
// Fall back to V6 behavior
ScummEngine_v6::processKeyboard(lastKeyHit);
}
}
#endif
void ScummEngine::waitForBannerInput(int32 waitTime, Common::KeyState &ks, bool &leftBtnClicked, bool &rightBtnClicked, bool handleMouseWheel) {
bool validKey = false;
if (waitTime && waitTime != -1) {
uint32 millis = _system->getMillis();
while (((_system->getMillis() - millis) * (getTimerFrequency() / 4) / 1000) < waitTime) {
waitForTimer(1); // Allow the engine to update the screen and fetch new inputs...
if (_game.version < 7 && (_guiCursorAnimCounter++ & 16)) {
_guiCursorAnimCounter = 0;
animateCursor();
}
ks = _keyPressed;
leftBtnClicked = (_leftBtnPressed & msClicked) != 0;
rightBtnClicked = (_rightBtnPressed & msClicked) != 0;
validKey = ks.keycode != Common::KEYCODE_INVALID &&
ks.keycode != Common::KEYCODE_LALT &&
ks.keycode != Common::KEYCODE_RALT &&
!(ks.keycode == Common::KEYCODE_s && ks.hasFlags(Common::KBD_ALT));
if (validKey || leftBtnClicked || rightBtnClicked || (handleMouseWheel && _mouseWheelFlag))
return;
if (shouldQuit())
return;
if (_closeBannerAndQueryQuitFlag) {
_closeBannerAndQueryQuitFlag = false;
Common::Event event;
event.type = Common::EVENT_QUIT;
getEventManager()->pushEvent(event);
return;
}
}
} else {
while (!validKey && !leftBtnClicked && !rightBtnClicked && !(handleMouseWheel && _mouseWheelFlag)) {
waitForTimer(1, true); // Allow the engine to update the screen and fetch new inputs...
if (_game.version > 2 && _game.version < 7 && (_guiCursorAnimCounter++ & 16)) {
_guiCursorAnimCounter = 0;
animateCursor();
}
ks = _keyPressed;
leftBtnClicked = (_leftBtnPressed & msClicked) != 0;
rightBtnClicked = (_rightBtnPressed & msClicked) != 0;
if (shouldQuit())
return;
if (_closeBannerAndQueryQuitFlag && !_comiQuitMenuIsOpen) {
_closeBannerAndQueryQuitFlag = false;
Common::Event event;
event.type = Common::EVENT_QUIT;
getEventManager()->pushEvent(event);
return;
}
validKey = ks.keycode != Common::KEYCODE_INVALID &&
ks.keycode != Common::KEYCODE_LALT &&
ks.keycode != Common::KEYCODE_RALT &&
ks.keycode != Common::KEYCODE_LCTRL &&
ks.keycode != Common::KEYCODE_RCTRL &&
ks.keycode != Common::KEYCODE_LSHIFT &&
ks.keycode != Common::KEYCODE_RSHIFT &&
ks.keycode != Common::KEYCODE_UP &&
ks.keycode != Common::KEYCODE_DOWN &&
ks.keycode != Common::KEYCODE_LEFT &&
ks.keycode != Common::KEYCODE_RIGHT &&
!(ks.keycode == Common::KEYCODE_s && ks.hasFlags(Common::KBD_ALT));
}
}
}
void ScummEngine_v6::processKeyboard(Common::KeyState lastKeyHit) {
if (isUsingOriginalGUI()) {
char sliderString[256];
PauseToken pt;
if (_game.version != 8 || (_game.version == 8 && (_game.features & GF_DEMO))) {
// "Music Volume Low ========= High"
if (lastKeyHit.hasFlags(Common::KBD_SHIFT) &&
(lastKeyHit.keycode == Common::KEYCODE_o || lastKeyHit.keycode == Common::KEYCODE_p)) {
Common::KeyState ks = lastKeyHit;
pt = pauseEngine();
#ifdef ENABLE_SCUMM_7_8
int volume = (_game.version > 6) ? _imuseDigital->diMUSEGetMusicGroupVol() : getMusicVolume();
#else
int volume = getMusicVolume();
#endif
do {
if (ks.keycode == Common::KEYCODE_o) {
volume -= 16;
if (volume < 0)
volume = 0;
} else {
volume += 16;
if (volume > 127)
volume = 127;
}
getSliderString(gsMusicVolumeSlider, volume, sliderString, sizeof(sliderString));
showBannerAndPause(0, 0, sliderString);
ks = Common::KEYCODE_INVALID;
bool leftBtnPressed = false, rightBtnPressed = false;
waitForBannerInput(60, ks, leftBtnPressed, rightBtnPressed);
} while (ks.keycode == Common::KEYCODE_o || ks.keycode == Common::KEYCODE_p);
clearBanner();
setMusicVolume(volume);
pt.clear();
return;
}
// "Voice Volume Low ========= High"
if (lastKeyHit.hasFlags(Common::KBD_SHIFT) &&
(lastKeyHit.keycode == Common::KEYCODE_k || lastKeyHit.keycode == Common::KEYCODE_l)) {
Common::KeyState ks = lastKeyHit;
pt = pauseEngine();
#ifdef ENABLE_SCUMM_7_8
int volume = (_game.version > 6) ? _imuseDigital->diMUSEGetVoiceGroupVol() : getSpeechVolume();
#else
int volume = getSpeechVolume();
#endif
do {
if (ks.keycode == Common::KEYCODE_k) {
volume -= 16;
if (volume < 0)
volume = 0;
} else {
volume += 16;
if (volume > 127)
volume = 127;
}
getSliderString(gsVoiceVolumeSlider, volume, sliderString, sizeof(sliderString));
showBannerAndPause(0, 0, sliderString);
ks = Common::KEYCODE_INVALID;
bool leftBtnPressed = false, rightBtnPressed = false;
waitForBannerInput(60, ks, leftBtnPressed, rightBtnPressed);
} while (ks.keycode == Common::KEYCODE_k || ks.keycode == Common::KEYCODE_l);
clearBanner();
setSpeechVolume(volume);
pt.clear();
return;
}
// "Sfx Volume Low ========= High"
if (lastKeyHit.hasFlags(Common::KBD_SHIFT) &&
(lastKeyHit.keycode == Common::KEYCODE_n || lastKeyHit.keycode == Common::KEYCODE_m)) {
Common::KeyState ks = lastKeyHit;
pt = pauseEngine();
#ifdef ENABLE_SCUMM_7_8
int volume = (_game.version > 6) ? _imuseDigital->diMUSEGetSFXGroupVol() : getSFXVolume();
#else
int volume = getSFXVolume();
#endif
do {
if (ks.keycode == Common::KEYCODE_n) {
volume -= 16;
if (volume < 0)
volume = 0;
} else {
volume += 16;
if (volume > 127)
volume = 127;
}
getSliderString(gsSfxVolumeSlider, volume, sliderString, sizeof(sliderString));
showBannerAndPause(0, 0, sliderString);
ks = Common::KEYCODE_INVALID;
bool leftBtnPressed = false, rightBtnPressed = false;
waitForBannerInput(60, ks, leftBtnPressed, rightBtnPressed);
} while (ks.keycode == Common::KEYCODE_n || ks.keycode == Common::KEYCODE_m);
clearBanner();
setSFXVolume(volume);
pt.clear();
return;
}
}
if (VAR_VERSION_KEY != 0xFF && VAR(VAR_VERSION_KEY) != 0 &&
lastKeyHit.keycode == Common::KEYCODE_v && lastKeyHit.hasFlags(Common::KBD_CTRL)) {
if (_game.version == 8) {
showBannerAndPause(0, -1, _dataFileVersionString);
// This is not the string being used by the interpreter, which is instead hardcoded
// in the executable. The one used here is found in the data files.
showBannerAndPause(0, -1, _engineVersionString);
if (_game.features & GF_DEMO)
showBannerAndPause(0, -1, "iMuse(tm) initialized");
return;
} else if (_game.version == 7) {
showBannerAndPause(0, -1, getGUIString(gsVersion));
showBannerAndPause(0, -1, "Scripts compiled %s", _dataFileVersionString);
showBannerAndPause(0, -1, "SPU(tm) version %s", _engineVersionString);
showBannerAndPause(0, -1, "iMuse(tm) initialized");
return;
}
// Older versions show this banner via scripts, so just let it fallback...
}
} else {
if (lastKeyHit.keycode == Common::KEYCODE_t && lastKeyHit.hasFlags(Common::KBD_CTRL)) {
SubtitleSettingsDialog dialog(this, _voiceMode);
_voiceMode = runDialog(dialog);
switch (_voiceMode) {
case 0:
ConfMan.setBool("speech_mute", false);
ConfMan.setBool("subtitles", false);
break;
case 1:
ConfMan.setBool("speech_mute", false);
ConfMan.setBool("subtitles", true);
break;
case 2:
ConfMan.setBool("speech_mute", true);
ConfMan.setBool("subtitles", true);
break;
default:
break;
}
// We need to sync the current sound settings here to make sure that
// we actually update the mute state of speech properly.
syncSoundSettings();
return;
}
}
// Fall back to default behavior
ScummEngine::processKeyboard(lastKeyHit);
}
void ScummEngine_v2::processKeyboard(Common::KeyState lastKeyHit) {
if (isUsingOriginalGUI()) {
if (lastKeyHit.keycode == Common::KEYCODE_F5) {
if (_game.id == GID_MANIAC && _game.version == 0) {
runScript(2, 0, 0, nullptr);
}
}
}
// RETURN is used to skip cutscenes in the Commodore 64 version of Zak McKracken
if (_game.id == GID_ZAK &&_game.platform == Common::kPlatformC64 && lastKeyHit.keycode == Common::KEYCODE_RETURN && lastKeyHit.hasFlags(0)) {
lastKeyHit = Common::KeyState(Common::KEYCODE_ESCAPE);
// F7 is used to skip cutscenes in the Commodore 64 version of Maniac Mansion
} else if (_game.id == GID_MANIAC &&_game.platform == Common::kPlatformC64) {
// Demo always F7 to be pressed to restart
if (_game.features & GF_DEMO) {
if (_roomResource != 0x2D && lastKeyHit.keycode == Common::KEYCODE_F7 && lastKeyHit.hasFlags(0)) {
restart();
return;
}
} else {
if (lastKeyHit.keycode == Common::KEYCODE_F7 && lastKeyHit.hasFlags(0))
lastKeyHit = Common::KeyState(Common::KEYCODE_ESCAPE);
}
// 'B' is used to skip cutscenes in the NES version of Maniac Mansion
} else if (_game.id == GID_MANIAC &&_game.platform == Common::kPlatformNES) {
if (lastKeyHit.keycode == Common::KEYCODE_b && lastKeyHit.hasFlags(Common::KBD_SHIFT))
lastKeyHit = Common::KeyState(Common::KEYCODE_ESCAPE);
// 'F4' is used to skip cutscenes in the other versions of Maniac Mansion
} else if (_game.id == GID_MANIAC) {
if (lastKeyHit.keycode == Common::KEYCODE_F4 && lastKeyHit.hasFlags(0))
lastKeyHit = Common::KeyState(Common::KEYCODE_ESCAPE);
}
// Fall back to default behavior
ScummEngine::processKeyboard(lastKeyHit);
// On Alt-F5 load the original save/load dialog for MANIAC NES
if (lastKeyHit.keycode == Common::KEYCODE_F5 && lastKeyHit.hasFlags(Common::KBD_ALT)) {
if (_game.id == GID_MANIAC && _game.platform == Common::kPlatformNES) {
runScript(163, 0, 0, nullptr);
}
}
if (VAR_KEYPRESS != 0xFF && _mouseAndKeyboardStat) { // Key Input
if (315 <= _mouseAndKeyboardStat && _mouseAndKeyboardStat <= 323) {
// Convert F-Keys for V1/V2 games (they start at 1)
VAR(VAR_KEYPRESS) = _mouseAndKeyboardStat - 314;
} else {
VAR(VAR_KEYPRESS) = _mouseAndKeyboardStat;
}
}
}
void ScummEngine_v3::processKeyboard(Common::KeyState lastKeyHit) {
// Fall back to default behavior
ScummEngine::processKeyboard(lastKeyHit);
if (!isUsingOriginalGUI()) {
// 'i' brings up an IQ dialog in Indy3 (disabled in save/load dialog for input)
if (lastKeyHit.ascii == 'i' && _game.id == GID_INDY3 && _currentRoom != 14) {
// SCUMM var 244 is the episode score
// and var 245 is the series score
char text[50];
updateIQPoints();
Common::sprintf_s(text, "IQ Points: Episode = %d, Series = %d", _scummVars[244], _scummVars[245]);
Indy3IQPointsDialog indy3IQPointsDialog(this, text);
runDialog(indy3IQPointsDialog);
}
}
}
void ScummEngine::processKeyboard(Common::KeyState lastKeyHit) {
// Enable the following special keys conditionally:
bool restartKeyEnabled = (VAR_RESTART_KEY == 0xFF || VAR(VAR_RESTART_KEY) != 0);
bool pauseKeyEnabled = (VAR_PAUSE_KEY == 0xFF || VAR(VAR_PAUSE_KEY) != 0);
bool talkstopKeyEnabled = (VAR_TALKSTOP_KEY == 0xFF || VAR(VAR_TALKSTOP_KEY) != 0);
bool cutsceneExitKeyEnabled = (VAR_CUTSCENEEXIT_KEY == 0xFF || VAR(VAR_CUTSCENEEXIT_KEY) != 0);
bool mainmenuKeyEnabled = (VAR_MAINMENU_KEY == 0xFF || VAR(VAR_MAINMENU_KEY) != 0);
bool snapScrollKeyEnabled = (_game.version >= 2 && _game.version <= 4);
bool optionKeysEnabled = !isUsingOriginalGUI();
bool isSegaCD = _game.platform == Common::kPlatformSegaCD;
bool isNES = _game.platform == Common::kPlatformNES;
bool inSaveRoom = false;
bool canToggleSmoothing = _macScreen && _game.version > 3 && _game.heversion == 0;
// The following check is used by v3 games which have writable savegame names
// and also support some key combinations which in our case are mapped to SHIFT-<letter>
// The originals don't do this, because they use either CTRL or ALT as their key modifier,
// and those key modifiers serve other functions within the ScummVM backend.
if (_game.version == 3) {
int saveRoom = -1;
if (_game.id == GID_ZAK) {
saveRoom = 50;
} else if (_game.id == GID_INDY3) {
saveRoom = 14;
} else if (_game.id == GID_LOOM) {
saveRoom = 70;
}
inSaveRoom = _currentRoom == saveRoom;
}
// In FM-TOWNS games F8 / restart is always enabled
if (_game.platform == Common::kPlatformFMTowns)
restartKeyEnabled = true;
if (isUsingOriginalGUI()) {
if (lastKeyHit.keycode == Common::KEYCODE_F5 && _game.version <= 3) {
_savegameThumbnail.free();
Graphics::createThumbnail(_savegameThumbnail);
}
char sliderString[256];
PauseToken pt;
if ((VAR_PAUSE_KEY != 0xFF && lastKeyHit.ascii == VAR(VAR_PAUSE_KEY)) ||
(lastKeyHit.keycode == Common::KEYCODE_SPACE && _game.features & GF_DEMO)) {
if (isSegaCD) {
if (VAR(VAR_MAINMENU_KEY) != 0)
showMainMenu();
return;
} else {
// Force the cursor OFF...
int8 oldCursorState = _cursor.state;
_cursor.state = (_game.id == GID_MONKEY && _game.platform == Common::kPlatformMacintosh) ? 1 : 0;
CursorMan.showMouse(_cursor.state > 0);
// "Game Paused. Press SPACE to Continue."
if (_game.version > 4)
showBannerAndPause(0, -1, getGUIString(gsPause));
else
showOldStyleBannerAndPause(getGUIString(gsPause), 12, -1);
_cursor.state = oldCursorState;
return;
}
} else if (lastKeyHit.keycode == Common::KEYCODE_SPACE && isNES) {
runScript(163, 0, 0, nullptr);
return;
} else if (_game.version <= 2 && lastKeyHit.keycode == Common::KEYCODE_SPACE) {
printMessageAndPause(getGUIString(gsPause), 0, -1, true);
return;
}
bool restartKeyPressed = false;
// Restart if we've hit the restart key or if there is none but F8 is pressed...
restartKeyPressed |= ((VAR_RESTART_KEY != 0xFF && (lastKeyHit.ascii == VAR(VAR_RESTART_KEY))));
// ...or if this is a pre v3 or post v6, force the restart prompt on F8...
restartKeyPressed |= ((_game.version < 3 || _game.version > 6) &&
lastKeyHit.keycode == Common::KEYCODE_F8 && lastKeyHit.hasFlags(0));
// ...or if this is a v3 FM-Towns game, restart on F8 (the original accepted a key value of 0xFFFF8008)...
restartKeyPressed |= _game.platform == Common::kPlatformFMTowns && _game.version == 3 &&
lastKeyHit.keycode == Common::KEYCODE_F8 && lastKeyHit.hasFlags(0);
// ...but do not allow the restart banner to appear at all, if this is MI1 SegaCD or Maniac NES.
restartKeyPressed &= !isSegaCD && !isNES;
if (restartKeyPressed) {
if (_macGui) {
if (_macGui->runRestartDialog()) {
restart();
}
} else {
queryRestart();
}
return;
}
// Generally allow voice mode settings only for v6, 7 and 8.
// Also allow it for Indy4 Talkie, which does its own thing.
if (((VAR_VOICE_MODE != 0xFF) || ((_game.features & GF_ULTIMATE_TALKIE) ||
(_game.id == GID_INDY4 && strcmp(_game.variant, "Floppy") && strcmp(_game.variant, "Amiga")))) &&
(lastKeyHit.keycode == Common::KEYCODE_t && lastKeyHit.hasFlags(Common::KBD_CTRL))) {
int voiceMode = (_game.version == 5) ? _v5VoiceMode : VAR(VAR_VOICE_MODE);
voiceMode++;
if (voiceMode >= 3) {
voiceMode = 0;
}
if (_game.version == 5)
_v5VoiceMode = voiceMode;
switch (voiceMode) {
case 0: // "Voice Only"
showBannerAndPause(0, 120, getGUIString(gsVoiceOnly));
break;
case 1: // "Voice and Text"
showBannerAndPause(0, 120, getGUIString(gsVoiceAndText));
break;
default: // "Text Display Only"
showBannerAndPause(0, 120, getGUIString(gsTextDisplayOnly));
}
ConfMan.setInt("original_gui_text_status", voiceMode);
switch (voiceMode) {
case 0:
ConfMan.setBool("speech_mute", false);
ConfMan.setBool("subtitles", false);
break;
case 1:
ConfMan.setBool("speech_mute", false);
ConfMan.setBool("subtitles", true);
break;
case 2:
ConfMan.setBool("speech_mute", true);
ConfMan.setBool("subtitles", true);
break;
default:
break;
}
ConfMan.flushToDisk();
syncSoundSettings();
return;
}
// "Text Speed Slow ========== Fast"
if (((_game.version > 3 && _game.version < 8) || (_game.version == 8 && (_game.features & GF_DEMO)))
&& (lastKeyHit.ascii == '+' || lastKeyHit.ascii == '-') && !isSegaCD) {
if (VAR_CHARINC == 0xFF)
return;
Common::KeyState ks = lastKeyHit;
pt = pauseEngine();
do {
if (ks.ascii == '+') {
VAR(VAR_CHARINC) -= 1;
if (VAR(VAR_CHARINC) < 0)
VAR(VAR_CHARINC) = 0;
} else {
VAR(VAR_CHARINC) += 1;
if (VAR(VAR_CHARINC) > 9)
VAR(VAR_CHARINC) = 9;
}
_defaultTextSpeed = 9 - VAR(VAR_CHARINC);
ConfMan.setInt("original_gui_text_speed", _defaultTextSpeed);
setTalkSpeed(_defaultTextSpeed);
getSliderString(gsTextSpeedSlider, VAR(VAR_CHARINC), sliderString, sizeof(sliderString));
if (_game.version > 4) {
showBannerAndPause(0, 0, sliderString);
} else if (_game.version == 4) {
showOldStyleBannerAndPause(sliderString, 9, 0);
}
ks = Common::KEYCODE_INVALID;
bool leftBtnPressed = false, rightBtnPressed = false;
waitForBannerInput(60, ks, leftBtnPressed, rightBtnPressed);
} while (ks.ascii == '+' || ks.ascii == '-');
if (_game.version > 6 || _game.platform == Common::Platform::kPlatformFMTowns)
clearBanner();
pt.clear();
return;
}
if (_game.version <= 2 && (lastKeyHit.ascii == '+' || lastKeyHit.ascii == '-' ||
lastKeyHit.ascii == '>' || lastKeyHit.ascii == '<') && !isSegaCD) {
Common::KeyState ks = lastKeyHit;
byte textSpeedColor;
if (ks.ascii == '+' || ks.ascii == '>') {
textSpeedColor = _game.version <= 1 ? 7 : 14;
if (_defaultTextSpeed > 0)
_defaultTextSpeed -= 1;
} else {
textSpeedColor = _game.version <= 1 ? 2 : 4;
if (_defaultTextSpeed < 9)
_defaultTextSpeed += 1;
}
setTalkSpeed(_defaultTextSpeed);
ConfMan.setInt("original_gui_text_speed", _defaultTextSpeed);
getSliderString(gsTextSpeedSlider, 9 - _defaultTextSpeed, sliderString, sizeof(sliderString));
printMessageAndPause(sliderString, textSpeedColor, 0, false);
return;
}
if (_game.version > 4 && lastKeyHit.keycode == Common::KEYCODE_k && lastKeyHit.hasFlags(Common::KBD_CTRL) && !isSegaCD) {
bool useExtendedMsg = _game.id == GID_TENTACLE ||
(_game.id == GID_SAMNMAX && (!strcmp(_game.variant, "Floppy") || (_game.features & GF_DEMO)));
if (useExtendedMsg && VAR_V6_EMSSPACE != 0xFF) {
showBannerAndPause(0, 120, getGUIString(gsHeapExt), _res->getHeapSize() / 1024, VAR(VAR_V6_EMSSPACE));
} else {
showBannerAndPause(0, 120, getGUIString(gsHeap), _res->getHeapSize() / 1024);
}
return;
}
// NOTE: For consistency we enable the quit message even for sub v3 games which don't have it.
if ((lastKeyHit.keycode == Common::KEYCODE_c && lastKeyHit.hasFlags(Common::KBD_CTRL)) ||
(lastKeyHit.keycode == Common::KEYCODE_x && lastKeyHit.hasFlags(Common::KBD_ALT))) {
Common::Event event;
event.type = Common::EVENT_QUIT;
getEventManager()->pushEvent(event);
return;
}
if (VAR_MAINMENU_KEY != 0xFF && (lastKeyHit.ascii == VAR(VAR_MAINMENU_KEY) && lastKeyHit.hasFlags(0))
&& _game.version > 3) {
if (isSegaCD) {
// We map the GMM to F5, while SPACE (which acts as our pause button) calls the original menu...
openMainMenuDialog();
} else if (_macGui) {
openMainMenuDialog(); // Mac games have their own menu so let's just call the GMM...
} else {
showMainMenu();
}
return;
} else if (lastKeyHit.keycode == Common::KEYCODE_F5 && isNES) {
// We map the GMM to F5, while SPACE (which acts as our pause button) calls the original menu...
openMainMenuDialog();
} else if (lastKeyHit.keycode == Common::KEYCODE_F5 && _game.version == 3 && _game.platform == Common::kPlatformMacintosh) {
// We don't have original menus for Mac versions of LOOM and INDY3, so let's just open the GMM...
openMainMenuDialog();
return;
}
if (enhancementEnabled(kEnhUIUX) && _game.id == GID_LOOM &&
mainmenuKeyEnabled && (lastKeyHit.keycode == Common::KEYCODE_d && lastKeyHit.hasFlags(Common::KBD_CTRL))) {
// Drafts menu
if (_macGui) {
_macGui->runDraftsInventory();
} else {
showDraftsInventory();
}
}
if (snapScrollKeyEnabled) {
if ((_game.version == 2 && lastKeyHit.keycode == Common::KEYCODE_s && lastKeyHit.hasFlags(Common::KBD_SHIFT)) ||
(_game.version == 3 && lastKeyHit.keycode == Common::KEYCODE_i && lastKeyHit.hasFlags(Common::KBD_ALT)) ||
(_game.version == 4 && lastKeyHit.keycode == Common::KEYCODE_r && lastKeyHit.hasFlags(Common::KBD_CTRL))) {
_snapScroll ^= 1;
if (_game.version < 3) {
if (_snapScroll) {
printMessageAndPause(getGUIString(gsSnapOn), 2, 0, false);
} else {
printMessageAndPause(getGUIString(gsSnapOff), 14, 0, false);
}
} else {
if (_snapScroll) {
showOldStyleBannerAndPause(getGUIString(gsSnapOn), 9, 90);
} else {
showOldStyleBannerAndPause(getGUIString(gsSnapOff), 9, 90);
}
}
if (VAR_CAMERA_FAST_X != 0xFF)
VAR(VAR_CAMERA_FAST_X) = _snapScroll;
return;
}
}
// The following ones serve no purpose whatsoever, but just for the sake of completeness...
// Also, some of these were originally mapped with the CTRL flag, but they would clash with other
// internal ScummVM commands, so they are instead available with the SHIFT flag.
if (_game.version < 7 && !isSegaCD && !isNES) {
if (_game.version == 6 && lastKeyHit.keycode == Common::KEYCODE_j && lastKeyHit.hasFlags(Common::KBD_CTRL)) {
showBannerAndPause(0, 90, getGUIString(gsRecalJoystick));
return;
} else if (_game.version >= 4 && lastKeyHit.keycode == Common::KEYCODE_j && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
if (_game.version == 4) {
showOldStyleBannerAndPause(getGUIString(gsRecalJoystick), 2, 90);
} else if (!_macGui) {
showBannerAndPause(0, 90, getGUIString(gsRecalJoystick));
}
return;
}
if (_game.version == 6 && lastKeyHit.keycode == Common::KEYCODE_n && lastKeyHit.hasFlags(Common::KBD_CTRL)) {
showBannerAndPause(0, 90, getGUIString(gsMouseMode));
return;
}
if (_game.version >= 4 && lastKeyHit.keycode == Common::KEYCODE_m && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
if (_game.version == 4) {
showOldStyleBannerAndPause(getGUIString(gsMouseMode), 2, 90);
} else if (!_macGui) {
showBannerAndPause(0, 90, getGUIString(gsMouseMode));
}
return;
}
if (_game.version < 3) {
if (lastKeyHit.keycode == Common::KEYCODE_m && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
_guiMouseFlag ^= 1;
if (_guiMouseFlag) {
printMessageAndPause(getGUIString(gsMouseOn), _game.version <= 1 ? 5 : 2, 0, false);
} else {
printMessageAndPause(getGUIString(gsMouseOff), _game.version <= 1 ? 2 : 4, 0, false);
}
return;
}
if (lastKeyHit.keycode == Common::KEYCODE_j && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
_guiJoystickFlag ^= 1;
if (_guiJoystickFlag) {
printMessageAndPause(getGUIString(gsJoystickOn), _game.version <= 1 ? 5 : 2, 0, false);
} else {
printMessageAndPause(getGUIString(gsJoystickOff), _game.version <= 1 ? 2 : 4, 0, false);
}
return;
}
if (lastKeyHit.keycode == Common::KEYCODE_F6) {
_internalSpeakerSoundsAreOn ^= 1;
if (_internalSpeakerSoundsAreOn) {
printMessageAndPause(getGUIString(gsSoundsOn), _game.version <= 1 ? 5 : 2, 0, false);
} else {
printMessageAndPause(getGUIString(gsSoundsOff), _game.version <= 1 ? 2 : 4, 0, false);
}
return;
}
}
if ((_game.version > 2 && _game.version < 5)) {
if (lastKeyHit.keycode == Common::KEYCODE_s && lastKeyHit.hasFlags(Common::KBD_SHIFT) && !inSaveRoom) {
_internalSpeakerSoundsAreOn ^= 1;
if (_internalSpeakerSoundsAreOn) {
showOldStyleBannerAndPause(getGUIString(gsSoundsOn), 9, 90);
} else {
showOldStyleBannerAndPause(getGUIString(gsSoundsOff), 9, 90);
}
return;
}
}
// Graphic mode toggles for v1-2... maybe one day they'll actually do something :-)
if (_game.version == 1 || _game.version == 2) {
// VGA/MCGA mode
if (lastKeyHit.keycode == Common::KEYCODE_v && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
printMessageAndPause(getGUIString(gsVGAMode), _game.version <= 1 ? 5 : 2, 0, false);
}
// EGA mode
if (lastKeyHit.keycode == Common::KEYCODE_e && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
printMessageAndPause(getGUIString(gsEGAMode), _game.version <= 1 ? 5 : 2, 0, false);
}
// CGA mode
if (lastKeyHit.keycode == Common::KEYCODE_c && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
printMessageAndPause(getGUIString(gsCGAMode), _game.version <= 1 ? 5 : 2, 0, false);
}
// Hercules mode
if (lastKeyHit.keycode == Common::KEYCODE_h && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
printMessageAndPause(getGUIString(gsHerculesMode), _game.version <= 1 ? 5 : 2, 0, false);
}
// Tandy 16-color mode
if (lastKeyHit.keycode == Common::KEYCODE_t && lastKeyHit.hasFlags(Common::KBD_SHIFT)) {
printMessageAndPause(getGUIString(gsTandyMode), _game.version <= 1 ? 5 : 2, 0, false);
}
}
}
}
// For games which use VAR_MAINMENU_KEY, disable the mainmenu key if
// requested by the scripts. We make an exception for COMI (i.e.
// forcefully always enable it there), as that always disables it.
if (_game.id == GID_CMI)
mainmenuKeyEnabled = true;
if (mainmenuKeyEnabled && !isUsingOriginalGUI() && (lastKeyHit.keycode == Common::KEYCODE_F5 && lastKeyHit.hasFlags(0))) {
if (VAR_PRE_SAVELOAD_SCRIPT != 0xFF && _currentRoom != 0)
runScript(VAR(VAR_PRE_SAVELOAD_SCRIPT), 0, 0, nullptr);
openMainMenuDialog(); // Display global main menu
// reload options
_enableAudioOverride = ConfMan.getBool("audio_override");
if (VAR_POST_SAVELOAD_SCRIPT != 0xFF && _currentRoom != 0)
runScript(VAR(VAR_POST_SAVELOAD_SCRIPT), 0, 0, nullptr);
} else if (restartKeyEnabled && !isUsingOriginalGUI() && (lastKeyHit.keycode == Common::KEYCODE_F8 && lastKeyHit.hasFlags(0))) {
confirmRestartDialog();
} else if (pauseKeyEnabled && !isUsingOriginalGUI() && (lastKeyHit.keycode == Common::KEYCODE_SPACE && lastKeyHit.hasFlags(0))) {
pauseGame();
} else if (talkstopKeyEnabled && lastKeyHit.ascii == '.') {
_talkDelay = 0;
if (_sound->_digiSndMode & DIGI_SND_MODE_TALKIE)
stopTalk();
} else if (cutsceneExitKeyEnabled && (lastKeyHit.keycode == Common::KEYCODE_ESCAPE && lastKeyHit.hasFlags(0))) {
abortCutscene();
// VAR_CUTSCENEEXIT_KEY doesn't exist in SCUMM0
if (VAR_CUTSCENEEXIT_KEY != 0xFF)
_mouseAndKeyboardStat = VAR(VAR_CUTSCENEEXIT_KEY);
} else if (snapScrollKeyEnabled && !isUsingOriginalGUI() && lastKeyHit.keycode == Common::KEYCODE_r &&
lastKeyHit.hasFlags(Common::KBD_CTRL)) {
_snapScroll ^= 1;
if (_snapScroll) {
messageDialog(_("Snap scroll on"));
} else {
messageDialog(_("Snap scroll off"));
}
if (VAR_CAMERA_FAST_X != 0xFF)
VAR(VAR_CAMERA_FAST_X) = _snapScroll;
} else if (optionKeysEnabled && (lastKeyHit.ascii == '[' || lastKeyHit.ascii == ']')) { // Change music volume
int vol = ConfMan.getInt("music_volume") / 16;
if (lastKeyHit.ascii == ']' && vol < 16)
vol++;
else if (lastKeyHit.ascii == '[' && vol > 0)
vol--;
// Display the music volume
ValueDisplayDialog dlg(_("Music volume: "), 0, 16, vol, ']', '[');
vol = runDialog(dlg);
vol *= 16;
if (vol > Audio::Mixer::kMaxMixerVolume)
vol = Audio::Mixer::kMaxMixerVolume;
ConfMan.setInt("music_volume", vol);
syncSoundSettings();
} else if (optionKeysEnabled && (lastKeyHit.ascii == '-' || lastKeyHit.ascii == '+')) { // Change text speed
if (lastKeyHit.ascii == '-' && _defaultTextSpeed > 0)
_defaultTextSpeed--;
else if (lastKeyHit.ascii == '+' && _defaultTextSpeed < 9)
_defaultTextSpeed++;
// Display the talk speed
ValueDisplayDialog dlg(_("Subtitle speed: "), 0, 9, _defaultTextSpeed, '+', '-');
_defaultTextSpeed = runDialog(dlg);
// Save the new talkspeed value to ConfMan
setTalkSpeed(_defaultTextSpeed);
if (VAR_CHARINC != 0xFF)
VAR(VAR_CHARINC) = 9 - _defaultTextSpeed;
} else if (canToggleSmoothing && (lastKeyHit.keycode == Common::KEYCODE_g && lastKeyHit.hasFlags(Common::KBD_ALT))) {
mac_toggleSmoothing();
} else {
if (lastKeyHit.keycode >= Common::KEYCODE_F1 &&
lastKeyHit.keycode <= Common::KEYCODE_F9) {
_mouseAndKeyboardStat = lastKeyHit.keycode - Common::KEYCODE_F1 + 315;
} else if (lastKeyHit.flags & Common::KBD_CTRL && _game.version >= 3 && _game.version <= 7 &&
(lastKeyHit.keycode >= Common::KEYCODE_a && lastKeyHit.keycode <= Common::KEYCODE_z)) {
// Some games (at least their DOS variants)
// expect Ctrl+A, B, C, etc. to generate codes 1, 2, 3, etc.
//
// This is used for several settings in the "ultimate talkie" versions of
// Monkey Island 1 and 2. Monkey Island 1 also uses it for Ctrl+W to immediately
// win the game. On other games, Ctrl+I shows the inventory, Ctrl+V shows version
// information. On The Dig Ctrl+B makes Boston display his muscles.
_mouseAndKeyboardStat = lastKeyHit.keycode & 0x1f;
} else if (_game.id == GID_MONKEY2 && (lastKeyHit.flags & Common::KBD_ALT)) {
// Handle KBD_ALT combos in MI2. We know that the result must be 273 for Alt-W
// because that's what MI2 looks for in its "instant win" cheat.
_mouseAndKeyboardStat = lastKeyHit.keycode + 154;
} else if (lastKeyHit.keycode >= Common::KEYCODE_UP && lastKeyHit.keycode <= Common::KEYCODE_LEFT) {
if (isSegaCD) {
// Map arrow keys to number keys in the SEGA version of MI to support
// scrolling to conversation choices. See bug report #2013 for details.
_mouseAndKeyboardStat = lastKeyHit.keycode - Common::KEYCODE_UP + 54;
// Left and right are swapped
if (lastKeyHit.keycode == Common::KEYCODE_LEFT || lastKeyHit.keycode == Common::KEYCODE_RIGHT) {
_mouseAndKeyboardStat += lastKeyHit.keycode == Common::KEYCODE_LEFT ? -1 : 1;
}
} else if (isUsingOriginalGUI() || (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine)) {
// Map arrow keys to number keys in games which use the original menu screen.
switch (lastKeyHit.keycode) {
case Common::KEYCODE_UP:
_mouseAndKeyboardStat = 328;
break;
case Common::KEYCODE_DOWN:
_mouseAndKeyboardStat = 336;
break;
case Common::KEYCODE_LEFT:
_mouseAndKeyboardStat = 331;
break;
case Common::KEYCODE_RIGHT:
_mouseAndKeyboardStat = 333;
break;
default:
break;
}
} else if (_game.version >= 7) {
// Don't let pre-V7 game see arrow keys. This fixes bug with up arrow (273)
// corresponding to the "instant win" cheat in MI2 mentioned above.
//
// This is not applicable to V7+ games, which need to see the arrow keys,
// too, else certain things (derby scene, asterorid lander) won't work.
_mouseAndKeyboardStat = lastKeyHit.ascii;
}
} else if (isSegaCD && lastKeyHit.keycode >= Common::KEYCODE_KP0 && lastKeyHit.keycode <= Common::KEYCODE_KP9) {
switch (lastKeyHit.keycode) {
case Common::KEYCODE_KP8: // Up:
_mouseAndKeyboardStat = 54;
break;
case Common::KEYCODE_KP2: // Down:
_mouseAndKeyboardStat = 55;
break;
case Common::KEYCODE_KP4: // Left (swapped):
_mouseAndKeyboardStat = 56;
break;
case Common::KEYCODE_KP6: // Right (swapped):
_mouseAndKeyboardStat = 57;
break;
default:
break;
}
} else {
// Map the DEL key when using the original GUI; used when writing the savegame name.
if (isUsingOriginalGUI() && lastKeyHit.keycode == Common::KEYCODE_DELETE)
_mouseAndKeyboardStat = 339;
else
_mouseAndKeyboardStat = lastKeyHit.ascii;
}
}
// The original interpreters allowed the usage of the Enter key as a substitute for left mouse click,
// and the Tab key as a substitute for right click; while v7-8 games handle this substitution via
// scripts, we have to do this manually for the other games. We don't want to do this for (later)
// HE games, since they can sometimes have scripts that accept Enter and Tab keys.
if (_game.heversion < 71) {
if (_mouseAndKeyboardStat == Common::KEYCODE_RETURN && (_cursor.state > 0 || isSegaCD) && _game.version <= 6) {
_mouseAndKeyboardStat = MBS_LEFT_CLICK;
} else if (_mouseAndKeyboardStat == Common::KEYCODE_TAB && (_cursor.state > 0 || isSegaCD) && _game.version >= 4 && _game.version <= 6) {
_mouseAndKeyboardStat = MBS_RIGHT_CLICK;
}
}
}
} // End of namespace Scumm
|