From fdbcb5f785dcc4a4bf8b178c11f4a92d07467e6c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 28 Sep 2013 10:41:52 +0200 Subject: AVALANCHE: Move some more functions to Graphics --- engines/avalanche/avalanche.h | 3 --- engines/avalanche/avalot.cpp | 59 ++++++------------------------------------ engines/avalanche/enums.h | 4 +++ engines/avalanche/graphics.cpp | 51 ++++++++++++++++++++++++++++++++++++ engines/avalanche/graphics.h | 19 +++++++++----- engines/avalanche/parser.cpp | 8 +++--- engines/avalanche/timer.cpp | 2 +- 7 files changed, 80 insertions(+), 66 deletions(-) (limited to 'engines/avalanche') diff --git a/engines/avalanche/avalanche.h b/engines/avalanche/avalanche.h index 5736291ad7..ae490e0056 100644 --- a/engines/avalanche/avalanche.h +++ b/engines/avalanche/avalanche.h @@ -320,7 +320,6 @@ public: void init(); void callVerb(VerbCode id); - void drawAlsoLines(); void loadRoom(byte num); void exitRoom(byte x); void enterRoom(Room room, byte ped); @@ -349,8 +348,6 @@ public: Common::String intToStr(int32 num); - void setBackgroundColor(byte x); - void resetVariables(); void newGame(); // This sets up the DNA for a completely new game. void slowDown(); diff --git a/engines/avalanche/avalot.cpp b/engines/avalanche/avalot.cpp index bb69de864b..bcd501001e 100644 --- a/engines/avalanche/avalot.cpp +++ b/engines/avalanche/avalot.cpp @@ -442,22 +442,6 @@ void AvalancheEngine::callVerb(VerbCode id) { } } -void AvalancheEngine::drawAlsoLines() { - CursorMan.showMouse(false); - - _graphics->_magics.fillRect(Common::Rect(0, 0, 640, 200), 0); - _graphics->_magics.frameRect(Common::Rect(0, 45, 640, 161), 15); - - for (int i = 0; i < _lineNum; i++) { - // We had to check if the lines are within the borders of the screen. - if ((_lines[i]._x1 >= 0) && (_lines[i]._x1 < _graphics->kScreenWidth) && (_lines[i]._y1 >= 0) && (_lines[i]._y1 < _graphics->kScreenHeight) - && (_lines[i]._x2 >= 0) && (_lines[i]._x2 < _graphics->kScreenWidth) && (_lines[i]._y2 >= 0) && (_lines[i]._y2 < _graphics->kScreenHeight)) - _graphics->_magics.drawLine(_lines[i]._x1, _lines[i]._y1, _lines[i]._x2, _lines[i]._y2, _lines[i]._color); - } - - CursorMan.showMouse(true); -} - /** * Check is it's possible to give something to Spludwick * @remarks Originally called 'nextstring' @@ -564,7 +548,7 @@ void AvalancheEngine::loadAlso(byte num) { for (int i = 0; i < listen_length; i++) _listen += file.readByte(); - drawAlsoLines(); + _graphics->drawAlsoLines(); file.close(); unScramble(); @@ -1077,19 +1061,14 @@ void AvalancheEngine::enterRoom(Room roomId, byte ped) { } void AvalancheEngine::thinkAbout(byte object, bool type) { - const int16 picSize = 966; - _thinks = object; object--; - _graphics->loadMouse(kCurWait); - + Common::String filename; if (type == kThing) { - if (!file.open("thinks.avd")) - error("AVALANCHE: File not found: thinks.avd"); + filename = "thinks.avd"; } else { // kPerson - if (!file.open("folk.avd")) - error("AVALANCHE: File not found: folk.avd"); + filename = "folk.avd"; object -= 149; if (object >= 25) @@ -1098,34 +1077,16 @@ void AvalancheEngine::thinkAbout(byte object, bool type) { object--; // Last time... } + _graphics->loadMouse(kCurWait); CursorMan.showMouse(false); - - file.seek(object * picSize + 65); - ::Graphics::Surface picture = _graphics->loadPictureGraphic(file); - _graphics->drawPicture(_graphics->_surface, picture, 205, 170); - - picture.free(); - file.close(); - + _graphics->drawThinkPic(filename, object); CursorMan.showMouse(true); + _thinkThing = type; } void AvalancheEngine::drawToolbar() { - if (!file.open("useful.avd")) - error("AVALANCHE: File not found: useful.avd"); - - file.seek(40); - - CursorMan.showMouse(false); - - ::Graphics::Surface picture = _graphics->loadPictureGraphic(file); - _graphics->drawPicture(_graphics->_surface, picture, 5, 169); - picture.free(); - - file.close(); - - CursorMan.showMouse(true); + _graphics->drawToolbar(); _animation->setOldDirection(kDirNone); drawDirection(); } @@ -1751,10 +1712,6 @@ Common::String AvalancheEngine::f5Does() { return Common::String::format("%c", kVerbCodePardon); // If all else fails... } -void AvalancheEngine::setBackgroundColor(byte x) { - warning("STUB: background()"); -} - void AvalancheEngine::hangAroundForAWhile() { for (int i = 0; i < 28; i++) slowDown(); diff --git a/engines/avalanche/enums.h b/engines/avalanche/enums.h index 4abd35c0fc..e10033a64c 100644 --- a/engines/avalanche/enums.h +++ b/engines/avalanche/enums.h @@ -91,4 +91,8 @@ enum MouseCursor { kCurUpArrow = 0, kCurScrewDriver = 1, kCurRightArrow = 2, kCurFletch = 3, kCurWait = 4, kCurHand = 5, kCurCrosshair = 6, kCurIBeam = 7 }; + +static const int16 kScreenWidth = 640; +static const int16 kScreenHeight = 200; + #endif // AVALANCHE_ENUMS_H diff --git a/engines/avalanche/graphics.cpp b/engines/avalanche/graphics.cpp index 744876d27f..9c7c07e748 100644 --- a/engines/avalanche/graphics.cpp +++ b/engines/avalanche/graphics.cpp @@ -147,6 +147,36 @@ void Graphics::loadMouse(byte which) { cursor.free(); } +void Graphics::drawThinkPic(Common::String filename, int id) { + static const int16 kPicSize = 966; + Common::File file; + if (!file.open(filename)) + error("drawThinkPic(): File not found: %s", filename.c_str()); + + file.seek(id * kPicSize + 65); + ::Graphics::Surface picture = loadPictureGraphic(file); + drawPicture(_surface, picture, 205, 170); + + picture.free(); + file.close(); +} + +void Graphics::drawToolbar() { + Common::File file; + if (!file.open("useful.avd")) + error("drawToolbar(): File not found: useful.avd"); + + file.seek(40); + + CursorMan.showMouse(false); + ::Graphics::Surface picture = loadPictureGraphic(file); + drawPicture(_surface, picture, 5, 169); + CursorMan.showMouse(true); + + picture.free(); + file.close(); +} + void Graphics::fleshColors() { g_system->getPaletteManager()->setPalette(_egaPalette[39], 13, 1); g_system->getPaletteManager()->setPalette(_egaPalette[28], 5, 1); @@ -349,6 +379,22 @@ void Graphics::drawDirection(int index, int x, int y) { return picture; } +void Graphics::drawAlsoLines() { + CursorMan.showMouse(false); + + _magics.fillRect(Common::Rect(0, 0, 640, 200), 0); + _magics.frameRect(Common::Rect(0, 45, 640, 161), 15); + + for (int i = 0; i < _vm->_lineNum; i++) { + // We had to check if the lines are within the borders of the screen. + if ((_vm->_lines[i]._x1 >= 0) && (_vm->_lines[i]._x1 < kScreenWidth) && (_vm->_lines[i]._y1 >= 0) && (_vm->_lines[i]._y1 < kScreenHeight) + && (_vm->_lines[i]._x2 >= 0) && (_vm->_lines[i]._x2 < kScreenWidth) && (_vm->_lines[i]._y2 >= 0) && (_vm->_lines[i]._y2 < kScreenHeight)) + _magics.drawLine(_vm->_lines[i]._x1, _vm->_lines[i]._y1, _vm->_lines[i]._x2, _vm->_lines[i]._y2, _vm->_lines[i]._color); + } + + CursorMan.showMouse(true); +} + void Graphics::drawSprite(const SpriteInfo &sprite, byte picnum, int16 x, int16 y) { // First we make the pixels of the spirte blank. for (int j = 0; j < sprite._yLength; j++) { @@ -425,4 +471,9 @@ void Graphics::zoomOut(int16 x, int16 y) { backup.free(); } +// Original name background() +void Graphics::setBackgroundColor(Color x) { + warning("STUB: setBackgroundColor(%d)", x); +} + } // End of namespace Avalanche diff --git a/engines/avalanche/graphics.h b/engines/avalanche/graphics.h index 137d3e4ade..3df59727a5 100644 --- a/engines/avalanche/graphics.h +++ b/engines/avalanche/graphics.h @@ -56,12 +56,6 @@ public: class Graphics { public: - static const int16 kScreenWidth = 640; - static const int16 kScreenHeight = 200; - static const uint16 kBackgroundWidth = kScreenWidth; - static const byte kBackgroundHeight = 8 * 12080 / kScreenWidth; // With 640 width it's 151. - // The 8 = number of bits in a byte, and 12080 comes from Lucerna::load(). - ::Graphics::Surface _surface; ::Graphics::Surface _background; ::Graphics::Surface _magics; // Lucerna::draw_also_lines() draws the "magical" lines here. Further information: https://github.com/urukgit/avalot/wiki/Also @@ -85,20 +79,30 @@ public: void drawText(::Graphics::Surface &surface, const Common::String &text, FontType font, byte fontHeight, int16 x, int16 y, Color color); void drawDigit(int index, int x, int y); void drawDirection(int index, int x, int y); + void drawAlsoLines(); // The caller has to .free() the returned Surfaces!!! // Further information about these two: http://www.shikadi.net/moddingwiki/Raw_EGA_data - ::Graphics::Surface loadPictureGraphic(Common::File &file); // Reads Graphic-planar EGA data. ::Graphics::Surface loadPictureRow(Common::File &file, uint16 width, uint16 height); // Reads Row-planar EGA data. void drawSprite(const SpriteInfo &sprite, byte picnum, int16 x, int16 y); void drawPicture(::Graphics::Surface &target, const ::Graphics::Surface &picture, uint16 destX, uint16 destY); // Can't call .free() here. See showScore() for example. + + void drawThinkPic(Common::String filename, int id); + void drawToolbar(); + void refreshScreen(); void loadBackground(Common::File &file); void refreshBackground(); + void setBackgroundColor(Color x); + void zoomOut(int16 x, int16 y); // Only used when entering the map. private: + static const uint16 kBackgroundWidth = kScreenWidth; + static const byte kBackgroundHeight = 8 * 12080 / kScreenWidth; // With 640 width it's 151. + // The 8 = number of bits in a byte, and 12080 comes from Lucerna::load(). + static const byte kEgaPaletteIndex[16]; ::Graphics::Surface _digits[10]; // digitsize and rwlitesize are defined in loadDigits() !!! ::Graphics::Surface _directions[9]; // Maybe it will be needed to move them to the class itself instead. @@ -107,6 +111,7 @@ private: AvalancheEngine *_vm; + ::Graphics::Surface loadPictureGraphic(Common::File &file); // Reads Graphic-planar EGA data. }; } // End of namespace Avalanche diff --git a/engines/avalanche/parser.cpp b/engines/avalanche/parser.cpp index e4c91a8fed..95bf535f8c 100644 --- a/engines/avalanche/parser.cpp +++ b/engines/avalanche/parser.cpp @@ -1066,10 +1066,10 @@ void Parser::swallow() { // Eat something. } break; case kObjectPotion: - _vm->setBackgroundColor(4); + _vm->_graphics->setBackgroundColor(kColorRed); _vm->_dialogs->displayScrollChain('U', 3); _vm->gameOver(); - _vm->setBackgroundColor(0); + _vm->_graphics->setBackgroundColor(kColorBlack); break; case kObjectInk: _vm->_dialogs->displayScrollChain('U', 4); @@ -1386,7 +1386,7 @@ void Parser::drink() { _vm->dusk(); _vm->hangAroundForAWhile(); _vm->flipRoom(kRoomYours, 1); - _vm->setBackgroundColor(14); + _vm->_graphics->setBackgroundColor(kColorYellow); _vm->_animation->_sprites[0]._visible = false; } } @@ -1414,7 +1414,7 @@ void Parser::standUp() { if (_vm->_avvyIsAwake && _vm->_avvyInBed) { // But he's in bed. if (_vm->_teetotal) { _vm->_dialogs->displayScrollChain('d', 12); - _vm->setBackgroundColor(0); + _vm->_graphics->setBackgroundColor(kColorBlack); _vm->_dialogs->displayScrollChain('d', 14); } _vm->_animation->_sprites[0]._visible = true; diff --git a/engines/avalanche/timer.cpp b/engines/avalanche/timer.cpp index 5576a4826e..1d145e439e 100644 --- a/engines/avalanche/timer.cpp +++ b/engines/avalanche/timer.cpp @@ -562,7 +562,7 @@ void Timer::meetAvaroid() { avvy->_moveX = -3; avvy->_moveY = -5; - _vm->setBackgroundColor(2); + _vm->_graphics->setBackgroundColor(kColorGreen); } } -- cgit v1.2.3