[Scummvm-cvs-logs] SF.net SVN: scummvm:[46330] scummvm/trunk/engines/m4

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Fri Dec 11 10:41:27 CET 2009


Revision: 46330
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46330&view=rev
Author:   dreammaster
Date:     2009-12-11 09:41:27 +0000 (Fri, 11 Dec 2009)

Log Message:
-----------
Beginnings of a dialog display class

Modified Paths:
--------------
    scummvm/trunk/engines/m4/console.cpp
    scummvm/trunk/engines/m4/console.h
    scummvm/trunk/engines/m4/globals.cpp
    scummvm/trunk/engines/m4/globals.h
    scummvm/trunk/engines/m4/module.mk
    scummvm/trunk/engines/m4/scene.cpp

Added Paths:
-----------
    scummvm/trunk/engines/m4/dialogs.cpp
    scummvm/trunk/engines/m4/dialogs.h

Modified: scummvm/trunk/engines/m4/console.cpp
===================================================================
--- scummvm/trunk/engines/m4/console.cpp	2009-12-10 21:40:38 UTC (rev 46329)
+++ scummvm/trunk/engines/m4/console.cpp	2009-12-11 09:41:27 UTC (rev 46330)
@@ -25,6 +25,7 @@
 
 #include "m4/m4.h"
 #include "m4/console.h"
+#include "m4/dialogs.h"
 #include "m4/scene.h"
 #include "m4/staticres.h"
 
@@ -49,6 +50,7 @@
 	DCmd_Register("animview",		WRAP_METHOD(Console, cmdShowAnimview));
 	DCmd_Register("anim",			WRAP_METHOD(Console, cmdPlayAnimation));
 	DCmd_Register("object",			WRAP_METHOD(Console, cmdObject));
+	DCmd_Register("message",		WRAP_METHOD(Console, cmdMessage));
 }
 
 Console::~Console() {
@@ -356,4 +358,29 @@
 	return true;
 }
 
+bool Console::cmdMessage(int argc, const char **argv) {
+	VALIDATE_MADS;
+
+	if (argc == 1)
+		DebugPrintf("message 'objnum'\n");
+	else {
+		int messageId = strToInt(argv[1]);
+		int idx = _vm->_globals->messageIndexOf(messageId);
+		if (idx == -1)
+			DebugPrintf("Unknown message");
+		else
+		{
+			const char *msg = _vm->_globals->loadMessage(idx);
+			Dialog *dlg = new Dialog(_vm, msg);
+
+			_vm->_viewManager->addView(dlg);
+			_vm->_viewManager->moveToFront(dlg);
+
+			return false;
+		}
+	}
+
+	return true;
+}
+
 } // End of namespace M4

Modified: scummvm/trunk/engines/m4/console.h
===================================================================
--- scummvm/trunk/engines/m4/console.h	2009-12-10 21:40:38 UTC (rev 46329)
+++ scummvm/trunk/engines/m4/console.h	2009-12-11 09:41:27 UTC (rev 46330)
@@ -54,6 +54,7 @@
 	bool cmdShowAnimview(int argc, const char **argv);
 	bool cmdPlayAnimation(int argc, const char **argv);
 	bool cmdObject(int argc, const char **argv);
+	bool cmdMessage(int argc, const char **argv);
 
 private:
 	M4Engine *_vm;

Added: scummvm/trunk/engines/m4/dialogs.cpp
===================================================================
--- scummvm/trunk/engines/m4/dialogs.cpp	                        (rev 0)
+++ scummvm/trunk/engines/m4/dialogs.cpp	2009-12-11 09:41:27 UTC (rev 46330)
@@ -0,0 +1,165 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "m4/dialogs.h"
+#include "common/file.h"
+
+namespace M4 {
+
+static void strToUpper(char *s) {
+	while (*s) {
+		*s = toupper(*s);
+		++s;
+	}
+}
+
+void Dialog::initDialog() {
+
+}
+
+void Dialog::incLine() {
+	++_numLines;
+	assert(++_numLines < 20);
+}
+
+void Dialog::writeChars(const char *line) {
+
+}
+
+void Dialog::addLine(const char *line) {
+
+}
+
+bool Dialog::matchCommand(const char *s1, const char *s2) {
+	return strncmp(s1, s2, strlen(s2)) == 0;
+}
+
+Dialog::Dialog(M4Engine *vm, const char *msgData): View(vm, Common::Rect(100, 80, 220, 140)) {
+	assert(msgData);
+	const char *srcP = msgData;
+	bool skipLine = false;
+	bool initFlag = false;
+	bool cmdFlag = false;
+	bool crFlag = false;
+
+	_dialogTitleId = 0;
+	_numLines = 0;
+	_dialogIndex = 0;
+
+	char dialogLine[256];
+	char cmdText[80];
+	char *lineP = &dialogLine[0];
+	char *cmdP = NULL;
+
+	while (*srcP != '\0') {
+		if (*srcP == '\n') {
+			// Line completed
+			*lineP = '\0';
+			++srcP;
+
+			if (!initFlag) {
+				initDialog();
+				incLine();
+				initFlag = true;
+			} else {
+				writeChars(dialogLine);
+			}
+		} else if (*srcP == '[') {
+			// Start of a command sequence
+			cmdFlag = true;
+			cmdP = &cmdText[0];
+			++srcP;
+			continue;
+		} else if (*srcP == ']') {
+			// End of a command sequence
+			*cmdP = '\0';
+			cmdFlag = false;
+			strToUpper(cmdText);
+
+			if (matchCommand(cmdText, "CENTER"))
+				// Center command
+				skipLine = true;
+			else if (matchCommand(cmdText, "TITLE")) {
+				// Title command
+				int id = atoi(cmdText + 5);
+				if (id > 0) 
+					_dialogTitleId = id;
+			} else if (matchCommand(cmdText, "CR")) {
+				// CR command
+				if (skipLine)
+					crFlag = true;
+				else {
+					initDialog();
+				}
+			} else if (matchCommand(cmdText, "ASK")) {
+				// doAsk();
+			} else if (matchCommand(cmdText, "VERB")) {
+				// Verb/vocab retrieval
+				/*getVocab(); */
+			} else if (matchCommand(cmdText, "INDEX")) {
+				// Index command
+				_dialogIndex = atoi(cmdText + 5);
+			} else if (matchCommand(cmdText, "NOUN")) {
+				// Noun command
+			} else if (matchCommand(cmdText, "SENTENCE")) {
+				// Sentence command
+			} else {
+				error("Unknown dialog command '%s' encountered", cmdText);
+			}
+		}
+
+		if (cmdFlag)
+			*cmdP++ = *srcP;
+		++srcP;
+	}
+
+	if (!skipLine)
+		incLine();
+	draw();
+}
+
+void Dialog::draw() {
+	// TODO: Implement rendering of dialog correctly
+	this->fillRect(Common::Rect(0, 0, width(), height()), 0);
+	_vm->_font->setColors(5, 5, 0xff);
+	_vm->_font->writeString(this, "This will be a dialog", 10, 10, 0, 0);
+}
+
+bool Dialog::onEvent(M4EventType eventType, int param1, int x, int y, bool &captureEvents) {
+	if (_vm->_mouse->getCursorNum() != CURSOR_ARROW)
+		_vm->_mouse->setCursorNum(CURSOR_ARROW);
+
+	captureEvents = true;
+
+	if (eventType == MEVENT_LEFT_CLICK) {
+		captureEvents = false;
+		_vm->_viewManager->deleteView(this);
+	}
+
+	return true;
+}
+
+
+} // End of namespace M4


Property changes on: scummvm/trunk/engines/m4/dialogs.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: scummvm/trunk/engines/m4/dialogs.h
===================================================================
--- scummvm/trunk/engines/m4/dialogs.h	                        (rev 0)
+++ scummvm/trunk/engines/m4/dialogs.h	2009-12-11 09:41:27 UTC (rev 46330)
@@ -0,0 +1,55 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef M4_DIALOGS_H
+#define M4_DIALOGS_H
+
+#include "m4/m4.h"
+#include "m4/viewmgr.h"
+
+namespace M4 {
+
+class Dialog: public View {
+private:
+	int _numLines;
+	int _dialogTitleId;
+	int _dialogIndex;
+
+	void initDialog();
+	void incLine();
+	bool matchCommand(const char *s1, const char *s2);
+	void writeChars(const char *line);
+	void addLine(const char *line);
+	void draw();
+public:
+	Dialog(M4Engine *vm, const char *msgData);
+	virtual ~Dialog() {}
+
+	bool onEvent(M4EventType eventType, int param1, int x, int y, bool &captureEvents);
+};
+
+} // End of namespace M4
+
+#endif


Property changes on: scummvm/trunk/engines/m4/dialogs.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/engines/m4/globals.cpp
===================================================================
--- scummvm/trunk/engines/m4/globals.cpp	2009-12-10 21:40:38 UTC (rev 46329)
+++ scummvm/trunk/engines/m4/globals.cpp	2009-12-11 09:41:27 UTC (rev 46330)
@@ -369,6 +369,15 @@
 	_vm->res()->toss("objects.dat");
 }
 
+int Globals::messageIndexOf(uint32 messageId) {
+	for (uint i = 0; i < _madsMessages.size(); ++i)
+	{
+		if (_madsMessages[i]->id == messageId)
+			return i;
+	}
+	return -1;
+}
+
 const char *Globals::loadMessage(uint index) {
 	if (index > _madsMessages.size() - 1) {
 		warning("Invalid message index: %i", index);
@@ -388,6 +397,7 @@
 		if (buffer[i] == '\0') buffer[i] = '\n';
 
 	_vm->res()->toss("messages.dat");
+	delete compData;
 
 	return (char*)buffer;
 }

Modified: scummvm/trunk/engines/m4/globals.h
===================================================================
--- scummvm/trunk/engines/m4/globals.h	2009-12-10 21:40:38 UTC (rev 46329)
+++ scummvm/trunk/engines/m4/globals.h	2009-12-11 09:41:27 UTC (rev 46330)
@@ -224,6 +224,7 @@
 
 	void loadMadsMessagesInfo();
 	uint32 getMessagesSize() { return _madsMessages.size(); }
+	int messageIndexOf(uint32 messageId);
 	const char *loadMessage(uint index);
 
 	void loadMadsObjects();

Modified: scummvm/trunk/engines/m4/module.mk
===================================================================
--- scummvm/trunk/engines/m4/module.mk	2009-12-10 21:40:38 UTC (rev 46329)
+++ scummvm/trunk/engines/m4/module.mk	2009-12-11 09:41:27 UTC (rev 46330)
@@ -8,6 +8,7 @@
 	console.o \
 	converse.o \
 	detection.o \
+	dialogs.o \
 	events.o \
 	font.o \
 	globals.o \

Modified: scummvm/trunk/engines/m4/scene.cpp
===================================================================
--- scummvm/trunk/engines/m4/scene.cpp	2009-12-10 21:40:38 UTC (rev 46329)
+++ scummvm/trunk/engines/m4/scene.cpp	2009-12-11 09:41:27 UTC (rev 46330)
@@ -25,6 +25,7 @@
 
 #include "common/system.h"
 
+#include "m4/dialogs.h"
 #include "m4/globals.h"
 #include "m4/scene.h"
 #include "m4/events.h"
@@ -555,6 +556,12 @@
 		if (_vm->getGameType() == GType_Burger) {
 			nextCommonCursor();
 			_vm->_interfaceView->_inventory.clearSelected();
+		} else {
+			// ***DEBUG*** - sample dialog display
+			const char *msg = _vm->_globals->loadMessage(10);
+			Dialog *dlg = new Dialog(_vm, msg);
+			_vm->_viewManager->addView(dlg);
+			_vm->_viewManager->moveToFront(dlg);
 		}
 		break;
 	case MEVENT_MOVE:


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