NANCY: Fix curtains in The Vampire Diaries

Fixed the visual artifacts in the inventory box curtains in The Vampire
Diaries. Renamed the Shades class to Curtains to reflect their name in
the original engine.
This commit is contained in:
fracturehill 2021-04-24 17:56:53 +03:00
parent 90c4f0c4dc
commit 8b8d3b38de
4 changed files with 42 additions and 32 deletions

View File

@ -30,7 +30,8 @@ const GameConstants gameConstants[] {
24,
120,
{ 0, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 125, 219, 220, -1 },
{ 110, 111, 112, 113, 114, -1 }
{ 110, 111, 112, 113, 114, -1 },
10
},
// Nancy Drew: Secrets Can Kill
@ -40,7 +41,8 @@ const GameConstants gameConstants[] {
{ 9, 10, 11, 666, 888, 1200, 1250, 1666, -1 },
{ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, -1 }
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, -1 },
7
},
// Nancy Drew: Stay Tuned For Danger
@ -50,7 +52,8 @@ const GameConstants gameConstants[] {
{ -1 }, // No dedicated Map state
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1 }
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1 },
7 // TODO
}
};

View File

@ -33,6 +33,7 @@ struct GameConstants {
uint numEventFlags;
int mapAccessSceneIDs[18];
int eventFlagsToClearOnSceneChange[32];
uint numCurtainAnimationFrames;
};
extern const GameConstants gameConstants[];

View File

@ -41,9 +41,9 @@ namespace UI {
InventoryBox::InventoryBox(RenderObject &redrawFrom) :
RenderObject(redrawFrom, 6),
_scrollbar(nullptr),
_shades(*this, this),
_curtains(*this, this),
_scrollbarPos(0),
_shadesFrameTime(0) {}
_curtainsFrameTime(0) {}
InventoryBox::~InventoryBox() {
_fullInventorySurface.free();
@ -65,12 +65,14 @@ void InventoryBox::init() {
stream.seek(0xD6, SEEK_SET);
for (uint i = 0; i < 14; ++i) {
readRect(stream, _shadesSrc[i]);
uint numFrames = g_nancy->getConstants().numCurtainAnimationFrames;
_curtainsSrc.resize(numFrames * 2);
for (uint i = 0; i < numFrames * 2; ++i) {
readRect(stream, _curtainsSrc[i]);
}
readRect(stream, _screenPosition);
_shadesFrameTime = stream.readUint16LE();
_curtainsFrameTime = stream.readUint16LE();
Common::String inventoryBoxIconsImageName;
readFilename(stream, inventoryBoxIconsImageName);
@ -111,7 +113,7 @@ void InventoryBox::init() {
_scrollbar = new Scrollbar(NancySceneState.getFrame(), 9, scrollbarSrcBounds, scrollbarDefaultPos, scrollbarMaxScroll - scrollbarDefaultPos.y);
_scrollbar->init();
_shades.init();
_curtains.init();
}
void InventoryBox::updateGraphics() {
@ -125,7 +127,7 @@ void InventoryBox::updateGraphics() {
void InventoryBox::registerGraphics() {
RenderObject::registerGraphics();
_scrollbar->registerGraphics();
_shades.registerGraphics();
_curtains.registerGraphics();
}
void InventoryBox::handleInput(NancyInput &input) {
@ -155,8 +157,8 @@ void InventoryBox::handleInput(NancyInput &input) {
void InventoryBox::addItem(int16 itemID) {
if (_order.size() == 0) {
// Adds first item, start shades animation
_shades.setOpen(true);
// Adds first item, start curtains animation
_curtains.setOpen(true);
}
Common::Array<int16> back = _order;
_order.clear();
@ -191,9 +193,9 @@ void InventoryBox::onReorder() {
}
if (_order.size() > 0) {
_shades.setOpen(true);
_curtains.setOpen(true);
} else {
_shades.setOpen(false);
_curtains.setOpen(false);
}
_needsRedraw = true;
@ -225,9 +227,14 @@ void InventoryBox::onScrollbarMove() {
_needsRedraw = true;
}
void InventoryBox::Shades::init() {
void InventoryBox::Curtains::init() {
Common::Rect bounds = _parent->getBounds();
_drawSurface.create(bounds.width(), bounds.height(), g_nancy->_graphicsManager->getScreenPixelFormat());
_drawSurface.create(bounds.width(), bounds.height(), g_nancy->_graphicsManager->getInputPixelFormat());
if (g_nancy->getGameFlags() & NGF_8BITCOLOR) {
_drawSurface.setPalette(g_nancy->_graphicsManager->_object0.getPalette(), 0, 256);
}
_screenPosition = _parent->getScreenPosition();
_nextFrameTime = 0;
setAnimationFrame(_curFrame);
@ -237,12 +244,12 @@ void InventoryBox::Shades::init() {
RenderObject::init();
}
void InventoryBox::Shades::updateGraphics() {
void InventoryBox::Curtains::updateGraphics() {
Time time = g_nancy->getTotalPlayTime();
if (_areOpen) {
if (_curFrame < 7 && time > _nextFrameTime) {
if (_curFrame < g_nancy->getConstants().numCurtainAnimationFrames && time > _nextFrameTime) {
setAnimationFrame(++_curFrame);
_nextFrameTime = time + _parent->_shadesFrameTime;
_nextFrameTime = time + _parent->_curtainsFrameTime;
if (!_soundTriggered) {
_soundTriggered = true;
@ -252,7 +259,7 @@ void InventoryBox::Shades::updateGraphics() {
} else {
if (_curFrame > 0 && time > _nextFrameTime) {
setAnimationFrame(--_curFrame);
_nextFrameTime = time + _parent->_shadesFrameTime;
_nextFrameTime = time + _parent->_curtainsFrameTime;
if (!_soundTriggered) {
_soundTriggered = true;
@ -261,17 +268,17 @@ void InventoryBox::Shades::updateGraphics() {
}
}
if (_curFrame == 0 || _curFrame == 7) {
if (_curFrame == 0 || _curFrame == g_nancy->getConstants().numCurtainAnimationFrames) {
_soundTriggered = false;
}
}
void InventoryBox::Shades::setAnimationFrame(uint frame) {
void InventoryBox::Curtains::setAnimationFrame(uint frame) {
Graphics::ManagedSurface &_object0 = g_nancy->_graphicsManager->_object0;
Common::Rect srcRect;
Common::Point destPoint;
if (frame > 6) {
if (frame > g_nancy->getConstants().numCurtainAnimationFrames - 1) {
setVisible(false);
return;
} else {
@ -281,11 +288,11 @@ void InventoryBox::Shades::setAnimationFrame(uint frame) {
_drawSurface.clear(g_nancy->_graphicsManager->getTransColor());
// Draw left shade
srcRect = _parent->_shadesSrc[frame * 2];
srcRect = _parent->_curtainsSrc[frame * 2];
_drawSurface.blitFrom(_object0, srcRect, destPoint);
// Draw right shade
srcRect = _parent->_shadesSrc[frame * 2 + 1];
srcRect = _parent->_curtainsSrc[frame * 2 + 1];
destPoint.x = getBounds().width() - srcRect.width();
_drawSurface.blitFrom(_object0, srcRect, destPoint);

View File

@ -72,15 +72,15 @@ private:
void onReorder();
void setHotspots(uint pageNr);
class Shades : public RenderObject {
class Curtains : public RenderObject {
public:
Shades(RenderObject &redrawFrom, InventoryBox *parent) :
Curtains(RenderObject &redrawFrom, InventoryBox *parent) :
RenderObject(redrawFrom, 9),
_parent(parent),
_soundTriggered(false),
_areOpen(false),
_curFrame(0) {}
virtual ~Shades() = default;
virtual ~Curtains() = default;
virtual void init() override;
virtual void updateGraphics() override;
@ -106,7 +106,7 @@ private:
Graphics::ManagedSurface _fullInventorySurface;
Scrollbar *_scrollbar;
Shades _shades;
Curtains _curtains;
float _scrollbarPos;
@ -115,14 +115,13 @@ private:
// INV contents
//...
Common::Rect _shadesSrc[14]; // 0xD6
Common::Array<Common::Rect> _curtainsSrc; // 0xD6
// _screenPosition 0x1B6
uint16 _shadesFrameTime; // 0x1C6
uint16 _curtainsFrameTime; // 0x1C6
Common::String _inventoryCursorsImageName; // 0x1D2, should this be here?
Common::Rect _emptySpace; // 0x1E4
Common::Array<ItemDescription> _itemDescriptions; // 0x1F4
};
} // End of namespace UI