[Scummvm-cvs-logs] SF.net SVN: scummvm: [28889] scummvm/trunk/engines/saga

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Sep 11 11:19:23 CEST 2007


Revision: 28889
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28889&view=rev
Author:   fingolfin
Date:     2007-09-11 02:19:23 -0700 (Tue, 11 Sep 2007)

Log Message:
-----------
Change SAGA engine to properly use KeyState structs for handling keyboard input

Modified Paths:
--------------
    scummvm/trunk/engines/saga/actor.cpp
    scummvm/trunk/engines/saga/input.cpp
    scummvm/trunk/engines/saga/interface.cpp
    scummvm/trunk/engines/saga/interface.h

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2007-09-10 16:03:12 UTC (rev 28888)
+++ scummvm/trunk/engines/saga/actor.cpp	2007-09-11 09:19:23 UTC (rev 28889)
@@ -2014,6 +2014,8 @@
 					newLocation.y += _vm->_rnd.getRandomNumber(prefer1.y - 1) - prefer1.y / 2;
 				}
 
+				// FIXME: Fingolfin asks: why is there a FIXME here? Please either clarify what
+				// needs fixing, or remove it!
 				newLocation.x = clamp(-31*4, newLocation.x, (_vm->getDisplayWidth() + 31) * 4); //fixme
 
 				return actorWalkTo(actor->_id, newLocation);

Modified: scummvm/trunk/engines/saga/input.cpp
===================================================================
--- scummvm/trunk/engines/saga/input.cpp	2007-09-10 16:03:12 UTC (rev 28888)
+++ scummvm/trunk/engines/saga/input.cpp	2007-09-11 09:19:23 UTC (rev 28889)
@@ -49,7 +49,7 @@
 					_console->attach();
 			}
 			if (_interface->_textInput || _interface->_statusTextInput) {
-				_interface->processAscii(event.kbd.ascii);
+				_interface->processAscii(event.kbd);
 				return SUCCESS;
 			}
 
@@ -115,7 +115,7 @@
 				_render->toggleFlag(RF_RENDERPAUSE);
 				break;
 			default:
-				_interface->processAscii(event.kbd.ascii);
+				_interface->processAscii(event.kbd);
 				break;
 			}
 			break;

Modified: scummvm/trunk/engines/saga/interface.cpp
===================================================================
--- scummvm/trunk/engines/saga/interface.cpp	2007-09-10 16:03:12 UTC (rev 28888)
+++ scummvm/trunk/engines/saga/interface.cpp	2007-09-11 09:19:23 UTC (rev 28889)
@@ -476,22 +476,22 @@
 	draw();
 }
 
-bool Interface::processAscii(uint16 ascii) {
+bool Interface::processAscii(Common::KeyState keystate) {
 	// TODO: Checking for Esc and Enter below is a bit hackish, and
 	// and probably only works with the English version. Maybe we should
 	// add a flag to the button so it can indicate if it's the default or
 	// cancel button?
-
+	uint16 ascii = keystate.ascii;
 	int i;
 	PanelButton *panelButton;
 	if (_statusTextInput) {
-		processStatusTextInput(ascii);
+		processStatusTextInput(keystate);
 		return true;
 	}
 
 	switch (_panelMode) {
 	case kPanelNull:
-		if (ascii == 27) { // Esc
+		if (keystate.keycode == Common::KEYCODE_ESCAPE) {
 			if (_vm->_scene->isInIntro()) {
 				_vm->_scene->skipScene();
 			} else {
@@ -505,7 +505,7 @@
 			_vm->_scene->showIHNMDemoSpecialScreen();
 		break;
 	case kPanelCutaway:
-		if (ascii == 27) { // Esc
+		if (keystate.keycode == Common::KEYCODE_ESCAPE) {
 			if (!_disableAbortSpeeches)
 				_vm->_actor->abortAllSpeeches();
 			_vm->_scene->cutawaySkip();
@@ -516,7 +516,7 @@
 			_vm->_scene->showIHNMDemoSpecialScreen();
 		break;
 	case kPanelVideo:
-		if (ascii == 27) { // Esc
+		if (keystate.keycode == Common::KEYCODE_ESCAPE) {
 			if (_vm->_scene->isInIntro()) {
 				_vm->_scene->skipScene();
 			} else {
@@ -532,7 +532,7 @@
 		break;
 	case kPanelOption:
 		// TODO: check input dialog keys
-		if (ascii == 27 || ascii == 13) { // Esc or Enter
+		if (keystate.keycode == Common::KEYCODE_ESCAPE || keystate.keycode == Common::KEYCODE_RETURN) { // Esc or Enter
 			ascii = 'c'; //continue
 		}
 
@@ -547,13 +547,13 @@
 		}
 		break;
 	case kPanelSave:
-		if (_textInput && processTextInput(ascii)) {
+		if (_textInput && processTextInput(keystate)) {
 			return true;
 		}
 
-		if (ascii == 27) { // Esc
+		if (keystate.keycode == Common::KEYCODE_ESCAPE) {
 			ascii = 'c'; // cancel
-		} else if (ascii == 13) { // Enter
+		} else if (keystate.keycode == Common::KEYCODE_RETURN) { // Enter
 			ascii = 's'; // save
 		}
 
@@ -568,9 +568,9 @@
 		}
 		break;
 	case kPanelQuit:
-		if (ascii == 27) { // Esc
+		if (keystate.keycode == Common::KEYCODE_ESCAPE) {
 			ascii = 'c'; // cancel
-		} else if (ascii == 13) { // Enter
+		} else if (keystate.keycode == Common::KEYCODE_RETURN) { // Enter
 			ascii = 'q'; // quit
 		}
 
@@ -608,7 +608,7 @@
 				return true;
 			}
 		}
-		if (ascii == 15) { // ctrl-o
+		if (keystate.keycode == Common::KEYCODE_o && keystate.flags == Common::KBD_CTRL) { // ctrl-o
 			if (_saveReminderState > 0) {
 				setMode(kPanelOption);
 				return true;
@@ -651,7 +651,7 @@
 		mapPanelClean();
 		break;
 	case kPanelSceneSubstitute:
-		if (ascii == 13) {
+		if (keystate.keycode == Common::KEYCODE_RETURN) {
 			_vm->_render->clearFlag(RF_DEMO_SUBST);
 			_vm->_gfx->setPalette(_mapSavedPal);
 			setMode(kPanelMain);
@@ -666,11 +666,11 @@
 		break;
 	case kPanelProtect:
 		if (_vm->getGameType() == GType_ITE) {
-			if (_textInput && processTextInput(ascii)) {
+			if (_textInput && processTextInput(keystate)) {
 				return true;
 			}
 
-			if (ascii == 27 || ascii == 13) { // Esc or Enter
+			if (keystate.keycode == Common::KEYCODE_ESCAPE || keystate.keycode == Common::KEYCODE_RETURN) {
 				_vm->_script->wakeUpThreads(kWaitTypeRequest);
 				_vm->_interface->setMode(kPanelMain);
 				
@@ -1113,20 +1113,20 @@
 	}
 }
 
-void Interface::processStatusTextInput(uint16 ascii) {
+void Interface::processStatusTextInput(Common::KeyState keystate) {
 
-	switch (ascii) {
-	case 27: // esc
+	switch (keystate.keycode) {
+	case Common::KEYCODE_ESCAPE:
 		_statusTextInputState = kStatusTextInputAborted;
 		_statusTextInput = false;
 		_vm->_script->wakeUpThreads(kWaitTypeStatusTextInput);
 		break;
-	case 13: // return
+	case Common::KEYCODE_RETURN:
 		_statusTextInputState = kStatusTextInputEntered;
 		_statusTextInput = false;
 		_vm->_script->wakeUpThreads(kWaitTypeStatusTextInput);
 		break;
-	case 8: // backspace
+	case Common::KEYCODE_BACKSPACE:
 		if (_statusTextInputPos == 0) {
 			break;
 		}
@@ -1136,18 +1136,15 @@
 		if (_statusTextInputPos >= STATUS_TEXT_INPUT_MAX) {
 			break;
 		}
-		if (((ascii >= 'a') && (ascii <='z')) ||
-			((ascii >= '0') && (ascii <='9')) ||
-			((ascii >= 'A') && (ascii <='Z')) ||
-			(ascii == ' ')) {
-			_statusTextInputString[_statusTextInputPos++] = ascii;
+		if (isalnum(keystate.ascii) || (keystate.ascii == ' ')) {
+			_statusTextInputString[_statusTextInputPos++] = keystate.ascii;
 			_statusTextInputString[_statusTextInputPos] = 0;
 		}
 	}
 	setStatusText(_statusTextInputString);
 }
 
-bool Interface::processTextInput(uint16 ascii) {
+bool Interface::processTextInput(Common::KeyState keystate) {
 	char ch[2];
 	char tempString[SAVE_TITLE_SIZE];
 	uint tempWidth;
@@ -1157,18 +1154,18 @@
 	// in IHNM, to preserve backwards compatibility with older save games
 	uint save_title_size = _vm->getGameType() == GType_ITE ? SAVE_TITLE_SIZE : IHNM_SAVE_TITLE_SIZE;
 
-	switch (ascii) {
-	case 13:
+	switch (keystate.keycode) {
+	case Common::KEYCODE_RETURN:
 		return false;
-	case 27: // esc
+	case Common::KEYCODE_ESCAPE:
 		_textInput = false;
 		break;
-	case 8: // backspace
+	case Common::KEYCODE_BACKSPACE:
 		if (_textInputPos <= 1) {
 			break;
 		}
 		_textInputPos--;
-	case 127: // del
+	case Common::KEYCODE_DELETE:
 		if (_textInputPos <= _textInputStringLength) {
 			if (_textInputPos != 1) {
 				strncpy(tempString, _textInputString, _textInputPos - 1);
@@ -1180,27 +1177,25 @@
 			_textInputStringLength = strlen(_textInputString);
 		}
 		break;
-	case 276: // left
+	case Common::KEYCODE_LEFT:
 		if (_textInputPos > 1) {
 			_textInputPos--;
 		}
 		break;
-	case 275: // right
+	case Common::KEYCODE_RIGHT:
 		if (_textInputPos <= _textInputStringLength) {
 			_textInputPos++;
 		}
 		break;
 	default:
-		if (((ascii >= 'a') && (ascii <='z')) ||
-			((ascii >= '0') && (ascii <='9')) ||
-			((ascii >= 'A') && (ascii <='Z')) ||
-			 (ascii == ' ') || (ascii == '-') || (ascii == '_')) {
+		if (isalnum(keystate.ascii) || (keystate.ascii == ' ') ||
+		    (keystate.ascii == '-') || (keystate.ascii == '_')) {
 			if (_textInputStringLength < save_title_size - 1) {
-				ch[0] = ascii;
+				ch[0] = keystate.ascii;
 				tempWidth = _vm->_font->getStringWidth(kKnownFontSmall, ch, 0, kFontNormal);
 				tempWidth += _vm->_font->getStringWidth(kKnownFontSmall, _textInputString, 0, kFontNormal);
 				if (tempWidth > _textInputMaxWidth) {
-									break;
+					break;
 				}
 				if (_textInputPos != 1) {
 					strncpy(tempString, _textInputString, _textInputPos - 1);

Modified: scummvm/trunk/engines/saga/interface.h
===================================================================
--- scummvm/trunk/engines/saga/interface.h	2007-09-10 16:03:12 UTC (rev 28888)
+++ scummvm/trunk/engines/saga/interface.h	2007-09-11 09:19:23 UTC (rev 28889)
@@ -28,6 +28,7 @@
 #ifndef SAGA_INTERFACE_H
 #define SAGA_INTERFACE_H
 
+#include "common/keyboard.h"
 #include "common/savefile.h"
 
 #include "saga/displayinfo.h"
@@ -225,7 +226,7 @@
 	void drawStatusBar();
 	void setVerbState(int verb, int state);
 
-	bool processAscii(uint16 ascii);
+	bool processAscii(Common::KeyState keystate);
 
 	void keyBoss();
 	void keyBossExit();
@@ -341,8 +342,8 @@
 	void drawVerbPanelText(Surface *ds, PanelButton *panelButton, KnownColor textKnownColor, KnownColor textShadowKnownColor);
 	void drawVerbPanel(Surface *backBuffer, PanelButton* panelButton);
 	void calcOptionSaveSlider();
-	bool processTextInput(uint16 ascii);
-	void processStatusTextInput(uint16 ascii);
+	bool processTextInput(Common::KeyState keystate);
+	void processStatusTextInput(Common::KeyState keystate);
 
 public:
 	void converseInit(void);


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