2012-03-06 03:34:46 +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.
|
2012-05-11 14:03:59 +00:00
|
|
|
|
2012-03-06 03:34:46 +00:00
|
|
|
* 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.
|
2012-05-11 14:03:59 +00:00
|
|
|
|
2012-03-06 03:34:46 +00:00
|
|
|
* 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 file is based on WME Lite.
|
|
|
|
* http://dead-code.org/redir.php?target=wmelite
|
|
|
|
* Copyright (c) 2011 Jan Nedoma
|
|
|
|
*/
|
|
|
|
|
2012-06-01 23:17:46 +00:00
|
|
|
#include "engines/wintermute/dcgf.h"
|
2012-07-19 17:29:15 +00:00
|
|
|
#include "engines/wintermute/base/BGame.h"
|
|
|
|
#include "engines/wintermute/ad/AdNodeState.h"
|
|
|
|
#include "engines/wintermute/ad/AdEntity.h"
|
|
|
|
#include "engines/wintermute/base/BStringTable.h"
|
|
|
|
#include "engines/wintermute/base/BSprite.h"
|
2012-06-02 00:31:59 +00:00
|
|
|
#include "engines/wintermute/utils/utils.h"
|
2012-07-19 22:45:20 +00:00
|
|
|
#include "engines/wintermute/platform_osystem.h"
|
2012-03-06 03:34:46 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
|
|
|
|
namespace WinterMute {
|
|
|
|
|
|
|
|
IMPLEMENT_PERSISTENT(CAdNodeState, false)
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
CAdNodeState::CAdNodeState(CBGame *inGame): CBBase(inGame) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_name = NULL;
|
|
|
|
_active = false;
|
|
|
|
for (int i = 0; i < 7; i++) _caption[i] = NULL;
|
|
|
|
_alphaColor = 0;
|
|
|
|
_filename = NULL;
|
|
|
|
_cursor = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
CAdNodeState::~CAdNodeState() {
|
2012-04-27 22:00:14 +00:00
|
|
|
delete[] _name;
|
|
|
|
delete[] _filename;
|
|
|
|
delete[] _cursor;
|
|
|
|
_name = NULL;
|
|
|
|
_filename = NULL;
|
|
|
|
_cursor = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
for (int i = 0; i < 7; i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
delete[] _caption[i];
|
|
|
|
_caption[i] = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
void CAdNodeState::setName(const char *name) {
|
2012-04-27 22:00:14 +00:00
|
|
|
delete[] _name;
|
|
|
|
_name = NULL;
|
2012-07-03 04:32:19 +00:00
|
|
|
CBUtils::setString(&_name, name);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-04 11:15:47 +00:00
|
|
|
void CAdNodeState::setFilename(const char *filename) {
|
2012-04-27 22:00:14 +00:00
|
|
|
delete[] _filename;
|
|
|
|
_filename = NULL;
|
2012-07-04 11:15:47 +00:00
|
|
|
CBUtils::setString(&_filename, filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-04 17:23:41 +00:00
|
|
|
void CAdNodeState::setCursor(const char *filename) {
|
2012-04-27 22:00:14 +00:00
|
|
|
delete[] _cursor;
|
|
|
|
_cursor = NULL;
|
2012-07-04 11:15:47 +00:00
|
|
|
CBUtils::setString(&_cursor, filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-18 16:31:56 +00:00
|
|
|
bool CAdNodeState::persist(CBPersistMgr *persistMgr) {
|
2012-07-18 16:25:09 +00:00
|
|
|
persistMgr->transfer(TMEMBER(_gameRef));
|
2012-06-22 11:56:51 +00:00
|
|
|
|
|
|
|
persistMgr->transfer(TMEMBER(_active));
|
|
|
|
persistMgr->transfer(TMEMBER(_name));
|
|
|
|
persistMgr->transfer(TMEMBER(_filename));
|
|
|
|
persistMgr->transfer(TMEMBER(_cursor));
|
|
|
|
persistMgr->transfer(TMEMBER(_alphaColor));
|
|
|
|
for (int i = 0; i < 7; i++) persistMgr->transfer(TMEMBER(_caption[i]));
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-04 17:23:41 +00:00
|
|
|
void CAdNodeState::setCaption(const char *caption, int caseVal) {
|
|
|
|
if (caseVal== 0) caseVal= 1;
|
|
|
|
if (caseVal< 1 || caseVal> 7) return;
|
|
|
|
|
|
|
|
delete[] _caption[caseVal- 1];
|
|
|
|
_caption[caseVal- 1] = new char[strlen(caption) + 1];
|
|
|
|
if (_caption[caseVal- 1]) {
|
|
|
|
strcpy(_caption[caseVal- 1], caption);
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->_stringTable->expand(&_caption[caseVal- 1]);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-04 17:23:41 +00:00
|
|
|
char *CAdNodeState::getCaption(int caseVal) {
|
|
|
|
if (caseVal== 0) caseVal= 1;
|
|
|
|
if (caseVal< 1 || caseVal> 7 || _caption[caseVal- 1] == NULL) return "";
|
|
|
|
else return _caption[caseVal- 1];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-18 16:31:56 +00:00
|
|
|
bool CAdNodeState::transferEntity(CAdEntity *entity, bool includingSprites, bool saving) {
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!entity) return STATUS_FAILED;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// hack!
|
2012-07-18 16:25:09 +00:00
|
|
|
if (this->_gameRef != entity->_gameRef) this->_gameRef = entity->_gameRef;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
if (saving) {
|
2012-03-06 03:34:46 +00:00
|
|
|
for (int i = 0; i < 7; i++) {
|
2012-07-04 17:23:41 +00:00
|
|
|
if (entity->_caption[i]) setCaption(entity->_caption[i], i);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-04 17:23:41 +00:00
|
|
|
if (!entity->_region && entity->_sprite && entity->_sprite->_filename) {
|
|
|
|
if (includingSprites) setFilename(entity->_sprite->_filename);
|
2012-06-25 22:41:05 +00:00
|
|
|
else setFilename("");
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-04 17:23:41 +00:00
|
|
|
if (entity->_cursor && entity->_cursor->_filename) setCursor(entity->_cursor->_filename);
|
|
|
|
_alphaColor = entity->_alphaColor;
|
|
|
|
_active = entity->_active;
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 7; i++) {
|
2012-07-04 17:23:41 +00:00
|
|
|
if (_caption[i]) entity->setCaption(_caption[i], i);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-04 17:23:41 +00:00
|
|
|
if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) {
|
|
|
|
if (!entity->_sprite || !entity->_sprite->_filename || scumm_stricmp(entity->_sprite->_filename, _filename) != 0)
|
|
|
|
entity->setSprite(_filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_cursor) {
|
2012-07-04 17:23:41 +00:00
|
|
|
if (!entity->_cursor || !entity->_cursor->_filename || scumm_stricmp(entity->_cursor->_filename, _cursor) != 0)
|
|
|
|
entity->setCursor(_cursor);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
entity->_active = _active;
|
|
|
|
entity->_alphaColor = _alphaColor;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace WinterMute
|