diff options
author | Eugene Sandulenko | 2015-11-06 06:34:50 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2015-11-07 13:26:55 +0100 |
commit | 81a4359eeed8305ab10f8d66236c0888ad3364d4 (patch) | |
tree | 9c768a7b39ba494cfa0d77b5f27bcc5e6fcfb7e3 | |
parent | 6f44d4f7e199813e7cfc68c7be246a08afe6df40 (diff) | |
download | scummvm-rg350-81a4359eeed8305ab10f8d66236c0888ad3364d4.tar.gz scummvm-rg350-81a4359eeed8305ab10f8d66236c0888ad3364d4.tar.bz2 scummvm-rg350-81a4359eeed8305ab10f8d66236c0888ad3364d4.zip |
BBVS: Implement file chooser for Air Guitar minigame
-rw-r--r-- | engines/bbvs/minigames/bbairguitar.cpp | 25 | ||||
-rw-r--r-- | gui/filebrowser-dialog.cpp | 160 | ||||
-rw-r--r-- | gui/filebrowser-dialog.h | 64 | ||||
-rw-r--r-- | gui/module.mk | 1 | ||||
-rw-r--r-- | gui/themes/default.inc | 44 | ||||
-rw-r--r-- | gui/themes/scummclassic.zip | bin | 110106 -> 111302 bytes | |||
-rw-r--r-- | gui/themes/scummclassic/classic_layout.stx | 41 | ||||
-rw-r--r-- | gui/themes/scummclassic/classic_layout_lowres.stx | 35 | ||||
-rw-r--r-- | gui/themes/scummmodern.zip | bin | 1485886 -> 1487079 bytes | |||
-rw-r--r-- | gui/themes/scummmodern/scummmodern_layout.stx | 43 | ||||
-rw-r--r-- | gui/themes/scummmodern/scummmodern_layout_lowres.stx | 37 |
11 files changed, 411 insertions, 39 deletions
diff --git a/engines/bbvs/minigames/bbairguitar.cpp b/engines/bbvs/minigames/bbairguitar.cpp index 26e27a966f..04175f7290 100644 --- a/engines/bbvs/minigames/bbairguitar.cpp +++ b/engines/bbvs/minigames/bbairguitar.cpp @@ -27,6 +27,7 @@ #include "gui/dialog.h" #include "gui/message.h" +#include "gui/filebrowser-dialog.h" namespace Bbvs { @@ -1204,15 +1205,25 @@ void MinigameBbAirGuitar::stopNote(int noteNum) { } bool MinigameBbAirGuitar::getLoadFilename(Common::String &filename) { - // TODO Run dialog and return actual filename - filename = "test.air"; - return true; + GUI::FileBrowserDialog browser(0, "air", GUI::kFBModeLoad); + + if (browser.runModal() > 0) { + filename = browser.getResult(); + return true; + } + + return false; } bool MinigameBbAirGuitar::getSaveFilename(Common::String &filename) { - // TODO Run dialog and return actual filename - filename = "test.air"; - return true; + GUI::FileBrowserDialog browser(0, "air", GUI::kFBModeSave); + + if (browser.runModal() > 0) { + filename = browser.getResult(); + return true; + } + + return false; } bool MinigameBbAirGuitar::querySaveModifiedDialog() { @@ -1240,7 +1251,7 @@ bool MinigameBbAirGuitar::loadTracks() { if (!querySaveModifiedTracks()) return false; - + Common::String filename; if (!getLoadFilename(filename)) return false; diff --git a/gui/filebrowser-dialog.cpp b/gui/filebrowser-dialog.cpp new file mode 100644 index 0000000000..93395ba909 --- /dev/null +++ b/gui/filebrowser-dialog.cpp @@ -0,0 +1,160 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "gui/filebrowser-dialog.h" + +#include "common/system.h" +#include "common/algorithm.h" +#include "common/savefile.h" +#include "common/str-array.h" + +#include "common/translation.h" + +#include "gui/widgets/list.h" +#include "gui/message.h" + +namespace GUI { + +enum { + kChooseCmd = 'Chos' +}; + +FileBrowserDialog::FileBrowserDialog(const char *title, const char *fileExtension, int mode) + : Dialog("FileBrowser"), _mode(mode), _fileExt(fileExtension) { + + _fileMask = "*."; + _fileMask += fileExtension; + _fileList = NULL; + + new StaticTextWidget(this, "FileBrowser.Headline", title ? title : + mode == kFBModeLoad ? _("Choose file for loading") : _("Enter filename for saving")); + + _fileName = new EditTextWidget(this, "FileBrowser.Filename", ""); + + if (mode == kFBModeLoad) + _fileName->setEnabled(false); + + // Add file list + _fileList = new ListWidget(this, "FileBrowser.List"); + _fileList->setNumberingMode(kListNumberingOff); + _fileList->setEditable(false); + + _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; + + // Buttons + new ButtonWidget(this, "FileBrowser.Cancel", _("Cancel"), 0, kCloseCmd); + new ButtonWidget(this, "FileBrowser.Choose", _("Choose"), 0, kChooseCmd); +} + +void FileBrowserDialog::open() { + // Call super implementation + Dialog::open(); + + updateListing(); +} + +void FileBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + switch (cmd) { + case kChooseCmd: + if (_fileName->getEditString().empty()) + break; + + normalieFileName(); + + if (!isProceedSave()) + break; + + setResult(1); + close(); + break; + case kListSelectionChangedCmd: + _fileName->setEditString(_fileList->getList().operator[](_fileList->getSelected()).c_str()); + _fileName->draw(); + break; + case kListItemActivatedCmd: + case kListItemDoubleClickedCmd: + normalieFileName(); + + if (!isProceedSave()) + break; + + setResult(1); + close(); + break; + default: + Dialog::handleCommand(sender, cmd, data); + } +} + +void FileBrowserDialog::normalieFileName() { + Common::String filename = _fileName->getEditString(); + + if (filename.matchString(_fileMask)) + return; + + _fileName->setEditString(filename + "." + _fileExt); +} + + +bool FileBrowserDialog::isProceedSave() { + bool matched = false; + + if (_mode == kFBModeLoad) + return true; + + for (ListWidget::StringArray::const_iterator file = _fileList->getList().begin(); file != _fileList->getList().end(); ++file) { + if (*file == _fileName->getEditString()) { + matched = true; + break; + } + } + + if (matched) { + GUI::MessageDialog alert(_("Do you really want to overwrite the file?"), _("Yes"), _("No")); + + if (alert.runModal() != GUI::kMessageOK) + return false; + } + + return true; +} + +void FileBrowserDialog::updateListing() { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + + ListWidget::StringArray list; + + Common::StringArray filenames = saveFileMan->listSavefiles(_fileMask); + Common::sort(filenames.begin(), filenames.end()); + + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + list.push_back(file->c_str()); + } + + _fileList->setList(list); + _fileList->scrollTo(0); + + // Finally, redraw + draw(); +} + +} // End of namespace GUI diff --git a/gui/filebrowser-dialog.h b/gui/filebrowser-dialog.h new file mode 100644 index 0000000000..5916d76c80 --- /dev/null +++ b/gui/filebrowser-dialog.h @@ -0,0 +1,64 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef FILEBROWSER_DIALOG_H +#define FILEBROWSER_DIALOG_H + +#include "gui/dialog.h" +#include "gui/widgets/edittext.h" + +namespace GUI { + +class ListWidget; +class EditTextWidget; +class CommandSender; + +enum { + kFBModeLoad = 0, + kFBModeSave +}; + +class FileBrowserDialog : public Dialog { +public: + FileBrowserDialog(const char *title, const char *fileExtension, int mode); + + virtual void open(); + + virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); + + const char *getResult() { return Dialog::getResult() ? _fileName->getEditString().c_str() : NULL; } + +protected: + EditTextWidget *_fileName; + ListWidget *_fileList; + Common::String _fileMask; + Common::String _fileExt; + int _mode; + + void updateListing(); + void normalieFileName(); + bool isProceedSave(); +}; + +} // End of namespace GUI + +#endif diff --git a/gui/module.mk b/gui/module.mk index 338e43c6a4..e355212620 100644 --- a/gui/module.mk +++ b/gui/module.mk @@ -8,6 +8,7 @@ MODULE_OBJS := \ dialog.o \ error.o \ EventRecorder.o \ + filebrowser-dialog.o \ gui-manager.o \ launcher.o \ massadd.o \ diff --git a/gui/themes/default.inc b/gui/themes/default.inc index aa2a24bf00..33aac29835 100644 --- a/gui/themes/default.inc +++ b/gui/themes/default.inc @@ -771,6 +771,28 @@ "</layout>" "</layout>" "</dialog>" +"<dialog name='FileBrowser' overlays='screen' inset='32' shading='dim'>" +"<layout type='vertical' padding='16,16,16,16'>" +"<widget name='Headline' " +"height='Globals.Line.Height' " +"/>" +"<widget name='Filename' " +"height='Globals.Line.Height' " +"/>" +"<space size='10' />" +"<widget name='List'/>" +"<layout type='vertical' padding='0,0,16,0'>" +"<layout type='horizontal' padding='0,0,0,0'>" +"<widget name='Cancel' " +"type='Button' " +"/>" +"<widget name='Choose' " +"type='Button' " +"/>" +"</layout>" +"</layout>" +"</layout>" +"</dialog>" "<dialog name='GlobalOptions' overlays='Dialog.Launcher.GameList' shading='dim'>" "<layout type='vertical' padding='0,0,0,0'>" "<widget name='TabWidget'/>" @@ -2031,6 +2053,28 @@ "</layout>" "</layout>" "</dialog>" +"<dialog name='FileBrowser' overlays='screen' inset='16' shading='dim'>" +"<layout type='vertical' padding='16,16,16,16'>" +"<widget name='Headline' " +"height='Globals.Line.Height' " +"/>" +"<widget name='Filename' " +"height='Globals.Line.Height' " +"/>" +"<space size='5' />" +"<widget name='List'/>" +"<layout type='vertical' padding='0,0,16,0'>" +"<layout type='horizontal' padding='0,0,0,0'>" +"<widget name='Cancel' " +"type='Button' " +"/>" +"<widget name='Choose' " +"type='Button' " +"/>" +"</layout>" +"</layout>" +"</layout>" +"</dialog>" "<dialog name='GlobalOptions' overlays='screen' inset='16' shading='dim'>" "<layout type='vertical' padding='0,0,0,0'>" "<widget name='TabWidget'/>" diff --git a/gui/themes/scummclassic.zip b/gui/themes/scummclassic.zip Binary files differindex 1b555a6c27..d7016cab58 100644 --- a/gui/themes/scummclassic.zip +++ b/gui/themes/scummclassic.zip diff --git a/gui/themes/scummclassic/classic_layout.stx b/gui/themes/scummclassic/classic_layout.stx index cf8268696d..26656deaf9 100644 --- a/gui/themes/scummclassic/classic_layout.stx +++ b/gui/themes/scummclassic/classic_layout.stx @@ -196,6 +196,29 @@ </layout> </dialog> + <dialog name = 'FileBrowser' overlays = 'screen' inset = '32' shading = 'dim'> + <layout type = 'vertical' padding = '16, 16, 16, 16'> + <widget name = 'Headline' + height = 'Globals.Line.Height' + /> + <widget name = 'Filename' + height = 'Globals.Line.Height' + /> + <space size = '10' /> + <widget name = 'List'/> + <layout type = 'vertical' padding = '0, 0, 16, 0'> + <layout type = 'horizontal' padding = '0, 0, 0, 0'> + <widget name = 'Cancel' + type = 'Button' + /> + <widget name = 'Choose' + type = 'Button' + /> + </layout> + </layout> + </layout> + </dialog> + <dialog name = 'GlobalOptions' overlays = 'Dialog.Launcher.GameList' shading = 'dim'> <layout type = 'vertical' padding = '0, 0, 0, 0'> <widget name = 'TabWidget'/> @@ -673,7 +696,7 @@ /> </layout> </dialog> - + <dialog name = 'GlobalMenu' overlays = 'screen_center'> <layout type = 'vertical' padding = '16, 16, 16, 16' center = 'true'> <widget name = 'Title' @@ -1040,7 +1063,7 @@ width = '180' height = '170' /> - <layout type = 'horizontal' padding = '0, 0, 0, 0'> + <layout type = 'horizontal' padding = '0, 0, 0, 0'> <widget name = 'NextScreenShotButton' width = '25' height = '25' @@ -1115,15 +1138,15 @@ <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'AuthorLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'AuthorEdit' type = 'EditRecord' - /> + /> </layout> <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'NameLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'NameEdit' type = 'EditRecord' /> @@ -1142,11 +1165,11 @@ /> <widget name = 'OK' type = 'Button' - /> + /> </layout> </layout> </dialog> - + <dialog name = 'ScummHelp' overlays = 'screen_center'> <layout type = 'vertical' padding = '8, 8, 8, 8' center = 'true'> <widget name = 'Title' @@ -1250,7 +1273,7 @@ <layout type = 'horizontal' padding = '5, 5, 5, 5'> <widget name = 'Word' width = '190' - height = 'Globals.Button.Height' + height = 'Globals.Button.Height' /> <widget name = 'Delete' width = '20' @@ -1315,7 +1338,7 @@ /> </layout> <space size = '5' /> - <layout type = 'horizontal' padding = '3, 3, 3, 3'> + <layout type = 'horizontal' padding = '3, 3, 3, 3'> <widget name = 'Add' width = 'Globals.Predictive.Button.Width' height = 'Globals.Button.Height' diff --git a/gui/themes/scummclassic/classic_layout_lowres.stx b/gui/themes/scummclassic/classic_layout_lowres.stx index 506657ef31..60057fa4ba 100644 --- a/gui/themes/scummclassic/classic_layout_lowres.stx +++ b/gui/themes/scummclassic/classic_layout_lowres.stx @@ -193,6 +193,29 @@ </layout> </dialog> + <dialog name = 'FileBrowser' overlays = 'screen' inset = '16' shading = 'dim'> + <layout type = 'vertical' padding = '16, 16, 16, 16'> + <widget name = 'Headline' + height = 'Globals.Line.Height' + /> + <widget name = 'Filename' + height = 'Globals.Line.Height' + /> + <space size = '5' /> + <widget name = 'List'/> + <layout type = 'vertical' padding = '0, 0, 16, 0'> + <layout type = 'horizontal' padding = '0, 0, 0, 0'> + <widget name = 'Cancel' + type = 'Button' + /> + <widget name = 'Choose' + type = 'Button' + /> + </layout> + </layout> + </layout> + </dialog> + <dialog name = 'GlobalOptions' overlays = 'screen' inset = '16' shading = 'dim'> <layout type = 'vertical' padding = '0, 0, 0, 0'> <widget name = 'TabWidget'/> @@ -685,7 +708,7 @@ /> </layout> </dialog> - + <dialog name = 'GlobalMenu' overlays = 'screen_center'> <layout type = 'vertical' padding = '2, 2, 2, 6' center = 'true' spacing='0'> <widget name = 'Title' @@ -1086,15 +1109,15 @@ <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'AuthorLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'AuthorEdit' type = 'EditRecord' - /> + /> </layout> <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'NameLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'NameEdit' type = 'EditRecord' /> @@ -1113,7 +1136,7 @@ /> <widget name = 'OK' type = 'Button' - /> + /> </layout> </layout> </dialog> @@ -1220,7 +1243,7 @@ <layout type = 'horizontal' padding = '3, 3, 3, 3'> <widget name = 'Word' width = '120' - height = 'Globals.Button.Height' + height = 'Globals.Button.Height' /> <widget name = 'Delete' width = '20' diff --git a/gui/themes/scummmodern.zip b/gui/themes/scummmodern.zip Binary files differindex c7c585654d..5bf1b8e17d 100644 --- a/gui/themes/scummmodern.zip +++ b/gui/themes/scummmodern.zip diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx index 7e61d6820e..3254049c62 100644 --- a/gui/themes/scummmodern/scummmodern_layout.stx +++ b/gui/themes/scummmodern/scummmodern_layout.stx @@ -67,7 +67,7 @@ <widget name = 'Button' size = '108, 24' - /> + /> <widget name = 'Slider' size = '128, 18' @@ -210,6 +210,29 @@ </layout> </dialog> + <dialog name = 'FileBrowser' overlays = 'screen' inset = '32' shading = 'dim'> + <layout type = 'vertical' padding = '16, 16, 16, 16'> + <widget name = 'Headline' + height = 'Globals.Line.Height' + /> + <widget name = 'Filename' + height = 'Globals.Line.Height' + /> + <space size = '10' /> + <widget name = 'List'/> + <layout type = 'vertical' padding = '0, 0, 16, 0'> + <layout type = 'horizontal' padding = '0, 0, 0, 0'> + <widget name = 'Cancel' + type = 'Button' + /> + <widget name = 'Choose' + type = 'Button' + /> + </layout> + </layout> + </layout> + </dialog> + <dialog name = 'GlobalOptions' overlays = 'Dialog.Launcher.GameList' shading = 'dim'> <layout type = 'vertical' padding = '0, 0, 0, 0'> <widget name = 'TabWidget'/> @@ -687,7 +710,7 @@ /> </layout> </dialog> - + <dialog name = 'GlobalMenu' overlays = 'screen_center'> <layout type = 'vertical' padding = '16, 16, 16, 16' center = 'true'> <widget name = 'Logo' @@ -1054,7 +1077,7 @@ width = '180' height = '170' /> - <layout type = 'horizontal' padding = '0, 0, 0, 0'> + <layout type = 'horizontal' padding = '0, 0, 0, 0'> <widget name = 'NextScreenShotButton' width = '25' height = '25' @@ -1130,15 +1153,15 @@ <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'AuthorLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'AuthorEdit' type = 'EditRecord' - /> + /> </layout> <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'NameLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'NameEdit' type = 'EditRecord' /> @@ -1157,11 +1180,11 @@ /> <widget name = 'OK' type = 'Button' - /> + /> </layout> </layout> </dialog> - + <dialog name = 'ScummHelp' overlays = 'screen_center'> <layout type = 'vertical' padding = '8, 8, 8, 8' center = 'true'> <widget name = 'Title' @@ -1252,7 +1275,7 @@ type = 'Button' /> </layout> - </dialog> + </dialog> <dialog name = 'Predictive' overlays = 'screen_center'> <layout type = 'vertical' padding = '5, 5, 5, 5' center = 'true'> <widget name = 'Headline' @@ -1264,7 +1287,7 @@ <layout type = 'horizontal' padding = '5, 5, 5, 5'> <widget name = 'Word' width = '190' - height = 'Globals.Button.Height' + height = 'Globals.Button.Height' /> <widget name = 'Delete' width = '20' diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx index cee1e4af2b..2b4dc099a0 100644 --- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx +++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx @@ -191,6 +191,29 @@ </layout> </dialog> + <dialog name = 'FileBrowser' overlays = 'screen' inset = '16' shading = 'dim'> + <layout type = 'vertical' padding = '16, 16, 16, 16'> + <widget name = 'Headline' + height = 'Globals.Line.Height' + /> + <widget name = 'Filename' + height = 'Globals.Line.Height' + /> + <space size = '5' /> + <widget name = 'List'/> + <layout type = 'vertical' padding = '0, 0, 16, 0'> + <layout type = 'horizontal' padding = '0, 0, 0, 0'> + <widget name = 'Cancel' + type = 'Button' + /> + <widget name = 'Choose' + type = 'Button' + /> + </layout> + </layout> + </layout> + </dialog> + <dialog name = 'GlobalOptions' overlays = 'screen' inset = '16' shading = 'dim'> <layout type = 'vertical' padding = '0, 0, 0, 0'> <widget name = 'TabWidget'/> @@ -683,7 +706,7 @@ /> </layout> </dialog> - + <dialog name = 'GlobalMenu' overlays = 'screen_center'> <layout type = 'vertical' padding = '4, 4, 4, 4' center = 'true' spacing='2'> <widget name = 'Title' @@ -1105,15 +1128,15 @@ <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'AuthorLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'AuthorEdit' type = 'EditRecord' - /> + /> </layout> <layout type = 'horizontal' spacing = '5' padding = '0, 0, 0, 10'> <widget name = 'NameLabel' type = 'EditRecordLabel' - /> + /> <widget name = 'NameEdit' type = 'EditRecord' /> @@ -1132,11 +1155,11 @@ /> <widget name = 'OK' type = 'Button' - /> + /> </layout> </layout> </dialog> - + <dialog name = 'ScummHelp' overlays = 'screen' inset = '8'> <layout type = 'vertical' padding = '8, 8, 8, 8'> <widget name = 'Title' @@ -1237,7 +1260,7 @@ <layout type = 'horizontal' padding = '0, 0, 2, 2'> <widget name = 'Word' width = '120' - height = 'Globals.Button.Height' + height = 'Globals.Button.Height' /> <widget name = 'Delete' width = '20' |