[Scummvm-cvs-logs] SF.net SVN: scummvm:[54977] scummvm/trunk/engines/hugo

strangerke at users.sourceforge.net strangerke at users.sourceforge.net
Mon Dec 20 18:25:58 CET 2010


Revision: 54977
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54977&view=rev
Author:   strangerke
Date:     2010-12-20 17:25:58 +0000 (Mon, 20 Dec 2010)

Log Message:
-----------
HUGO: Improve keyboard handling

- Handle keypad
- Fix 'QWERTY' only issue
- Suppress useless variable and parameter

Modified Paths:
--------------
    scummvm/trunk/engines/hugo/hugo.cpp
    scummvm/trunk/engines/hugo/parser.cpp
    scummvm/trunk/engines/hugo/parser.h
    scummvm/trunk/engines/hugo/parser_v1d.cpp
    scummvm/trunk/engines/hugo/parser_v1w.cpp
    scummvm/trunk/engines/hugo/parser_v3d.cpp
    scummvm/trunk/engines/hugo/route.cpp

Modified: scummvm/trunk/engines/hugo/hugo.cpp
===================================================================
--- scummvm/trunk/engines/hugo/hugo.cpp	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/hugo.cpp	2010-12-20 17:25:58 UTC (rev 54977)
@@ -284,7 +284,7 @@
 					this->getDebugger()->attach();
 					this->getDebugger()->onFrame();
 				}
-				_parser->keyHandler(event.kbd.keycode, 0);
+				_parser->keyHandler(event);
 				break;
 			case Common::EVENT_MOUSEMOVE:
 				_mouseX = event.mouse.x;

Modified: scummvm/trunk/engines/hugo/parser.cpp
===================================================================
--- scummvm/trunk/engines/hugo/parser.cpp	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/parser.cpp	2010-12-20 17:25:58 UTC (rev 54977)
@@ -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() {
 }
 
-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()

Modified: scummvm/trunk/engines/hugo/parser.h
===================================================================
--- scummvm/trunk/engines/hugo/parser.h	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/parser.h	2010-12-20 17:25:58 UTC (rev 54977)
@@ -52,7 +52,7 @@
 	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:
 	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 @@
 	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 @@
 	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 @@
 	Parser_v1w(HugoEngine *vm);
 	~Parser_v1w();
 
-	void  keyHandler(uint16 nChar, uint16 nFlags);
+	void  keyHandler(Common::Event event);
 	void  lineHandler();
 };
 

Modified: scummvm/trunk/engines/hugo/parser_v1d.cpp
===================================================================
--- scummvm/trunk/engines/hugo/parser_v1d.cpp	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/parser_v1d.cpp	2010-12-20 17:25:58 UTC (rev 54977)
@@ -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 @@
 			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 @@
 	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
 */

Modified: scummvm/trunk/engines/hugo/parser_v1w.cpp
===================================================================
--- scummvm/trunk/engines/hugo/parser_v1w.cpp	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/parser_v1w.cpp	2010-12-20 17:25:58 UTC (rev 54977)
@@ -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() {
 }
 
-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 @@
 		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 @@
 			if (bnext >= sizeof(_ringBuffer))
 				bnext = 0;
 			if (bnext != _getIndex) {
-				_ringBuffer[_putIndex] = nChar;
+				_ringBuffer[_putIndex] = event.kbd.ascii;
 				_putIndex = bnext;
 			}
 		}

Modified: scummvm/trunk/engines/hugo/parser_v3d.cpp
===================================================================
--- scummvm/trunk/engines/hugo/parser_v3d.cpp	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/parser_v3d.cpp	2010-12-20 17:25:58 UTC (rev 54977)
@@ -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() {

Modified: scummvm/trunk/engines/hugo/route.cpp
===================================================================
--- scummvm/trunk/engines/hugo/route.cpp	2010-12-20 15:30:31 UTC (rev 54976)
+++ scummvm/trunk/engines/hugo/route.cpp	2010-12-20 17:25:58 UTC (rev 54977)
@@ -55,27 +55,35 @@
 	// 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 @@
 		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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list