Permalink
Browse files

MUTATIONOFJB: Change cursor color when it's under entity.

  • Loading branch information...
LubomirR committed Jul 15, 2018
1 parent dae4d1a commit 4cf3ad74121be73ff05da623f3fc2ae44868b09d
Showing with 96 additions and 16 deletions.
  1. +2 −2 engines/mutationofjb/game.cpp
  2. +82 −14 engines/mutationofjb/mutationofjb.cpp
  3. +12 −0 engines/mutationofjb/mutationofjb.h
@@ -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;
}

@@ -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);
@@ -41,23 +41,35 @@ 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);

Console *_console;
Graphics::Screen *_screen;
Game *_game;
uint8 _mapObjectId;

CursorState _cursorState;
};


0 comments on commit 4cf3ad7

Please sign in to comment.