From 9d6de4da652b2494d37756e9d12f944cddcf18c8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 30 Dec 2014 10:22:05 -1000 Subject: XEEN: Implemented cursor display --- engines/xeen/events.cpp | 22 +++++--- engines/xeen/events.h | 4 ++ engines/xeen/resources.cpp | 80 ++++++++++++++++++--------- engines/xeen/resources.h | 42 +++++++++++--- engines/xeen/screen.cpp | 18 ++---- engines/xeen/screen.h | 1 + engines/xeen/worldofxeen/worldofxeen_game.cpp | 8 +++ engines/xeen/xeen.cpp | 2 +- 8 files changed, 123 insertions(+), 54 deletions(-) (limited to 'engines/xeen') diff --git a/engines/xeen/events.cpp b/engines/xeen/events.cpp index 8e1b207556..29dde3a031 100644 --- a/engines/xeen/events.cpp +++ b/engines/xeen/events.cpp @@ -34,13 +34,11 @@ namespace Xeen { /** * Constructor */ -EventsManager::EventsManager(XeenEngine *vm) : _vm(vm) { - _frameCounter = 0; - _priorFrameCounterTime = 0; - _gameCounter = 0; - _priorGameCounterTime = 0; - _keyCode = Common::KEYCODE_INVALID; - _leftButton = _rightButton = false; +EventsManager::EventsManager(XeenEngine *vm) : _vm(vm), + _frameCounter(0), _priorFrameCounterTime(0), _gameCounter(0), + _priorGameCounterTime(0), _keyCode(Common::KEYCODE_INVALID), + _leftButton(false), _rightButton(false), + _sprites("mouse.icn") { } /** @@ -49,6 +47,16 @@ EventsManager::EventsManager(XeenEngine *vm) : _vm(vm) { EventsManager::~EventsManager() { } +/* + * Set the cursor + */ +void EventsManager::setCursor(int cursorId) { + XSurface cursor; + _sprites.draw(cursor, cursorId); + + CursorMan.replaceCursor(cursor.getPixels(), cursor.w, cursor.h, 0, 0, 0); +} + /** * Show the mouse cursor */ diff --git a/engines/xeen/events.h b/engines/xeen/events.h index b380f7bb93..3590267b66 100644 --- a/engines/xeen/events.h +++ b/engines/xeen/events.h @@ -25,6 +25,7 @@ #include "common/scummsys.h" #include "common/events.h" +#include "xeen/resources.h" namespace Xeen { @@ -41,6 +42,7 @@ private: uint32 _priorGameCounterTime; Common::KeyCode _keyCode; bool _leftButton, _rightButton; + FramesResource _sprites; void nextFrame(); public: @@ -50,6 +52,8 @@ public: uint32 getFrameCounter() { return _frameCounter; } + void setCursor(int cursorId); + void showCursor(); void hideCursor(); diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp index 40353c1cdc..4da84c1d38 100644 --- a/engines/xeen/resources.cpp +++ b/engines/xeen/resources.cpp @@ -216,19 +216,10 @@ void File::openFile(const Common::String &filename) { /*------------------------------------------------------------------------*/ -SpriteResource::SpriteResource(const Common::String &filename) { +GraphicResource::GraphicResource(const Common::String &filename) { // Open the resource File f(filename); - // Read in the index - int count = f.readUint16LE(); - _index.resize(count); - - for (int i = 0; i < count; ++i) { - _index[i]._offset1 = f.readUint16LE(); - _index[i]._offset2 = f.readUint16LE(); - } - // Read in a copy of the file _filesize = f.size(); _data = new byte[_filesize]; @@ -236,26 +227,15 @@ SpriteResource::SpriteResource(const Common::String &filename) { f.read(_data, _filesize); } -SpriteResource::~SpriteResource() { +GraphicResource::~GraphicResource() { delete[] _data; } -int SpriteResource::size() const { - return _index.size(); -} - -void SpriteResource::draw(XSurface &dest, int frame, const Common::Point &destPos) const { - drawOffset(dest, _index[frame]._offset1, destPos); - if (_index[frame]._offset2) - drawOffset(dest, _index[frame]._offset2, destPos); -} - -void SpriteResource::draw(XSurface &dest, int frame) const { - draw(dest, frame, Common::Point()); +int GraphicResource::size() const { + return READ_LE_UINT16(_data); } - -void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Point &destPos) const { +void GraphicResource::drawOffset(XSurface &dest, uint16 offset, const Common::Point &destPos) const { // Get cell header Common::MemoryReadStream f(_data, _filesize); f.seek(offset); @@ -264,6 +244,9 @@ void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Poi int yOffset = f.readUint16LE(); int height = f.readUint16LE(); + if (dest.w < (xOffset + width) || dest.h < (yOffset + height)) + dest.create(xOffset + width, yOffset + height); + // The pattern steps used in the pattern command const int patternSteps[] = { 0, 1, 1, 1, 2, 2, 3, 3, 0, -1, -1, -1, -2, -2, -3, -3 }; @@ -355,4 +338,51 @@ void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Poi destPos.x + xOffset + width, destPos.y + yOffset + height)); } +/*------------------------------------------------------------------------*/ + +FramesResource::FramesResource(const Common::String &filename) : + GraphicResource(filename) { + // Read in the index + Common::MemoryReadStream f(_data, _filesize); + int count = f.readUint16LE(); + _index.resize(count); + + for (int i = 0; i < count; ++i) { + _index[i] = f.readUint32LE(); + } +} + +void FramesResource::draw(XSurface &dest, int frame, const Common::Point &destPos) const { + drawOffset(dest, _index[frame], destPos); +} + +void FramesResource::draw(XSurface &dest, int frame) const { + draw(dest, frame, Common::Point()); +} + +/*------------------------------------------------------------------------*/ + +SpriteResource::SpriteResource(const Common::String &filename) : + GraphicResource(filename) { + // Read in the index + Common::MemoryReadStream f(_data, _filesize); + int count = f.readUint16LE(); + _index.resize(count); + + for (int i = 0; i < count; ++i) { + _index[i]._offset1 = f.readUint16LE(); + _index[i]._offset2 = f.readUint16LE(); + } +} + +void SpriteResource::draw(XSurface &dest, int frame, const Common::Point &destPos) const { + drawOffset(dest, _index[frame]._offset1, destPos); + if (_index[frame]._offset2) + drawOffset(dest, _index[frame]._offset2, destPos); +} + +void SpriteResource::draw(XSurface &dest, int frame) const { + draw(dest, frame, Common::Point()); +} + } // End of namespace Xeen diff --git a/engines/xeen/resources.h b/engines/xeen/resources.h index d29f0f125c..0476319875 100644 --- a/engines/xeen/resources.h +++ b/engines/xeen/resources.h @@ -53,23 +53,49 @@ public: void openFile(const Common::String &filename); }; -class SpriteResource { +class GraphicResource { +protected: + int32 _filesize; + byte *_data; + + void drawOffset(XSurface &dest, uint16 offset, const Common::Point &destPos) const; +public: + GraphicResource(const Common::String &filename); + + virtual ~GraphicResource(); + + int size() const; +}; + +/** + * Defines a resource that Contains a list of singular sprite frames + */ +class FramesResource : public GraphicResource { +private: + Common::Array _index; +public: + FramesResource(const Common::String &filename); + virtual ~FramesResource() {} + + void draw(XSurface &dest, int frame, const Common::Point &destPos) const; + + void draw(XSurface &dest, int frame) const; +}; + +/** + * Defines a resource that contains sets of two layered sprites per frame + */ +class SpriteResource : public GraphicResource { private: struct IndexEntry { uint16 _offset1, _offset2; }; Common::Array _index; - int32 _filesize; - byte *_data; - - void drawOffset(XSurface &dest, uint16 offset, const Common::Point &destPos) const; public: SpriteResource(const Common::String &filename); - ~SpriteResource(); - - int size() const; + virtual ~SpriteResource() {} void draw(XSurface &dest, int frame, const Common::Point &destPos) const; diff --git a/engines/xeen/screen.cpp b/engines/xeen/screen.cpp index 79aa733df7..b1275aaf4b 100644 --- a/engines/xeen/screen.cpp +++ b/engines/xeen/screen.cpp @@ -28,13 +28,13 @@ namespace Xeen { -Window::Window() : _screen(nullptr), _a(0), _border(0), +Window::Window() : _screen(nullptr), _enabled(false), _a(0), _border(0), _xLo(0), _xHi(0), _ycL(0), _ycH(0) { } Window::Window(Screen *screen, const Common::Rect &bounds, int a, int border, int xLo, int ycL, int xHi, int ycH): - _screen(screen), _bounds(bounds), _a(a), _border(border), + _screen(screen), _enabled(false), _bounds(bounds), _a(a), _border(border), _xLo(xLo), _ycL(ycL), _xHi(xHi), _ycH(ycH) { } @@ -50,7 +50,7 @@ Screen::Screen(XeenEngine *vm) : _vm(vm) { } void Screen::setupWindows() { - Window windows[48] = { + Window windows[40] = { Window(this, Common::Rect(0, 0, 320, 200), 0, 0, 0, 0, 320, 200), Window(this, Common::Rect(237, 9, 317, 74), 0, 0, 237, 12, 307, 68), Window(this, Common::Rect(225, 1, 319, 73), 1, 8, 225, 1, 319, 73), @@ -89,18 +89,10 @@ void Screen::setupWindows() { Window(this, Common::Rect(226, 26, 319, 146), 30, 8, 0, 0, 0, 0), Window(this, Common::Rect(225, 74, 319, 154), 31, 8, 0, 0, 0, 0), Window(this, Common::Rect(27, 6, 195, 142), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(225, 140, 319, 199), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0), - Window(this, Common::Rect(), 0, 8, 0, 0, 0, 0) + Window(this, Common::Rect(225, 140, 319, 199), 0, 8, 0, 0, 0, 0) }; - _windows = Common::Array(windows, 48); + _windows = Common::Array(windows, 40); } void Screen::update() { diff --git a/engines/xeen/screen.h b/engines/xeen/screen.h index cd4608cf9c..4178460caa 100644 --- a/engines/xeen/screen.h +++ b/engines/xeen/screen.h @@ -47,6 +47,7 @@ private: int _border; int _xLo, _xHi; int _ycL, _ycH; + bool _enabled; public: Window(); diff --git a/engines/xeen/worldofxeen/worldofxeen_game.cpp b/engines/xeen/worldofxeen/worldofxeen_game.cpp index dba5612e29..8057331250 100644 --- a/engines/xeen/worldofxeen/worldofxeen_game.cpp +++ b/engines/xeen/worldofxeen/worldofxeen_game.cpp @@ -30,7 +30,15 @@ WorldOfXeenEngine::WorldOfXeenEngine(OSystem *syst, const XeenGameDescription *g } void WorldOfXeenEngine::playGame () { + _screen->loadPalette("mm4.pal"); + _screen->fadeIn(4); + //darkSideIntro(); + _events->setCursor(0); + _events->showCursor(); + while (!shouldQuit()) { + _events->pollEventsAndWait(); + } } } // End of namespace Xeen diff --git a/engines/xeen/xeen.cpp b/engines/xeen/xeen.cpp index f1330f5b0e..5a293636a9 100644 --- a/engines/xeen/xeen.cpp +++ b/engines/xeen/xeen.cpp @@ -55,11 +55,11 @@ void XeenEngine::initialize() { DebugMan.addDebugChannel(kDebugSound, "sound", "Sound and Music handling"); // Create sub-objects of the engine + Resources::init(this); _debugger = new Debugger(this); _events = new EventsManager(this); _screen = new Screen(this); _sound = new SoundManager(this); - Resources::init(this); // Set graphics mode initGraphics(320, 200, false); -- cgit v1.2.3