aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2002-11-21 02:19:02 +0000
committerMax Horn2002-11-21 02:19:02 +0000
commit2eb39f6497b2c87e60314201561a79ffb0df1c6d (patch)
treef9c20bd800286715958b5a96dc82cdf418297e15 /gui
parent60f5096e63c3888a7519f73c48b93135085fef51 (diff)
downloadscummvm-rg350-2eb39f6497b2c87e60314201561a79ffb0df1c6d.tar.gz
scummvm-rg350-2eb39f6497b2c87e60314201561a79ffb0df1c6d.tar.bz2
scummvm-rg350-2eb39f6497b2c87e60314201561a79ffb0df1c6d.zip
lo and behold - the 'Add Game' button now works, at least in some cases! More to come...
svn-id: r5646
Diffstat (limited to 'gui')
-rw-r--r--gui/launcher.cpp189
-rw-r--r--gui/launcher.h13
2 files changed, 117 insertions, 85 deletions
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index 8d3e727b83..eceb8d1978 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -37,7 +37,9 @@ enum {
kConfigureGameCmd = 'CONF',
kQuitCmd = 'QUIT'
};
-
+
+typedef ScummVM::List<const VersionSettings *> GameList;
+
/*
* TODO list
* - add an text entry widget
@@ -52,7 +54,6 @@ enum {
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 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
_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 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
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 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
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 determine a list of candidates, games that
+ // could be contained in the specified directory.
+ GameList candidates = findGame(dir);
+ const VersionSettings *v = 0;
- // ...so let's examine it and try to figure out which game it is
- findGame(dir);
+ 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:
diff --git a/gui/launcher.h b/gui/launcher.h
index 694121c24d..7bbf223a29 100644
--- a/gui/launcher.h
+++ b/gui/launcher.h
@@ -25,6 +25,7 @@
#include "common/str.h"
#include "common/list.h"
+class BrowserDialog;
class GameDetector;
class ListWidget;
@@ -33,14 +34,18 @@ class LauncherDialog : public Dialog {
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