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.
This commit is contained in:
parent
f9c370d942
commit
e44c5bdcc6
6 changed files with 83 additions and 31 deletions
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue