From 07ea74d37b636f27c4fc0075f35ec4f4ad50501b Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 25 Nov 2010 04:49:11 +0000 Subject: MOHAWK: Refactor cursor handling Cursor handling has now been moved to a new CursorManager class (which is subclassed for Myst/Riven) from the GraphicsManager classes. This will be needed for Living Books which will have a class for Windows and Mac cursors (coming soon!). svn-id: r54469 --- engines/mohawk/cursors.cpp | 195 ++++++++++++++++++++++++++++++++++++++ engines/mohawk/cursors.h | 97 +++++++++++++++++++ engines/mohawk/graphics.cpp | 141 --------------------------- engines/mohawk/graphics.h | 31 ------ engines/mohawk/module.mk | 1 + engines/mohawk/mohawk.cpp | 6 ++ engines/mohawk/mohawk.h | 2 + engines/mohawk/myst.cpp | 14 +-- engines/mohawk/myst_scripts.cpp | 7 +- engines/mohawk/riven.cpp | 8 +- engines/mohawk/riven_external.cpp | 63 ++++++------ engines/mohawk/riven_scripts.cpp | 3 +- 12 files changed, 352 insertions(+), 216 deletions(-) create mode 100644 engines/mohawk/cursors.cpp create mode 100644 engines/mohawk/cursors.h (limited to 'engines/mohawk') diff --git a/engines/mohawk/cursors.cpp b/engines/mohawk/cursors.cpp new file mode 100644 index 0000000000..3b937385f9 --- /dev/null +++ b/engines/mohawk/cursors.cpp @@ -0,0 +1,195 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "mohawk/bitmap.h" +#include "mohawk/cursors.h" +#include "mohawk/resource.h" +#include "mohawk/graphics.h" +#include "mohawk/myst.h" +#include "mohawk/riven_cursors.h" + +#include "common/system.h" +#include "graphics/cursorman.h" + +namespace Mohawk { + +void CursorManager::showCursor() { + CursorMan.showMouse(true); +} + +void CursorManager::hideCursor() { + CursorMan.showMouse(false); +} + +MystCursorManager::MystCursorManager(MohawkEngine_Myst *vm) : _vm(vm) { + _bmpDecoder = new MystBitmap(); +} + +MystCursorManager::~MystCursorManager() { + delete _bmpDecoder; +} + +void MystCursorManager::showCursor() { + CursorMan.showMouse(true); + _vm->_needsUpdate = true; +} + +void MystCursorManager::hideCursor() { + CursorMan.showMouse(false); + _vm->_needsUpdate = true; +} + +void MystCursorManager::setCursor(uint16 id) { + // Both Myst and Myst ME use the "MystBitmap" format for cursor images. + MohawkSurface *mhkSurface = _bmpDecoder->decodeImage(_vm->getResource(ID_WDIB, id)); + Graphics::Surface *surface = mhkSurface->getSurface(); + Common::SeekableReadStream *clrcStream = _vm->getResource(ID_CLRC, id); + uint16 hotspotX = clrcStream->readUint16LE(); + uint16 hotspotY = clrcStream->readUint16LE(); + delete clrcStream; + + // Myst ME stores some cursors as 24bpp images instead of 8bpp + if (surface->bytesPerPixel == 1) { + CursorMan.replaceCursor((byte *)surface->pixels, surface->w, surface->h, hotspotX, hotspotY, 0); + CursorMan.replaceCursorPalette(mhkSurface->getPalette(), 0, 256); + } else { + Graphics::PixelFormat pixelFormat = g_system->getScreenFormat(); + CursorMan.replaceCursor((byte *)surface->pixels, surface->w, surface->h, hotspotX, hotspotY, pixelFormat.RGBToColor(255, 255, 255), 1, &pixelFormat); + } + + _vm->_needsUpdate = true; + delete mhkSurface; +} + +void RivenCursorManager::setCursor(uint16 id) { + // All of Riven's cursors are hardcoded. See riven_cursors.h for these definitions. + + switch (id) { + case 1002: + // Zip Mode + CursorMan.replaceCursor(s_zipModeCursor, 16, 16, 8, 8, 0); + CursorMan.replaceCursorPalette(s_zipModeCursorPalette, 1, ARRAYSIZE(s_zipModeCursorPalette) / 4); + break; + case 2003: + // Hand Over Object + CursorMan.replaceCursor(s_objectHandCursor, 16, 16, 8, 8, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 2004: + // Grabbing/Using Object + CursorMan.replaceCursor(s_grabbingHandCursor, 13, 13, 6, 6, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3000: + // Standard Hand + CursorMan.replaceCursor(s_standardHandCursor, 15, 16, 6, 0, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3001: + // Pointing Left + CursorMan.replaceCursor(s_pointingLeftCursor, 15, 13, 0, 3, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3002: + // Pointing Right + CursorMan.replaceCursor(s_pointingRightCursor, 15, 13, 14, 3, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3003: + // Pointing Down (Palm Up) + CursorMan.replaceCursor(s_pointingDownCursorPalmUp, 13, 16, 3, 15, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3004: + // Pointing Up (Palm Up) + CursorMan.replaceCursor(s_pointingUpCursorPalmUp, 13, 16, 3, 0, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3005: + // Pointing Left (Curved) + CursorMan.replaceCursor(s_pointingLeftCursorBent, 15, 13, 0, 5, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3006: + // Pointing Right (Curved) + CursorMan.replaceCursor(s_pointingRightCursorBent, 15, 13, 14, 5, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 3007: + // Pointing Down (Palm Down) + CursorMan.replaceCursor(s_pointingDownCursorPalmDown, 15, 16, 7, 15, 0); + CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); + break; + case 4001: + // Red Marble + CursorMan.replaceCursor(s_redMarbleCursor, 12, 12, 5, 5, 0); + CursorMan.replaceCursorPalette(s_redMarbleCursorPalette, 1, ARRAYSIZE(s_redMarbleCursorPalette) / 4); + break; + case 4002: + // Orange Marble + CursorMan.replaceCursor(s_orangeMarbleCursor, 12, 12, 5, 5, 0); + CursorMan.replaceCursorPalette(s_orangeMarbleCursorPalette, 1, ARRAYSIZE(s_orangeMarbleCursorPalette) / 4); + break; + case 4003: + // Yellow Marble + CursorMan.replaceCursor(s_yellowMarbleCursor, 12, 12, 5, 5, 0); + CursorMan.replaceCursorPalette(s_yellowMarbleCursorPalette, 1, ARRAYSIZE(s_yellowMarbleCursorPalette) / 4); + break; + case 4004: + // Green Marble + CursorMan.replaceCursor(s_greenMarbleCursor, 12, 12, 5, 5, 0); + CursorMan.replaceCursorPalette(s_greenMarbleCursorPalette, 1, ARRAYSIZE(s_greenMarbleCursorPalette) / 4); + break; + case 4005: + // Blue Marble + CursorMan.replaceCursor(s_blueMarbleCursor, 12, 12, 5, 5, 0); + CursorMan.replaceCursorPalette(s_blueMarbleCursorPalette, 1, ARRAYSIZE(s_blueMarbleCursorPalette) / 4); + break; + case 4006: + // Violet Marble + CursorMan.replaceCursor(s_violetMarbleCursor, 12, 12, 5, 5, 0); + CursorMan.replaceCursorPalette(s_violetMarbleCursorPalette, 1, ARRAYSIZE(s_violetMarbleCursorPalette) / 4); + break; + case 5000: + // Pellet + CursorMan.replaceCursor(s_pelletCursor, 8, 8, 4, 4, 0); + CursorMan.replaceCursorPalette(s_pelletCursorPalette, 1, ARRAYSIZE(s_pelletCursorPalette) / 4); + break; + case 9000: + // Hide Cursor + CursorMan.showMouse(false); + break; + default: + error("Cursor %d does not exist!", id); + } + + if (id != 9000) // Show Cursor + CursorMan.showMouse(true); + + // Should help in cases where we need to hide the cursor immediately. + g_system->updateScreen(); +} + +} // End of namespace Mohawk diff --git a/engines/mohawk/cursors.h b/engines/mohawk/cursors.h new file mode 100644 index 0000000000..90858a2421 --- /dev/null +++ b/engines/mohawk/cursors.h @@ -0,0 +1,97 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#ifndef MOHAWK_CURSORS_H +#define MOHAWK_CURSORS_H + +#include "common/scummsys.h" + +namespace Mohawk { + +// 803-805 are animated, one large bmp which is in chunks - these are NEVER USED +// Other cursors (200, 300, 400, 500, 600, 700) are not the same in each stack +enum { + kDefaultMystCursor = 100, // The default hand + kWhitePageCursor = 800, // Holding a white page + kRedPageCursor = 801, // Holding a red page + kBluePageCursor = 802, // Holding a blue page + // kDroppingWhitePageAnimCursor = 803, + // kDroppingRedPageAnimCursor = 804, + // kDroppingBluePageAnimCursor = 805, + kNewMatchCursor = 900, // Match that has not yet been lit + kLitMatchCursor = 901, // Match that's burning + kDeadMatchCursor = 902, // Match that's been extinguished + kKeyCursor = 903, // Key in Lighthouse in Stoneship + kRotateClockwiseCursor = 904, // Rotate gear clockwise (boiler on Myst) + kRotateCounterClockwiseCursor = 905, // Rotate gear counter clockwise (boiler on Myst) + kMystZipModeCursor = 999 // Zip Mode cursor +}; + +enum { + kRivenOpenHandCursor = 2003, + kRivenClosedHandCursor = 2004, + kRivenMainCursor = 3000, + kRivenPelletCursor = 5000, + kRivenHideCursor = 9000 +}; + +class MohawkEngine_Myst; +class MystBitmap; + +class CursorManager { +public: + CursorManager() {} + virtual ~CursorManager() {} + + virtual void showCursor(); + virtual void hideCursor(); + virtual void setCursor(uint16 id) = 0; +}; + +class MystCursorManager : public CursorManager { +public: + MystCursorManager(MohawkEngine_Myst *vm); + ~MystCursorManager(); + + void showCursor(); + void hideCursor(); + void setCursor(uint16 id); + +private: + MohawkEngine_Myst *_vm; + MystBitmap *_bmpDecoder; +}; + +class RivenCursorManager : public CursorManager { +public: + RivenCursorManager() {} + ~RivenCursorManager() {} + + void setCursor(uint16 id); +}; + +} // End of namespace Mohawk + +#endif diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp index e7f1d5af51..65eebf7134 100644 --- a/engines/mohawk/graphics.cpp +++ b/engines/mohawk/graphics.cpp @@ -27,11 +27,9 @@ #include "mohawk/graphics.h" #include "mohawk/myst.h" #include "mohawk/riven.h" -#include "mohawk/riven_cursors.h" #include "engines/util.h" -#include "graphics/cursorman.h" #include "graphics/primitives.h" #include "gui/message.h" @@ -296,36 +294,6 @@ void MystGraphics::updateScreen() { } } -void MystGraphics::showCursor(void) { - CursorMan.showMouse(true); - _vm->_needsUpdate = true; -} - -void MystGraphics::hideCursor(void) { - CursorMan.showMouse(false); - _vm->_needsUpdate = true; -} - -void MystGraphics::changeCursor(uint16 cursor) { - // Both Myst and Myst ME use the "MystBitmap" format for cursor images. - MohawkSurface *mhkSurface = _bmpDecoder->decodeImage(_vm->getResource(ID_WDIB, cursor)); - Graphics::Surface *surface = mhkSurface->getSurface(); - Common::SeekableReadStream *clrcStream = _vm->getResource(ID_CLRC, cursor); - uint16 hotspotX = clrcStream->readUint16LE(); - uint16 hotspotY = clrcStream->readUint16LE(); - delete clrcStream; - - // Myst ME stores some cursors as 24bpp images instead of 8bpp - if (surface->bytesPerPixel == 1) { - CursorMan.replaceCursor((byte *)surface->pixels, surface->w, surface->h, hotspotX, hotspotY, 0); - CursorMan.replaceCursorPalette(mhkSurface->getPalette(), 0, 256); - } else - CursorMan.replaceCursor((byte *)surface->pixels, surface->w, surface->h, hotspotX, hotspotY, _pixelFormat.RGBToColor(255, 255, 255), 1, &_pixelFormat); - - _vm->_needsUpdate = true; - delete mhkSurface; -} - void MystGraphics::drawRect(Common::Rect rect, bool active) { // Useful with debugging. Shows where hotspots are on the screen and whether or not they're active. if (rect.left < 0 || rect.top < 0 || rect.right > 544 || rect.bottom > 333 || !rect.isValidRect() || rect.width() == 0 || rect.height() == 0) @@ -571,115 +539,6 @@ void RivenGraphics::runScheduledTransition() { _scheduledTransition = -1; // Clear scheduled transition } -void RivenGraphics::changeCursor(uint16 num) { - // All of Riven's cursors are hardcoded. See riven_cursors.h for these definitions. - - switch (num) { - case 1002: - // Zip Mode - CursorMan.replaceCursor(s_zipModeCursor, 16, 16, 8, 8, 0); - CursorMan.replaceCursorPalette(s_zipModeCursorPalette, 1, ARRAYSIZE(s_zipModeCursorPalette) / 4); - break; - case 2003: - // Hand Over Object - CursorMan.replaceCursor(s_objectHandCursor, 16, 16, 8, 8, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 2004: - // Grabbing/Using Object - CursorMan.replaceCursor(s_grabbingHandCursor, 13, 13, 6, 6, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3000: - // Standard Hand - CursorMan.replaceCursor(s_standardHandCursor, 15, 16, 6, 0, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3001: - // Pointing Left - CursorMan.replaceCursor(s_pointingLeftCursor, 15, 13, 0, 3, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3002: - // Pointing Right - CursorMan.replaceCursor(s_pointingRightCursor, 15, 13, 14, 3, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3003: - // Pointing Down (Palm Up) - CursorMan.replaceCursor(s_pointingDownCursorPalmUp, 13, 16, 3, 15, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3004: - // Pointing Up (Palm Up) - CursorMan.replaceCursor(s_pointingUpCursorPalmUp, 13, 16, 3, 0, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3005: - // Pointing Left (Curved) - CursorMan.replaceCursor(s_pointingLeftCursorBent, 15, 13, 0, 5, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3006: - // Pointing Right (Curved) - CursorMan.replaceCursor(s_pointingRightCursorBent, 15, 13, 14, 5, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 3007: - // Pointing Down (Palm Down) - CursorMan.replaceCursor(s_pointingDownCursorPalmDown, 15, 16, 7, 15, 0); - CursorMan.replaceCursorPalette(s_handCursorPalette, 1, ARRAYSIZE(s_handCursorPalette) / 4); - break; - case 4001: - // Red Marble - CursorMan.replaceCursor(s_redMarbleCursor, 12, 12, 5, 5, 0); - CursorMan.replaceCursorPalette(s_redMarbleCursorPalette, 1, ARRAYSIZE(s_redMarbleCursorPalette) / 4); - break; - case 4002: - // Orange Marble - CursorMan.replaceCursor(s_orangeMarbleCursor, 12, 12, 5, 5, 0); - CursorMan.replaceCursorPalette(s_orangeMarbleCursorPalette, 1, ARRAYSIZE(s_orangeMarbleCursorPalette) / 4); - break; - case 4003: - // Yellow Marble - CursorMan.replaceCursor(s_yellowMarbleCursor, 12, 12, 5, 5, 0); - CursorMan.replaceCursorPalette(s_yellowMarbleCursorPalette, 1, ARRAYSIZE(s_yellowMarbleCursorPalette) / 4); - break; - case 4004: - // Green Marble - CursorMan.replaceCursor(s_greenMarbleCursor, 12, 12, 5, 5, 0); - CursorMan.replaceCursorPalette(s_greenMarbleCursorPalette, 1, ARRAYSIZE(s_greenMarbleCursorPalette) / 4); - break; - case 4005: - // Blue Marble - CursorMan.replaceCursor(s_blueMarbleCursor, 12, 12, 5, 5, 0); - CursorMan.replaceCursorPalette(s_blueMarbleCursorPalette, 1, ARRAYSIZE(s_blueMarbleCursorPalette) / 4); - break; - case 4006: - // Violet Marble - CursorMan.replaceCursor(s_violetMarbleCursor, 12, 12, 5, 5, 0); - CursorMan.replaceCursorPalette(s_violetMarbleCursorPalette, 1, ARRAYSIZE(s_violetMarbleCursorPalette) / 4); - break; - case 5000: - // Pellet - CursorMan.replaceCursor(s_pelletCursor, 8, 8, 4, 4, 0); - CursorMan.replaceCursorPalette(s_pelletCursorPalette, 1, ARRAYSIZE(s_pelletCursorPalette) / 4); - break; - case 9000: - // Hide Cursor - CursorMan.showMouse(false); - break; - default: - error("Cursor %d does not exist!", num); - } - - if (num != 9000) // Show Cursor - CursorMan.showMouse(true); - - // Should help in cases where we need to hide the cursor immediately. - _vm->_system->updateScreen(); -} - void RivenGraphics::showInventory() { // Don't redraw the inventory if (_inventoryDrawn) diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h index f90c792d25..38d174b481 100644 --- a/engines/mohawk/graphics.h +++ b/engines/mohawk/graphics.h @@ -41,33 +41,6 @@ class MohawkEngine_Riven; class MohawkBitmap; class MystBitmap; -enum { - kRivenOpenHandCursor = 2003, - kRivenClosedHandCursor = 2004, - kRivenMainCursor = 3000, - kRivenPelletCursor = 5000, - kRivenHideCursor = 9000 -}; - -// 803-805 are animated, one large bmp which is in chunks -// Other cursors (200, 300, 400, 500, 600, 700) are not the same in each stack -enum { - kDefaultMystCursor = 100, // The default hand - kWhitePageCursor = 800, // Holding a white page - kRedPageCursor = 801, // Holding a red page - kBluePageCursor = 802, // Holding a blue page - // kDroppingWhitePageAnimCursor = 803, - // kDroppingRedPageAnimCursor = 804, - // kDroppingBluePageAnimCursor = 805, - kNewMatchCursor = 900, // Match that has not yet been lit - kLitMatchCursor = 901, // Match that's burning - kDeadMatchCursor = 902, // Match that's been extinguished - kKeyCursor = 903, // Key in Lighthouse in Stoneship - kRotateClockwiseCursor = 904, // Rotate gear clockwise (boiler on Myst) - kRotateCounterClockwiseCursor = 905, // Rotate gear counter clockwise (boiler on Myst) - kMystZipModeCursor = 999 // Zip Mode cursor -}; - class MohawkSurface { public: MohawkSurface(); @@ -125,9 +98,6 @@ public: void loadExternalPictureFile(uint16 stack); void copyImageSectionToScreen(uint16 image, Common::Rect src, Common::Rect dest); void copyImageToScreen(uint16 image, Common::Rect dest); - void showCursor(); - void hideCursor(); - void changeCursor(uint16); void updateScreen(); void drawRect(Common::Rect rect, bool active); @@ -180,7 +150,6 @@ public: void copyImageToScreen(uint16, uint32, uint32, uint32, uint32); void updateScreen(); bool _updatesEnabled; - void changeCursor(uint16); Common::Array _activatedPLSTs; void drawPLST(uint16 x); void drawRect(Common::Rect rect, bool active); diff --git a/engines/mohawk/module.mk b/engines/mohawk/module.mk index bb79d4abac..2304121c87 100644 --- a/engines/mohawk/module.mk +++ b/engines/mohawk/module.mk @@ -3,6 +3,7 @@ MODULE := engines/mohawk MODULE_OBJS = \ bitmap.o \ console.o \ + cursors.o \ detection.o \ dialogs.o \ graphics.o \ diff --git a/engines/mohawk/mohawk.cpp b/engines/mohawk/mohawk.cpp index 4558f95d0b..1a6c8907d4 100644 --- a/engines/mohawk/mohawk.cpp +++ b/engines/mohawk/mohawk.cpp @@ -47,12 +47,18 @@ MohawkEngine::MohawkEngine(OSystem *syst, const MohawkGameDescription *gamedesc) _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); + + _sound = 0; + _video = 0; + _pauseDialog = 0; + _cursor = 0; } MohawkEngine::~MohawkEngine() { delete _sound; delete _video; delete _pauseDialog; + delete _cursor; for (uint32 i = 0; i < _mhk.size(); i++) delete _mhk[i]; diff --git a/engines/mohawk/mohawk.h b/engines/mohawk/mohawk.h index 2cba8aa021..ed59f727f3 100644 --- a/engines/mohawk/mohawk.h +++ b/engines/mohawk/mohawk.h @@ -76,6 +76,7 @@ class Sound; class PauseDialog; class MohawkArchive; class VideoManager; +class CursorManager; class MohawkEngine : public ::Engine { protected: @@ -99,6 +100,7 @@ public: Sound *_sound; VideoManager *_video; + CursorManager *_cursor; virtual Common::SeekableReadStream *getResource(uint32 tag, uint16 id); bool hasResource(uint32 tag, uint16 id); diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp index 4a577464cc..b4ec087b61 100644 --- a/engines/mohawk/myst.cpp +++ b/engines/mohawk/myst.cpp @@ -27,6 +27,7 @@ #include "common/debug-channels.h" #include "common/translation.h" +#include "mohawk/cursors.h" #include "mohawk/graphics.h" #include "mohawk/myst.h" #include "mohawk/myst_saveload.h" @@ -238,6 +239,7 @@ Common::Error MohawkEngine_Myst::run() { _loadDialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load")); _loadDialog->setSaveMode(false); _optionsDialog = new MystOptionsDialog(this); + _cursor = new MystCursorManager(this); // Start us on the first stack. if (getGameType() == GType_MAKINGOF) @@ -273,8 +275,8 @@ Common::Error MohawkEngine_Myst::run() { loadHelp(10000); // Set the cursor - _gfx->changeCursor(_currentCursor); - _gfx->showCursor(); + _cursor->setCursor(_currentCursor); + _cursor->showCursor(); Common::Event event; while (!shouldQuit()) { @@ -822,7 +824,7 @@ void MohawkEngine_Myst::loadCursorHints() { void MohawkEngine_Myst::setMainCursor(uint16 cursor) { _currentCursor = _mainCursor = cursor; - _gfx->changeCursor(_currentCursor); + _cursor->setCursor(_currentCursor); } void MohawkEngine_Myst::checkCursorHints() { @@ -841,7 +843,7 @@ void MohawkEngine_Myst::checkCursorHints() { _currentCursor = _cursorHints[i].variableHint.values[var_value]; if (_currentCursor == 0) _currentCursor = _mainCursor; - _gfx->changeCursor(_currentCursor); + _cursor->setCursor(_currentCursor); } } else if (_currentCursor != _cursorHints[i].cursor) { if (_cursorHints[i].cursor == 0) @@ -849,14 +851,14 @@ void MohawkEngine_Myst::checkCursorHints() { else _currentCursor = _cursorHints[i].cursor; - _gfx->changeCursor(_currentCursor); + _cursor->setCursor(_currentCursor); } return; } if (_currentCursor != _mainCursor) { _currentCursor = _mainCursor; - _gfx->changeCursor(_currentCursor); + _cursor->setCursor(_currentCursor); } } diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp index d9f1dfa4b6..b67c109acc 100644 --- a/engines/mohawk/myst_scripts.cpp +++ b/engines/mohawk/myst_scripts.cpp @@ -23,6 +23,7 @@ * */ +#include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/graphics.h" #include "mohawk/myst_scripts.h" @@ -1017,7 +1018,7 @@ void MystScriptParser::changeCursor(uint16 op, uint16 var, uint16 argc, uint16 * debugC(kDebugScript, "Cursor: %d", argv[0]); // TODO: Not sure if this needs to change mainCursor or similar... - _vm->_gfx->changeCursor(argv[0]); + _vm->_cursor->setCursor(argv[0]); } else unknown(op, var, argc, argv); } @@ -1027,7 +1028,7 @@ void MystScriptParser::hideCursor(uint16 op, uint16 var, uint16 argc, uint16 *ar if (argc == 0) { debugC(kDebugScript, "Opcode %d: Hide Cursor", op); - _vm->_gfx->hideCursor(); + _vm->_cursor->hideCursor(); } else unknown(op, var, argc, argv); } @@ -1037,7 +1038,7 @@ void MystScriptParser::showCursor(uint16 op, uint16 var, uint16 argc, uint16 *ar if (argc == 0) { debugC(kDebugScript, "Opcode %d: Show Cursor", op); - _vm->_gfx->showCursor(); + _vm->_cursor->showCursor(); } else unknown(op, var, argc, argv); } diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 8888200d8b..45b000ec5f 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -29,6 +29,7 @@ #include "common/keyboard.h" #include "common/translation.h" +#include "mohawk/cursors.h" #include "mohawk/graphics.h" #include "mohawk/resource.h" #include "mohawk/riven.h" @@ -111,6 +112,7 @@ Common::Error MohawkEngine_Riven::run() { _externalScriptHandler = new RivenExternal(this); _optionsDialog = new RivenOptionsDialog(this); _scriptMan = new RivenScriptManager(this); + _cursor = new RivenCursorManager(); _rnd = new Common::RandomSource(); g_eventRec.registerRandomSource(*_rnd, "riven"); @@ -124,7 +126,7 @@ Common::Error MohawkEngine_Riven::run() { error("Could not open extras.mhk"); // Start at main cursor - _gfx->changeCursor(kRivenMainCursor); + _cursor->setCursor(kRivenMainCursor); // Let's begin, shall we? if (getFeatures() & GF_DEMO) { @@ -478,11 +480,11 @@ void MohawkEngine_Riven::checkHotspotChange() { if (foundHotspot) { if (_curHotspot != hotspotIndex) { _curHotspot = hotspotIndex; - _gfx->changeCursor(_hotspots[_curHotspot].mouse_cursor); + _cursor->setCursor(_hotspots[_curHotspot].mouse_cursor); } } else { _curHotspot = -1; - _gfx->changeCursor(kRivenMainCursor); + _cursor->setCursor(kRivenMainCursor); } } diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp index e68e8e9548..8848716967 100644 --- a/engines/mohawk/riven_external.cpp +++ b/engines/mohawk/riven_external.cpp @@ -23,6 +23,7 @@ * */ +#include "mohawk/cursors.h" #include "mohawk/graphics.h" #include "mohawk/riven.h" #include "mohawk/riven_external.h" @@ -310,9 +311,9 @@ void RivenExternal::checkSliderCursorChange(uint16 startHotspot) { for (uint16 i = 0; i < kDomeSliderSlotCount; i++) { if (_vm->_hotspots[i + startHotspot].rect.contains(_vm->_system->getEventManager()->getMousePos())) { if (_sliderState & (1 << (24 - i))) - _vm->_gfx->changeCursor(kRivenOpenHandCursor); + _vm->_cursor->setCursor(kRivenOpenHandCursor); else - _vm->_gfx->changeCursor(kRivenMainCursor); + _vm->_cursor->setCursor(kRivenMainCursor); break; } } @@ -337,7 +338,7 @@ void RivenExternal::dragDomeSlider(uint16 soundId, uint16 resetSlidersHotspot, u return; // We've clicked down, so show the closed hand cursor - _vm->_gfx->changeCursor(kRivenClosedHandCursor); + _vm->_cursor->setCursor(kRivenClosedHandCursor); bool done = false; while (!done) { @@ -826,7 +827,7 @@ void RivenExternal::xbchangeboiler(uint16 argc, uint16 *argv) { else if (argv[0] == 2) _vm->_sound->playSLST(1, _vm->getCurCard()); - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_video->playMovieBlocking(11); } @@ -858,7 +859,7 @@ void RivenExternal::xbcheckcatch(uint16 argc, uint16 *argv) { void RivenExternal::xbait(uint16 argc, uint16 *argv) { // Set the cursor to the pellet - _vm->_gfx->changeCursor(kRivenPelletCursor); + _vm->_cursor->setCursor(kRivenPelletCursor); // Loop until the player lets go (or quits) Common::Event event; @@ -877,7 +878,7 @@ void RivenExternal::xbait(uint16 argc, uint16 *argv) { } // Set back the cursor - _vm->_gfx->changeCursor(kRivenMainCursor); + _vm->_cursor->setCursor(kRivenMainCursor); // Set the bait if we put it on the plate if (_vm->_hotspots[9].rect.contains(_vm->_system->getEventManager()->getMousePos())) { @@ -897,7 +898,7 @@ void RivenExternal::xbaitplate(uint16 argc, uint16 *argv) { // Remove the pellet from the plate and put it in your hand _vm->_gfx->drawPLST(3); _vm->_gfx->updateScreen(); - _vm->_gfx->changeCursor(kRivenPelletCursor); + _vm->_cursor->setCursor(kRivenPelletCursor); // Loop until the player lets go (or quits) Common::Event event; @@ -916,7 +917,7 @@ void RivenExternal::xbaitplate(uint16 argc, uint16 *argv) { } // Set back the cursor - _vm->_gfx->changeCursor(kRivenMainCursor); + _vm->_cursor->setCursor(kRivenMainCursor); // Set the bait if we put it on the plate, remove otherwise if (_vm->_hotspots[9].rect.contains(_vm->_system->getEventManager()->getMousePos())) { @@ -967,7 +968,7 @@ void RivenExternal::xvalvecontrol(uint16 argc, uint16 *argv) { bool done = false; // Set the cursor to the closed position - _vm->_gfx->changeCursor(kRivenClosedHandCursor); + _vm->_cursor->setCursor(kRivenClosedHandCursor); _vm->_system->updateScreen(); while (!done) { @@ -984,24 +985,24 @@ void RivenExternal::xvalvecontrol(uint16 argc, uint16 *argv) { // FIXME: These values for changes in x/y could be tweaked. if (*valve == 0 && changeY <= -10) { *valve = 1; - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_video->playMovieBlocking(2); _vm->refreshCard(); } else if (*valve == 1) { if (changeX >= 0 && changeY >= 10) { *valve = 0; - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_video->playMovieBlocking(3); _vm->refreshCard(); } else if (changeX <= -10 && changeY <= 10) { *valve = 2; - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_video->playMovieBlocking(1); _vm->refreshCard(); } } else if (*valve == 2 && changeX >= 10) { *valve = 1; - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_video->playMovieBlocking(4); _vm->refreshCard(); } @@ -1081,7 +1082,7 @@ void RivenExternal::xgisland1490_domecheck(uint16 argc, uint16 *argv) { void RivenExternal::xgplateau3160_dopools(uint16 argc, uint16 *argv) { // Play the deactivation of a pool if one is active and a different one is activated - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_video->playMovieBlocking(*_vm->getVar("glkbtns") * 2); } @@ -1289,11 +1290,11 @@ void RivenExternal::xjtunnel106_pictfix(uint16 argc, uint16 *argv) { void RivenExternal::xvga1300_carriage(uint16 argc, uint16 *argv) { // Run the gallows's carriage - _vm->_gfx->changeCursor(kRivenHideCursor); // Hide the cursor + _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor _vm->_video->playMovieBlocking(1); // Play handle movie _vm->_gfx->scheduleTransition(15); // Set pan down transition _vm->changeToCard(_vm->matchRMAPToCard(0x18e77)); // Change to card facing up - _vm->_gfx->changeCursor(kRivenHideCursor); // Hide the cursor (again) + _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor (again) _vm->_video->playMovieBlocking(4); // Play carriage beginning to drop _vm->_gfx->scheduleTransition(14); // Set pan up transition _vm->changeToCard(_vm->matchRMAPToCard(0x183a9)); // Change to card looking straight again @@ -1327,16 +1328,16 @@ void RivenExternal::xvga1300_carriage(uint16 argc, uint16 *argv) { _vm->_system->delayMillis(10); } - _vm->_gfx->changeCursor(kRivenHideCursor); // Hide the cursor + _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor if (gotClick) { _vm->_gfx->scheduleTransition(16); // Schedule dissolve transition _vm->changeToCard(_vm->matchRMAPToCard(0x18d4d)); // Move forward - _vm->_gfx->changeCursor(kRivenHideCursor); // Hide the cursor + _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor _vm->_system->delayMillis(500); // Delay a half second before changing again _vm->_gfx->scheduleTransition(12); // Schedule pan left transition _vm->changeToCard(_vm->matchRMAPToCard(0x18ab5)); // Turn right - _vm->_gfx->changeCursor(kRivenHideCursor); // Hide the cursor + _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor _vm->_video->playMovieBlocking(1); // Play carriage ride movie _vm->changeToCard(_vm->matchRMAPToCard(0x17167)); // We have arrived at the top } else @@ -1369,7 +1370,7 @@ int RivenExternal::jspitElevatorLoop() { Common::Event event; int changeLevel = 0; - _vm->_gfx->changeCursor(kRivenClosedHandCursor); + _vm->_cursor->setCursor(kRivenClosedHandCursor); _vm->_system->updateScreen(); for (;;) { while (_vm->_system->getEventManager()->pollEvent(event)) { @@ -1385,7 +1386,7 @@ int RivenExternal::jspitElevatorLoop() { _vm->_system->updateScreen(); break; case Common::EVENT_LBUTTONUP: - _vm->_gfx->changeCursor(kRivenMainCursor); + _vm->_cursor->setCursor(kRivenMainCursor); _vm->_system->updateScreen(); return changeLevel; default: @@ -1527,7 +1528,7 @@ void RivenExternal::xorollcredittime(uint16 argc, uint16 *argv) { void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { // Hide the cursor - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); // Let's hook onto our video VideoHandle video = _vm->_video->findVideoHandle(argv[0]); @@ -1567,9 +1568,9 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { // Update our hotspot stuff if (hotspotRect.contains(_vm->_system->getEventManager()->getMousePos())) - _vm->_gfx->changeCursor(kRivenOpenHandCursor); + _vm->_cursor->setCursor(kRivenOpenHandCursor); else - _vm->_gfx->changeCursor(kRivenMainCursor); + _vm->_cursor->setCursor(kRivenMainCursor); // OK, Gehn has opened the trap book and has asked us to go in. Let's watch // and see what the player will do... @@ -1581,9 +1582,9 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { switch (event.type) { case Common::EVENT_MOUSEMOVE: if (hotspotRect.contains(_vm->_system->getEventManager()->getMousePos())) - _vm->_gfx->changeCursor(kRivenOpenHandCursor); + _vm->_cursor->setCursor(kRivenOpenHandCursor); else - _vm->_gfx->changeCursor(kRivenMainCursor); + _vm->_cursor->setCursor(kRivenMainCursor); updateScreen = false; // Don't update twice, changing the cursor already updates the screen break; case Common::EVENT_LBUTTONUP: @@ -1591,7 +1592,7 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { // OK, we've used the trap book! We go for ride lady! _vm->_scriptMan->stopAllScripts(); // Stop all running scripts (so we don't remain in the cage) _vm->_video->stopVideos(); // Stop all videos - _vm->_gfx->changeCursor(kRivenHideCursor); // Hide the cursor + _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor _vm->_gfx->drawPLST(3); // Black out the screen _vm->_gfx->updateScreen(); // Update the screen _vm->_sound->playSound(0); // Play the link sound @@ -1620,7 +1621,7 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { return; // Hide the cursor again - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); // If there was no click and this is the third time Gehn asks us to // use the trap book, he will shoot the player. Dead on arrival. @@ -1717,7 +1718,7 @@ uint16 RivenExternal::getComboDigit(uint32 correctCombo, uint32 digit) { void RivenExternal::xgwatch(uint16 argc, uint16 *argv) { // Hide the cursor - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); uint32 *prisonCombo = _vm->getVar("pcorrectorder"); uint32 soundTime = _vm->_system->getMillis() - 500; // Start the first sound instantly @@ -1878,7 +1879,7 @@ void RivenExternal::xtexterior300_telescopedown(uint16 argc, uint16 *argv) { } else { // ...the telescope can't move down anymore. // Play the sound of not being able to move - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_sound->playSoundBlocking(13); } } else { @@ -1905,7 +1906,7 @@ void RivenExternal::xtexterior300_telescopeup(uint16 argc, uint16 *argv) { // Check if we can't move up anymore if (*telescopePos == 5) { // Play the sound of not being able to move - _vm->_gfx->changeCursor(kRivenHideCursor); + _vm->_cursor->setCursor(kRivenHideCursor); _vm->_sound->playSoundBlocking(13); return; } diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index b20dc37f0e..8d0743340c 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -23,6 +23,7 @@ * */ +#include "mohawk/cursors.h" #include "mohawk/graphics.h" #include "mohawk/riven.h" #include "mohawk/riven_external.h" @@ -401,7 +402,7 @@ void RivenScript::clearSLST(uint16 op, uint16 argc, uint16 *argv) { // Command 13: set mouse cursor (cursor_id) void RivenScript::changeCursor(uint16 op, uint16 argc, uint16 *argv) { debug(2, "Change to cursor %d", argv[0]); - _vm->_gfx->changeCursor(argv[0]); + _vm->_cursor->setCursor(argv[0]); } // Command 14: pause script execution (delay in ms, u1) -- cgit v1.2.3