[Scummvm-git-logs] scummvm master -> e44c5bdcc6ca300d70d2455a70ee466552e52dc2

dreammaster dreammaster at scummvm.org
Sat Aug 5 04:02:28 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:
e44c5bdcc6 TITANIC: Introduce movement via arrow keys


Commit: e44c5bdcc6ca300d70d2455a70ee466552e52dc2
    https://github.com/scummvm/scummvm/commit/e44c5bdcc6ca300d70d2455a70ee466552e52dc2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-08-04T22:00:49-04:00

Commit Message:
TITANIC: Introduce movement via arrow keys

This also fixes a bug with Page Up, Down, Home, & End not working for
the Conversation tab. Additionally, code for scrolling individual
lines in the conversation and glyphs via the arrow keys has been
removed in favor of this centrallised movement, since they were
somewhat redundant, and the mouse wheel can be used for scrolling.

Changed paths:
    engines/titanic/core/view_item.cpp
    engines/titanic/core/view_item.h
    engines/titanic/input_translator.cpp
    engines/titanic/input_translator.h
    engines/titanic/pet_control/pet_conversations.cpp
    engines/titanic/pet_control/pet_glyphs.cpp


diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp
index 243d47f..2b58516 100644
--- a/engines/titanic/core/view_item.cpp
+++ b/engines/titanic/core/view_item.cpp
@@ -36,6 +36,7 @@ BEGIN_MESSAGE_MAP(CViewItem, CNamedItem)
 	ON_MESSAGE(MouseButtonUpMsg)
 	ON_MESSAGE(MouseDoubleClickMsg)
 	ON_MESSAGE(MouseMoveMsg)
+	ON_MESSAGE(VirtualKeyCharMsg)
 END_MESSAGE_MAP()
 
 CViewItem::CViewItem() : CNamedItem() {
@@ -337,4 +338,56 @@ 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;
+	}
+
+	// Iterate through the links to find an appropriate link
+	for (CTreeItem *treeItem = getFirstChild(); treeItem;
+			treeItem = treeItem->scan(this)) {
+		CLinkItem *link = dynamic_cast<CLinkItem *>(treeItem);
+		if (!link)
+			continue;
+		
+		CursorId c = link->_cursorId;
+		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)) {
+			// Found a matching link
+			CGameManager *gm = getGameManager();
+			gm->_gameState.triggerLink(link);
+			return true;
+		}
+	}
+
+	return false;
+}
+
 } // End of namespace Titanic
diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h
index ceb8a02..e18536d 100644
--- a/engines/titanic/core/view_item.h
+++ b/engines/titanic/core/view_item.h
@@ -36,6 +36,7 @@ class CViewItem : public CNamedItem {
 	bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
 	bool MouseMoveMsg(CMouseMoveMsg *msg);
 	bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg);
+	bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg);
 private:
 	CTreeItem *_buttonUpTargets[4];
 private:
diff --git a/engines/titanic/input_translator.cpp b/engines/titanic/input_translator.cpp
index cd0dbc7..bd80525 100644
--- a/engines/titanic/input_translator.cpp
+++ b/engines/titanic/input_translator.cpp
@@ -86,12 +86,12 @@ void CInputTranslator::mouseWheel(bool wheelUp, const Point &pt) {
 }
 
 void CInputTranslator::keyDown(const Common::KeyState &keyState) {
-	if (keyState.keycode >= Common::KEYCODE_F1 && keyState.keycode <= Common::KEYCODE_F5) {
+	if (isSpecialKey(keyState.keycode)) {
 		CVirtualKeyCharMsg msg(keyState);
 		_inputHandler->handleMessage(msg);
 	}
 
-	if (keyState.ascii <= 127) {
+	if (keyState.ascii > 0 && keyState.ascii <= 127) {
 		CKeyCharMsg msg(keyState.ascii);
 		_inputHandler->handleMessage(msg);
 	}
@@ -101,4 +101,18 @@ bool CInputTranslator::isMousePressed() const {
 	return g_vm->_events->getSpecialButtons() & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON);
 }
 
+bool CInputTranslator::isSpecialKey(Common::KeyCode key) {
+	if ((key >= Common::KEYCODE_F1 && key <= Common::KEYCODE_F8) ||
+		(key >= Common::KEYCODE_KP1 && key <= Common::KEYCODE_KP9))
+		return true;
+
+	if (key == Common::KEYCODE_PAGEUP || key == Common::KEYCODE_PAGEDOWN ||
+		key == Common::KEYCODE_HOME || key == Common::KEYCODE_END ||
+		key == Common::KEYCODE_LEFT || key == Common::KEYCODE_RIGHT ||
+		key == Common::KEYCODE_UP || key == Common::KEYCODE_DOWN)
+		return true;
+
+	return false;
+}
+
 } // End of namespace Titanic
diff --git a/engines/titanic/input_translator.h b/engines/titanic/input_translator.h
index cb53a2c..0e1b5de 100644
--- a/engines/titanic/input_translator.h
+++ b/engines/titanic/input_translator.h
@@ -36,6 +36,12 @@ private:
 	 * Converts the special buttons bitset into a buttons bitset
 	 */
 	int getButtons(int special) const;
+
+	/**
+	 * Returns true if a key down contains a special non-ascii key
+	 * that should still be passed onto the game
+	 */
+	bool isSpecialKey(Common::KeyCode key);
 public:
 	CInputHandler *_inputHandler;
 public:
diff --git a/engines/titanic/pet_control/pet_conversations.cpp b/engines/titanic/pet_control/pet_conversations.cpp
index 6db804e..0a31f44 100644
--- a/engines/titanic/pet_control/pet_conversations.cpp
+++ b/engines/titanic/pet_control/pet_conversations.cpp
@@ -461,37 +461,30 @@ TTnpcScript *CPetConversations::getNPCScript(const CString &name) const {
 
 bool CPetConversations::handleKey(const Common::KeyState &keyState) {
 	switch (keyState.keycode) {
-	case Common::KEYCODE_UP:
-	case Common::KEYCODE_KP8:
-		scrollUp();
-		break;
-	case Common::KEYCODE_DOWN:
-	case Common::KEYCODE_KP2:
-		scrollDown();
-		break;
 	case Common::KEYCODE_PAGEUP:
 	case Common::KEYCODE_KP9:
 		scrollUpPage();
-		break;
+		return true;
 	case Common::KEYCODE_PAGEDOWN:
 	case Common::KEYCODE_KP3:
 		scrollDownPage();
-		break;
+		return true;
 	case Common::KEYCODE_HOME:
 	case Common::KEYCODE_KP7:
 		scrollToTop();
-		break;
+		return true;
 	case Common::KEYCODE_END:
 	case Common::KEYCODE_KP1:
 		scrollToBottom();
-		break;
+		return true;
 	default:
-		if (keyState.ascii > 0 && keyState.ascii) {
+		if (keyState.ascii > 0 && keyState.ascii <= 127) {
 			if (_textInput.handleKey(keyState.ascii))
 				// Text line finished, so process line
 				textLineEntered(_textInput.getText());
+			return true;
 		}
-		return true;
+		break;
 	}
 
 	return false;
diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp
index 0f64029..5ce2283 100644
--- a/engines/titanic/pet_control/pet_glyphs.cpp
+++ b/engines/titanic/pet_control/pet_glyphs.cpp
@@ -415,21 +415,6 @@ bool CPetGlyphs::KeyCharMsg(int key) {
 }
 
 bool CPetGlyphs::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
-	Common::KeyCode key = msg->_keyState.keycode;
-
-	switch (key) {
-	case Common::KEYCODE_LEFT:
-		decSelection();
-		return true;
-
-	case Common::KEYCODE_RIGHT:
-		incSelection();
-		return true;
-
-	default:
-		break;
-	}
-
 	if (_highlightIndex >= 0) {
 		CPetGlyph *glyph = getGlyph(_highlightIndex);
 		if (glyph && glyph->VirtualKeyCharMsg(msg))





More information about the Scummvm-git-logs mailing list