aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb
diff options
context:
space:
mode:
authorĽubomír Remák2018-09-06 19:38:16 +0200
committerĽubomír Remák2018-09-06 19:38:16 +0200
commitc36fb36afba47f52c1f81f1df61eb31838134cd2 (patch)
treea87bc4e4c7a70542da8b54e1cb4e86373ec199f8 /engines/mutationofjb
parentf10816d9ed0b74b478799a96f26ee8f3f42f9ee2 (diff)
downloadscummvm-rg350-c36fb36afba47f52c1f81f1df61eb31838134cd2.tar.gz
scummvm-rg350-c36fb36afba47f52c1f81f1df61eb31838134cd2.tar.bz2
scummvm-rg350-c36fb36afba47f52c1f81f1df61eb31838134cd2.zip
MUTATIONOFJB: Add support for 'look' action on inventory items.
Diffstat (limited to 'engines/mutationofjb')
-rw-r--r--engines/mutationofjb/assets.cpp4
-rw-r--r--engines/mutationofjb/assets.h3
-rw-r--r--engines/mutationofjb/game.cpp2
-rw-r--r--engines/mutationofjb/game.h6
-rw-r--r--engines/mutationofjb/gamescreen.cpp (renamed from engines/mutationofjb/gui.cpp)125
-rw-r--r--engines/mutationofjb/gamescreen.h (renamed from engines/mutationofjb/gui.h)28
-rw-r--r--engines/mutationofjb/guiscreen.cpp73
-rw-r--r--engines/mutationofjb/guiscreen.h88
-rw-r--r--engines/mutationofjb/inventory.cpp4
-rw-r--r--engines/mutationofjb/inventoryitemdefinitionlist.cpp73
-rw-r--r--engines/mutationofjb/inventoryitemdefinitionlist.h50
-rw-r--r--engines/mutationofjb/module.mk4
-rw-r--r--engines/mutationofjb/mutationofjb.cpp4
-rw-r--r--engines/mutationofjb/tasks/conversationtask.cpp10
-rw-r--r--engines/mutationofjb/widgets/buttonwidget.cpp2
-rw-r--r--engines/mutationofjb/widgets/buttonwidget.h2
-rw-r--r--engines/mutationofjb/widgets/conversationwidget.cpp4
-rw-r--r--engines/mutationofjb/widgets/conversationwidget.h2
-rw-r--r--engines/mutationofjb/widgets/imagewidget.cpp2
-rw-r--r--engines/mutationofjb/widgets/imagewidget.h2
-rw-r--r--engines/mutationofjb/widgets/inventorywidget.cpp64
-rw-r--r--engines/mutationofjb/widgets/inventorywidget.h41
-rw-r--r--engines/mutationofjb/widgets/widget.h6
23 files changed, 461 insertions, 138 deletions
diff --git a/engines/mutationofjb/assets.cpp b/engines/mutationofjb/assets.cpp
index 2adda51c09..6f3236177b 100644
--- a/engines/mutationofjb/assets.cpp
+++ b/engines/mutationofjb/assets.cpp
@@ -42,4 +42,8 @@ ConversationLineList &Assets::getResponseList() {
return _responseList;
}
+InventoryItemDefinitionList &Assets::getInventoryItemDefList() {
+ return _invItemDefList;
+}
+
}
diff --git a/engines/mutationofjb/assets.h b/engines/mutationofjb/assets.h
index 2cd0612f20..89ed678c60 100644
--- a/engines/mutationofjb/assets.h
+++ b/engines/mutationofjb/assets.h
@@ -25,6 +25,7 @@
#include "mutationofjb/font.h"
#include "mutationofjb/conversationlinelist.h"
+#include "mutationofjb/inventoryitemdefinitionlist.h"
namespace MutationOfJB {
@@ -39,6 +40,7 @@ public:
ConversationLineList &getToSayList();
ConversationLineList &getResponseList();
+ InventoryItemDefinitionList &getInventoryItemDefList();
private:
Game &_game;
@@ -46,6 +48,7 @@ private:
SpeechFont _speechFont;
ConversationLineList _toSayList;
ConversationLineList _responseList;
+ InventoryItemDefinitionList _invItemDefList;
};
}
diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp
index ff05bb99eb..5e0d1e699c 100644
--- a/engines/mutationofjb/game.cpp
+++ b/engines/mutationofjb/game.cpp
@@ -194,7 +194,7 @@ void Game::update() {
_taskManager.update();
}
-Gui &Game::getGui() {
+GameScreen &Game::getGameScreen() {
return _gui;
}
diff --git a/engines/mutationofjb/game.h b/engines/mutationofjb/game.h
index 6230b93aff..adb5bf5c48 100644
--- a/engines/mutationofjb/game.h
+++ b/engines/mutationofjb/game.h
@@ -24,7 +24,7 @@
#define MUTATIONOFJB_GAME_H
#include "mutationofjb/assets.h"
-#include "mutationofjb/gui.h"
+#include "mutationofjb/gamescreen.h"
#include "mutationofjb/script.h"
#include "mutationofjb/tasks/taskmanager.h"
@@ -66,7 +66,7 @@ public:
void update();
- Gui &getGui();
+ GameScreen &getGameScreen();
ActionInfo::Action getCurrentAction() const;
void setCurrentAction(ActionInfo::Action);
@@ -97,7 +97,7 @@ private:
Script *_localScript;
Script *_delayedLocalScript;
Room *_room;
- Gui _gui;
+ GameScreen _gui;
ActionInfo::Action _currentAction;
ScriptExecutionContext _scriptExecCtx;
diff --git a/engines/mutationofjb/gui.cpp b/engines/mutationofjb/gamescreen.cpp
index 7c219bc706..3c007f415f 100644
--- a/engines/mutationofjb/gui.cpp
+++ b/engines/mutationofjb/gamescreen.cpp
@@ -20,7 +20,8 @@
*
*/
-#include "mutationofjb/gui.h"
+#include "mutationofjb/gamescreen.h"
+
#include "mutationofjb/animationdecoder.h"
#include "mutationofjb/encryptedfile.h"
#include "mutationofjb/game.h"
@@ -31,7 +32,9 @@
#include "mutationofjb/widgets/inventorywidget.h"
#include "mutationofjb/widgets/imagewidget.h"
#include "mutationofjb/widgets/conversationwidget.h"
+
#include "common/rect.h"
+
#include "graphics/screen.h"
namespace MutationOfJB {
@@ -62,27 +65,14 @@ enum {
};
-Gui::Gui(Game &game, Graphics::Screen *screen)
- : _game(game),
- _screen(screen),
+GameScreen::GameScreen(Game &game, Graphics::Screen *screen)
+ : GuiScreen(game, screen),
_inventoryWidget(nullptr),
_conversationWidget(nullptr) {}
-Gui::~Gui() {
- for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
- delete *it;
- }
-}
-
-Game &Gui::getGame() {
- return _game;
-}
-
-bool Gui::init() {
- if (!loadInventoryList()) {
- return false;
- }
+GameScreen::~GameScreen() {}
+bool GameScreen::init() {
if (!loadInventoryGfx()) {
return false;
}
@@ -98,10 +88,11 @@ bool Gui::init() {
const Common::Rect backgroundRect(CONVERSATION_X, CONVERSATION_Y, CONVERSATION_X + CONVERSATION_WIDTH, CONVERSATION_Y + CONVERSATION_HEIGHT);
const Graphics::Surface backgroundSurface = _hudSurfaces[0].getSubArea(backgroundRect);
ImageWidget *image = new ImageWidget(*this, backgroundRect, backgroundSurface);
- _widgets.push_back(image);
+ addWidget(image);
- _inventoryWidget = new InventoryWidget(*this, _inventoryItems, _inventorySurfaces);
- _widgets.push_back(_inventoryWidget);
+ _inventoryWidget = new InventoryWidget(*this, _inventorySurfaces);
+ _inventoryWidget->setCallback(this);
+ addWidget(_inventoryWidget);
const Common::Rect ButtonRects[] = {
Common::Rect(0, 148, 67, 158), // Walk
@@ -120,53 +111,29 @@ bool Gui::init() {
ButtonWidget *button = new ButtonWidget(*this, ButtonRects[i], normalSurface, pressedSurface);
button->setId(i);
button->setCallback(this);
- _widgets.push_back(button);
+ addWidget(button);
}
const Common::Rect conversationRect(CONVERSATION_X, CONVERSATION_Y, CONVERSATION_X + CONVERSATION_WIDTH, CONVERSATION_Y + CONVERSATION_HEIGHT);
const Graphics::Surface conversationSurface = _hudSurfaces[2].getSubArea(conversationRect);
_conversationWidget = new ConversationWidget(*this, conversationRect, conversationSurface);
_conversationWidget->setVisible(false);
- _widgets.push_back(_conversationWidget);
+ addWidget(_conversationWidget);
return true;
}
-void Gui::markDirty() {
- for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
- if ((*it)->isVisible()) {
- (*it)->markDirty();
- }
- }
-}
-
-void Gui::handleEvent(const Common::Event &event) {
- for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
- if ((*it)->isVisible()) {
- (*it)->handleEvent(event);
- }
- }
-}
-
-void Gui::update() {
- for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
- if ((*it)->isVisible()) {
- (*it)->update(*_screen);
- }
- }
-}
-
-ConversationWidget &Gui::getConversationWidget() {
+ConversationWidget &GameScreen::getConversationWidget() {
return *_conversationWidget;
}
class InventoryAnimationDecoderCallback : public AnimationDecoderCallback {
public:
- InventoryAnimationDecoderCallback(Gui &gui) : _gui(gui) {}
+ InventoryAnimationDecoderCallback(GameScreen &gui) : _gui(gui) {}
virtual void onFrame(int frameNo, Graphics::Surface &surface) override;
virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) override;
private:
- Gui &_gui;
+ GameScreen &_gui;
};
void InventoryAnimationDecoderCallback::onPaletteUpdated(byte palette[PALETTE_SIZE]) {
@@ -181,7 +148,7 @@ void InventoryAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &
}
}
-bool Gui::loadInventoryGfx() {
+bool GameScreen::loadInventoryGfx() {
AnimationDecoder decoder("icons.dat");
InventoryAnimationDecoderCallback callback(*this);
return decoder.decode(&callback);
@@ -189,11 +156,11 @@ bool Gui::loadInventoryGfx() {
class HudAnimationDecoderCallback : public AnimationDecoderCallback {
public:
- HudAnimationDecoderCallback(Gui &gui) : _gui(gui) {}
+ HudAnimationDecoderCallback(GameScreen &gui) : _gui(gui) {}
virtual void onFrame(int frameNo, Graphics::Surface &surface) override;
virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) override;
private:
- Gui &_gui;
+ GameScreen &_gui;
};
void HudAnimationDecoderCallback::onPaletteUpdated(byte [PALETTE_SIZE]) {
@@ -207,48 +174,17 @@ void HudAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &surfac
}
}
-bool Gui::loadHudGfx() {
+bool GameScreen::loadHudGfx() {
AnimationDecoder decoder("room0.dat");
HudAnimationDecoderCallback 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::onInventoryChanged() {
+void GameScreen::onInventoryChanged() {
_inventoryWidget->markDirty();
}
-void Gui::onButtonClicked(ButtonWidget *button) {
+void GameScreen::onButtonClicked(ButtonWidget *button) {
const int buttonId = button->getId();
if (buttonId <= BUTTON_PICKUP) {
const ActionInfo::Action actions[] = {ActionInfo::Walk, ActionInfo::Talk, ActionInfo::Look, ActionInfo::Use, ActionInfo::PickUp};
@@ -260,4 +196,19 @@ void Gui::onButtonClicked(ButtonWidget *button) {
}
}
+void GameScreen::onInventoryItemHovered(InventoryWidget *widget, int posInWidget) {
+ // TODO
+}
+
+void GameScreen::onInventoryItemClicked(InventoryWidget *widget, int posInWidget) {
+ // Position in widget should match the position in inventory.
+ const Common::String &item = getGame().getGameData().getInventory().getItems()[posInWidget];
+
+ if (_game.getCurrentAction() == ActionInfo::Use) {
+ // TODO
+ } else {
+ _game.startActionSection(ActionInfo::Look, item);
+ }
+}
+
}
diff --git a/engines/mutationofjb/gui.h b/engines/mutationofjb/gamescreen.h
index 354d04f960..bc70580eda 100644
--- a/engines/mutationofjb/gui.h
+++ b/engines/mutationofjb/gamescreen.h
@@ -23,12 +23,16 @@
#ifndef MUTATIONOFJB_GUI_H
#define MUTATIONOFJB_GUI_H
+#include "mutationofjb/inventory.h"
+#include "mutationofjb/widgets/buttonwidget.h"
+#include "mutationofjb/widgets/inventorywidget.h"
+#include "mutationofjb/guiscreen.h"
+
#include "common/array.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
+
#include "graphics/surface.h"
-#include "mutationofjb/inventory.h"
-#include "mutationofjb/widgets/buttonwidget.h"
namespace Common {
struct Event;
@@ -45,44 +49,34 @@ class Widget;
class InventoryWidget;
class ConversationWidget;
-class Gui : public InventoryObserver, public ButtonWidgetCallback {
+class GameScreen : public GuiScreen, public InventoryObserver, public ButtonWidgetCallback, public InventoryWidgetCallback {
public:
- typedef Common::HashMap<Common::String, int> InventoryMap;
-
friend class InventoryAnimationDecoderCallback;
friend class HudAnimationDecoderCallback;
- Gui(Game &game, Graphics::Screen *screen);
- ~Gui();
- Game &getGame();
+ GameScreen(Game &game, Graphics::Screen *screen);
+ ~GameScreen();
bool init();
- void update();
-
- void markDirty();
- void handleEvent(const Common::Event &event);
virtual void onInventoryChanged() override;
virtual void onButtonClicked(ButtonWidget *) override;
+ virtual void onInventoryItemHovered(InventoryWidget *widget, int posInWidget) override;
+ virtual void onInventoryItemClicked(InventoryWidget *widget, int posInWidget) override;
ConversationWidget &getConversationWidget();
private:
bool loadInventoryGfx();
bool loadHudGfx();
- bool loadInventoryList();
void drawInventoryItem(const Common::String &item, int pos);
void drawInventory();
- Game &_game;
- Graphics::Screen *_screen;
- InventoryMap _inventoryItems;
Common::Array<Graphics::Surface> _inventorySurfaces;
Common::Array<Graphics::Surface> _hudSurfaces;
InventoryWidget *_inventoryWidget;
ConversationWidget *_conversationWidget;
- Common::Array<Widget *> _widgets;
};
}
diff --git a/engines/mutationofjb/guiscreen.cpp b/engines/mutationofjb/guiscreen.cpp
new file mode 100644
index 0000000000..5ad545dc3c
--- /dev/null
+++ b/engines/mutationofjb/guiscreen.cpp
@@ -0,0 +1,73 @@
+/* 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/guiscreen.h"
+
+#include "mutationofjb/widgets/widget.h"
+
+#include "graphics/screen.h"
+
+namespace MutationOfJB {
+
+GuiScreen::GuiScreen(Game &game, Graphics::Screen *screen)
+ : _game(game),
+ _screen(screen) {}
+
+GuiScreen::~GuiScreen() {
+ for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
+ delete *it;
+ }
+}
+
+Game &GuiScreen::getGame() {
+ return _game;
+}
+
+void GuiScreen::markDirty() {
+ for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
+ if ((*it)->isVisible()) {
+ (*it)->markDirty();
+ }
+ }
+}
+
+void GuiScreen::handleEvent(const Common::Event &event) {
+ for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
+ if ((*it)->isVisible()) {
+ (*it)->handleEvent(event);
+ }
+ }
+}
+
+void GuiScreen::update() {
+ for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) {
+ if ((*it)->isVisible()) {
+ (*it)->update(*_screen);
+ }
+ }
+}
+
+void GuiScreen::addWidget(Widget *widget) {
+ _widgets.push_back(widget);
+}
+
+}
diff --git a/engines/mutationofjb/guiscreen.h b/engines/mutationofjb/guiscreen.h
new file mode 100644
index 0000000000..c1761be39a
--- /dev/null
+++ b/engines/mutationofjb/guiscreen.h
@@ -0,0 +1,88 @@
+/* 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_GUISCREEN_H
+#define MUTATIONOFJB_GUISCREEN_H
+
+#include "common/array.h"
+
+namespace Common {
+struct Event;
+}
+
+namespace Graphics {
+class Screen;
+}
+
+namespace MutationOfJB {
+
+class Game;
+class Widget;
+
+/**
+ * Base class for GUI screens.
+ *
+ * GUI screen is a collection of widgets.
+ */
+class GuiScreen {
+public:
+
+ GuiScreen(Game &game, Graphics::Screen *screen);
+ virtual ~GuiScreen();
+ Game &getGame();
+
+ /**
+ * Marks all visible widgets as dirty (needs redraw).
+ */
+ void markDirty();
+
+ /**
+ * Lets all visible widgets handle core events.
+ *
+ * @param event ScummVM event.
+ */
+ void handleEvent(const Common::Event &event);
+
+ /**
+ * Updates all visible widgets.
+ */
+ void update();
+
+ /**
+ * Adds a widget to the GUI screen.
+ * The GUI screen will own the widget.
+ *
+ * @param widget Widget to add.
+ */
+ void addWidget(Widget *widget);
+
+protected:
+ Game &_game;
+ Graphics::Screen *_screen;
+
+private:
+ Common::Array<Widget *> _widgets;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/inventory.cpp b/engines/mutationofjb/inventory.cpp
index 91bfd9f005..6176425ca2 100644
--- a/engines/mutationofjb/inventory.cpp
+++ b/engines/mutationofjb/inventory.cpp
@@ -21,8 +21,10 @@
*/
#include "mutationofjb/inventory.h"
+
#include "mutationofjb/game.h"
-#include "mutationofjb/gui.h"
+#include "mutationofjb/gamescreen.h"
+
#include "common/algorithm.h"
#include "common/debug.h"
diff --git a/engines/mutationofjb/inventoryitemdefinitionlist.cpp b/engines/mutationofjb/inventoryitemdefinitionlist.cpp
new file mode 100644
index 0000000000..8af9bd4dee
--- /dev/null
+++ b/engines/mutationofjb/inventoryitemdefinitionlist.cpp
@@ -0,0 +1,73 @@
+/* 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/inventoryitemdefinitionlist.h"
+
+#include "mutationofjb/encryptedfile.h"
+#include "mutationofjb/util.h"
+
+namespace MutationOfJB {
+
+InventoryItemDefinitionList::InventoryItemDefinitionList() {
+ parseFile();
+}
+
+int InventoryItemDefinitionList::findItemIndex(const Common::String &itemName) {
+ const InventoryItemMap::const_iterator it = _inventoryItemMap.find(itemName);
+ if (it == _inventoryItemMap.end())
+ return -1;
+ return it->_value;
+}
+
+bool InventoryItemDefinitionList::parseFile() {
+ 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;
+ }
+
+ Common::String::const_iterator firstSpace = Common::find(line.begin(), line.end(), ' ');
+ if (firstSpace == line.end()) {
+ continue;
+ }
+ const int len = firstSpace - line.begin();
+ if (!len) {
+ continue;
+ }
+ Common::String item(line.c_str(), len);
+ _inventoryItemMap[item] = itemIndex;
+ itemIndex++;
+ }
+
+ return true;
+}
+
+}
diff --git a/engines/mutationofjb/inventoryitemdefinitionlist.h b/engines/mutationofjb/inventoryitemdefinitionlist.h
new file mode 100644
index 0000000000..5f29b277c7
--- /dev/null
+++ b/engines/mutationofjb/inventoryitemdefinitionlist.h
@@ -0,0 +1,50 @@
+/* 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_INVENTORYITEMDEFINITIONLIST_H
+#define MUTATIONOFJB_INVENTORYITEMDEFINITIONLIST_H
+
+#include "common/str.h"
+#include "common/hash-str.h"
+#include "common/hashmap.h"
+
+namespace MutationOfJB {
+
+typedef Common::HashMap<Common::String, int> InventoryMap;
+
+class InventoryItemDefinitionList {
+public:
+ InventoryItemDefinitionList();
+ const InventoryMap &getInventorMap() const;
+
+ int findItemIndex(const Common::String &itemName);
+
+private:
+ bool parseFile();
+
+ typedef Common::HashMap<Common::String, int> InventoryItemMap;
+ InventoryItemMap _inventoryItemMap;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk
index 465f228a43..c7de62bfa1 100644
--- a/engines/mutationofjb/module.mk
+++ b/engines/mutationofjb/module.mk
@@ -42,8 +42,10 @@ MODULE_OBJS := \
font.o \
game.o \
gamedata.o \
- gui.o \
+ gamescreen.o \
+ guiscreen.o \
inventory.o \
+ inventoryitemdefinitionlist.o \
mutationofjb.o \
room.o \
script.o \
diff --git a/engines/mutationofjb/mutationofjb.cpp b/engines/mutationofjb/mutationofjb.cpp
index d96d1658b8..84ef9742f1 100644
--- a/engines/mutationofjb/mutationofjb.cpp
+++ b/engines/mutationofjb/mutationofjb.cpp
@@ -150,7 +150,7 @@ Common::Error MutationOfJBEngine::loadGameState(int slot) {
delete saveFile;
_game->changeScene(_game->getGameData()._currentScene, _game->getGameData()._partB);
- _game->getGui().markDirty();
+ _game->getGameScreen().markDirty();
return Common::kNoError;
}
@@ -204,7 +204,7 @@ void MutationOfJBEngine::handleNormalScene(const Common::Event &event) {
default:
break;
}
- _game->getGui().handleEvent(event);
+ _game->getGameScreen().handleEvent(event);
}
void MutationOfJBEngine::handleMapScene(const Common::Event &event) {
diff --git a/engines/mutationofjb/tasks/conversationtask.cpp b/engines/mutationofjb/tasks/conversationtask.cpp
index 9c3ae4b8d8..5167ec5308 100644
--- a/engines/mutationofjb/tasks/conversationtask.cpp
+++ b/engines/mutationofjb/tasks/conversationtask.cpp
@@ -25,7 +25,7 @@
#include "mutationofjb/assets.h"
#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
-#include "mutationofjb/gui.h"
+#include "mutationofjb/gamescreen.h"
#include "mutationofjb/script.h"
#include "mutationofjb/tasks/saytask.h"
#include "mutationofjb/tasks/sequentialtask.h"
@@ -39,7 +39,7 @@ void ConversationTask::start() {
setState(RUNNING);
Game &game = getTaskManager()->getGame();
- ConversationWidget &widget = game.getGui().getConversationWidget();
+ ConversationWidget &widget = game.getGameScreen().getConversationWidget();
widget.setCallback(this);
widget.setVisible(true);
@@ -156,7 +156,7 @@ void ConversationTask::showChoicesOrPick() {
}
if (itemsWithValidQuestions.size() > 1) {
- ConversationWidget &widget = game.getGui().getConversationWidget();
+ ConversationWidget &widget = game.getGameScreen().getConversationWidget();
const ConversationLineList &toSayList = game.getAssets().getToSayList();
for (Common::Array<uint32>::size_type i = 0; i < itemsWithValidQuestions.size() && i < ConversationWidget::CONVERSATION_MAX_CHOICES; ++i) {
@@ -219,9 +219,9 @@ void ConversationTask::finish() {
setState(FINISHED);
Game &game = getTaskManager()->getGame();
- ConversationWidget &widget = game.getGui().getConversationWidget();
+ ConversationWidget &widget = game.getGameScreen().getConversationWidget();
widget.setVisible(false);
- game.getGui().markDirty(); // TODO: Handle automatically when changing visibility.
+ game.getGameScreen().markDirty(); // TODO: Handle automatically when changing visibility.
}
void ConversationTask::startExtra() {
diff --git a/engines/mutationofjb/widgets/buttonwidget.cpp b/engines/mutationofjb/widgets/buttonwidget.cpp
index e2a9dd3b65..b7a1ce0845 100644
--- a/engines/mutationofjb/widgets/buttonwidget.cpp
+++ b/engines/mutationofjb/widgets/buttonwidget.cpp
@@ -26,7 +26,7 @@
namespace MutationOfJB {
-ButtonWidget::ButtonWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface) :
+ButtonWidget::ButtonWidget(GuiScreen &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface) :
Widget(gui, area),
_normalSurface(normalSurface),
_pressedSurface(pressedSurface),
diff --git a/engines/mutationofjb/widgets/buttonwidget.h b/engines/mutationofjb/widgets/buttonwidget.h
index d148fa8727..ae544b2508 100644
--- a/engines/mutationofjb/widgets/buttonwidget.h
+++ b/engines/mutationofjb/widgets/buttonwidget.h
@@ -38,7 +38,7 @@ public:
class ButtonWidget : public Widget {
public:
- ButtonWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface);
+ ButtonWidget(GuiScreen &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface);
void setCallback(ButtonWidgetCallback *callback);
virtual void handleEvent(const Common::Event &event) override;
diff --git a/engines/mutationofjb/widgets/conversationwidget.cpp b/engines/mutationofjb/widgets/conversationwidget.cpp
index 56e00579d3..049b73d0c5 100644
--- a/engines/mutationofjb/widgets/conversationwidget.cpp
+++ b/engines/mutationofjb/widgets/conversationwidget.cpp
@@ -23,7 +23,7 @@
#include "mutationofjb/widgets/conversationwidget.h"
#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
-#include "mutationofjb/gui.h"
+#include "mutationofjb/guiscreen.h"
#include "mutationofjb/font.h"
#include "common/events.h"
@@ -35,7 +35,7 @@ enum {
CONVERSATION_LINE_HEIGHT = 12
};
-ConversationWidget::ConversationWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &surface) :
+ConversationWidget::ConversationWidget(GuiScreen &gui, const Common::Rect &area, const Graphics::Surface &surface) :
Widget(gui, area),
_surface(surface),
_callback(nullptr) {}
diff --git a/engines/mutationofjb/widgets/conversationwidget.h b/engines/mutationofjb/widgets/conversationwidget.h
index 34ea2152e8..ea6e49f807 100644
--- a/engines/mutationofjb/widgets/conversationwidget.h
+++ b/engines/mutationofjb/widgets/conversationwidget.h
@@ -40,7 +40,7 @@ class ConversationWidget : public Widget {
public:
enum { CONVERSATION_MAX_CHOICES = 4 };
- ConversationWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &surface);
+ ConversationWidget(GuiScreen &gui, const Common::Rect &area, const Graphics::Surface &surface);
void setCallback(ConversationWidgetCallback *callback) {
_callback = callback;
}
diff --git a/engines/mutationofjb/widgets/imagewidget.cpp b/engines/mutationofjb/widgets/imagewidget.cpp
index 8eeb7ed5e5..1bab1ade91 100644
--- a/engines/mutationofjb/widgets/imagewidget.cpp
+++ b/engines/mutationofjb/widgets/imagewidget.cpp
@@ -25,7 +25,7 @@
namespace MutationOfJB {
-ImageWidget::ImageWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &image) :
+ImageWidget::ImageWidget(GuiScreen &gui, const Common::Rect &area, const Graphics::Surface &image) :
Widget(gui, area),
_image(image) {}
diff --git a/engines/mutationofjb/widgets/imagewidget.h b/engines/mutationofjb/widgets/imagewidget.h
index da3dd36d69..80f5537f6d 100644
--- a/engines/mutationofjb/widgets/imagewidget.h
+++ b/engines/mutationofjb/widgets/imagewidget.h
@@ -30,7 +30,7 @@ namespace MutationOfJB {
class ImageWidget : public Widget {
public:
- ImageWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &image);
+ ImageWidget(GuiScreen &gui, const Common::Rect &area, const Graphics::Surface &image);
protected:
virtual void draw(Graphics::ManagedSurface &surface) override;
diff --git a/engines/mutationofjb/widgets/inventorywidget.cpp b/engines/mutationofjb/widgets/inventorywidget.cpp
index 46bfab9c34..851f8af9d0 100644
--- a/engines/mutationofjb/widgets/inventorywidget.cpp
+++ b/engines/mutationofjb/widgets/inventorywidget.cpp
@@ -23,11 +23,14 @@
#include "mutationofjb/widgets/inventorywidget.h"
#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
-#include "mutationofjb/gui.h"
+#include "mutationofjb/gamescreen.h"
#include "mutationofjb/inventory.h"
+
#include "common/str.h"
#include "common/rect.h"
#include "common/util.h"
+#include "common/events.h"
+
#include "graphics/managed_surface.h"
namespace MutationOfJB {
@@ -41,18 +44,18 @@ enum {
INVENTORY_ITEMS_LINES = 5
};
-InventoryWidget::InventoryWidget(Gui &gui, Gui::InventoryMap &inventoryMap, const Common::Array<Graphics::Surface> &inventorySurfaces) :
+InventoryWidget::InventoryWidget(GuiScreen &gui, const Common::Array<Graphics::Surface> &inventorySurfaces) :
Widget(gui, Common::Rect(INVENTORY_START_X, INVENTORY_START_Y, INVENTORY_START_X + Inventory::VISIBLE_ITEMS * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y + INVENTORY_ITEM_HEIGHT)),
- _inventoryMap(inventoryMap),
- _surfaces(inventorySurfaces) {}
+ _surfaces(inventorySurfaces),
+ _callback(nullptr),
+ _hoveredItemPos(-1) {}
void InventoryWidget::drawInventoryItem(Graphics::ManagedSurface &surface, const Common::String &item, int pos) {
- Gui::InventoryMap::iterator it = _inventoryMap.find(item);
- if (it == _inventoryMap.end()) {
+ const int index = _gui.getGame().getAssets().getInventoryItemDefList().findItemIndex(item);
+ if (index == -1) {
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;
@@ -72,4 +75,51 @@ void InventoryWidget::draw(Graphics::ManagedSurface &surface) {
}
}
+void InventoryWidget::handleEvent(const Common::Event &event) {
+ if (!_callback)
+ return;
+
+ Inventory &inventory = _gui.getGame().getGameData().getInventory();
+ const int numItems = inventory.getItems().size();
+
+ switch (event.type) {
+ case Common::EVENT_LBUTTONDOWN: {
+ const int16 x = event.mouse.x;
+ const int16 y = event.mouse.y;
+ if (_area.contains(x, y)) {
+ int itemPos = (x - INVENTORY_START_X) / INVENTORY_ITEM_WIDTH;
+ if (itemPos < numItems) {
+ _callback->onInventoryItemClicked(this, itemPos);
+ }
+ }
+ break;
+ }
+ case Common::EVENT_MOUSEMOVE: {
+ const int16 x = event.mouse.x;
+ const int16 y = event.mouse.y;
+
+ int newHoveredItemPos = -1;
+ if (_area.contains(x, y)) {
+ int itemPos = (x - INVENTORY_START_X) / INVENTORY_ITEM_WIDTH;
+ if (itemPos < numItems) {
+ newHoveredItemPos = itemPos;
+
+ if (_hoveredItemPos != newHoveredItemPos) {
+ _callback->onInventoryItemHovered(this, itemPos);
+ }
+ }
+ }
+
+ if (newHoveredItemPos == -1 && _hoveredItemPos != -1) {
+ _callback->onInventoryItemHovered(this, -1);
+ }
+
+ _hoveredItemPos = newHoveredItemPos;
+ break;
+ }
+ default:
+ break;
+ }
+}
+
}
diff --git a/engines/mutationofjb/widgets/inventorywidget.h b/engines/mutationofjb/widgets/inventorywidget.h
index f1841e8668..1819aa1821 100644
--- a/engines/mutationofjb/widgets/inventorywidget.h
+++ b/engines/mutationofjb/widgets/inventorywidget.h
@@ -24,7 +24,9 @@
#define MUTATIONOFJB_INVENTORYWIDGET_H
#include "mutationofjb/widgets/widget.h"
-#include "mutationofjb/gui.h"
+
+#include "common/array.h"
+#include "graphics/surface.h"
namespace Common {
class String;
@@ -32,15 +34,46 @@ class String;
namespace MutationOfJB {
+class InventoryWidget;
+
+class InventoryWidgetCallback {
+public:
+ virtual ~InventoryWidgetCallback() {}
+
+ /**
+ * Called when the user hovers an inventory item with the mouse or when stops hovering an item.
+ *
+ * @param widget Inventory widget.
+ * @param posInWidget Item position in the widget or -1 if none.
+ */
+ virtual void onInventoryItemHovered(InventoryWidget *widget, int posInWidget) = 0;
+
+ /**
+ * Called when the user clicks on an inventory item.
+ *
+ * @param widget Inventory widget.
+ * @param posInWidget Item position in the widget.
+ */
+ virtual void onInventoryItemClicked(InventoryWidget *widget, int posInWidget) = 0;
+};
+
class InventoryWidget : public Widget {
public:
- InventoryWidget(Gui &gui, Gui::InventoryMap &inventoryMap, const Common::Array<Graphics::Surface> &inventorySurfaces);
- virtual void draw(Graphics::ManagedSurface &) override;
+ InventoryWidget(GuiScreen &gui, const Common::Array<Graphics::Surface> &inventorySurfaces);
+ void setCallback(InventoryWidgetCallback *callback) {
+ _callback = callback;
+ }
+
+ virtual void handleEvent(const Common::Event &event) override;
+
+protected:
+ virtual void draw(Graphics::ManagedSurface &surface) override;
private:
void drawInventoryItem(Graphics::ManagedSurface &surface, const Common::String &item, int pos);
- Gui::InventoryMap &_inventoryMap;
const Common::Array<Graphics::Surface> &_surfaces;
+ InventoryWidgetCallback *_callback;
+ int _hoveredItemPos;
};
}
diff --git a/engines/mutationofjb/widgets/widget.h b/engines/mutationofjb/widgets/widget.h
index e16b1e4447..86c912a555 100644
--- a/engines/mutationofjb/widgets/widget.h
+++ b/engines/mutationofjb/widgets/widget.h
@@ -36,11 +36,11 @@ class ManagedSurface;
namespace MutationOfJB {
-class Gui;
+class GuiScreen;
class Widget {
public:
- Widget(Gui &gui, const Common::Rect &area) : _gui(gui), _area(area), _id(0), _visible(true), _dirty(true) {}
+ Widget(GuiScreen &gui, const Common::Rect &area) : _gui(gui), _area(area), _id(0), _visible(true), _dirty(true) {}
virtual ~Widget() {}
int getId() const;
@@ -57,7 +57,7 @@ public:
protected:
virtual void draw(Graphics::ManagedSurface &) = 0;
- Gui &_gui;
+ GuiScreen &_gui;
Common::Rect _area;
int _id;
bool _visible;