aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2017-08-04 22:00:49 -0400
committerPaul Gilbert2017-08-04 22:00:49 -0400
commite44c5bdcc6ca300d70d2455a70ee466552e52dc2 (patch)
treebdba17efbfcae4808bccc5c4b0da5c14665cc194 /engines/titanic
parentf9c370d942d28c15b44a7f1786fac3e9e3bb545f (diff)
downloadscummvm-rg350-e44c5bdcc6ca300d70d2455a70ee466552e52dc2.tar.gz
scummvm-rg350-e44c5bdcc6ca300d70d2455a70ee466552e52dc2.tar.bz2
scummvm-rg350-e44c5bdcc6ca300d70d2455a70ee466552e52dc2.zip
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.
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/core/view_item.cpp53
-rw-r--r--engines/titanic/core/view_item.h1
-rw-r--r--engines/titanic/input_translator.cpp18
-rw-r--r--engines/titanic/input_translator.h6
-rw-r--r--engines/titanic/pet_control/pet_conversations.cpp21
-rw-r--r--engines/titanic/pet_control/pet_glyphs.cpp15
6 files changed, 83 insertions, 31 deletions
diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp
index 243d47f3fd..2b585160ea 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 ceb8a020da..e18536dc36 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 cd0dbc7d56..bd805258d5 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 cb53a2c396..0e1b5de1b1 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 6db804ee16..0a31f44bbf 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 0f640294fc..5ce2283f6e 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))