Permalink
Browse files

MUTATIONOFJB: Fix SETANIM and add support for pickupable statics.

  • Loading branch information...
LubomirR committed Jan 12, 2019
1 parent a97a14c commit b4fed90145e7aa22601de9f32b5a4b0501266d1a
@@ -29,7 +29,7 @@
/** @file
* "SETANIM " <objectId> " " <frame>
*
* Sets the frame for the specified object and redraws it.
* Draws the frame for the specified object without changing the object's current frame.
* If the object is active, it is deactivated.
*/

@@ -51,7 +51,8 @@ Command::ExecuteResult SetObjectFrameCommand::execute(ScriptExecutionContext &sc
Object *const object = scriptExecCtx.getGameData().getCurrentScene()->getObject(_objectId);

object->_active = 0;
scriptExecCtx.getGame().getRoom().drawObject(_objectId);
// The object's current frame is not changed, so use frame override instead.
scriptExecCtx.getGame().getRoom().drawObject(_objectId, _frame);

return Finished;
}
@@ -28,6 +28,7 @@
#include "mutationofjb/gamedata.h"
#include "mutationofjb/mutationofjb.h"
#include "mutationofjb/inventory.h"
#include "mutationofjb/room.h"
#include "mutationofjb/util.h"
#include "mutationofjb/widgets/conversationwidget.h"
#include "mutationofjb/widgets/gamewidget.h"
@@ -405,6 +406,7 @@ void GameScreen::onGameStaticClicked(GameWidget *, Static *stat) {

_game.getGameData().getInventory().addItem(inventoryName);
stat->_active = 0;
_game.getRoom().drawStatic(stat);
}
}
}
@@ -148,11 +148,11 @@ void Room::drawObjectAnimation(uint8 objectId, int animOffset) {
blit_if(_surfaces[animFrame], _background, Common::Point(object->_x, object->_y), ThresholdBlitOperation());
}

void Room::drawObject(uint8 objectId) {
void Room::drawObject(uint8 objectId, uint8 overrideFrame) {
Scene *const currentScene = _game->getGameData().getCurrentScene();
Object *const object = currentScene->getObject(objectId);

drawObjectAnimation(objectId, object->_currentFrame - _objectsStart[objectId - 1] - 1);
drawObjectAnimation(objectId, (overrideFrame ? overrideFrame : object->_currentFrame) - _objectsStart[objectId - 1] - 1);
}

void Room::drawBitmap(uint8 bitmapId) {
@@ -171,6 +171,16 @@ void Room::drawBitmap(uint8 bitmapId) {
drawFrames(bitmap->_roomFrame - 1, bitmap->_roomFrame - 1, bitmapArea, 0xC0);
}

void Room::drawStatic(Static *const stat) {
if (!stat || !stat->allowsImplicitPickup()) {
return;
}

const uint8 frame = stat->_active ? 1 : 2; // Hardcoded values. Active is taken from frame 1 and inactive from frame 2.
const Common::Rect staticArea(stat->_x, stat->_y, stat->_x + stat->_width, stat->_y + stat->_height);
drawFrames(frame, frame, staticArea, 0xC0); // Hardcoded threshold.
}

void Room::drawFrames(uint8 fromFrame, uint8 toFrame, const Common::Rect &area, uint8 threshold) {
GameData &gameData = _game->getGameData();

@@ -195,15 +205,19 @@ void Room::drawFrames(uint8 fromFrame, uint8 toFrame, const Common::Rect &area,
AnimationDecoder decoder(fileName, _background);
decoder.setPartialMode(fromFrame, toFrame, area, threshold);
decoder.decode(nullptr);
if (!area.isEmpty())
_screen->getSubArea(area); // Add dirty rect.
else
_screen->makeAllDirty();
}
}

void Room::initialDraw() {
Scene *const currentScene = _game->getGameData().getCurrentScene();

for (uint8 i = 0; i < currentScene->getNoStatics(); ++i) {
Static *const stat = currentScene->getStatic(i + 1);
if (stat->_active && stat->allowsImplicitPickup()) {
drawStatic(stat);
}
}

for (uint8 i = 0; i < currentScene->getNoObjects(); ++i) {
Object *const obj = currentScene->getObject(i + 1);
if (obj->_active) {
@@ -36,6 +36,7 @@ namespace MutationOfJB {

class EncryptedFile;
class Game;
class Static;

class Room {
public:
@@ -45,8 +46,24 @@ class Room {
Room(Game *game, Graphics::Screen *screen);
bool load(uint8 roomNumber, bool roomB);
void drawObjectAnimation(uint8 objectId, int animOffset);
void drawObject(uint8 objectId);

/**
* Draws an object.
* By default, object's current frame is used, but that can be overridden.
*
* @param objectId ID of object to draw.
* @param overrideFrame Optional frame override.
*/
void drawObject(uint8 objectId, uint8 overrideFrame = 0);
void drawBitmap(uint8 bitmapId);

/**
* Draws a static.
* Only statics that allow implicit pickup are drawable.
*
* @param stat Static.
*/
void drawStatic(Static *stat);
void drawFrames(uint8 fromFrame, uint8 toFrame, const Common::Rect &area = Common::Rect(), uint8 threshold = 0xFF);
void initialDraw();
void redraw(bool useBackgroundBuffer = true);

0 comments on commit b4fed90

Please sign in to comment.