Permalink
Browse files

BLADERUNNER: Add in-game saving screen

  • Loading branch information...
peterkohaut committed Dec 5, 2018
1 parent 216d474 commit 1855d1cf13de5c9f4cf84fc07ab4b5053cae5295
@@ -221,9 +221,7 @@ bool BladeRunnerEngine::canLoadGameStateCurrently() {
}
Common::Error BladeRunnerEngine::loadGameState(int slot) {
const Common::String saveName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
Common::InSaveFile *saveFile = getSaveFileManager()->openForLoading(saveName);
Common::InSaveFile *saveFile = BladeRunner::SaveFileManager::openForLoading(_targetName, slot);
if (saveFile == nullptr || saveFile->err()) {
delete saveFile;
return Common::kReadingFailed;
@@ -253,9 +251,7 @@ bool BladeRunnerEngine::canSaveGameStateCurrently() {
}
Common::Error BladeRunnerEngine::saveGameState(int slot, const Common::String &desc) {
const Common::String saveName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(saveName);
Common::OutSaveFile *saveFile = BladeRunner::SaveFileManager::openForSaving(_targetName, slot);
if (saveFile == nullptr || saveFile->err()) {
delete saveFile;
return Common::kReadingFailed;
@@ -1097,6 +1093,7 @@ void BladeRunnerEngine::handleKeyDown(Common::Event &event) {
if (_kia->isOpen()) {
_kia->handleKeyDown(event.kbd);
return;
}
if (_spinner->isOpen()) {
@@ -95,8 +95,7 @@ int BladeRunnerMetaEngine::getMaximumSaveSlot() const {
}
void BladeRunnerMetaEngine::removeSaveState(const char *target, int slot) const {
Common::String filename = Common::String::format("%s.%03d", target, slot);
g_system->getSavefileManager()->removeSavefile(filename);
BladeRunner::SaveFileManager::remove(target, slot);
}
SaveStateDescriptor BladeRunnerMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
@@ -259,6 +259,7 @@ MODULE_OBJS = \
ui/kia_section_help.o \
ui/kia_section_load.o \
ui/kia_section_pogo.o \
ui/kia_section_save.o \
ui/kia_section_settings.o \
ui/kia_section_suspects.o \
ui/kia_shapes.o \
@@ -78,6 +78,21 @@ SaveStateDescriptor SaveFileManager::queryMetaInfos(const Common::String &target
return desc;
}
Common::InSaveFile *SaveFileManager::openForLoading(const Common::String &target, int slot) {
Common::String filename = Common::String::format("%s.%03d", target.c_str(), slot);
return g_system->getSavefileManager()->openForLoading(filename);
}
Common::OutSaveFile *SaveFileManager::openForSaving(const Common::String &target, int slot) {
Common::String filename = Common::String::format("%s.%03d", target.c_str(), slot);
return g_system->getSavefileManager()->openForSaving(filename);
}
void SaveFileManager::remove(const Common::String &target, int slot) {
Common::String filename = Common::String::format("%s.%03d", target.c_str(), slot);
g_system->getSavefileManager()->removeSavefile(filename);
}
bool SaveFileManager::readHeader(Common::SeekableReadStream &in, SaveFileHeader &header, bool skipThumbnail) {
SaveFileReadStream s(in);
@@ -25,6 +25,7 @@
#include "common/array.h"
#include "common/memstream.h"
#include "common/savefile.h"
#include "common/types.h"
#include "graphics/surface.h"
@@ -67,8 +68,14 @@ class SaveFileManager {
static SaveStateList list(const Common::String &target);
static SaveStateDescriptor queryMetaInfos(const Common::String &target, int slot);
static Common::InSaveFile *openForLoading(const Common::String &target, int slot);
static Common::OutSaveFile *openForSaving(const Common::String &target, int slot);
static void remove(const Common::String &target, int slot);
static bool readHeader(Common::SeekableReadStream &in, SaveFileHeader &header, bool skipThumbnail = true);
static bool writeHeader(Common::WriteStream &out, SaveFileHeader &header);
};
class SaveFileWriteStream : public Common::WriteStream {
@@ -115,14 +115,15 @@ class KIA {
int _pogoPos;
Graphics::Surface _thumbnail;
public:
bool _forceOpen;
bool _forceOpen;
KIALog *_log;
KIAScript *_script;
KIAShapes *_shapes;
KIALog *_log;
KIAScript *_script;
KIAShapes *_shapes;
Graphics::Surface _thumbnail;
public:
KIA(BladeRunnerEngine *vm);
@@ -45,10 +45,10 @@ class KIASectionClues : public KIASectionBase {
int flags;
};
UIContainer *_uiContainer;
UIImagePicker *_buttons;
UIScrollBox *_cluesScrollBox;
UIScrollBox *_filterScrollBox;
UIContainer *_uiContainer;
UIImagePicker *_buttons;
UIScrollBox *_cluesScrollBox;
UIScrollBox *_filterScrollBox;
bool _isOpen;
bool _debugIntangible;
@@ -35,8 +35,6 @@
#include "common/error.h"
#include "common/system.h"
#include "engines/savestate.h"
namespace BladeRunner {
KIASectionLoad::KIASectionLoad(BladeRunnerEngine *vm) : KIASectionBase(vm) {
@@ -56,47 +54,48 @@ void KIASectionLoad::open() {
_scrollBox->show();
_scrollBox->clearLines();
SaveStateList saveList = SaveFileManager::list(_vm->getTargetName());
_saveSlotMax = -1;
_saveList = SaveFileManager::list(_vm->getTargetName());
if (!saveList.empty()) {
if (!_saveList.empty()) {
_scrollBox->addLine(_vm->_textOptions->getText(36), -1, 4); // Load game:
for (Common::Array<SaveStateDescriptor>::iterator save = saveList.begin(); save != saveList.end(); save++) {
_scrollBox->addLine(save->getDescription(), save->getSaveSlot(), 0);
_saveSlotMax = MAX(_saveSlotMax, save->getSaveSlot());
for (uint i = 0; i < _saveList.size(); ++i) {
_scrollBox->addLine(_saveList[i].getDescription(), i, 0);
}
_scrollBox->addLine("", -1, 4);
}
_newGameEasyLineId = _saveList.size();
_newGameMediumLineId = _saveList.size() + 1;
_newGameHardLineId = _saveList.size() + 2;
_scrollBox->addLine(_vm->_textOptions->getText(37), -1, 4); // New game:
_scrollBox->addLine(_vm->_textOptions->getText(20), _saveSlotMax + 1, 0); // Easy
_scrollBox->addLine(_vm->_textOptions->getText(28), _saveSlotMax + 2, 0); // Medium
_scrollBox->addLine(_vm->_textOptions->getText(29), _saveSlotMax + 3, 0); // Hard
_scrollBox->addLine(_vm->_textOptions->getText(20), _newGameEasyLineId, 0); // Easy
_scrollBox->addLine(_vm->_textOptions->getText(28), _newGameMediumLineId, 0); // Medium
_scrollBox->addLine(_vm->_textOptions->getText(29), _newGameHardLineId, 0); // Hard
_hoveredSaveSlot = -1;
_hoveredLineId = -1;
_timeLast = _vm->getTotalPlayTime();
_timeLeft = 800;
}
void KIASectionLoad::close() {
_scrollBox->hide();
_vm->_kia->playerReset();
_saveList.clear();
}
void KIASectionLoad::draw(Graphics::Surface &surface){
_vm->_kia->_shapes->get(69)->draw(surface, 501, 123);
_uiContainer->draw(surface);
int selectedSaveSlot = _scrollBox->getSelectedLineData();
int selectedLineId = _scrollBox->getSelectedLineData();
if (_hoveredSaveSlot != selectedSaveSlot) {
if (selectedSaveSlot >= 0) {
if (_hoveredLineId != selectedLineId) {
if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size()) {
if (_timeLeft == 0) {
SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), selectedSaveSlot);
SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), selectedLineId);
const Graphics::Surface *thumbnail = desc.getThumbnail();
if (thumbnail != nullptr) {
_vm->_kia->playImage(*thumbnail);
@@ -106,15 +105,15 @@ void KIASectionLoad::draw(Graphics::Surface &surface){
_vm->_kia->playerReset();
_timeLeft = 800;
}
_hoveredSaveSlot = selectedSaveSlot;
_hoveredLineId = selectedLineId;
}
uint32 now = _vm->getTotalPlayTime();
if (selectedSaveSlot >= 0) {
if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size()) {
if (_timeLeft) {
uint32 timeDiff = now - _timeLast;
if (timeDiff >= _timeLeft) {
SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), selectedSaveSlot);
SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), _saveList[selectedLineId].getSaveSlot());
const Graphics::Surface *thumbnail = desc.getThumbnail();
if (thumbnail != nullptr) {
_vm->_kia->playImage(*thumbnail);
@@ -144,11 +143,11 @@ void KIASectionLoad::scrollBoxCallback(void *callbackData, void *source, int lin
KIASectionLoad *self = (KIASectionLoad *)callbackData;
if (mouseButton == 0 && source == self->_scrollBox && lineData >= 0) {
if (lineData == self->_saveSlotMax + 1) {
if (lineData == self->_newGameEasyLineId) {
self->_vm->newGame(0);
} else if (lineData == self->_saveSlotMax + 2) {
} else if (lineData == self->_newGameMediumLineId) {
self->_vm->newGame(1);
} else if (lineData == self->_saveSlotMax + 3) {
} else if (lineData == self->_newGameHardLineId) {
self->_vm->newGame(2);
} else {
self->_vm->loadGameState(lineData);
@@ -28,6 +28,8 @@
#include "common/scummsys.h"
#include "common/str.h"
#include "engines/savestate.h"
namespace Graphics {
struct Surface;
}
@@ -38,33 +40,31 @@ class UIContainer;
class UIScrollBox;
class KIASectionLoad : public KIASectionBase {
UIContainer *_uiContainer;
UIScrollBox *_scrollBox;
struct Save {
Common::String name;
int slotNum;
};
UIContainer *_uiContainer;
UIScrollBox *_scrollBox;
uint32 _timeLast;
uint32 _timeLeft;
uint32 _timeLast;
uint32 _timeLeft;
SaveStateList _saveList;
int _hoveredSaveSlot;
int _saveSlotMax;
int _hoveredLineId;
int _newGameEasyLineId;
int _newGameMediumLineId;
int _newGameHardLineId;
public:
KIASectionLoad(BladeRunnerEngine *vm);
~KIASectionLoad();
void open();
void close();
void open() override;
void close() override;
void draw(Graphics::Surface &surface);
void draw(Graphics::Surface &surface) override;
void handleMouseMove(int mouseX, int mouseY);
void handleMouseDown(bool mainButton);
void handleMouseUp(bool mainButton);
void handleMouseMove(int mouseX, int mouseY) override;
void handleMouseDown(bool mainButton) override;
void handleMouseUp(bool mainButton) override;
private:
static void scrollBoxCallback(void *callbackData, void *source, int lineData, int mouseButton);
Oops, something went wrong.

0 comments on commit 1855d1c

Please sign in to comment.