diff options
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/messages/messages.h | 2 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_glyphs.cpp | 211 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_glyphs.h | 124 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_inventory.cpp | 31 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_inventory.h | 16 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_real_life.cpp | 51 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_real_life.h | 28 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_section.h | 8 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_sound.cpp | 13 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_sound.h | 5 |
10 files changed, 441 insertions, 48 deletions
diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index 649b20b779..ae66af1780 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -265,7 +265,7 @@ MESSAGE0(CInitializeAnimMsg); MESSAGE1(CIsEarBowlPuzzleDone, int, value, 0); MESSAGE3(CIsHookedOnMsg, Rect, rect, Rect(), bool, result, false, CString, string1, ""); MESSAGE1(CIsParrotPresentMsg, bool, value, false); -MESSAGE1(CKeyCharMsg, int, value, 32); +MESSAGE1(CKeyCharMsg, int, key, 32); MESSAGE2(CLeaveNodeMsg, CNodeItem *, oldNode, nullptr, CNodeItem *, newNode, nullptr); MESSAGE2(CLeaveRoomMsg, CRoomItem *, oldRoom, nullptr, CRoomItem *, newRoom, nullptr); MESSAGE2(CLeaveViewMsg, CViewItem *, oldView, nullptr, CViewItem *, newView, nullptr); diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp index eedd94dff3..1ab7d7ee1b 100644 --- a/engines/titanic/pet_control/pet_glyphs.cpp +++ b/engines/titanic/pet_control/pet_glyphs.cpp @@ -22,6 +22,7 @@ #include "titanic/pet_control/pet_glyphs.h" #include "titanic/pet_control/pet_section.h" +#include "titanic/pet_control/pet_control.h" namespace Titanic { @@ -37,7 +38,7 @@ void CPetGlyph::drawAt(CScreenManager *screenManager, const Point &pt) { _element.translate(-pt.x, -pt.y); } -void CPetGlyph::proc14() { +void CPetGlyph::proc14(const Point &pt) { warning("TODO: CPetGlyph::proc14"); } @@ -66,7 +67,8 @@ void CPetGlyph::setName(const CString &name, CPetControl *petControl) { /*------------------------------------------------------------------------*/ CPetGlyphs::CPetGlyphs() : _firstVisibleIndex(0), _numVisibleGlyphs(TOTAL_GLYPHS), - _highlightIndex(-1), _field1C(-1), _field20(0), _owner(nullptr) { + _highlightIndex(-1), _field1C(-1), _field20(0), + _field94(nullptr), _owner(nullptr) { } void CPetGlyphs::setNumVisible(int total) { @@ -107,12 +109,24 @@ void CPetGlyphs::reset() { } } -void CPetGlyphs::proc10() { - error("TODO"); +bool CPetGlyphs::enter() { + if (_highlightIndex != -1) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + if (glyph && glyph->enter()) + return true; + } + + return false; } -void CPetGlyphs::proc11() { - error("TODO"); +bool CPetGlyphs::leave() { + if (_highlightIndex != -1) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + if (glyph && glyph->leave()) + return true; + } + + return false; } void CPetGlyphs::draw(CScreenManager *screenManager) { @@ -163,6 +177,11 @@ Point CPetGlyphs::getPosition(int index) { return tempPoint; } +Rect CPetGlyphs::getRect(int index) { + Point pt = getPosition(index); + return Rect(pt.x, pt.y, pt.x + 52, pt.y + 52); +} + void CPetGlyphs::changeHighlight(int index) { warning("TODO: CPetGlyphs::changeHighlight"); } @@ -193,4 +212,184 @@ CPetControl *CPetGlyphs::getPetControl() const { return _owner ? _owner->getPetControl() : nullptr; } +void CPetGlyphs::setFirstVisible(int index) { + if (index != _firstVisibleIndex) { + _firstVisibleIndex = index; + + if ((_field20 & 8) && _highlightIndex != -1) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + + if (glyph) { + int idx = getHighlightedIndex(_highlightIndex); + if (idx != -1) { + Point tempPt = getPosition(idx); + glyph->proc27(tempPt, true); + } + } + } + } +} + +void CPetGlyphs::scrollLeft() { + if (_firstVisibleIndex > 0) { + setFirstVisible(_firstVisibleIndex - 1); + if (_highlightIndex != -1) { + int index = getHighlightedIndex(_highlightIndex); + if (index == -1) + changeHighlight(_highlightIndex - 1); + } + + makePetDirty(); + } +} + +void CPetGlyphs::scrollRight() { + int count = size(); + int right = count - _numVisibleGlyphs; + + if (_firstVisibleIndex < right) { + setFirstVisible(_firstVisibleIndex + 1); + if (_highlightIndex != -1) { + int index = getHighlightedIndex(_highlightIndex); + if (index == -1) + changeHighlight(_highlightIndex + 1); + } + + makePetDirty(); + } +} + +void CPetGlyphs::makePetDirty() { + if (_owner && _owner->_petControl) + _owner->_petControl->makeDirty(); +} + +bool CPetGlyphs::mouseButtonDown(const Point &pt) { + if (_scrollLeft.contains2(pt)) { + scrollLeft(); + return true; + } + + if (_scrollRight.contains2(pt)) { + scrollRight(); + return true; + } + + for (int idx = 0; idx < _numVisibleGlyphs; ++idx) { + Rect glyphRect = getRect(idx); + if (glyphRect.contains(pt)) { + int index = getItemIndex(idx); + CPetGlyph *glyph = getGlyph(index); + if (glyph) { + if (index == _highlightIndex) { + glyph->proc28(glyphRect); + glyph->proc14(pt); + return true; + } else { + changeHighlight(index); + makePetDirty(); + return true; + } + } + } + } + + if (_highlightIndex != -1) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + + if (glyph) { + if (glyph->checkHighlight(pt)) + return true; + + if (!(_field20 & 2)) { + changeHighlight(-1); + makePetDirty(); + } + } + } + + return false; +} + +bool CPetGlyphs::mouseButtonUp(const Point &pt) { + if (_highlightIndex >= 0) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + if (glyph) { + if (glyph->MouseButtonMsg(pt)) + return true; + } + } + + return false; +} + +bool CPetGlyphs::mouseDragStart(CMouseDragStartMsg *msg) { + if (!(_field20 & 1) && _highlightIndex >= 0) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + int index = getHighlightedIndex(_highlightIndex); + Rect glyphRect = getRect(index); + + if (glyphRect.contains(msg->_mousePos)) + return glyph->proc29(glyphRect); + else + return glyph->MouseDragStartMsg(msg); + } + + return false; +} + +bool CPetGlyphs::mouseDragMove(CMouseDragMoveMsg *msg) { + if (_field94) { + error("TODO"); + } else { + return false; + } +} + +bool CPetGlyphs::mouseDragEnd(CMouseDragEndMsg *msg) { + if (_field94) { + error("TODO"); + } else { + return false; + } +} + +bool CPetGlyphs::keyCharMsg(int key) { + if (_highlightIndex >= 0) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + + if (glyph && glyph->KeyCharMsg(key)) + return true; + } + + return false; +} + +bool CPetGlyphs::virtualKeyCharMsg(int key) { + bool handled = false; + warning("TODO: CPetGlyphs::virtualKeyCharMsg"); + + if (!handled && _highlightIndex >= 0) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + if (glyph && glyph->VirtualKeyCharMsg(key)) + handled = true; + } + + return handled; +} + +bool CPetGlyphs::enterHighlighted() { + if (_highlightIndex >= 0) + return getGlyph(_highlightIndex)->enterHighlighted(); + else + return false; +} + +bool CPetGlyphs::leaveHighlighted() { + if (_highlightIndex >= 0) + return getGlyph(_highlightIndex)->leaveHighlighted(); + else + return false; +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_glyphs.h b/engines/titanic/pet_control/pet_glyphs.h index 9d2f283af4..496654762e 100644 --- a/engines/titanic/pet_control/pet_glyphs.h +++ b/engines/titanic/pet_control/pet_glyphs.h @@ -90,8 +90,15 @@ public: */ virtual bool reset() { return false; } - virtual void proc10() {} - virtual void proc11() {} + /** + * Called when the PET area is entered + */ + virtual bool enter() { return false; } + + /** + * Called when the PET area is left + */ + virtual bool leave() { return false; } /** * Draw the glyph at a specified position @@ -103,7 +110,7 @@ public: */ virtual void draw2(CScreenManager *screenManager) {} - virtual void proc14(); + virtual void proc14(const Point &pt); /** * Get the bounds for the glyph @@ -116,14 +123,14 @@ public: */ virtual bool checkHighlight(const Point &pt) { return false; } - virtual int proc17() { return 0; } + virtual bool MouseDragStartMsg(const CMouseDragStartMsg *msg) { return false; } virtual int proc18() { return 0; } virtual int proc19() { return 0; } /** * Handles mouse button messages */ - virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg) { return false; } + virtual bool MouseButtonMsg(const Point &pt) { return false; } virtual int proc21() { return 0; } virtual int proc22() { return 0; } @@ -131,9 +138,9 @@ public: /** * Handles keypresses when the glyph is focused */ - virtual bool KeyCharMsg(Common::KeyCode key) { return false; } + virtual bool KeyCharMsg(int key) { return false; } - virtual int proc24() { return 0; } + virtual bool VirtualKeyCharMsg(int key) { return false; } /** * Unhighlight any currently highlighted element @@ -145,9 +152,9 @@ public: */ virtual void highlightCurrent() {} - virtual void proc27() {} - virtual void proc28() {} - virtual int proc29() { return 0; } + virtual void proc27(const Point &pt, bool flag) {} + virtual void proc28(const Point &pt) {} + virtual int proc29(const Point &pt) { return 0; } /** * Returns true if the glyph's bounds, shifted to a given position, @@ -164,8 +171,17 @@ public: virtual int proc33() { return 1; } virtual int proc34() { return 1; } - virtual int proc35() { return 0; } - virtual void proc36() {} + + /** + * Called on a highlighted item when PET area is entered + */ + virtual bool enterHighlighted() { return false; } + + /** + * Called on a highlighted item when PET area is left + */ + virtual bool leaveHighlighted() { return false; } + virtual int proc37() { return 0; } /** @@ -182,6 +198,11 @@ private: Point getPosition(int index); /** + * Get a rect for the glyph + */ + Rect getRect(int index); + + /** * Returns the on-screen index for the highlight to be shown at */ int getHighlightedIndex(int index); @@ -195,6 +216,26 @@ private: * Return a specified glyph */ CPetGlyph *getGlyph(int index); + + /** + * Scrolls the glyphs to the left + */ + void scrollLeft(); + + /** + * Scrolls the glyphs to the right + */ + void scrollRight(); + + /** + * Set the first visible glyph index + */ + void setFirstVisible(int index); + + /** + * Make the PET dirty + */ + void makePetDirty(); protected: int _firstVisibleIndex; int _totalGlyphs; @@ -202,6 +243,7 @@ protected: int _highlightIndex; int _field1C; int _field20; + void *_field94; CPetSection *_owner; CPetGfxElement _selection; CPetGfxElement _scrollLeft; @@ -235,8 +277,15 @@ public: */ virtual void reset(); - virtual void proc10(); - virtual void proc11(); + /** + * Called when PET area is entered + */ + virtual bool enter(); + + /** + * Called when PET area is left + */ + virtual bool leave(); void set20(int val) { _field20 = val; } @@ -259,6 +308,53 @@ public: * Get the PET control */ CPetControl *getPetControl() const; + + /** + * Mouse button down message + */ + bool mouseButtonDown(const Point &pt); + + /** + * Mouse button up message + */ + bool mouseButtonUp(const Point &pt); + + /** + * Mouse drag start messagge + */ + bool mouseDragStart(CMouseDragStartMsg *msg); + + /** + * Mouse drag move message + */ + bool mouseDragMove(CMouseDragMoveMsg *msg); + + /** + * Mouse drag end message + */ + bool mouseDragEnd(CMouseDragEndMsg *msg); + + /** + * Key character message + */ + bool keyCharMsg(int key); + + /** + * Virtual key message + */ + bool virtualKeyCharMsg(int key); + + /** + * When the PET section is entered, passes onto the highlighted + * glyph, if any + */ + bool enterHighlighted(); + + /** + * When the PET section is left, passes onto the highlighted + * glyph, if any + */ + bool leaveHighlighted(); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp index 063f019655..b27b664ab9 100644 --- a/engines/titanic/pet_control/pet_inventory.cpp +++ b/engines/titanic/pet_control/pet_inventory.cpp @@ -57,22 +57,37 @@ Rect CPetInventory::getBounds() { return Rect(); } -void CPetInventory::save(SimpleFile *file, int indent) const { - file->writeNumberLine(_field298, indent); +CGameObject *CPetInventory::dragEnd(const Point &pt) const { + warning("TODO: CPetInventory::dragEnd"); + return nullptr; +} + +bool CPetInventory::isValid(CPetControl *petControl) { + setPetControl(petControl); + return true; } void CPetInventory::load(SimpleFile *file, int param) { _field298 = file->readNumber(); } -CGameObject *CPetInventory::dragEnd(const Point &pt) const { - warning("TODO: CPetInventory::dragEnd"); - return nullptr; +void CPetInventory::postLoad() { + reset(); + _field290 = 1; + itemsChanged(); + _field290 = 0; } -bool CPetInventory::isValid(CPetControl *petControl) { - // TODO - return true; +void CPetInventory::save(SimpleFile *file, int indent) const { + file->writeNumberLine(_field298, indent); +} + +void CPetInventory::enter(PetArea oldArea) { + _items.enter(); +} + +void CPetInventory::leave() { + _items.leave(); } bool CPetInventory::setPetControl(CPetControl *petControl) { diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h index 32cb47edf5..ed1b679c63 100644 --- a/engines/titanic/pet_control/pet_inventory.h +++ b/engines/titanic/pet_control/pet_inventory.h @@ -91,11 +91,27 @@ public: */ virtual CGameObject *dragEnd(const Point &pt) const; + /** * Returns true if the object is in a valid state */ virtual bool isValid(CPetControl *petControl); + /** + * Called after a game has been loaded + */ + virtual void postLoad(); + + /** + * Called when a section is switched to + */ + virtual void enter(PetArea oldArea); + + /** + * Called when a section is being left, to switch to another area + */ + virtual void leave(); + virtual CGameObject *getBackground(int index) const { return (index >= 0 && index < 46) ? _itemBackgrounds[index] : nullptr; } diff --git a/engines/titanic/pet_control/pet_real_life.cpp b/engines/titanic/pet_control/pet_real_life.cpp index 38b7125ed3..ec1ea2c727 100644 --- a/engines/titanic/pet_control/pet_real_life.cpp +++ b/engines/titanic/pet_control/pet_real_life.cpp @@ -50,6 +50,52 @@ void CPetRealLife::draw(CScreenManager *screenManager) { _text.draw(screenManager); } +bool CPetRealLife::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { + return _glyphs.mouseButtonDown(msg->_mousePos); +} + +bool CPetRealLife::MouseDragStartMsg(CMouseDragStartMsg *msg) { + return _glyphs.mouseDragStart(msg); +} + +bool CPetRealLife::MouseDragMoveMsg(CMouseDragMoveMsg *msg) { + return _glyphs.mouseDragMove(msg); +} + +bool CPetRealLife::MouseDragEndMsg(CMouseDragEndMsg *msg) { + return _glyphs.mouseDragEnd(msg); +} + +bool CPetRealLife::MouseButtonUpMsg(CMouseButtonUpMsg *msg) { + return _glyphs.mouseButtonUp(msg->_mousePos); +} + +bool CPetRealLife::KeyCharMsg(CKeyCharMsg *msg) { + _glyphs.keyCharMsg(msg->_key); + return true; +} + +bool CPetRealLife::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { + return _glyphs.virtualKeyCharMsg(msg->_keyState.keycode); +} + +void CPetRealLife::postLoad() { + reset(); +} + +bool CPetRealLife::isValid(CPetControl *petControl) { + setupControl(petControl); + return true; +} + +void CPetRealLife::enter(PetArea oldArea) { + _glyphs.enterHighlighted(); +} + +void CPetRealLife::leave() { + _glyphs.leaveHighlighted(); +} + bool CPetRealLife::setupControl(CPetControl *petControl) { if (petControl) { _petControl = petControl; @@ -78,11 +124,6 @@ void CPetRealLife::addButton(CPetGlyph *glyph) { } } -bool CPetRealLife::isValid(CPetControl *petControl) { - setupControl(petControl); - return true; -} - } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_real_life.h b/engines/titanic/pet_control/pet_real_life.h index c4c597c45f..b00c7c14c3 100644 --- a/engines/titanic/pet_control/pet_real_life.h +++ b/engines/titanic/pet_control/pet_real_life.h @@ -75,14 +75,13 @@ public: * Following are handlers for the various messages that the PET can * pass onto the currently active section/area */ - virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg) { return false; } - virtual bool MouseDragStartMsg(CMouseDragStartMsg *msg) { return false; } - virtual bool MouseDragMoveMsg(CMouseDragMoveMsg *msg) { return false; } - virtual bool MouseDragEndMsg(CMouseDragEndMsg *msg) { return false; } - virtual bool MouseButtonUpMsg(CMouseButtonUpMsg *msg) { return false; } - virtual bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) { return false; } - virtual bool KeyCharMsg(CKeyCharMsg *msg) { return false; } - virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; } + virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); + virtual bool MouseDragStartMsg(CMouseDragStartMsg *msg); + virtual bool MouseDragMoveMsg(CMouseDragMoveMsg *msg); + virtual bool MouseDragEndMsg(CMouseDragEndMsg *msg); + virtual bool MouseButtonUpMsg(CMouseButtonUpMsg *msg); + virtual bool KeyCharMsg(CKeyCharMsg *msg); + virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg); virtual int proc14() { return 0; } @@ -109,7 +108,7 @@ public: /** * Called after a game has been loaded */ - virtual void postLoad() {} + virtual void postLoad(); /** * Save the data for the class to file @@ -119,20 +118,23 @@ public: /** * Called when a section is switched to */ - virtual void enter(PetArea oldArea) {} + virtual void enter(PetArea oldArea); /** * Called when a section is being left, to switch to another area */ - virtual void leave() {} - - virtual void proc23() {} + virtual void leave(); /** * Called when a new room is entered */ virtual void enterRoom(CRoomItem *room) {} + /** + * Get a reference to the tooltip text associated with the section + */ + virtual CPetText *getText() { return &_text; } + }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_section.h b/engines/titanic/pet_control/pet_section.h index 6cc1c10333..0911fd44f1 100644 --- a/engines/titanic/pet_control/pet_section.h +++ b/engines/titanic/pet_control/pet_section.h @@ -34,6 +34,7 @@ enum PetArea { }; class CPetControl; +class CPetText; class CScreenManager; class CRoomItem; @@ -139,7 +140,12 @@ public: virtual void enterRoom(CRoomItem *room) {} virtual void proc25(); - virtual int proc26() { return 0; } + + /** + * Get a reference to the tooltip text associated with the section + */ + virtual CPetText *getText() { return nullptr; } + virtual void proc27(); virtual void proc28(); virtual void proc29(); diff --git a/engines/titanic/pet_control/pet_sound.cpp b/engines/titanic/pet_control/pet_sound.cpp index 75dff34db5..d4c6fb376c 100644 --- a/engines/titanic/pet_control/pet_sound.cpp +++ b/engines/titanic/pet_control/pet_sound.cpp @@ -107,5 +107,18 @@ bool CPetSound::reset() { return false; } +void CPetSound::draw2(CScreenManager *screenManager) { + _element.draw(screenManager); + + _musicVolume.draw(screenManager); + _masterVolume.draw(screenManager); + _parrotVolume.draw(screenManager); + _speechVolume.draw(screenManager); + + _textMusicVolume.draw(screenManager); + _textMasterVolume.draw(screenManager); + _textParrotVolume.draw(screenManager); + _textSpeechVolume.draw(screenManager); +} } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_sound.h b/engines/titanic/pet_control/pet_sound.h index de6c637bd2..55e1f8a45c 100644 --- a/engines/titanic/pet_control/pet_sound.h +++ b/engines/titanic/pet_control/pet_sound.h @@ -55,6 +55,11 @@ public: * Reset the glyph */ virtual bool reset(); + + /** + * Handles any secondary drawing of the glyph + */ + virtual void draw2(CScreenManager *screenManager); }; } // End of namespace Titanic |