[Scummvm-cvs-logs] SF.net SVN: scummvm:[34583] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Sep 16 16:56:03 CEST 2008


Revision: 34583
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34583&view=rev
Author:   lordhoto
Date:     2008-09-16 14:56:02 +0000 (Tue, 16 Sep 2008)

Log Message:
-----------
Added support for SCUMM savestates date/time and playtime info in the launcher load dialog.

Modified Paths:
--------------
    scummvm/trunk/base/game.cpp
    scummvm/trunk/base/game.h
    scummvm/trunk/engines/metaengine.h
    scummvm/trunk/engines/scumm/detection.cpp
    scummvm/trunk/engines/scumm/saveload.cpp
    scummvm/trunk/engines/scumm/scumm.h
    scummvm/trunk/gui/launcher.cpp

Modified: scummvm/trunk/base/game.cpp
===================================================================
--- scummvm/trunk/base/game.cpp	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/base/game.cpp	2008-09-16 14:56:02 UTC (rev 34583)
@@ -96,3 +96,21 @@
 	setVal("is_deletable", state ? "true" : "false");
 }
 
+void SaveStateDescriptor::setSaveDate(int year, int month, int day) {
+	char buffer[32];
+	snprintf(buffer, 32, "%.2d.%.2d.%.4d", day, month, year);
+	setVal("save_date", buffer);
+}
+
+void SaveStateDescriptor::setSaveTime(int hour, int min) {
+	char buffer[32];
+	snprintf(buffer, 32, "%.2d:%.2d", hour, min);
+	setVal("save_time", buffer);
+}
+
+void SaveStateDescriptor::setPlayTime(int hours, int minutes) {
+	char buffer[32];
+	snprintf(buffer, 32, "%.2d:%.2d", hours, minutes);
+	setVal("play_time", buffer);
+}
+

Modified: scummvm/trunk/base/game.h
===================================================================
--- scummvm/trunk/base/game.h	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/base/game.h	2008-09-16 14:56:02 UTC (rev 34583)
@@ -187,6 +187,21 @@
 	const Graphics::Surface *getThumbnail() const { return _thumbnail.get(); }
 	
 	void setThumbnail(Graphics::Surface *t);
+
+	/**
+	 * Sets the 'save_date' key properly, based on the given values
+	 */
+	void setSaveDate(int year, int month, int day);
+
+	/**
+	 * Sets the 'save_time' key properly, based on the given values
+	 */
+	void setSaveTime(int hour, int min);
+
+	/**
+	 * Sets the 'play_time' key properly, based on the given values
+	 */
+	void setPlayTime(int hours, int minutes);
 };
 
 /** List of savestates. */

Modified: scummvm/trunk/engines/metaengine.h
===================================================================
--- scummvm/trunk/engines/metaengine.h	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/engines/metaengine.h	2008-09-16 14:56:02 UTC (rev 34583)
@@ -151,10 +151,26 @@
 
 		/**
 		 * Features a thumbnail in savegames (i.e. includes a thumbnail
-		 * in savestates returned via querySaveMetaInfo). This flag may 
-		 * only be set when 'kSupportsMetaInfos' is set.
+		 * in savestates returned via querySaveMetaInfo).
+		 * This flag may only be set when 'kSupportsMetaInfos' is set.
 		 */
-		kSupportsThumbnails		= 5
+		kSupportsThumbnails		= 5,
+
+		/**
+		 * Features 'save_date' and 'save_time' entries in the 
+		 * savestate returned by querySaveMetaInfo. Those values
+		 * indicate the date/time the savegame was created.
+		 * This flag may only be set when 'kSupportsMetaInfos' is set.
+		 */
+		kSupportsSaveDate		= 6,
+
+		/**
+		 * Features 'play_time' entry in the savestate returned by
+		 * querySaveMetaInfo. It indicates how long the user played
+		 * the game till the save.
+		 * This flag may only be set when 'kSupportsMetaInfos' is set.
+		 */
+		kSupportsSavePlayTime	= 7
 	};	
 
 	/**

Modified: scummvm/trunk/engines/scumm/detection.cpp
===================================================================
--- scummvm/trunk/engines/scumm/detection.cpp	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/engines/scumm/detection.cpp	2008-09-16 14:56:02 UTC (rev 34583)
@@ -693,7 +693,9 @@
 		(f == kSupportsDirectLoad) ||
 		(f == kSupportsDeleteSave) ||
 		(f == kSupportsMetaInfos) ||
-		(f == kSupportsThumbnails);
+		(f == kSupportsThumbnails) ||
+		(f == kSupportsSaveDate) ||
+		(f == kSupportsSavePlayTime);
 }
 
 GameList ScummMetaEngine::getSupportedGames() const {
@@ -1002,6 +1004,27 @@
 	desc.setDeletableFlag(true);
 	desc.setThumbnail(thumbnail);
 
+	InfoStuff infos;
+	memset(&infos, 0, sizeof(infos));
+	if (ScummEngine::loadInfosFromSlot(target, slot, &infos)) {
+		int day = (infos.date >> 24) & 0xFF;
+		int month = (infos.date >> 16) & 0xFF;
+		int year = infos.date & 0xFFFF;
+
+		desc.setSaveDate(year, month, day);
+		
+		int hour = (infos.time >> 8) & 0xFF;
+		int minutes = infos.time & 0xFF;
+
+		desc.setSaveTime(hour, minutes);
+
+		minutes = infos.playtime / 60;
+		hour = minutes / 60;
+		minutes %= 60;
+
+		desc.setPlayTime(hour, minutes);
+	}
+
 	return desc;
 }
 

Modified: scummvm/trunk/engines/scumm/saveload.cpp
===================================================================
--- scummvm/trunk/engines/scumm/saveload.cpp	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/engines/scumm/saveload.cpp	2008-09-16 14:56:02 UTC (rev 34583)
@@ -518,15 +518,15 @@
 	return thumb;
 }
 
-bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) {
+bool ScummEngine::loadInfosFromSlot(const char *target, int slot, InfoStuff *stuff) {
 	Common::SeekableReadStream *in;
 	SaveGameHeader hdr;
 
 	if (slot < 0)
 		return  0;
 
-	Common::String filename = makeSavegameName(slot, false);
-	if (!(in = _saveFileMan->openForLoading(filename.c_str()))) {
+	Common::String filename = makeSavegameName(target, slot, false);
+	if (!(in = g_system->getSavefileManager()->openForLoading(filename.c_str()))) {
 		return false;
 	}
 
@@ -598,9 +598,8 @@
 	stuff->playtime = section.playtime;
 
 	// Skip over the remaining (unsupported) data
-	if (section.size > SaveInfoSectionSize) {
+	if (section.size > SaveInfoSectionSize)
 		file->skip(section.size - SaveInfoSectionSize);
-	}
 
 	return true;
 }

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/engines/scumm/scumm.h	2008-09-16 14:56:02 UTC (rev 34583)
@@ -637,11 +637,14 @@
 	}
 	static Graphics::Surface *loadThumbnailFromSlot(const char *target, int slot);
 
-	bool loadInfosFromSlot(int slot, InfoStuff *stuff);
+	bool loadInfosFromSlot(int slot, InfoStuff *stuff) {
+		return loadInfosFromSlot(_targetName.c_str(), slot, stuff);
+	}
+	static bool loadInfosFromSlot(const char *target, int slot, InfoStuff *stuff);
 
 protected:
 	void saveInfos(Common::WriteStream* file);
-	bool loadInfos(Common::SeekableReadStream *file, InfoStuff *stuff);
+	static bool loadInfos(Common::SeekableReadStream *file, InfoStuff *stuff);
 
 	int32 _engineStartTime;
 	int32 _pauseStartTime;

Modified: scummvm/trunk/gui/launcher.cpp
===================================================================
--- scummvm/trunk/gui/launcher.cpp	2008-09-16 14:22:51 UTC (rev 34582)
+++ scummvm/trunk/gui/launcher.cpp	2008-09-16 14:56:02 UTC (rev 34583)
@@ -482,11 +482,16 @@
 	GUI::ButtonWidget	*_deleteButton;
 	GUI::GraphicsWidget	*_gfxWidget;
 	GUI::ContainerWidget	*_container;
+	GUI::StaticTextWidget	*_date;
+	GUI::StaticTextWidget	*_time;
+	GUI::StaticTextWidget	*_playtime;
 
 	const EnginePlugin		*_plugin;
 	bool					_delSupport;
 	bool					_metaInfoSupport;
 	bool					_thumbnailSupport;
+	bool					_saveDateSupport;
+	bool					_playTimeSupport;
 	String					_target;
 	SaveStateList			_saveList;
 
@@ -523,6 +528,10 @@
 
 	_gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10);
 
+	_date = new StaticTextWidget(this, 0, 0, 10, 10, "No date saved", kTextAlignCenter);
+	_time = new StaticTextWidget(this, 0, 0, 10, 10, "No time saved", kTextAlignCenter);
+	_playtime = new StaticTextWidget(this, 0, 0, 10, 10, "No playtime saved", kTextAlignCenter);
+
 	// Buttons
 	new GUI::ButtonWidget(this, "scummsaveload_cancel", "Cancel", kCloseCmd, 0);
 	_chooseButton = new GUI::ButtonWidget(this, "scummsaveload_choose", buttonLabel, kChooseCmd, 0);
@@ -546,6 +555,8 @@
 	_delSupport = (*_plugin)->hasFeature(MetaEngine::kSupportsDeleteSave);
 	_metaInfoSupport = (*_plugin)->hasFeature(MetaEngine::kSupportsMetaInfos);
 	_thumbnailSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSupportsThumbnails);
+	_saveDateSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSupportsSaveDate);
+	_playTimeSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSupportsSavePlayTime);
 	reflowLayout();
 	updateSaveList();
 
@@ -604,14 +615,43 @@
 		int vPad = g_gui.evaluator()->getVar("scummsaveload_thumbnail.vPad");
 		int thumbH = ((g_system->getHeight() % 200 && g_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1);
 
-		_container->resize(thumbX - hPad, thumbY - vPad, kThumbnailWidth + hPad * 2, thumbH + vPad * 2/* + kLineHeight * 4*/);
+		int textLines = 0;
+		if (_saveDateSupport)
+			textLines += 2;
+		if (_playTimeSupport)
+			textLines += 1;
 
+		if (textLines)
+			++textLines;
+
+		_container->resize(thumbX - hPad, thumbY - vPad, kThumbnailWidth + hPad * 2, thumbH + vPad * 2 + kLineHeight * textLines);
+
 		// Add the thumbnail display
 		_gfxWidget->resize(thumbX, thumbY, kThumbnailWidth, thumbH);
 
+		int height = thumbY + thumbH + kLineHeight;
+
+		if (_saveDateSupport) {
+			_date->resize(thumbX, height, kThumbnailWidth, kLineHeight);
+			height += kLineHeight;
+			_time->resize(thumbX, height, kThumbnailWidth, kLineHeight);
+			height += kLineHeight;
+		}
+
+		if (_playTimeSupport)
+			_playtime->resize(thumbX, height, kThumbnailWidth, kLineHeight);
+
 		_container->clearFlags(GUI::WIDGET_INVISIBLE);
 		_gfxWidget->clearFlags(GUI::WIDGET_INVISIBLE);
 
+		if (_saveDateSupport) {
+			_date->clearFlags(GUI::WIDGET_INVISIBLE);
+			_time->clearFlags(GUI::WIDGET_INVISIBLE);
+		}
+
+		if (_playTimeSupport)
+			_playtime->clearFlags(GUI::WIDGET_INVISIBLE);
+
 		_fillR = g_gui.evaluator()->getVar("scummsaveload_thumbnail.fillR");
 		_fillG = g_gui.evaluator()->getVar("scummsaveload_thumbnail.fillG");
 		_fillB = g_gui.evaluator()->getVar("scummsaveload_thumbnail.fillB");
@@ -619,6 +659,9 @@
 	} else {
 		_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();
@@ -643,6 +686,33 @@
 				_gfxWidget->setGfx(-1, -1, _fillR, _fillG, _fillB);
 			}
 		}
+
+		if (_saveDateSupport) {
+			Common::String date = "Date: ";
+			if (desc.contains("save_date"))
+				date += desc.getVal("save_date");
+			else
+				date = "No date saved";
+
+			Common::String time = "Time: ";
+			if (desc.contains("save_time"))
+				time += desc.getVal("save_time");
+			else
+				time = "No time saved";
+
+			_date->setLabel(date);
+			_time->setLabel(time);
+		}
+
+		if (_playTimeSupport) {
+			Common::String time = "Playtime:";
+			if (desc.contains("play_time"))
+				time += desc.getVal("play_time");
+			else
+				time = "No playtime saved";
+
+			_playtime->setLabel(time);
+		}
 	}
 
 
@@ -654,6 +724,9 @@
 
 	if (redraw) {
 		_gfxWidget->draw();
+		_date->draw();
+		_time->draw();
+		_playtime->draw();
 		_chooseButton->draw();
 		_deleteButton->draw();
 	}


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