[Scummvm-cvs-logs] CVS: scummvm/gui browser.cpp,1.3,1.4 browser.h,1.3,1.4 dialog.cpp,1.23,1.24 dialog.h,1.14,1.15 launcher.cpp,1.13,1.14 message.cpp,1.4,1.5

Max Horn fingolfin at projects.sourceforge.net
Mon Nov 18 17:37:04 CET 2002


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

Modified Files:
	browser.cpp browser.h dialog.cpp dialog.h launcher.cpp 
	message.cpp 
Log Message:
added some preliminary game auto detect code to the launcher; this required a small change to the FS API, Windows/Morphos code will have to be adapted slightly I fear. Also, not all games are detected correctly, and some probably never will be, so we still have to add a dialog for cases where auto detect doesn't work

Index: browser.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- browser.cpp	15 Nov 2002 17:54:48 -0000	1.3
+++ browser.cpp	19 Nov 2002 01:36:47 -0000	1.4
@@ -58,6 +58,13 @@
 	addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0);
 }
 
+BrowserDialog::~BrowserDialog()
+{
+	delete _node;
+	delete _nodeContent;
+	delete _choice;
+}
+
 void BrowserDialog::open()
 {
 	// If no node has been set, or the last used one is now invalid,
@@ -71,6 +78,10 @@
 	// Alway refresh file list
 	updateListing();
 
+	// Nothing chosen by default
+	delete _choice;
+	_choice = 0;
+	
 	// Call super implementation
 	Dialog::open();
 }
@@ -92,11 +103,18 @@
 	FilesystemNode *tmp;
 	
 	switch (cmd) {
-	case kChooseCmd:
-		// If nothing is selected in the list widget, choose the current dir.
-		// Else, choose the dir that is selected.
-		// TODO
-		close();
+	case kChooseCmd: {
+			// If nothing is selected in the list widget, choose the current dir.
+			// Else, choose the dir that is selected.
+			int selection = _fileList->getSelected();
+			if (selection >= 0) {
+				_choice = (*_nodeContent)[selection].clone();
+			} else {
+				_choice = _node->clone();
+			}
+			setResult(1);
+			close();
+		}
 		break;
 	case kGoUpCmd:
 		tmp = _node->parent();

Index: browser.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- browser.h	15 Nov 2002 17:54:49 -0000	1.3
+++ browser.h	19 Nov 2002 01:36:47 -0000	1.4
@@ -36,16 +36,20 @@
 	typedef ScummVM::StringList StringList;
 public:
 	BrowserDialog(NewGui *gui);
+	virtual ~BrowserDialog();
 
 	virtual void open();
 	virtual void close();
 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+	
+	FilesystemNode	*getResult()	{ return _choice; };
 
 protected:
 	ListWidget		*_fileList;
 	StaticTextWidget*_currentPath;
 	FilesystemNode	*_node;
 	FSList			*_nodeContent;
+	FilesystemNode	*_choice;
 	
 	void updateListing();
 };

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- dialog.cpp	10 Nov 2002 19:39:32 -0000	1.23
+++ dialog.cpp	19 Nov 2002 01:36:47 -0000	1.24
@@ -58,14 +58,15 @@
 	// Start processing events
 	_gui->runLoop();
 	
-	// FIXME - for now always return 0....
-	return 0;
+	// Return the result code
+	return _result;
 }
 
 void Dialog::open()
 {
 	Widget *w = _firstWidget;
 	
+	_result = 0;
 	_visible = true;
 	_gui->openDialog(this);
 	

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- dialog.h	10 Nov 2002 19:39:32 -0000	1.14
+++ dialog.h	19 Nov 2002 01:36:47 -0000	1.15
@@ -45,6 +45,9 @@
 	Widget  *_focusedWidget;
 	bool	_visible;
 
+private:
+	int		_result;
+	
 public:
 	Dialog(NewGui *gui, int x, int y, int w, int h)
 		: _gui(gui), _x(x), _y(y), _w(w), _h(h), _firstWidget(0),
@@ -62,7 +65,7 @@
 protected:
 	virtual void open();
 	virtual void close();
-
+	
 	virtual void draw();
 	virtual void drawDialog();
 
@@ -79,6 +82,8 @@
 
 	ButtonWidget* addButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey);
 	PushButtonWidget* addPushButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey);
+
+	void setResult(int result) { _result = result; }
 };
 
 #endif

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- launcher.cpp	14 Nov 2002 13:46:35 -0000	1.13
+++ launcher.cpp	19 Nov 2002 01:36:47 -0000	1.14
@@ -24,10 +24,12 @@
 #include "newgui.h"
 #include "ListWidget.h"
 
+#include "backends/fs/fs.h"
 #include "common/config-file.h"
 #include "common/engine.h"
 #include "common/gameDetector.h"
 
+
 enum {
 	kStartCmd = 'STRT',
 	kOptionsCmd = 'OPTN',
@@ -118,6 +120,74 @@
 	bw->setEnabled(false);
 }
 
+bool 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;
+
+	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");
+			}
+			if (0 == scumm_stricmp(detectName, filename)) {
+				printf("Match found, apparently this is '%s'\n", v->gamename);
+				return true;
+			}
+			v++;
+		}
+	}
+	
+	printf("Unable to autodetect a game in %s\n", dir->displayName().c_str());
+	return false;
+}
+
 void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
 {
 	int item;
@@ -132,7 +202,13 @@
 		// 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);
-		browser->runModal();
+		if (browser->runModal()) {
+			// User did make a choice...
+			FilesystemNode *dir = browser->getResult();
+			
+			// ...so let's examine it and try to figure out which game it is
+			findGame(dir);
+		}
 		delete browser;
 		}
 		break;

Index: message.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/message.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- message.cpp	10 Nov 2002 14:53:28 -0000	1.4
+++ message.cpp	19 Nov 2002 01:36:47 -0000	1.5
@@ -23,44 +23,6 @@
 #include "newgui.h"
 
 
-int MessageDialog::addLine(const char *line, int size)
-{
-	int width = 0, maxWidth = 0;
-	const char *start = line;
-	String tmp;
-
-	for (int i = 0; i < size; ++i) {
-		int w = _gui->getCharWidth(*line);
-
-		// Check if we exceed the maximum line width, if so, split the line
-		// TODO - we could make this more clever by trying to split at
-		// non-letters, e.g. at space/slash/dot
-		if (width + w > 280) {
-			if (maxWidth < width)
-				maxWidth = width;
-			
-			// Add the substring from intervall [start, i-1]
-			tmp = String(start, line - start);
-			_lines.push_back(tmp);
-			
-			start = line;
-			width = w;
-		} else
-			width += w;
-		
-		line++;
-	}
-
-	if (maxWidth < width)
-		maxWidth = width;
-
-	if (start < line) {
-		tmp = String(start, line - start);
-		_lines.push_back(tmp);
-	}
-	return maxWidth;
-}
-
 MessageDialog::MessageDialog(NewGui *gui, const String &message)
 	: Dialog(gui, 30, 20, 260, 124)
 {
@@ -107,3 +69,42 @@
 	// was selected.
 	addButton((_w - kButtonWidth)/2, _h - 24, "OK", kCloseCmd, '\n');	// Confirm dialog
 }
+
+int MessageDialog::addLine(const char *line, int size)
+{
+	int width = 0, maxWidth = 0;
+	const char *start = line;
+	String tmp;
+
+	for (int i = 0; i < size; ++i) {
+		int w = _gui->getCharWidth(*line);
+
+		// Check if we exceed the maximum line width, if so, split the line
+		// TODO - we could make this more clever by trying to split at
+		// non-letters, e.g. at space/slash/dot
+		if (width + w > 280) {
+			if (maxWidth < width)
+				maxWidth = width;
+			
+			// Add the substring from intervall [start, i-1]
+			tmp = String(start, line - start);
+			_lines.push_back(tmp);
+			
+			start = line;
+			width = w;
+		} else
+			width += w;
+		
+		line++;
+	}
+
+	if (maxWidth < width)
+		maxWidth = width;
+
+	if (start < line) {
+		tmp = String(start, line - start);
+		_lines.push_back(tmp);
+	}
+	return maxWidth;
+}
+





More information about the Scummvm-git-logs mailing list