diff options
author | Max Horn | 2002-11-21 03:51:07 +0000 |
---|---|---|
committer | Max Horn | 2002-11-21 03:51:07 +0000 |
commit | e5257ac4fe67adbda53fae9daff9a85a5e347fd7 (patch) | |
tree | 5dd3448c4445eb3cd0fab7ecac7f3c432462c8b6 /gui | |
parent | d76627abac9869a979f06deea9fc0a46dfb5dc5c (diff) | |
download | scummvm-rg350-e5257ac4fe67adbda53fae9daff9a85a5e347fd7.tar.gz scummvm-rg350-e5257ac4fe67adbda53fae9daff9a85a5e347fd7.tar.bz2 scummvm-rg350-e5257ac4fe67adbda53fae9daff9a85a5e347fd7.zip |
added a chooser sub dialog used by 'Add Game'
svn-id: r5651
Diffstat (limited to 'gui')
-rw-r--r-- | gui/launcher.cpp | 77 |
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: |