Permalink
Browse files

STARTREK: Begin implementation of showText.

Also started using SharedPtrs.
  • Loading branch information...
Drenn1 authored and sev- committed Feb 24, 2018
1 parent 8cd5441 commit 2dd96e044f46aed90ed1b6dbc682bc01f43e438c
@@ -31,15 +31,13 @@ static const byte CHARACTER_COUNT = 0x80;
static const byte CHARACTER_SIZE = 0x40;

Font::Font(StarTrekEngine *vm) : _vm(vm) {
Common::SeekableReadStream *fontStream = _vm->openFile("FONT.FNT");
SharedPtr<Common::SeekableReadStream> fontStream = _vm->openFile("FONT.FNT");

_characters = new Character[CHARACTER_COUNT];

for (byte i = 0; i < CHARACTER_COUNT; i++)
fontStream->read(_characters[i].data, CHARACTER_SIZE);

delete fontStream;

#if 0
// Code to dump the font
printf ("DUMPING FONT");
@@ -42,7 +42,7 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
if (_vm->getGameType() == GType_ST25 && _vm->getPlatform() == Common::kPlatformDOS)
_font = new Font(_vm);

_backgroundImage = new Bitmap(_vm->openFile("DEMON0.BMP"));
_backgroundImage = new Bitmap(_vm->openFile("DEMON0.BMP").get());
_canvas = new Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);

_numSprites = 0;
@@ -67,15 +67,14 @@ void Graphics::loadEGAData(const char *filename) {
if (!_egaData)
_egaData = new byte[256];

Common::SeekableReadStream *egaStream = _vm->openFile(filename);
SharedPtr<Common::SeekableReadStream> egaStream = _vm->openFile(filename);
egaStream->read(_egaData, 256);
delete egaStream;
}

void Graphics::drawBackgroundImage(const char *filename) {
// Draw an stjr BGD image (palette built-in)

Common::SeekableReadStream *imageStream = _vm->openFile(filename);
SharedPtr<Common::SeekableReadStream> imageStream = _vm->openFile(filename);
byte *palette = new byte[256 * 3];
imageStream->read(palette, 256 * 3);

@@ -96,7 +95,6 @@ void Graphics::drawBackgroundImage(const char *filename) {
_vm->_system->updateScreen();

delete[] palette;
delete imageStream;
}


@@ -105,7 +103,7 @@ void Graphics::loadPalette(const Common::String &paletteName) {
Common::String palFile = paletteName + ".PAL";
Common::String lutFile = paletteName + ".LUT";

Common::SeekableReadStream *palStream = _vm->openFile(palFile.c_str());
SharedPtr<Common::SeekableReadStream> palStream = _vm->openFile(palFile.c_str());
byte *palette = new byte[256 * 3];
palStream->read(palette, 256 * 3);

@@ -117,26 +115,27 @@ void Graphics::loadPalette(const Common::String &paletteName) {
_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);

delete[] palette;
delete palStream;

// Load LUT file
Common::SeekableReadStream *lutStream = _vm->openFile(lutFile.c_str());
SharedPtr<Common::SeekableReadStream> lutStream = _vm->openFile(lutFile.c_str());

delete[] _lutData;
_lutData = new byte[256];
lutStream->read(_lutData, 256);

delete lutStream;
}

void Graphics::loadPri(const char *priFile) {
Common::SeekableReadStream *priStream = _vm->openFile(priFile);
SharedPtr<Common::SeekableReadStream> priStream = _vm->openFile(priFile);

delete[] _priData;
_priData = new byte[SCREEN_WIDTH*SCREEN_HEIGHT/2];
priStream->read(_priData, SCREEN_WIDTH*SCREEN_HEIGHT/2);
}

SharedPtr<Bitmap> Graphics::loadBitmap(Common::String basename) {
return SharedPtr<Bitmap>(new Bitmap(_vm->openFile(basename+".BMP").get()));
}

void Graphics::redrawScreen() {
// TODO: get rid of _canvas for efficiency
memcpy(_canvas->pixels, _backgroundImage->pixels, SCREEN_WIDTH*SCREEN_HEIGHT);
@@ -27,12 +27,16 @@
#define STARTREK_GRAPHICS_H

#include "startrek/bitmap.h"
#include "startrek/startrek.h"
#include "startrek/font.h"
#include "startrek/startrek.h"
#include "startrek/sprite.h"

#include "common/ptr.h"
#include "common/rect.h"
#include "common/stream.h"

using Common::SharedPtr;

namespace StarTrek {

class Font;
@@ -44,24 +48,11 @@ const int SCREEN_HEIGHT = 200;

const int MAX_SPRITES = 32;

const int TEXTBOX_WIDTH = 26;

struct Sprite {
uint16 x,y;
uint16 drawPriority;
uint16 field6;
uint16 field8;
Bitmap *bitmap;
uint16 drawMode;
uint16 textColor;
uint16 bitmapChanged;
uint16 redrawCondition2;
uint16 redrawCondition3;
uint16 field16;
Common::Rect rectangle1;
Common::Rect clickRectangle;
Common::Rect rectangle2;
uint16 drawX,drawY;
};

class Graphics;
typedef Common::String (Graphics::*TextGetterFunc)(int, int, Common::String *);


class Graphics {
@@ -75,6 +66,8 @@ class Graphics {
void loadPalette(const Common::String &paletteFile);
void loadPri(const char *priFile);

SharedPtr<Bitmap> loadBitmap(Common::String basename);

void redrawScreen();
void drawSprite(const Sprite &sprite);
void drawSprite(const Sprite &sprite, const Common::Rect &rect);
@@ -102,6 +95,32 @@ class Graphics {

Sprite *_sprites[MAX_SPRITES];
int _numSprites;

Common::Point _mousePos;
Sprite _mouseSprite;


// text.cpp (TODO: separate class)
public:
int showText(TextGetterFunc textGetter, int var, int xoffset, int yoffset, int textColor, int argC, int maxTextLines, int arg10);
Common::String tmpFunction(int choiceIndex, int var, Common::String *speakerTextOutput);
SharedPtr<TextBitmap> initTextSprite(int *xoffsetPtr, int *yoffsetPtr, byte textColor, int numTextLines, bool withHeader, Sprite *sprite);

private:
Common::String skipOverAudioPrompt(const Common::String &str);
int getNumLines(const Common::String &str);
Common::String readLineFormattedText(TextGetterFunc textGetter, int var, int choiceIndex, SharedPtr<TextBitmap> textBitmap, int numTextboxLines, int *numLines);
void loadTextButtons(Common::String mnuFilename, int xpos, int ypos);
void warpMousePosition(int x, int y);

uint16 _textboxVar1;
uint32 _textboxVar2;
uint32 _textboxVar3;
uint16 _textboxVar4;
uint16 _textboxVar5;
uint16 _textboxVar6;
uint16 _textboxVar7;
bool _textboxHasMultipleChoices;
};

}
@@ -8,7 +8,9 @@ MODULE_OBJS = \
lzss.o \
graphics.o \
sound.o \
startrek.o
sprite.o \
startrek.o \
text.o



@@ -107,12 +107,11 @@ void Sound::playSMFSound(const char *baseSoundName) {
}

debug(0, "Playing sound \'%s\'\n", soundName.c_str());
Common::SeekableReadStream *soundStream = _vm->openFile(soundName.c_str());
SharedPtr<Common::SeekableReadStream> soundStream = _vm->openFile(soundName.c_str());

byte *soundData = (byte *)malloc(soundStream->size());
soundStream->read(soundData, soundStream->size());
_midiParser->loadMusic(soundData, soundStream->size());
delete soundStream;

_midiDriver->setTimerCallback(_midiParser, MidiParser::timerCallback);
}
@@ -135,12 +134,11 @@ void Sound::playXMIDISound(const char *baseSoundName) {
}

debug(0, "Playing sound \'%s\'\n", soundName.c_str());
Common::SeekableReadStream *soundStream = _vm->openFile(soundName.c_str());
SharedPtr<Common::SeekableReadStream> soundStream = _vm->openFile(soundName.c_str());

byte *soundData = (byte *)malloc(soundStream->size());
soundStream->read(soundData, soundStream->size());
_midiParser->loadMusic(soundData, soundStream->size());
delete soundStream;

_midiDriver->setTimerCallback(_midiParser, MidiParser::timerCallback);
}
@@ -165,7 +163,7 @@ void Sound::playAmigaSoundEffect(const char *baseSoundName) {
if (_vm->_mixer->isSoundHandleActive(*_soundHandle))
_vm->_mixer->stopHandle(*_soundHandle);

Audio::AudioStream *audStream = (Audio::AudioStream *)Audio::makeRawStream(_vm->openFile(soundName.c_str()), 11025, 0);
Audio::AudioStream *audStream = (Audio::AudioStream *)Audio::makeRawStream(_vm->openFile(soundName.c_str()).get(), 11025, 0);
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _soundHandle, audStream);
}

@@ -0,0 +1,35 @@
/* 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: https://scummvm-startrek.googlecode.com/svn/trunk/graphics.h $
* $Id: graphics.h 2 2009-09-12 20:13:40Z clone2727 $
*
*/

#include "startrek/sprite.h"

namespace StarTrek {

void Sprite::setBitmap(SharedPtr<Bitmap> b) {
bitmap = b;
bitmapChanged = 1;
}

}
@@ -0,0 +1,63 @@
/* 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: https://scummvm-startrek.googlecode.com/svn/trunk/graphics.h $
* $Id: graphics.h 2 2009-09-12 20:13:40Z clone2727 $
*
*/

#ifndef STARTREK_SPRITE_H
#define STARTREK_SPRITE_H

#include "startrek/bitmap.h"

#include "common/ptr.h"
#include "common/rect.h"
#include "common/stream.h"

using Common::SharedPtr;

namespace StarTrek {


struct Sprite {
Common::Point pos;
uint16 drawPriority;
uint16 field6;
uint16 field8;
SharedPtr<Bitmap> bitmap;
uint16 drawMode;
uint16 textColor;
uint16 bitmapChanged;
uint16 redrawCondition2;
uint16 redrawCondition3;
uint16 field16;
Common::Rect rectangle1;
Common::Rect clickRectangle;
Common::Rect rectangle2;
uint16 drawX,drawY;


void setBitmap(SharedPtr<Bitmap> b);
};

}

#endif
Oops, something went wrong.

0 comments on commit 2dd96e0

Please sign in to comment.