aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Boutonné2010-12-20 17:25:58 +0000
committerArnaud Boutonné2010-12-20 17:25:58 +0000
commit184d56df0ace87d5350ce394691904b00fd27c56 (patch)
tree29c6273aad562166d52582e43508040a4ceeb967
parent26dfb6affabbe3da91934b43819c3a998cd8d125 (diff)
downloadscummvm-rg350-184d56df0ace87d5350ce394691904b00fd27c56.tar.gz
scummvm-rg350-184d56df0ace87d5350ce394691904b00fd27c56.tar.bz2
scummvm-rg350-184d56df0ace87d5350ce394691904b00fd27c56.zip
HUGO: Improve keyboard handling
- Handle keypad - Fix 'QWERTY' only issue - Suppress useless variable and parameter svn-id: r54977
-rw-r--r--engines/hugo/hugo.cpp2
-rw-r--r--engines/hugo/parser.cpp75
-rw-r--r--engines/hugo/parser.h37
-rw-r--r--engines/hugo/parser_v1d.cpp88
-rw-r--r--engines/hugo/parser_v1w.cpp27
-rw-r--r--engines/hugo/parser_v3d.cpp2
-rw-r--r--engines/hugo/route.cpp16
7 files changed, 140 insertions, 107 deletions
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index 3093cd988f..0a19ee441e 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -284,7 +284,7 @@ Common::Error HugoEngine::run() {
this->getDebugger()->attach();
this->getDebugger()->onFrame();
}
- _parser->keyHandler(event.kbd.keycode, 0);
+ _parser->keyHandler(event);
break;
case Common::EVENT_MOUSEMOVE:
_mouseX = event.mouse.x;
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index a07fbff319..9836861bca 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -35,9 +35,7 @@
#include "hugo/hugo.h"
#include "hugo/parser.h"
#include "hugo/file.h"
-#include "hugo/display.h"
#include "hugo/schedule.h"
-#include "hugo/route.h"
#include "hugo/util.h"
#include "hugo/sound.h"
#include "hugo/object.h"
@@ -55,79 +53,6 @@ Parser::Parser(HugoEngine *vm) :
Parser::~Parser() {
}
-void Parser::keyHandler(uint16 nChar, uint16 nFlags) {
- debugC(1, kDebugParser, "keyHandler(%d, %d)", nChar, nFlags);
-
- status_t &gameStatus = _vm->getGameStatus();
- bool repeatedFl = (nFlags & 0x4000); // TRUE if key is a repeat
-
-// Process key down event - called from OnKeyDown()
- switch (nChar) { // Set various toggle states
- case Common::KEYCODE_ESCAPE: // Escape key, may want to QUIT
- if (gameStatus.inventoryState == I_ACTIVE) // Remove inventory, if displayed
- gameStatus.inventoryState = I_UP;
- gameStatus.inventoryObjId = -1; // Deselect any dragged icon
- break;
- case Common::KEYCODE_END:
- case Common::KEYCODE_HOME:
- case Common::KEYCODE_LEFT:
- case Common::KEYCODE_RIGHT:
- case Common::KEYCODE_UP:
- case Common::KEYCODE_DOWN:
- if (!repeatedFl) {
- gameStatus.routeIndex = -1; // Stop any automatic route
- _vm->_route->setWalk(nChar); // Direction of hero travel
- }
- break;
- case Common::KEYCODE_F1: // User Help (DOS)
- if (_checkDoubleF1Fl)
- _vm->_file->instructions();
- else
- _vm->_screen->userHelp();
- _checkDoubleF1Fl = !_checkDoubleF1Fl;
- break;
- case Common::KEYCODE_F2: // Toggle sound
- _vm->_sound->toggleSound();
- _vm->_sound->toggleMusic();
- break;
- case Common::KEYCODE_F3: // Repeat last line
- gameStatus.recallFl = true;
- break;
- case Common::KEYCODE_F4: // Save game
- if (gameStatus.viewState == V_PLAY)
- _vm->_file->saveGame(-1, Common::String());
- break;
- case Common::KEYCODE_F5: // Restore game
- _vm->_file->restoreGame(-1);
- _vm->_scheduler->restoreScreen(*_vm->_screen_p);
- gameStatus.viewState = V_PLAY;
- break;
- case Common::KEYCODE_F6: // Inventory
- showDosInventory();
- break;
- case Common::KEYCODE_F8: // Turbo mode
- _config.turboFl = !_config.turboFl;
- break;
- case Common::KEYCODE_F9: // Boss button
- warning("STUB: F9 (DOS) - BossKey");
- break;
- default: // Any other key
- if (!gameStatus.storyModeFl) { // Keyboard disabled
- // Add printable keys to ring buffer
- uint16 bnext = _putIndex + 1;
- if (bnext >= sizeof(_ringBuffer))
- bnext = 0;
- if (bnext != _getIndex) {
- _ringBuffer[_putIndex] = nChar;
- _putIndex = bnext;
- }
- }
- break;
- }
- if (_checkDoubleF1Fl && (nChar != Common::KEYCODE_F1))
- _checkDoubleF1Fl = false;
-}
-
/**
* Add any new chars to line buffer and display them.
* If CR pressed, pass line to LineHandler()
diff --git a/engines/hugo/parser.h b/engines/hugo/parser.h
index d25b1434e6..c0184dc600 100644
--- a/engines/hugo/parser.h
+++ b/engines/hugo/parser.h
@@ -52,7 +52,7 @@ public:
void charHandler();
void command(const char *format, ...);
- virtual void keyHandler(uint16 nChar, uint16 nFlags);
+ virtual void keyHandler(Common::Event event) = 0;
virtual void lineHandler() = 0;
protected:
@@ -61,13 +61,12 @@ protected:
protected:
char *findNoun();
char *findVerb();
- bool _checkDoubleF1Fl; // Flag used to display user help or instructions
- uint16 _putIndex;
+ void showDosInventory();
+
+ bool _checkDoubleF1Fl; // Flag used to display user help or instructions
uint16 _getIndex; // Index into ring buffer
+ uint16 _putIndex;
char _ringBuffer[32]; // Ring buffer
-
-private:
- void showDosInventory();
};
class Parser_v1d : public Parser {
@@ -75,17 +74,19 @@ public:
Parser_v1d(HugoEngine *vm);
~Parser_v1d();
+ virtual void keyHandler(Common::Event event);
virtual void lineHandler();
protected:
- bool isNear(char *verb, char *noun, object_t *obj, char *comment);
- bool isGenericVerb(char *word, object_t *obj);
- bool isObjectVerb(char *word, object_t *obj);
- bool isBackgroundWord(char *noun, char *verb, objectList_t obj);
- bool isCatchallVerb(bool testNounFl, char *noun, char *verb, objectList_t obj);
+ virtual void dropObject(object_t *obj);
+ virtual bool isBackgroundWord(char *noun, char *verb, objectList_t obj);
+ virtual bool isCatchallVerb(bool testNounFl, char *noun, char *verb, objectList_t obj);
+ virtual bool isGenericVerb(char *word, object_t *obj);
+ virtual bool isNear(char *verb, char *noun, object_t *obj, char *comment);
+ virtual bool isObjectVerb(char *word, object_t *obj);
+ virtual void takeObject(object_t *obj);
+
char *findNextNoun(char *noun);
- void dropObject(object_t *obj);
- void takeObject(object_t *obj);
};
class Parser_v2d : public Parser_v1d {
@@ -96,22 +97,20 @@ public:
void lineHandler();
};
-class Parser_v3d : public Parser {
+class Parser_v3d : public Parser_v1d {
public:
Parser_v3d(HugoEngine *vm);
~Parser_v3d();
virtual void lineHandler();
protected:
+ void dropObject(object_t *obj);
bool isBackgroundWord(objectList_t obj);
bool isCatchallVerb(objectList_t obj);
bool isGenericVerb(object_t *obj, char *comment);
+ bool isNear(object_t *obj, char *verb, char *comment);
bool isObjectVerb(object_t *obj, char *comment);
void takeObject(object_t *obj);
-
-private:
- bool isNear(object_t *obj, char *verb, char *comment);
- void dropObject(object_t *obj);
};
class Parser_v1w : public Parser_v3d {
@@ -119,7 +118,7 @@ public:
Parser_v1w(HugoEngine *vm);
~Parser_v1w();
- void keyHandler(uint16 nChar, uint16 nFlags);
+ void keyHandler(Common::Event event);
void lineHandler();
};
diff --git a/engines/hugo/parser_v1d.cpp b/engines/hugo/parser_v1d.cpp
index ce57222317..976690bde3 100644
--- a/engines/hugo/parser_v1d.cpp
+++ b/engines/hugo/parser_v1d.cpp
@@ -33,12 +33,15 @@
// parser.c - handles all keyboard/command input
#include "common/system.h"
+#include "common/events.h"
#include "hugo/hugo.h"
#include "hugo/parser.h"
#include "hugo/file.h"
#include "hugo/schedule.h"
+#include "hugo/display.h"
#include "hugo/util.h"
+#include "hugo/route.h"
#include "hugo/sound.h"
#include "hugo/object.h"
@@ -196,11 +199,11 @@ bool Parser_v1d::isObjectVerb(char *word, object_t *obj) {
break;
}
- if (_vm->_cmdList[cmdIndex][i].verbIndex == 0) // No
+ if (_vm->_cmdList[cmdIndex][i].verbIndex == 0) // No
return false;
// Verb match found, check all required objects are being carried
- cmd *cmnd = &_vm->_cmdList[cmdIndex][i]; // ptr to struct cmd
+ cmd *cmnd = &_vm->_cmdList[cmdIndex][i]; // ptr to struct cmd
if (cmnd->reqIndex) { // At least 1 thing in list
uint16 *reqs = _vm->_arrayReqs[cmnd->reqIndex]; // ptr to list of required objects
for (i = 0; reqs[i]; i++) { // for each obj
@@ -297,6 +300,87 @@ bool Parser_v1d::isCatchallVerb(bool testNounFl, char *noun, char *verb, objectL
return false;
}
+void Parser_v1d::keyHandler(Common::Event event) {
+ debugC(1, kDebugParser, "keyHandler(%d)", event.kbd.keycode);
+
+ status_t &gameStatus = _vm->getGameStatus();
+ uint16 nChar = event.kbd.keycode;
+
+ // Process key down event - called from OnKeyDown()
+ switch (nChar) { // Set various toggle states
+ case Common::KEYCODE_ESCAPE: // Escape key, may want to QUIT
+ if (gameStatus.inventoryState == I_ACTIVE) // Remove inventory, if displayed
+ gameStatus.inventoryState = I_UP;
+ gameStatus.inventoryObjId = -1; // Deselect any dragged icon
+ break;
+ case Common::KEYCODE_END:
+ case Common::KEYCODE_HOME:
+ case Common::KEYCODE_PAGEUP:
+ case Common::KEYCODE_PAGEDOWN:
+ case Common::KEYCODE_KP1:
+ case Common::KEYCODE_KP7:
+ case Common::KEYCODE_KP9:
+ case Common::KEYCODE_KP3:
+ case Common::KEYCODE_LEFT:
+ case Common::KEYCODE_RIGHT:
+ case Common::KEYCODE_UP:
+ case Common::KEYCODE_DOWN:
+ case Common::KEYCODE_KP4:
+ case Common::KEYCODE_KP6:
+ case Common::KEYCODE_KP8:
+ case Common::KEYCODE_KP2:
+ gameStatus.routeIndex = -1; // Stop any automatic route
+ _vm->_route->setWalk(nChar); // Direction of hero travel
+ break;
+ case Common::KEYCODE_F1: // User Help (DOS)
+ if (_checkDoubleF1Fl)
+ _vm->_file->instructions();
+ else
+ _vm->_screen->userHelp();
+ _checkDoubleF1Fl = !_checkDoubleF1Fl;
+ break;
+ case Common::KEYCODE_F2: // Toggle sound
+ _vm->_sound->toggleSound();
+ _vm->_sound->toggleMusic();
+ break;
+ case Common::KEYCODE_F3: // Repeat last line
+ gameStatus.recallFl = true;
+ break;
+ case Common::KEYCODE_F4: // Save game
+ if (gameStatus.viewState == V_PLAY)
+ _vm->_file->saveGame(-1, Common::String());
+ break;
+ case Common::KEYCODE_F5: // Restore game
+ _vm->_file->restoreGame(-1);
+ _vm->_scheduler->restoreScreen(*_vm->_screen_p);
+ gameStatus.viewState = V_PLAY;
+ break;
+ case Common::KEYCODE_F6: // Inventory
+ showDosInventory();
+ break;
+ case Common::KEYCODE_F8: // Turbo mode
+ _config.turboFl = !_config.turboFl;
+ break;
+ case Common::KEYCODE_F9: // Boss button
+ warning("STUB: F9 (DOS) - BossKey");
+ break;
+ default: // Any other key
+ if (!gameStatus.storyModeFl) { // Keyboard disabled
+ // Add printable keys to ring buffer
+ uint16 bnext = _putIndex + 1;
+ if (bnext >= sizeof(_ringBuffer))
+ bnext = 0;
+ if (bnext != _getIndex) {
+ _ringBuffer[_putIndex] = event.kbd.ascii;
+ _putIndex = bnext;
+ }
+ }
+ break;
+ }
+ if (_checkDoubleF1Fl && (nChar != Common::KEYCODE_F1))
+ _checkDoubleF1Fl = false;
+}
+
/**
* Parse the user's line of text input. Generate events as necessary
*/
diff --git a/engines/hugo/parser_v1w.cpp b/engines/hugo/parser_v1w.cpp
index 6629dd03f1..cc82dfa3c2 100644
--- a/engines/hugo/parser_v1w.cpp
+++ b/engines/hugo/parser_v1w.cpp
@@ -33,6 +33,7 @@
// parser.c - handles all keyboard/command input
#include "common/system.h"
+#include "common/events.h"
#include "hugo/hugo.h"
#include "hugo/parser.h"
@@ -51,13 +52,13 @@ Parser_v1w::Parser_v1w(HugoEngine *vm) : Parser_v3d(vm) {
Parser_v1w::~Parser_v1w() {
}
-void Parser_v1w::keyHandler(uint16 nChar, uint16 nFlags) {
- debugC(1, kDebugParser, "keyHandler(%d, %d)", nChar, nFlags);
+void Parser_v1w::keyHandler(Common::Event event) {
+ debugC(1, kDebugParser, "keyHandler(%d)", event.kbd.keycode);
status_t &gameStatus = _vm->getGameStatus();
- bool repeatedFl = (nFlags & 0x4000); // TRUE if key is a repeat
+ uint16 nChar = event.kbd.keycode;
-// Process key down event - called from OnKeyDown()
+ // Process key down event - called from OnKeyDown()
switch (nChar) { // Set various toggle states
case Common::KEYCODE_ESCAPE: // Escape key, may want to QUIT
if (gameStatus.inventoryState == I_ACTIVE) // Remove inventory, if displayed
@@ -66,14 +67,22 @@ void Parser_v1w::keyHandler(uint16 nChar, uint16 nFlags) {
break;
case Common::KEYCODE_END:
case Common::KEYCODE_HOME:
+ case Common::KEYCODE_PAGEUP:
+ case Common::KEYCODE_PAGEDOWN:
+ case Common::KEYCODE_KP1:
+ case Common::KEYCODE_KP7:
+ case Common::KEYCODE_KP9:
+ case Common::KEYCODE_KP3:
case Common::KEYCODE_LEFT:
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_UP:
case Common::KEYCODE_DOWN:
- if (!repeatedFl) {
- gameStatus.routeIndex = -1; // Stop any automatic route
- _vm->_route->setWalk(nChar); // Direction of hero travel
- }
+ case Common::KEYCODE_KP4:
+ case Common::KEYCODE_KP6:
+ case Common::KEYCODE_KP8:
+ case Common::KEYCODE_KP2:
+ gameStatus.routeIndex = -1; // Stop any automatic route
+ _vm->_route->setWalk(nChar); // Direction of hero travel
break;
case Common::KEYCODE_F1: // User Help (DOS)
if (_checkDoubleF1Fl)
@@ -117,7 +126,7 @@ void Parser_v1w::keyHandler(uint16 nChar, uint16 nFlags) {
if (bnext >= sizeof(_ringBuffer))
bnext = 0;
if (bnext != _getIndex) {
- _ringBuffer[_putIndex] = nChar;
+ _ringBuffer[_putIndex] = event.kbd.ascii;
_putIndex = bnext;
}
}
diff --git a/engines/hugo/parser_v3d.cpp b/engines/hugo/parser_v3d.cpp
index bba42f6cf8..f1e4e8caba 100644
--- a/engines/hugo/parser_v3d.cpp
+++ b/engines/hugo/parser_v3d.cpp
@@ -44,7 +44,7 @@
namespace Hugo {
-Parser_v3d::Parser_v3d(HugoEngine *vm) : Parser(vm) {
+Parser_v3d::Parser_v3d(HugoEngine *vm) : Parser_v1d(vm) {
}
Parser_v3d::~Parser_v3d() {
diff --git a/engines/hugo/route.cpp b/engines/hugo/route.cpp
index 070e952747..e8ecf0796b 100644
--- a/engines/hugo/route.cpp
+++ b/engines/hugo/route.cpp
@@ -55,27 +55,35 @@ void Route::setDirection(uint16 keyCode) {
// Set first image in sequence
switch (keyCode) {
case Common::KEYCODE_UP:
+ case Common::KEYCODE_KP8:
obj->currImagePtr = obj->seqList[_UP].seqPtr;
break;
case Common::KEYCODE_DOWN:
+ case Common::KEYCODE_KP2:
obj->currImagePtr = obj->seqList[DOWN].seqPtr;
break;
case Common::KEYCODE_LEFT:
+ case Common::KEYCODE_KP4:
obj->currImagePtr = obj->seqList[LEFT].seqPtr;
break;
case Common::KEYCODE_RIGHT:
+ case Common::KEYCODE_KP6:
obj->currImagePtr = obj->seqList[RIGHT].seqPtr;
break;
case Common::KEYCODE_HOME:
+ case Common::KEYCODE_KP7:
obj->currImagePtr = obj->seqList[LEFT].seqPtr;
break;
case Common::KEYCODE_END:
+ case Common::KEYCODE_KP1:
obj->currImagePtr = obj->seqList[LEFT].seqPtr;
break;
case Common::KEYCODE_PAGEUP:
+ case Common::KEYCODE_KP9:
obj->currImagePtr = obj->seqList[RIGHT].seqPtr;
break;
case Common::KEYCODE_PAGEDOWN:
+ case Common::KEYCODE_KP3:
obj->currImagePtr = obj->seqList[RIGHT].seqPtr;
break;
}
@@ -103,33 +111,41 @@ void Route::setWalk(uint16 direction) {
obj->vx = obj->vy = 0;
switch (direction) { // And set correct velocity
case Common::KEYCODE_UP:
+ case Common::KEYCODE_KP8:
obj->vy = -DY;
break;
case Common::KEYCODE_DOWN:
+ case Common::KEYCODE_KP2:
obj->vy = DY;
break;
case Common::KEYCODE_LEFT:
+ case Common::KEYCODE_KP4:
obj->vx = -DX;
break;
case Common::KEYCODE_RIGHT:
+ case Common::KEYCODE_KP6:
obj->vx = DX;
break;
case Common::KEYCODE_HOME:
+ case Common::KEYCODE_KP7:
obj->vx = -DX;
// Note: in v1 Dos and v2 Dos, obj->vy is set to DY
obj->vy = -DY / 2;
break;
case Common::KEYCODE_END:
+ case Common::KEYCODE_KP1:
obj->vx = -DX;
// Note: in v1 Dos and v2 Dos, obj->vy is set to -DY
obj->vy = DY / 2;
break;
case Common::KEYCODE_PAGEUP:
+ case Common::KEYCODE_KP9:
obj->vx = DX;
// Note: in v1 Dos and v2 Dos, obj->vy is set to -DY
obj->vy = -DY / 2;
break;
case Common::KEYCODE_PAGEDOWN:
+ case Common::KEYCODE_KP3:
obj->vx = DX;
// Note: in v1 Dos and v2 Dos, obj->vy is set to DY
obj->vy = DY / 2;