diff options
-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 | ||||
-rw-r--r-- | engines/titanic/input_translator.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/messages/messages.cpp | 21 | ||||
-rw-r--r-- | engines/titanic/messages/messages.h | 26 |
10 files changed, 100 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: diff --git a/engines/titanic/input_translator.cpp b/engines/titanic/input_translator.cpp index c5640a48bc..02e9b8794d 100644 --- a/engines/titanic/input_translator.cpp +++ b/engines/titanic/input_translator.cpp @@ -92,6 +92,12 @@ void CInputTranslator::keyDown(const Common::KeyState &keyState) { return; } + if (CMovementMsg::getMovement(keyState.keycode) != MOVE_NONE) { + CMovementMsg msg(keyState.keycode); + if (_inputHandler->handleMessage(msg)) + return; + } + if (isSpecialKey(keyState.keycode)) { CVirtualKeyCharMsg msg(keyState); msg._keyState.ascii = 0; diff --git a/engines/titanic/messages/messages.cpp b/engines/titanic/messages/messages.cpp index 331d580dee..83c09688c4 100644 --- a/engines/titanic/messages/messages.cpp +++ b/engines/titanic/messages/messages.cpp @@ -177,4 +177,25 @@ CShowTextMsg::CShowTextMsg(StringId stringId) : CMessage() { _message = g_vm->_strings[stringId]; } +/*------------------------------------------------------------------------*/ + +Movement CMovementMsg::getMovement(Common::KeyCode keycode) { + switch (keycode) { + case Common::KEYCODE_LEFT: + case Common::KEYCODE_KP4: + return TURN_LEFT; + case Common::KEYCODE_RIGHT: + case Common::KEYCODE_KP6: + return TURN_RIGHT; + case Common::KEYCODE_UP: + case Common::KEYCODE_KP8: + return MOVE_FORWARDS; + case Common::KEYCODE_DOWN: + case Common::KEYCODE_KP2: + return MOVE_BACKWARDS; + default: + return MOVE_NONE; + } +} + } // End of namespace Titanic diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index 8f8c785e43..b5c8dd4e21 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -222,6 +222,32 @@ enum MissiveOMatAction { MESSAGE_STARTUP = 9 }; +enum Movement { + MOVE_NONE = 0, MOVE_FORWARDS, MOVE_BACKWARDS, TURN_LEFT, TURN_RIGHT +}; + + +class CMovementMsg : public CMessage { +public: + Movement _movement; +public: + CLASSDEF; + CMovementMsg() : _movement(MOVE_NONE) {} + CMovementMsg(Movement move) : _movement(move) {} + CMovementMsg(Common::KeyCode key) : + _movement(getMovement(key)) {} + + static bool isSupportedBy(const CTreeItem *item) { + return supports(item, _type); + } + + /** + * Returns the movement associated with a given key, if any + */ + static Movement getMovement(Common::KeyCode keycode); +}; + + MESSAGE1(CActMsg, CString, action, ""); MESSAGE1(CActivationmsg, CString, value, ""); MESSAGE1(CAddHeadPieceMsg, CString, value, "NULL"); |