Skip to content

Commit

Permalink
MOHAWK: Fix the inventory being visible when scripts are running
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK authored and sev- committed Jul 3, 2017
1 parent 64c1a1d commit 8c6cd98
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 57 deletions.
10 changes: 2 additions & 8 deletions engines/mohawk/riven.cpp
Expand Up @@ -202,14 +202,6 @@ void MohawkEngine_Riven::doFrame() {
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
_stack->onMouseMove(event.mouse);

if (!(getFeatures() & GF_DEMO)) {
// Check to show the inventory, but it is always "showing" in the demo
if (_eventMan->getMousePos().y >= 392)
_inventory->show();
else
_inventory->hide();
}
break;
case Common::EVENT_LBUTTONDOWN:
_stack->onMouseDown(_eventMan->getMousePos());
Expand Down Expand Up @@ -274,6 +266,8 @@ void MohawkEngine_Riven::doFrame() {
_scriptMan->runQueuedScripts();
}

_inventory->onFrame();

// Update the screen once per frame
_system->updateScreen();

Expand Down
88 changes: 49 additions & 39 deletions engines/mohawk/riven_inventory.cpp
Expand Up @@ -31,9 +31,9 @@
namespace Mohawk {

RivenInventory::RivenInventory(MohawkEngine_Riven *vm) :
_vm(vm) {

_inventoryDrawn = false;
_vm(vm),
_inventoryDrawn(false),
_forceVisible(false) {

_atrusJournalRect1 = Common::Rect(295, 402, 313, 426);
_atrusJournalRect2 = Common::Rect(259, 402, 278, 426);
Expand All @@ -48,11 +48,7 @@ RivenInventory::~RivenInventory() {

}

void RivenInventory::show() {
// Don't redraw the inventory
if (_inventoryDrawn)
return;

void RivenInventory::draw() {
// Clear the inventory area
clearArea();

Expand All @@ -63,17 +59,13 @@ void RivenInventory::show() {
// but has hacked tBMP 101 with "EXIT". *sigh*
_vm->_gfx->drawExtrasImageToScreen(101, _demoExitRect);
} else {
// We don't want to show the inventory on setup screens or in other journals.
if (_vm->getStack()->getId() == kStackAspit)
return;

// There are three books and three vars. We have three different
// combinations. At the start you have just Atrus' journal. Later,
// you get Catherine's journal and the trap book. Near the end,
// you lose the trap book and have just the two journals.

bool hasCathBook = _vm->_vars["acathbook"] != 0;
bool hasTrapBook = _vm->_vars["atrapbook"] != 0;
bool hasCathBook = _vm->_vars["rrebel"] == 5 || _vm->_vars["rrebel"] == 6;
bool hasTrapBook = _vm->_vars["atrapbook"] == 1;

if (!hasCathBook) {
_vm->_gfx->drawExtrasImageToScreen(101, _atrusJournalRect1);
Expand All @@ -86,20 +78,6 @@ void RivenInventory::show() {
_vm->_gfx->drawExtrasImageToScreen(100, _trapBookRect3);
}
}

_vm->_system->updateScreen();
_inventoryDrawn = true;
}

void RivenInventory::hide() {
// Don't hide the inventory twice
if (!_inventoryDrawn)
return;

// Clear the area
clearArea();

_inventoryDrawn = false;
}

void RivenInventory::clearArea() {
Expand All @@ -116,9 +94,9 @@ void RivenInventory::clearArea() {
}

void RivenInventory::checkClick(const Common::Point &mousePos) {
// Don't even bother. We're not in the inventory portion of the screen.
if (mousePos.y < 392)
return;
if (!isVisible()) {
return; // Don't even bother.
}

// In the demo, check if we've clicked the exit button
if (_vm->getFeatures() & GF_DEMO) {
Expand Down Expand Up @@ -149,37 +127,31 @@ void RivenInventory::checkClick(const Common::Point &mousePos) {

// See RivenGraphics::show() for an explanation
// of the variables' meanings.
bool hasCathBook = _vm->_vars["acathbook"] != 0;
bool hasTrapBook = _vm->_vars["atrapbook"] != 0;
bool hasCathBook = _vm->_vars["rrebel"] == 5 || _vm->_vars["rrebel"] == 6;
bool hasTrapBook = _vm->_vars["atrapbook"] == 1;

// Go to the book if a hotspot contains the mouse
if (!hasCathBook) {
if (_atrusJournalRect1.contains(mousePos)) {
hide();
_vm->changeToStack(kStackAspit);
_vm->changeToCard(5);
}
} else if (!hasTrapBook) {
if (_atrusJournalRect2.contains(mousePos)) {
hide();
_vm->changeToStack(kStackAspit);
_vm->changeToCard(5);
} else if (_cathJournalRect2.contains(mousePos)) {
hide();
_vm->changeToStack(kStackAspit);
_vm->changeToCard(6);
}
} else {
if (_atrusJournalRect3.contains(mousePos)) {
hide();
_vm->changeToStack(kStackAspit);
_vm->changeToCard(5);
} else if (_cathJournalRect3.contains(mousePos)) {
hide();
_vm->changeToStack(kStackAspit);
_vm->changeToCard(6);
} else if (_trapBookRect3.contains(mousePos)) {
hide();
_vm->changeToStack(kStackAspit);
_vm->changeToCard(7);
}
Expand All @@ -199,4 +171,42 @@ void RivenInventory::backFromItemScript() const {
_vm->_scriptMan->runScript(backScript, true);
}

bool RivenInventory::isVisible() const {
if (_forceVisible) {
return true;
}

if (_vm->getFeatures() & GF_DEMO) {
// The inventory is always visible in the demo
return true;
}

// We don't want to show the inventory on setup screens or in other journals.
if (_vm->getStack()->getId() == kStackAspit)
return false;

// We don't want to show the inventory while scripts are running
if (_vm->_scriptMan->runningQueuedScripts())
return false;

Common::Point mouse = _vm->getStack()->getMousePosition();
return mouse.y >= 392;
}

void RivenInventory::onFrame() {
bool visible = isVisible();

if (visible && !_inventoryDrawn) {
draw();
_inventoryDrawn = true;
} else if (!visible && _inventoryDrawn) {
clearArea();
_inventoryDrawn = false;
}
}

void RivenInventory::forceVisible(bool visible) {
_forceVisible = visible;
}

} // End of namespace Mohawk
15 changes: 9 additions & 6 deletions engines/mohawk/riven_inventory.h
Expand Up @@ -39,24 +39,27 @@ class RivenInventory {
RivenInventory(MohawkEngine_Riven *vm);
virtual ~RivenInventory();

/** Make the inventory visible */
void show();

/** Make the inventory invisible */
void hide();

/** Handle a click event in the inventory area */
void checkClick(const Common::Point &mousePos);

/** Go back to the game from an inventory item detail view */
void backFromItemScript() const;

/** Make the inventory visible and draw it as necessary */
void onFrame();

/** Force the inventory to be visible even in situations where it usually is not */
void forceVisible(bool visible);

private:
bool isVisible() const;
void draw();
void clearArea();

MohawkEngine_Riven *_vm;

bool _inventoryDrawn;
bool _forceVisible;

// Rects for the inventory object positions
Common::Rect _atrusJournalRect1;
Expand Down
4 changes: 2 additions & 2 deletions engines/mohawk/riven_stacks/aspit.cpp
Expand Up @@ -333,7 +333,7 @@ void ASpit::xadisablemenuintro(uint16 argc, uint16 *argv) {
// The original also had this shortcut.

// Hide the "exit" button here
_vm->_inventory->hide();
//_vm->_inventory->forceVisible(false);
}

void ASpit::xaenablemenuintro(uint16 argc, uint16 *argv) {
Expand All @@ -342,7 +342,7 @@ void ASpit::xaenablemenuintro(uint16 argc, uint16 *argv) {
// The original also had this shortcut.

// Show the "exit" button here
_vm->_inventory->show();
//_vm->_inventory->forceVisible(true);
}

void ASpit::xademoquit(uint16 argc, uint16 *argv) {
Expand Down
4 changes: 2 additions & 2 deletions engines/mohawk/riven_stacks/ospit.cpp
Expand Up @@ -122,9 +122,9 @@ void OSpit::xbookclick(uint16 argc, uint16 *argv) {
_vm->_sound->playSound(0); // Play the link sound again
_vm->_gfx->scheduleTransition(kRivenTransitionBlend);
_vm->changeToCard(_vm->getStack()->getCardStackId(0x2885)); // Link out!
_vm->_inventory->show();
_vm->_inventory->forceVisible(true);
_vm->delay(2000);
_vm->_inventory->hide();
_vm->_inventory->forceVisible(false);
_vm->_scriptMan->stopAllScripts(); // Stop all running scripts (so we don't remain in the cage)
return;
}
Expand Down

0 comments on commit 8c6cd98

Please sign in to comment.