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
|
/* 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 "sherlock/tattoo/tattoo_user_interface.h"
#include "sherlock/tattoo/tattoo_fixed_text.h"
#include "sherlock/tattoo/tattoo_journal.h"
#include "sherlock/tattoo/tattoo_scene.h"
#include "sherlock/tattoo/tattoo.h"
namespace Sherlock {
namespace Tattoo {
bool WidgetList::contains(const WidgetBase *item) const {
for (const_iterator i = begin(); i != end(); ++i) {
if ((*i) == item)
return true;
}
return false;
}
/*-------------------------------------------------------------------------*/
TattooUserInterface::TattooUserInterface(SherlockEngine *vm): UserInterface(vm),
_inventoryWidget(vm), _messageWidget(vm), _textWidget(vm), _tooltipWidget(vm),
_verbsWidget(vm), _creditsWidget(vm), _optionsWidget(vm), _quitWidget(vm) {
Common::fill(&_lookupTable[0], &_lookupTable[PALETTE_COUNT], 0);
Common::fill(&_lookupTable1[0], &_lookupTable1[PALETTE_COUNT], 0);
_scrollSize = 0;
_scrollSpeed = 16;
_drawMenu = false;
_bgShape = nullptr;
_personFound = false;
_lockoutTimer = 0;
_exitZone = -1;
_scriptZone = -1;
_arrowZone = _oldArrowZone = -1;
_activeObj = -1;
_cAnimFramePause = 0;
_scrollHighlight = SH_NONE;
_mask = _mask1 = nullptr;
_maskCounter = 0;
_interfaceImages = new ImageFile("intrface.vgs");
}
TattooUserInterface::~TattooUserInterface() {
delete _interfaceImages;
delete _mask;
delete _mask1;
}
void TattooUserInterface::initScrollVars() {
Screen &screen = *_vm->_screen;
_scrollSize = screen._backBuffer1.width() - SHERLOCK_SCREEN_WIDTH;
_targetScroll = Common::Point(0, 0);
screen._currentScroll = Common::Point(0, 0);
}
void TattooUserInterface::lookAtObject() {
Events &events = *_vm->_events;
People &people = *_vm->_people;
Scene &scene = *_vm->_scene;
Sound &sound = *_vm->_sound;
Talk &talk = *_vm->_talk;
Common::Point mousePos = events.mousePos();
Common::String desc;
_lookPos = mousePos;
_menuMode = LOOK_MODE;
if (_personFound) {
desc = people[_bgFound - 1000]._examine;
} else {
// Check if there is a Look animation
if (_bgShape->_lookcAnim != 0) {
//int cAnimSpeed = _bgShape->_lookcAnim & 0xe0;
//cAnimSpeed >>= 5;
//++cAnimSpeed;
_cAnimFramePause = _bgShape->_lookFrames;
desc = _bgShape->_examine;
int cNum = (_bgShape->_lookcAnim & 0x1f) - 1;
scene.startCAnim(cNum);
} else if (_bgShape->_lookPosition.y != 0) {
// Need to walk to object before looking at it
people[HOLMES].walkToCoords(_bgShape->_lookPosition, _bgShape->_lookPosition._facing);
}
if (!talk._talkToAbort) {
desc = _bgShape->_examine;
if (_bgShape->_lookFlag)
_vm->setFlags(_bgShape->_lookFlag);
// Find the Sound File to Play if there is one
if (!desc.hasPrefix("_")) {
for (uint idx = 0; idx < scene._objSoundList.size(); ++idx) {
// Get the object name up to the equals
const char *p = strchr(scene._objSoundList[idx].c_str(), '=');
// Form the name and remove any trailing spaces
Common::String name(scene._objSoundList[idx].c_str(), p);
while (name.hasSuffix(" "))
name.deleteLastChar();
// See if this Object Sound List entry matches the object's name
if (!_bgShape->_name.compareToIgnoreCase(name)) {
// Move forward to get the sound filename
while ((*p == ' ') || (*p == '='))
++p;
// If it's not "NONE", play the speech File
Common::String soundName(p);
if (soundName.compareToIgnoreCase("NONE")) {
soundName.toLowercase();
if (!soundName.contains('.'))
soundName += ".wav";
sound.playSound(Common::Path(soundName), WAIT_RETURN_IMMEDIATELY);
}
break;
}
}
}
}
}
// Only show the desciption if the object has one, and if no talk file interrupted while walking to it
if (!talk._talkToAbort && !desc.empty()) {
if (_cAnimFramePause == 0)
printObjectDesc(desc, true);
else
// The description was already printed by an animation
_cAnimFramePause = 0;
} else if (desc.empty()) {
// There was no description to display, so reset back to STD_MODE
_menuMode = STD_MODE;
}
}
void TattooUserInterface::printObjectDesc(const Common::String &str, bool firstTime) {
Events &events = *_vm->_events;
TattooScene &scene = *(TattooScene *)_vm->_scene;
Talk &talk = *_vm->_talk;
if (str.hasPrefix("_")) {
// The passed string specifies a talk file
_lookScriptFlag = true;
events.setCursor(MAGNIFY);
int savedSelector = _selector;
if (!_invLookFlag)
_windowOpen = false;
talk.talkTo(str.c_str() + 1);
_lookScriptFlag = false;
if (talk._talkToAbort) {
events.setCursor(ARROW);
return;
}
// See if we're looking at an inventory item
if (_invLookFlag) {
_selector = _oldSelector = savedSelector;
doInventory(0);
_invLookFlag = false;
} else {
// Nope
events.setCursor(ARROW);
_key = -1;
_menuMode = scene._labTableScene ? LAB_MODE : STD_MODE;
events._pressed = events._released = events._rightReleased = false;
events._oldButtons = 0;
}
} else {
events._pressed = events._released = events._rightReleased = false;
// Show text dialog
_textWidget.load(str);
_textWidget.summonWindow();
if (firstTime)
_selector = _oldSelector = -1;
_drawMenu = _windowOpen = true;
}
}
void TattooUserInterface::doJournal() {
TattooJournal &journal = *(TattooJournal *)_vm->_journal;
TattooScene &scene = *(TattooScene *)_vm->_scene;
Screen &screen = *_vm->_screen;
byte lookupTable[PALETTE_COUNT], lookupTable1[PALETTE_COUNT];
Common::copy(&_lookupTable[0], &_lookupTable[PALETTE_COUNT], &lookupTable[0]);
Common::copy(&_lookupTable1[0], &_lookupTable1[PALETTE_COUNT], &lookupTable1[0]);
_menuMode = JOURNAL_MODE;
journal.show();
_menuMode = STD_MODE;
_windowOpen = false;
_key = -1;
// Restore the old screen palette and greyscale lookup table
screen.clear();
screen.setPalette(screen._cMap);
Common::copy(&lookupTable[0], &lookupTable[PALETTE_COUNT], &_lookupTable[0]);
Common::copy(&lookupTable1[0], &lookupTable1[PALETTE_COUNT], &_lookupTable1[0]);
// Restore the scene
screen._backBuffer1.SHblitFrom(screen._backBuffer2);
scene.updateBackground();
screen.slamArea(screen._currentScroll.x, screen._currentScroll.y, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT);
}
void TattooUserInterface::reset() {
UserInterface::reset();
_lookPos = Common::Point(SHERLOCK_SCREEN_WIDTH / 2, SHERLOCK_SCREEN_HEIGHT / 2);
_tooltipWidget.setText("");
_widgets.clear();
_fixedWidgets.clear();
}
void TattooUserInterface::handleInput() {
TattooEngine &vm = *(TattooEngine *)_vm;
Events &events = *_vm->_events;
TattooScene &scene = *(TattooScene *)_vm->_scene;
Common::Point mousePos = events.mousePos();
_keyState.keycode = Common::KEYCODE_INVALID;
// Check for credits starting
if (_vm->readFlags(3000) && !_creditsWidget.active())
_creditsWidget.initCredits();
// Check the mouse positioning
if (events.isCursorVisible())
_bgFound = scene.findBgShape(mousePos);
_personFound = _bgFound >= 1000;
_bgShape = (_bgFound != -1 && _bgFound < 1000) ? &scene._bgShapes[_bgFound] : nullptr;
if (_lockoutTimer)
--_lockoutTimer;
// Key handling
if (events.kbHit()) {
_keyState = events.getKey();
if (_keyState.keycode == Common::KEYCODE_ESCAPE && vm._runningProlog && !_lockoutTimer) {
vm.setFlags(-76);
vm.setFlags(396);
scene._goToScene = STARTING_GAME_SCENE;
} else if (_menuMode == STD_MODE) {
if (_keyState.keycode == Common::KEYCODE_s && vm._allowFastMode) {
events.toggleSpeed();
} else if (_keyState.keycode == Common::KEYCODE_l && _bgFound != -1) {
// Beging used for testing that Look dialogs work
lookAtObject();
}
}
}
if (!events.isCursorVisible())
_keyState.keycode = Common::KEYCODE_INVALID;
// If there's any active widgets/windows, let the most recently open one do event processing
if (!_widgets.empty())
_widgets.back()->handleEvents();
else if (!_fixedWidgets.empty())
_fixedWidgets.back()->handleEvents();
// Handle input depending on what mode we're in
switch (_menuMode) {
case STD_MODE:
doStandardControl();
break;
case LOOK_MODE:
doLookControl();
break;
default:
break;
}
}
void TattooUserInterface::drawInterface(int bufferNum) {
Screen &screen = *_vm->_screen;
// Draw any active on-screen widgets
for (Common::List<WidgetBase *>::iterator i = _fixedWidgets.begin(); i != _fixedWidgets.end(); ++i)
(*i)->draw();
for (Common::List<WidgetBase *>::iterator i = _widgets.begin(); i != _widgets.end(); ++i)
(*i)->draw();
// Handle drawing credits
// TODO: See if credits are only shown on a single screen. If so, _fixedWidgets could be used
if (_creditsWidget.active())
_creditsWidget.drawCredits();
// Bring the widgets to the screen
if (_mask != nullptr)
screen._flushScreen = true;
}
void TattooUserInterface::doBgAnimRestoreUI() {
TattooScene &scene = *((TattooScene *)_vm->_scene);
Screen &screen = *_vm->_screen;
// If there are any on-screen widgets, then erase them
for (Common::List<WidgetBase *>::iterator i = _widgets.begin(); i != _widgets.end(); ++i)
(*i)->erase();
for (Common::List<WidgetBase *>::iterator i = _fixedWidgets.begin(); i != _fixedWidgets.end(); ++i)
(*i)->erase();
// If there is a Text Tag being display, restore the area underneath it
_tooltipWidget.erase();
// If a canimation is active, restore the graphics underneath it
if (scene._activeCAnim.active())
screen.restoreBackground(scene._activeCAnim._oldBounds);
// If a canimation just ended, remove its graphics from the backbuffer
if (scene._activeCAnim._removeBounds.width() > 0)
screen.restoreBackground(scene._activeCAnim._removeBounds);
}
void TattooUserInterface::doScroll() {
Screen &screen = *_vm->_screen;
// If we're already at the target scroll position, nothing needs to be done
if (_targetScroll.x == screen._currentScroll.x)
return;
screen._flushScreen = true;
if (_targetScroll.x > screen._currentScroll.x) {
screen._currentScroll.x += _scrollSpeed;
if (screen._currentScroll.x > _targetScroll.x)
screen._currentScroll.x = _targetScroll.x;
} else if (_targetScroll.x < screen._currentScroll.x) {
screen._currentScroll.x -= _scrollSpeed;
if (screen._currentScroll.x < _targetScroll.x)
screen._currentScroll.x = _targetScroll.x;
}
// Reset the default look position to the center of the new screen area
_lookPos = screen._currentScroll + Common::Point(SHERLOCK_SCREEN_WIDTH / 2, SHERLOCK_SCREEN_HEIGHT / 2);
}
void TattooUserInterface::doStandardControl() {
TattooEngine &vm = *(TattooEngine *)_vm;
Events &events = *_vm->_events;
People &people = *_vm->_people;
SaveManager &saves = *_vm->_saves;
TattooScene &scene = *(TattooScene *)_vm->_scene;
Talk &talk = *_vm->_talk;
Common::Point mousePos = events.mousePos();
// Don't do any input processing whilst the prolog is running
// or the cursor is hidden (e.g. by a call to cmdMouseOnOff())
if (vm._runningProlog || !events.isCursorVisible())
return;
// When the end credits are active, any press will open the ScummVM global main menu
if (_creditsWidget.active()) {
if (_keyState.keycode || events._released || events._rightReleased) {
vm._canLoadSave = true;
vm.openMainMenuDialog();
vm._canLoadSave = false;
}
return;
}
// Display the names of any Objects the cursor is pointing at
displayObjectNames();
switch (_keyState.keycode) {
case Common::KEYCODE_F5:
// Save game
events.warpMouse();
saveGame();
return;
case Common::KEYCODE_F7:
// Load game
events.warpMouse();
loadGame();
return;
case Common::KEYCODE_F1:
// Display journal
if (vm.readFlags(FLAG_PLAYER_IS_HOLMES)) {
freeMenu();
doJournal();
// See if we're in a Lab Table Room
_menuMode = (scene._labTableScene) ? LAB_MODE : STD_MODE;
return;
}
break;
case Common::KEYCODE_TAB:
case Common::KEYCODE_F3:
// Display inventory
freeMenu();
doInventory(3);
return;
case Common::KEYCODE_F4:
// Display options
events.warpMouse();
_optionsWidget.load();
return;
case Common::KEYCODE_F10:
// Quit menu
freeMenu();
events.warpMouse();
doQuitMenu();
return;
default:
break;
}
// See if a mouse button was released
if (events._released || events._rightReleased) {
// See if the mouse was released in an exit (Arrow) zone. Unless it's also pointing at an object
// within the zone, in which case the object gets precedence
_exitZone = -1;
if (_arrowZone != -1 && events._released)
_exitZone = _arrowZone;
// Turn any Text display off
if (_arrowZone == -1 || events._rightReleased)
freeMenu();
bool noDesc = false;
if (_personFound) {
if (people[_bgFound - 1000]._description.empty() || people[_bgFound - 1000]._description.hasPrefix(" "))
noDesc = true;
} else if (_bgFound != -1) {
if (_bgShape->_description.empty() || _bgShape->_description.hasPrefix(" "))
noDesc = true;
} else {
noDesc = true;
}
if (events._rightReleased) {
// Show the verbs menu for the highlighted object
_tooltipWidget.banishWindow();
saves.createThumbnail();
_verbsWidget.load(!noDesc);
_verbsWidget.summonWindow();
_selector = _oldSelector = -1;
_activeObj = _bgFound;
_menuMode = VERB_MODE;
} else if (_personFound || (_bgFound != -1 && _bgFound < 1000 && _bgShape->_aType == PERSON)) {
// The object found is a person (the default for people is TALK)
talk.initTalk(_bgFound);
_activeObj = -1;
} else if (!noDesc) {
// Either call the code to Look at its Examine Field or call the Exit animation
// if the object is an exit, specified by the first four characters of the name being "EXIT"
Common::String name = _personFound ? people[_bgFound - 1000]._name : _bgShape->_name;
if (!name.hasPrefix("EXIT")) {
lookAtObject();
} else {
// Run the Exit animation and set which scene to go to next
for (int idx = 0; idx < 6; ++idx) {
if (!_bgShape->_use[idx]._verb.compareToIgnoreCase("Open")) {
checkAction(_bgShape->_use[idx], _bgFound);
_activeObj = -1;
}
}
}
} else {
// See if there are any Script Zones where they clicked
if (scene.checkForZones(mousePos, _scriptZone) != 0) {
// Mouse click in a script zone
events._pressed = events._released = false;
} else if (scene.checkForZones(mousePos, NOWALK_ZONE) != 0) {
events._pressed = events._released = false;
} else {
// Walk to where the mouse was clicked
people[HOLMES]._walkDest = mousePos;
people[HOLMES].goAllTheWay();
}
}
}
}
void TattooUserInterface::doLookControl() {
Events &events = *_vm->_events;
TattooScene &scene = *(TattooScene *)_vm->_scene;
// See if a mouse button was released or a key pressed to close the active look dialog
if (events._released || events._rightReleased || _keyState.keycode) {
// See if we were looking at an inventory object
if (!_invLookFlag) {
// See if there is any more text to display
if (!_textWidget._remainingText.empty()) {
printObjectDesc(_textWidget._remainingText, false);
} else {
// Otherwise restore the background and go back into STD_MODE
freeMenu();
_key = -1;
_menuMode = scene._labTableScene ? LAB_MODE : STD_MODE;
events.setCursor(ARROW);
events._pressed = events._released = events._rightReleased = false;
events._oldButtons = 0;
}
} else {
// We were looking at a Inventory object
// Erase the text window, and then redraw the inventory window
_textWidget.banishWindow();
doInventory(0);
_invLookFlag = false;
_key = -1;
events.setCursor(ARROW);
events._pressed = events._released = events._rightReleased = false;
events._oldButtons = 0;
}
}
}
void TattooUserInterface::displayObjectNames() {
Events &events = *_vm->_events;
Scene &scene = *_vm->_scene;
Common::Point mousePos = events.mousePos();
_arrowZone = -1;
if (_bgFound == -1 || scene._currentScene == OVERHEAD_MAP2) {
for (uint idx = 0; idx < scene._exits.size() && _arrowZone == -1; ++idx) {
Exit &exit = scene._exits[idx];
if (exit.contains(mousePos))
_arrowZone = idx;
}
}
_tooltipWidget.handleEvents();
_oldArrowZone = _arrowZone;
}
void TattooUserInterface::doInventory(int mode) {
People &people = *_vm->_people;
people[HOLMES].gotoStand();
_inventoryWidget.load(mode);
_inventoryWidget.summonWindow();
_menuMode = INV_MODE;
}
void TattooUserInterface::doControls() {
_optionsWidget.load();
}
void TattooUserInterface::pickUpObject(int objNum) {
Inventory &inv = *_vm->_inventory;
Scene &scene = *_vm->_scene;
Talk &talk = *_vm->_talk;
Object &obj = scene._bgShapes[objNum];
bool printed = false;
int verbField = -1;
// Find which Verb field to use for pick up data
for (int idx = 0; idx < 6; ++idx) {
if (!scumm_stricmp(obj._use[idx]._target.c_str(), "*PICKUP"))
verbField = idx;
}
if (verbField != -1) {
if (obj._use[verbField]._cAnimNum)
scene.startCAnim(obj._use[verbField]._cAnimNum - 1);
}
if (!talk._talkToAbort) {
if (obj._type == NO_SHAPE)
obj._type = INVALID;
else
// Erase shape
obj._type = REMOVE;
} else {
return;
}
if (verbField != -1) {
for (int idx = 0; idx < 4 && !talk._talkToAbort; ++idx) {
if (obj.checkNameForCodes(obj._use[verbField]._names[idx])) {
if (!talk._talkToAbort)
printed = true;
}
}
}
if (talk._talkToAbort)
return;
// Add the item to the player's inventory
inv.putItemInInventory(obj);
if (!printed) {
Common::String desc = obj._description;
desc.setChar(tolower(desc[0]), 0);
putMessage("%s %s", FIXED(PickedUp), desc.c_str());
}
if (_menuMode != TALK_MODE && _menuMode != MESSAGE_MODE) {
_menuMode = STD_MODE;
_keyState.keycode = Common::KEYCODE_INVALID;
}
}
void TattooUserInterface::doQuitMenu() {
_quitWidget.show();
}
void TattooUserInterface::putMessage(const char *formatStr, ...) {
// Create the string to display
va_list args;
va_start(args, formatStr);
Common::String str = Common::String::vformat(formatStr, args);
va_end(args);
// Open the message widget
_menuMode = MESSAGE_MODE;
_messageWidget.load(str, 25);
_messageWidget.summonWindow();
}
void TattooUserInterface::setupBGArea(const byte cMap[PALETTE_SIZE]) {
Scene &scene = *_vm->_scene;
// This requires that there is a 16 grayscale palette sequence in the palette that goes from lighter
// to darker as the palette numbers go up. The last palette entry in that run is specified by _bgColor
byte *p = &_lookupTable[0];
for (int idx = 0; idx < PALETTE_COUNT; ++idx)
*p++ = BG_GREYSCALE_RANGE_END - (cMap[idx * 3] * 30 + cMap[idx * 3 + 1] * 59 + cMap[idx * 3 + 2] * 11) / 480;
// If we're going to a scene with a haze special effect, initialize the translate table to lighten the colors
if (_mask != nullptr) {
p = &_lookupTable1[0];
for (int idx = 0; idx < PALETTE_COUNT; ++idx) {
int r, g, b;
switch (scene._currentScene) {
case 8:
r = cMap[idx * 3] * 4 / 5;
g = cMap[idx * 3 + 1] * 3 / 4;
b = cMap[idx * 3 + 2] * 3 / 4;
break;
case 18:
case 68:
r = cMap[idx * 3] * 4 / 3;
g = cMap[idx * 3 + 1] * 4 / 3;
b = cMap[idx * 3 + 2] * 4 / 3;
break;
case 7:
case 53:
r = cMap[idx * 3] * 4 / 3;
g = cMap[idx * 3 + 1] * 4 / 3;
b = cMap[idx * 3 + 2] * 4 / 3;
break;
default:
r = g = b = 0;
break;
}
byte c = 0xff;
int cd = 99999;
for (int pal = 0; pal < PALETTE_COUNT; ++pal) {
int d = (r - cMap[pal * 3]) * (r - cMap[pal * 3]) + (g - cMap[pal * 3 + 1]) * (g - cMap[pal * 3 + 1]) +
(b - cMap[pal * 3 + 2]) * (b - cMap[pal * 3 + 2]);
if (d < cd) {
c = pal;
cd = d;
if (!d)
break;
}
}
*p++ = c;
}
}
}
void TattooUserInterface::doBgAnimEraseBackground() {
People &people = *_vm->_people;
Scene &scene = *_vm->_scene;
Screen &screen = *_vm->_screen;
static const int16 OFFSETS[16] = { -1, -2, -3, -3, -2, -1, -1, 0, 1, 2, 3, 3, 2, 1, 0, 0 };
if (_mask != nullptr) {
// Since a mask is active, restore the screen from the secondary back buffer prior to applying the mask
screen._backBuffer1.SHblitFrom(screen._backBuffer2, screen._currentScroll, Common::Rect(screen._currentScroll.x, 0,
screen._currentScroll.x + SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT));
switch (scene._currentScene) {
case 7:
if (++_maskCounter == 2) {
_maskCounter = 0;
if (--_maskOffset.x < 0)
_maskOffset.x = SHERLOCK_SCREEN_WIDTH - 1;
}
break;
case 8:
_maskOffset.x += 2;
if (_maskOffset.x >= SHERLOCK_SCREEN_WIDTH)
_maskOffset.x = 0;
break;
case 18:
case 68:
++_maskCounter;
if (_maskCounter / 4 >= 16)
_maskCounter = 0;
_maskOffset.x = OFFSETS[_maskCounter / 4];
break;
case 53:
if (++_maskCounter == 2) {
_maskCounter = 0;
if (++_maskOffset.x == screen._backBuffer1.width())
_maskOffset.x = 0;
}
break;
default:
break;
}
} else {
// Standard scene without mask, so call user interface to erase any UI elements as necessary
doBgAnimRestoreUI();
// Restore background for any areas covered by characters and shapes
for (int idx = 0; idx < MAX_CHARACTERS; ++idx)
screen.restoreBackground(Common::Rect(people[idx]._oldPosition.x, people[idx]._oldPosition.y,
people[idx]._oldPosition.x + people[idx]._oldSize.x, people[idx]._oldPosition.y + people[idx]._oldSize.y));
for (uint idx = 0; idx < scene._bgShapes.size(); ++idx) {
Object &obj = scene._bgShapes[idx];
if ((obj._type == ACTIVE_BG_SHAPE && (obj._maxFrames > 1 || obj._delta.x != 0 || obj._delta.y != 0)) ||
obj._type == HIDE_SHAPE || obj._type == REMOVE)
screen._backBuffer1.SHblitFrom(screen._backBuffer2, obj._oldPosition,
Common::Rect(obj._oldPosition.x, obj._oldPosition.y, obj._oldPosition.x + obj._oldSize.x,
obj._oldPosition.y + obj._oldSize.y));
}
// If credits are active, erase the area they cover
if (_creditsWidget.active())
_creditsWidget.eraseCredits();
}
for (uint idx = 0; idx < scene._bgShapes.size(); ++idx) {
Object &obj = scene._bgShapes[idx];
if (obj._type == NO_SHAPE && (obj._flags & 1) == 0) {
screen._backBuffer1.SHblitFrom(screen._backBuffer2, obj._position, obj.getNoShapeBounds());
obj._oldPosition = obj._position;
obj._oldSize = obj._noShapeSize;
}
}
// Adjust the Target Scroll if needed
if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - screen._currentScroll.x) <
(SHERLOCK_SCREEN_WIDTH / 8) && people[people._walkControl]._delta.x < 0) {
_targetScroll.x = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER -
SHERLOCK_SCREEN_WIDTH / 8 - 250);
if (_targetScroll.x < 0)
_targetScroll.x = 0;
}
if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - screen._currentScroll.x) >
(SHERLOCK_SCREEN_WIDTH / 4 * 3) && people[people._walkControl]._delta.x > 0)
_targetScroll.x = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER -
SHERLOCK_SCREEN_WIDTH / 4 * 3 + 250);
if (_targetScroll.x > _scrollSize)
_targetScroll.x = _scrollSize;
doScroll();
}
void TattooUserInterface::drawMaskArea(bool mode) {
Scene &scene = *_vm->_scene;
int xp = mode ? _maskOffset.x : 0;
if (_mask != nullptr) {
switch (scene._currentScene) {
case 7:
maskArea(*_mask, Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110));
maskArea(*_mask, Common::Point(_maskOffset.x, 110));
maskArea(*_mask, Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 110));
break;
case 8:
maskArea(*_mask, Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 180));
maskArea(*_mask, Common::Point(_maskOffset.x, 180));
maskArea(*_mask, Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 180));
if (!_vm->readFlags(880))
maskArea(*_mask1, Common::Point(940, 300));
break;
case 18:
maskArea(*_mask, Common::Point(xp, 203));
if (!_vm->readFlags(189))
maskArea(*_mask1, Common::Point(124 + xp, 239));
break;
case 53:
maskArea(*_mask, Common::Point(_maskOffset.x, 110));
if (mode)
maskArea(*_mask, Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110));
break;
case 68:
maskArea(*_mask, Common::Point(xp, 203));
maskArea(*_mask1, Common::Point(124 + xp, 239));
break;
default:
break;
}
}
}
void TattooUserInterface::maskArea(Common::SeekableReadStream &mask, const Common::Point &pt) {
Screen &screen = *_vm->_screen;
Surface &bb1 = screen._backBuffer1;
mask.seek(0);
int xSize = mask.readUint16LE();
int ySize = mask.readUint16LE();
int pixel, len, xp, yp;
for (yp = 0; yp < ySize; ++yp) {
byte *ptr = (byte *)bb1.getBasePtr(pt.x, pt.y + yp);
for (xp = 0; xp < xSize;) {
// The mask data consists of pairs of pixel/lengths, where all non-zero pixels means that the
// given pixel on the back buffer is darkened (the mask pixel value isn't otherwise used)
pixel = mask.readByte();
len = mask.readByte();
for (; len > 0; --len, ++xp, ++ptr) {
if (pixel && (pt.x + xp) >= screen._currentScroll.x && (pt.x + xp) < (screen._currentScroll.x + SHERLOCK_SCREEN_WIDTH)) {
*ptr = _lookupTable1[*ptr];
}
}
}
assert(xp == xSize);
}
}
void TattooUserInterface::makeBGArea(const Common::Rect &r) {
Screen &screen = *_vm->_screen;
for (int yp = r.top; yp < r.bottom; ++yp) {
byte *ptr = (byte *)screen._backBuffer1.getBasePtr(r.left, yp);
for (int xp = r.left; xp < r.right; ++xp, ++ptr)
*ptr = _lookupTable[*ptr];
}
screen.slamRect(r);
}
void TattooUserInterface::drawDialogRect(Surface &s, const Common::Rect &r, bool raised) {
if (raised) {
// Draw Left
s.vLine(r.left, r.top, r.bottom - 1, INFO_TOP);
s.vLine(r.left + 1, r.top, r.bottom - 2, INFO_TOP);
// Draw Top
s.hLine(r.left + 2, r.top, r.right - 1, INFO_TOP);
s.hLine(r.left + 2, r.top + 1, r.right - 2, INFO_TOP);
// Draw Right
s.vLine(r.right - 1, r.top + 1, r.bottom - 1, INFO_BOTTOM);
s.vLine(r.right - 2, r.top + 2, r.bottom - 1, INFO_BOTTOM);
// Draw Bottom
s.hLine(r.left + 1, r.bottom - 1, r.right - 3, INFO_BOTTOM);
s.hLine(r.left + 2, r.bottom - 2, r.right - 3, INFO_BOTTOM);
} else {
// Draw Left
s.vLine(r.left, r.top, r.bottom - 1, INFO_BOTTOM);
s.vLine(r.left + 1, r.top, r.bottom - 2, INFO_BOTTOM);
// Draw Top
s.hLine(r.left + 2, r.top, r.right - 1, INFO_BOTTOM);
s.hLine(r.left + 2, r.top + 1, r.right - 2, INFO_BOTTOM);
// Draw Right
s.vLine(r.right - 1, r.top + 1, r.bottom - 1, INFO_TOP);
s.vLine(r.right - 2, r.top + 2, r.bottom - 1, INFO_TOP);
// Draw Bottom
s.hLine(r.left + 1, r.bottom - 1, r.right - 3, INFO_TOP);
s.hLine(r.left + 2, r.bottom - 2, r.right - 3, INFO_TOP);
}
}
void TattooUserInterface::banishWindow(bool slideUp) {
if (!_widgets.empty())
_widgets.back()->banishWindow();
}
void TattooUserInterface::freeMenu() {
for (Common::List<WidgetBase *>::iterator i = _widgets.begin(); i != _widgets.end(); ++i)
(*i)->erase();
_widgets.clear();
}
void TattooUserInterface::clearWindow() {
banishWindow();
}
void TattooUserInterface::loadGame() {
WidgetFiles &files = *(WidgetFiles *)_vm->_saves;
files.show(SAVEMODE_LOAD);
}
void TattooUserInterface::saveGame() {
WidgetFiles &files = *(WidgetFiles *)_vm->_saves;
files.show(SAVEMODE_SAVE);
}
void TattooUserInterface::addFixedWidget(WidgetBase *widget) {
_fixedWidgets.push_back(widget);
widget->summonWindow();
}
} // End of namespace Tattoo
} // End of namespace Sherlock
|