[Scummvm-git-logs] scummvm master -> c36fb36afba47f52c1f81f1df61eb31838134cd2
LubomirR
lubomirr at lubomirr.eu
Thu Sep 6 19:41:57 CEST 2018
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c36fb36afb MUTATIONOFJB: Add support for 'look' action on inventory items.
Commit: c36fb36afba47f52c1f81f1df61eb31838134cd2
https://github.com/scummvm/scummvm/commit/c36fb36afba47f52c1f81f1df61eb31838134cd2
Author: Ľubomír Remák (lubomirr at lubomirr.eu)
Date: 2018-09-06T19:38:16+02:00
Commit Message:
MUTATIONOFJB: Add support for 'look' action on inventory items.
Changed paths:
A engines/mutationofjb/gamescreen.cpp
A engines/mutationofjb/gamescreen.h
A engines/mutationofjb/guiscreen.cpp
A engines/mutationofjb/guiscreen.h
A engines/mutationofjb/inventoryitemdefinitionlist.cpp
A engines/mutationofjb/inventoryitemdefinitionlist.h
R engines/mutationofjb/gui.cpp
R engines/mutationofjb/gui.h
engines/mutationofjb/assets.cpp
engines/mutationofjb/assets.h
engines/mutationofjb/game.cpp
engines/mutationofjb/game.h
engines/mutationofjb/inventory.cpp
engines/mutationofjb/module.mk
engines/mutationofjb/mutationofjb.cpp
engines/mutationofjb/tasks/conversationtask.cpp
engines/mutationofjb/widgets/buttonwidget.cpp
engines/mutationofjb/widgets/buttonwidget.h
engines/mutationofjb/widgets/conversationwidget.cpp
engines/mutationofjb/widgets/conversationwidget.h
engines/mutationofjb/widgets/imagewidget.cpp
engines/mutationofjb/widgets/imagewidget.h
engines/mutationofjb/widgets/inventorywidget.cpp
engines/mutationofjb/widgets/inventorywidget.h
engines/mutationofjb/widgets/widget.h
diff --git a/engines/mutationofjb/assets.cpp b/engines/mutationofjb/assets.cpp
index 2adda51..6f32361 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 2cd0612..89ed678 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 ff05bb9..5e0d1e6 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 6230b93..adb5bf5 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/gamescreen.cpp b/engines/mutationofjb/gamescreen.cpp
new file mode 100644
index 0000000..3c007f4
--- /dev/null
+++ b/engines/mutationofjb/gamescreen.cpp
@@ -0,0 +1,214 @@
+/* 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/gamescreen.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 "mutationofjb/widgets/widget.h"
+#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 {
+
+enum ButtonType {
+ BUTTON_WALK = 0,
+ BUTTON_TALK,
+ BUTTON_LOOK,
+ BUTTON_USE,
+ BUTTON_PICKUP,
+ BUTTON_SCROLL_LEFT,
+ BUTTON_SCROLL_RIGHT,
+ BUTTON_SETTINGS,
+ NUM_BUTTONS
+};
+
+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,
+ CONVERSATION_X = 0,
+ CONVERSATION_Y = 139,
+ CONVERSATION_WIDTH = 320,
+ CONVERSATION_HEIGHT = 61
+};
+
+
+GameScreen::GameScreen(Game &game, Graphics::Screen *screen)
+ : GuiScreen(game, screen),
+ _inventoryWidget(nullptr),
+ _conversationWidget(nullptr) {}
+
+GameScreen::~GameScreen() {}
+
+bool GameScreen::init() {
+ if (!loadInventoryGfx()) {
+ return false;
+ }
+
+ if (!loadHudGfx()) {
+ return false;
+ }
+
+ _game.getGameData().getInventory().setObserver(this);
+
+ // Init widgets.
+
+ 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);
+ addWidget(image);
+
+ _inventoryWidget = new InventoryWidget(*this, _inventorySurfaces);
+ _inventoryWidget->setCallback(this);
+ addWidget(_inventoryWidget);
+
+ const 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
+ };
+
+ for (int i = 0; i < NUM_BUTTONS; ++i) {
+ const Graphics::Surface normalSurface = _hudSurfaces[0].getSubArea(ButtonRects[i]);
+ const Graphics::Surface pressedSurface = _hudSurfaces[1].getSubArea(ButtonRects[i]);
+ ButtonWidget *button = new ButtonWidget(*this, ButtonRects[i], normalSurface, pressedSurface);
+ button->setId(i);
+ button->setCallback(this);
+ 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);
+ addWidget(_conversationWidget);
+
+ return true;
+}
+
+ConversationWidget &GameScreen::getConversationWidget() {
+ return *_conversationWidget;
+}
+
+class InventoryAnimationDecoderCallback : public AnimationDecoderCallback {
+public:
+ InventoryAnimationDecoderCallback(GameScreen &gui) : _gui(gui) {}
+ virtual void onFrame(int frameNo, Graphics::Surface &surface) override;
+ virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) override;
+private:
+ GameScreen &_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 GameScreen::loadInventoryGfx() {
+ AnimationDecoder decoder("icons.dat");
+ InventoryAnimationDecoderCallback callback(*this);
+ return decoder.decode(&callback);
+}
+
+class HudAnimationDecoderCallback : public AnimationDecoderCallback {
+public:
+ HudAnimationDecoderCallback(GameScreen &gui) : _gui(gui) {}
+ virtual void onFrame(int frameNo, Graphics::Surface &surface) override;
+ virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) override;
+private:
+ GameScreen &_gui;
+};
+
+void HudAnimationDecoderCallback::onPaletteUpdated(byte [PALETTE_SIZE]) {
+}
+
+void HudAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &surface) {
+ if (frameNo == 0 || frameNo == 1 || frameNo == 4) {
+ Graphics::Surface outSurface;
+ outSurface.copyFrom(surface);
+ _gui._hudSurfaces.push_back(outSurface);
+ }
+}
+
+bool GameScreen::loadHudGfx() {
+ AnimationDecoder decoder("room0.dat");
+ HudAnimationDecoderCallback callback(*this);
+ return decoder.decode(&callback);
+}
+
+void GameScreen::onInventoryChanged() {
+ _inventoryWidget->markDirty();
+}
+
+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};
+ _game.setCurrentAction(actions[buttonId]);
+ } else if (buttonId == BUTTON_SCROLL_LEFT) {
+ _game.getGameData().getInventory().scrollLeft();
+ } else if (buttonId == BUTTON_SCROLL_RIGHT) {
+ _game.getGameData().getInventory().scrollRight();
+ }
+}
+
+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/gamescreen.h b/engines/mutationofjb/gamescreen.h
new file mode 100644
index 0000000..bc70580
--- /dev/null
+++ b/engines/mutationofjb/gamescreen.h
@@ -0,0 +1,84 @@
+/* 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 "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"
+
+namespace Common {
+struct Event;
+}
+
+namespace Graphics {
+class Screen;
+}
+
+namespace MutationOfJB {
+
+class Game;
+class Widget;
+class InventoryWidget;
+class ConversationWidget;
+
+class GameScreen : public GuiScreen, public InventoryObserver, public ButtonWidgetCallback, public InventoryWidgetCallback {
+public:
+ friend class InventoryAnimationDecoderCallback;
+ friend class HudAnimationDecoderCallback;
+
+ GameScreen(Game &game, Graphics::Screen *screen);
+ ~GameScreen();
+
+ bool init();
+
+ 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();
+ void drawInventoryItem(const Common::String &item, int pos);
+ void drawInventory();
+
+ Common::Array<Graphics::Surface> _inventorySurfaces;
+ Common::Array<Graphics::Surface> _hudSurfaces;
+
+ InventoryWidget *_inventoryWidget;
+ ConversationWidget *_conversationWidget;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/gui.cpp b/engines/mutationofjb/gui.cpp
deleted file mode 100644
index 7c219bc..0000000
--- a/engines/mutationofjb/gui.cpp
+++ /dev/null
@@ -1,263 +0,0 @@
-/* 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 "mutationofjb/widgets/widget.h"
-#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 {
-
-enum ButtonType {
- BUTTON_WALK = 0,
- BUTTON_TALK,
- BUTTON_LOOK,
- BUTTON_USE,
- BUTTON_PICKUP,
- BUTTON_SCROLL_LEFT,
- BUTTON_SCROLL_RIGHT,
- BUTTON_SETTINGS,
- NUM_BUTTONS
-};
-
-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,
- CONVERSATION_X = 0,
- CONVERSATION_Y = 139,
- CONVERSATION_WIDTH = 320,
- CONVERSATION_HEIGHT = 61
-};
-
-
-Gui::Gui(Game &game, Graphics::Screen *screen)
- : _game(game),
- _screen(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;
- }
-
- if (!loadInventoryGfx()) {
- return false;
- }
-
- if (!loadHudGfx()) {
- return false;
- }
-
- _game.getGameData().getInventory().setObserver(this);
-
- // Init widgets.
-
- 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);
-
- _inventoryWidget = new InventoryWidget(*this, _inventoryItems, _inventorySurfaces);
- _widgets.push_back(_inventoryWidget);
-
- const 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
- };
-
- for (int i = 0; i < NUM_BUTTONS; ++i) {
- const Graphics::Surface normalSurface = _hudSurfaces[0].getSubArea(ButtonRects[i]);
- const Graphics::Surface pressedSurface = _hudSurfaces[1].getSubArea(ButtonRects[i]);
- ButtonWidget *button = new ButtonWidget(*this, ButtonRects[i], normalSurface, pressedSurface);
- button->setId(i);
- button->setCallback(this);
- _widgets.push_back(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);
-
- 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() {
- return *_conversationWidget;
-}
-
-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);
-}
-
-class HudAnimationDecoderCallback : public AnimationDecoderCallback {
-public:
- HudAnimationDecoderCallback(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 HudAnimationDecoderCallback::onPaletteUpdated(byte [PALETTE_SIZE]) {
-}
-
-void HudAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &surface) {
- if (frameNo == 0 || frameNo == 1 || frameNo == 4) {
- Graphics::Surface outSurface;
- outSurface.copyFrom(surface);
- _gui._hudSurfaces.push_back(outSurface);
- }
-}
-
-bool Gui::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() {
- _inventoryWidget->markDirty();
-}
-
-void Gui::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};
- _game.setCurrentAction(actions[buttonId]);
- } else if (buttonId == BUTTON_SCROLL_LEFT) {
- _game.getGameData().getInventory().scrollLeft();
- } else if (buttonId == BUTTON_SCROLL_RIGHT) {
- _game.getGameData().getInventory().scrollRight();
- }
-}
-
-}
diff --git a/engines/mutationofjb/gui.h b/engines/mutationofjb/gui.h
deleted file mode 100644
index 354d04f..0000000
--- a/engines/mutationofjb/gui.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/* 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/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;
-}
-
-namespace Graphics {
-class Screen;
-}
-
-namespace MutationOfJB {
-
-class Game;
-class Widget;
-class InventoryWidget;
-class ConversationWidget;
-
-class Gui : public InventoryObserver, public ButtonWidgetCallback {
-public:
- typedef Common::HashMap<Common::String, int> InventoryMap;
-
- friend class InventoryAnimationDecoderCallback;
- friend class HudAnimationDecoderCallback;
-
- Gui(Game &game, Graphics::Screen *screen);
- ~Gui();
- Game &getGame();
-
- bool init();
- void update();
-
- void markDirty();
- void handleEvent(const Common::Event &event);
-
- virtual void onInventoryChanged() override;
- virtual void onButtonClicked(ButtonWidget *) 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;
-};
-
-}
-
-#endif
diff --git a/engines/mutationofjb/guiscreen.cpp b/engines/mutationofjb/guiscreen.cpp
new file mode 100644
index 0000000..5ad545d
--- /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 0000000..c1761be
--- /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 91bfd9f..6176425 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 0000000..8af9bd4
--- /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 0000000..5f29b27
--- /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 465f228..c7de62b 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 d96d165..84ef974 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 9c3ae4b..5167ec5 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 e2a9dd3..b7a1ce0 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 d148fa8..ae544b2 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 56e0057..049b73d 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 34ea215..ea6e49f 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 8eeb7ed..1bab1ad 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 da3dd36..80f5537 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 46bfab9..851f8af 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 f1841e8..1819aa1 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 e16b1e4..86c912a 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;
More information about the Scummvm-git-logs
mailing list