SHERLOCK: RT: Implement lookatObject and printObjectDesc

This commit is contained in:
Paul Gilbert 2015-06-17 18:54:39 -04:00
parent 3bde2238cd
commit ed6c10e022
14 changed files with 263 additions and 16 deletions

View File

@ -22,6 +22,7 @@ MODULE_OBJS = \
tattoo/tattoo_talk.o \
tattoo/tattoo_user_interface.o \
tattoo/widget_base.o \
tattoo/widget_text.o \
tattoo/widget_tooltip.o \
tattoo/widget_verbs.o \
animation.o \

View File

@ -23,6 +23,7 @@
#include "sherlock/scalpel/scalpel_scene.h"
#include "sherlock/scalpel/scalpel_map.h"
#include "sherlock/scalpel/scalpel_people.h"
#include "sherlock/scalpel/scalpel_user_interface.h"
#include "sherlock/scalpel/scalpel.h"
#include "sherlock/events.h"
#include "sherlock/people.h"
@ -490,7 +491,7 @@ int ScalpelScene::startCAnim(int cAnimNum, int playRate) {
People &people = *_vm->_people;
Resources &res = *_vm->_res;
Talk &talk = *_vm->_talk;
UserInterface &ui = *_vm->_ui;
ScalpelUserInterface &ui = *(ScalpelUserInterface *)_vm->_ui;
Point32 tpPos, walkPos;
int tpDir, walkDir;
int tFrames = 0;

View File

@ -81,7 +81,7 @@ public:
* @param playRate Play rate. 0 is invalid; 1=normal speed, 2=1/2 speed, etc.
* A negative playRate can also be specified to play the animation in reverse
*/
virtual int startCAnim(int cAnimNum, int playRate);
virtual int startCAnim(int cAnimNum, int playRate = 1);
};
} // End of namespace Scalpel

View File

@ -323,7 +323,7 @@ public:
* @param playRate Play rate. 0 is invalid; 1=normal speed, 2=1/2 speed, etc.
* A negative playRate can also be specified to play the animation in reverse
*/
virtual int startCAnim(int cAnimNum, int playRate) = 0;
virtual int startCAnim(int cAnimNum, int playRate = 1) = 0;
};
} // End of namespace Sherlock

View File

@ -140,7 +140,7 @@ public:
* @param playRate Play rate. 0 is invalid; 1=normal speed, 2=1/2 speed, etc.
* A negative playRate can also be specified to play the animation in reverse
*/
virtual int startCAnim(int cAnimNum, int playRate);
virtual int startCAnim(int cAnimNum, int playRate = 1);
};
} // End of namespace Tattoo

View File

@ -29,7 +29,7 @@ namespace Sherlock {
namespace Tattoo {
TattooUserInterface::TattooUserInterface(SherlockEngine *vm): UserInterface(vm),
_tooltipWidget(vm), _verbsWidget(vm) {
_tooltipWidget(vm), _verbsWidget(vm), _textWidget(vm) {
_menuBuffer = nullptr;
_invMenuBuffer = nullptr;
_invGraphic = nullptr;
@ -44,6 +44,8 @@ TattooUserInterface::TattooUserInterface(SherlockEngine *vm): UserInterface(vm),
_scriptZone = -1;
_arrowZone = _oldArrowZone = -1;
_activeObj = -1;
_cAnimFramePause = 0;
_widget = nullptr;
}
void TattooUserInterface::initScrollVars() {
@ -53,7 +55,134 @@ void TattooUserInterface::initScrollVars() {
}
void TattooUserInterface::lookAtObject() {
// TODO
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;
int cAnimSpeed = 0;
if (_personFound) {
desc = people[_bgFound - 1000]._examine;
} else {
// Check if there is a Look animation
if (_bgShape->_lookcAnim != 0) {
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(Common::Point(_bgShape->_lookPosition.x * FIXED_INT_MULTIPLIER,
_bgShape->_lookPosition.y * FIXED_INT_MULTIPLIER), _bgShape->_lookFacing);
}
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 Sound File
Common::String soundName(p);
if (soundName.compareToIgnoreCase("NONE")) {
soundName.toLowercase();
if (!soundName.contains('.'))
soundName += ".wav";
sound.playSound(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;
freeMenu();
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 {
// Show text dialog
_textWidget.load(str);
if (firstTime)
_selector = _oldSelector = -1;
_drawMenu = _windowOpen = true;
}
}
void TattooUserInterface::doJournal() {
@ -479,6 +608,13 @@ void TattooUserInterface::doQuitMenu() {
// TODO
}
void TattooUserInterface::freeMenu() {
if (_widget != nullptr) {
_widget->banishWindow();
_widget = nullptr;
}
}
} // End of namespace Tattoo
} // End of namespace Sherlock

View File

@ -26,6 +26,7 @@
#include "common/scummsys.h"
#include "sherlock/saveload.h"
#include "sherlock/user_interface.h"
#include "sherlock/tattoo/widget_text.h"
#include "sherlock/tattoo/widget_tooltip.h"
#include "sherlock/tattoo/widget_verbs.h"
@ -49,8 +50,11 @@ private:
SaveMode _fileMode;
int _exitZone;
int _scriptZone;
int _cAnimFramePause;
WidgetTooltip _tooltipWidget;
WidgetVerbs _verbsWidget;
WidgetText _textWidget;
WidgetBase *_widget;
private:
/**
* Draws designated areas of the screen that are meant to be grayed out using grayscale colors
@ -118,6 +122,11 @@ private:
* Handle displaying the quit menu
*/
void doQuitMenu();
/**
* Free any active menu
*/
void freeMenu();
public:
Common::Point _currentScroll, _targetScroll;
int _scrollSize, _scrollSpeed;
@ -130,6 +139,7 @@ public:
Common::KeyState _keyState;
public:
TattooUserInterface(SherlockEngine *vm);
virtual ~TattooUserInterface() {}
/**
* Handles restoring any areas of the back buffer that were/are covered by UI elements
@ -147,11 +157,17 @@ public:
void initScrollVars();
/**
* Display the long description for an object stored in it's _examine field, in a window that
* will be shown at the bottom of the screen
* Display the long description for an object in a window
*/
void lookAtObject();
/**
* Display the passed long description for an object. If the flag firstTime is set,
* the window will be opened to accomodate the text. Otherwise, the remaining text
* will be printed in an already open window
*/
void printObjectDesc(const Common::String &str, bool firstTime);
/**
* Handles displaying the journal
*/
@ -172,8 +188,6 @@ public:
*/
void pickUpObject(int objNum);
public:
virtual ~TattooUserInterface() {}
/**
* Main input handler for the user interface
*/

View File

@ -30,8 +30,13 @@ namespace Tattoo {
WidgetBase::WidgetBase(SherlockEngine *vm) : _vm(vm) {
}
void WidgetBase::summonWindow() {
}
void WidgetBase::banishWindow() {
// TODO
_surface.free();
}
} // End of namespace Tattoo

View File

@ -41,11 +41,17 @@ protected:
Surface _surface;
public:
WidgetBase(SherlockEngine *vm);
virtual ~WidgetBase() {}
/**
* Summon the window
*/
virtual void summonWindow();
/**
* Close a currently active menu
*/
void banishWindow();
virtual void banishWindow();
};
} // End of namespace Tattoo

View File

@ -0,0 +1,40 @@
/* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "sherlock/tattoo/widget_text.h"
#include "sherlock/tattoo/tattoo_user_interface.h"
#include "sherlock/tattoo/tattoo.h"
namespace Sherlock {
namespace Tattoo {
WidgetText::WidgetText(SherlockEngine *vm) : WidgetBase(vm) {
}
void WidgetText::load(const Common::String &str) {
// TODO
}
} // End of namespace Tattoo
} // End of namespace Sherlock

View File

@ -0,0 +1,47 @@
/* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef SHERLOCK_TATTOO_WIDGET_TEXT_H
#define SHERLOCK_TATTOO_WIDGET_TEXT_H
#include "common/scummsys.h"
#include "sherlock/tattoo/widget_base.h"
namespace Sherlock {
class SherlockEngine;
namespace Tattoo {
class WidgetText: public WidgetBase {
public:
WidgetText(SherlockEngine *vm);
virtual ~WidgetText() {}
void load(const Common::String &str);
};
} // End of namespace Tattoo
} // End of namespace Sherlock
#endif

View File

@ -36,6 +36,7 @@ namespace Tattoo {
class WidgetTooltip: public WidgetBase {
public:
WidgetTooltip(SherlockEngine *vm);
virtual ~WidgetTooltip() {}
/**
* Handle updating the tooltip state

View File

@ -47,6 +47,7 @@ public:
Common::StringArray _verbCommands;
public:
WidgetVerbs(SherlockEngine *vm);
virtual ~WidgetVerbs() {}
/**
* Turns on the menu with all the verbs that are available for the given object

View File

@ -129,11 +129,6 @@ public:
* Clear any active text window
*/
virtual void clearWindow() {}
/**
* Print the previously selected object's decription
*/
virtual void printObjectDesc() {}
};
} // End of namespace Sherlock