diff options
-rw-r--r-- | engines/titanic/continue_save_dialog.cpp | 80 | ||||
-rw-r--r-- | engines/titanic/continue_save_dialog.h | 78 | ||||
-rw-r--r-- | engines/titanic/main_game_window.cpp | 32 | ||||
-rw-r--r-- | engines/titanic/main_game_window.h | 2 | ||||
-rw-r--r-- | engines/titanic/module.mk | 1 | ||||
-rw-r--r-- | engines/titanic/support/image.cpp | 113 | ||||
-rw-r--r-- | engines/titanic/support/image.h | 49 |
7 files changed, 212 insertions, 143 deletions
diff --git a/engines/titanic/continue_save_dialog.cpp b/engines/titanic/continue_save_dialog.cpp new file mode 100644 index 0000000000..1db3ba29b8 --- /dev/null +++ b/engines/titanic/continue_save_dialog.cpp @@ -0,0 +1,80 @@ +/* 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 "titanic/continue_save_dialog.h" +#include "titanic/titanic.h" + +namespace Titanic { + +CContinueSaveDialog::CContinueSaveDialog() { + g_vm->_events->addTarget(this); + _highlightedSlot = _selectedSlot = -999; +} + +CContinueSaveDialog::~CContinueSaveDialog() { + g_vm->_events->removeTarget(); +} + +void CContinueSaveDialog::addSavegame(int slot, const CString &name) { + _saves.push_back(SaveEntry(slot, name)); +} + +int CContinueSaveDialog::show() { + // Load images for the dialog + loadImages(); + + // Render the view + render(); + + // Event loop waiting for selection + while (!g_vm->shouldQuit() && _selectedSlot == -999) { + g_vm->_events->pollEventsAndWait(); + } + + return _selectedSlot; +} + +void CContinueSaveDialog::loadImages() { + _backdrop.load("Bitmap/BACKDROP"); + _evilTwin.load("Bitmap/EVILTWIN"); +} + +void CContinueSaveDialog::render() { + Graphics::Screen &screen = *g_vm->_screen; + screen.clear(); + screen.blitFrom(_backdrop, Common::Point(48, 22)); +} + +void CContinueSaveDialog::leftButtonDown(const Point &mousePos) { + +} + +void CContinueSaveDialog::leftButtonUp(const Point &mousePos) { + +} + +void CContinueSaveDialog::keyDown(Common::KeyState keyState) { + if (keyState.keycode == Common::KEYCODE_ESCAPE) + _selectedSlot = EXIT_GAME; +} + +} // End of namespace Titanic diff --git a/engines/titanic/continue_save_dialog.h b/engines/titanic/continue_save_dialog.h new file mode 100644 index 0000000000..0dc0c069db --- /dev/null +++ b/engines/titanic/continue_save_dialog.h @@ -0,0 +1,78 @@ +/* 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 TITANIC_CONTINUE_SAVE_DIALOG_H +#define TITANIC_CONTINUE_SAVE_DIALOG_H + +#include "common/array.h" +#include "titanic/events.h" +#include "titanic/support/image.h" +#include "titanic/support/string.h" + +namespace Titanic { + +#define EXIT_GAME -2 + +class CContinueSaveDialog : public CEventTarget { + struct SaveEntry { + int _slot; + CString _name; + SaveEntry() : _slot(0) {} + SaveEntry(int slot, const CString &name) : _slot(slot), _name(name) {} + }; +private: + Common::Array<SaveEntry> _saves; + int _highlightedSlot, _selectedSlot; + Image _backdrop; + Image _evilTwin; +private: + /** + * Load the images + */ + void loadImages(); + + /** + * Render the dialog + */ + void render(); +public: + CContinueSaveDialog(); + virtual ~CContinueSaveDialog(); + + virtual void leftButtonDown(const Point &mousePos); + virtual void leftButtonUp(const Point &mousePos); + virtual void keyDown(Common::KeyState keyState); + + /** + * Add a savegame to the list to be displayed + */ + void addSavegame(int slot, const CString &name); + + /** + * Show the dialog and wait for a slot to be selected + */ + int show(); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_CONTINUE_SAVE_DIALOG_H */ diff --git a/engines/titanic/main_game_window.cpp b/engines/titanic/main_game_window.cpp index 736154a502..2ecc319257 100644 --- a/engines/titanic/main_game_window.cpp +++ b/engines/titanic/main_game_window.cpp @@ -22,6 +22,7 @@ #include "common/config-manager.h" #include "titanic/titanic.h" +#include "titanic/continue_save_dialog.h" #include "titanic/game_manager.h" #include "titanic/game_view.h" #include "titanic/main_game_window.h" @@ -50,23 +51,22 @@ CMainGameWindow::~CMainGameWindow() { bool CMainGameWindow::Create() { Image image; - bool result = image.loadResource("TITANIC"); - if (!result) - return true; + image.load("TITANIC"); // TODO: Stuff return true; } void CMainGameWindow::applicationStarting() { - // Set up the game project, and get game slot - int saveSlot = loadGame(); - assert(_project); - // Set the video mode CScreenManager *screenManager = CScreenManager::setCurrent(); screenManager->setMode(640, 480, 16, 0, true); + // Set up the game project, and get game slot + int saveSlot = getSavegameSlot(); + if (saveSlot == -2) + return; + // Create game view and manager _gameView = new CSTGameView(this); _gameManager = new CGameManager(_project, _gameView); @@ -96,7 +96,7 @@ void CMainGameWindow::applicationStarting() { _gameManager->initBounds(); } -int CMainGameWindow::loadGame() { +int CMainGameWindow::getSavegameSlot() { _project = new CProjectItem(); _project->setFilename("starship.prj"); @@ -108,7 +108,21 @@ int CMainGameWindow::selectSavegame() { if (ConfMan.hasKey("save_slot")) return ConfMan.getInt("save_slot"); - return -1; + CContinueSaveDialog dialog; + bool hasSavegames = false; + + // Loop through save slots to find any existing save slots + for (int idx = 0; idx < MAX_SAVES; ++idx) { + CString saveName = g_vm->getSavegameName(idx); + if (!saveName.empty()) { + dialog.addSavegame(idx, saveName); + hasSavegames = true; + } + } + + // If there are savegames, show the select dialog and get a choice. + // If there aren't, return -1 to indicate starting a new game + return hasSavegames ? dialog.show() : -1; } void CMainGameWindow::setActiveView(CViewItem *viewItem) { diff --git a/engines/titanic/main_game_window.h b/engines/titanic/main_game_window.h index 7a651ec970..82e24e250e 100644 --- a/engines/titanic/main_game_window.h +++ b/engines/titanic/main_game_window.h @@ -49,7 +49,7 @@ private: * Checks for the presence of any savegames and, if present, * lets the user pick one to resume */ - int loadGame(); + int getSavegameSlot(); /** * Creates the game "project" and determine a game save slot diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index ec3294747e..60a95bc094 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -1,6 +1,7 @@ MODULE := engines/titanic MODULE_OBJS := \ + continue_save_dialog.o \ debugger.o \ detection.o \ events.o \ diff --git a/engines/titanic/support/image.cpp b/engines/titanic/support/image.cpp index cabdd64cf3..1e936b6940 100644 --- a/engines/titanic/support/image.cpp +++ b/engines/titanic/support/image.cpp @@ -20,102 +20,37 @@ * */ -#include "common/file.h" #include "titanic/support/image.h" +#include "titanic/titanic.h" +#include "image/bmp.h" namespace Titanic { -BITMAPINFOHEADER::BITMAPINFOHEADER() { - _biSize = 0; - _biWidth = 0; - _biHeight = 0; - _biPlanes = 0; - _biBitCount = 0; - _biCompression = 0; - _biSizeImage = 0; - _biXPelsPerMeter = 0; - _biYPelsPerMeter = 0; - _biClrUsed = 0; - _biClrImportant = 0; -} - -/*------------------------------------------------------------------------*/ - -RGBQuad::RGBQuad() : _rgbRed(0), _rgbGreen(0), _rgbBlue(0), _rgbReserved(0) {} - -/*------------------------------------------------------------------------*/ - -Image::Image() { - _bitmapInfo = nullptr; - _bits = nullptr; - _flag = true; - - set(16, 16); -} - -void Image::proc6() { - -} - -void Image::set(int width, int height) { - delete _bitmapInfo; - if (_flag && _bitmapInfo) - delete[] _bits; - - _bitmapInfo = new tagBITMAPINFO; - _bits = new byte[(width + 3) & 0xFFFC * height]; - - tagBITMAPINFO &bi = *_bitmapInfo; - bi._bmiHeader._biWidth = width; - bi._bmiHeader._biHeight = height; - bi._bmiHeader._biPlanes = 1; - bi._bmiHeader._biBitCount = 8; -} - -void Image::proc8() { - -} - -bool Image::loadResource(const Common::String &name) { - // This method is hardcoded for the Titanic splash screen resource - assert(name == "TITANIC"); - - Common::File f; - if (!f.open("ST.exe")) - return false; - - // The ST.exe executable has a bitmap called "TITANIC". Since we can't use - // the Windows FindResource function in ScummVM, this is hardcoded for now - f.seek(0x29B660); - uint size = f.readUint32LE(); - if (size != 40) - return false; - - loadBitmap(f); - - return true; -} - -void Image::proc10() { - -} - -void Image::draw() { - +void Image::load(const CString &resName) { + Common::SeekableReadStream *stream = g_vm->_filesManager->getResource(resName); + loadBitmap(*stream); + delete stream; } void Image::loadBitmap(Common::SeekableReadStream &s) { - _bitmapInfo->_bmiHeader._biWidth = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biHeight = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biPlanes = s.readUint16LE(); - _bitmapInfo->_bmiHeader._biBitCount = s.readUint16LE(); - _bitmapInfo->_bmiHeader._biCompression = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biSizeImage = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biXPelsPerMeter = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biYPelsPerMeter = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biClrUsed = s.readUint32LE(); - _bitmapInfo->_bmiHeader._biClrImportant = s.readUint32LE(); - + ::Image::BitmapDecoder decoder; + decoder.loadStream(s); + const Graphics::Surface *src = decoder.getSurface(); + Graphics::PixelFormat scrFormat = g_system->getScreenFormat(); + + if (src->format == scrFormat) { + create(src->w, src->h, scrFormat); + blitFrom(*src); + } else { + // Convert the loaded surface to the screen surface format + const byte *palette = decoder.getPalette(); + Graphics::Surface *surface = src->convertTo(scrFormat, palette); + create(surface->w, surface->h, scrFormat); + blitFrom(*surface); + + surface->free(); + delete surface; + } } } // End of namespace Titanic diff --git a/engines/titanic/support/image.h b/engines/titanic/support/image.h index 9030e81ad7..9876f15c40 100644 --- a/engines/titanic/support/image.h +++ b/engines/titanic/support/image.h @@ -23,58 +23,19 @@ #ifndef TITANIC_IMAGE_H #define TITANIC_IMAGE_H -#include "common/scummsys.h" -#include "common/array.h" +#include "common/stream.h" +#include "graphics/managed_surface.h" +#include "titanic/support/string.h" namespace Titanic { -struct BITMAPINFOHEADER { - int _biSize; - int _biWidth; - int _biHeight; - int _biPlanes; - int _biBitCount; - int _biCompression; - int _biSizeImage; - int _biXPelsPerMeter; - int _biYPelsPerMeter; - int _biClrUsed; - int _biClrImportant; - - BITMAPINFOHEADER(); -}; - -struct RGBQuad { - byte _rgbRed; - byte _rgbGreen; - byte _rgbBlue; - byte _rgbReserved; - - RGBQuad(); -}; - -struct tagBITMAPINFO { - BITMAPINFOHEADER _bmiHeader; - RGBQuad _bmiColors[256]; -}; - -class Image { +class Image : public Graphics::ManagedSurface { private: void loadBitmap(Common::SeekableReadStream &s); public: - tagBITMAPINFO *_bitmapInfo; - byte *_bits; - bool _flag; -public: - Image(); virtual ~Image() {} - virtual void proc6(); - virtual void set(int width, int height); - virtual void proc8(); - virtual bool loadResource(const Common::String &name); - virtual void proc10(); - virtual void draw(); + void load(const CString &resName); }; } // End of namespace Titanic |