aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/chewy/graphics.cpp37
-rw-r--r--engines/chewy/graphics.h7
-rw-r--r--engines/chewy/scene.cpp53
-rw-r--r--engines/chewy/text.cpp10
4 files changed, 87 insertions, 20 deletions
diff --git a/engines/chewy/graphics.cpp b/engines/chewy/graphics.cpp
index 54a731fd3a..9ff681a450 100644
--- a/engines/chewy/graphics.cpp
+++ b/engines/chewy/graphics.cpp
@@ -34,12 +34,17 @@
namespace Chewy {
+#define DESC_WIDTH 80
+#define DESC_HEIGHT 8
+
Graphics::Graphics(ChewyEngine *vm) : _vm(vm) {
_font = nullptr;
+ _descSurface.create(DESC_WIDTH, DESC_HEIGHT, ::Graphics::PixelFormat::createFormatCLUT8());
}
Graphics::~Graphics() {
delete _font;
+ _descSurface.free();
}
void Graphics::drawSprite(Common::String filename, int spriteNum, uint x, uint y) {
@@ -67,6 +72,15 @@ void Graphics::drawImage(Common::String filename, int imageNum) {
delete res;
}
+void Graphics::drawRect(Common::Rect r, byte color) {
+ ::Graphics::Surface *screen = g_system->lockScreen();
+ screen->drawLine(r.left, r.top, r.right, r.top, color);
+ screen->drawLine(r.right, r.top, r.right, r.bottom, color);
+ screen->drawLine(r.left, r.bottom, r.right, r.bottom, color);
+ screen->drawLine(r.left, r.top, r.left, r.bottom, color);
+ g_system->unlockScreen();
+}
+
void Graphics::loadFont(Common::String filename) {
_font = new Font(filename);
}
@@ -145,4 +159,27 @@ void Graphics::playVideo(uint num) {
delete cfoDecoder;
}
+void Graphics::setDescSurface(Common::Point pos) {
+ _descPos = pos;
+
+ if (pos.x < 0)
+ return;
+
+ ::Graphics::Surface *s = g_system->lockScreen();
+ Common::Rect r = Common::Rect(pos.x, pos.y, pos.x + _descSurface.w, pos.y + _descSurface.h);
+ r.clip(Common::Rect(0, 0, 320, 200));
+ _descSurface.copyRectToSurface(*s, 0, 0, r);
+ g_system->unlockScreen();
+}
+
+void Graphics::restoreDescSurface() {
+ if (_descPos.x < 0)
+ return;
+
+ Common::Rect r = Common::Rect(_descPos.x, _descPos.y, _descPos.x + _descSurface.w, _descPos.y + _descSurface.h);
+ r.clip(Common::Rect(0, 0, 320, 200));
+ g_system->copyRectToScreen(_descSurface.getPixels(), _descSurface.pitch, _descPos.x, _descPos.y, r.width(), r.height());
+ _descPos = Common::Point(-1, -1);
+}
+
} // End of namespace Chewy
diff --git a/engines/chewy/graphics.h b/engines/chewy/graphics.h
index a260311df5..09865711df 100644
--- a/engines/chewy/graphics.h
+++ b/engines/chewy/graphics.h
@@ -24,6 +24,8 @@
#define CHEWY_GRAPHICS_H
#include "chewy/chewy.h"
+#include "common/rect.h"
+#include "graphics/surface.h"
namespace Chewy {
@@ -37,15 +39,20 @@ public:
void drawImage(Common::String filename, int imageNum);
void drawSprite(Common::String filename, int spriteNum, uint x, uint y);
+ void drawRect(Common::Rect r, byte color);
void playVideo(uint num);
void loadFont(Common::String filename);
void drawText(Common::String text, uint x, uint y);
+ void setDescSurface(Common::Point pos);
+ void restoreDescSurface();
private:
void drawTransparent(uint16 x, uint16 y, byte *data, uint16 width, uint16 height, byte transparentColor);
ChewyEngine *_vm;
Font *_font;
+ Common::Point _descPos;
+ ::Graphics::Surface _descSurface;
};
} // End of namespace Chewy
diff --git a/engines/chewy/scene.cpp b/engines/chewy/scene.cpp
index 0f12219078..778cec13b8 100644
--- a/engines/chewy/scene.cpp
+++ b/engines/chewy/scene.cpp
@@ -55,15 +55,19 @@ struct StaticDetails {
// 1 byte dummy
};
+struct Hotspot {
+ Common::Rect rect;
+ uint16 resource;
+ Common::String desc;
+};
+
struct SceneInfo {
uint16 staticDetailsCount;
uint16 animatedDetailsCount;
uint32 spritePtr;
AnimatedDetails animatedDetails[MAX_DETAILS];
StaticDetails staticDetails[MAX_DETAILS];
- Common::Rect hotspot[MAX_HOTSPOTS];
- uint16 hotspotDescRes[MAX_HOTSPOTS];
- Common::String hotspotDesc[MAX_HOTSPOTS];
+ Hotspot hotspot[MAX_HOTSPOTS];
byte roomNum;
byte picNum;
byte autoMoveCount;
@@ -78,6 +82,7 @@ struct SceneInfo {
Scene::Scene(ChewyEngine *vm) : _vm(vm) {
_sceneInfo = new SceneInfo();
+ _vm->_graphics->setDescSurface(Common::Point(-1, -1));
}
Scene::~Scene() {
@@ -98,7 +103,7 @@ void Scene::draw() {
_vm->_graphics->drawImage("episode1.tgp", _curScene);
// Static details
- for (uint16 i = 0; i < MAX_HOTSPOTS; i++) {
+ for (uint16 i = 0; i < MAX_DETAILS; i++) {
StaticDetails s = _sceneInfo->staticDetails[i];
if (s.spriteNum >= 0 && s.x >= 0 && s.y >= 0 && !s.hide)
_vm->_graphics->drawSprite(Common::String::format("det%d.taf", _curScene), s.spriteNum, s.x, s.y);
@@ -108,17 +113,25 @@ void Scene::draw() {
_vm->_graphics->drawSprite("det1.taf", 0, 200, 100);
_vm->_graphics->loadFont("6x8.tff");
_vm->_graphics->drawText("This is a test", 200, 80);
+
+ _vm->_graphics->setDescSurface(Common::Point(-1, -1));
}
void Scene::updateMouse(Common::Point coords) {
+ _vm->_graphics->restoreDescSurface();
+
// Animated details
// TODO: handle these
// Static details
for (uint16 i = 0; i < MAX_HOTSPOTS; i++) {
- if (_sceneInfo->hotspot[i].contains(coords)) {
- // TODO: Draw hotspot description on screen
- debug("Coords %d, %d: '%s'", coords.x, coords.y, _sceneInfo->hotspotDesc[i].c_str());
+ //_vm->_graphics->drawRect(_sceneInfo->hotspot[i].rect, 0); // debug
+
+ if (_sceneInfo->hotspot[i].rect.contains(coords) && _sceneInfo->hotspot[i].resource < kATSTextMax) {
+ if (coords.y >= 8) {
+ _vm->_graphics->setDescSurface(Common::Point(coords.x, coords.y - 8));
+ _vm->_graphics->drawText(_sceneInfo->hotspot[i].desc, coords.x, coords.y - 8);
+ }
break;
}
}
@@ -165,25 +178,29 @@ void Scene::loadSceneInfo() {
// Hotspots
for (int i = 0; i < MAX_HOTSPOTS; i++) {
- _sceneInfo->hotspot[i].left = indexFile.readUint16LE();
- _sceneInfo->hotspot[i].top = indexFile.readUint16LE();
- _sceneInfo->hotspot[i].right = indexFile.readUint16LE();
- _sceneInfo->hotspot[i].bottom = indexFile.readUint16LE();
- if (!_sceneInfo->hotspot[i].isValidRect())
+ _sceneInfo->hotspot[i].rect.left = indexFile.readUint16LE();
+ _sceneInfo->hotspot[i].rect.top = indexFile.readUint16LE();
+ _sceneInfo->hotspot[i].rect.right = indexFile.readUint16LE();
+ _sceneInfo->hotspot[i].rect.bottom = indexFile.readUint16LE();
+ if (!_sceneInfo->hotspot[i].rect.isValidRect())
warning("Hotspot %d has an invalid rect", i);
}
// Hotspot descriptions
for (int i = 0; i < MAX_HOTSPOTS; i++) {
- _sceneInfo->hotspotDescRes[i] = indexFile.readUint16LE();
+ _sceneInfo->hotspot[i].resource = indexFile.readUint16LE() + 4;
- if (_sceneInfo->hotspotDescRes[i] < 12) {
- // TODO: Hotspot description IDs are off... investigate why
- _sceneInfo->hotspotDesc[i] = text->getText(_curScene + kADSTextMax, _sceneInfo->hotspotDescRes[i])->text;
+ if (_sceneInfo->hotspot[i].resource < kATSTextMax) {
+ TextEntry *entry = text->getText(_curScene + kADSTextMax, _sceneInfo->hotspot[i].resource);
+ if (entry)
+ _sceneInfo->hotspot[i].desc = entry->text;
+ else
+ _sceneInfo->hotspot[i].desc = Common::String::format("Hotspot %d", _sceneInfo->hotspot[i].resource);
} else {
// TODO: Handle these types of hotspot descriptions
- warning("Hotspot %d has an invalid description resource (%d)", i, _sceneInfo->hotspotDescRes[i]);
- _sceneInfo->hotspotDesc[i] = Common::String::format("Hotspot %d", _sceneInfo->hotspotDescRes[i]);
+ _sceneInfo->hotspot[i].desc = "";
+ //warning("Hotspot %d has an invalid description resource (%d)", i, _sceneInfo->hotspot[i].resource);
+ //_sceneInfo->hotspot[i].desc = Common::String::format("Hotspot %d", _sceneInfo->hotspot[i].resource);
}
}
diff --git a/engines/chewy/text.cpp b/engines/chewy/text.cpp
index cf0fb041a7..095b74b290 100644
--- a/engines/chewy/text.cpp
+++ b/engines/chewy/text.cpp
@@ -112,8 +112,14 @@ TextEntry *Text::getText(uint dialogNum, uint entryNum) {
}
} while (*ptr);
- if (*(ptr + 1) != kEndText || *(ptr + 2) != kEndChunk)
- error("Invalid text resource - %d, %d", dialogNum, entryNum);
+ if (*(ptr + 1) != kEndText || *(ptr + 2) != kEndChunk) {
+ warning("Invalid text resource - %d, %d", dialogNum, entryNum);
+
+ delete[] data;
+ delete d;
+
+ return nullptr;
+ }
if (!isText)
ptr += 3; // 0, kEndText, kEndChunk