aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/launcher.cpp77
1 files changed, 71 insertions, 6 deletions
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index eceb8d1978..6b4e7cfd11 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -29,6 +29,66 @@
#include "common/engine.h"
#include "common/gameDetector.h"
+enum {
+ kChooseCmd = 'Chos'
+};
+
+/*
+ * A dialog that allows the user to choose between a selection of items
+ */
+
+class ChooserDialog : public Dialog {
+ typedef ScummVM::String String;
+ typedef ScummVM::StringList StringList;
+public:
+ ChooserDialog(NewGui *gui, const StringList& list);
+
+ virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+
+protected:
+ ListWidget *_list;
+ ButtonWidget *_chooseButton;
+};
+
+ChooserDialog::ChooserDialog(NewGui *gui, const StringList& list)
+ : Dialog(gui, 40, 30, 320-2*40, 200-2*30)
+{
+ // Headline
+ new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight,
+ "Pick the game:", kTextAlignCenter);
+
+ // Add choice list
+ _list = new ListWidget(this, 10, 22, _w-2*10, _h-22-24-10);
+ _list->setNumberingMode(kListNumberingOff);
+ _list->setList(list);
+
+ // Buttons
+ addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0);
+ _chooseButton = addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0);
+ _chooseButton->setEnabled(false);
+
+ // Result = -1 -> no choice was made
+ setResult(-1);
+}
+
+void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
+{
+ int item = _list->getSelected();
+ switch (cmd) {
+ case kChooseCmd:
+ case kListItemDoubleClickedCmd:
+ setResult(item);
+ close();
+ break;
+ case kListSelectionChangedCmd:
+ _chooseButton->setEnabled(item >= 0);
+ _chooseButton->draw();
+ break;
+ default:
+ Dialog::handleCommand(sender, cmd, data);
+ }
+}
+
enum {
kStartCmd = 'STRT',
@@ -213,11 +273,16 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
// 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");
+ // Display the candidates to the user and let her/him pick one
+ StringList list;
+ int i;
+ for (i = 0; i < candidates.size(); i++)
+ list.push_back(candidates[i]->gamename);
+
+ ChooserDialog dialog(_gui, list);
+ i = dialog.runModal();
+ if (0 <= i && i < candidates.size())
+ v = candidates[i];
}
if (v != 0) {
@@ -263,7 +328,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
close();
break;
case kListSelectionChangedCmd:
- _startButton->setEnabled(_list->getSelected() >= 0);
+ _startButton->setEnabled(data >= 0);
_startButton->draw();
break;
case kQuitCmd: