aboutsummaryrefslogtreecommitdiff
path: root/engines/mads
diff options
context:
space:
mode:
authorPaul Gilbert2014-05-11 18:08:31 -0400
committerPaul Gilbert2014-05-11 18:08:31 -0400
commit8abcbf3fb08fbca6f0cfdb9eabd22cf56e83b440 (patch)
tree9b24d0bd0e59fc81371ded67613a821fb3c2f323 /engines/mads
parente21534ecc2d39864d2cb3ba67248ad0dadecf72e (diff)
downloadscummvm-rg350-8abcbf3fb08fbca6f0cfdb9eabd22cf56e83b440.tar.gz
scummvm-rg350-8abcbf3fb08fbca6f0cfdb9eabd22cf56e83b440.tar.bz2
scummvm-rg350-8abcbf3fb08fbca6f0cfdb9eabd22cf56e83b440.zip
MADS: Refactoring of dialog classes, more implementation of PictureDialog
Diffstat (limited to 'engines/mads')
-rw-r--r--engines/mads/dialogs.cpp46
-rw-r--r--engines/mads/dialogs.h16
-rw-r--r--engines/mads/msurface.cpp10
-rw-r--r--engines/mads/msurface.h5
-rw-r--r--engines/mads/nebular/dialogs_nebular.cpp86
-rw-r--r--engines/mads/nebular/dialogs_nebular.h9
6 files changed, 106 insertions, 66 deletions
diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp
index e68411a4bb..3ea47c4de6 100644
--- a/engines/mads/dialogs.cpp
+++ b/engines/mads/dialogs.cpp
@@ -34,22 +34,20 @@ Dialog::Dialog(MADSEngine *vm): _vm(vm), _savedSurface(nullptr),
}
Dialog::~Dialog() {
- restore(&_vm->_screen);
}
-
-void Dialog::save(MSurface *s) {
+void Dialog::save() {
_savedSurface = new MSurface(_width, _height);
- s->copyTo(_savedSurface,
+ _vm->_screen.copyTo(_savedSurface,
Common::Rect(_position.x, _position.y, _position.x + _width, _position.y + _height),
Common::Point());
_vm->_screen.copyRectToScreen(getBounds());
}
-void Dialog::restore(MSurface *s) {
+void Dialog::restore() {
if (_savedSurface) {
- _savedSurface->copyTo(s, _position);
+ _savedSurface->copyTo(&_vm->_screen, _position);
delete _savedSurface;
_savedSurface = nullptr;
@@ -58,8 +56,11 @@ void Dialog::restore(MSurface *s) {
}
void Dialog::draw() {
+ // Calculate the dialog positioning
+ calculateBounds();
+
// Save the screen portion the dialog will overlap
- save(&_vm->_screen);
+ save();
// Draw the dialog
// Fill entire content of dialog
@@ -82,6 +83,9 @@ void Dialog::draw() {
TEXTDIALOG_CONTENT1, TEXTDIALOG_CONTENT2);
}
+void Dialog::calculateBounds() {
+}
+
void Dialog::drawContent(const Common::Rect &r, int seed, byte color1, byte color2) {
uint16 currSeed = seed ? seed : 0xB78E;
@@ -259,16 +263,7 @@ void TextDialog::draw() {
--_numLines;
// Figure out the size and position for the dialog
- _height = (_font->getHeight() + 1) * (_numLines + 1) + 10;
- if (_position.x == -1)
- _position.x = 160 - (_width / 2);
- if (_position.y == -1)
- _position.y = 100 - (_height / 2);
-
- if ((_position.x + _width) > _vm->_screen.getWidth())
- _position.x = _vm->_screen.getWidth() - (_position.x + _width);
- if ((_position.y + _height) > _vm->_screen.getHeight())
- _position.y = _vm->_screen.getHeight() - (_position.y + _height);
+ calculateBounds();
// Draw the underlying dialog
Dialog::draw();
@@ -305,6 +300,19 @@ void TextDialog::draw() {
_vm->_screen.copyRectToScreen(getBounds());
}
+void TextDialog::calculateBounds() {
+ _height = (_font->getHeight() + 1) * (_numLines + 1) + 10;
+ if (_position.x == -1)
+ _position.x = 160 - (_width / 2);
+ if (_position.y == -1)
+ _position.y = 100 - (_height / 2);
+
+ if ((_position.x + _width) > _vm->_screen.getWidth())
+ _position.x = _vm->_screen.getWidth() - (_position.x + _width);
+ if ((_position.y + _height) > _vm->_screen.getHeight())
+ _position.y = _vm->_screen.getHeight() - (_position.y + _height);
+}
+
void TextDialog::drawWithInput() {
//int innerWidth = _innerWidth;
//int lineHeight = _font->getHeight() + 1;
@@ -325,6 +333,7 @@ void TextDialog::restorePalette() {
}
void TextDialog::show() {
+ // Draw the dialog
draw();
_vm->_events->showCursor();
@@ -338,6 +347,9 @@ void TextDialog::show() {
_vm->_events->waitForNextFrame();
_vm->_events->_pendingKeys.clear();
}
+
+ // Restore the background
+ restore();
}
/*------------------------------------------------------------------------*/
diff --git a/engines/mads/dialogs.h b/engines/mads/dialogs.h
index d06611b1c4..aa635768a1 100644
--- a/engines/mads/dialogs.h
+++ b/engines/mads/dialogs.h
@@ -40,15 +40,13 @@ protected:
/**
* Save the section of the passed surface the dialog will cover.
- * @param s Screen surface to save
*/
- void save(MSurface *s);
+ virtual void save();
/**
* Restore saved dialog surface
- * @param s Screen surface to restore to.
*/
- void restore(MSurface *s);
+ virtual void restore();
/**
* Draws the content of a dialog with a gravelly alternating color.
@@ -59,6 +57,11 @@ protected:
* Draw the dialog
*/
virtual void draw();
+
+ /**
+ * Calculate bounds for the dialog
+ */
+ virtual void calculateBounds();
public:
/**
* Constructor
@@ -115,6 +118,11 @@ protected:
Common::String _lines[TEXT_DIALOG_MAX_LINES];
int _lineXp[TEXT_DIALOG_MAX_LINES];
byte _cyclingPalette[8 * 3];
+
+ /**
+ * Calculate the bounds for the dialog
+ */
+ virtual void calculateBounds();
public:
/**
* Constructor
diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp
index 5d1e948f77..4fae799c28 100644
--- a/engines/mads/msurface.cpp
+++ b/engines/mads/msurface.cpp
@@ -494,6 +494,16 @@ void MSurface::translate(Common::Array<RGB6> &palette) {
}
}
+void MSurface::translate(byte map[PALETTE_COUNT]) {
+ for (int y = 0; y < this->h; ++y) {
+ byte *pDest = getBasePtr(0, y);
+
+ for (int x = 0; x < this->w; ++x, ++pDest) {
+ *pDest = map[*pDest];
+ }
+ }
+}
+
MSurface *MSurface::flipHorizontal() const {
MSurface *dest = new MSurface(this->w, this->h);
diff --git a/engines/mads/msurface.h b/engines/mads/msurface.h
index 060a7ab540..fbd927084a 100644
--- a/engines/mads/msurface.h
+++ b/engines/mads/msurface.h
@@ -205,6 +205,11 @@ public:
void translate(Common::Array<RGB6> &palette);
/**
+ * Translates the pixels of an image used the passed palette with RGB mapping
+ */
+ void translate(byte map[PALETTE_COUNT]);
+
+ /**
* Create a new surface which is a flipped horizontal copy of the current one
*/
MSurface *flipHorizontal() const;
diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp
index 6ddb3230d9..2e020f3677 100644
--- a/engines/mads/nebular/dialogs_nebular.cpp
+++ b/engines/mads/nebular/dialogs_nebular.cpp
@@ -171,20 +171,6 @@ void DialogsNebular::showItem(int objectId, int messageId, int speech) {
assert(!speech);
show(messageId, objectId);
-#if 0
- Scene &scene = _vm->_game->_scene;
- byte highPalette[8 * 3];
- Common::copy(&_vm->_palette->_mainPalette[0x2E8], &_vm->_palette->_mainPalette[PALETTE_SIZE],
- &highPalette[0]);
- byte *depthP = scene._depthSurface.getData();
- byte greyScale[3];
- greyScale[0] = greyScale[1] = greyScale[2] = 0xFFFF;
- Common::String setName = Common::String::format("*OBJ%.3d.SS", objectId);
-
-
-
- delete[] savedSurface;
-#endif
}
Common::String DialogsNebular::getVocab(int vocabId) {
@@ -211,7 +197,7 @@ Common::String DialogsNebular::getVocab(int vocabId) {
bool DialogsNebular::textNoun(Common::String &dialogText, int nounNum,
const Common::String &valStr) {
- warning("TODO: textNoun");
+ error("TODO: textNoun");
return false;
}
@@ -337,12 +323,25 @@ bool CopyProtectionDialog::getHogAnusEntry(HOGANUS &entry) {
PictureDialog::PictureDialog(MADSEngine *vm, const Common::Point &pos,
int maxChars, int objectId) :
TextDialog(vm, FONT_INTERFACE, pos, maxChars), _objectId(objectId) {
- Scene &scene = _vm->_game->_scene;
- Palette &palette = *_vm->_palette;
-
// Turn off cycling if active
+ Scene &scene = _vm->_game->_scene;
_cyclingActive = scene._cyclingActive;
scene._cyclingActive = false;
+}
+
+PictureDialog::~PictureDialog() {
+ // Restore cycling flag
+ Scene &scene = _vm->_game->_scene;
+ scene._cyclingActive = _cyclingActive;
+}
+
+void PictureDialog::save() {
+ Palette &palette = *_vm->_palette;
+ byte map[PALETTE_COUNT];
+
+ // Save the entire screen
+ _savedSurface = new MSurface(MADS_SCREEN_WIDTH, MADS_SCREEN_HEIGHT);
+ _vm->_screen.copyTo(_savedSurface);
// Save palette information
Common::copy(&palette._mainPalette[0], &palette._mainPalette[PALETTE_SIZE], &_palette[0]);
@@ -358,34 +357,43 @@ PictureDialog::PictureDialog(MADSEngine *vm, const Common::Point &pos,
// Reset the flag list
palette._rgbList.reset();
-}
-PictureDialog::~PictureDialog() {
- // Restore cycling flag
- Scene &scene = _vm->_game->_scene;
- Palette &palette = *_vm->_palette;
- scene._cyclingActive = _cyclingActive;
+ // Fade the screen to grey
+ int numColors = PALETTE_COUNT - PALETTE_RESERVED_LOW_COUNT - PALETTE_RESERVED_HIGH_COUNT;
+ palette.fadeToGrey(palette._mainPalette, &map[PALETTE_RESERVED_LOW_COUNT],
+ PALETTE_RESERVED_LOW_COUNT, numColors, 248, 8, 1, 16);
- // Restore palette information
- Common::copy(&_palette[0], &_palette[PALETTE_SIZE], &palette._mainPalette[0]);
- _vm->_palette->setFullPalette(palette._mainPalette);
- Common::copy(&_palFlags[0], &_palFlags[PALETTE_COUNT], &palette._palFlags[0]);
- palette._rgbList.copy(_rgbList);
-}
+ // Remap the greyed out screen to use the small greyscale range
+ // at the top end of the palette
+ _vm->_screen.translate(map);
-void PictureDialog::show() {
- setupPalette();
+ // Load the inventory picture
+ Common::String setName = Common::String::format("*OB%.3d.SS", _objectId);
+ SpriteAsset *asset = new SpriteAsset(_vm, setName, 0x8000);
+ palette.setFullPalette(palette._mainPalette);
- TextDialog::show();
+ // Draw the inventory picture
+ MSprite *frame = asset->getFrame(0);
+ frame->copyTo(&_vm->_screen, Common::Point(160 - frame->w / 2, 6),
+ frame->getTransparencyIndex());
+ _vm->_screen.copyRectToScreen(_vm->_screen.getBounds());
}
-void PictureDialog::setupPalette() {
- Palette &palette = *_vm->_palette;
- byte map[PALETTE_COUNT];
+void PictureDialog::restore() {
+ if (_savedSurface) {
+ _savedSurface->copyTo(&_vm->_screen);
+ delete _savedSurface;
+ _savedSurface = nullptr;
- int numColors = PALETTE_COUNT - PALETTE_RESERVED_LOW_COUNT - PALETTE_RESERVED_HIGH_COUNT;
- palette.fadeToGrey(palette._mainPalette, &map[PALETTE_RESERVED_LOW_COUNT],
- PALETTE_RESERVED_LOW_COUNT, numColors, 248, 8, 1, 16);
+ _vm->_screen.copyRectToScreen(_vm->_screen.getBounds());
+
+ // Restore palette information
+ Palette &palette = *_vm->_palette;
+ Common::copy(&_palette[0], &_palette[PALETTE_SIZE], &palette._mainPalette[0]);
+ _vm->_palette->setFullPalette(palette._mainPalette);
+ Common::copy(&_palFlags[0], &_palFlags[PALETTE_COUNT], &palette._palFlags[0]);
+ palette._rgbList.copy(_rgbList);
+ }
}
/*------------------------------------------------------------------------*/
diff --git a/engines/mads/nebular/dialogs_nebular.h b/engines/mads/nebular/dialogs_nebular.h
index fd4d6e706e..60a215197f 100644
--- a/engines/mads/nebular/dialogs_nebular.h
+++ b/engines/mads/nebular/dialogs_nebular.h
@@ -89,17 +89,14 @@ private:
byte _palette[PALETTE_SIZE];
uint32 _palFlags[PALETTE_COUNT];
RGBList _rgbList;
+protected:
+ virtual void save();
- /**
- * Sets up the palette and fades the screen to gray
- */
- void setupPalette();
+ virtual void restore();
public:
PictureDialog(MADSEngine *vm, const Common::Point &pos, int maxChars, int objectId);
virtual ~PictureDialog();
-
- virtual void show();
};
enum DialogTextAlign { ALIGN_CENTER = -1, ALIGN_AT_CENTER = -2, ALIGN_RIGHT = -3 };