aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/mutationofjb/commands/seqcommand.h1
-rw-r--r--engines/mutationofjb/debug.cpp11
-rw-r--r--engines/mutationofjb/debug.h1
-rw-r--r--engines/mutationofjb/game.cpp14
-rw-r--r--engines/mutationofjb/game.h4
-rw-r--r--engines/mutationofjb/gamedata.cpp8
-rw-r--r--engines/mutationofjb/gamedata.h2
-rw-r--r--engines/mutationofjb/gui.cpp181
-rw-r--r--engines/mutationofjb/gui.h67
-rw-r--r--engines/mutationofjb/inventory.cpp23
-rw-r--r--engines/mutationofjb/inventory.h15
-rw-r--r--engines/mutationofjb/module.mk1
-rw-r--r--engines/mutationofjb/room.cpp6
13 files changed, 328 insertions, 6 deletions
diff --git a/engines/mutationofjb/commands/seqcommand.h b/engines/mutationofjb/commands/seqcommand.h
index 241932a360..04731c2984 100644
--- a/engines/mutationofjb/commands/seqcommand.h
+++ b/engines/mutationofjb/commands/seqcommand.h
@@ -35,6 +35,7 @@ public:
class SeqCommand : public Command {
public:
+ SeqCommand() : _nextCommand(nullptr) {}
void setNextCommand(Command *nextCommand);
virtual Command *next() const override;
diff --git a/engines/mutationofjb/debug.cpp b/engines/mutationofjb/debug.cpp
index 4ce2418d1b..171eca58f5 100644
--- a/engines/mutationofjb/debug.cpp
+++ b/engines/mutationofjb/debug.cpp
@@ -23,6 +23,7 @@
#include "mutationofjb/debug.h"
#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
+#include "mutationofjb/inventory.h"
#include "mutationofjb/mutationofjb.h"
#include "mutationofjb/script.h"
#include "mutationofjb/commands/command.h"
@@ -68,6 +69,7 @@ Console::Console(MutationOfJBEngine *vm) : _vm(vm) {
registerCmd("dumpdoorinfo", WRAP_METHOD(Console, cmd_dumpdoorinfo));
registerCmd("dumpobjectinfo", WRAP_METHOD(Console, cmd_dumpobjectinfo));
registerCmd("dumpstaticinfo", WRAP_METHOD(Console, cmd_dumpstaticinfo));
+ registerCmd("listinventory", WRAP_METHOD(Console, cmd_listinventory));
}
bool Console::cmd_showallcommands(int argc, const char **argv) {
@@ -438,4 +440,13 @@ Script *Console::getScriptFromArg(const char *arg) {
return script;
}
+bool Console::cmd_listinventory(int, const char **) {
+ Inventory &inventory =_vm->getGame().getGameData().getInventory();
+ const Inventory::Items &items = inventory.getItems();
+ for (Inventory::Items::const_iterator it = items.begin(); it != items.end(); ++it) {
+ debugPrintf("%s\n", convertToASCII(*it).c_str());
+ }
+ return true;
+}
+
}
diff --git a/engines/mutationofjb/debug.h b/engines/mutationofjb/debug.h
index 0cd7257203..24b1e95a7c 100644
--- a/engines/mutationofjb/debug.h
+++ b/engines/mutationofjb/debug.h
@@ -48,6 +48,7 @@ private:
bool cmd_dumpdoorinfo(int argc, const char **argv);
bool cmd_dumpobjectinfo(int argc, const char **argv);
bool cmd_dumpstaticinfo(int argc, const char **argv);
+ bool cmd_listinventory(int argc, const char **argv);
void showIndent(int indentLevel);
void showCommands(Command *command, int indentLevel = 0);
diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp
index a46ca63965..b7f1893198 100644
--- a/engines/mutationofjb/game.cpp
+++ b/engines/mutationofjb/game.cpp
@@ -35,7 +35,7 @@
namespace MutationOfJB {
Game::Game(MutationOfJBEngine *vm)
-: _vm(vm), _delayedLocalScript(nullptr), _scriptExecCtx(*this) {
+: _vm(vm), _delayedLocalScript(nullptr), _gui(*this, _vm->getScreen()), _scriptExecCtx(*this) {
_gameData = new GameData;
loadGameData(false);
@@ -48,6 +48,8 @@ Game::Game(MutationOfJBEngine *vm)
_localScript = nullptr;
_room = new Room(this, _vm->getScreen());
+ _gui.init();
+
changeScene(13, false); // Initial scene.
}
@@ -84,6 +86,10 @@ bool Game::loadGameData(bool partB) {
}
Script *Game::changeSceneLoadScript(uint8 sceneId, bool partB) {
+ if (isCurrentSceneMap()) {
+ _gui.markInventoryDirty();
+ }
+
_gameData->_lastScene = _gameData->_currentScene;
_gameData->_currentScene = sceneId;
_gameData->_partB = partB;
@@ -165,6 +171,12 @@ void Game::update() {
_localScript = _delayedLocalScript;
_delayedLocalScript = nullptr;
}
+
+ _gui.update();
+}
+
+Gui &Game::getGui() {
+ return _gui;
}
}
diff --git a/engines/mutationofjb/game.h b/engines/mutationofjb/game.h
index c71b5f16e7..71dadf2cd7 100644
--- a/engines/mutationofjb/game.h
+++ b/engines/mutationofjb/game.h
@@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "mutationofjb/script.h"
+#include "mutationofjb/gui.h"
namespace Common {
class String;
@@ -58,6 +59,8 @@ public:
void update();
+ Gui &getGui();
+
private:
bool loadGameData(bool partB);
void runActiveCommand();
@@ -71,6 +74,7 @@ private:
Script *_localScript;
Script *_delayedLocalScript;
Room *_room;
+ Gui _gui;
ScriptExecutionContext _scriptExecCtx;
};
diff --git a/engines/mutationofjb/gamedata.cpp b/engines/mutationofjb/gamedata.cpp
index fb9e642355..099cea7077 100644
--- a/engines/mutationofjb/gamedata.cpp
+++ b/engines/mutationofjb/gamedata.cpp
@@ -226,7 +226,9 @@ Bitmap *Scene::findBitmap(int16 x, int16 y, int *index) {
GameData::GameData()
: _currentScene(0),
_lastScene(0),
- _partB(false) {}
+ _partB(false),
+ _inventory()
+ {}
Scene *GameData::getScene(uint8 sceneId) {
if (sceneId == 0 || sceneId > ARRAYSIZE(_scenes)) {
@@ -241,6 +243,10 @@ Scene *GameData::getCurrentScene() {
return getScene(_currentScene);
}
+Inventory &GameData::getInventory() {
+ return _inventory;
+}
+
bool GameData::loadFromStream(Common::ReadStream &stream) {
for (int i = 0; i < ARRAYSIZE(_scenes); ++i) {
_scenes[i].loadFromStream(stream);
diff --git a/engines/mutationofjb/gamedata.h b/engines/mutationofjb/gamedata.h
index b0c64c5ac8..64de01ef01 100644
--- a/engines/mutationofjb/gamedata.h
+++ b/engines/mutationofjb/gamedata.h
@@ -164,6 +164,7 @@ public:
GameData();
Scene *getScene(uint8 sceneId);
Scene *getCurrentScene();
+ Inventory &getInventory();
bool loadFromStream(Common::ReadStream &stream);
@@ -174,7 +175,6 @@ public:
Common::String _currentAPK;
private:
Scene _scenes[45];
-
};
}
diff --git a/engines/mutationofjb/gui.cpp b/engines/mutationofjb/gui.cpp
new file mode 100644
index 0000000000..5ceed67b88
--- /dev/null
+++ b/engines/mutationofjb/gui.cpp
@@ -0,0 +1,181 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/gui.h"
+#include "mutationofjb/animationdecoder.h"
+#include "mutationofjb/encryptedfile.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/gamedata.h"
+#include "mutationofjb/inventory.h"
+#include "mutationofjb/util.h"
+#include "common/rect.h"
+#include "graphics/screen.h"
+
+namespace MutationOfJB {
+
+enum ButtonType {
+ BUTTON_WALK,
+ BUTTON_TALK,
+ BUTTON_LOOK,
+ BUTTON_USE,
+ BUTTON_PICKUP,
+ BUTTON_SCROLL_LEFT,
+ BUTTON_SCROLL_RIGHT,
+ BUTTON_SETTINGS
+};
+
+enum {
+ INVENTORY_START_X = 88,
+ INVENTORY_START_Y = 149,
+ INVENTORY_ITEM_WIDTH = 34,
+ INVENTORY_ITEM_HEIGHT = 33,
+ INVENTORY_ITEMS_PER_LINE = 8,
+ INVENTORY_ITEMS_LINES = 5
+};
+
+static Common::Rect ButtonRects[] = {
+ Common::Rect(0, 148, 67, 158), // Walk
+ Common::Rect(0, 158, 67, 168), // Talk
+ Common::Rect(0, 168, 67, 178), // Look
+ Common::Rect(0, 178, 67, 188), // Use
+ Common::Rect(0, 188, 67, 198), // PickUp
+ Common::Rect(67, 149, 88, 174), // ScrollLeft
+ Common::Rect(67, 174, 88, 199), // ScrollRight
+ Common::Rect(301, 148, 320, 200) // Settings
+};
+
+Gui::Gui(Game &game, Graphics::Screen *screen)
+ : _game(game),
+ _screen(screen),
+ _inventoryDirty(false) {
+}
+
+bool Gui::init() {
+ const bool result1 = loadInventoryList();
+ const bool result2 = loadInventoryGfx();
+
+ _game.getGameData().getInventory().setObserver(this);
+
+ return result1 && result2;
+}
+
+void Gui::markInventoryDirty() {
+ _inventoryDirty = true;
+}
+
+void Gui::update() {
+ if (_inventoryDirty) {
+ drawInventory();
+ _inventoryDirty = false;
+ }
+}
+
+class InventoryAnimationDecoderCallback : public AnimationDecoderCallback {
+public:
+ InventoryAnimationDecoderCallback(Gui &gui) : _gui(gui) {}
+ virtual void onFrame(int frameNo, Graphics::Surface &surface) override;
+ virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) override;
+private:
+ Gui &_gui;
+};
+
+void InventoryAnimationDecoderCallback::onPaletteUpdated(byte palette[PALETTE_SIZE]) {
+ _gui._screen->setPalette(palette + 0xC0 * 3, 0xC0, 0x20); // Load only 0x20 colors.
+}
+
+void InventoryAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &surface) {
+ if (frameNo < 3) {
+ Graphics::Surface outSurface;
+ outSurface.copyFrom(surface);
+ _gui._inventorySurfaces.push_back(outSurface);
+ }
+}
+
+bool Gui::loadInventoryGfx() {
+ AnimationDecoder decoder("icons.dat");
+ InventoryAnimationDecoderCallback callback(*this);
+ return decoder.decode(&callback);
+}
+
+bool Gui::loadInventoryList() {
+ EncryptedFile file;
+ const char *fileName = "fixitems.dat";
+ file.open(fileName);
+ if (!file.isOpen()) {
+ reportFileMissingError(fileName);
+ return false;
+ }
+
+ int itemIndex = 0;
+ while (!file.eos()) {
+ Common::String line = file.readLine();
+ if (line.empty() || line.hasPrefix("#")) {
+ continue;
+ }
+ const char *firstSpace = strchr(line.c_str(), ' ');
+ if (!firstSpace) {
+ continue;
+ }
+ const int len = firstSpace - line.c_str();
+ if (!len) {
+ continue;
+ }
+ Common::String item(line.c_str(), len);
+ _inventoryItems[item] = itemIndex;
+ itemIndex++;
+ }
+
+ return true;
+}
+
+void Gui::drawInventoryItem(const Common::String &item, int pos) {
+ InventoryMap::iterator it = _inventoryItems.find(item);
+ if (it == _inventoryItems.end()) {
+ return;
+ }
+
+ const int index = it->_value;
+ const int surfaceNo = index / (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE);
+ const int indexInSurface = index % (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE);
+ const int itemX = indexInSurface % INVENTORY_ITEMS_PER_LINE;
+ const int itemY = indexInSurface / INVENTORY_ITEMS_PER_LINE;
+
+ Common::Point destStartPos(INVENTORY_START_X + pos * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y);
+ Common::Rect sourceRect(itemX * INVENTORY_ITEM_WIDTH, itemY * INVENTORY_ITEM_HEIGHT, (itemX + 1) * INVENTORY_ITEM_WIDTH, (itemY + 1) * INVENTORY_ITEM_HEIGHT);
+ _screen->blitFrom(_inventorySurfaces[surfaceNo], sourceRect, destStartPos);
+}
+
+void Gui::drawInventory() {
+ Inventory &inventory = _game.getGameData().getInventory();
+ const Inventory::Items &items = inventory.getItems();
+ Common::Rect fullRect(INVENTORY_START_X, INVENTORY_START_Y, INVENTORY_START_X + Inventory::VISIBLE_ITEMS * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y + INVENTORY_ITEM_HEIGHT);
+ _screen->fillRect(fullRect, 0x00);
+ for (int i = 0; i < MIN((int) items.size(), (int) Inventory::VISIBLE_ITEMS); ++i) {
+ drawInventoryItem(items[i], i);
+ }
+}
+
+void Gui::onInventoryChanged() {
+ markInventoryDirty();
+}
+
+}
diff --git a/engines/mutationofjb/gui.h b/engines/mutationofjb/gui.h
new file mode 100644
index 0000000000..27e0b0c2b3
--- /dev/null
+++ b/engines/mutationofjb/gui.h
@@ -0,0 +1,67 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MUTATIONOFJB_GUI_H
+#define MUTATIONOFJB_GUI_H
+
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+#include "graphics/surface.h"
+#include "mutationofjb/inventory.h"
+
+namespace Graphics {
+class Screen;
+}
+
+namespace MutationOfJB {
+
+class Game;
+
+class Gui : public InventoryObserver {
+public:
+ friend class InventoryAnimationDecoderCallback;
+ Gui(Game &game, Graphics::Screen *screen);
+ bool init();
+ void update();
+
+ void markInventoryDirty();
+
+ virtual void onInventoryChanged() override;
+
+private:
+ bool loadInventoryGfx();
+ bool loadInventoryList();
+ void drawInventoryItem(const Common::String &item, int pos);
+ void drawInventory();
+
+ typedef Common::HashMap<Common::String, int> InventoryMap;
+
+ Game &_game;
+ Graphics::Screen *_screen;
+ InventoryMap _inventoryItems;
+ Common::Array<Graphics::Surface> _inventorySurfaces;
+ bool _inventoryDirty;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/inventory.cpp b/engines/mutationofjb/inventory.cpp
index 4a46548ad2..b6561b2e68 100644
--- a/engines/mutationofjb/inventory.cpp
+++ b/engines/mutationofjb/inventory.cpp
@@ -21,13 +21,13 @@
*/
#include "mutationofjb/inventory.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/gui.h"
#include "common/algorithm.h"
#include "common/debug.h"
namespace MutationOfJB {
-static const uint VISIBLE_ITEMS = 6;
-
const Inventory::Items &Inventory::getItems() const {
return _items;
}
@@ -43,6 +43,9 @@ void Inventory::addItem(const Common::String &item) {
if (_items.size() > VISIBLE_ITEMS) {
rotateItemsRight(VISIBLE_ITEMS);
}
+ if (_observer) {
+ _observer->onInventoryChanged();
+ }
}
void Inventory::removeItem(const Common::String &item) {
@@ -53,10 +56,16 @@ void Inventory::removeItem(const Common::String &item) {
}
_items.remove_at(it - _items.begin());
+ if (_observer) {
+ _observer->onInventoryChanged();
+ }
}
void Inventory::removeAllItems() {
_items.clear();
+ if (_observer) {
+ _observer->onInventoryChanged();
+ }
}
void Inventory::rotateItemsRight(uint n) {
@@ -68,6 +77,9 @@ void Inventory::rotateItemsRight(uint n) {
reverseItems(0, _items.size() - 1);
reverseItems(0, n - 1);
reverseItems(n, _items.size() - 1);
+ if (_observer) {
+ _observer->onInventoryChanged();
+ }
}
void Inventory::rotateItemsLeft(uint n) {
@@ -79,6 +91,13 @@ void Inventory::rotateItemsLeft(uint n) {
reverseItems(0, _items.size() - 1);
reverseItems(_items.size() - n, _items.size() - 1);
reverseItems(0, _items.size() - n - 1);
+ if (_observer) {
+ _observer->onInventoryChanged();
+ }
+}
+
+void Inventory::setObserver(InventoryObserver *observer) {
+ _observer = observer;
}
void Inventory::reverseItems(uint from, uint to) {
diff --git a/engines/mutationofjb/inventory.h b/engines/mutationofjb/inventory.h
index fe7ca67afa..91c2932f91 100644
--- a/engines/mutationofjb/inventory.h
+++ b/engines/mutationofjb/inventory.h
@@ -29,8 +29,20 @@
namespace MutationOfJB {
+class Game;
+
+class InventoryObserver {
+public:
+ virtual void onInventoryChanged() = 0;
+ virtual ~InventoryObserver() {}
+};
+
class Inventory {
public:
+ enum {
+ VISIBLE_ITEMS = 6
+ };
+
typedef Common::Array<Common::String> Items;
const Items &getItems() const;
@@ -42,10 +54,13 @@ public:
void rotateItemsRight(uint n);
void rotateItemsLeft(uint n);
+ void setObserver(InventoryObserver *observer);
+
private:
void reverseItems(uint from, uint to);
Items _items;
+ InventoryObserver *_observer;
};
}
diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk
index b7966988a5..729ea4409e 100644
--- a/engines/mutationofjb/module.mk
+++ b/engines/mutationofjb/module.mk
@@ -24,6 +24,7 @@ MODULE_OBJS := \
encryptedfile.o \
game.o \
gamedata.o \
+ gui.o \
inventory.o \
mutationofjb.o \
room.o \
diff --git a/engines/mutationofjb/room.cpp b/engines/mutationofjb/room.cpp
index 5ed6ca3ca2..62af98327e 100644
--- a/engines/mutationofjb/room.cpp
+++ b/engines/mutationofjb/room.cpp
@@ -47,7 +47,11 @@ void RoomAnimationDecoderCallback::onPaletteUpdated(byte palette[PALETTE_SIZE])
void RoomAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &surface) {
if (frameNo == 0) {
- _room._screen->blitFrom(surface);
+ Common::Rect rect(0, 0, 320, 139);
+ if (_room._game->isCurrentSceneMap()) {
+ rect = Common::Rect(0, 0, 320, 200);
+ }
+ _room._screen->blitFrom(surface, rect, Common::Point(0, 0));
}
const int frameNo1 = frameNo + 1;