aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJoseph-Eugene Winzer2017-12-27 01:50:13 +0100
committerThierry Crozat2018-01-23 02:15:44 +0000
commit3ae3ee6978f91beed9d6bb38f441db25103e28b7 (patch)
treee668e3b148e572a7e82dafe332cdbd0e9bda2ef4 /engines
parent586162760259fb226dfc8f3a3175f0ac290407b8 (diff)
downloadscummvm-rg350-3ae3ee6978f91beed9d6bb38f441db25103e28b7.tar.gz
scummvm-rg350-3ae3ee6978f91beed9d6bb38f441db25103e28b7.tar.bz2
scummvm-rg350-3ae3ee6978f91beed9d6bb38f441db25103e28b7.zip
SUPERNOVA: Fixes inventory scrolling
Correctly moves inventory view when items are added/removed/cleared
Diffstat (limited to 'engines')
-rw-r--r--engines/supernova/state.cpp25
-rw-r--r--engines/supernova/state.h6
2 files changed, 16 insertions, 15 deletions
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;
};