[Scummvm-cvs-logs] CVS: scummvm/gui launcher.cpp,1.15,1.16

Max Horn fingolfin at users.sourceforge.net
Wed Nov 20 19:52:06 CET 2002


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

Modified Files:
	launcher.cpp 
Log Message:
added a chooser sub dialog used by 'Add Game'

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- launcher.cpp	21 Nov 2002 02:19:02 -0000	1.15
+++ launcher.cpp	21 Nov 2002 03:51:07 -0000	1.16
@@ -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 @@
 				// 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 @@
 		close();
 		break;
 	case kListSelectionChangedCmd:
-		_startButton->setEnabled(_list->getSelected() >= 0);
+		_startButton->setEnabled(data >= 0);
 		_startButton->draw();
 		break;
 	case kQuitCmd:





More information about the Scummvm-git-logs mailing list