diff options
Diffstat (limited to 'engines/mutationofjb/widgets')
-rw-r--r-- | engines/mutationofjb/widgets/buttonwidget.cpp | 2 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/buttonwidget.h | 2 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/conversationwidget.cpp | 4 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/conversationwidget.h | 2 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/imagewidget.cpp | 2 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/imagewidget.h | 2 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/inventorywidget.cpp | 64 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/inventorywidget.h | 41 | ||||
-rw-r--r-- | engines/mutationofjb/widgets/widget.h | 6 |
9 files changed, 104 insertions, 21 deletions
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; |