[Scummvm-git-logs] scummvm master -> 07e70d9896c0d2eb9c2b1c56becfa1483822a382

dreammaster dreammaster at scummvm.org
Sun Aug 6 17:59:33 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
07e70d9896 TITANIC: Create new CMovementMsg for new movement functionality


Commit: 07e70d9896c0d2eb9c2b1c56becfa1483822a382
    https://github.com/scummvm/scummvm/commit/07e70d9896c0d2eb9c2b1c56becfa1483822a382
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-08-06T11:58:06-04:00

Commit Message:
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

Changed paths:
    engines/titanic/core/game_object.cpp
    engines/titanic/core/game_object.h
    engines/titanic/core/link_item.cpp
    engines/titanic/core/link_item.h
    engines/titanic/core/saveable_object.cpp
    engines/titanic/core/view_item.cpp
    engines/titanic/core/view_item.h
    engines/titanic/input_translator.cpp
    engines/titanic/messages/messages.cpp
    engines/titanic/messages/messages.h


diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index d4457e7..ea3cb4d 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 c09577a..d08ef4c 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 a131b85..c46e44a 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 dd93e2a..609310a 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 256ca41..586036a 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 3355dcb..979fea8 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 d8ec3c1..c32a7b4 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 c5640a4..02e9b87 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 331d580..83c0968 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 8f8c785..b5c8dd4 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");





More information about the Scummvm-git-logs mailing list