From 42c8ac1c880076c181071922aff3b923a185af98 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 25 Jun 2016 16:09:15 -0400 Subject: TITANIC: Added Pet Inventorty virtual methods --- engines/titanic/pet_control/pet_control.cpp | 2 +- engines/titanic/pet_control/pet_glyphs.cpp | 45 +++++++++++++++++---- engines/titanic/pet_control/pet_glyphs.h | 45 +++++++++++++++------ engines/titanic/pet_control/pet_inventory.cpp | 47 ++++++++++++++++++++-- engines/titanic/pet_control/pet_inventory.h | 47 +++++++++++++++++----- engines/titanic/pet_control/pet_inventory_glyphs.h | 4 +- engines/titanic/pet_control/pet_real_life.cpp | 2 +- engines/titanic/pet_control/pet_real_life.h | 2 - engines/titanic/pet_control/pet_remote.cpp | 2 +- engines/titanic/pet_control/pet_rooms.cpp | 2 +- engines/titanic/pet_control/pet_rooms.h | 3 ++ engines/titanic/pet_control/pet_section.h | 8 +++- 12 files changed, 168 insertions(+), 41 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index e2279e5bba..f5c5647688 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -131,7 +131,7 @@ void CPetControl::draw(CScreenManager *screenManager) { if (!bounds.isEmpty()) { if (_fieldC8 >= 0) { - _inventory.proc5(_fieldC8); + _inventory.changed(_fieldC8); _fieldC8 = -1; } diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp index c132a2f0ab..eca6f309ad 100644 --- a/engines/titanic/pet_control/pet_glyphs.cpp +++ b/engines/titanic/pet_control/pet_glyphs.cpp @@ -182,7 +182,7 @@ Point CPetGlyphs::getPosition(int index) const { return tempPoint; } -Rect CPetGlyphs::getRect(int index) { +Rect CPetGlyphs::getRect(int index) const { Point pt = getPosition(index); return Rect(pt.x, pt.y, pt.x + 52, pt.y + 52); } @@ -235,7 +235,7 @@ int CPetGlyphs::getHighlightedIndex(int index) const { return (idx >= 0 && idx < _numVisibleGlyphs) ? idx : -1; } -int CPetGlyphs::getItemIndex(int index) { +int CPetGlyphs::getItemIndex(int index) const { return _firstVisibleIndex + index; } @@ -248,8 +248,8 @@ void CPetGlyphs::setSelectedIndex(int index) { } } -CPetGlyph *CPetGlyphs::getGlyph(int index) { - for (iterator i = begin(); i != end(); ++i) { +CPetGlyph *CPetGlyphs::getGlyph(int index) const { + for (const_iterator i = begin(); i != end(); ++i) { if (index-- == 0) return *i; } @@ -414,7 +414,9 @@ bool CPetGlyphs::KeyCharMsg(int key) { return false; } -bool CPetGlyphs::VirtualKeyCharMsg(int key) { +bool CPetGlyphs::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { + Common::KeyCode key = msg->_keyState.keycode; + switch (key) { case Common::KEYCODE_LEFT: decSelection(); @@ -430,7 +432,7 @@ bool CPetGlyphs::VirtualKeyCharMsg(int key) { if (_highlightIndex >= 0) { CPetGlyph *glyph = getGlyph(_highlightIndex); - if (glyph && glyph->VirtualKeyCharMsg(key)) + if (glyph && glyph->VirtualKeyCharMsg(msg)) return true; } @@ -502,7 +504,7 @@ void CPetGlyphs::decSelection() { } } -CGameObject *CPetGlyphs::getObjectAt(const Point &pt) { +CGameObject *CPetGlyphs::getObjectAt(const Point &pt) const { for (int idx = 0; idx < _numVisibleGlyphs; ++idx) { Rect glyphRect = getRect(idx); if (glyphRect.contains(pt)) { @@ -532,4 +534,33 @@ Point CPetGlyphs::getHighlightedGlyphPos() const { return Point(0, 0); } +bool CPetGlyphs::areItemsValid() const { + for (const_iterator i = begin(); i != end(); ++i) { + if (!(*i)->isValid()) + return false; + } + + return true; +} + +void CPetGlyphs::removeInvalid() { + if (!areItemsValid()) { + changeHighlight(-1); + + for (iterator i = begin(); i != end(); ) { + CPetGlyph *glyph = *i; + + if (!glyph->isValid()) { + i = erase(i); + delete glyph; + } else { + ++i; + } + } + + _firstVisibleIndex = CLIP(_firstVisibleIndex, 0, + (int)size() - _numVisibleGlyphs); + } +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_glyphs.h b/engines/titanic/pet_control/pet_glyphs.h index e240cd1b86..7271d6cd61 100644 --- a/engines/titanic/pet_control/pet_glyphs.h +++ b/engines/titanic/pet_control/pet_glyphs.h @@ -127,16 +127,21 @@ public: * Handles mouse button up messages */ virtual bool MouseButtonUpMsg(const Point &pt) { return false; } - - virtual int proc21() { return 0; } - virtual int proc22() { return 0; } /** - * Handles keypresses when the glyph is focused + * Handles mouse double-click messages + */ + virtual bool MouseDoubleClickMsg(const CMouseDoubleClickMsg *msg) { return false; } + + /** + * Handles keypresses */ virtual bool KeyCharMsg(int key) { return false; } - virtual bool VirtualKeyCharMsg(int key) { return false; } + /** + * Handles keypresses + */ + virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; } /** * Unhighlight any currently highlighted element @@ -182,9 +187,9 @@ public: virtual bool proc33(CPetGlyph *glyph) { return true; } /** - * Return whether the glyph has an associated image + * Return whether the glyph is currently valid */ - virtual bool hasImage() const { return true; } + virtual bool isValid() const { return true; } /** * Called on a highlighted item when PET area is entered @@ -247,7 +252,7 @@ private: /** * Get a rect for the glyph */ - Rect getRect(int index); + Rect getRect(int index) const; /** * Returns the on-screen index for the highlight to be shown at @@ -257,7 +262,7 @@ private: /** * Returns the index of a glyph given the visible on-screen glyph number */ - int getItemIndex(int index); + int getItemIndex(int index) const; /** * Set the item index @@ -267,7 +272,7 @@ private: /** * Return a specified glyph */ - CPetGlyph *getGlyph(int index); + CPetGlyph *getGlyph(int index) const; /** * Scrolls the glyphs to the left @@ -288,6 +293,11 @@ private: * Make the PET dirty */ void makePetDirty(); + + /** + * Returns true if all the glyphs are in a valid state + */ + bool areItemsValid() const; protected: int _firstVisibleIndex; int _totalGlyphs; @@ -376,6 +386,11 @@ public: */ bool MouseButtonUpMsg(const Point &pt); + /** + * Mouse double click message + */ + bool MouseDoubleClickMsg(const Point &pt) { return true; } + /** * Mouse drag start messagge */ @@ -399,7 +414,7 @@ public: /** * Virtual key message */ - bool VirtualKeyCharMsg(int key); + bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg); /** * When the PET section is entered, passes onto the highlighted @@ -453,7 +468,7 @@ public: /** * Returns the object associated the glyph under the specified position */ - CGameObject *getObjectAt(const Point &pt); + CGameObject *getObjectAt(const Point &pt) const; /** * Returns true if the specified glyph is the currently highlighted one @@ -464,6 +479,12 @@ public: * Get the top-left position of the currently highlighted glyph */ Point getHighlightedGlyphPos() const; + + /** + * Removes any glyphs from the list that no longer have any images + * associated with them + */ + void removeInvalid(); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp index 930a93fbcb..a207c6695d 100644 --- a/engines/titanic/pet_control/pet_inventory.cpp +++ b/engines/titanic/pet_control/pet_inventory.cpp @@ -41,8 +41,9 @@ bool CPetInventory::setup(CPetControl *petControl) { bool CPetInventory::reset() { _items.reset(); _text.setup(); + _text.setColor(getColor(0)); + _text.setLineColor(0, getColor(0)); - // TODO return true; } @@ -56,9 +57,45 @@ Rect CPetInventory::getBounds() { return _movie ? _movie->getBounds() : Rect(); } +void CPetInventory::changed(int changeType) { + switch (changeType) { + case 0: + case 2: + itemsChanged(); + break; + case 1: + removeInvalid(); + break; + default: + break; + } +} + +bool CPetInventory::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { + return _items.MouseButtonDownMsg(msg->_mousePos); +} + +bool CPetInventory::MouseDragStartMsg(CMouseDragStartMsg *msg) { + bool result = _items.MouseDragStartMsg(msg); + if (result) + _petControl->makeDirty(); + return result; +} + +bool CPetInventory::MouseButtonUpMsg(CMouseButtonUpMsg *msg) { + return _items.MouseButtonUpMsg(msg->_mousePos); +} + +bool CPetInventory::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) { + return _items.MouseDoubleClickMsg(msg->_mousePos); +} + +bool CPetInventory::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { + return _items.VirtualKeyCharMsg(msg); +} + CGameObject *CPetInventory::dragEnd(const Point &pt) const { - warning("TODO: CPetInventory::dragEnd"); - return nullptr; + return _items.getObjectAt(pt); } bool CPetInventory::isValid(CPetControl *petControl) { @@ -212,4 +249,8 @@ void CPetInventory::playMovie(CGameObject *movie, int flag) { } } +void CPetInventory::removeInvalid() { + _items.removeInvalid(); +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h index 3437d098ef..e931abf5c6 100644 --- a/engines/titanic/pet_control/pet_inventory.h +++ b/engines/titanic/pet_control/pet_inventory.h @@ -53,6 +53,11 @@ private: * Get the index of an item added to the PET */ int getItemIndex(CGameObject *item) const; + + /** + * Remove any invalid inventory glyphs + */ + void removeInvalid(); public: CPetInventory(); @@ -77,41 +82,63 @@ public: virtual Rect getBounds(); /** - * Save the data for the class to file + * Called when a general change occurs */ - virtual void save(SimpleFile *file, int indent) const; + virtual void changed(int changeType); /** - * Load the data for the class from file + * Following are handlers for the various messages that the PET can + * pass onto the currently active section/area */ - virtual void load(SimpleFile *file, int param); + virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); + virtual bool MouseDragStartMsg(CMouseDragStartMsg *msg); + virtual bool MouseButtonUpMsg(CMouseButtonUpMsg *msg); + virtual bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg); + virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg); /** * Returns item a drag-drop operation has dropped on, if any */ virtual CGameObject *dragEnd(const Point &pt) const; - /** * Returns true if the object is in a valid state */ virtual bool isValid(CPetControl *petControl); + /** + * Load the data for the class from file + */ + virtual void load(SimpleFile *file, int param); + /** * Called after a game has been loaded */ virtual void postLoad(); /** - * Called when a section is switched to + * Save the data for the class to file */ + virtual void save(SimpleFile *file, int indent) const; + + /** + * Called when a section is switched to + */ virtual void enter(PetArea oldArea); - + /** - * Called when a section is being left, to switch to another area - */ + * Called when a section is being left, to switch to another area + */ virtual void leave(); - + + /** + * Get a reference to the tooltip text associated with the section + */ + virtual CPetText *getText() { return &_text; } + + /** + * Special retrieval of glyph background image + */ virtual CGameObject *getBackground(int index) const; /** diff --git a/engines/titanic/pet_control/pet_inventory_glyphs.h b/engines/titanic/pet_control/pet_inventory_glyphs.h index 06e1d06d30..716c9d1ad1 100644 --- a/engines/titanic/pet_control/pet_inventory_glyphs.h +++ b/engines/titanic/pet_control/pet_inventory_glyphs.h @@ -109,9 +109,9 @@ public: virtual void getTooltip(CPetText *text); /** - * Return whether the glyph has an associated image + * Return whether the glyph is currently valid */ - virtual bool hasImage() const { return _item && _background; } + virtual bool isValid() const { return _item && _background; } /** * Returns the object associated with the glyph diff --git a/engines/titanic/pet_control/pet_real_life.cpp b/engines/titanic/pet_control/pet_real_life.cpp index 72e350cd33..b9e1990dd2 100644 --- a/engines/titanic/pet_control/pet_real_life.cpp +++ b/engines/titanic/pet_control/pet_real_life.cpp @@ -76,7 +76,7 @@ bool CPetRealLife::KeyCharMsg(CKeyCharMsg *msg) { } bool CPetRealLife::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { - return _glyphs.VirtualKeyCharMsg(msg->_keyState.keycode); + return _glyphs.VirtualKeyCharMsg(msg); } void CPetRealLife::postLoad() { diff --git a/engines/titanic/pet_control/pet_real_life.h b/engines/titanic/pet_control/pet_real_life.h index b00c7c14c3..aa980fca0f 100644 --- a/engines/titanic/pet_control/pet_real_life.h +++ b/engines/titanic/pet_control/pet_real_life.h @@ -69,8 +69,6 @@ public: */ virtual Rect getBounds() { return Rect(); } - virtual void proc5(int val) {} - /** * Following are handlers for the various messages that the PET can * pass onto the currently active section/area diff --git a/engines/titanic/pet_control/pet_remote.cpp b/engines/titanic/pet_control/pet_remote.cpp index f59f1fb0d7..9b43b8dab9 100644 --- a/engines/titanic/pet_control/pet_remote.cpp +++ b/engines/titanic/pet_control/pet_remote.cpp @@ -158,7 +158,7 @@ bool CPetRemote::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) { } bool CPetRemote::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { - return _items.VirtualKeyCharMsg(msg->_keyState.keycode); + return _items.VirtualKeyCharMsg(msg); } bool CPetRemote::isValid(CPetControl *petControl) { diff --git a/engines/titanic/pet_control/pet_rooms.cpp b/engines/titanic/pet_control/pet_rooms.cpp index bbb8dafef7..467c645e0e 100644 --- a/engines/titanic/pet_control/pet_rooms.cpp +++ b/engines/titanic/pet_control/pet_rooms.cpp @@ -92,7 +92,7 @@ bool CPetRooms::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) { } bool CPetRooms::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { - return _glyphs.VirtualKeyCharMsg(msg->_keyState.keycode); + return _glyphs.VirtualKeyCharMsg(msg); } bool CPetRooms::checkDragEnd(CGameObject *item) { diff --git a/engines/titanic/pet_control/pet_rooms.h b/engines/titanic/pet_control/pet_rooms.h index b39587a7f7..14dbf8f26f 100644 --- a/engines/titanic/pet_control/pet_rooms.h +++ b/engines/titanic/pet_control/pet_rooms.h @@ -144,6 +144,9 @@ public: */ virtual CPetText *getText(); + /** + * Special retrieval of glyph background image + */ virtual CGameObject *getBackground(int index); /** diff --git a/engines/titanic/pet_control/pet_section.h b/engines/titanic/pet_control/pet_section.h index d888e051c8..cf729b70a4 100644 --- a/engines/titanic/pet_control/pet_section.h +++ b/engines/titanic/pet_control/pet_section.h @@ -76,7 +76,10 @@ public: */ virtual Rect getBounds() { return Rect(); } - virtual void proc5(int val) {} + /** + * Called when a general change occurs + */ + virtual void changed(int changeType) {} /** * Following are handlers for the various messages that the PET can @@ -159,6 +162,9 @@ public: */ virtual CPetElement *getElement(uint id) { return nullptr; } + /** + * Special retrieval of glyph background image + */ virtual CGameObject *getBackground(int index) const { return nullptr; } /** -- cgit v1.2.3