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

dreammaster dreammaster at scummvm.org
Sat Aug 8 14:46:35 CEST 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:
bb252129b6 SHERLOCK: RT: Implementing password entry window


Commit: bb252129b61ab2eb2b3aa84b1afa8ed1f20d7b98
    https://github.com/scummvm/scummvm/commit/bb252129b61ab2eb2b3aa84b1afa8ed1f20d7b98
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-08-08T08:45:41-04:00

Commit Message:
SHERLOCK: RT: Implementing password entry window

Changed paths:
  A engines/sherlock/tattoo/widget_password.cpp
  A engines/sherlock/tattoo/widget_password.h
    engines/sherlock/module.mk
    engines/sherlock/tattoo/tattoo_fixed_text.cpp
    engines/sherlock/tattoo/tattoo_fixed_text.h
    engines/sherlock/tattoo/tattoo_talk.cpp
    engines/sherlock/tattoo/tattoo_talk.h
    engines/sherlock/tattoo/widget_talk.cpp
    engines/sherlock/tattoo/widget_talk.h
    engines/sherlock/user_interface.h



diff --git a/engines/sherlock/module.mk b/engines/sherlock/module.mk
index 9e3fde0..7fa7896 100644
--- a/engines/sherlock/module.mk
+++ b/engines/sherlock/module.mk
@@ -39,6 +39,7 @@ MODULE_OBJS = \
 	tattoo/widget_inventory.o \
 	tattoo/widget_lab.o \
 	tattoo/widget_options.o \
+	tattoo/widget_password.o \
 	tattoo/widget_quit.o \
 	tattoo/widget_talk.o \
 	tattoo/widget_text.o \
diff --git a/engines/sherlock/tattoo/tattoo_fixed_text.cpp b/engines/sherlock/tattoo/tattoo_fixed_text.cpp
index 76e7b38..c9345e4 100644
--- a/engines/sherlock/tattoo/tattoo_fixed_text.cpp
+++ b/engines/sherlock/tattoo/tattoo_fixed_text.cpp
@@ -104,7 +104,9 @@ static const char *const FIXED_TEXT_ENGLISH[] = {
 	"Are you sure you",
 	"wish to Quit ?",
 	"Yes",
-	"No"
+	"No",
+	"Enter Password",
+	"Going East"
 };
 
 static const char *const FIXED_TEXT_GERMAN[] = {
@@ -183,7 +185,9 @@ static const char *const FIXED_TEXT_GERMAN[] = {
 	"Spiel beenden? ",
 	"Sind Sie sicher ?",
 	"Ja",
-	"Nein"
+	"Nein",
+	"Pacwort eingeben",
+	"Going East"
 };
 
 TattooFixedText::TattooFixedText(SherlockEngine *vm) : FixedText(vm) {
diff --git a/engines/sherlock/tattoo/tattoo_fixed_text.h b/engines/sherlock/tattoo/tattoo_fixed_text.h
index 2052b34..3f43678 100644
--- a/engines/sherlock/tattoo/tattoo_fixed_text.h
+++ b/engines/sherlock/tattoo/tattoo_fixed_text.h
@@ -104,7 +104,9 @@ enum FixedTextId {
 	kFixedText_AreYouSureYou,
 	kFixedText_WishToQuit,
 	kFixedText_Yes,
-	kFixedText_No
+	kFixedText_No,
+	kFixedText_EnterPassword,
+	kFixedText_CorrectPassword
 };
 
 class TattooFixedText: public FixedText {
diff --git a/engines/sherlock/tattoo/tattoo_talk.cpp b/engines/sherlock/tattoo/tattoo_talk.cpp
index 24b46bf..ddd863f 100644
--- a/engines/sherlock/tattoo/tattoo_talk.cpp
+++ b/engines/sherlock/tattoo/tattoo_talk.cpp
@@ -111,7 +111,7 @@ const byte TATTOO_OPCODES[] = {
 
 /*----------------------------------------------------------------*/
 
-TattooTalk::TattooTalk(SherlockEngine *vm) : Talk(vm), _talkWidget(vm) {
+TattooTalk::TattooTalk(SherlockEngine *vm) : Talk(vm), _talkWidget(vm), _passwordWidget(vm) {
 	static OpcodeMethod OPCODE_METHODS[] = {
 		(OpcodeMethod)&TattooTalk::cmdSwitchSpeaker,
 
@@ -379,7 +379,11 @@ OpcodeReturn TattooTalk::cmdNPCLabelSet(const byte *&str) {
 	return RET_SUCCESS;
 }
 
-OpcodeReturn TattooTalk::cmdPassword(const byte *&str) { error("TODO: script opcode (cmdPassword)"); }
+OpcodeReturn TattooTalk::cmdPassword(const byte *&str) {
+	_vm->_ui->clearWindow();
+	_passwordWidget.show();
+	return RET_EXIT;
+}
 
 OpcodeReturn TattooTalk::cmdPlaySong(const byte *&str) { 
 	Music &music = *_vm->_music;
diff --git a/engines/sherlock/tattoo/tattoo_talk.h b/engines/sherlock/tattoo/tattoo_talk.h
index cd96183..f84bcee 100644
--- a/engines/sherlock/tattoo/tattoo_talk.h
+++ b/engines/sherlock/tattoo/tattoo_talk.h
@@ -30,6 +30,7 @@
 #include "common/stream.h"
 #include "common/stack.h"
 #include "sherlock/talk.h"
+#include "sherlock/tattoo/widget_password.h"
 #include "sherlock/tattoo/widget_talk.h"
 
 namespace Sherlock {
@@ -42,6 +43,7 @@ class TattooTalk : public Talk {
 	friend class WidgetTalk;
 private:
 	WidgetTalk _talkWidget;
+	WidgetPassword _passwordWidget;
 
 	OpcodeReturn cmdCallTalkFile(const byte *&str);
 	OpcodeReturn cmdSwitchSpeaker(const byte *&str);
diff --git a/engines/sherlock/tattoo/widget_password.cpp b/engines/sherlock/tattoo/widget_password.cpp
new file mode 100644
index 0000000..4bea26a
--- /dev/null
+++ b/engines/sherlock/tattoo/widget_password.cpp
@@ -0,0 +1,220 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "sherlock/tattoo/widget_password.h"
+#include "sherlock/tattoo/tattoo.h"
+#include "sherlock/tattoo/tattoo_fixed_text.h"
+#include "sherlock/tattoo/tattoo_user_interface.h"
+
+namespace Sherlock {
+
+namespace Tattoo {
+
+WidgetPassword::WidgetPassword(SherlockEngine *vm) : WidgetBase(vm) {
+	_blinkFlag = false;
+	_blinkCounter = 0;
+	_index = 0;
+	Common::fill(&_password[0], &_password[MAX_PASSWORD], ' ');
+	_password[MAX_PASSWORD] = '\0';
+	_cursorColor = 192;
+	_insert = true;
+}
+
+void WidgetPassword::show() {
+	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
+	ImageFile &images = *ui._interfaceImages;
+
+	// Set the up window to be centered on the screen
+	_bounds = Common::Rect(_surface.widestChar() * 20 + 6, (_surface.fontHeight() + 7) * 2 + 3);
+	_bounds.moveTo(SHERLOCK_SCREEN_WIDTH / 2 - _bounds.width() / 2, SHERLOCK_SCREEN_HEIGHT / 2 - _bounds.height() / 2);
+
+	// Create the surface
+	_surface.create(_bounds.width(), _bounds.height());
+	_surface.fill(TRANSPARENCY);
+	makeInfoArea();
+
+	// Draw the header area
+	_surface.writeString(FIXED(EnterPassword), Common::Point((_bounds.width() - _surface.stringWidth(FIXED(EnterPassword))) / 2, 5), INFO_TOP);
+	_surface.hLine(3, _surface.fontHeight() + 7, _bounds.width() - 4, INFO_TOP);
+	_surface.hLine(3, _surface.fontHeight() + 8, _bounds.width() - 4, INFO_MIDDLE);
+	_surface.hLine(3, _surface.fontHeight() + 9, _bounds.width() - 4, INFO_BOTTOM);
+	_surface.transBlitFrom(images[4], Common::Point(0, _surface.fontHeight() + 7 - 1));
+	_surface.transBlitFrom(images[5], Common::Point(_bounds.width() - images[5]._width, _surface.fontHeight() + 7 - 1));
+
+	// Set the password entry data
+	_cursorPos = Common::Point(_surface.widestChar(), _surface.fontHeight() + 12);
+	Common::fill(&_password[0], &_password[MAX_PASSWORD], ' ');
+	_password[MAX_PASSWORD] = '\0';
+	_index = 0;
+	_cursorColor = 192;
+	_insert = true;
+
+	// Show the dialog
+	ui._menuMode = PASSWORD_MODE;
+	summonWindow();
+}
+
+void WidgetPassword::handleEvents() {
+	Events &events = *_vm->_events;
+	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
+	Common::Point mousePos = events.mousePos();
+	const Common::KeyCode &keycode = ui._keyState.keycode;
+	int width = _surface.charWidth(_password[_index]);
+
+	if (!keycode) {
+		// Nothing entered, so keep blinking the cursor
+		if (--_blinkCounter < 0) {
+			_blinkCounter = 3;
+			_blinkFlag = !_blinkFlag;
+
+			byte color, textColor;
+			if (_blinkFlag) {
+				textColor = 236;
+				color = _cursorColor;
+			} else {
+				textColor = COMMAND_HIGHLIGHTED;
+				color = TRANSPARENCY;
+			}
+
+			// Draw the cursor and the character it's over
+			_surface.fillRect(Common::Rect(_cursorPos.x, _cursorPos.y, _cursorPos.x + width, _cursorPos.y + _surface.fontHeight()), color);
+			if (_password[_index] != ' ')
+				_surface.writeString(Common::String::format("%c", _password[_index]), _cursorPos, textColor);
+		}
+	} else if (keycode == Common::KEYCODE_BACKSPACE && _index) {
+		_cursorPos.x -= _surface.charWidth(_password[_index - 1]);
+
+		if (_insert) {
+			Common::copy_backward(&_password[_index], &_password[MAX_PASSWORD], &_password[_index - 1]);
+			_password[MAX_PASSWORD - 1] = ' ';
+		} else {
+			_password[_index - 1] = ' ';
+		}
+
+		// Redraw the text
+		--_index;
+		_surface.fillRect(Common::Rect(_cursorPos.x, _cursorPos.y, _bounds.width() - 9, _cursorPos.y +
+			_surface.fontHeight() - 1), TRANSPARENCY);
+		_surface.writeString(&_password[_index], _cursorPos, COMMAND_HIGHLIGHTED);
+	} else if ((keycode == Common::KEYCODE_LEFT && _index > 0)
+			|| (keycode == Common::KEYCODE_RIGHT && _index < (MAX_PASSWORD - 1) && _cursorPos.x < (_bounds.width() - _surface.widestChar() - 3))
+			|| (keycode == Common::KEYCODE_HOME && _index > 0)
+			|| (keycode == Common::KEYCODE_END)) {
+		// Restore character the cursor was previously over
+		_surface.fillRect(Common::Rect(_cursorPos.x, _cursorPos.y, _cursorPos.x + width, _cursorPos.y + _surface.fontHeight()), COMMAND_HIGHLIGHTED);
+		if (_password[_index] != ' ')
+			_surface.writeString(Common::String::format("%c", _password[_index]), _cursorPos, COMMAND_HIGHLIGHTED);
+		
+		switch (keycode) {
+		case Common::KEYCODE_LEFT:
+			_cursorPos.x -= _surface.charWidth(_password[_index - 1]);
+			--_index;
+			break;
+		case Common::KEYCODE_RIGHT:
+			_cursorPos.x += _surface.charWidth(_password[_index]);
+			++_index;
+			break;
+		case Common::KEYCODE_HOME:
+			_cursorPos.x = _surface.widestChar();
+			_index = 0;
+			break;
+		case Common::KEYCODE_END:
+			_cursorPos.x = _surface.stringWidth(_password) + _surface.widestChar();
+			_index = MAX_PASSWORD;
+			
+			while (_index > 0 && _password[_index - 1] == ' ') {
+				_cursorPos.x -= _surface.charWidth(_password[_index - 1]);
+				--_index;
+			}
+			break;
+		default:
+			break;
+		}
+	} else if (keycode == Common::KEYCODE_INSERT) {
+		_insert = !_insert;
+		_cursorColor = _insert ? 192 : 200;
+	} else if (keycode == Common::KEYCODE_DELETE) {
+		if (_index < (MAX_PASSWORD - 1))
+			Common::copy(&_password[_index + 1], &_password[MAX_PASSWORD], &_password[_index]);
+		_password[MAX_PASSWORD - 1] = ' ';
+
+		// Redraw the text
+		_surface.fillRect(Common::Rect(_cursorPos.x, _cursorPos.y, _bounds.width() - 9, _cursorPos.y +
+			_surface.fontHeight() - 1), TRANSPARENCY);
+		_surface.writeString(&_password[_index], _cursorPos, COMMAND_HIGHLIGHTED);
+	} else if (keycode == Common::KEYCODE_RETURN || keycode == Common::KEYCODE_ESCAPE) {
+		close();
+		return;
+	} else if (((ui._keyState.ascii >= ' ' && ui._keyState.ascii < 169) || ui._keyState.ascii == 225)
+			&& (_index < MAX_PASSWORD)) {
+		if (_cursorPos.x + _surface.charWidth(ui._keyState.ascii) < _bounds.width() - _surface.widestChar() - 3) {
+			if (_insert)
+				Common::copy_backward(&_password[_index], &_password[MAX_PASSWORD] - 1, &_password[_index + 1]);
+			_password[_index] = ui._keyState.ascii;
+
+			// Redraw the text
+			_surface.fillRect(Common::Rect(_cursorPos.x, _cursorPos.y, _bounds.width() - 9, _cursorPos.y +
+				_surface.fontHeight() - 1), TRANSPARENCY);
+			_surface.writeString(&_password[_index], _cursorPos, COMMAND_HIGHLIGHTED);
+
+			_cursorPos.x += _surface.charWidth(ui._keyState.ascii);
+			++_index;
+		}
+	}
+
+	// Also handle clicking outside the window to abort
+	if (events._firstPress && !_bounds.contains(mousePos))
+		_outsideMenu = true;
+
+	if ((events._released || events._rightReleased) && _outsideMenu && !_bounds.contains(mousePos)) {
+		close();
+	}
+}
+
+void WidgetPassword::close() {
+	Talk &talk = *_vm->_talk;
+	
+	banishWindow();
+	if (talk._talkToAbort)
+		return;
+
+	// Get the password they entered, stripping off trailing spaces
+	Common::String password(_password);
+	while (password.hasSuffix(" "))
+		password.deleteLastChar();
+
+	// See if they entered the correct password
+	Common::String correct1 = FIXED(CorrectPassword);
+	Common::String correct2 = Common::String::format("%s?", FIXED(CorrectPassword));
+	Common::String correct3 = Common::String::format("%s ?", FIXED(CorrectPassword));
+
+	if (!password.compareToIgnoreCase(correct1) || !password.compareToIgnoreCase(correct2)
+			|| !password.compareToIgnoreCase(correct3))
+		// They got it correct
+		_vm->setFlags(149);
+
+	talk.talkTo("LASC52P");
+}
+
+} // End of namespace Tattoo
+
+} // End of namespace Sherlock
diff --git a/engines/sherlock/tattoo/widget_password.h b/engines/sherlock/tattoo/widget_password.h
new file mode 100644
index 0000000..9c842ca
--- /dev/null
+++ b/engines/sherlock/tattoo/widget_password.h
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SHERLOCK_TATTOO_WIDGET_PASSWORD_H
+#define SHERLOCK_TATTOO_WIDGET_PASSWORD_H
+
+#include "common/scummsys.h"
+#include "sherlock/tattoo/widget_base.h"
+
+namespace Sherlock {
+
+#define MAX_PASSWORD 40
+
+class SherlockEngine;
+
+namespace Tattoo {
+
+class WidgetPassword: public WidgetBase {
+private:
+	Common::Point _cursorPos;
+	char _password[MAX_PASSWORD + 1];
+	int _index;
+	bool _blinkFlag;
+	int _blinkCounter;
+	byte _cursorColor;
+	bool _insert;
+
+	/**
+	 * Close the window and check if the entered password is correct
+	 */
+	void close();
+public:
+	WidgetPassword(SherlockEngine *vm);
+	virtual ~WidgetPassword() {}
+
+	/**
+	 * Show the password entry window
+	 */
+	void show();
+
+	/**
+	 * Handle event processing
+	 */
+	virtual void handleEvents();
+};
+
+} // End of namespace Tattoo
+
+} // End of namespace Sherlock
+
+#endif
diff --git a/engines/sherlock/tattoo/widget_talk.cpp b/engines/sherlock/tattoo/widget_talk.cpp
index dfb2360..a5afa0c 100644
--- a/engines/sherlock/tattoo/widget_talk.cpp
+++ b/engines/sherlock/tattoo/widget_talk.cpp
@@ -344,8 +344,10 @@ void WidgetTalk::handleEvents() {
 									people[idx].pullNPCPath();
 						}
 
-						ui.banishWindow();
-						ui._menuMode = scene._labTableScene ? LAB_MODE : STD_MODE;
+						if (ui._menuMode != PASSWORD_MODE) {
+							ui.banishWindow();
+							ui._menuMode = scene._labTableScene ? LAB_MODE : STD_MODE;
+						}
 						break;
 					}
 				} else {
diff --git a/engines/sherlock/tattoo/widget_talk.h b/engines/sherlock/tattoo/widget_talk.h
index 1dbbc22..f5e939b 100644
--- a/engines/sherlock/tattoo/widget_talk.h
+++ b/engines/sherlock/tattoo/widget_talk.h
@@ -52,6 +52,9 @@ private:
 	int _talkTextX;
 	uint32 _dialogTimer;
 
+	/**
+	 * Get the needed size for a talk window
+	 */
 	void getTalkWindowSize();
 
 	/**
diff --git a/engines/sherlock/user_interface.h b/engines/sherlock/user_interface.h
index 799912f..c16c9f5 100644
--- a/engines/sherlock/user_interface.h
+++ b/engines/sherlock/user_interface.h
@@ -56,7 +56,8 @@ enum MenuMode {
 	VERB_MODE		= 22,
 	OPTION_MODE		= 23,
 	QUIT_MODE		= 24,
-	FOOLSCAP_MODE	= 25
+	FOOLSCAP_MODE	= 25,
+	PASSWORD_MODE	= 26
 };
 
 class UserInterface {






More information about the Scummvm-git-logs mailing list