From 3ae3ee6978f91beed9d6bb38f441db25103e28b7 Mon Sep 17 00:00:00 2001 From: Joseph-Eugene Winzer Date: Wed, 27 Dec 2017 01:50:13 +0100 Subject: SUPERNOVA: Fixes inventory scrolling Correctly moves inventory view when items are added/removed/cleared --- engines/supernova/state.cpp | 25 +++++++++++-------------- engines/supernova/state.h | 6 +++++- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'engines') diff --git a/engines/supernova/state.cpp b/engines/supernova/state.cpp index 71d6bc20d9..5eabbda581 100644 --- a/engines/supernova/state.cpp +++ b/engines/supernova/state.cpp @@ -155,24 +155,24 @@ bool GameManager::deserialize(Common::ReadStream *in, int version) { return !in->err(); } -Inventory::Inventory() : _numObjects(0) { -} - -// TODO: Update Inventory surface for scrolling void Inventory::add(Object &obj) { if (_numObjects < kMaxCarry) { _inventory[_numObjects++] = &obj; obj.setProperty(CARRIED); } -// if (inventory_amount>8) inventory_scroll = ((inventory_amount+1)/2)*2-8; -// show_inventory(); + if (getSize() > _inventoryScroll + 8) { + _inventoryScroll = getSize() - 8; + _inventoryScroll += _inventoryScroll % 2; + } } -// TODO: Update Inventory surface for scrolling void Inventory::remove(Object &obj) { for (int i = 0; i < _numObjects; ++i) { if (_inventory[i] == &obj) { + if (_inventoryScroll >= 2 && getSize() % 2) + _inventoryScroll -= 2; + --_numObjects; while (i < _numObjects) { _inventory[i] = _inventory[i + 1]; @@ -185,6 +185,7 @@ void Inventory::remove(Object &obj) { void Inventory::clear() { _numObjects = 0; + _inventoryScroll = 0; } Object *Inventory::get(int index) const { @@ -272,9 +273,9 @@ static Common::String timeToString(int msec) { return Common::String(s); } -GameManager::GameManager(SupernovaEngine *vm) { - _vm = vm; - +GameManager::GameManager(SupernovaEngine *vm) + : _inventory(_inventoryScroll) + , _vm(vm) { initRooms(); changeRoom(INTRO); initState(); @@ -1455,10 +1456,6 @@ void GameManager::takeObject(Object &obj) { _vm->renderImage(obj._section); obj._click = obj._click2 = 255; _inventory.add(obj); - if (_inventory.getSize() > _inventoryScroll + 8) { - _inventoryScroll = _inventory.getSize() - 8; - _inventoryScroll += _inventoryScroll % 2; - } } void GameManager::drawCommandBox() { diff --git a/engines/supernova/state.h b/engines/supernova/state.h index 568d4cf22e..e47c906aa5 100644 --- a/engines/supernova/state.h +++ b/engines/supernova/state.h @@ -63,7 +63,10 @@ struct GameState { class Inventory { public: - Inventory(); + Inventory(int &inventoryScroll) + : _numObjects(0) + , _inventoryScroll(inventoryScroll) + {} void add(Object &obj); void remove(Object &obj); @@ -74,6 +77,7 @@ public: private: Object *_inventory[kMaxCarry]; + int &_inventoryScroll; int _numObjects; }; -- cgit v1.2.3