[Scummvm-cvs-logs] scummvm master -> a5553b319706e2421202fecd44d3a771ebc22ebf

bluegr bluegr at gmail.com
Thu Dec 24 18:12:43 CET 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a5553b3197 Use Common::Keycode and enums in interface buttons


Commit: a5553b319706e2421202fecd44d3a771ebc22ebf
    https://github.com/scummvm/scummvm/commit/a5553b319706e2421202fecd44d3a771ebc22ebf
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2015-12-24T19:12:02+02:00

Commit Message:
Use Common::Keycode and enums in interface buttons

Changed paths:
    engines/lab/dispman.cpp
    engines/lab/engine.cpp
    engines/lab/eventman.h
    engines/lab/interface.cpp
    engines/lab/lab.h
    engines/lab/map.cpp
    engines/lab/special.cpp



diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp
index 097521f..8ff6a61 100644
--- a/engines/lab/dispman.cpp
+++ b/engines/lab/dispman.cpp
@@ -335,16 +335,16 @@ void DisplayMan::setUpScreens() {
 	// It's very convenient to have those shortcut, so I added them
 	// for all versions. (Strangerke)
 	uint16 y = _vm->_utils->vgaScaleY(173) - _vm->_utils->svgaCord(2);
-	moveButtonList->push_back(e->createButton(  1, y, 0,          't', moveImages[0],  moveImages[1]));
-	moveButtonList->push_back(e->createButton( 33, y, 1,          'm', moveImages[2],  moveImages[3]));
-	moveButtonList->push_back(e->createButton( 65, y, 2,          'o', moveImages[4],  moveImages[5]));
-	moveButtonList->push_back(e->createButton( 97, y, 3,          'c', moveImages[6],  moveImages[7]));
-	moveButtonList->push_back(e->createButton(129, y, 4,          'l', moveImages[8],  moveImages[9]));
-	moveButtonList->push_back(e->createButton(161, y, 5,          'i', moveImages[12], moveImages[13]));
-	moveButtonList->push_back(e->createButton(193, y, 6, VKEY_LTARROW, moveImages[14], moveImages[15]));
-	moveButtonList->push_back(e->createButton(225, y, 7, VKEY_UPARROW, moveImages[16], moveImages[17]));
-	moveButtonList->push_back(e->createButton(257, y, 8, VKEY_RTARROW, moveImages[18], moveImages[19]));
-	moveButtonList->push_back(e->createButton(289, y, 9,          'p', moveImages[10], moveImages[11]));
+	moveButtonList->push_back(e->createButton(  1, y, 0, Common::KEYCODE_t,     moveImages[0],  moveImages[1]));
+	moveButtonList->push_back(e->createButton( 33, y, 1, Common::KEYCODE_m,     moveImages[2],  moveImages[3]));
+	moveButtonList->push_back(e->createButton( 65, y, 2, Common::KEYCODE_o,     moveImages[4],  moveImages[5]));
+	moveButtonList->push_back(e->createButton( 97, y, 3, Common::KEYCODE_c,     moveImages[6],  moveImages[7]));
+	moveButtonList->push_back(e->createButton(129, y, 4, Common::KEYCODE_l,     moveImages[8],  moveImages[9]));
+	moveButtonList->push_back(e->createButton(161, y, 5, Common::KEYCODE_i,     moveImages[12], moveImages[13]));
+	moveButtonList->push_back(e->createButton(193, y, 6, Common::KEYCODE_LEFT,  moveImages[14], moveImages[15]));
+	moveButtonList->push_back(e->createButton(225, y, 7, Common::KEYCODE_UP,    moveImages[16], moveImages[17]));
+	moveButtonList->push_back(e->createButton(257, y, 8, Common::KEYCODE_RIGHT, moveImages[18], moveImages[19]));
+	moveButtonList->push_back(e->createButton(289, y, 9, Common::KEYCODE_p,     moveImages[10], moveImages[11]));
 
 	// TODO: The INV file is not present in the Amiga version
 	Common::File *invFile = _vm->_resource->openDataFile("P:Inv");
@@ -355,18 +355,18 @@ void DisplayMan::setUpScreens() {
 		for (int imgIdx = 0; imgIdx < 6; imgIdx++)
 			_vm->_invImages[imgIdx] = new Image(invFile, _vm);
 	}
-	invButtonList->push_back(e->createButton( 24, y, 0,          'm', invImages[0],   invImages[1]));
-	invButtonList->push_back(e->createButton( 56, y, 1,          'g', invImages[2],   invImages[3]));
-	invButtonList->push_back(e->createButton( 94, y, 2,          'u', invImages[4],   invImages[5]));
-	invButtonList->push_back(e->createButton(126, y, 3,          'l', moveImages[8],  moveImages[9]));
-	invButtonList->push_back(e->createButton(164, y, 4, VKEY_LTARROW, moveImages[14], moveImages[15]));
-	invButtonList->push_back(e->createButton(196, y, 5, VKEY_RTARROW, moveImages[18], moveImages[19]));
+	invButtonList->push_back(e->createButton( 24, y, 0, Common::KEYCODE_ESCAPE, invImages[0],   invImages[1]));
+	invButtonList->push_back(e->createButton( 56, y, 1, Common::KEYCODE_g,      invImages[2],   invImages[3]));
+	invButtonList->push_back(e->createButton( 94, y, 2, Common::KEYCODE_u,      invImages[4],   invImages[5]));
+	invButtonList->push_back(e->createButton(126, y, 3, Common::KEYCODE_l,      moveImages[8],  moveImages[9]));
+	invButtonList->push_back(e->createButton(164, y, 4, Common::KEYCODE_LEFT,   moveImages[14], moveImages[15]));
+	invButtonList->push_back(e->createButton(196, y, 5, Common::KEYCODE_RIGHT,  moveImages[18], moveImages[19]));
 
 	// The windows version has 2 extra buttons for breadcrumb trail
 	// CHECKME: the game is really hard to play without those, maybe we could add something to enable that.
 	if (_vm->getPlatform() == Common::kPlatformWindows) {
-		invButtonList->push_back(e->createButton(234, y, 6, 'b', invImages[6], invImages[7]));
-		invButtonList->push_back(e->createButton(266, y, 7, 'f', invImages[8], invImages[9]));
+		invButtonList->push_back(e->createButton(234, y, 6, Common::KEYCODE_b, invImages[6], invImages[7]));
+		invButtonList->push_back(e->createButton(266, y, 7, Common::KEYCODE_f, invImages[8], invImages[9]));
 	}
 
 	delete invFile;
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp
index 021456f..499ae79 100644
--- a/engines/lab/engine.cpp
+++ b/engines/lab/engine.cpp
@@ -77,19 +77,6 @@ enum Monitors {
 	//kMonitorLevers = 82
 };
 
-enum MainButtons {
-	kButtonPickup,
-	kButtonUse,
-	kButtonOpen,
-	kButtonClose,
-	kButtonLook,
-	kButtonInventory,
-	kButtonLeft,
-	kButtonForward,
-	kButtonRight,
-	kButtonMap
-};
-
 enum AltButtons {
 	kButtonMainDisplay,
 	kButtonSaveLoad,
@@ -505,24 +492,9 @@ void LabEngine::mainGameLoop() {
 			_anim->diffNextFrame();
 
 			if (_followingCrumbs) {
-				int result = followCrumbs();
-
-				if (result != 0) {
-					uint16 code = 0;
-					switch (result) {
-					case VKEY_UPARROW:
-						code = kButtonForward;
-						break;
-					case VKEY_LTARROW:
-						code = kButtonLeft;
-						break;
-					case VKEY_RTARROW:
-						code = kButtonRight;
-						break;
-					default:
-						break;
-					}
+				MainButton code = followCrumbs();
 
+				if (code == kButtonForward || code == kButtonLeft || code == kButtonRight) {
 					gotMessage = true;
 					mayShowCrumbIndicator();
 					_graphics->screenUpdate();
@@ -1100,18 +1072,18 @@ void LabEngine::go() {
 	_music->freeMusic();
 }
 
-int LabEngine::followCrumbs() {
+MainButton LabEngine::followCrumbs() {
 	// kDirectionNorth, kDirectionSouth, kDirectionEast, kDirectionWest
-	int movement[4][4] = {
-		{ VKEY_UPARROW, VKEY_RTARROW, VKEY_RTARROW, VKEY_LTARROW },
-		{ VKEY_RTARROW, VKEY_UPARROW, VKEY_LTARROW, VKEY_RTARROW },
-		{ VKEY_LTARROW, VKEY_RTARROW, VKEY_UPARROW, VKEY_RTARROW },
-		{ VKEY_RTARROW, VKEY_LTARROW, VKEY_RTARROW, VKEY_UPARROW }
+	MainButton movement[4][4] = {
+		{ kButtonForward, kButtonRight, kButtonRight, kButtonLeft },
+		{ kButtonRight, kButtonForward, kButtonLeft, kButtonRight },
+		{ kButtonLeft, kButtonRight, kButtonForward, kButtonRight },
+		{ kButtonRight, kButtonLeft, kButtonRight, kButtonForward }
 	};
 
 	if (_isCrumbWaiting) {
 		if (_system->getMillis() <= _crumbTimestamp)
-			return 0;
+			return kButtonNone;
 
 		_isCrumbWaiting = false;
 	}
@@ -1125,10 +1097,10 @@ int LabEngine::followCrumbs() {
 		_breadCrumbs[0]._roomNum = 0;
 		_droppingCrumbs = false;
 		_followingCrumbs = false;
-		return 0;
+		return kButtonNone;
 	}
 
-	int exitDir;
+	Direction exitDir;
 	// which direction is last crumb
 	if (_breadCrumbs[_numCrumbs]._direction == kDirectionEast)
 		exitDir = kDirectionWest;
@@ -1139,7 +1111,7 @@ int LabEngine::followCrumbs() {
 	else
 		exitDir = kDirectionNorth;
 
-	int moveDir = movement[_direction][exitDir];
+	MainButton moveDir = movement[_direction][exitDir];
 
 	if (_numCrumbs == 0) {
 		_isCrumbTurning = false;
@@ -1147,7 +1119,7 @@ int LabEngine::followCrumbs() {
 		_droppingCrumbs = false;
 		_followingCrumbs = false;
 	} else {
-		_isCrumbTurning = (moveDir != VKEY_UPARROW);
+		_isCrumbTurning = (moveDir != kButtonForward);
 		_isCrumbWaiting = true;
 
 		int theDelay = (_followCrumbsFast ? 1000 / 4 : 1000);
diff --git a/engines/lab/eventman.h b/engines/lab/eventman.h
index f0e04fc..3a10fb9 100644
--- a/engines/lab/eventman.h
+++ b/engines/lab/eventman.h
@@ -46,11 +46,6 @@ enum MessageClasses {
 	kMessageDeltaMove
 };
 
-#define VKEY_UPARROW    273
-#define VKEY_DNARROW    274
-#define VKEY_RTARROW    275
-#define VKEY_LTARROW    276
-
 struct IntuiMessage {
 	uint32 _msgClass;
 	uint16 _code; // KeyCode or Button Id
@@ -61,7 +56,7 @@ struct IntuiMessage {
 
 struct Button {
 	uint16 _x, _y, _buttonId;
-	uint16 _keyEquiv; // if not zero, a key that activates button
+	Common::KeyCode _keyEquiv; // if not zero, a key that activates button
 	bool _isEnabled;
 	Image *_image, *_altImage;
 };
@@ -95,7 +90,7 @@ private:
 	 * Checks whether or not the coords fall within one of the buttons in a list
 	 * of buttons.
 	 */
-	Button *checkNumButtonHit(ButtonList *buttonList, uint16 key);
+	Button *checkNumButtonHit(ButtonList *buttonList, Common::KeyCode key);
 
 	/**
 	 * Make a key press have the right case for a button KeyEquiv value.
@@ -106,7 +101,7 @@ public:
 	EventManager (LabEngine *vm);
 
 	void attachButtonList(ButtonList *buttonList);
-	Button *createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *image, Image *altImage);
+	Button *createButton(uint16 x, uint16 y, uint16 id, Common::KeyCode key, Image *image, Image *altImage);
 	void toggleButton(Button *button, uint16 penColor, bool enable);
 
 	/**
diff --git a/engines/lab/interface.cpp b/engines/lab/interface.cpp
index 4d00d7a..85d5897 100644
--- a/engines/lab/interface.cpp
+++ b/engines/lab/interface.cpp
@@ -39,7 +39,7 @@
 
 namespace Lab {
 
-Button *EventManager::createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *image, Image *altImage) {
+Button *EventManager::createButton(uint16 x, uint16 y, uint16 id, Common::KeyCode key, Image *image, Image *altImage) {
 	Button *button = new Button();
 
 	if (button) {
@@ -92,7 +92,7 @@ uint16 EventManager::makeButtonKeyEquiv(uint16 key) {
 	return key;
 }
 
-Button *EventManager::checkNumButtonHit(ButtonList *buttonList, uint16 key) {
+Button *EventManager::checkNumButtonHit(ButtonList *buttonList, Common::KeyCode key) {
 	uint16 gkey = key - '0';
 
 	if (!buttonList)
@@ -100,9 +100,10 @@ Button *EventManager::checkNumButtonHit(ButtonList *buttonList, uint16 key) {
 
 	for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) {
 		Button *button = *buttonItr;
-		if (((gkey - 1 == button->_buttonId) || ((gkey == 0) && (button->_buttonId == 9))
-		 || ((button->_keyEquiv != 0) && (makeButtonKeyEquiv(key) == button->_keyEquiv)))
-			  && button->_isEnabled) {
+		if (!button->_isEnabled)
+			continue;
+
+		if ((gkey - 1 == button->_buttonId) || (gkey == 0 && button->_buttonId == 9) || (button->_keyEquiv != Common::KEYCODE_INVALID && key == button->_keyEquiv)) {
 			button->_altImage->drawImage(button->_x, button->_y);
 			_vm->_system->delayMillis(80);
 			button->_image->drawImage(button->_x, button->_y);
diff --git a/engines/lab/lab.h b/engines/lab/lab.h
index 3741505..e3bd5e2 100644
--- a/engines/lab/lab.h
+++ b/engines/lab/lab.h
@@ -97,6 +97,20 @@ enum Direction {
 	kDirectionWest
 };
 
+enum MainButton {
+	kButtonNone = -1,
+	kButtonPickup,
+	kButtonUse,
+	kButtonOpen,
+	kButtonClose,
+	kButtonLook,
+	kButtonInventory,
+	kButtonLeft,
+	kButtonForward,
+	kButtonRight,
+	kButtonMap
+};
+
 class LabEngine : public Engine {
 private:
 	bool _interfaceOff;
@@ -346,7 +360,7 @@ private:
 	/**
 	 * New code to allow quick(er) return navigation in game.
 	 */
-	int followCrumbs();
+	MainButton followCrumbs();
 	void freeMapData();
 	void freeScreens();
 	bool fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Common::Point tmpPos,
diff --git a/engines/lab/map.cpp b/engines/lab/map.cpp
index d84f852..bc766f4 100644
--- a/engines/lab/map.cpp
+++ b/engines/lab/map.cpp
@@ -75,9 +75,9 @@ void LabEngine::loadMapData() {
 	_imgPath = new Image(mapImages, this);
 	_imgBridge = new Image(mapImages, this);
 
-	_mapButtonList.push_back(_event->createButton( 8,  _utils->vgaScaleY(105), 0, VKEY_LTARROW, new Image(mapImages, this), new Image(mapImages, this)));	// back
-	_mapButtonList.push_back(_event->createButton( 55, _utils->vgaScaleY(105), 1, VKEY_UPARROW, new Image(mapImages, this), new Image(mapImages, this)));	// up
-	_mapButtonList.push_back(_event->createButton(101, _utils->vgaScaleY(105), 2, VKEY_DNARROW, new Image(mapImages, this), new Image(mapImages, this)));	// down
+	_mapButtonList.push_back(_event->createButton( 8,  _utils->vgaScaleY(105), 0, Common::KEYCODE_ESCAPE, new Image(mapImages, this), new Image(mapImages, this)));	// back
+	_mapButtonList.push_back(_event->createButton( 55, _utils->vgaScaleY(105), 1, Common::KEYCODE_UP,     new Image(mapImages, this), new Image(mapImages, this)));	// up
+	_mapButtonList.push_back(_event->createButton(101, _utils->vgaScaleY(105), 2, Common::KEYCODE_DOWN,   new Image(mapImages, this), new Image(mapImages, this)));	// down
 
 	delete mapImages;
 
diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp
index 81d6bea..e15561d 100644
--- a/engines/lab/special.cpp
+++ b/engines/lab/special.cpp
@@ -128,9 +128,9 @@ void LabEngine::loadJournalData() {
 	_journalTextTitle = _resource->getText("Lab:Rooms/jt");
 
 	Common::File *journalFile = _resource->openDataFile("P:JImage");
-	_journalButtonList.push_back(_event->createButton( 80, _utils->vgaScaleY(162) + _utils->svgaCord(1), 0, VKEY_LTARROW, new Image(journalFile, this), new Image(journalFile, this)));	// back
-	_journalButtonList.push_back(_event->createButton(194, _utils->vgaScaleY(162) + _utils->svgaCord(1), 2,            0, new Image(journalFile, this), new Image(journalFile, this)));	// cancel
-	_journalButtonList.push_back(_event->createButton(144, _utils->vgaScaleY(164) - _utils->svgaCord(1), 1, VKEY_RTARROW, new Image(journalFile, this), new Image(journalFile, this)));	// forward
+	_journalButtonList.push_back(_event->createButton( 80, _utils->vgaScaleY(162) + _utils->svgaCord(1), 0,  Common::KEYCODE_LEFT,   new Image(journalFile, this), new Image(journalFile, this)));	// back
+	_journalButtonList.push_back(_event->createButton(194, _utils->vgaScaleY(162) + _utils->svgaCord(1), 2,  Common::KEYCODE_ESCAPE, new Image(journalFile, this), new Image(journalFile, this)));	// cancel
+	_journalButtonList.push_back(_event->createButton(144, _utils->vgaScaleY(164) - _utils->svgaCord(1), 1,  Common::KEYCODE_RIGHT,  new Image(journalFile, this), new Image(journalFile, this)));	// forward
 	delete journalFile;
 
 	_anim->_noPalChange = true;






More information about the Scummvm-git-logs mailing list