reuse SaveLoadChooser in main dialog -> this means the SaveLoadChooser remembers the scroll position -> improved user experience

svn-id: r11415
This commit is contained in:
Max Horn 2003-11-28 21:56:14 +00:00
parent 8a6b0e2e18
commit 54aa33310d
5 changed files with 26 additions and 12 deletions

View file

@ -29,7 +29,7 @@ enum {
kChooseCmd = 'Chos'
};
ChooserDialog::ChooserDialog(const String &title, const StringList& list, const String &buttonLabel, int height)
ChooserDialog::ChooserDialog(const String &title, const String &buttonLabel, int height)
: Dialog(8, (200 - height) / 2, 320 - 2 * 8, height) {
// Headline
new StaticTextWidget(this, 10, 6, _w - 2 * 10, kLineHeight, title, kTextAlignCenter);
@ -37,7 +37,6 @@ ChooserDialog::ChooserDialog(const String &title, const StringList& list, const
// Add choice list
_list = new ListWidget(this, 10, 18, _w - 2 * 10, _h - 14 - 24 - 10);
_list->setNumberingMode(kListNumberingOff);
_list->setList(list);
// Buttons
addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0);
@ -45,6 +44,10 @@ ChooserDialog::ChooserDialog(const String &title, const StringList& list, const
_chooseButton->setEnabled(false);
}
void ChooserDialog::setList(const StringList& list) {
_list->setList(list);
}
void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
int item = _list->getSelected();
switch (cmd) {

View file

@ -42,7 +42,9 @@ protected:
ButtonWidget *_chooseButton;
public:
ChooserDialog(const String &title, const StringList &list, const String &buttonLabel = "Choose", int height = 140);
ChooserDialog(const String &title, const String &buttonLabel = "Choose", int height = 140);
void setList(const StringList& list);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
};

View file

@ -428,7 +428,8 @@ void LauncherDialog::addGame() {
for (idx = 0; idx < candidates.size(); idx++)
list.push_back(candidates[idx].description);
ChooserDialog dialog("Pick the game:", list);
ChooserDialog dialog("Pick the game:");
dialog.setList(list);
idx = dialog.runModal();
}
if (0 <= idx && idx < candidates.size()) {

View file

@ -198,14 +198,14 @@ protected:
bool _saveMode;
public:
SaveLoadChooser(const String &title, const StringList& list, const String &buttonLabel, bool saveMode);
SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
const String &getResultString() const;
};
SaveLoadChooser::SaveLoadChooser(const String &title, const StringList& list, const String &buttonLabel, bool saveMode)
: ChooserDialog(title, list, buttonLabel, 182), _saveMode(saveMode) {
SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode)
: ChooserDialog(title, buttonLabel, 182), _saveMode(saveMode) {
_list->setEditable(saveMode);
_list->setNumberingMode(saveMode ? kListNumberingOne : kListNumberingZero);
@ -303,6 +303,8 @@ MainMenuDialog::MainMenuDialog(ScummEngine *scumm)
#ifndef DISABLE_HELP
_helpDialog = new HelpDialog(scumm);
#endif
_saveDialog = new SaveLoadChooser("Save game:", "Save", true);
_loadDialog = new SaveLoadChooser("Load game:", "Load", false);
}
MainMenuDialog::~MainMenuDialog() {
@ -310,6 +312,8 @@ MainMenuDialog::~MainMenuDialog() {
#ifndef DISABLE_HELP
delete _helpDialog;
#endif
delete _saveDialog;
delete _loadDialog;
}
void MainMenuDialog::open() {
@ -361,10 +365,10 @@ void MainMenuDialog::close() {
void MainMenuDialog::save() {
int idx;
SaveLoadChooser dialog("Save game:", generateSavegameList(_scumm, true), "Save", true);
idx = dialog.runModal();
_saveDialog->setList(generateSavegameList(_scumm, true));
idx = _saveDialog->runModal();
if (idx >= 0) {
const String &result = dialog.getResultString();
const String &result = _saveDialog->getResultString();
char buffer[20];
const char *str;
if (result.isEmpty()) {
@ -380,8 +384,8 @@ void MainMenuDialog::save() {
void MainMenuDialog::load() {
int idx;
SaveLoadChooser dialog("Load game:", generateSavegameList(_scumm, false), "Load", false);
idx = dialog.runModal();
_loadDialog->setList(generateSavegameList(_scumm, false));
idx = _loadDialog->runModal();
if (idx >= 0) {
_scumm->requestLoad(idx);
close();

View file

@ -54,6 +54,8 @@ protected:
const String queryResString(int stringno);
};
class SaveLoadChooser;
class MainMenuDialog : public ScummDialog {
public:
MainMenuDialog(ScummEngine *scumm);
@ -67,6 +69,8 @@ protected:
#ifndef DISABLE_HELP
GUI::Dialog *_helpDialog;
#endif
SaveLoadChooser *_saveDialog;
SaveLoadChooser *_loadDialog;
void save();
void load();