FREESCAPE: added more UI elements for castle

This commit is contained in:
neuromancer 2024-08-24 15:38:22 +02:00
parent 49cfdf1122
commit 8d0a6784f7
3 changed files with 98 additions and 21 deletions

View File

@ -61,6 +61,8 @@ CastleEngine::CastleEngine(OSystem *syst, const ADGameDescription *gd) : Freesca
_optionTexture = nullptr;
_keysFrame = nullptr;
_spiritsMeterIndicatorFrame = nullptr;
_strenghtBackgroundFrame = nullptr;
_strenghtBarFrame = nullptr;
_menu = nullptr;
_numberKeys = 0;
@ -78,6 +80,13 @@ CastleEngine::~CastleEngine() {
_option->free();
delete _option;
}
for (int i = 0; i < int(_strenghtWeightsFrames.size()); i++) {
if (_strenghtWeightsFrames[i]) {
_strenghtWeightsFrames[i]->free();
delete _strenghtWeightsFrames[i];
}
}
}
void CastleEngine::initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) {
@ -629,21 +638,57 @@ void CastleEngine::drawStringInSurface(const Common::String &str, int x, int y,
}
void CastleEngine::drawEnergyMeter(Graphics::Surface *surface) {
uint32 back = 0;
/*uint32 back = 0;
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
Common::Rect weightRect;
Common::Rect barRect;
Common::Rect backRect;
Common::Rect backRect;*/
Common::Point origin;
if (isDOS()) {
back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xA7, 0x00, 0x00);
/*back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xA7, 0x00, 0x00);
barRect = Common::Rect(45, 164, 110, 166);
weightRect = Common::Rect(57, 158, 59, 172);
backRect = Common::Rect(45, 157, 112, 173);
if (_gameStateVars[k8bitVariableShield] > 16)
weightRect.translate(3, 0);
weightRect.translate(3, 0);*/
} if (isSpectrum()) {
origin = Common::Point(63, 154);
surface->copyRectToSurface((const Graphics::Surface)*_strenghtBackgroundFrame, origin.x, origin.y, Common::Rect(0, 0, _strenghtBackgroundFrame->w, _strenghtBackgroundFrame->h));
surface->copyRectToSurface((const Graphics::Surface)*_strenghtBarFrame, origin.x, origin.y + 6, Common::Rect(0, 0, _strenghtBarFrame->w, _strenghtBarFrame->h));
Common::Point weightPoint;
int frameIdx = -1;
weightPoint = Common::Point(origin.x + 5, origin.y + 1);
frameIdx = 3 - _gameStateVars[k8bitVariableShield] % 4;
frameIdx++;
frameIdx = frameIdx % 4;
surface->copyRectToSurface((const Graphics::Surface)*_strenghtWeightsFrames[frameIdx], weightPoint.x, weightPoint.y, Common::Rect(0, 0, 3, _strenghtWeightsFrames[frameIdx]->h));
weightPoint += Common::Point(3, 0);
for (int i = 0; i < _gameStateVars[k8bitVariableShield] / 4 - 1; i++) {
surface->copyRectToSurface((const Graphics::Surface)*_strenghtWeightsFrames[0], weightPoint.x, weightPoint.y, Common::Rect(0, 0, 3, _strenghtWeightsFrames[0]->h));
weightPoint += Common::Point(3, 0);
}
weightPoint = Common::Point(origin.x + 64, origin.y + 1);
frameIdx = 3 - _gameStateVars[k8bitVariableShield] % 4;
frameIdx++;
frameIdx = frameIdx % 4;
surface->copyRectToSurface((const Graphics::Surface)*_strenghtWeightsFrames[frameIdx], weightPoint.x, weightPoint.y, Common::Rect(0, 0, 3, _strenghtWeightsFrames[frameIdx]->h));
weightPoint += Common::Point(-3, 0);
for (int i = 0; i < _gameStateVars[k8bitVariableShield] / 4 - 1; i++) {
surface->copyRectToSurface((const Graphics::Surface)*_strenghtWeightsFrames[0], weightPoint.x, weightPoint.y, Common::Rect(0, 0, 3, _strenghtWeightsFrames[0]->h));
weightPoint += Common::Point(-3, 0);
}
return;
}
surface->fillRect(backRect, black);
/*surface->fillRect(backRect, black);
surface->fillRect(barRect, back);
for (int i = 0; i < _gameStateVars[k8bitVariableShield] / 4; i++) {
@ -656,7 +701,7 @@ void CastleEngine::drawEnergyMeter(Graphics::Surface *surface) {
weightRect.translate(0, remainder / 2);
weightRect.setHeight(weightRect.height() - remainder);
surface->fillRect(weightRect, back);
}
}*/
}
void CastleEngine::addGhosts() {

View File

@ -66,11 +66,16 @@ public:
void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0) override;
//void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0) override;
Graphics::Surface *loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 back);
Graphics::Surface *loadFrames(Common::SeekableReadStream *file, Graphics::Surface *surface, int width, int height, uint32 back);
Common::Array<Graphics::Surface *> loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back);
Graphics::Surface *loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back);
Graphics::Surface *loadFrame(Common::SeekableReadStream *file, Graphics::Surface *surface, int width, int height, uint32 back);
Graphics::Surface *_keysFrame;
Graphics::Surface *_spiritsMeterIndicatorFrame;
Graphics::Surface *_strenghtBackgroundFrame;
Graphics::Surface *_strenghtBarFrame;
Common::Array<Graphics::Surface *> _strenghtWeightsFrames;
int _numberKeys;
bool _useRockTravel;
int _spiritsDestroyed;

View File

@ -41,7 +41,7 @@ void CastleEngine::initZX() {
_soundIndexAreaChange = 5;
}
Graphics::Surface *CastleEngine::loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 back) {
Graphics::Surface *CastleEngine::loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back) {
Graphics::Surface *surface = new Graphics::Surface();
file->seek(pos);
int16 width = file->readByte();
@ -50,24 +50,39 @@ Graphics::Surface *CastleEngine::loadFramesWithHeader(Common::SeekableReadStream
/*byte mask =*/ file->readByte();
uint8 r, g, b;
_gfx->readFromPalette(7, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
surface->fillRect(Common::Rect(0, 0, width * 8, height), white);
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
/*int frameSize =*/ file->readUint16LE();
return loadFrames(file, surface, width, height, back);
return loadFrame(file, surface, width, height, front);
}
Common::Array<Graphics::Surface *> CastleEngine::loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back) {
Graphics::Surface *surface = nullptr;
file->seek(pos);
int16 width = file->readByte();
int16 height = file->readByte();
/*byte mask =*/ file->readByte();
/*int frameSize =*/ file->readUint16LE();
Common::Array<Graphics::Surface *> frames;
for (int i = 0; i < numFrames; i++) {
surface = new Graphics::Surface();
surface->create(width * 8, height, _gfx->_texturePixelFormat);
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
frames.push_back(loadFrame(file, surface, width, height, front));
}
return frames;
}
Graphics::Surface *CastleEngine::loadFrames(Common::SeekableReadStream *file, Graphics::Surface *surface, int width, int height, uint32 back) {
Graphics::Surface *CastleEngine::loadFrame(Common::SeekableReadStream *file, Graphics::Surface *surface, int width, int height, uint32 front) {
for (int i = 0; i < width * height; i++) {
byte color = file->readByte();
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
if ((color & (1 << n)))
surface->setPixel(x, y, back);
surface->setPixel(x, y, front);
}
}
return surface;
@ -118,10 +133,14 @@ void CastleEngine::loadAssetsZXFullGame() {
loadColorPalette();
_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_keysFrame = loadFramesWithHeader(&file, 0xdf7, 1, red);
_gfx->readFromPalette(7, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_keysFrame = loadFrameWithHeader(&file, 0xdf7, white, red);
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
_spiritsMeterIndicatorFrame = loadFramesWithHeader(&file, _language == Common::ES_ESP ? 0xe5e : 0xe4f, 1, green);
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe5e : 0xe4f, green, white);
Graphics::Surface *background = new Graphics::Surface();
@ -134,7 +153,15 @@ void CastleEngine::loadAssetsZXFullGame() {
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
file.seek(_language == Common::ES_ESP ? 0xfd3 : 0xfc4);
_background = loadFrames(&file, background, backgroundWidth, backgroundHeight, front);
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
_gfx->readFromPalette(6, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
_strenghtBackgroundFrame = loadFrameWithHeader(&file, 0xed7, yellow, black);
_strenghtBarFrame = loadFrameWithHeader(&file, 0xf63, yellow, black);
_strenghtWeightsFrames = loadFramesWithHeader(&file, 0xf83, 4, yellow, black);
for (auto &it : _areaMap) {
it._value->addStructure(_areaMap[255]);
@ -203,7 +230,7 @@ void CastleEngine::drawZXUI(Graphics::Surface *surface) {
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
//drawEnergyMeter(surface);
drawEnergyMeter(surface);
}
} // End of namespace Freescape