lo and behold - the 'Add Game' button now works, at least in some cases! More to come...

svn-id: r5646
This commit is contained in:
Max Horn 2002-11-21 02:19:02 +00:00
parent 60f5096e63
commit 2eb39f6497
2 changed files with 119 additions and 87 deletions

View File

@ -37,7 +37,9 @@ enum {
kConfigureGameCmd = 'CONF', kConfigureGameCmd = 'CONF',
kQuitCmd = 'QUIT' kQuitCmd = 'QUIT'
}; };
typedef ScummVM::List<const VersionSettings *> GameList;
/* /*
* TODO list * TODO list
* - add an text entry widget * - add an text entry widget
@ -52,7 +54,6 @@ enum {
LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector) LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
: Dialog(gui, 0, 0, 320, 200), _detector(detector) : Dialog(gui, 0, 0, 320, 200), _detector(detector)
{ {
int i;
Widget *bw; Widget *bw;
// Show game name // Show game name
@ -72,6 +73,30 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
_list->setEditable(false); _list->setEditable(false);
_list->setNumberingMode(kListNumberingOff); _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; const VersionSettings *v = version_settings;
ScummVM::StringList l; ScummVM::StringList l;
// TODO - maybe only display those games for which settings are known // TODO - maybe only display those games for which settings are known
@ -109,83 +134,55 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
if (l.size() > 0) if (l.size() > 0)
_list->setList(l); _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)
{ {
/* GameList list;
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); FSList *files = dir->listDir(FilesystemNode::kListFilesOnly);
int size = files->size(); const int size = files->size();
for (int i = 0; i < size; i++) { char detectName[256];
const char *filename = (*files)[i].displayName().c_str(); int i;
//printf("%2d. %s\n", i, filename);
// Iterate over all known games and for each check if it might be
// Check if there is any game matching this file // the game in the presented directory.
const VersionSettings *v = version_settings; const VersionSettings *v = version_settings;
while (v->filename && v->gamename) { while (v->filename && v->gamename) {
char detectName[256];
if (v->detectname) // Determine the 'detectname' for this game, that is, the name of a
strcpy(detectName, v->detectname); // file that *must* be presented if the directory contains the data
else { // for this game. For example, FOA requires atlantis.000
strcpy(detectName, v->filename); if (v->detectname)
if (v->features & GF_AFTER_V7) strcpy(detectName, v->detectname);
strcat(detectName, ".la0"); else {
else if (v->features & GF_HUMONGOUS) strcpy(detectName, v->filename);
strcat(detectName, ".he0"); if (v->features & GF_AFTER_V7)
else strcat(detectName, ".la0");
strcat(detectName, ".000"); else if (v->features & GF_HUMONGOUS)
} strcat(detectName, ".he0");
if (0 == scumm_stricmp(detectName, filename)) { else
printf("Match found, apparently this is '%s'\n", v->gamename); strcat(detectName, ".000");
return true;
}
v++;
} }
// 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)) {
// Match found, add to list of candidates, then abort inner loop.
list.push_back(v);
break;
}
}
v++;
} }
printf("Unable to autodetect a game in %s\n", dir->displayName().c_str()); return list;
return false;
} }
void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
@ -194,22 +191,52 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
switch (cmd) { switch (cmd) {
case kAddGameCmd: { 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 // 1) show a dir selection dialog which lets
// the user pick the directory the game data resides in. // the user pick the directory the game data resides in.
// 2) show the user a list of games to pick from. Initially just show // 2) show the user a list of games to pick from, already narrowed
// all known games. But ideally, we would refine this list by checking // down to all possible choices
// which choices are possible. E.g. if we don't find atlantis.000 in that
// directory, then it's not FOA etc. if (_browser->runModal()) {
BrowserDialog *browser = new BrowserDialog(_gui);
if (browser->runModal()) {
// User did make a choice... // 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 // ...so let's determine a list of candidates, games that
findGame(dir); // 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; break;
case kConfigureGameCmd: case kConfigureGameCmd:

View File

@ -25,6 +25,7 @@
#include "common/str.h" #include "common/str.h"
#include "common/list.h" #include "common/list.h"
class BrowserDialog;
class GameDetector; class GameDetector;
class ListWidget; class ListWidget;
@ -33,14 +34,18 @@ class LauncherDialog : public Dialog {
typedef ScummVM::StringList StringList; typedef ScummVM::StringList StringList;
public: public:
LauncherDialog(NewGui *gui, GameDetector &detector); LauncherDialog(NewGui *gui, GameDetector &detector);
~LauncherDialog();
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected: protected:
ListWidget *_list; ListWidget *_list;
Widget *_startButton; Widget *_startButton;
StringList _filenames; StringList _filenames;
GameDetector &_detector; GameDetector &_detector;
BrowserDialog *_browser;
void updateListing();
}; };
#endif #endif