Skip to content

Commit

Permalink
SHERLOK: Beginnings of split of doBgAnim logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 27, 2015
1 parent 57575b9 commit fdf1617
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 44 deletions.
8 changes: 8 additions & 0 deletions engines/sherlock/events.cpp
Expand Up @@ -75,6 +75,14 @@ void Events::setCursor(const Graphics::Surface &src) {
showCursor();
}

void Events::animateCursorIfNeeded() {
if (_cursorId >= WAIT && _cursorId < (WAIT + 3)) {
CursorId newId = (WAIT + 2) ? WAIT : (CursorId)((int)_cursorId + 1);
setCursor(newId);
}
}


void Events::showCursor() {
CursorMan.showMouse(true);
}
Expand Down
7 changes: 6 additions & 1 deletion engines/sherlock/events.h
Expand Up @@ -33,7 +33,7 @@ namespace Sherlock {
#define GAME_FRAME_RATE 60
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)

enum CursorId { ARROW = 0, MAGNIFY = 1, WAIT = 2, INVALID_CURSOR = -1 };
enum CursorId { ARROW = 0, MAGNIFY = 1, WAIT = 2, EXIT_ZONES_START = 5, INVALID_CURSOR = -1 };

class SherlockEngine;

Expand Down Expand Up @@ -77,6 +77,11 @@ class Events {
*/
void setCursor(const Graphics::Surface &src);

/**
* Animates the mouse cursor if the Wait cursor is showing
*/
void animateCursorIfNeeded();

/**
* Show the mouse cursor
*/
Expand Down
112 changes: 72 additions & 40 deletions engines/sherlock/scene.cpp
Expand Up @@ -1199,53 +1199,15 @@ int Scene::startCAnim(int cAnimNum, int playRate) {

void Scene::doBgAnim() {
Events &events = *_vm->_events;
Inventory &inv = *_vm->_inventory;
People &people = *_vm->_people;
Screen &screen = *_vm->_screen;
Sound &sound = *_vm->_sound;
Talk &talk = *_vm->_talk;
UserInterface &ui = *_vm->_ui;

screen.setDisplayBounds(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCENE_HEIGHT));

int cursorId = events.getCursor();
Common::Point mousePos = events.mousePos();
events.animateCursorIfNeeded();

screen.setDisplayBounds(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCENE_HEIGHT));
talk._talkToAbort = false;

// Animate the mouse cursor
if (cursorId >= WAIT) {
if (++cursorId > (WAIT + 2))
cursorId = WAIT;

events.setCursor((CursorId)cursorId);
}

if (ui._menuMode == LOOK_MODE) {
if (mousePos.y > CONTROLS_Y1)
events.setCursor(ARROW);
else if (mousePos.y < CONTROLS_Y)
events.setCursor(MAGNIFY);
}

// Check for setting magnifying glass cursor
if (ui._menuMode == INV_MODE || ui._menuMode == USE_MODE || ui._menuMode == GIVE_MODE) {
if (inv._invMode == INVMODE_LOOK) {
// Only show Magnifying glass cursor if it's not on the inventory command line
if (mousePos.y < CONTROLS_Y || mousePos.y >(CONTROLS_Y1 + 13))
events.setCursor(MAGNIFY);
else
events.setCursor(ARROW);
} else {
events.setCursor(ARROW);
}
}

if (sound._diskSoundPlaying && !*sound._soundIsOn) {
// Loaded sound just finished playing
sound.freeDigiSound();
}

if (_restoreFlag) {
if (people[AL]._type == CHARACTER)
people[AL].checkSprite();
Expand Down Expand Up @@ -1676,8 +1638,48 @@ void ScalpelScene::checkBgShapes() {
}
}

void ScalpelScene::doBgAnim() {
Inventory &inv = *_vm->_inventory;
Events &events = *_vm->_events;
Sound &sound = *_vm->_sound;
UserInterface &ui = *_vm->_ui;
Common::Point mousePos = events.mousePos();

if (ui._menuMode == LOOK_MODE) {
if (mousePos.y > CONTROLS_Y1)
events.setCursor(ARROW);
else if (mousePos.y < CONTROLS_Y)
events.setCursor(MAGNIFY);
}

// Check for setting magnifying glass cursor
if (ui._menuMode == INV_MODE || ui._menuMode == USE_MODE || ui._menuMode == GIVE_MODE) {
if (inv._invMode == INVMODE_LOOK) {
// Only show Magnifying glass cursor if it's not on the inventory command line
if (mousePos.y < CONTROLS_Y || mousePos.y >(CONTROLS_Y1 + 13))
events.setCursor(MAGNIFY);
else
events.setCursor(ARROW);
} else {
events.setCursor(ARROW);
}
}

if (sound._diskSoundPlaying && !*sound._soundIsOn) {
// Loaded sound just finished playing
sound.freeDigiSound();
}

// Handle doing the actual drawing
Scene::doBgAnim();
}

/*----------------------------------------------------------------*/

TattooScene::TattooScene(SherlockEngine *vm) : Scene(vm) {
_arrowZone = -1;
}

void TattooScene::checkBgShapes() {
People &people = *_vm->_people;
Person &holmes = people._player;
Expand Down Expand Up @@ -1705,4 +1707,34 @@ void TattooScene::checkBgShapes() {
}
}

void TattooScene::doBgAnim() {
Events &events = *_vm->_events;
UserInterface &ui = *_vm->_ui;
Common::Point mousePos = events.mousePos();

// If we're in Look Mode, make sure the cursor is the magnifying glass
if (ui._menuMode == LOOK_MODE && events.getCursor() != MAGNIFY)
events.setCursor(MAGNIFY);

// See if the mouse is over any of the arrow zones, and if so, change the cursor to the correct
// arrow cursor indicating the direcetion of the exit
if (events.getCursor() == ARROW || events.getCursor() >= EXIT_ZONES_START) {
CursorId cursorId = ARROW;

if (ui._menuMode == STD_MODE && _arrowZone != -1 && _currentScene != 90) {
for (uint idx = 0; idx < _exits.size(); ++idx) {
Exit &exit = _exits[idx];
if (exit.contains(mousePos))
cursorId = (CursorId)(exit._image + EXIT_ZONES_START);
}
}

events.setCursor(cursorId);
}

// Handle doing the actual drawing
_restoreFlag = true;
Scene::doBgAnim();
}

} // End of namespace Sherlock
17 changes: 14 additions & 3 deletions engines/sherlock/scene.h
Expand Up @@ -273,9 +273,9 @@ class Scene {
int toggleObject(const Common::String &name);

/**
* Animate all objects and people.
* Draw all objects and characters.
*/
void doBgAnim();
virtual void doBgAnim();

/**
* Attempts to find a background shape within the passed bounds. If found,
Expand Down Expand Up @@ -328,11 +328,17 @@ class ScalpelScene : public Scene {
virtual void checkBgShapes();
public:
ScalpelScene(SherlockEngine *vm) : Scene(vm) {}

/**
* Draw all objects and characters.
*/
virtual void doBgAnim();
};

class TattooScene : public Scene {
private:
CAnimStream _activeCAnim;
int _arrowZone;
protected:
/**
* Checks all the background shapes. If a background shape is animating,
Expand All @@ -341,7 +347,12 @@ class TattooScene : public Scene {
*/
virtual void checkBgShapes();
public:
TattooScene(SherlockEngine *vm) : Scene(vm) {}
TattooScene(SherlockEngine *vm);

/**
* Draw all objects and characters.
*/
virtual void doBgAnim();
};

} // End of namespace Sherlock
Expand Down

0 comments on commit fdf1617

Please sign in to comment.