diff options
author | Paul Gilbert | 2017-08-06 11:58:06 -0400 |
---|---|---|
committer | Paul Gilbert | 2017-08-06 11:58:06 -0400 |
commit | 07e70d9896c0d2eb9c2b1c56becfa1483822a382 (patch) | |
tree | c280946cbce939f10f47705dfce71da153cd4b6e /engines/titanic/core | |
parent | f5b335af100c84d2ad761548825548d6fe3be125 (diff) | |
download | scummvm-rg350-07e70d9896c0d2eb9c2b1c56becfa1483822a382.tar.gz scummvm-rg350-07e70d9896c0d2eb9c2b1c56becfa1483822a382.tar.bz2 scummvm-rg350-07e70d9896c0d2eb9c2b1c56becfa1483822a382.zip |
TITANIC: Create new CMovementMsg for new movement functionality
This also moves logic for detecting which movement is associated
with given keycodes and cursors to CMovementMsg and CLinkItem,
which are better suited to contain the logic
Diffstat (limited to 'engines/titanic/core')
-rw-r--r-- | engines/titanic/core/game_object.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/core/game_object.h | 5 | ||||
-rw-r--r-- | engines/titanic/core/link_item.cpp | 21 | ||||
-rw-r--r-- | engines/titanic/core/link_item.h | 8 | ||||
-rw-r--r-- | engines/titanic/core/saveable_object.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/core/view_item.cpp | 42 | ||||
-rw-r--r-- | engines/titanic/core/view_item.h | 2 |
7 files changed, 47 insertions, 37 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index d4457e7456..ea3cb4ddac 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -1151,6 +1151,10 @@ CTextCursor *CGameObject::getTextCursor() const { return CScreenManager::_screenManagerPtr->_textCursor; } +Movement CGameObject::getMovement() const { + return CLinkItem::getMovementFromCursor(_cursorId); +} + void CGameObject::scrollTextUp() { if (_text) _text->scrollUp(CScreenManager::_screenManagerPtr); diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index c09577a53f..d08ef4cf76 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -781,6 +781,11 @@ public: */ CTextCursor *getTextCursor() const; + /** + * Get the movement, if any, the cursor represents + */ + Movement getMovement() const; + /*--- CGameManager Methods ---*/ /** diff --git a/engines/titanic/core/link_item.cpp b/engines/titanic/core/link_item.cpp index a131b85654..c46e44aa8b 100644 --- a/engines/titanic/core/link_item.cpp +++ b/engines/titanic/core/link_item.cpp @@ -29,6 +29,20 @@ namespace Titanic { EMPTY_MESSAGE_MAP(CLinkItem, CNamedItem); +Movement CLinkItem::getMovementFromCursor(CursorId cursorId) { + if (cursorId == CURSOR_MOVE_LEFT) + return TURN_LEFT; + else if (cursorId == CURSOR_MOVE_RIGHT) + return TURN_RIGHT; + else if (cursorId == CURSOR_MOVE_FORWARD || cursorId == CURSOR_MOVE_THROUGH || + cursorId == CURSOR_DOWN) + return MOVE_FORWARDS; + else if (cursorId == CURSOR_BACKWARDS) + return MOVE_BACKWARDS; + else + return MOVE_NONE; +} + CLinkItem::CLinkItem() : CNamedItem() { _roomNumber = -1; _nodeNumber = -1; @@ -173,4 +187,11 @@ CMovieClip *CLinkItem::getClip() const { return findRoom()->findClip(getName()); } +Movement CLinkItem::getMovement() const { + if (_bounds.isEmpty()) + return MOVE_NONE; + + return getMovementFromCursor(_cursorId); +} + } // End of namespace Titanic diff --git a/engines/titanic/core/link_item.h b/engines/titanic/core/link_item.h index dd93e2a0bf..609310a7c3 100644 --- a/engines/titanic/core/link_item.h +++ b/engines/titanic/core/link_item.h @@ -26,6 +26,7 @@ #include "titanic/support/mouse_cursor.h" #include "titanic/core/named_item.h" #include "titanic/support/movie_clip.h" +#include "titanic/messages/messages.h" namespace Titanic { @@ -50,6 +51,8 @@ public: Rect _bounds; CursorId _cursorId; public: + static Movement getMovementFromCursor(CursorId cursorId); +public: CLASSDEF; CLinkItem(); @@ -93,6 +96,11 @@ public: * Get the movie clip, if any, that's used when the link is used */ CMovieClip *getClip() const; + + /** + * Get the movement, if any, the cursor represents + */ + Movement getMovement() const; }; } // End of namespace Titanic diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index 256ca41821..586036a5c1 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -837,6 +837,7 @@ DEFFN(CMouseDragStartMsg); DEFFN(CMouseDragMoveMsg); DEFFN(CMouseDragEndMsg); DEFFN(CMouseWheelMsg); +DEFFN(CMovementMsg); DEFFN(CMoveToStartPosMsg); DEFFN(CMovieEndMsg); DEFFN(CMovieFrameMsg); @@ -1422,6 +1423,7 @@ void CSaveableObject::initClassList() { ADDFN(CMouseDragMoveMsg, CMouseDragMsg); ADDFN(CMouseDragEndMsg, CMouseDragMsg); ADDFN(CMouseWheelMsg, CMouseMsg); + ADDFN(CMovementMsg, CMessage); ADDFN(CMoveToStartPosMsg, CMessage); ADDFN(CMovieEndMsg, CMessage); ADDFN(CMovieFrameMsg, CMessage); diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp index 3355dcb074..979fea81fe 100644 --- a/engines/titanic/core/view_item.cpp +++ b/engines/titanic/core/view_item.cpp @@ -36,7 +36,7 @@ BEGIN_MESSAGE_MAP(CViewItem, CNamedItem) ON_MESSAGE(MouseButtonUpMsg) ON_MESSAGE(MouseDoubleClickMsg) ON_MESSAGE(MouseMoveMsg) - ON_MESSAGE(VirtualKeyCharMsg) + ON_MESSAGE(MovementMsg) END_MESSAGE_MAP() CViewItem::CViewItem() : CNamedItem() { @@ -338,35 +338,9 @@ CString CViewItem::getNodeViewName() const { return CString::format("%s.%s", node->getName().c_str(), getName().c_str()); } -bool CViewItem::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { - enum Movement { LEFT, RIGHT, FORWARDS, BACKWARDS }; - Movement move; - - switch (msg->_keyState.keycode) { - case Common::KEYCODE_LEFT: - case Common::KEYCODE_KP4: - // Left arrow - move = LEFT; - break; - case Common::KEYCODE_RIGHT: - case Common::KEYCODE_KP6: - // Right arrow - move = RIGHT; - break; - case Common::KEYCODE_UP: - case Common::KEYCODE_KP8: - // Up arrow - move = FORWARDS; - break; - case Common::KEYCODE_DOWN: - case Common::KEYCODE_KP2: - // Down arrow - move = BACKWARDS; - break; - default: - return false; - } - +bool CViewItem::MovementMsg(CMovementMsg *msg) { + Movement move = msg->_movement; + // Iterate through the links to find an appropriate link for (CTreeItem *treeItem = getFirstChild(); treeItem; treeItem = treeItem->scan(this)) { @@ -374,12 +348,8 @@ bool CViewItem::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { if (!link) continue; - CursorId c = getLinkCursor(link); - if ((move == LEFT && c == CURSOR_MOVE_LEFT) || - (move == RIGHT && c == CURSOR_MOVE_RIGHT) || - (move == FORWARDS && (c == CURSOR_MOVE_FORWARD || - c == CURSOR_MOVE_THROUGH || c == CURSOR_DOWN)) || - (move == BACKWARDS && c == CURSOR_BACKWARDS)) { + Movement m = link->getMovement(); + if (move == m) { // Found a matching link CGameManager *gm = getGameManager(); gm->_gameState.triggerLink(link); diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h index d8ec3c1b98..c32a7b4b90 100644 --- a/engines/titanic/core/view_item.h +++ b/engines/titanic/core/view_item.h @@ -36,7 +36,7 @@ class CViewItem : public CNamedItem { bool MouseButtonUpMsg(CMouseButtonUpMsg *msg); bool MouseMoveMsg(CMouseMoveMsg *msg); bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg); - bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg); + bool MovementMsg(CMovementMsg *msg); private: CTreeItem *_buttonUpTargets[4]; private: |