diff options
-rw-r--r-- | engines/titanic/core/game_object.h | 10 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_glyphs.cpp | 18 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_glyphs.h | 16 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_inventory.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_inventory.h | 10 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_inventory_glyphs.cpp | 181 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_inventory_glyphs.h | 71 |
7 files changed, 248 insertions, 60 deletions
diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index afcd2f05ee..7f245cc5fe 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -280,11 +280,6 @@ protected: */ Point getControid() const; - /** - * Set the position of the object - */ - void setPosition(const Point &newPos); - void sound8(bool flag) const; /** @@ -484,6 +479,11 @@ public: bool checkPoint(const Point &pt, bool ignore40 = false, bool visibleOnly = false); /** + * Set the position of the object + */ + void setPosition(const Point &newPos); + + /** * Change the object's status */ void playMovie(uint flags); diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp index 2e9b590db1..c132a2f0ab 100644 --- a/engines/titanic/pet_control/pet_glyphs.cpp +++ b/engines/titanic/pet_control/pet_glyphs.cpp @@ -120,24 +120,20 @@ void CPetGlyphs::reset() { } } -bool CPetGlyphs::enter() { +void CPetGlyphs::enter() { if (_highlightIndex != -1) { CPetGlyph *glyph = getGlyph(_highlightIndex); - if (glyph && glyph->enter()) - return true; + if (glyph) + glyph->enter(); } - - return false; } -bool CPetGlyphs::leave() { +void CPetGlyphs::leave() { if (_highlightIndex != -1) { CPetGlyph *glyph = getGlyph(_highlightIndex); - if (glyph && glyph->leave()) - return true; + if (glyph) + glyph->leave(); } - - return false; } void CPetGlyphs::draw(CScreenManager *screenManager) { @@ -419,8 +415,6 @@ bool CPetGlyphs::KeyCharMsg(int key) { } bool CPetGlyphs::VirtualKeyCharMsg(int key) { - bool handled = false; - switch (key) { case Common::KEYCODE_LEFT: decSelection(); diff --git a/engines/titanic/pet_control/pet_glyphs.h b/engines/titanic/pet_control/pet_glyphs.h index 9dfe5ad3fa..e240cd1b86 100644 --- a/engines/titanic/pet_control/pet_glyphs.h +++ b/engines/titanic/pet_control/pet_glyphs.h @@ -76,12 +76,12 @@ public: /** * Called when the PET area is entered */ - virtual bool enter() { return false; } + virtual void enter() {} /** * Called when the PET area is left */ - virtual bool leave() { return false; } + virtual void leave() {} /** * Draw the glyph at a specified position @@ -151,7 +151,7 @@ public: /** * Glyph has been shifted to be first visible one */ - virtual void glyphFocused(const Point &pt, bool flag) {} + virtual void glyphFocused(const Point &topLeft, bool flag) {} /** * Selects a glyph @@ -180,7 +180,11 @@ public: virtual void saveGlyph(SimpleFile *file, int indent) {} virtual bool proc33(CPetGlyph *glyph) { return true; } - virtual int proc34() { return 1; } + + /** + * Return whether the glyph has an associated image + */ + virtual bool hasImage() const { return true; } /** * Called on a highlighted item when PET area is entered @@ -328,12 +332,12 @@ public: /** * Called when PET area is entered */ - virtual bool enter(); + virtual void enter(); /** * Called when PET area is left */ - virtual bool leave(); + virtual void leave(); void setFlags(int flags) { _flags = flags; } diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp index bf6b913d0d..930a93fbcb 100644 --- a/engines/titanic/pet_control/pet_inventory.cpp +++ b/engines/titanic/pet_control/pet_inventory.cpp @@ -199,7 +199,7 @@ CGameObject *CPetInventory::getImage(int index) { return nullptr; } -void CPetInventory::setMovie(CGameObject *movie, int flag) { +void CPetInventory::playMovie(CGameObject *movie, int flag) { if (_movie) _movie->stopMovie(); _movie = movie; diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h index 58e6bd9a1d..3437d098ef 100644 --- a/engines/titanic/pet_control/pet_inventory.h +++ b/engines/titanic/pet_control/pet_inventory.h @@ -53,11 +53,6 @@ private: * Get the index of an item added to the PET */ int getItemIndex(CGameObject *item) const; - - /** - * Set the animated inventory item movie - */ - void setMovie(CGameObject *movie, int flag); public: CPetInventory(); @@ -140,6 +135,11 @@ public: void highlightItem(CGameObject *item); CGameObject *getImage(int index); + + /** + * Play the animated movie for an object + */ + void playMovie(CGameObject *movie, int flag); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_inventory_glyphs.cpp b/engines/titanic/pet_control/pet_inventory_glyphs.cpp index 441726ee75..57c8611b9c 100644 --- a/engines/titanic/pet_control/pet_inventory_glyphs.cpp +++ b/engines/titanic/pet_control/pet_inventory_glyphs.cpp @@ -20,9 +20,9 @@ * */ -#include "common/textconsole.h" #include "titanic/pet_control/pet_inventory_glyphs.h" #include "titanic/pet_control/pet_inventory.h" +#include "titanic/messages/pet_messages.h" #include "titanic/titanic.h" namespace Titanic { @@ -34,6 +34,129 @@ const uint ITEM_MODES[40] = { 33, 34, 35, 38, 41, 42, 43, 44, 45, 37 }; +void CPetInventoryGlyph::enter() { + startBackgroundMovie(); +} + +void CPetInventoryGlyph::leave() { + stopMovie(); +} + +void CPetInventoryGlyph::drawAt(CScreenManager *screenManager, const Point &pt, bool isHighlighted) { + if (!_field34) + return; + + if (_image) { + if (_image->hasActiveMovie()) { + if (isHighlighted) + _image->draw(screenManager); + else + _image->draw(screenManager, pt); + return; + } + + _image = nullptr; + if (_background && isHighlighted) { + _background->setPosition(pt); + startBackgroundMovie(); + } + } + + if (_background) { + if (isHighlighted) + _background->draw(screenManager); + else + _background->draw(screenManager, pt); + } else if (_image) { + _image->draw(screenManager, pt, Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); + } +} + + +void CPetInventoryGlyph::unhighlightCurrent() { + if (_image) { + _image->setPosition(Point(0, 0)); + stopMovie(); + } else if (_background) { + _background->setPosition(Point(0, 0)); + _background->loadFrame(0); + stopMovie(); + } +} + +void CPetInventoryGlyph::highlightCurrent(const Point &pt) { + reposition(pt); + if (_item) { + CPETObjectSelectedMsg selectedMsg; + selectedMsg.execute(_item); + } +} + +void CPetInventoryGlyph::glyphFocused(const Point &topLeft, bool flag) { + if (_background && flag) + _background->setPosition(topLeft); +} + +bool CPetInventoryGlyph::dragGlyph(const Point &topLeft, CMouseDragStartMsg *msg) { + warning("TODO"); + return false; +} + +void CPetInventoryGlyph::getTooltip(CPetText *text) { + if (text) { + text->setText(""); + + if (_field34 && _item) { + int itemIndex = populateItem(_item, 0); + if (itemIndex >= 14 && itemIndex <= 18) { + CPETObjectStateMsg stateMsg(0); + stateMsg.execute(_item); + + text->setText(CString::format("%s %s", + stateMsg._value ? "A hot " : "A cold ", + g_vm->_itemDescriptions[itemIndex].c_str() + )); + + } else { + text->setText(g_vm->_itemDescriptions[itemIndex]); + } + } + } +} + +bool CPetInventoryGlyph::doAction(CGlyphAction *action) { + CInventoryGlyphAction *invAction = static_cast<CInventoryGlyphAction *>(action); + CPetInventoryGlyphs *owner = static_cast<CPetInventoryGlyphs *>(_owner); + if (!invAction) + return false; + + switch (invAction->getMode()) { + case ACTION_REMOVED: + if (invAction->_item == _item) { + _item = nullptr; + _background = nullptr; + _field34 = 0; + } + break; + + case ACTION_REMOVE: + if (_item == invAction->_item && _owner) { + int v = populateItem(_item, 0); + _background = owner->getBackground(v); + + if (isHighlighted()) { + warning("TODO"); + } + } + break; + + default: + break; + } + + return true; +} + void CPetInventoryGlyph::setItem(CGameObject *item, int val) { _item = item; @@ -127,37 +250,39 @@ int CPetInventoryGlyph::subMode(CGameObject *item, int val) { return frameNum; } -bool CPetInventoryGlyph::doAction(CGlyphAction *action) { - CInventoryGlyphAction *invAction = static_cast<CInventoryGlyphAction *>(action); - CPetInventoryGlyphs *owner = static_cast<CPetInventoryGlyphs *>(_owner); - if (!invAction) - return false; - - switch (invAction->getMode()) { - case ACTION_REMOVED: - if (invAction->_item == _item) { - _item = nullptr; - _background = nullptr; - _field34 = 0; - } - break; - - case ACTION_REMOVE: - if (_item == invAction->_item && _owner) { - int v = populateItem(_item, 0); - _background = owner->getBackground(v); +void CPetInventoryGlyph::startBackgroundMovie() { + if (_owner) { + CPetInventory *section = static_cast<CPetInventory *>(_owner->getOwner()); + if (section) + section->playMovie(_background, 1); + } +} - if (isHighlighted()) { - warning("TODO"); - } - } - break; +void CPetInventoryGlyph::startForegroundMovie() { + if (_owner) { + CPetInventory *section = static_cast<CPetInventory *>(_owner->getOwner()); + if (section) + section->playMovie(_image, 1); + } +} - default: - break; +void CPetInventoryGlyph::stopMovie() { + if (_owner) { + CPetInventory *section = static_cast<CPetInventory *>(_owner->getOwner()); + if (section) + section->playMovie(nullptr, 1); } +} - return true; +void CPetInventoryGlyph::reposition(const Point &pt) { + if (_image) { + _image->setPosition(pt); + startForegroundMovie(); + } + else if (_background) { + _background->setPosition(pt); + startBackgroundMovie(); + } } /*------------------------------------------------------------------------*/ diff --git a/engines/titanic/pet_control/pet_inventory_glyphs.h b/engines/titanic/pet_control/pet_inventory_glyphs.h index 17222a9076..06e1d06d30 100644 --- a/engines/titanic/pet_control/pet_inventory_glyphs.h +++ b/engines/titanic/pet_control/pet_inventory_glyphs.h @@ -37,21 +37,81 @@ private: int populateItem(CGameObject *item, int val); int subMode(CGameObject *item, int val); + + /** + * Start any movie for the background + */ + void startBackgroundMovie(); + + /** + * Start any movie for the foreground item + */ + void startForegroundMovie(); + + /** + * Stop any previously started foreground or background movie + */ + void stopMovie(); + + /** + * Reposition the inventory item + */ + void reposition(const Point &pt); public: CGameObject *_item; int _field34; CGameObject *_background; CGameObject *_image; public: - CPetInventoryGlyph() : _item(nullptr), _field34(0), + CPetInventoryGlyph() : _item(nullptr), _field34(1), _background(nullptr), _image(nullptr) {} CPetInventoryGlyph(CCarry *item, int val) : _item(item), _field34(val), _background(nullptr), _image(nullptr) {} /** - * Set the inventory item + * Called when the PET area is entered */ - void setItem(CGameObject *item, int val); + virtual void enter(); + + /** + * Called when the PET area is left + */ + virtual void leave(); + + /** + * Draw the glyph at a specified position + */ + virtual void drawAt(CScreenManager *screenManager, const Point &pt, bool isHighlighted); + + /** + * Unhighlight any currently highlighted element + */ + virtual void unhighlightCurrent(); + + /** + * Highlight any currently highlighted element + */ + virtual void highlightCurrent(const Point &pt); + + /** + * Glyph has been shifted to be first visible one + */ + virtual void glyphFocused(const Point &topLeft, bool flag); + + /** + * Called when a glyph drag starts + */ + virtual bool dragGlyph(const Point &topLeft, CMouseDragStartMsg *msg); + + /** + * Returns the tooltip text for when the glyph is selected + */ + virtual void getTooltip(CPetText *text); + + /** + * Return whether the glyph has an associated image + */ + virtual bool hasImage() const { return _item && _background; } /** * Returns the object associated with the glyph @@ -62,6 +122,11 @@ public: * Does a processing action on the glyph */ virtual bool doAction(CGlyphAction *action); + + /** + * Set the inventory item + */ + void setItem(CGameObject *item, int val); }; class CInventoryGlyphAction : public CGlyphAction { |