From 71c3129ecff1e5e4e847825eba58d1be9594b1c8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 8 Mar 2016 22:34:51 -0500 Subject: TITANIC: Added skeletons for game manager support classes --- engines/titanic/input_handler.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 engines/titanic/input_handler.cpp (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp new file mode 100644 index 0000000000..0c09429bd4 --- /dev/null +++ b/engines/titanic/input_handler.cpp @@ -0,0 +1,39 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "titanic/input_handler.h" +#include "titanic/screen_manager.h" + +namespace Titanic { + +CInputHandler::CInputHandler(CGameManager *owner) : + _gameManager(owner), _inputTranslator(nullptr), + _field4(0), _field8(0), _fieldC(0), _field10(0), _field14(0), + _field18(0), _field1C(0), _field20(0), _field24(0) { + CScreenManager::_screenManagerPtr->_inputHandler = this; +} + +void CInputHandler::setTranslator(CInputTranslator *translator) { + _inputTranslator = translator; +} + +} // End of namespace Titanic z -- cgit v1.2.3 From f0d992d8548ee8bacae72ecc15e69f9de4187549 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 13 Mar 2016 10:28:45 -0400 Subject: TITANIC: Implemented setMode method for game state --- engines/titanic/input_handler.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 0c09429bd4..d5825c0c32 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -28,7 +28,7 @@ namespace Titanic { CInputHandler::CInputHandler(CGameManager *owner) : _gameManager(owner), _inputTranslator(nullptr), _field4(0), _field8(0), _fieldC(0), _field10(0), _field14(0), - _field18(0), _field1C(0), _field20(0), _field24(0) { + _lockCount(0), _field24(0) { CScreenManager::_screenManagerPtr->_inputHandler = this; } @@ -36,4 +36,14 @@ void CInputHandler::setTranslator(CInputTranslator *translator) { _inputTranslator = translator; } +void CInputHandler::incLockCount() { + ++_lockCount; +} + +void CInputHandler::decLockCount() { + if (--_lockCount == 0 && _inputTranslator) { + warning("TODO"); + } +} + } // End of namespace Titanic z -- cgit v1.2.3 From 9565fbaeac8f48ea0090ebbd751a18eacc6d1230 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 18 Mar 2016 21:34:04 -0400 Subject: TITANIC: Implement input translator event methods --- engines/titanic/input_handler.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index d5825c0c32..d7199215f7 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -21,7 +21,9 @@ */ #include "titanic/input_handler.h" +#include "titanic/game_manager.h" #include "titanic/screen_manager.h" +#include "titanic/titanic.h" namespace Titanic { @@ -46,4 +48,18 @@ void CInputHandler::decLockCount() { } } +void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) { + if (!respectLock || _lockCount <= 0) { + if (_gameManager->_gameState._mode == GSMODE_1) { + processMessage(msg); + } else if (!msg.isMouseMsg()) { + g_vm->_filesManager.fn1(); + } + } +} + +void CInputHandler::processMessage(const CMessage &msg) { + warning("TODO: CInputHandler::processMessage"); +} + } // End of namespace Titanic z -- cgit v1.2.3 From 7a38b51357ba581fe51a392a031d09dd238039e8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 18 Mar 2016 23:15:31 -0400 Subject: TITANIC: Implemented drag/drop handling --- engines/titanic/input_handler.cpp | 88 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 6 deletions(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index d7199215f7..5d50c00377 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -24,13 +24,13 @@ #include "titanic/game_manager.h" #include "titanic/screen_manager.h" #include "titanic/titanic.h" +#include "titanic/pet_control/pet_control.h" namespace Titanic { CInputHandler::CInputHandler(CGameManager *owner) : - _gameManager(owner), _inputTranslator(nullptr), - _field4(0), _field8(0), _fieldC(0), _field10(0), _field14(0), - _lockCount(0), _field24(0) { + _gameManager(owner), _inputTranslator(nullptr), _dragging(false), + _buttonDown(false), _dragItem(nullptr), _lockCount(0), _field24(0) { CScreenManager::_screenManagerPtr->_inputHandler = this; } @@ -51,15 +51,91 @@ void CInputHandler::decLockCount() { void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) { if (!respectLock || _lockCount <= 0) { if (_gameManager->_gameState._mode == GSMODE_1) { - processMessage(msg); + processMessage(&msg); } else if (!msg.isMouseMsg()) { g_vm->_filesManager.fn1(); } } } -void CInputHandler::processMessage(const CMessage &msg) { - warning("TODO: CInputHandler::processMessage"); +void CInputHandler::processMessage(const CMessage *msg) { + const CMouseMsg *mouseMsg = dynamic_cast(msg); + _field24 = 0; + dispatchMessage(msg); + + if (_field24) { + _field24 = 0; + } else if (mouseMsg) { + // Keep the game state mouse position up to date + if (_mousePos != mouseMsg->_mousePos) { + _mousePos = mouseMsg->_mousePos; + _gameManager->_gameState.setMousePos(mouseMsg->_mousePos); + } + + // Set flag for whether a mouse button is currently being pressed + if (mouseMsg->isButtonDownMsg()) + _buttonDown = true; + else if (mouseMsg->isButtonUpMsg()) + _buttonDown = false; + + // Drag events generation + if (_dragging) { + if (mouseMsg->isMouseMoveMsg()) { + if (_dragItem) { + CMouseDragMoveMsg moveMsg(_mousePos); + moveMsg.execute(_dragItem); + } + } else { + if (mouseMsg->isButtonUpMsg() && _dragItem) { + // Mouse drag ended + dragEnd(_mousePos, _dragItem); + CMouseDragEndMsg endMsg(_mousePos, _dragItem); + endMsg.execute(_dragItem); + } + + _dragging = false; + _dragItem = nullptr; + } + } else if (_buttonDown) { + if (!mouseMsg->isMouseMoveMsg()) { + // Save where the drag movement started from + _dragStartPos = _mousePos; + } else { + Common::Point delta = mouseMsg->_mousePos - _dragStartPos; + int distance = (int)sqrt(double(delta.x * delta.x + delta.y * delta.y)); + + if (distance > 4) { + // We've moved far enough with the mouse button held down + // to trigger an official dragging operation + CMouseDragStartMsg startMsg(_dragStartPos); + dispatchMessage(&startMsg); + + // Set the drag item, if any, that a handler will have set on the message + _dragItem = startMsg._dragItem; + _gameManager->_dragItem = startMsg._dragItem; + + if (_dragItem) { + CMouseDragMoveMsg moveMsg(_dragStartPos); + dispatchMessage(&moveMsg); + } + + _dragging = true; + } + } + } + } +} + +void CInputHandler::dispatchMessage(const CMessage *msg) { + CPetControl *pet = _gameManager->_project->getPetControl(); + if (!pet || !msg->execute(pet, nullptr, MSGFLAG_BREAK_IF_HANDLED)) { + CViewItem *view = _gameManager->getView(); + msg->execute(view); + } +} + +void CInputHandler::dragEnd(const Common::Point &mousePos, CTreeItem *dragItem) { + warning("TODO CInputHandler::dragEnd"); } } // End of namespace Titanic z -- cgit v1.2.3 From ea54e6244e75c609e6886ba210f80fb22c479d3f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 20 Mar 2016 00:01:40 -0400 Subject: TITANIC: Fixes/renames for files manager --- engines/titanic/input_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 5d50c00377..c710374d05 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -53,7 +53,7 @@ void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) { if (_gameManager->_gameState._mode == GSMODE_1) { processMessage(&msg); } else if (!msg.isMouseMsg()) { - g_vm->_filesManager.fn1(); + g_vm->_filesManager.loadDrive(); } } } -- cgit v1.2.3 From 217360d0c5a0b8289c16b22fc46782c475fcc9f5 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 21 Mar 2016 20:53:49 -0400 Subject: TITANIC: Add new derived Rect and Point classes --- engines/titanic/input_handler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index c710374d05..110bddfd90 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -101,7 +101,7 @@ void CInputHandler::processMessage(const CMessage *msg) { // Save where the drag movement started from _dragStartPos = _mousePos; } else { - Common::Point delta = mouseMsg->_mousePos - _dragStartPos; + Point delta = mouseMsg->_mousePos - _dragStartPos; int distance = (int)sqrt(double(delta.x * delta.x + delta.y * delta.y)); if (distance > 4) { @@ -134,7 +134,7 @@ void CInputHandler::dispatchMessage(const CMessage *msg) { } } -void CInputHandler::dragEnd(const Common::Point &mousePos, CTreeItem *dragItem) { +void CInputHandler::dragEnd(const Point &mousePos, CTreeItem *dragItem) { warning("TODO CInputHandler::dragEnd"); } -- cgit v1.2.3 From 66e198d665a8aacd1724848a40e6533f3d5cfebc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 24 Mar 2016 07:49:59 -0400 Subject: TITANIC: Cleanup and fixes for message hierarchy --- engines/titanic/input_handler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 110bddfd90..2eb4427a46 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -48,7 +48,7 @@ void CInputHandler::decLockCount() { } } -void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) { +void CInputHandler::handleMessage(CMessage &msg, bool respectLock) { if (!respectLock || _lockCount <= 0) { if (_gameManager->_gameState._mode == GSMODE_1) { processMessage(&msg); @@ -58,7 +58,7 @@ void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) { } } -void CInputHandler::processMessage(const CMessage *msg) { +void CInputHandler::processMessage(CMessage *msg) { const CMouseMsg *mouseMsg = dynamic_cast(msg); _field24 = 0; dispatchMessage(msg); @@ -126,7 +126,7 @@ void CInputHandler::processMessage(const CMessage *msg) { } } -void CInputHandler::dispatchMessage(const CMessage *msg) { +void CInputHandler::dispatchMessage(CMessage *msg) { CPetControl *pet = _gameManager->_project->getPetControl(); if (!pet || !msg->execute(pet, nullptr, MSGFLAG_BREAK_IF_HANDLED)) { CViewItem *view = _gameManager->getView(); -- cgit v1.2.3 From 5923ee5001af91d1ca9294b1fead56ec04ece7df Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 31 Mar 2016 22:31:13 -0400 Subject: TITANIC: Implement CPetFrame::setArea --- engines/titanic/input_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 2eb4427a46..8323531a1f 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -50,7 +50,7 @@ void CInputHandler::decLockCount() { void CInputHandler::handleMessage(CMessage &msg, bool respectLock) { if (!respectLock || _lockCount <= 0) { - if (_gameManager->_gameState._mode == GSMODE_1) { + if (_gameManager->_gameState._mode == GSMODE_SELECTED) { processMessage(&msg); } else if (!msg.isMouseMsg()) { g_vm->_filesManager.loadDrive(); -- cgit v1.2.3 From 1efbed540948edcbf3ac2c72c0984def044274cf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Apr 2016 16:16:35 -0400 Subject: TITANIC: Move most of the root classes into new support/ folder --- engines/titanic/input_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 8323531a1f..0657ebec94 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -22,7 +22,7 @@ #include "titanic/input_handler.h" #include "titanic/game_manager.h" -#include "titanic/screen_manager.h" +#include "titanic/support/screen_manager.h" #include "titanic/titanic.h" #include "titanic/pet_control/pet_control.h" -- cgit v1.2.3 From cf785a19e3dbe52eb71b253a5dcdcd7ba77b47ca Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Apr 2016 17:09:22 -0400 Subject: TITANIC: Implement drag&drop dropping --- engines/titanic/input_handler.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 0657ebec94..082bdd080e 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -88,8 +88,8 @@ void CInputHandler::processMessage(CMessage *msg) { } else { if (mouseMsg->isButtonUpMsg() && _dragItem) { // Mouse drag ended - dragEnd(_mousePos, _dragItem); - CMouseDragEndMsg endMsg(_mousePos, _dragItem); + CTreeItem *target = dragEnd(_mousePos, _dragItem); + CMouseDragEndMsg endMsg(_mousePos, target); endMsg.execute(_dragItem); } @@ -134,8 +134,36 @@ void CInputHandler::dispatchMessage(CMessage *msg) { } } -void CInputHandler::dragEnd(const Point &mousePos, CTreeItem *dragItem) { - warning("TODO CInputHandler::dragEnd"); +CTreeItem *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; + for (CTreeItem *treeItem = view->scan(view); treeItem; treeItem = treeItem->scan(view)) { + CGameObject *gameObject = static_cast(treeItem); + if (gameObject && gameObject != dragItem) { + if (gameObject->checkPoint(pt)) + target = gameObject; + } + } + + if (target) { + // Check if the cursor is on the PET. If so, pass to the PET + // to see what specific element the drag ended on + CProjectItem *project = view->getRoot(); + if (project) { + CPetControl *petControl = project->getPetControl(); + if (petControl && petControl->contains(pt)) { + target = petControl->dragEnd(pt); + if (!target) + target = petControl; + } + } + } + + return target; } -} // End of namespace Titanic z +} // End of namespace Titanic -- cgit v1.2.3 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/input_handler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/titanic/input_handler.cpp') 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) { -- cgit v1.2.3 From 0820c3ffaee211270ab75a14cd1d42047354aa34 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 9 May 2016 21:03:21 -0400 Subject: TITANIC: Refactor CTitleEngine to use CFilesManager for PE resources --- engines/titanic/input_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 3d3541b1dd..289e707bb0 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -53,7 +53,7 @@ void CInputHandler::handleMessage(CMessage &msg, bool respectLock) { if (_gameManager->_gameState._mode == GSMODE_SELECTED) { processMessage(&msg); } else if (!msg.isMouseMsg()) { - g_vm->_filesManager.loadDrive(); + g_vm->_filesManager->loadDrive(); } } } -- cgit v1.2.3 From d979dcd020d65aa0019d7a53c1dcd8b4f4a0f909 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 23 Jul 2016 17:21:38 -0400 Subject: TITANIC: Fixes for movie notification, computer game logic cleanup --- engines/titanic/input_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 289e707bb0..395f55df6f 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -50,7 +50,7 @@ void CInputHandler::decLockCount() { void CInputHandler::handleMessage(CMessage &msg, bool respectLock) { if (!respectLock || _lockCount <= 0) { - if (_gameManager->_gameState._mode == GSMODE_SELECTED) { + if (_gameManager->_gameState._mode == GSMODE_INTERACTIVE) { processMessage(&msg); } else if (!msg.isMouseMsg()) { g_vm->_filesManager->loadDrive(); -- cgit v1.2.3 From fd316a60589f07ac75cfdf1b56188d9d464336bd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 24 Jul 2016 07:45:30 -0400 Subject: TITANIC: Fleshed out various methods --- engines/titanic/input_handler.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'engines/titanic/input_handler.cpp') diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index 395f55df6f..7c35a5d855 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -22,15 +22,17 @@ #include "titanic/input_handler.h" #include "titanic/game_manager.h" -#include "titanic/support/screen_manager.h" #include "titanic/titanic.h" +#include "titanic/messages/mouse_messages.h" #include "titanic/pet_control/pet_control.h" +#include "titanic/support/screen_manager.h" namespace Titanic { CInputHandler::CInputHandler(CGameManager *owner) : _gameManager(owner), _inputTranslator(nullptr), _dragging(false), - _buttonDown(false), _dragItem(nullptr), _lockCount(0), _field24(0) { + _buttonDown(false), _dragItem(nullptr), _lockCount(0), + _singleton(false) { CScreenManager::_screenManagerPtr->_inputHandler = this; } @@ -44,7 +46,13 @@ void CInputHandler::incLockCount() { void CInputHandler::decLockCount() { if (--_lockCount == 0 && _inputTranslator) { - warning("TODO"); + if (_dragging && !_inputTranslator->isMousePressed()) { + CMouseButtonUpMsg upMsg(_mousePos, MK_LBUTTON); + handleMessage(upMsg); + } + + _buttonDown = _inputTranslator->isMousePressed(); + _singleton = true; } } @@ -60,11 +68,11 @@ void CInputHandler::handleMessage(CMessage &msg, bool respectLock) { void CInputHandler::processMessage(CMessage *msg) { const CMouseMsg *mouseMsg = dynamic_cast(msg); - _field24 = 0; + _singleton = false; dispatchMessage(msg); - if (_field24) { - _field24 = 0; + if (_singleton) { + _singleton = false; } else if (mouseMsg) { // Keep the game state mouse position up to date if (_mousePos != mouseMsg->_mousePos) { -- cgit v1.2.3