aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2009-12-11 09:41:27 +0000
committerPaul Gilbert2009-12-11 09:41:27 +0000
commit724d698a05bfda015e428ffa3ac4094ecbc1b4c0 (patch)
treed70e3c7e8c258915385023f1d15f7aa352d4a7bd /engines
parent6b44a09a528ae219e6b3bf4d316a72ca067a7c9c (diff)
downloadscummvm-rg350-724d698a05bfda015e428ffa3ac4094ecbc1b4c0.tar.gz
scummvm-rg350-724d698a05bfda015e428ffa3ac4094ecbc1b4c0.tar.bz2
scummvm-rg350-724d698a05bfda015e428ffa3ac4094ecbc1b4c0.zip
Beginnings of a dialog display class
svn-id: r46330
Diffstat (limited to 'engines')
-rw-r--r--engines/m4/console.cpp27
-rw-r--r--engines/m4/console.h1
-rw-r--r--engines/m4/dialogs.cpp165
-rw-r--r--engines/m4/dialogs.h55
-rw-r--r--engines/m4/globals.cpp10
-rw-r--r--engines/m4/globals.h1
-rw-r--r--engines/m4/module.mk1
-rw-r--r--engines/m4/scene.cpp7
8 files changed, 267 insertions, 0 deletions
diff --git a/engines/m4/console.cpp b/engines/m4/console.cpp
index 9744741a52..a6a757d2ab 100644
--- a/engines/m4/console.cpp
+++ b/engines/m4/console.cpp
@@ -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 @@ Console::Console(M4Engine *vm) : GUI::Debugger() {
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 @@ bool Console::cmdObject(int argc, const char **argv) {
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
diff --git a/engines/m4/console.h b/engines/m4/console.h
index f34fa627b8..4d9d008b2f 100644
--- a/engines/m4/console.h
+++ b/engines/m4/console.h
@@ -54,6 +54,7 @@ private:
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;
diff --git a/engines/m4/dialogs.cpp b/engines/m4/dialogs.cpp
new file mode 100644
index 0000000000..d4b341f891
--- /dev/null
+++ b/engines/m4/dialogs.cpp
@@ -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
diff --git a/engines/m4/dialogs.h b/engines/m4/dialogs.h
new file mode 100644
index 0000000000..f25821e3a9
--- /dev/null
+++ b/engines/m4/dialogs.h
@@ -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
diff --git a/engines/m4/globals.cpp b/engines/m4/globals.cpp
index 64681b3e4d..b21c17edd8 100644
--- a/engines/m4/globals.cpp
+++ b/engines/m4/globals.cpp
@@ -369,6 +369,15 @@ void Globals::loadMadsObjects() {
_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 @@ const char *Globals::loadMessage(uint index) {
if (buffer[i] == '\0') buffer[i] = '\n';
_vm->res()->toss("messages.dat");
+ delete compData;
return (char*)buffer;
}
diff --git a/engines/m4/globals.h b/engines/m4/globals.h
index 36b5a28b61..324ad13182 100644
--- a/engines/m4/globals.h
+++ b/engines/m4/globals.h
@@ -224,6 +224,7 @@ public:
void loadMadsMessagesInfo();
uint32 getMessagesSize() { return _madsMessages.size(); }
+ int messageIndexOf(uint32 messageId);
const char *loadMessage(uint index);
void loadMadsObjects();
diff --git a/engines/m4/module.mk b/engines/m4/module.mk
index 2f5756a12f..31746be5af 100644
--- a/engines/m4/module.mk
+++ b/engines/m4/module.mk
@@ -8,6 +8,7 @@ MODULE_OBJS = \
console.o \
converse.o \
detection.o \
+ dialogs.o \
events.o \
font.o \
globals.o \
diff --git a/engines/m4/scene.cpp b/engines/m4/scene.cpp
index 3d99e62961..e233680493 100644
--- a/engines/m4/scene.cpp
+++ b/engines/m4/scene.cpp
@@ -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 @@ bool Scene::onEvent(M4EventType eventType, int param1, int x, int y, bool &captu
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: