[Scummvm-cvs-logs] CVS: scummvm/gui launcher.cpp,1.14,1.15 launcher.h,1.3,1.4

Max Horn fingolfin at users.sourceforge.net
Wed Nov 20 18:20:02 CET 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv26606

Modified Files:
	launcher.cpp launcher.h 
Log Message:
lo and behold - the 'Add Game' button now works, at least in some cases! More to come...

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- launcher.cpp	19 Nov 2002 01:36:47 -0000	1.14
+++ launcher.cpp	21 Nov 2002 02:19:02 -0000	1.15
@@ -37,7 +37,9 @@
 	kConfigureGameCmd = 'CONF',
 	kQuitCmd = 'QUIT'
 };
-	
+
+typedef ScummVM::List<const VersionSettings *> GameList;
+
 /*
  * TODO list
  * - add an text entry widget
@@ -52,7 +54,6 @@
 LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
 	: Dialog(gui, 0, 0, 320, 200), _detector(detector)
 {
-	int i;
 	Widget *bw;
 
 	// Show game name
@@ -72,6 +73,30 @@
 	_list->setEditable(false);
 	_list->setNumberingMode(kListNumberingOff);
 	
+	// Populate the list
+	updateListing();
+
+	// TODO - make a default selection (maybe the game user played last?)
+	//_list->setSelected(0);
+
+	// Two more buttons directly below the list box
+	bw = new ButtonWidget(this, 10, 144, 80, 16, "Add Game...", kAddGameCmd, 'A');
+//	bw->setEnabled(false);
+	bw = new ButtonWidget(this, 320-90, 144, 80, 16, "Configure...", kConfigureGameCmd, 'C');
+	bw->setEnabled(false);
+	
+	// Create file browser dialog
+	_browser = new BrowserDialog(_gui);
+}
+
+LauncherDialog::~LauncherDialog()
+{
+	delete _browser;
+}
+
+void LauncherDialog::updateListing()
+{
+	int i;
 	const VersionSettings *v = version_settings;
 	ScummVM::StringList l;
 	// TODO - maybe only display those games for which settings are known
@@ -109,83 +134,55 @@
 
 	if (l.size() > 0) 
 		_list->setList(l);
-
-	// TODO - make a default selection (maybe the game user played last?)
-	//_list->setSelected(0);
-
-	// Two more buttons directly below the list box
-	bw = new ButtonWidget(this, 10, 144, 80, 16, "Add Game...", kAddGameCmd, 'A');
-//	bw->setEnabled(false);
-	bw = new ButtonWidget(this, 320-90, 144, 80, 16, "Configure...", kConfigureGameCmd, 'C');
-	bw->setEnabled(false);
 }
 
-bool findGame(FilesystemNode *dir)
+/*
+ * Return a list of all games which might be the game in the specified directory.
+ */
+GameList findGame(FilesystemNode *dir)
 {
-	/*
-	atlantis -> ATLANTIS.000
-	dig -> dig.la0
-	ft -> ft.la0
-	indy3 -> 00.LFL, ???
-	indy3vga -> 00.LFL, INDYVGA.EXE
-	loom -> 00.LFL, LOOMEXE.EXE
-	loomcd -> 000.LFL, LOOM.EXE
-	maniac -> 00.LFL, MANIACEX.EXE
-	monkey -> monkey.000
-	monkey2 -> monkey2.000
-	monkeyvga -> 000.LFL, MONKEY.EXE
-	samnmax -> samnmax.000
-	tentacle -> tentacle.000
-	zak -> 00.LFL, zakexe.exe
-	zak256 -> 00.LFL, ZAK.EXP
-	*/
-	
-	// TODO - this doesn't deal with Simon games at all yet!
-	// We may have to offer a choice dialog between win/dos/talkie versions...
-	
-	// TODO - if we can't decide which game this supposedly is, we should ask the user.
-	// We simply can't autodetect all games, e.g. for old games (with 00.LFL), it is
-	// hard to distinguish them based on file names alone. We do luck for .exe files
-	// but those could be deleted by the user, or for the Amiga/Mac/... versions
-	// may not be present at all.
-	// Or maybe somebody has a better idea? Is there a reliable way to tell from
-	// the XX.lfl files which game we are dealing with (taking into account that
-	// for most of the games many variations exist, so we can't just hard code expected
-	// file sizes or checksums).
-	
-//	ScummVM::Map<String, FilesystemNode *file> map;
+	GameList list;
 
 	FSList *files = dir->listDir(FilesystemNode::kListFilesOnly);
-	int size = files->size();
-	for (int i = 0; i < size; i++) {
-		const char *filename = (*files)[i].displayName().c_str();
-		//printf("%2d. %s\n", i, filename);
-		
-		// Check if there is any game matching this file
-		const VersionSettings *v = version_settings;
-		while (v->filename && v->gamename) {
-			char detectName[256];
-			if (v->detectname)
-				strcpy(detectName, v->detectname);
-			else {
-				strcpy(detectName, v->filename);
-				if (v->features & GF_AFTER_V7)
-					strcat(detectName, ".la0");
-				else if (v->features & GF_HUMONGOUS)
-					strcat(detectName, ".he0");
-				else
-					strcat(detectName, ".000");
-			}
+	const int size = files->size();
+	char detectName[256];
+	int i;
+
+	// Iterate over all known games and for each check if it might be
+	// the game in the presented directory.
+	const VersionSettings *v = version_settings;
+	while (v->filename && v->gamename) {
+
+		// Determine the 'detectname' for this game, that is, the name of a 
+		// file that *must* be presented if the directory contains the data
+		// for this game. For example, FOA requires atlantis.000
+		if (v->detectname)
+			strcpy(detectName, v->detectname);
+		else {
+			strcpy(detectName, v->filename);
+			if (v->features & GF_AFTER_V7)
+				strcat(detectName, ".la0");
+			else if (v->features & GF_HUMONGOUS)
+				strcat(detectName, ".he0");
+			else
+				strcat(detectName, ".000");
+		}
+
+		// Iterate over all files in the given directory
+		for (i = 0; i < size; i++) {
+			const char *filename = (*files)[i].displayName().c_str();
+
 			if (0 == scumm_stricmp(detectName, filename)) {
-				printf("Match found, apparently this is '%s'\n", v->gamename);
-				return true;
+				// Match found, add to list of candidates, then abort inner loop.
+				list.push_back(v);
+				break;
 			}
-			v++;
 		}
+
+		v++;
 	}
-	
-	printf("Unable to autodetect a game in %s\n", dir->displayName().c_str());
-	return false;
+
+	return list;
 }
 
 void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
@@ -194,22 +191,52 @@
 	
 	switch (cmd) {
 	case kAddGameCmd: {
-		// TODO: Allow user to add a new game to the list.
+		// Allow user to add a new game to the list.
 		// 1) show a dir selection dialog which lets 
 		// the user pick the directory the game data resides in.
-		// 2) show the user a list of games to pick from. Initially just show
-		// all known games. But ideally, we would refine this list by checking
-		// which choices are possible. E.g. if we don't find atlantis.000 in that
-		// directory, then it's not FOA etc.
-		BrowserDialog *browser = new BrowserDialog(_gui);
-		if (browser->runModal()) {
+		// 2) show the user a list of games to pick from, already narrowed
+		// down to all possible choices
+		
+		if (_browser->runModal()) {
 			// User did make a choice...
-			FilesystemNode *dir = browser->getResult();
+			FilesystemNode *dir = _browser->getResult();
 			
-			// ...so let's examine it and try to figure out which game it is
-			findGame(dir);
+			// ...so let's determine a list of candidates, games that
+			// could be contained in the specified directory.
+			GameList candidates = findGame(dir);
+			const VersionSettings *v = 0;
+			
+			if (candidates.isEmpty()) {
+				// TODO - display dialog telling user that no match was found?!?
+				// Optionally, offer to let the user force a certain game?
+			} else if (candidates.size() == 1) {
+				// Exact match
+				v = candidates[0];
+			} else {
+				// TODO - display candidates to the user and let him pick one
+				printf("Found these candidates: ");
+				for (int i = 0; i < candidates.size(); i++)
+					printf("%s, ", candidates[i]->filename);
+				printf("\n");
+			}
+			
+			if (v != 0) {
+				// The auto detector or the user made a choice.
+				// For now we just forcefully insert it into the config list, but
+				// in the future we might want to check for an existing entry
+				// first... of course the question is, what do we do if we find one?
+				g_config->set("path", dir->path(), v->filename);
+				
+				// Write it to disk
+				g_config->set_writing(true);
+				g_config->flush();
+				g_config->set_writing(false);
+				
+				// Update the ListWidget and force a redraw
+				updateListing();
+				draw();
+			}
 		}
-		delete browser;
 		}
 		break;
 	case kConfigureGameCmd:

Index: launcher.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- launcher.h	1 Oct 2002 23:11:19 -0000	1.3
+++ launcher.h	21 Nov 2002 02:19:02 -0000	1.4
@@ -25,6 +25,7 @@
 #include "common/str.h"
 #include "common/list.h"
 
+class BrowserDialog;
 class GameDetector;
 class ListWidget;
 
@@ -33,14 +34,18 @@
 	typedef ScummVM::StringList StringList;
 public:
 	LauncherDialog(NewGui *gui, GameDetector &detector);
+	~LauncherDialog();
 
 	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 protected:
-	ListWidget	*_list;
-	Widget *_startButton;
-	StringList	_filenames;
-	GameDetector &_detector;
+	ListWidget		*_list;
+	Widget			*_startButton;
+	StringList		_filenames;
+	GameDetector 	&_detector;
+	BrowserDialog	*_browser;
+
+	void updateListing();
 };
 
 #endif





More information about the Scummvm-git-logs mailing list