mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 21:31:53 +00:00
Beginnings of a dialog display class
svn-id: r46330
This commit is contained in:
parent
6b44a09a52
commit
724d698a05
@ -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
|
||||
|
@ -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;
|
||||
|
165
engines/m4/dialogs.cpp
Normal file
165
engines/m4/dialogs.cpp
Normal file
@ -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
|
55
engines/m4/dialogs.h
Normal file
55
engines/m4/dialogs.h
Normal file
@ -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
|
@ -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;
|
||||
}
|
||||
|
@ -224,6 +224,7 @@ public:
|
||||
|
||||
void loadMadsMessagesInfo();
|
||||
uint32 getMessagesSize() { return _madsMessages.size(); }
|
||||
int messageIndexOf(uint32 messageId);
|
||||
const char *loadMessage(uint index);
|
||||
|
||||
void loadMadsObjects();
|
||||
|
@ -8,6 +8,7 @@ MODULE_OBJS = \
|
||||
console.o \
|
||||
converse.o \
|
||||
detection.o \
|
||||
dialogs.o \
|
||||
events.o \
|
||||
font.o \
|
||||
globals.o \
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user