[Scummvm-cvs-logs] SF.net SVN: scummvm: [25496] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Feb 11 22:17:44 CET 2007


Revision: 25496
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25496&view=rev
Author:   peres001
Date:     2007-02-11 13:17:37 -0800 (Sun, 11 Feb 2007)

Log Message:
-----------
added load/save support

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/loadsave.cpp
    scummvm/trunk/engines/parallaction/menu.cpp
    scummvm/trunk/engines/parallaction/parallaction.h

Modified: scummvm/trunk/engines/parallaction/loadsave.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/loadsave.cpp	2007-02-11 20:16:35 UTC (rev 25495)
+++ scummvm/trunk/engines/parallaction/loadsave.cpp	2007-02-11 21:17:37 UTC (rev 25496)
@@ -29,28 +29,45 @@
 
 #include "common/savefile.h"
 
+#include "gui/widget.h"
+#include "gui/ListWidget.h"
+#include "gui/message.h"
+
+/* Nippon Safes savefiles are called 'game.1' to 'game.10'. The game conventiently allows users to
+ * give meanigful name to savegames, and it uses an extra file 'savegame' to keep track of these
+ * names.
+ *
+ * This re-implementation disposes of the extra file to make moving of savefiles easier. Debugging
+ * will benefit from this, too. The savegame name is written as the first line of the savefile
+ * itself, thus breaking compatibility with the original version. Who cares anyway?
+ */
+
+
 namespace Parallaction {
 
 
 extern char _gameNames[][20];
 
-void Parallaction::doLoadGame(uint16 _di) {
+void Parallaction::doLoadGame(uint16 slot) {
 
 	_introSarcData3 = 200;
 	_introSarcData2 = 1;
 
 	char filename[PATH_LEN];
-	sprintf(filename, "game.%d", _di);
+	sprintf(filename, "game.%i", slot);
 
 	Common::InSaveFile *f = _saveFileMan->openForLoading(filename);
 	if (!f) return;
 
+    char s[20];
+
+    f->readLine(s, 19);
+
 	f->readLine(_vm->_characterName, 15);
 	f->readLine(_location, 15);
 
 	strcat(_location, ".");
 
-	char s[20];
 	f->readLine(s, 15);
 	_firstPosition._x = atoi(s);
 
@@ -122,47 +139,39 @@
 	strcat(_location, _vm->_characterName);
 	_engineFlags |= kEngineChangeLocation;
 
+#if 0
 	printf("game loaded: character %s, location %s\n", _vm->_characterName, _location);
-//	  getch();
+#endif
 
 	return;
 }
 
 
+void Parallaction::doSaveGame(uint16 slot, const char* name) {
 
-
-// FIXME: implements this (select a file slot for load/save)
-int16 selectSaveFile(uint16 arg_0) {
-	return 0;
-}
-
-
-
-void Parallaction::loadGame() {
-
-	bool marks[10];
-	_saveFileMan->listSavefiles("game.", marks, 10);
-
-	int16 _di = selectSaveFile( 0 );
-	if (_di > 10) return;
-
-	doLoadGame(_di);
-
-	return;
-}
-
-void Parallaction::doSaveGame(uint16 _di) {
-
 	char path[PATH_LEN];
-	sprintf(path, "game.%d", _di);
+	sprintf(path, "game.%i", slot);
 
 	Common::OutSaveFile *f = _saveFileMan->openForSaving(path);
-	// FIXME: Properly handle openForSaving failures instead of
-	// just crashing silently!
-	assert(f);
+	if (f == 0) {
+	    char buf[32];
+	    sprintf(buf, "Can't save game in slot %i\n\n(%s)", slot, path);
+	    GUI::MessageDialog dialog(buf);
+        dialog.runModal();
+        return;
+	}
 
 	char s[30];
 
+    if (!name || name[0] == '\0') {
+        sprintf(s, "default_%i", slot);
+    } else {
+        strncpy(s, name, 29);
+    }
+
+    f->writeString(s);
+    f->writeString("\n");
+
 	if (_engineFlags & kEngineMiniDonna) {
 		sprintf(s, "%stras\n", _vm->_characterName);
 	} else {
@@ -209,29 +218,7 @@
 
 
 
-void Parallaction::saveGame() {
 
-//	strcpy(v30, asc_1C91A);
-
-	if (!scumm_stricmp(_location, "caveau")) return;
-
-	bool marks[10];
-	_saveFileMan->listSavefiles("game.", marks, 10);
-
-	int16 _di = selectSaveFile( 1 );
-	if (_di > 10) return;
-
-
-	printf("saving game %i...", _di);
-	doSaveGame(_di);
-	printf("done\n");
-//	  getch();
-
-	return;
-
-
-}
-
 #if 0
 int16 selectSaveFile(uint16 arg_0) {
 
@@ -531,4 +518,266 @@
 
 
 
+enum {
+	kSaveCmd = 'SAVE',
+	kLoadCmd = 'LOAD',
+	kPlayCmd = 'PLAY',
+	kOptionsCmd = 'OPTN',
+	kHelpCmd = 'HELP',
+	kAboutCmd = 'ABOU',
+	kQuitCmd = 'QUIT',
+	kChooseCmd = 'CHOS'
+};
+
+
+
+SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, Parallaction *engine)
+	: Dialog("scummsaveload"), _list(0), _chooseButton(0), _gfxWidget(0), _vm(engine) {
+
+//	_drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR;
+
+	new GUI::StaticTextWidget(this, "scummsaveload_title", title);
+
+	// Add choice list
+	_list = new GUI::ListWidget(this, "scummsaveload_list");
+	_list->setEditable(true);
+	_list->setNumberingMode(GUI::kListNumberingOne);
+
+	_container = new GUI::ContainerWidget(this, 0, 0, 10, 10);
+	_container->setHints(GUI::THEME_HINT_USE_SHADOW);
+
+	_gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10);
+
+	_date = new GUI::StaticTextWidget(this, 0, 0, 10, 10, "No date saved", GUI::kTextAlignCenter);
+	_time = new GUI::StaticTextWidget(this, 0, 0, 10, 10, "No time saved", GUI::kTextAlignCenter);
+	_playtime = new GUI::StaticTextWidget(this, 0, 0, 10, 10, "No playtime saved", GUI::kTextAlignCenter);
+
+	// Buttons
+	new GUI::ButtonWidget(this, "scummsaveload_cancel", "Cancel", GUI::kCloseCmd, 0);
+	_chooseButton = new GUI::ButtonWidget(this, "scummsaveload_choose", buttonLabel, kChooseCmd, 0);
+	_chooseButton->setEnabled(false);
+}
+
+SaveLoadChooser::~SaveLoadChooser() {
+}
+
+const Common::String &SaveLoadChooser::getResultString() const {
+	return _list->getSelectedString();
+}
+
+void SaveLoadChooser::setList(const StringList& list) {
+	_list->setList(list);
+}
+
+int SaveLoadChooser::runModal() {
+	if (_gfxWidget)
+		_gfxWidget->setGfx(0);
+	int ret = GUI::Dialog::runModal();
+	return ret;
+}
+
+void SaveLoadChooser::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
+	int selItem = _list->getSelected();
+	switch (cmd) {
+	case GUI::kListItemActivatedCmd:
+	case GUI::kListItemDoubleClickedCmd:
+		if (selItem >= 0) {
+			if (!getResultString().empty()) {
+				_list->endEditMode();
+				setResult(selItem);
+				close();
+			}
+		}
+		break;
+	case kChooseCmd:
+		_list->endEditMode();
+		setResult(selItem);
+		close();
+		break;
+	case GUI::kListSelectionChangedCmd: {
+		if (_gfxWidget) {
+			updateInfos();
+		}
+
+        _list->startEditMode();
+		// Disable button if nothing is selected, or (in load mode) if an empty
+		// list item is selected. We allow choosing an empty item in save mode
+		// because we then just assign a default name.
+		_chooseButton->setEnabled(selItem >= 0 && (!getResultString().empty()));
+		_chooseButton->draw();
+	} break;
+	case GUI::kCloseCmd:
+		setResult(-1);
+	default:
+		Dialog::handleCommand(sender, cmd, data);
+	}
+}
+
+void SaveLoadChooser::reflowLayout() {
+    _container->setFlags(GUI::WIDGET_INVISIBLE);
+    _gfxWidget->setFlags(GUI::WIDGET_INVISIBLE);
+    _date->setFlags(GUI::WIDGET_INVISIBLE);
+    _time->setFlags(GUI::WIDGET_INVISIBLE);
+    _playtime->setFlags(GUI::WIDGET_INVISIBLE);
+
+	Dialog::reflowLayout();
+}
+
+void SaveLoadChooser::updateInfos() {
+/*	int selItem = _list->getSelected();
+	Graphics::Surface *thumb;
+	thumb = _vm->loadThumbnailFromSlot(selItem + 1);
+
+	if (thumb) {
+		_gfxWidget->setGfx(thumb);
+		_gfxWidget->useAlpha(256);
+		thumb->free();
+	} else {
+		_gfxWidget->setGfx(-1, -1, _fillR, _fillG, _fillB);
+	}
+
+	delete thumb;
+	_gfxWidget->draw();
+
+	InfoStuff infos;
+	memset(&infos, 0, sizeof(InfoStuff));
+	char buffer[32];
+	if (_vm->loadInfosFromSlot(selItem + 1, &infos)) {
+		snprintf(buffer, 32, "Date: %.2d.%.2d.%.4d",
+			(infos.date >> 24) & 0xFF, (infos.date >> 16) & 0xFF,
+			infos.date & 0xFFFF);
+		_date->setLabel(buffer);
+		_date->draw();
+
+		snprintf(buffer, 32, "Time: %.2d:%.2d",
+			(infos.time >> 8) & 0xFF, infos.time & 0xFF);
+		_time->setLabel(buffer);
+		_time->draw();
+
+		int minutes = infos.playtime / 60;
+		int hours = minutes / 60;
+		minutes %= 60;
+
+		snprintf(buffer, 32, "Playtime: %.2d:%.2d",
+			hours & 0xFF, minutes & 0xFF);
+		_playtime->setLabel(buffer);
+		_playtime->draw();
+	} else {
+		snprintf(buffer, 32, "No date saved");
+		_date->setLabel(buffer);
+		_date->draw();
+
+		snprintf(buffer, 32, "No time saved");
+		_time->setLabel(buffer);
+		_time->draw();
+
+		snprintf(buffer, 32, "No playtime saved");
+		_playtime->setLabel(buffer);
+		_playtime->draw();
+	}
+*/
+}
+
+int Parallaction::buildSaveFileList(Common::StringList& l) {
+
+    char name[16];
+    char buf[30];
+
+    int count = 0;
+
+    for (int i = 0; i < 10; i++) {
+        sprintf(name, "game.%i", i);
+
+        buf[0] = '\0';
+        Common::InSaveFile *f = _saveFileMan->openForLoading(name);
+
+        if (f) {
+            f->readLine(buf, 29);
+            delete f;
+
+            count++;
+        }
+
+        l.push_back(buf);
+    }
+
+    return count;
+}
+
+
+int Parallaction::selectSaveFile(uint16 arg_0) {
+
+    const Common::String caption[2] = {
+        "Load file",
+        "Save file"
+    };
+
+    const Common::String button[2] = {
+        "Load",
+        "Save"
+    };
+
+    SaveLoadChooser* slc = new SaveLoadChooser(caption[arg_0], button[arg_0], _vm);
+
+	Common::StringList l;
+
+    int count = buildSaveFileList(l);
+    slc->setList(l);
+
+    int idx = slc->runModal();
+    _saveFileName = slc->getResultString();
+    delete slc;
+
+	return idx;
+}
+
+
+
+void Parallaction::loadGame() {
+
+    char buf[32];
+
+	int _di = selectSaveFile( 0 );
+	if (_di == -1) {
+	    return;
+	}
+
+	doLoadGame(_di);
+
+    GUI::TimedMessageDialog dialog("Loading game...", 1500);
+    dialog.runModal();
+
+	changeCursor(kCursorArrow);
+
+	return;
+}
+
+
+void Parallaction::saveGame() {
+
+//	strcpy(v30, asc_1C91A);
+
+	if (!scumm_stricmp(_location, "caveau")) return;
+
+    char buf[32];
+
+	int slot = selectSaveFile( 1 );
+	if (slot == -1) {
+	    return;
+	}
+
+	doSaveGame(slot, _saveFileName.c_str());
+
+    GUI::TimedMessageDialog dialog("Saving game...", 1500);
+    dialog.runModal();
+
+	return;
+
+
+}
+
+
+
+
+
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/menu.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/menu.cpp	2007-02-11 20:16:35 UTC (rev 25495)
+++ scummvm/trunk/engines/parallaction/menu.cpp	2007-02-11 21:17:37 UTC (rev 25496)
@@ -284,7 +284,7 @@
 	strcpy(_location, "fogne");
 	strcpy(_engine->_characterName, "dough");
 
-//	loadGame();
+	_vm->loadGame();
 	closeArchive();
 
 	return 1;  // load game

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-02-11 20:16:35 UTC (rev 25495)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-02-11 21:17:37 UTC (rev 25496)
@@ -26,8 +26,16 @@
 #include "engines/engine.h"
 #include "parallaction/defs.h"
 #include "parallaction/inventory.h"
+#include "common/str.h"
+#include "gui/dialog.h"
+#include "gui/widget.h"
 
+namespace GUI {
+	class ListWidget;
+	class CommandSender;
+}
 
+
 namespace Parallaction {
 
 // high values mean high priority
@@ -290,8 +298,11 @@
 	void		initGame();
 	void		initGlobals();
 
-	void		doLoadGame(uint16 _di);
-	void		doSaveGame(uint16 _di);
+    Common::String      _saveFileName;
+    int         buildSaveFileList(Common::StringList& l);
+    int         selectSaveFile(uint16 arg_0);
+	void		doLoadGame(uint16 slot);
+	void		doSaveGame(uint16 slot, const char* name);
 
 	void		runGame();
 	InputData * translateInput();
@@ -315,7 +326,35 @@
 // FIXME: remove global
 extern Parallaction *_vm;
 
+class SaveLoadChooser : public GUI::Dialog {
+	typedef Common::String String;
+	typedef Common::StringList StringList;
+protected:
+	GUI::ListWidget		*_list;
+	GUI::ButtonWidget	*_chooseButton;
+	GUI::GraphicsWidget	*_gfxWidget;
+	GUI::StaticTextWidget	*_date;
+	GUI::StaticTextWidget	*_time;
+	GUI::StaticTextWidget	*_playtime;
+	GUI::ContainerWidget	*_container;
+	Parallaction			*_vm;
 
+	uint8 _fillR, _fillG, _fillB;
+
+	void updateInfos();
+public:
+	SaveLoadChooser(const String &title, const String &buttonLabel, Parallaction *engine);
+	~SaveLoadChooser();
+
+	virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
+	const String &getResultString() const;
+	void setList(const StringList& list);
+	int runModal();
+
+	virtual void reflowLayout();
+};
+
+
 } // namespace Parallaction
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list