diff options
author | Ľubomír Remák | 2018-07-15 18:06:52 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | 2ee0a900598caa2e91b7261eb886793b74f9e25e (patch) | |
tree | 72e381ea2c71e2af494aea48e3f468500bff7ac9 | |
parent | 2cd1728f42664643b1bb20f76b5350ef40401786 (diff) | |
download | scummvm-rg350-2ee0a900598caa2e91b7261eb886793b74f9e25e.tar.gz scummvm-rg350-2ee0a900598caa2e91b7261eb886793b74f9e25e.tar.bz2 scummvm-rg350-2ee0a900598caa2e91b7261eb886793b74f9e25e.zip |
MUTATIONOFJB: Change cursor color when it's under entity.
-rw-r--r-- | engines/mutationofjb/game.cpp | 4 | ||||
-rw-r--r-- | engines/mutationofjb/mutationofjb.cpp | 96 | ||||
-rw-r--r-- | engines/mutationofjb/mutationofjb.h | 12 |
3 files changed, 96 insertions, 16 deletions
diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp index 190b62e240..0cb6f53fe1 100644 --- a/engines/mutationofjb/game.cpp +++ b/engines/mutationofjb/game.cpp @@ -57,8 +57,6 @@ Game::Game(MutationOfJBEngine *vm) _room = new Room(this, _vm->getScreen()); _gui.init(); - - changeScene(13, false); // Initial scene. } Common::RandomSource &Game::getRandomSource() { @@ -126,6 +124,8 @@ Script *Game::changeSceneLoadScript(uint8 sceneId, bool partB) { localScript->loadFromStream(scriptFile); scriptFile.close(); + _vm->updateCursor(); + return localScript; } diff --git a/engines/mutationofjb/mutationofjb.cpp b/engines/mutationofjb/mutationofjb.cpp index b535e19c40..cdaa03788b 100644 --- a/engines/mutationofjb/mutationofjb.cpp +++ b/engines/mutationofjb/mutationofjb.cpp @@ -43,7 +43,8 @@ MutationOfJBEngine::MutationOfJBEngine(OSystem *syst) : Engine(syst), _console(nullptr), _screen(nullptr), - _mapObjectId(0) { + _mapObjectId(0), + _cursorState(CURSOR_IDLE) { debug("MutationOfJBEngine::MutationOfJBEngine"); } @@ -53,8 +54,6 @@ MutationOfJBEngine::~MutationOfJBEngine() { void MutationOfJBEngine::setupCursor() { - const uint8 white[] = {0xFF, 0xFF, 0xFF}; - const uint8 cursor[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -73,13 +72,24 @@ void MutationOfJBEngine::setupCursor() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - _screen->setPalette(white, 0xFF, 1); + updateCursorPalette(); CursorMan.disableCursorPalette(true); CursorMan.pushCursor(cursor, 15, 15, 7, 7, 0); CursorMan.showMouse(true); } +void MutationOfJBEngine::updateCursorPalette() { + if (_cursorState == CURSOR_OFF) { + return; + } + + const uint8 white[] = {0xFF, 0xFF, 0xFF}; + const uint8 blue[] = {0x00, 0xFF, 0xC3}; + + _screen->setPalette(_cursorState == CURSOR_ACTIVE ? blue : white, 0xFF, 1); +} + Graphics::Screen *MutationOfJBEngine::getScreen() const { return _screen; } @@ -88,12 +98,36 @@ Game &MutationOfJBEngine::getGame() { return *_game; } +void MutationOfJBEngine::setCursorState(CursorState cursorState) { + if (_cursorState == cursorState) { + return; + } + + _cursorState = cursorState; + updateCursorPalette(); +} + +void MutationOfJBEngine::updateCursor() { + if (_cursorState == CURSOR_OFF) { + return; + } + + if (_game->isCurrentSceneMap()) { + if (_cursorState != CURSOR_IDLE) { + _cursorState = CURSOR_IDLE; + updateCursorPalette(); + } + } else { + const Common::Point point = _eventMan->getMousePos(); + updateCursorHitTest(point.x, point.y); + } +} + void MutationOfJBEngine::handleNormalScene(const Common::Event &event) { Scene *const scene = _game->getGameData().getCurrentScene(); switch (event.type) { - case Common::EVENT_LBUTTONDOWN: - { + case Common::EVENT_LBUTTONDOWN: { const int16 x = event.mouse.x; const int16 y = event.mouse.y; @@ -108,6 +142,15 @@ void MutationOfJBEngine::handleNormalScene(const Common::Event &event) { } break; } + case Common::EVENT_MOUSEMOVE: { + const int16 x = event.mouse.x; + const int16 y = event.mouse.y; + + if (_cursorState != CURSOR_OFF) { + updateCursorHitTest(x, y); + } + break; + } default: break; } @@ -126,8 +169,7 @@ void MutationOfJBEngine::handleMapScene(const Common::Event &event) { Scene *const scene = _game->getGameData().getCurrentScene(); switch (event.type) { - case Common::EVENT_LBUTTONDOWN: - { + case Common::EVENT_LBUTTONDOWN: { const int16 x = event.mouse.x; const int16 y = event.mouse.y; @@ -140,8 +182,7 @@ void MutationOfJBEngine::handleMapScene(const Common::Event &event) { } break; } - case Common::EVENT_MOUSEMOVE: - { + case Common::EVENT_MOUSEMOVE: { const int16 x = event.mouse.x; const int16 y = event.mouse.y; @@ -177,6 +218,33 @@ void MutationOfJBEngine::handleMapScene(const Common::Event &event) { } } +void MutationOfJBEngine::updateCursorHitTest(int16 x, int16 y) { + Scene *const scene = _game->getGameData().getCurrentScene(); + if (!scene) { + return; + } + + bool entityHit = false; + if (Door *const door = scene->findDoor(x, y)) { + if (door->_destSceneId != 0) { + entityHit = true; + } + } else if (Static *const stat = scene->findStatic(x, y)) { + if (stat->_active == 1) { + entityHit = true; + } + } + bool cursorPaletteChange = false; + if ((_cursorState == CURSOR_ACTIVE && !entityHit) || (_cursorState == CURSOR_IDLE && entityHit)) { + cursorPaletteChange = true; + } + _cursorState = entityHit ? CURSOR_ACTIVE : CURSOR_IDLE; + if (cursorPaletteChange) { + updateCursorPalette(); + } + +} + Common::Error MutationOfJBEngine::run() { debug("MutationOfJBEngine::run"); @@ -188,20 +256,20 @@ Common::Error MutationOfJBEngine::run() { setupCursor(); + _game->changeScene(13, false); // Initial scene. + while (!shouldQuit()) { Common::Event event; while (_eventMan->pollEvent(event)) { switch (event.type) { - case Common::EVENT_KEYDOWN: - { + case Common::EVENT_KEYDOWN: { if ((event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d) || event.kbd.ascii == '~' || event.kbd.ascii == '#') { _console->attach(); } break; } - case Common::EVENT_KEYUP: - { + case Common::EVENT_KEYUP: { switch (event.kbd.ascii) { case 'g': _game->setCurrentAction(ActionInfo::Walk); diff --git a/engines/mutationofjb/mutationofjb.h b/engines/mutationofjb/mutationofjb.h index 348165f081..050800ee71 100644 --- a/engines/mutationofjb/mutationofjb.h +++ b/engines/mutationofjb/mutationofjb.h @@ -41,16 +41,26 @@ class Game; class MutationOfJBEngine : public Engine { public: + enum CursorState { + CURSOR_OFF, + CURSOR_IDLE, + CURSOR_ACTIVE + }; + MutationOfJBEngine(OSystem *syst); ~MutationOfJBEngine(); virtual Common::Error run(); Graphics::Screen *getScreen() const; Game &getGame(); + void setCursorState(CursorState cursorState); + void updateCursor(); private: bool loadGameData(bool partB); void setupCursor(); + void updateCursorHitTest(int16 x, int16 y); + void updateCursorPalette(); void handleNormalScene(const Common::Event &event); void handleMapScene(const Common::Event &event); @@ -58,6 +68,8 @@ private: Graphics::Screen *_screen; Game *_game; uint8 _mapObjectId; + + CursorState _cursorState; }; |