From 6d1d31d0f95ab82872dd821131e0070473bd1aac Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 17 Apr 2011 16:28:05 +0200 Subject: LASTEXPRESS: Prefer Surface::create taking a PixelFormat over the one taking a byte depth. I am not sure whether the engine really uses only surfaces with the exat same format as the screen. The engine maintainer should review this commit and fix it in case the surfaces use a different pixel format. --- engines/lastexpress/data/animation.cpp | 2 +- engines/lastexpress/data/sequence.cpp | 2 +- engines/lastexpress/graphics.cpp | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/data/animation.cpp b/engines/lastexpress/data/animation.cpp index 7288889f09..ed0a5a67e1 100644 --- a/engines/lastexpress/data/animation.cpp +++ b/engines/lastexpress/data/animation.cpp @@ -266,7 +266,7 @@ void Animation::play() { if (_changed) { // Create a temporary surface to merge the overlay with the background Graphics::Surface *s = new Graphics::Surface; - s->create(640, 480, 2); + s->create(640, 480, g_system->getScreenFormat()); draw(s); diff --git a/engines/lastexpress/data/sequence.cpp b/engines/lastexpress/data/sequence.cpp index 2308d70a2b..fe694187a4 100644 --- a/engines/lastexpress/data/sequence.cpp +++ b/engines/lastexpress/data/sequence.cpp @@ -82,7 +82,7 @@ void FrameInfo::read(Common::SeekableReadStream *in, bool isSequence) { AnimFrame::AnimFrame(Common::SeekableReadStream *in, const FrameInfo &f) : _palette(NULL) { _palSize = 1; // TODO: use just the needed rectangle - _image.create(640, 480, 1); + _image.create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); //debugC(6, kLastExpressDebugGraphics, " Offsets: data=%d, unknown=%d, palette=%d", f.dataOffset, f.unknown, f.paletteOffset); //debugC(6, kLastExpressDebugGraphics, " Position: (%d, %d) - (%d, %d)", f.xPos1, f.yPos1, f.xPos2, f.yPos2); diff --git a/engines/lastexpress/graphics.cpp b/engines/lastexpress/graphics.cpp index e5a69d16ea..b627796e25 100644 --- a/engines/lastexpress/graphics.cpp +++ b/engines/lastexpress/graphics.cpp @@ -32,13 +32,14 @@ namespace LastExpress { #define COLOR_KEY 0xFFFF GraphicsManager::GraphicsManager() : _changed(false) { - _screen.create(640, 480, 2); + const Graphics::PixelFormat format = g_system->getScreenFormat(); + _screen.create(640, 480, format); // Create the game surfaces - _backgroundA.create(640, 480, 2); - _backgroundC.create(640, 480, 2); - _overlay.create(640, 480, 2); - _inventory.create(640, 480, 2); + _backgroundA.create(640, 480, format); + _backgroundC.create(640, 480, format); + _overlay.create(640, 480, format); + _inventory.create(640, 480, format); clear(kBackgroundAll); } -- cgit v1.2.3 From 14d496400111a52ecd31b559131f5743ded10689 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 17 Apr 2011 22:17:09 +0200 Subject: LASTEXPRESS: Use RGB555 PixelFormat for surfaces instead of screen format. This makes the code a bit more readable, thanks to fuzzie for pointing that out. --- engines/lastexpress/data/animation.cpp | 2 +- engines/lastexpress/graphics.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/data/animation.cpp b/engines/lastexpress/data/animation.cpp index ed0a5a67e1..11e4b4d290 100644 --- a/engines/lastexpress/data/animation.cpp +++ b/engines/lastexpress/data/animation.cpp @@ -266,7 +266,7 @@ void Animation::play() { if (_changed) { // Create a temporary surface to merge the overlay with the background Graphics::Surface *s = new Graphics::Surface; - s->create(640, 480, g_system->getScreenFormat()); + s->create(640, 480, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)); draw(s); diff --git a/engines/lastexpress/graphics.cpp b/engines/lastexpress/graphics.cpp index b627796e25..6c862ebc1e 100644 --- a/engines/lastexpress/graphics.cpp +++ b/engines/lastexpress/graphics.cpp @@ -32,7 +32,7 @@ namespace LastExpress { #define COLOR_KEY 0xFFFF GraphicsManager::GraphicsManager() : _changed(false) { - const Graphics::PixelFormat format = g_system->getScreenFormat(); + const Graphics::PixelFormat format(2, 5, 5, 5, 0, 10, 5, 0, 0); _screen.create(640, 480, format); // Create the game surfaces -- cgit v1.2.3 From 9d8874c7072709c3739efdad317454cdccf82683 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 24 Apr 2011 23:14:14 -0400 Subject: AUDIO: Cleanup MS IMA handling - Split The Last Express' ADPCM to the engine. Using the MS IMA routine was really a hack. - Fixed stereo MS IMA ADPCM, the old routine was completely wrong. --- engines/lastexpress/data/snd.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/data/snd.cpp b/engines/lastexpress/data/snd.cpp index bd2320726a..6389489abb 100644 --- a/engines/lastexpress/data/snd.cpp +++ b/engines/lastexpress/data/snd.cpp @@ -30,12 +30,45 @@ #include "lastexpress/debug.h" -#include "audio/decoders/adpcm.h" +#include "audio/decoders/adpcm_intern.h" #include "audio/audiostream.h" #include "common/memstream.h" namespace LastExpress { +// Last Express ADPCM is similar to MS IMA mono, but inverts its nibbles +// and does not have the 4 byte per channel requirement + +class LastExpress_ADPCMStream : public Audio::Ima_ADPCMStream { +public: + LastExpress_ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, uint32 blockSize) : + Audio::Ima_ADPCMStream(stream, disposeAfterUse, size, 44100, 1, blockSize) {} + + int readBuffer(int16 *buffer, const int numSamples) { + int samples = 0; + + assert(numSamples % 2 == 0); + + while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) { + if (_blockPos[0] == _blockAlign) { + // read block header + _status.ima_ch[0].last = _stream->readSint16LE(); + _status.ima_ch[0].stepIndex = _stream->readSint16LE(); + _blockPos[0] = 4; + } + + for (; samples < numSamples && _blockPos[0] < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) { + byte data = _stream->readByte(); + _blockPos[0]++; + buffer[samples] = decodeIMA((data >> 4) & 0x0f); + buffer[samples + 1] = decodeIMA(data & 0x0f); + } + } + + return samples; + } +}; + ////////////////////////////////////////////////////////////////////////// // Sound ////////////////////////////////////////////////////////////////////////// @@ -60,7 +93,7 @@ void SimpleSound::loadHeader(Common::SeekableReadStream *in) { } Audio::AudioStream *SimpleSound::makeDecoder(Common::SeekableReadStream *in, uint32 size) const { - return Audio::makeADPCMStream(in, DisposeAfterUse::YES, size, Audio::kADPCMMSImaLastExpress, 44100, 1, _blockSize); + return new LastExpress_ADPCMStream(in, DisposeAfterUse::YES, size, _blockSize); } void SimpleSound::play(Audio::AudioStream *as) { -- cgit v1.2.3 From cd6ee0589d0556d3d9e81d835c8b900636083de5 Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Mon, 25 Apr 2011 22:29:26 +0300 Subject: JANITORIAL: Format forward declarations to follow convention --- engines/lastexpress/data/snd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/data/snd.h b/engines/lastexpress/data/snd.h index 2d28404f42..61d1c0951a 100644 --- a/engines/lastexpress/data/snd.h +++ b/engines/lastexpress/data/snd.h @@ -42,8 +42,8 @@ #include "audio/mixer.h" namespace Audio { - class AudioStream; - class QueuingAudioStream; +class AudioStream; +class QueuingAudioStream; } namespace Common { -- cgit v1.2.3 From 9414d7a6e287ff8abfb5746b564e92c8f0e6de58 Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Sun, 24 Apr 2011 11:34:27 +0300 Subject: JANITORIAL: Reduce header dependencies in shared code Some backends may break as I only compiled SDL --- engines/lastexpress/data/animation.cpp | 3 +++ engines/lastexpress/data/archive.h | 3 +++ engines/lastexpress/data/background.cpp | 1 + engines/lastexpress/data/font.cpp | 2 ++ engines/lastexpress/data/font.h | 2 ++ engines/lastexpress/data/scene.cpp | 1 + engines/lastexpress/data/scene.h | 6 ++++++ engines/lastexpress/data/sequence.cpp | 1 + engines/lastexpress/data/sequence.h | 2 ++ engines/lastexpress/data/snd.cpp | 3 +++ engines/lastexpress/data/subtitle.cpp | 2 ++ engines/lastexpress/entities/entity.h | 1 + engines/lastexpress/game/state.h | 2 ++ engines/lastexpress/graphics.cpp | 2 ++ engines/lastexpress/resource.cpp | 1 + 15 files changed, 32 insertions(+) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/data/animation.cpp b/engines/lastexpress/data/animation.cpp index 7288889f09..6e80d3d9d6 100644 --- a/engines/lastexpress/data/animation.cpp +++ b/engines/lastexpress/data/animation.cpp @@ -35,7 +35,10 @@ #include "common/events.h" #include "common/rational.h" +#include "common/rect.h" #include "common/stream.h" +#include "common/system.h" +#include "common/textconsole.h" #include "engines/engine.h" diff --git a/engines/lastexpress/data/archive.h b/engines/lastexpress/data/archive.h index 3860245bc5..17b1d661fa 100644 --- a/engines/lastexpress/data/archive.h +++ b/engines/lastexpress/data/archive.h @@ -39,6 +39,9 @@ */ #include "common/archive.h" +#include "common/hash-str.h" +#include "common/hashmap.h" +#include "common/str.h" namespace LastExpress { diff --git a/engines/lastexpress/data/background.cpp b/engines/lastexpress/data/background.cpp index 8b0d338f64..e8236bca86 100644 --- a/engines/lastexpress/data/background.cpp +++ b/engines/lastexpress/data/background.cpp @@ -31,6 +31,7 @@ #include "lastexpress/debug.h" +#include "common/rect.h" #include "common/stream.h" namespace LastExpress { diff --git a/engines/lastexpress/data/font.cpp b/engines/lastexpress/data/font.cpp index 99239606ab..d9acbb8382 100644 --- a/engines/lastexpress/data/font.cpp +++ b/engines/lastexpress/data/font.cpp @@ -25,8 +25,10 @@ #include "lastexpress/data/font.h" +#include "common/rect.h" #include "common/stream.h" #include "common/system.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/data/font.h b/engines/lastexpress/data/font.h index d49db35ba5..7bcf03ed7d 100644 --- a/engines/lastexpress/data/font.h +++ b/engines/lastexpress/data/font.h @@ -39,10 +39,12 @@ byte {x} - Unknown data (probably just garbage) */ +#include "common/str.h" #include "graphics/surface.h" namespace Common { class SeekableReadStream; +struct Rect; } namespace LastExpress { diff --git a/engines/lastexpress/data/scene.cpp b/engines/lastexpress/data/scene.cpp index 5a943982c4..e893d641a5 100644 --- a/engines/lastexpress/data/scene.cpp +++ b/engines/lastexpress/data/scene.cpp @@ -31,6 +31,7 @@ #include "lastexpress/lastexpress.h" #include "lastexpress/resource.h" +#include "common/textconsole.h" #include "common/stream.h" namespace LastExpress { diff --git a/engines/lastexpress/data/scene.h b/engines/lastexpress/data/scene.h index 7fc9425f28..9ec1899402 100644 --- a/engines/lastexpress/data/scene.h +++ b/engines/lastexpress/data/scene.h @@ -72,9 +72,15 @@ #include "lastexpress/shared.h" #include "common/array.h" +#include "common/rect.h" namespace Common { class SeekableReadStream; +class String; +} + +namespace Graphics { +struct Surface; } namespace LastExpress { diff --git a/engines/lastexpress/data/sequence.cpp b/engines/lastexpress/data/sequence.cpp index 2308d70a2b..0e6df13995 100644 --- a/engines/lastexpress/data/sequence.cpp +++ b/engines/lastexpress/data/sequence.cpp @@ -30,6 +30,7 @@ #include "lastexpress/debug.h" #include "common/stream.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/data/sequence.h b/engines/lastexpress/data/sequence.h index 7ad0a57254..cd16f26ab2 100644 --- a/engines/lastexpress/data/sequence.h +++ b/engines/lastexpress/data/sequence.h @@ -77,6 +77,8 @@ #include "lastexpress/shared.h" #include "common/array.h" +#include "common/rect.h" +#include "common/str.h" namespace Common { class SeekableReadStream; diff --git a/engines/lastexpress/data/snd.cpp b/engines/lastexpress/data/snd.cpp index 6389489abb..a50fa7be08 100644 --- a/engines/lastexpress/data/snd.cpp +++ b/engines/lastexpress/data/snd.cpp @@ -32,7 +32,10 @@ #include "audio/decoders/adpcm_intern.h" #include "audio/audiostream.h" +#include "common/debug.h" #include "common/memstream.h" +#include "common/system.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/data/subtitle.cpp b/engines/lastexpress/data/subtitle.cpp index 953edd1d1a..2bc5d3c5ad 100644 --- a/engines/lastexpress/data/subtitle.cpp +++ b/engines/lastexpress/data/subtitle.cpp @@ -33,7 +33,9 @@ #include "lastexpress/debug.h" #include "common/debug.h" +#include "common/rect.h" #include "common/stream.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/entities/entity.h b/engines/lastexpress/entities/entity.h index ccef312cd6..8c6cc2bafc 100644 --- a/engines/lastexpress/entities/entity.h +++ b/engines/lastexpress/entities/entity.h @@ -35,6 +35,7 @@ #include "common/array.h" #include "common/func.h" #include "common/serializer.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/game/state.h b/engines/lastexpress/game/state.h index d97ebc1b55..4196bfe06a 100644 --- a/engines/lastexpress/game/state.h +++ b/engines/lastexpress/game/state.h @@ -28,8 +28,10 @@ #include "lastexpress/shared.h" +#include "common/rect.h" #include "common/serializer.h" #include "common/system.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/graphics.cpp b/engines/lastexpress/graphics.cpp index e5a69d16ea..5c72fa76d8 100644 --- a/engines/lastexpress/graphics.cpp +++ b/engines/lastexpress/graphics.cpp @@ -25,7 +25,9 @@ #include "lastexpress/graphics.h" +#include "common/rect.h" #include "common/system.h" +#include "common/textconsole.h" namespace LastExpress { diff --git a/engines/lastexpress/resource.cpp b/engines/lastexpress/resource.cpp index 5a77b23602..dff686a503 100644 --- a/engines/lastexpress/resource.cpp +++ b/engines/lastexpress/resource.cpp @@ -34,6 +34,7 @@ #include "common/debug.h" #include "common/file.h" +#include "common/textconsole.h" namespace LastExpress { -- cgit v1.2.3 From 1516ba73671d59ab5d6e26602dbb1e5055cbb05c Mon Sep 17 00:00:00 2001 From: Littleboy Date: Fri, 29 Apr 2011 22:00:38 -0400 Subject: LASTEXPRESS: Implement skeleton code for selected item and inventory selection --- engines/lastexpress/game/inventory.cpp | 102 ++++++++++++++++++++++++++++++--- engines/lastexpress/game/inventory.h | 5 +- engines/lastexpress/game/logic.cpp | 28 ++++----- 3 files changed, 111 insertions(+), 24 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp index 81189ae633..25db782c62 100644 --- a/engines/lastexpress/game/inventory.cpp +++ b/engines/lastexpress/game/inventory.cpp @@ -45,7 +45,7 @@ namespace LastExpress { Inventory::Inventory(LastExpressEngine *engine) : _engine(engine), _selectedItem(kItemNone), _highlightedItem(kItemNone), _itemsShown(0), _showingHourGlass(false), _blinkingEgg(false), _blinkingTime(0), _blinkingInterval(_defaultBlinkingInterval), _blinkingBrightness(1), - _useMagnifier(false), _flag1(false), _isOpened(false), _eggHightlighted(false), _itemScene(NULL) { + _useMagnifier(false), _portraitHighlighted(false), _isOpened(false), _eggHightlighted(false), _itemScene(NULL) { _inventoryRect = Common::Rect(0, 0, 32, 32); _menuRect = Common::Rect(608, 448, 640, 480); @@ -143,6 +143,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448, 1); askForRedraw(); } + _eggHightlighted = false; } } else { @@ -159,7 +160,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { // If clicked, show the menu if (ev.type == Common::EVENT_LBUTTONDOWN) { _eggHightlighted = false; - _flag1 = false; + _portraitHighlighted = false; _isOpened = false; getSound()->playSoundWithSubtitles("LIB039.SND", SoundManager::kFlagMenuClock, kEntityPlayer); @@ -178,14 +179,95 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { // Selected item if (ev.mouse.x >= 32) { - // TODO + if (_isOpened) { + // If clicked + if (ev.type == Common::EVENT_LBUTTONDOWN) { + if (_highlightedItem != kItemNone) { + error("[Inventory::handleMouseEvent] Click on highlighted item not implemented"); + } + } else { + error("[Inventory::handleMouseEvent] Default handling of open menu not implemented"); + } + } else { + if (_portraitHighlighted) { + drawItem((CursorStyle)getProgress().portrait, 0, 0, 1); + askForRedraw(); + _portraitHighlighted = false; + } + + if (_selectedItem != kItemNone) { + error("[Inventory::handleMouseEvent] Default handling of selected item not implemented"); + } + } return; } // Opened inventory if (ev.mouse.y >= 32) { - // TODO + if (!_isOpened) { + if (_portraitHighlighted) { + drawItem((CursorStyle)getProgress().portrait, 0, 0, 1); + askForRedraw(); + _portraitHighlighted = false; + } + + return; + } + + if (ev.type == Common::EVENT_LBUTTONDOWN) { + error("[Inventory::handleMouseEvent] Click on open inventory item not implemented"); + + return; + } + + uint32 index = 0; + if (_highlightedItem != kItemNone) { + error("[Inventory::handleMouseEvent] Computing of open inventory clicked item not implemented"); + } + + drawItem((CursorStyle)getProgress().portrait, 0, 0, 1); + + // TODO clear items on inventory surface before redraw + + // Load the scene if an item has been selected + if (index) { + error("[Inventory::handleMouseEvent] Loading of item scene not implemented"); + + _isOpened = false; + + return; + } + + // Draw the selected item if any + if (!_selectedItem || get(_selectedItem)->manualSelect) { + _selectedItem = getFirstExaminableItem(); + + if (_selectedItem) { + drawItem(get(_selectedItem)->cursor, 44, 0); + } else { + clearSelectedItem(); + } + askForRedraw(); + } + + // Stop processing if we are not looking at an item already + if (!getState()->sceneUseBackup) { + _isOpened = false; + return; + } + + SceneIndex scene = kSceneNone; + if (getState()->sceneBackup2) { + scene = getState()->sceneBackup2; + getState()->sceneBackup2 = kSceneNone; + } else { + error("[Inventory::handleMouseEvent] Processing of item scene not implemented"); + } + + getScenes()->loadScene(scene); + + _isOpened = false; return; } @@ -202,9 +284,9 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { return; } - if (!_flag1 && !_isOpened) { + if (!_portraitHighlighted && !_isOpened) { drawItem((CursorStyle)getProgress().portrait, 0, 0); - _flag1 = true; + _portraitHighlighted = true; } else if (!_isOpened || (ev.type == Common::EVENT_LBUTTONDOWN || ev.type == Common::EVENT_LBUTTONUP)) { // Do nothing } else if (_isOpened) { @@ -239,7 +321,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { } } - _flag1 = true; + _portraitHighlighted = true; } // Draw highlighted item @@ -511,9 +593,13 @@ void Inventory::drawItem(CursorStyle id, uint16 x, uint16 y, int16 brightnessInd _engine->getGraphicsManager()->draw(&icon, GraphicsManager::kBackgroundInventory); } +void Inventory::clearSelectedItem() { + _engine->getGraphicsManager()->clear(GraphicsManager::kBackgroundInventory, Common::Rect(44, 0, 44 + 32, 32)); +} + // Close inventory: clear items and reset icon void Inventory::open() { - _flag1 = false; + _portraitHighlighted = false; _isOpened = true; // Draw highlighted portrait diff --git a/engines/lastexpress/game/inventory.h b/engines/lastexpress/game/inventory.h index 860f8257fe..b38ffa849e 100644 --- a/engines/lastexpress/game/inventory.h +++ b/engines/lastexpress/game/inventory.h @@ -120,7 +120,7 @@ public: // State bool isMagnifierInUse() { return _useMagnifier; } - bool isFlag1() { return _flag1; } + bool isPortraitHighlighted() { return _portraitHighlighted; } bool isOpened() { return _isOpened; } bool isEggHighlighted() { return _eggHightlighted; } @@ -154,7 +154,7 @@ private: // Flags bool _useMagnifier; - bool _flag1; + bool _portraitHighlighted; bool _isOpened; bool _eggHightlighted; @@ -175,6 +175,7 @@ private: bool isItemSceneParameter(InventoryItem item) const; void drawItem(CursorStyle id, uint16 x, uint16 y, int16 brighnessIndex = -1); + void clearSelectedItem(); }; } // End of namespace LastExpress diff --git a/engines/lastexpress/game/logic.cpp b/engines/lastexpress/game/logic.cpp index bfed65eb4a..83e067f67c 100644 --- a/engines/lastexpress/game/logic.cpp +++ b/engines/lastexpress/game/logic.cpp @@ -89,7 +89,7 @@ Logic::~Logic() { #define REDRAW_CURSOR() { \ if (getInventory()->isMagnifierInUse()) \ _engine->getCursor()->setStyle(kCursorMagnifier); \ - if (getInventory()->isFlag1() \ + if (getInventory()->isPortraitHighlighted() \ || getInventory()->isOpened() \ || getInventory()->isEggHighlighted()) \ _engine->getCursor()->setStyle(kCursorNormal); \ @@ -104,7 +104,7 @@ void Logic::eventMouse(const Common::Event &ev) { getFlags()->mouseRightClick = false; // Process event flags - if (ev.type == Common::EVENT_LBUTTONUP) { + if (ev.type == Common::EVENT_LBUTTONDOWN) { if (getFlags()->frameInterval) _ignoreFrameInterval = false; @@ -113,7 +113,7 @@ void Logic::eventMouse(const Common::Event &ev) { } if (getFlags()->flag_0) { - if (ev.type == Common::EVENT_LBUTTONUP || ev.type == Common::EVENT_RBUTTONUP) { + if (ev.type == Common::EVENT_LBUTTONDOWN || ev.type == Common::EVENT_RBUTTONDOWN) { getFlags()->flag_0 = false; getFlags()->shouldRedraw = true; updateCursor(true); @@ -143,7 +143,7 @@ void Logic::eventMouse(const Common::Event &ev) { && !getProgress().isEggOpen && !getEntities()->isPlayerPosition(kCarGreenSleeping, 59) && !getEntities()->isPlayerPosition(kCarGreenSleeping, 76) - && !getInventory()->isFlag1() + && !getInventory()->isPortraitHighlighted() && !getInventory()->isOpened() && !getInventory()->isEggHighlighted() && !getInventory()->isMagnifierInUse()) { @@ -173,7 +173,7 @@ void Logic::eventMouse(const Common::Event &ev) { if (getInventory()->getSelectedItem() == kItemMatch && (getEntities()->isPlayerInCar(kCarGreenSleeping) || getEntities()->isPlayerInCar(kCarRedSleeping)) && getProgress().jacket == kJacketGreen - && !getInventory()->isFlag1() + && !getInventory()->isPortraitHighlighted() && !getInventory()->isOpened() && !getInventory()->isEggHighlighted() && !getInventory()->isMagnifierInUse() @@ -198,7 +198,7 @@ void Logic::eventMouse(const Common::Event &ev) { // Handle entity item case EntityIndex entityIndex = getEntities()->canInteractWith(ev.mouse); if (entityIndex - && !getInventory()->isFlag1() + && !getInventory()->isPortraitHighlighted() && !getInventory()->isOpened() && !getInventory()->isEggHighlighted() && !getInventory()->isMagnifierInUse()) { @@ -223,17 +223,17 @@ void Logic::eventMouse(const Common::Event &ev) { ////////////////////////////////////////////////////////////////////////// // Handle standard actions - if (getInventory()->isFlag1() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) + if (getInventory()->isPortraitHighlighted() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) _engine->getCursor()->setStyle(kCursorNormal); - if (hotspotHandled || getInventory()->isFlag1() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) + if (hotspotHandled || getInventory()->isPortraitHighlighted() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) return; // Magnifier in use if (getInventory()->isMagnifierInUse()) { _engine->getCursor()->setStyle(kCursorMagnifier); - if (getInventory()->isFlag1() + if (getInventory()->isPortraitHighlighted() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) _engine->getCursor()->setStyle(kCursorNormal); @@ -518,7 +518,7 @@ void Logic::updateCursor(bool) const { /* the cursor is always updated, even whe || getProgress().isEggOpen || getEntities()->isPlayerPosition(kCarGreenSleeping, 59) || getEntities()->isPlayerPosition(kCarGreenSleeping, 76) - || getInventory()->isFlag1() + || getInventory()->isPortraitHighlighted() || getInventory()->isOpened() || getInventory()->isEggHighlighted() || getInventory()->isMagnifierInUse()) { @@ -526,7 +526,7 @@ void Logic::updateCursor(bool) const { /* the cursor is always updated, even whe if (getInventory()->getSelectedItem() != kItemMatch || (!getEntities()->isPlayerInCar(kCarGreenSleeping) && !getEntities()->isPlayerInCar(kCarRedSleeping)) || getProgress().jacket != kJacketGreen - || getInventory()->isFlag1() + || getInventory()->isPortraitHighlighted() || getInventory()->isOpened() || getInventory()->isEggHighlighted() || getInventory()->isMagnifierInUse() @@ -536,7 +536,7 @@ void Logic::updateCursor(bool) const { /* the cursor is always updated, even whe EntityIndex entity = getEntities()->canInteractWith(getCoords()); if (entity - && !getInventory()->isFlag1() + && !getInventory()->isPortraitHighlighted() && !getInventory()->isOpened() && !getInventory()->isEggHighlighted() && !getInventory()->isMagnifierInUse()) { @@ -550,7 +550,7 @@ void Logic::updateCursor(bool) const { /* the cursor is always updated, even whe } if (!interact - && !getInventory()->isFlag1() + && !getInventory()->isPortraitHighlighted() && !getInventory()->isOpened() && !getInventory()->isEggHighlighted() && !getInventory()->isMagnifierInUse()) { @@ -587,7 +587,7 @@ void Logic::updateCursor(bool) const { /* the cursor is always updated, even whe if (getInventory()->isMagnifierInUse()) style = kCursorMagnifier; - if (getInventory()->isFlag1() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) + if (getInventory()->isPortraitHighlighted() || getInventory()->isOpened() || getInventory()->isEggHighlighted()) style = kCursorNormal; _engine->getCursor()->setStyle(style); -- cgit v1.2.3 From 3088acf69a41dc0e942faad1b624fe097c690a3e Mon Sep 17 00:00:00 2001 From: Littleboy Date: Wed, 4 May 2011 10:10:46 -0400 Subject: LASTEXPRESS: Add button pressed state for inventory handling --- engines/lastexpress/game/inventory.cpp | 6 ++++-- engines/lastexpress/game/state.h | 6 ++++++ engines/lastexpress/lastexpress.cpp | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp index 25db782c62..5df745d641 100644 --- a/engines/lastexpress/game/inventory.cpp +++ b/engines/lastexpress/game/inventory.cpp @@ -186,7 +186,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { error("[Inventory::handleMouseEvent] Click on highlighted item not implemented"); } } else { - error("[Inventory::handleMouseEvent] Default handling of open menu not implemented"); + warning("[Inventory::handleMouseEvent] Default handling of open menu not implemented"); } } else { if (_portraitHighlighted) { @@ -251,6 +251,8 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { askForRedraw(); } + return; + // Stop processing if we are not looking at an item already if (!getState()->sceneUseBackup) { _isOpened = false; @@ -287,7 +289,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { if (!_portraitHighlighted && !_isOpened) { drawItem((CursorStyle)getProgress().portrait, 0, 0); _portraitHighlighted = true; - } else if (!_isOpened || (ev.type == Common::EVENT_LBUTTONDOWN || ev.type == Common::EVENT_LBUTTONUP)) { + } else if (!_isOpened || getFlags()->mouseLeftPressed) { // Do nothing } else if (_isOpened) { close(); diff --git a/engines/lastexpress/game/state.h b/engines/lastexpress/game/state.h index 4196bfe06a..663550acc2 100644 --- a/engines/lastexpress/game/state.h +++ b/engines/lastexpress/game/state.h @@ -566,6 +566,9 @@ public: bool mouseLeftClick; bool mouseRightClick; + bool mouseLeftPressed; + bool mouseRightPressed; + bool flag_entities_0; bool flag_entities_1; @@ -587,6 +590,9 @@ public: mouseRightClick = false; mouseLeftClick = false; + mouseLeftPressed = false; + mouseRightPressed = false; + flag_entities_0 = false; flag_entities_1 = false; diff --git a/engines/lastexpress/lastexpress.cpp b/engines/lastexpress/lastexpress.cpp index 7c08fef627..535f5e86b7 100644 --- a/engines/lastexpress/lastexpress.cpp +++ b/engines/lastexpress/lastexpress.cpp @@ -215,6 +215,7 @@ bool LastExpressEngine::handleEvents() { case Common::EVENT_LBUTTONUP: case Common::EVENT_LBUTTONDOWN: getGameLogic()->getGameState()->getGameFlags()->mouseLeftClick = true; + getGameLogic()->getGameState()->getGameFlags()->mouseLeftPressed = (ev.type == Common::EVENT_LBUTTONDOWN) ? true : false; // Adjust frameInterval flag if (_frameCounter < _lastFrameCount + 30) @@ -228,6 +229,8 @@ bool LastExpressEngine::handleEvents() { case Common::EVENT_RBUTTONUP: case Common::EVENT_RBUTTONDOWN: getGameLogic()->getGameState()->getGameFlags()->mouseRightClick = true; + getGameLogic()->getGameState()->getGameFlags()->mouseRightPressed = (ev.type == Common::EVENT_RBUTTONDOWN) ? true : false; + if (_eventMouse && _eventMouse->isValid()) (*_eventMouse)(ev); break; -- cgit v1.2.3 From 8d4622d70dc6f9d6b2788c849a0dfb0beb2ecc96 Mon Sep 17 00:00:00 2001 From: Littleboy Date: Wed, 4 May 2011 10:12:14 -0400 Subject: LASTEXPRESS: Draw portrait non-highlighted in Inventory::show() --- engines/lastexpress/game/inventory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp index 5df745d641..a8a6556626 100644 --- a/engines/lastexpress/game/inventory.cpp +++ b/engines/lastexpress/game/inventory.cpp @@ -340,7 +340,7 @@ void Inventory::show() { askForRedraw(); // Show portrait (first draw, cannot be highlighted) - drawItem((CursorStyle)getProgress().portrait, 0, 0); + drawItem((CursorStyle)getProgress().portrait, 0, 0, 1); // Show selected item if (_selectedItem != kItemNone) @@ -599,7 +599,7 @@ void Inventory::clearSelectedItem() { _engine->getGraphicsManager()->clear(GraphicsManager::kBackgroundInventory, Common::Rect(44, 0, 44 + 32, 32)); } -// Close inventory: clear items and reset icon +// Open inventory: show portrait selected and draw contents void Inventory::open() { _portraitHighlighted = false; _isOpened = true; -- cgit v1.2.3 From 2bc865f01af8733e8411eb4b50bfb0d3b29dd2a5 Mon Sep 17 00:00:00 2001 From: Littleboy Date: Tue, 10 May 2011 18:19:01 -0400 Subject: LASTEXPRESS: Implement highlight of inventory items --- engines/lastexpress/game/inventory.cpp | 40 ++++++++++++++++++++-------------- engines/lastexpress/game/inventory.h | 10 ++++----- 2 files changed, 29 insertions(+), 21 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp index a8a6556626..05348fb5a4 100644 --- a/engines/lastexpress/game/inventory.cpp +++ b/engines/lastexpress/game/inventory.cpp @@ -43,13 +43,13 @@ namespace LastExpress { -Inventory::Inventory(LastExpressEngine *engine) : _engine(engine), _selectedItem(kItemNone), _highlightedItem(kItemNone), _itemsShown(0), +Inventory::Inventory(LastExpressEngine *engine) : _engine(engine), _selectedItem(kItemNone), _highlightedItemIndex(0), _itemsShown(0), _showingHourGlass(false), _blinkingEgg(false), _blinkingTime(0), _blinkingInterval(_defaultBlinkingInterval), _blinkingBrightness(1), _useMagnifier(false), _portraitHighlighted(false), _isOpened(false), _eggHightlighted(false), _itemScene(NULL) { - _inventoryRect = Common::Rect(0, 0, 32, 32); - _menuRect = Common::Rect(608, 448, 640, 480); - _selectedRect = Common::Rect(44, 0, 76, 32); + //_inventoryRect = Common::Rect(0, 0, 32, 32); + _menuEggRect = Common::Rect(608, 448, 640, 480); + //_selectedItemRect = Common::Rect(44, 0, 76, 32); init(); } @@ -136,7 +136,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { _useMagnifier = false; // Egg (menu) - if (!_menuRect.contains(ev.mouse)) { + if (!_menuEggRect.contains(ev.mouse)) { // Remove highlight if needed if (_eggHightlighted) { if (!getGlobalTimer()) { @@ -182,7 +182,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { if (_isOpened) { // If clicked if (ev.type == Common::EVENT_LBUTTONDOWN) { - if (_highlightedItem != kItemNone) { + if (_highlightedItemIndex != 0) { error("[Inventory::handleMouseEvent] Click on highlighted item not implemented"); } } else { @@ -215,14 +215,21 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { return; } - if (ev.type == Common::EVENT_LBUTTONDOWN) { - error("[Inventory::handleMouseEvent] Click on open inventory item not implemented"); + // Change highlights on item list + if (getFlags()->mouseLeftPressed) { + uint32 index = ev.mouse.y / 40; + + if (_highlightedItemIndex && _highlightedItemIndex != index) + drawHighlight(_highlightedItemIndex, true); + + if (index && index <= _itemsShown && index != _highlightedItemIndex) + drawHighlight(index, false); return; } uint32 index = 0; - if (_highlightedItem != kItemNone) { + if (_highlightedItemIndex) { error("[Inventory::handleMouseEvent] Computing of open inventory clicked item not implemented"); } @@ -327,8 +334,8 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { } // Draw highlighted item - if (_highlightedItem) - drawHighlight(); + if (_highlightedItemIndex) + drawHighlight(_highlightedItemIndex, true); } } @@ -640,8 +647,8 @@ void Inventory::close() { askForRedraw(); } -void Inventory::drawHighlight() { - int32 count = 0; +void Inventory::drawHighlight(uint32 currentIndex, bool reset) { + uint32 count = 0; uint32 index = 0; for (uint32 i = 1; i < ARRAYSIZE(_entries); i++) { @@ -653,7 +660,7 @@ void Inventory::drawHighlight() { if (count < 11) { ++count; - if (count == _highlightedItem) { + if (count == currentIndex) { index = i; break; } @@ -661,8 +668,9 @@ void Inventory::drawHighlight() { } if (index) { - drawItem(_entries[index].cursor, 0, 40 * _highlightedItem + 4, 1); - _highlightedItem = kItemNone; + drawItem(_entries[index].cursor, 0, 40 * currentIndex + 4, reset ? 1 : -1); + _highlightedItemIndex = reset ? 0 : currentIndex; + askForRedraw(); } } diff --git a/engines/lastexpress/game/inventory.h b/engines/lastexpress/game/inventory.h index b38ffa849e..301e32d2a7 100644 --- a/engines/lastexpress/game/inventory.h +++ b/engines/lastexpress/game/inventory.h @@ -142,7 +142,7 @@ private: InventoryEntry _entries[32]; InventoryItem _selectedItem; - InventoryItem _highlightedItem; + uint32 _highlightedItemIndex; uint32 _itemsShown; @@ -161,16 +161,16 @@ private: Scene *_itemScene; // Important rects - Common::Rect _inventoryRect; - Common::Rect _menuRect; - Common::Rect _selectedRect; + //Common::Rect _inventoryRect; + Common::Rect _menuEggRect; + //Common::Rect _selectedItemRect; void init(); void open(); void close(); void examine(InventoryItem item); - void drawHighlight(); + void drawHighlight(uint32 currentIndex, bool reset); bool isItemSceneParameter(InventoryItem item) const; -- cgit v1.2.3 From 33c3e19cea2a08fbf26ecbe940763e8ee1c37d28 Mon Sep 17 00:00:00 2001 From: Littleboy Date: Tue, 10 May 2011 18:59:21 -0400 Subject: LASTEXPRESS: Implement item selection and scene loading --- engines/lastexpress/game/inventory.cpp | 107 ++++++++++++++++++++++----------- engines/lastexpress/game/inventory.h | 5 +- 2 files changed, 77 insertions(+), 35 deletions(-) (limited to 'engines/lastexpress') diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp index 05348fb5a4..c4d43d53d7 100644 --- a/engines/lastexpress/game/inventory.cpp +++ b/engines/lastexpress/game/inventory.cpp @@ -49,7 +49,7 @@ Inventory::Inventory(LastExpressEngine *engine) : _engine(engine), _selectedItem //_inventoryRect = Common::Rect(0, 0, 32, 32); _menuEggRect = Common::Rect(608, 448, 640, 480); - //_selectedItemRect = Common::Rect(44, 0, 76, 32); + _selectedItemRect = Common::Rect(44, 0, 76, 32); init(); } @@ -195,7 +195,9 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { _portraitHighlighted = false; } - if (_selectedItem != kItemNone) { + if (_selectedItem != kItemNone + && get(_selectedItem)->scene != kSceneNone + && _selectedItemRect.contains(ev.mouse)) { error("[Inventory::handleMouseEvent] Default handling of selected item not implemented"); } } @@ -205,6 +207,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { // Opened inventory if (ev.mouse.y >= 32) { + // Draw portrait (darkened) if the inventory is closed (and we are not on top of it) if (!_isOpened) { if (_portraitHighlighted) { drawItem((CursorStyle)getProgress().portrait, 0, 0, 1); @@ -215,7 +218,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { return; } - // Change highlights on item list + // Change item highlight on list if (getFlags()->mouseLeftPressed) { uint32 index = ev.mouse.y / 40; @@ -228,37 +231,46 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { return; } - uint32 index = 0; - if (_highlightedItemIndex) { - error("[Inventory::handleMouseEvent] Computing of open inventory clicked item not implemented"); - } + // User released the mouse button, check if we were on a valid item + uint32 index = _highlightedItemIndex ? getItemIndex(_highlightedItemIndex) : 0; + // Reset items and portrait drawItem((CursorStyle)getProgress().portrait, 0, 0, 1); - - // TODO clear items on inventory surface before redraw + _engine->getGraphicsManager()->clear(GraphicsManager::kBackgroundInventory, Common::Rect(0, 44, 32, (int16)(40 * _itemsShown + 40))); + _highlightedItemIndex = 0; + _itemsShown = 0; // Load the scene if an item has been selected if (index) { - error("[Inventory::handleMouseEvent] Loading of item scene not implemented"); - - _isOpened = false; - - return; - } + InventoryEntry entry = _entries[index]; + + // If a scene is affected to the item + if (entry.scene) { + if (getState()->sceneUseBackup) { + if (getFirstExaminableItem() && !getState()->sceneBackup2) + getState()->sceneBackup2 = getState()->scene; + } else { + getState()->sceneUseBackup = true; + getState()->sceneBackup = getState()->scene; + } - // Draw the selected item if any - if (!_selectedItem || get(_selectedItem)->manualSelect) { - _selectedItem = getFirstExaminableItem(); + getScenes()->loadScene(entry.scene); + } - if (_selectedItem) { - drawItem(get(_selectedItem)->cursor, 44, 0); + if (entry.field_2) { + selectItem((InventoryItem)index); } else { - clearSelectedItem(); + drawSelectedItem(); } - askForRedraw(); + + // Set inventory as closed (will cause a cleanup on next call) + _isOpened = false; + + return; } - return; + // Draw the currently selected item + drawSelectedItem(); // Stop processing if we are not looking at an item already if (!getState()->sceneUseBackup) { @@ -271,7 +283,16 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { scene = getState()->sceneBackup2; getState()->sceneBackup2 = kSceneNone; } else { - error("[Inventory::handleMouseEvent] Processing of item scene not implemented"); + if (getEvent(kEventKronosBringFirebird) || getProgress().isEggOpen) { + _isOpened = false; + return; + } + + getState()->sceneUseBackup = false; + scene = getState()->sceneBackup; + + if (getEntities()->getPosition(getScenes()->get(scene)->car, getScenes()->get(scene)->position)) + scene = getScenes()->processIndex(getState()->sceneBackup); } getScenes()->loadScene(scene); @@ -602,6 +623,20 @@ void Inventory::drawItem(CursorStyle id, uint16 x, uint16 y, int16 brightnessInd _engine->getGraphicsManager()->draw(&icon, GraphicsManager::kBackgroundInventory); } +void Inventory::drawSelectedItem() { + // Draw the selected item if any + if (!_selectedItem || get(_selectedItem)->manualSelect) { + _selectedItem = getFirstExaminableItem(); + + if (_selectedItem) { + drawItem(get(_selectedItem)->cursor, 44, 0); + } else { + clearSelectedItem(); + } + askForRedraw(); + } +} + void Inventory::clearSelectedItem() { _engine->getGraphicsManager()->clear(GraphicsManager::kBackgroundInventory, Common::Rect(44, 0, 44 + 32, 32)); } @@ -648,8 +683,17 @@ void Inventory::close() { } void Inventory::drawHighlight(uint32 currentIndex, bool reset) { + uint32 index = getItemIndex(currentIndex); + + if (index) { + drawItem(_entries[index].cursor, 0, 40 * currentIndex + 4, reset ? 1 : -1); + _highlightedItemIndex = reset ? 0 : currentIndex; + askForRedraw(); + } +} + +uint32 Inventory::getItemIndex(uint32 currentIndex) { uint32 count = 0; - uint32 index = 0; for (uint32 i = 1; i < ARRAYSIZE(_entries); i++) { if (!_entries[i].isPresent) @@ -660,18 +704,13 @@ void Inventory::drawHighlight(uint32 currentIndex, bool reset) { if (count < 11) { ++count; - if (count == currentIndex) { - index = i; - break; - } + + if (count == currentIndex) + return i; } } - if (index) { - drawItem(_entries[index].cursor, 0, 40 * currentIndex + 4, reset ? 1 : -1); - _highlightedItemIndex = reset ? 0 : currentIndex; - askForRedraw(); - } + return 0; } } // End of namespace LastExpress diff --git a/engines/lastexpress/game/inventory.h b/engines/lastexpress/game/inventory.h index 301e32d2a7..9a885438eb 100644 --- a/engines/lastexpress/game/inventory.h +++ b/engines/lastexpress/game/inventory.h @@ -163,7 +163,7 @@ private: // Important rects //Common::Rect _inventoryRect; Common::Rect _menuEggRect; - //Common::Rect _selectedItemRect; + Common::Rect _selectedItemRect; void init(); @@ -171,10 +171,13 @@ private: void close(); void examine(InventoryItem item); void drawHighlight(uint32 currentIndex, bool reset); + uint32 getItemIndex(uint32 currentIndex); bool isItemSceneParameter(InventoryItem item) const; void drawItem(CursorStyle id, uint16 x, uint16 y, int16 brighnessIndex = -1); + + void drawSelectedItem(); void clearSelectedItem(); }; -- cgit v1.2.3