2011-06-10 05:45:18 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on original Soltys source code
|
|
|
|
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
|
|
|
|
*/
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#include "cge/general.h"
|
|
|
|
#include "cge/text.h"
|
|
|
|
#include "cge/talk.h"
|
|
|
|
#include "cge/game.h"
|
|
|
|
#include "cge/snail.h"
|
2011-06-19 22:13:41 +00:00
|
|
|
#include "cge/cge_main.h"
|
2011-09-11 12:19:46 +00:00
|
|
|
#include "common/str.h"
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
namespace CGE {
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
Text *_text;
|
|
|
|
Talk *_talk = NULL;
|
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
Text::Text(CGEEngine *vm, const char *fname) : _vm(vm) {
|
2011-07-30 22:52:35 +00:00
|
|
|
mergeExt(_fileName, fname, kSayExt);
|
2011-09-09 16:24:11 +00:00
|
|
|
if (!_cat->exist(_fileName))
|
2011-07-03 09:28:22 +00:00
|
|
|
error("No talk (%s)\n", _fileName);
|
2011-09-11 12:19:46 +00:00
|
|
|
int16 txtCount = count() + 1;
|
|
|
|
warning("Number of texts: %d", txtCount);
|
2011-07-03 09:28:22 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
_cache = new Handler[txtCount];
|
|
|
|
for (_size = 0; _size < txtCount; _size++) {
|
2011-07-03 09:28:22 +00:00
|
|
|
_cache[_size]._ref = 0;
|
2011-07-30 22:52:35 +00:00
|
|
|
_cache[_size]._text = NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-09-11 12:19:46 +00:00
|
|
|
load();
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
Text::~Text() {
|
|
|
|
clear();
|
|
|
|
delete[] _cache;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
int16 Text::count() {
|
|
|
|
EncryptedStream tf = _fileName;
|
2011-08-19 22:23:45 +00:00
|
|
|
if (tf._error)
|
2011-09-11 12:19:46 +00:00
|
|
|
return NULL;
|
2011-08-19 22:23:45 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
Common::String line;
|
|
|
|
char tmpStr[kLineMax + 1];
|
|
|
|
int n, count = 0;
|
2011-08-19 22:23:45 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
for (line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) {
|
|
|
|
n = line.size();
|
2011-08-19 22:23:45 +00:00
|
|
|
char *s;
|
2011-09-11 12:19:46 +00:00
|
|
|
|
|
|
|
strcpy(tmpStr, line.c_str());
|
|
|
|
if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL)
|
2011-08-19 22:23:45 +00:00
|
|
|
continue;
|
2011-09-05 22:16:07 +00:00
|
|
|
if (!isdigit(*s))
|
2011-08-19 22:23:45 +00:00
|
|
|
continue;
|
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2011-08-19 22:23:45 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
void Text::clear() {
|
|
|
|
for (Handler *p = _cache, *q = p + _size; p < q; p++) {
|
|
|
|
if (p->_ref) {
|
|
|
|
p->_ref = 0;
|
|
|
|
delete[] p->_text;
|
|
|
|
p->_text = NULL;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
void Text::load() {
|
|
|
|
EncryptedStream tf = _fileName;
|
|
|
|
assert(!tf._error);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
Common::String line;
|
|
|
|
char tmpStr[kLineMax + 1];
|
|
|
|
int idx;
|
2011-08-19 14:04:10 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
for (idx = 0, line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) {
|
|
|
|
int n = line.size();
|
2011-08-19 14:04:10 +00:00
|
|
|
char *s;
|
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
strcpy(tmpStr, line.c_str());
|
|
|
|
if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL)
|
2011-08-19 14:04:10 +00:00
|
|
|
continue;
|
2011-09-05 22:16:07 +00:00
|
|
|
if (!isdigit(*s))
|
2011-08-19 14:04:10 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int r = atoi(s);
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-08-19 14:04:10 +00:00
|
|
|
s += strlen(s);
|
2011-09-11 12:19:46 +00:00
|
|
|
if (s < tmpStr + n)
|
2011-08-19 14:04:10 +00:00
|
|
|
++s;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
_cache[idx]._ref = r;
|
|
|
|
_cache[idx]._text = new char[strlen(s) + 1];
|
|
|
|
strcpy(_cache[idx]._text, s);
|
|
|
|
idx++;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
char *Text::getText(int ref) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int i;
|
2011-09-11 12:19:46 +00:00
|
|
|
for (i = 0; (i < _size) && (_cache[i]._ref != ref); i++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (i < _size)
|
2011-07-30 22:52:35 +00:00
|
|
|
return _cache[i]._text;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-09-11 12:19:46 +00:00
|
|
|
warning("getText: Unable to find ref %d", ref);
|
|
|
|
return NULL;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
void Text::say(const char *text, Sprite *spr) {
|
2011-07-03 09:28:22 +00:00
|
|
|
killText();
|
2011-07-30 22:52:35 +00:00
|
|
|
_talk = new Talk(_vm, text, kTBRound);
|
2011-08-19 14:04:10 +00:00
|
|
|
if (!_talk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool east = spr->_flags._east;
|
|
|
|
int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2);
|
|
|
|
int y = spr->_y + 2;
|
|
|
|
Sprite *spike = new Spike(_vm);
|
|
|
|
uint16 sw = spike->_w;
|
|
|
|
|
|
|
|
if (east) {
|
|
|
|
if (x + sw + kTextRoundCorner + 5 >= kScrWidth)
|
|
|
|
east = false;
|
|
|
|
} else {
|
|
|
|
if (x <= 5 + kTextRoundCorner + sw)
|
|
|
|
east = true;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-08-19 14:04:10 +00:00
|
|
|
x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw);
|
|
|
|
if (spr->_ref == 1)
|
|
|
|
x += ((east) ? -10 : 10); // Hero
|
|
|
|
|
|
|
|
_talk->_flags._kill = true;
|
|
|
|
_talk->_flags._bDel = true;
|
|
|
|
_talk->setName(_text->getText(kSayName));
|
|
|
|
_talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1);
|
|
|
|
_talk->_z = 125;
|
|
|
|
_talk->_ref = kSayRef;
|
|
|
|
|
|
|
|
spike->gotoxy(x, _talk->_y + _talk->_h - 1);
|
|
|
|
spike->_z = 126;
|
|
|
|
spike->_flags._slav = true;
|
|
|
|
spike->_flags._kill = true;
|
|
|
|
spike->setName(_text->getText(kSayName));
|
|
|
|
spike->step(east);
|
|
|
|
spike->_ref = kSayRef;
|
|
|
|
|
|
|
|
_vga->_showQ->insert(_talk, _vga->_showQ->last());
|
|
|
|
_vga->_showQ->insert(spike, _vga->_showQ->last());
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
void CGEEngine::inf(const char *text) {
|
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::inf(%s)", text);
|
2011-07-19 05:13:41 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
killText();
|
2011-07-30 22:52:35 +00:00
|
|
|
_talk = new Talk(this, text, kTBRect);
|
2011-08-19 14:04:10 +00:00
|
|
|
if (!_talk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_talk->_flags._kill = true;
|
|
|
|
_talk->_flags._bDel = true;
|
|
|
|
_talk->setName(_text->getText(kInfName));
|
|
|
|
_talk->center();
|
|
|
|
_talk->gotoxy(_talk->_x, _talk->_y - 20);
|
|
|
|
_talk->_z = 126;
|
|
|
|
_talk->_ref = kInfRef;
|
|
|
|
_vga->_showQ->insert(_talk, _vga->_showQ->last());
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:33:39 +00:00
|
|
|
void Text::sayTime(Sprite *spr) {
|
|
|
|
TimeDate curTime;
|
|
|
|
_vm->_system->getTimeAndDate(curTime);
|
2011-08-19 14:04:10 +00:00
|
|
|
|
|
|
|
char t[6];
|
2011-08-13 07:33:39 +00:00
|
|
|
sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min);
|
|
|
|
say(t, spr);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
void killText() {
|
2011-08-19 14:04:10 +00:00
|
|
|
if (!_talk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_snail_->addCom(kSnKill, -1, 0, _talk);
|
|
|
|
_talk = NULL;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
} // End of namespace CGE
|