From 404c7cd5d33e81c7724cb78dfce5701b26b4659b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 17 Aug 2014 11:14:30 -0400 Subject: ACCESS: Split the bubble box code from Room into it's own file --- engines/access/access.cpp | 3 + engines/access/access.h | 2 + engines/access/bubble_box.cpp | 144 ++++++++++++++++++++++++++++++++++++++++++ engines/access/bubble_box.h | 75 ++++++++++++++++++++++ engines/access/module.mk | 1 + engines/access/room.cpp | 114 --------------------------------- engines/access/room.h | 32 +--------- engines/access/scripts.cpp | 4 +- 8 files changed, 229 insertions(+), 146 deletions(-) create mode 100644 engines/access/bubble_box.cpp create mode 100644 engines/access/bubble_box.h diff --git a/engines/access/access.cpp b/engines/access/access.cpp index d2967c0377..7d12ba5b35 100644 --- a/engines/access/access.cpp +++ b/engines/access/access.cpp @@ -33,6 +33,7 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc) _gameDescription(gameDesc), Engine(syst), _randomSource("Access"), _useItem(_flags[100]), _startup(_flags[170]), _manScaleOff(_flags[172]) { _animation = nullptr; + _bubbleBox = nullptr; _debugger = nullptr; _events = nullptr; _files = nullptr; @@ -102,6 +103,7 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc) AccessEngine::~AccessEngine() { delete _animation; + delete _bubbleBox; delete _debugger; delete _events; delete _files; @@ -142,6 +144,7 @@ void AccessEngine::initialize() { // Create sub-objects of the engine ASurface::init(); _animation = new AnimationManager(this); + _bubbleBox = new BubbleBox(this); _debugger = new Debugger(this); _events = new EventsManager(this); _files = new FileManager(this); diff --git a/engines/access/access.h b/engines/access/access.h index 37be9cfc36..88b6c837a5 100644 --- a/engines/access/access.h +++ b/engines/access/access.h @@ -31,6 +31,7 @@ #include "engines/engine.h" #include "graphics/surface.h" #include "access/animation.h" +#include "access/bubble_box.h" #include "access/data.h" #include "access/debugger.h" #include "access/events.h" @@ -104,6 +105,7 @@ protected: virtual void playGame() = 0; public: AnimationManager *_animation; + BubbleBox *_bubbleBox; Debugger *_debugger; EventsManager *_events; FileManager *_files; diff --git a/engines/access/bubble_box.cpp b/engines/access/bubble_box.cpp new file mode 100644 index 0000000000..2b6d9dd11a --- /dev/null +++ b/engines/access/bubble_box.cpp @@ -0,0 +1,144 @@ +/* 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. + * + */ + +#include "common/algorithm.h" +#include "access/bubble_box.h" +#include "access/access.h" + +namespace Access { + +Box::Box(AccessEngine *vm) : Manager(vm) { + _edgeSize = 0; +} + +void Box::doBox(int item, int box) { + error("TODO: doBox"); +} + +/*------------------------------------------------------------------------*/ + +BubbleBox::BubbleBox(AccessEngine *vm) : Box(vm) { + _bubblePtr = nullptr; + _maxChars = 0; +} + +void BubbleBox::load(Common::SeekableReadStream *stream) { + _bubbleTitle.clear(); + + byte v; + while ((v = stream->readByte()) != 0) + _bubbleTitle += (char)v; + + _bubblePtr = _bubbleTitle.c_str(); +} + +void BubbleBox::clearBubbles() { + _bubbles.clear(); +} + +void BubbleBox::placeBubble() { + BubbleBox::_maxChars = 27; + placeBubble1(); +} + +void BubbleBox::placeBubble1() { + BubbleBox::clearBubbles(); + _vm->_fonts._charSet._lo = 1; + _vm->_fonts._charSet._hi = 8; + _vm->_fonts._charFor._lo = 29; + _vm->_fonts._charFor._hi = 32; + + calcBubble(); + + Common::Rect r = BubbleBox::_bubbles[0]; + r.translate(-2, 0); + _vm->_screen->saveBlock(r); + printBubble(); +} + +void BubbleBox::calcBubble() { + // Save points + Common::Point printOrg = _vm->_fonts._printOrg; + Common::Point printStart = _vm->_fonts._printStart; + + // Figure out maximum width allowed + if (_edgeSize == 4) { + _vm->_fonts._printMaxX = 110; + } else { + _vm->_fonts._printMaxX = _vm->_fonts._font2.stringWidth(BubbleBox::_bubblePtr); + } + + // Start of with a rect with the given starting x and y + Common::Rect bounds(printOrg.x - 2, printOrg.y, printOrg.x - 2, printOrg.y); + + // Loop through getting lines + Common::String msg(BubbleBox::_bubblePtr); + Common::String line; + int width = 0; + bool lastLine; + do { + lastLine = _vm->_fonts._font2.getLine(msg, _vm->_fonts._printMaxX, line, width); + width = MIN(width, _vm->_fonts._printMaxX); + + _vm->_fonts._printOrg.y += 6; + _vm->_fonts._printOrg.x = _vm->_fonts._printStart.x; + } while (!lastLine); + + if (_edgeSize == 4) + ++_vm->_fonts._printOrg.y += 6; + + // Determine the width for the area + width = (((_vm->_fonts._printMaxX >> 4) + 1) << 4) + 5; + if (width >= 24) + width += 20 - ((width - 24) % 20); + bounds.setWidth(width); + + // Determine the height for area + int y = _vm->_fonts._printOrg.y + 6; + if (_edgeSize == 4) + y += 6; + int height = y - bounds.top; + bounds.setHeight(height); + + height -= (_edgeSize == 4) ? 30 : 24; + if (height >= 0) + bounds.setHeight(bounds.height() + 13 - (height % 13)); + + // Add the new bounds to the bubbles list + BubbleBox::_bubbles.push_back(bounds); + + // Restore points + _vm->_fonts._printOrg = printOrg; + _vm->_fonts._printStart = printStart; +} + +void BubbleBox::printBubble() { + //drawBubble(BubbleBox::_bubbles.size() - 1); + error("TODO: printBubble"); +} + +void BubbleBox::drawBubble(int index) { + _bounds = BubbleBox::_bubbles[index]; + doBox(0, 0); +} + +} // End of namespace Access diff --git a/engines/access/bubble_box.h b/engines/access/bubble_box.h new file mode 100644 index 0000000000..e02fa7c572 --- /dev/null +++ b/engines/access/bubble_box.h @@ -0,0 +1,75 @@ +/* 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. + * + */ + +#ifndef ACCESS_BUBBLE_BOX_H +#define ACCESS_BUBBLE_BOX_H + +#include "common/scummsys.h" +#include "common/array.h" +#include "common/rect.h" +#include "common/stream.h" +#include "common/types.h" +#include "graphics/surface.h" +#include "access/data.h" + +namespace Access { + +class AccessEngine; + +class Box: public Manager { +public: + int _edgeSize; + Common::Rect _bounds; +public: + Box(AccessEngine *vm); + + void doBox(int item, int box); +}; + +class BubbleBox: public Box { +public: + Common::String _bubbleTitle; + const char *_bubblePtr; + int _maxChars; + Common::Array _bubbles; +public: + BubbleBox(AccessEngine *vm); + + void load(Common::SeekableReadStream *stream); + + void clearBubbles(); + + void placeBubble(); + void placeBubble1(); + + void calcBubble(); + + void printBubble(); + + void drawBubble(int index); + + +}; + +} // End of namespace Access + +#endif /* ACCESS_BUBBLE_BOX_H */ diff --git a/engines/access/module.mk b/engines/access/module.mk index 6f906a9c21..d74892c241 100644 --- a/engines/access/module.mk +++ b/engines/access/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ animation.o \ asurface.o \ access.o \ + bubble_box.o \ data.o \ debugger.o \ decompress.o \ diff --git a/engines/access/room.cpp b/engines/access/room.cpp index b46363b32d..0405e7c4ac 100644 --- a/engines/access/room.cpp +++ b/engines/access/room.cpp @@ -584,96 +584,6 @@ int Room::validateBox(int boxId) { return _vm->_scripts->executeScript(); } -void Room::placeBubble() { - _bubbleBox._maxChars = 27; - placeBubble1(); -} - -void Room::placeBubble1() { - _bubbleBox.clearBubbles(); - _vm->_fonts._charSet._lo = 1; - _vm->_fonts._charSet._hi = 8; - _vm->_fonts._charFor._lo = 29; - _vm->_fonts._charFor._hi = 32; - - calcBubble(); - - Common::Rect r = _bubbleBox._bubbles[0]; - r.translate(-2, 0); - _vm->_screen->saveBlock(r); - printBubble(); -} - -void Room::calcBubble() { - // Save points - Common::Point printOrg = _vm->_fonts._printOrg; - Common::Point printStart = _vm->_fonts._printStart; - - // Figure out maximum width allowed - if (_bubbleBox._type == 4) { - _vm->_fonts._printMaxX = 110; - } else { - _vm->_fonts._printMaxX = _vm->_fonts._font2.stringWidth(_bubbleBox._bubblePtr); - } - - // Start of with a rect with the given starting x and y - Common::Rect bounds(printOrg.x - 2, printOrg.y, printOrg.x - 2, printOrg.y); - - // Loop through getting lines - Common::String msg(_bubbleBox._bubblePtr); - Common::String line; - int width = 0; - bool lastLine; - do { - lastLine = _vm->_fonts._font2.getLine(msg, _vm->_fonts._printMaxX, line, width); - width = MIN(width, _vm->_fonts._printMaxX); - - _vm->_fonts._printOrg.y += 6; - _vm->_fonts._printOrg.x = _vm->_fonts._printStart.x; - } while (!lastLine); - - if (_bubbleBox._type == 4) - ++_vm->_fonts._printOrg.y += 6; - - // Determine the width for the area - width = (((_vm->_fonts._printMaxX >> 4) + 1) << 4) + 5; - if (width >= 24) - width += 20 - ((width - 24) % 20); - bounds.setWidth(width); - - // Determine the height for area - int y = _vm->_fonts._printOrg.y + 6; - if (_bubbleBox._type == 4) - y += 6; - int height = y - bounds.top; - bounds.setHeight(height); - - height -= (_bubbleBox._type == 4) ? 30 : 24; - if (height >= 0) - bounds.setHeight(bounds.height() + 13 - (height % 13)); - - // Add the new bounds to the bubbles list - _bubbleBox._bubbles.push_back(bounds); - - // Restore points - _vm->_fonts._printOrg = printOrg; - _vm->_fonts._printStart = printStart; -} - -void Room::printBubble() { - //drawBubble(_bubbleBox._bubbles.size() - 1); - error("TODO: printBubble"); -} - -void Room::drawBubble(int index) { - _bubbleBox._bounds = _bubbleBox._bubbles[index]; - doBox(); -} - -void Room::doBox() { - error("TODO: doBox"); -} - /*------------------------------------------------------------------------*/ RoomInfo::RoomInfo(const byte *data) { @@ -732,28 +642,4 @@ RoomInfo::RoomInfo(const byte *data) { } } -/*------------------------------------------------------------------------*/ - -BubbleBox::BubbleBox() { - _type = 2; - _bounds = Common::Rect(64, 32, 130, 122); - _bubblePtr = nullptr; - _maxChars = 0; -} - -void BubbleBox::load(Common::SeekableReadStream *stream) { - _bubbleTitle.clear(); - - byte v; - while ((v = stream->readByte()) != 0) - _bubbleTitle += (char)v; - - _bubblePtr = _bubbleTitle.c_str(); -} - -void BubbleBox::clearBubbles() { - _bubbles.clear(); -} - - } // End of namespace Access diff --git a/engines/access/room.h b/engines/access/room.h index 22dbd16411..f76db6f681 100644 --- a/engines/access/room.h +++ b/engines/access/room.h @@ -58,22 +58,6 @@ public: } }; -class BubbleBox { -public: - int _type; - Common::Rect _bounds; - Common::String _bubbleTitle; - const char *_bubblePtr; - int _maxChars; - Common::Array _bubbles; -public: - BubbleBox(); - - void load(Common::SeekableReadStream *stream); - - void clearBubbles(); -}; - class Room: public Manager { private: void roomLoop(); @@ -125,10 +109,11 @@ protected: virtual void roomMenu() = 0; virtual void mainAreaClick() = 0; +public: + virtual void setIconPalette() {} public: Plotter _plotter; Common::Array _jetFrame; - BubbleBox _bubbleBox; int _function; int _roomFlag; byte *_playField; @@ -156,21 +141,8 @@ public: void buildRow(int playY, int screenY); void init4Quads(); - - virtual void setIconPalette() {} - void placeBubble(); - void placeBubble1(); - - void calcBubble(); - - void printBubble(); - - void drawBubble(int index); - - void doBox(); }; - class RoomInfo { public: struct FileIdent { diff --git a/engines/access/scripts.cpp b/engines/access/scripts.cpp index f781ec14d0..f91b49c9ef 100644 --- a/engines/access/scripts.cpp +++ b/engines/access/scripts.cpp @@ -117,7 +117,7 @@ void Scripts::executeCommand(int commandIndex) { } void Scripts::CMDOBJECT() { - _vm->_room->_bubbleBox.load(_data); + _vm->_bubbleBox->load(_data); } void Scripts::CMDENDOBJECT() { error("TODO ENDOBJECT"); } @@ -176,7 +176,7 @@ void Scripts::cmdPrint() { _vm->_timers[PRINT_TIMER]._initTm = 50; _vm->_timers[PRINT_TIMER]._flag = true; - _vm->_room->placeBubble(); + _vm->_bubbleBox->placeBubble(); _vm->_events->waitKeyMouse(); while (_vm->_timers[PRINT_TIMER]._flag) { -- cgit v1.2.3