From 7e1f802abdab1442bd49f1c398c0aab6d81d452b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 11 Apr 2016 18:53:40 -0400 Subject: TITANIC: CCarry drag & move msg handlers --- engines/titanic/carry/carry.cpp | 26 +++++++++++++++++++++++--- engines/titanic/carry/carry.h | 2 +- engines/titanic/core/game_object.cpp | 4 ++++ engines/titanic/core/game_object.h | 5 +++++ engines/titanic/input_handler.cpp | 6 +++--- engines/titanic/input_handler.h | 2 +- engines/titanic/messages/messages.h | 1 - engines/titanic/messages/mouse_messages.h | 19 ++++++++++++++++--- engines/titanic/pet_control/pet_control.h | 2 +- engines/titanic/pet_control/pet_inventory.cpp | 2 +- engines/titanic/pet_control/pet_inventory.h | 2 +- engines/titanic/pet_control/pet_section.h | 2 +- 12 files changed, 57 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/titanic/carry/carry.cpp b/engines/titanic/carry/carry.cpp index b075444cd7..eefb13f462 100644 --- a/engines/titanic/carry/carry.cpp +++ b/engines/titanic/carry/carry.cpp @@ -57,7 +57,7 @@ void CCarry::save(SimpleFile *file, int indent) const { file->writeNumberLine(_fieldE0, indent); file->writeQuotedLine(_string3, indent); file->writeQuotedLine(_string4, indent); - file->writePoint(_pos2, indent); + file->writePoint(_tempPos, indent); file->writeNumberLine(_field104, indent); file->writeNumberLine(_field108, indent); file->writeNumberLine(_field10C, indent); @@ -79,7 +79,7 @@ void CCarry::load(SimpleFile *file) { _fieldE0 = file->readNumber(); _string3 = file->readString(); _string4 = file->readString(); - _pos2 = file->readPoint(); + _tempPos = file->readPoint(); _field104 = file->readNumber(); _field108 = file->readNumber(); _field10C = file->readNumber(); @@ -93,14 +93,34 @@ void CCarry::load(SimpleFile *file) { } bool CCarry::MouseDragStartMsg(CMouseDragStartMsg *msg) { - return true; + CString name = getName(); + + if (_fieldE0) { + if (_visible) { + CShowTextMsg textMsg("You can't get this."); + textMsg.execute("PET"); + } + } else { + if (checkStartDragging(msg)) { + CPassOnDragStartMsg startMsg(msg->_mousePos); + startMsg.execute(this); + return true; + } + } + + return false; } bool CCarry::MouseDragMoveMsg(CMouseDragMoveMsg *msg) { + setPosition(msg->_mousePos - _tempPos); return true; } bool CCarry::MouseDragEndMsg(CMouseDragEndMsg *msg) { + if (msg->_dropTarget) { + // TODO + } + return true; } diff --git a/engines/titanic/carry/carry.h b/engines/titanic/carry/carry.h index 9788b25602..b98a7bedea 100644 --- a/engines/titanic/carry/carry.h +++ b/engines/titanic/carry/carry.h @@ -51,7 +51,7 @@ private: int _fieldE0; CString _string3; CString _string4; - Point _pos2; + Point _tempPos; int _field100; int _field104; int _field108; diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index a798c4db98..c179ed8b50 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -221,6 +221,10 @@ void CGameObject::draw(CScreenManager *screenManager, const Common::Point &destP } } +bool CGameObject::isPet() const { + return isInstanceOf(CPetControl::_type); +} + void CGameObject::loadResource(const CString &name) { switch (name.fileTypeSuffix()) { case FILETYPE_IMAGE: diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index ab1833934b..a8d8513587 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -167,6 +167,11 @@ public: */ virtual void draw(CScreenManager *screenManager, const Common::Point &destPos); + /** + * Returns true if the item is the PET control + */ + virtual bool isPet() const; + /** * Stops any movie currently playing for the object */ diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 082bdd080e..3d3541b1dd 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -88,7 +88,7 @@ void CInputHandler::processMessage(CMessage *msg) { } else { if (mouseMsg->isButtonUpMsg() && _dragItem) { // Mouse drag ended - CTreeItem *target = dragEnd(_mousePos, _dragItem); + CGameObject *target = dragEnd(_mousePos, _dragItem); CMouseDragEndMsg endMsg(_mousePos, target); endMsg.execute(_dragItem); } @@ -134,13 +134,13 @@ void CInputHandler::dispatchMessage(CMessage *msg) { } } -CTreeItem *CInputHandler::dragEnd(const Point &pt, CTreeItem *dragItem) { +CGameObject *CInputHandler::dragEnd(const Point &pt, CTreeItem *dragItem) { CViewItem *view = _gameManager->getView(); if (!view) return nullptr; // Scan through the view items to find the item being dropped on - CTreeItem *target = nullptr; + CGameObject *target = nullptr; for (CTreeItem *treeItem = view->scan(view); treeItem; treeItem = treeItem->scan(view)) { CGameObject *gameObject = static_cast(treeItem); if (gameObject && gameObject != dragItem) { diff --git a/engines/titanic/input_handler.h b/engines/titanic/input_handler.h index 05838e88c0..2d62127a11 100644 --- a/engines/titanic/input_handler.h +++ b/engines/titanic/input_handler.h @@ -46,7 +46,7 @@ private: /** * Called when a drag operation has ended */ - CTreeItem *dragEnd(const Point &pt, CTreeItem *dragItem); + CGameObject *dragEnd(const Point &pt, CTreeItem *dragItem); public: CGameManager *_gameManager; CInputTranslator *_inputTranslator; diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index 82601e525f..e74c26fd97 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -319,7 +319,6 @@ MESSAGE0(COpeningCreditsMsg); MESSAGE1(CPanningAwayFromParrotMsg, int, value, 0); MESSAGE2(CParrotSpeakMsg, CString, value1, "", CString, value2, ""); MESSAGE2(CParrotTriesChickenMsg, int, value1, 0, int, value2, 0); -MESSAGE4(CPassOnDragStartMsg, int, value1, 0, int, value2, 0, int, value3, 0, int, value4, 0); MESSAGE1(CPhonographPlayMsg, int, value, 0); MESSAGE0(CPhonographReadyToPlayMsg); MESSAGE1(CPhonographRecordMsg, int, value, 0); diff --git a/engines/titanic/messages/mouse_messages.h b/engines/titanic/messages/mouse_messages.h index 811fdf0ad0..705247a2dc 100644 --- a/engines/titanic/messages/mouse_messages.h +++ b/engines/titanic/messages/mouse_messages.h @@ -139,14 +139,27 @@ public: } }; +class CPassOnDragStartMsg : public CMessage { +public: + Point _mousePos; +public: + CLASSDEF + CPassOnDragStartMsg() : CMessage() {} + CPassOnDragStartMsg(const Point &pt) : CMessage(), _mousePos(pt) {} + + static bool isSupportedBy(const CTreeItem *item) { + return supports(item, _type); + } +}; + class CMouseDragEndMsg : public CMouseDragMsg { public: - CTreeItem *_dropTarget; + CGameObject *_dropTarget; public: CLASSDEF CMouseDragEndMsg() : CMouseDragMsg(), _dropTarget(nullptr) {} - CMouseDragEndMsg(const Point &pt, CTreeItem *dragItem = nullptr) : - CMouseDragMsg(pt), _dropTarget(dragItem) {} + CMouseDragEndMsg(const Point &pt, CGameObject *dropTarget = nullptr) : + CMouseDragMsg(pt), _dropTarget(dropTarget) {} static bool isSupportedBy(const CTreeItem *item) { return supports(item, _type); diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index 39bc5fb41b..f357c29378 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -193,7 +193,7 @@ public: /** * Handles drag ends within the PET */ - CTreeItem *dragEnd(const Point &pt) const { + CGameObject *dragEnd(const Point &pt) const { return _currentArea == PET_INVENTORY ? _inventory.dragEnd(pt) : nullptr; } }; diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp index 79923bdb41..1104b653b6 100644 --- a/engines/titanic/pet_control/pet_inventory.cpp +++ b/engines/titanic/pet_control/pet_inventory.cpp @@ -64,7 +64,7 @@ void CPetInventory::load(SimpleFile *file, int param) { _field298 = file->readNumber(); } -CTreeItem *CPetInventory::dragEnd(const Point &pt) const { +CGameObject *CPetInventory::dragEnd(const Point &pt) const { warning("TODO: CPetInventory::dragEnd"); return nullptr; } diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h index a0a9304fd6..16dfd227f1 100644 --- a/engines/titanic/pet_control/pet_inventory.h +++ b/engines/titanic/pet_control/pet_inventory.h @@ -84,7 +84,7 @@ public: /** * Returns item a drag-drop operation has dropped on, if any */ - virtual CTreeItem *dragEnd(const Point &pt) const; + virtual CGameObject *dragEnd(const Point &pt) const; /** * Returns true if the object is in a valid state diff --git a/engines/titanic/pet_control/pet_section.h b/engines/titanic/pet_control/pet_section.h index bc24737b1d..93a9145411 100644 --- a/engines/titanic/pet_control/pet_section.h +++ b/engines/titanic/pet_control/pet_section.h @@ -94,7 +94,7 @@ public: /** * Returns item a drag-drop operation has dropped on, if any */ - virtual CTreeItem *dragEnd(const Point &pt) const { return nullptr; } + virtual CGameObject *dragEnd(const Point &pt) const { return nullptr; } virtual void proc16(); -- cgit v1.2.3