diff options
author | Paul Gilbert | 2018-11-02 22:35:00 -0700 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | 99266b85868beaf1baa37ddc9764ae289c315881 (patch) | |
tree | efc2b2429714053c5072406bcda20dd527b01abb /engines | |
parent | aafaace942f6291682d4d2fb2d0af944844bb906 (diff) | |
download | scummvm-rg350-99266b85868beaf1baa37ddc9764ae289c315881.tar.gz scummvm-rg350-99266b85868beaf1baa37ddc9764ae289c315881.tar.bz2 scummvm-rg350-99266b85868beaf1baa37ddc9764ae289c315881.zip |
GLK: Beginnings of file reference handling
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gargoyle/files.cpp | 97 | ||||
-rw-r--r-- | engines/gargoyle/files.h | 98 | ||||
-rw-r--r-- | engines/gargoyle/gargoyle.cpp | 3 | ||||
-rw-r--r-- | engines/gargoyle/gargoyle.h | 2 | ||||
-rw-r--r-- | engines/gargoyle/glk.cpp | 2 | ||||
-rw-r--r-- | engines/gargoyle/glk.h | 1 | ||||
-rw-r--r-- | engines/gargoyle/glk_types.h | 24 | ||||
-rw-r--r-- | engines/gargoyle/module.mk | 1 | ||||
-rw-r--r-- | engines/gargoyle/streams.h | 10 |
9 files changed, 204 insertions, 34 deletions
diff --git a/engines/gargoyle/files.cpp b/engines/gargoyle/files.cpp new file mode 100644 index 0000000000..c3f1367c66 --- /dev/null +++ b/engines/gargoyle/files.cpp @@ -0,0 +1,97 @@ +/* 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 "gargoyle/files.h" +#include "gui/saveload.h" +#include "common/translation.h" + +namespace Gargoyle { + +frefid_t Files::prompt(glui32 usage, FileMode fmode, glui32 rock) { + switch (usage & fileusage_TypeMask) { + case fileusage_SavedGame: { + if (fmode == filemode_Write) { + // Select a savegame slot + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); + + int slot = dialog->runModalWithCurrentTarget(); + if (slot >= 0) { + Common::String desc = dialog->getResultString(); + return createRef(slot, desc, usage, rock); + } + } else if (fmode == filemode_Read) { + // Load a savegame slot + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); + + int slot = dialog->runModalWithCurrentTarget(); + if (slot >= 0) { + return createRef(slot, "", usage, rock); + } + } else { + error("Unsupport file mode"); + } + break; + } + + case fileusage_Transcript: + return createRef("transcript.txt", fmode, rock); + + default: + error("Unsupport file mode"); + break; + } + + return nullptr; +} + +frefid_t Files::createRef(int slot, const Common::String &desc, glui32 usage, glui32 rock) { + _fileReferences.push_back(FileReference()); + frefid_t fref = &_fileReferences.back(); + + fref->_slotNumber = slot; + fref->_description = desc; + fref->_textMode = ((usage & fileusage_TextMode) != 0); + fref->_fileType = (FileUsage)(usage & fileusage_TypeMask); + return fref; +} + +frefid_t Files::createRef(const Common::String &filename, glui32 usage, glui32 rock) { + _fileReferences.push_back(FileReference()); + frefid_t fref = &_fileReferences.back(); + + fref->_filename = filename; + fref->_textMode = ((usage & fileusage_TextMode) != 0); + fref->_fileType = (FileUsage)(usage & fileusage_TypeMask); + return fref; +} + +void Files::deleteRef(frefid_t fref) { + for (uint idx = 0; idx < _fileReferences.size(); ++idx) { + if (&_fileReferences[idx] == fref) { + _fileReferences.remove_at(idx); + return; + } + } +} + + +} // End of namespace Gargoyle diff --git a/engines/gargoyle/files.h b/engines/gargoyle/files.h new file mode 100644 index 0000000000..cfd757b053 --- /dev/null +++ b/engines/gargoyle/files.h @@ -0,0 +1,98 @@ +/* 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 GARGOYLE_FILES_H +#define GARGOYLE_FILES_H + +#include "gargoyle/glk_types.h" +#include "common/array.h" +#include "common/str.h" + +namespace Gargoyle { + +enum FileUsage { + fileusage_Data = 0x00, + fileusage_SavedGame = 0x01, + fileusage_Transcript = 0x02, + fileusage_InputRecord = 0x03, + fileusage_TypeMask = 0x0f, + + fileusage_TextMode = 0x100, + fileusage_BinaryMode = 0x000, +}; + +enum FileMode { + filemode_Write = 0x01, + filemode_Read = 0x02, + filemode_ReadWrite = 0x03, + filemode_WriteAppend = 0x05, +}; + +enum SeekMode { + seekmode_Start = 0, + seekmode_Current = 1, + seekmode_End = 2, +}; + + +/** + * File details + */ +struct FileReference { + glui32 _rock; + int _slotNumber; + Common::String _description; + Common::String _filename; + FileUsage _fileType; + bool _textMode; + gidispatch_rock_t _dispRock; +}; +typedef FileReference *frefid_t; + +class Files { +private: + Common::Array<FileReference> _fileReferences; +public: + /** + * Prompt for a file + */ + frefid_t prompt(glui32 usage, FileMode fmode, glui32 rock); + + /** + * Create a new file reference + */ + frefid_t createRef(int slot, const Common::String &desc, glui32 usage, glui32 rock); + + /** + * Create a new file reference + */ + frefid_t createRef(const Common::String &filename, glui32 usage, glui32 rock); + + /** + * Delete a file reference + */ + void deleteRef(frefid_t fref); +}; + +} // End of namespace Gargoyle + +#endif diff --git a/engines/gargoyle/gargoyle.cpp b/engines/gargoyle/gargoyle.cpp index 3135fcb5fe..503cf1cd1b 100644 --- a/engines/gargoyle/gargoyle.cpp +++ b/engines/gargoyle/gargoyle.cpp @@ -32,6 +32,7 @@ #include "gargoyle/clipboard.h" #include "gargoyle/conf.h" #include "gargoyle/events.h" +#include "gargoyle/files.h" #include "gargoyle/picture.h" #include "gargoyle/screen.h" #include "gargoyle/streams.h" @@ -54,6 +55,7 @@ GargoyleEngine::~GargoyleEngine() { delete _clipboard; delete _conf; delete _events; + delete _files; delete _picList; delete _screen; delete _streams; @@ -74,6 +76,7 @@ void GargoyleEngine::initialize() { _clipboard = new Clipboard(); _events = new Events(); + _files = new Files(); _picList = new PicList(); _streams = new Streams(); _windows = new Windows(_screen); diff --git a/engines/gargoyle/gargoyle.h b/engines/gargoyle/gargoyle.h index 9677d67706..3538b4c825 100644 --- a/engines/gargoyle/gargoyle.h +++ b/engines/gargoyle/gargoyle.h @@ -36,6 +36,7 @@ namespace Gargoyle { class Clipboard; class Conf; class Events; +class Files; class PicList; class Screen; class Streams; @@ -97,6 +98,7 @@ public: Clipboard *_clipboard; Conf *_conf; Events *_events; + Files *_files; PicList *_picList; Screen *_screen; Streams *_streams; diff --git a/engines/gargoyle/glk.cpp b/engines/gargoyle/glk.cpp index bda0fa74e6..2f9f57ed84 100644 --- a/engines/gargoyle/glk.cpp +++ b/engines/gargoyle/glk.cpp @@ -479,7 +479,7 @@ frefid_t Glk::glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui3 } void Glk::glk_fileref_destroy(frefid_t fref) { - // TODO + _files->deleteRef(fref); } frefid_t Glk::glk_fileref_iterate(frefid_t fref, glui32 *rockptr) { diff --git a/engines/gargoyle/glk.h b/engines/gargoyle/glk.h index 6bfffd6bc6..0124cb1b40 100644 --- a/engines/gargoyle/glk.h +++ b/engines/gargoyle/glk.h @@ -24,6 +24,7 @@ #define GARGOYLE_GLK_H #include "gargoyle/gargoyle.h" +#include "gargoyle/files.h" #include "gargoyle/glk_types.h" #include "gargoyle/time.h" #include "gargoyle/windows.h" diff --git a/engines/gargoyle/glk_types.h b/engines/gargoyle/glk_types.h index 274443a9f9..6ea4408305 100644 --- a/engines/gargoyle/glk_types.h +++ b/engines/gargoyle/glk_types.h @@ -146,30 +146,6 @@ enum WinMethod { winmethod_BorderMask = 0x100, }; -enum FileUsage { - fileusage_Data = 0x00, - fileusage_SavedGame = 0x01, - fileusage_Transcript = 0x02, - fileusage_InputRecord = 0x03, - fileusage_TypeMask = 0x0f, - - fileusage_TextMode = 0x100, - fileusage_BinaryMode = 0x000, -}; - -enum FileMode { - filemode_Write = 0x01, - filemode_Read = 0x02, - filemode_ReadWrite = 0x03, - filemode_WriteAppend = 0x05, -}; - -enum SeekMode { - seekmode_Start = 0, - seekmode_Current = 1, - seekmode_End = 2, -}; - enum StyleHint { stylehint_Indentation = 0, stylehint_ParaIndentation = 1, diff --git a/engines/gargoyle/module.mk b/engines/gargoyle/module.mk index f4422b0b31..306ac8b7a5 100644 --- a/engines/gargoyle/module.mk +++ b/engines/gargoyle/module.mk @@ -5,6 +5,7 @@ MODULE_OBJS := \ conf.o \ detection.o \ events.o \ + files.o \ fonts.o \ gargoyle.o \ glk.o \ diff --git a/engines/gargoyle/streams.h b/engines/gargoyle/streams.h index de8b704033..08d97cb402 100644 --- a/engines/gargoyle/streams.h +++ b/engines/gargoyle/streams.h @@ -25,6 +25,7 @@ #include "common/scummsys.h" #include "common/savefile.h" +#include "gargoyle/files.h" #include "gargoyle/glk_types.h" namespace Gargoyle { @@ -32,15 +33,6 @@ namespace Gargoyle { class Window; class Streams; -struct FileReference { - glui32 _rock; - Common::String _filename; - int _fileType; - int _textMode; - gidispatch_rock_t _dispRock; -}; -typedef FileReference *frefid_t; - struct StreamResult { uint32 _readCount; uint32 _writeCount; |