2007-05-30 21:56:52 +00:00
/* 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 .
2002-09-27 23:27:14 +00:00
*
* 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
2005-10-18 01:30:26 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2002-09-27 23:27:14 +00:00
*/
2004-02-09 01:27:27 +00:00
# include "base/version.h"
2003-11-05 00:59:03 +00:00
# include "common/config-manager.h"
2007-03-17 16:05:16 +00:00
# include "common/events.h"
2006-06-24 08:07:48 +00:00
# include "common/fs.h"
2003-11-05 00:59:03 +00:00
# include "common/util.h"
2005-05-16 00:26:23 +00:00
# include "common/system.h"
2010-06-15 10:44:51 +00:00
# include "common/translation.h"
2003-11-05 00:59:03 +00:00
2003-09-08 18:09:32 +00:00
# include "gui/about.h"
# include "gui/browser.h"
# include "gui/chooser.h"
# include "gui/launcher.h"
2007-02-18 18:23:52 +00:00
# include "gui/massadd.h"
2003-09-08 18:09:32 +00:00
# include "gui/message.h"
2010-11-16 10:19:01 +00:00
# include "gui/gui-manager.h"
2003-09-08 18:09:32 +00:00
# include "gui/options.h"
2008-11-11 12:13:55 +00:00
# include "gui/saveload.h"
2010-11-16 10:11:57 +00:00
# include "gui/widgets/edittext.h"
# include "gui/widgets/list.h"
# include "gui/widgets/tab.h"
# include "gui/widgets/popup.h"
2008-11-11 12:13:55 +00:00
# include "gui/ThemeEval.h"
2008-06-16 18:47:32 +00:00
# include "graphics/cursorman.h"
2002-09-27 23:27:14 +00:00
2003-10-08 21:59:23 +00:00
using Common : : ConfigManager ;
2002-09-27 23:27:14 +00:00
2003-11-10 23:40:48 +00:00
namespace GUI {
2002-09-27 23:27:14 +00:00
enum {
2002-09-30 00:55:47 +00:00
kStartCmd = ' STRT ' ,
2003-09-08 18:09:32 +00:00
kAboutCmd = ' ABOU ' ,
2002-09-30 00:55:47 +00:00
kOptionsCmd = ' OPTN ' ,
2002-10-13 11:51:48 +00:00
kAddGameCmd = ' ADDG ' ,
2002-11-21 13:11:29 +00:00
kEditGameCmd = ' EDTG ' ,
kRemoveGameCmd = ' REMG ' ,
2008-07-30 21:48:45 +00:00
kLoadGameCmd = ' LOAD ' ,
2003-11-07 16:01:51 +00:00
kQuitCmd = ' QUIT ' ,
2009-06-06 17:53:25 +00:00
kSearchCmd = ' SRCH ' ,
2009-06-06 17:54:28 +00:00
kListSearchCmd = ' LSSR ' ,
2009-06-07 22:19:48 +00:00
kSearchClearCmd = ' SRCL ' ,
2005-07-30 21:11:48 +00:00
2003-11-07 16:01:51 +00:00
kCmdGlobalGraphicsOverride = ' OGFX ' ,
kCmdGlobalAudioOverride = ' OSFX ' ,
2005-04-13 00:11:49 +00:00
kCmdGlobalMIDIOverride = ' OMID ' ,
2010-07-24 22:29:17 +00:00
kCmdGlobalMT32Override = ' OM32 ' ,
2004-06-29 14:23:39 +00:00
kCmdGlobalVolumeOverride = ' OVOL ' ,
2005-05-16 06:33:33 +00:00
kCmdChooseSoundFontCmd = ' chsf ' ,
2004-06-29 14:23:39 +00:00
kCmdExtraBrowser = ' PEXT ' ,
kCmdGameBrowser = ' PGME ' ,
kCmdSaveBrowser = ' PSAV '
2002-09-27 23:27:14 +00:00
} ;
2002-11-21 02:19:02 +00:00
2004-12-30 12:54:04 +00:00
/*
* TODO : Clean up this ugly design : we subclass EditTextWidget to perform
* input validation . It would be much more elegant to use a decorator pattern ,
* or a validation callback , or something like that .
*/
class DomainEditTextWidget : public EditTextWidget {
public :
2010-06-15 10:54:22 +00:00
DomainEditTextWidget ( GuiObject * boss , const String & name , const String & text , const char * tooltip = 0 )
: EditTextWidget ( boss , name , text , tooltip ) {
2004-12-30 12:54:04 +00:00
}
2005-07-30 21:11:48 +00:00
2004-12-30 12:54:04 +00:00
protected :
2006-06-20 22:50:27 +00:00
bool tryInsertChar ( byte c , int pos ) {
2004-12-30 12:54:04 +00:00
if ( isalnum ( c ) | | c = = ' - ' | | c = = ' _ ' ) {
2005-01-29 16:30:51 +00:00
_editString . insertChar ( c , pos ) ;
2004-12-30 12:54:04 +00:00
return true ;
}
return false ;
}
} ;
2002-11-21 14:12:55 +00:00
/*
* A dialog that allows the user to edit a config game entry .
2002-11-21 15:24:38 +00:00
* TODO : add widgets for some / all of the following
* - Maybe scaler / graphics mode . But there are two problems :
* 1 ) Different backends can have different scalers with different names ,
2002-11-21 14:12:55 +00:00
* so we first have to add a way to query those . . . no Ender , I don ' t
* think a bitmasked property ( ) value is nice for this , because we would
* have to add to the bitmask values whenever a backends adds a new scaler ) .
2002-11-21 15:24:38 +00:00
* 2 ) At the time the launcher is running , the GFX backend is already setup .
* So when a game is run via the launcher , the custom scaler setting for it won ' t be
2002-11-21 14:12:55 +00:00
* used . So we ' d also have to add an API to change the scaler during runtime
* ( the SDL backend can already do that based on user input , but there is no API
* to achieve it )
* If the APIs for 1 & 2 are in place , we can think about adding this to the Edit & Option dialogs
*/
2003-11-05 12:25:42 +00:00
class EditGameDialog : public OptionsDialog {
2003-10-02 17:43:02 +00:00
typedef Common : : String String ;
2010-03-18 15:09:24 +00:00
typedef Common : : Array < Common : : String > StringArray ;
2002-11-21 14:12:55 +00:00
public :
2006-03-09 02:52:51 +00:00
EditGameDialog ( const String & domain , const String & desc ) ;
2002-11-21 14:12:55 +00:00
2004-03-15 02:28:47 +00:00
void open ( ) ;
void close ( ) ;
2002-11-21 14:12:55 +00:00
virtual void handleCommand ( CommandSender * sender , uint32 cmd , uint32 data ) ;
protected :
2003-03-06 19:52:54 +00:00
EditTextWidget * _descriptionWidget ;
2004-12-30 12:54:04 +00:00
DomainEditTextWidget * _domainWidget ;
2003-11-05 12:25:42 +00:00
2004-06-29 14:23:39 +00:00
StaticTextWidget * _gamePathWidget ;
StaticTextWidget * _extraPathWidget ;
StaticTextWidget * _savePathWidget ;
2009-06-06 17:52:44 +00:00
StaticTextWidget * _langPopUpDesc ;
2003-11-05 00:59:03 +00:00
PopUpWidget * _langPopUp ;
2009-06-06 17:52:44 +00:00
StaticTextWidget * _platformPopUpDesc ;
2003-11-05 00:59:03 +00:00
PopUpWidget * _platformPopUp ;
2003-11-07 16:01:51 +00:00
CheckboxWidget * _globalGraphicsOverride ;
CheckboxWidget * _globalAudioOverride ;
2005-04-13 00:11:49 +00:00
CheckboxWidget * _globalMIDIOverride ;
2010-07-24 22:29:17 +00:00
CheckboxWidget * _globalMT32Override ;
2003-11-07 16:01:51 +00:00
CheckboxWidget * _globalVolumeOverride ;
2002-11-21 14:12:55 +00:00
} ;
2006-03-09 02:52:51 +00:00
EditGameDialog : : EditGameDialog ( const String & domain , const String & desc )
2008-08-07 10:53:33 +00:00
: OptionsDialog ( domain , " GameOptions " ) {
2003-11-03 23:42:53 +00:00
2004-06-29 14:23:39 +00:00
// GAME: Path to game data (r/o), extra data (r/o), and save data (r/w)
String gamePath ( ConfMan . get ( " path " , _domain ) ) ;
String extraPath ( ConfMan . get ( " extrapath " , _domain ) ) ;
String savePath ( ConfMan . get ( " savepath " , _domain ) ) ;
2003-11-03 05:27:53 +00:00
// GAME: Determine the description string
2003-10-08 21:59:23 +00:00
String description ( ConfMan . get ( " description " , domain ) ) ;
2006-03-28 09:42:54 +00:00
if ( description . empty ( ) & & ! desc . empty ( ) ) {
2006-02-18 11:12:08 +00:00
description = desc ;
2002-11-21 14:12:55 +00:00
}
2003-09-08 15:38:34 +00:00
2003-11-03 23:42:53 +00:00
// GUI: Add tab widget
2008-08-07 10:53:33 +00:00
TabWidget * tab = new TabWidget ( this , " GameOptions.TabWidget " ) ;
2003-11-03 23:42:53 +00:00
2003-11-04 21:17:33 +00:00
//
// 1) The game tab
//
2010-06-15 10:44:51 +00:00
tab - > addTab ( _ ( " Game " ) ) ;
2003-11-03 05:27:53 +00:00
// GUI: Label & edit widget for the game ID
2010-09-11 16:18:55 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
new StaticTextWidget ( tab , " GameOptions_Game.Id " , _ ( " ID: " ) , _ ( " Short game identifier used for referring to savegames and running the game from the command line " ) ) ;
else
new StaticTextWidget ( tab , " GameOptions_Game.Id " , _c ( " ID: " , " lowres " ) , _ ( " Short game identifier used for referring to savegames and running the game from the command line " ) ) ;
2010-06-15 10:54:22 +00:00
_domainWidget = new DomainEditTextWidget ( tab , " GameOptions_Game.Domain " , _domain , _ ( " Short game identifier used for referring to savegames and running the game from the command line " ) ) ;
2003-11-03 05:27:53 +00:00
// GUI: Label & edit widget for the description
2010-09-19 17:50:21 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
new StaticTextWidget ( tab , " GameOptions_Game.Name " , _ ( " Name: " ) , _ ( " Full title of the game " ) ) ;
else
new StaticTextWidget ( tab , " GameOptions_Game.Name " , _c ( " Name: " , " lowres " ) , _ ( " Full title of the game " ) ) ;
2010-06-15 10:54:22 +00:00
_descriptionWidget = new EditTextWidget ( tab , " GameOptions_Game.Desc " , description , _ ( " Full title of the game " ) ) ;
2003-11-03 05:27:53 +00:00
2004-06-29 14:23:39 +00:00
// Language popup
2010-06-15 10:53:30 +00:00
_langPopUpDesc = new StaticTextWidget ( tab , " GameOptions_Game.LangPopupDesc " , _ ( " Language: " ) , _ ( " Language of the game. This will not turn your Spanish game version into English " ) ) ;
_langPopUp = new PopUpWidget ( tab , " GameOptions_Game.LangPopup " , _ ( " Language of the game. This will not turn your Spanish game version into English " ) ) ;
2011-01-18 21:03:13 +00:00
_langPopUp - > appendEntry ( _ ( " <default> " ) , ( uint32 ) Common : : UNK_LANG ) ;
_langPopUp - > appendEntry ( " " , ( uint32 ) Common : : UNK_LANG ) ;
2003-11-05 00:59:03 +00:00
const Common : : LanguageDescription * l = Common : : g_languages ;
2003-12-30 19:07:55 +00:00
for ( ; l - > code ; + + l ) {
2010-06-15 10:57:28 +00:00
if ( checkGameGUIOptionLanguage ( l - > id , _guioptionsString ) )
_langPopUp - > appendEntry ( l - > description , l - > id ) ;
2003-11-05 00:59:03 +00:00
}
// Platform popup
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
_platformPopUpDesc = new StaticTextWidget ( tab , " GameOptions_Game.PlatformPopupDesc " , _ ( " Platform: " ) , _ ( " Platform the game was originally designed for " ) ) ;
else
_platformPopUpDesc = new StaticTextWidget ( tab , " GameOptions_Game.PlatformPopupDesc " , _c ( " Platform: " , " lowres " ) , _ ( " Platform the game was originally designed for " ) ) ;
2010-06-15 10:53:30 +00:00
_platformPopUp = new PopUpWidget ( tab , " GameOptions_Game.PlatformPopup " , _ ( " Platform the game was originally designed for " ) ) ;
2010-06-15 10:44:51 +00:00
_platformPopUp - > appendEntry ( _ ( " <default> " ) ) ;
2003-11-05 00:59:03 +00:00
_platformPopUp - > appendEntry ( " " ) ;
2004-02-07 17:12:10 +00:00
const Common : : PlatformDescription * p = Common : : g_platforms ;
for ( ; p - > code ; + + p ) {
_platformPopUp - > appendEntry ( p - > description , p - > id ) ;
}
2003-11-03 05:27:53 +00:00
2003-11-04 21:17:33 +00:00
//
2010-07-24 22:29:17 +00:00
// 2) The graphics tab
2003-11-04 21:17:33 +00:00
//
2010-06-15 10:44:51 +00:00
_graphicsTabId = tab - > addTab ( g_system - > getOverlayWidth ( ) > 320 ? _ ( " Graphics " ) : _ ( " GFX " ) ) ;
2003-11-07 16:01:51 +00:00
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
_globalGraphicsOverride = new CheckboxWidget ( tab , " GameOptions_Graphics.EnableTabCheckbox " , _ ( " Override global graphic settings " ) , 0 , kCmdGlobalGraphicsOverride ) ;
else
_globalGraphicsOverride = new CheckboxWidget ( tab , " GameOptions_Graphics.EnableTabCheckbox " , _c ( " Override global graphic settings " , " lowres " ) , 0 , kCmdGlobalGraphicsOverride ) ;
2003-11-07 16:01:51 +00:00
2008-08-07 10:53:33 +00:00
addGraphicControls ( tab , " GameOptions_Graphics. " ) ;
2003-11-04 21:17:33 +00:00
//
2010-07-24 22:29:17 +00:00
// 3) The audio tab
2003-11-04 21:17:33 +00:00
//
2010-06-15 10:44:51 +00:00
tab - > addTab ( _ ( " Audio " ) ) ;
2003-11-07 16:01:51 +00:00
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
_globalAudioOverride = new CheckboxWidget ( tab , " GameOptions_Audio.EnableTabCheckbox " , _ ( " Override global audio settings " ) , 0 , kCmdGlobalAudioOverride ) ;
else
_globalAudioOverride = new CheckboxWidget ( tab , " GameOptions_Audio.EnableTabCheckbox " , _c ( " Override global audio settings " , " lowres " ) , 0 , kCmdGlobalAudioOverride ) ;
2003-11-07 16:01:51 +00:00
2008-08-07 10:53:33 +00:00
addAudioControls ( tab , " GameOptions_Audio. " ) ;
addSubtitleControls ( tab , " GameOptions_Audio. " ) ;
2005-04-13 00:11:49 +00:00
//
2010-07-24 22:29:17 +00:00
// 4) The volume tab
2005-04-13 00:11:49 +00:00
//
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
tab - > addTab ( _ ( " Volume " ) ) ;
else
tab - > addTab ( _c ( " Volume " , " lowres " ) ) ;
2005-04-13 00:11:49 +00:00
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
_globalVolumeOverride = new CheckboxWidget ( tab , " GameOptions_Volume.EnableTabCheckbox " , _ ( " Override global volume settings " ) , 0 , kCmdGlobalVolumeOverride ) ;
else
_globalVolumeOverride = new CheckboxWidget ( tab , " GameOptions_Volume.EnableTabCheckbox " , _c ( " Override global volume settings " , " lowres " ) , 0 , kCmdGlobalVolumeOverride ) ;
2005-04-13 00:11:49 +00:00
2008-08-07 10:53:33 +00:00
addVolumeControls ( tab , " GameOptions_Volume. " ) ;
2003-11-04 21:17:33 +00:00
2003-11-05 12:25:42 +00:00
//
2010-07-24 22:29:17 +00:00
// 5) The MIDI tab
2003-11-05 12:25:42 +00:00
//
2010-06-15 10:44:51 +00:00
tab - > addTab ( _ ( " MIDI " ) ) ;
2003-11-07 16:01:51 +00:00
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
_globalMIDIOverride = new CheckboxWidget ( tab , " GameOptions_MIDI.EnableTabCheckbox " , _ ( " Override global MIDI settings " ) , 0 , kCmdGlobalMIDIOverride ) ;
else
_globalMIDIOverride = new CheckboxWidget ( tab , " GameOptions_MIDI.EnableTabCheckbox " , _c ( " Override global MIDI settings " , " lowres " ) , 0 , kCmdGlobalMIDIOverride ) ;
2003-11-07 16:01:51 +00:00
2009-06-06 18:21:07 +00:00
if ( _guioptions & Common : : GUIO_NOMIDI )
_globalMIDIOverride - > setEnabled ( false ) ;
2008-08-07 10:53:33 +00:00
addMIDIControls ( tab , " GameOptions_MIDI. " ) ;
2003-11-04 21:17:33 +00:00
2006-06-15 02:30:05 +00:00
//
2010-07-24 22:29:17 +00:00
// 6) The MT-32 tab
//
tab - > addTab ( _ ( " MT-32 " ) ) ;
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
_globalMT32Override = new CheckboxWidget ( tab , " GameOptions_MT32.EnableTabCheckbox " , _ ( " Override global MT-32 settings " ) , 0 , kCmdGlobalMT32Override ) ;
else
_globalMT32Override = new CheckboxWidget ( tab , " GameOptions_MT32.EnableTabCheckbox " , _c ( " Override global MT-32 settings " , " lowres " ) , 0 , kCmdGlobalMT32Override ) ;
2010-07-24 22:29:17 +00:00
//if (_guioptions & Common::GUIO_NOMIDI)
// _globalMT32Override->setEnabled(false);
addMT32Controls ( tab , " GameOptions_MT32. " ) ;
//
// 7) The Paths tab
2006-06-15 02:30:05 +00:00
//
2010-09-11 16:18:55 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
tab - > addTab ( _ ( " Paths " ) ) ;
else
tab - > addTab ( _c ( " Paths " , " lowres " ) ) ;
2006-06-15 02:30:05 +00:00
// These buttons have to be extra wide, or the text will be truncated
// in the small version of the GUI.
// GUI: Button + Label for the game path
2010-09-11 16:18:55 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
new ButtonWidget ( tab , " GameOptions_Paths.Gamepath " , _ ( " Game Path: " ) , 0 , kCmdGameBrowser ) ;
else
2010-10-12 00:26:17 +00:00
new ButtonWidget ( tab , " GameOptions_Paths.Gamepath " , _c ( " Game Path: " , " lowres " ) , 0 , kCmdGameBrowser ) ;
2008-08-07 10:53:33 +00:00
_gamePathWidget = new StaticTextWidget ( tab , " GameOptions_Paths.GamepathText " , gamePath ) ;
2006-06-15 02:30:05 +00:00
// GUI: Button + Label for the additional path
2010-09-11 16:18:55 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
new ButtonWidget ( tab , " GameOptions_Paths.Extrapath " , _ ( " Extra Path: " ) , _ ( " Specifies path to additional data used the game " ) , kCmdExtraBrowser ) ;
else
new ButtonWidget ( tab , " GameOptions_Paths.Extrapath " , _c ( " Extra Path: " , " lowres " ) , _ ( " Specifies path to additional data used the game " ) , kCmdExtraBrowser ) ;
2010-06-15 10:53:30 +00:00
_extraPathWidget = new StaticTextWidget ( tab , " GameOptions_Paths.ExtrapathText " , extraPath , _ ( " Specifies path to additional data used the game " ) ) ;
2006-06-15 02:30:05 +00:00
// GUI: Button + Label for the save path
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 )
new ButtonWidget ( tab , " GameOptions_Paths.Savepath " , _ ( " Save Path: " ) , _ ( " Specifies where your savegames are put " ) , kCmdSaveBrowser ) ;
else
new ButtonWidget ( tab , " GameOptions_Paths.Savepath " , _c ( " Save Path: " , " lowres " ) , _ ( " Specifies where your savegames are put " ) , kCmdSaveBrowser ) ;
2010-06-15 10:53:30 +00:00
_savePathWidget = new StaticTextWidget ( tab , " GameOptions_Paths.SavepathText " , savePath , _ ( " Specifies where your savegames are put " ) ) ;
2008-12-22 11:22:15 +00:00
2003-11-03 23:42:53 +00:00
// Activate the first tab
tab - > setActiveTab ( 0 ) ;
2008-08-14 23:17:41 +00:00
_tabWidget = tab ;
2003-11-03 05:27:53 +00:00
2003-11-05 12:25:42 +00:00
// Add OK & Cancel buttons
2010-06-15 10:52:35 +00:00
new ButtonWidget ( this , " GameOptions.Cancel " , _ ( " Cancel " ) , 0 , kCloseCmd ) ;
new ButtonWidget ( this , " GameOptions.Ok " , _ ( " OK " ) , 0 , kOKCmd ) ;
2002-11-21 14:12:55 +00:00
}
2004-03-15 02:28:47 +00:00
void EditGameDialog : : open ( ) {
OptionsDialog : : open ( ) ;
2003-11-05 12:25:42 +00:00
2009-01-10 23:38:30 +00:00
String extraPath ( ConfMan . get ( " extrapath " , _domain ) ) ;
if ( extraPath . empty ( ) | | ! ConfMan . hasKey ( " extrapath " , _domain ) ) {
2010-08-23 19:45:14 +00:00
_extraPathWidget - > setLabel ( _c ( " None " , " path " ) ) ;
2009-01-10 23:38:30 +00:00
}
String savePath ( ConfMan . get ( " savepath " , _domain ) ) ;
if ( savePath . empty ( ) | | ! ConfMan . hasKey ( " savepath " , _domain ) ) {
2010-06-15 10:44:51 +00:00
_savePathWidget - > setLabel ( _ ( " Default " ) ) ;
2009-01-10 23:38:30 +00:00
}
2004-02-07 17:12:10 +00:00
int sel , i ;
2007-06-11 07:57:39 +00:00
bool e ;
2003-11-07 16:01:51 +00:00
2004-02-07 17:12:10 +00:00
// En-/disable dialog items depending on whether overrides are active or not.
2007-03-10 18:25:37 +00:00
e = ConfMan . hasKey ( " gfx_mode " , _domain ) | |
ConfMan . hasKey ( " render_mode " , _domain ) | |
ConfMan . hasKey ( " fullscreen " , _domain ) | |
2010-11-04 15:58:53 +00:00
ConfMan . hasKey ( " aspect_ratio " , _domain ) | |
2010-11-05 10:53:37 +00:00
ConfMan . hasKey ( " disable_dithering " , _domain ) ;
2003-11-07 16:01:51 +00:00
_globalGraphicsOverride - > setState ( e ) ;
e = ConfMan . hasKey ( " music_driver " , _domain ) | |
2007-03-10 18:25:37 +00:00
ConfMan . hasKey ( " output_rate " , _domain ) | |
2009-05-13 21:02:03 +00:00
ConfMan . hasKey ( " opl_driver " , _domain ) | |
2006-05-13 17:30:04 +00:00
ConfMan . hasKey ( " subtitles " , _domain ) | |
ConfMan . hasKey ( " talkspeed " , _domain ) ;
2007-06-11 07:57:39 +00:00
_globalAudioOverride - > setState ( e ) ;
2003-11-07 16:01:51 +00:00
2007-06-11 07:57:39 +00:00
e = ConfMan . hasKey ( " music_volume " , _domain ) | |
2004-04-05 18:24:36 +00:00
ConfMan . hasKey ( " sfx_volume " , _domain ) | |
2004-04-06 11:50:35 +00:00
ConfMan . hasKey ( " speech_volume " , _domain ) ;
2007-06-11 07:57:39 +00:00
_globalVolumeOverride - > setState ( e ) ;
2007-03-10 18:25:37 +00:00
e = ConfMan . hasKey ( " soundfont " , _domain ) | |
ConfMan . hasKey ( " multi_midi " , _domain ) | |
ConfMan . hasKey ( " midi_gain " , _domain ) ;
_globalMIDIOverride - > setState ( e ) ;
2003-11-07 16:01:51 +00:00
2010-07-24 22:29:17 +00:00
e = ConfMan . hasKey ( " native_mt32 " , _domain ) | |
ConfMan . hasKey ( " enable_gs " , _domain ) ;
_globalMT32Override - > setState ( e ) ;
2003-11-05 12:25:42 +00:00
// TODO: game path
2004-02-07 17:12:10 +00:00
const Common : : Language lang = Common : : parseLanguage ( ConfMan . get ( " language " , _domain ) ) ;
2006-05-30 01:41:49 +00:00
if ( ConfMan . hasKey ( " language " , _domain ) ) {
2010-06-15 10:57:28 +00:00
_langPopUp - > setSelectedTag ( lang ) ;
2011-01-16 20:12:55 +00:00
} else {
2011-01-18 21:03:13 +00:00
_langPopUp - > setSelectedTag ( ( uint32 ) Common : : UNK_LANG ) ;
2010-06-15 10:57:28 +00:00
}
if ( _langPopUp - > numEntries ( ) < = 3 ) { // If only one language is avaliable
_langPopUpDesc - > setEnabled ( false ) ;
_langPopUp - > setEnabled ( false ) ;
2003-11-05 12:25:42 +00:00
}
2004-02-07 17:12:10 +00:00
const Common : : PlatformDescription * p = Common : : g_platforms ;
const Common : : Platform platform = Common : : parsePlatform ( ConfMan . get ( " platform " , _domain ) ) ;
sel = 0 ;
for ( i = 0 ; p - > code ; + + p , + + i ) {
if ( platform = = p - > id )
sel = i + 2 ;
2003-11-05 12:25:42 +00:00
}
_platformPopUp - > setSelected ( sel ) ;
}
2004-03-15 02:28:47 +00:00
void EditGameDialog : : close ( ) {
if ( getResult ( ) ) {
2005-01-29 18:04:34 +00:00
ConfMan . set ( " description " , _descriptionWidget - > getEditString ( ) , _domain ) ;
2003-11-05 12:25:42 +00:00
2004-03-15 02:28:47 +00:00
Common : : Language lang = ( Common : : Language ) _langPopUp - > getSelectedTag ( ) ;
if ( lang < 0 )
ConfMan . removeKey ( " language " , _domain ) ;
else
ConfMan . set ( " language " , Common : : getLanguageCode ( lang ) , _domain ) ;
2003-11-05 12:25:42 +00:00
2006-06-03 13:33:39 +00:00
String gamePath ( _gamePathWidget - > getLabel ( ) ) ;
2006-03-28 09:42:54 +00:00
if ( ! gamePath . empty ( ) )
2004-06-29 14:23:39 +00:00
ConfMan . set ( " path " , gamePath , _domain ) ;
2006-06-03 13:33:39 +00:00
String extraPath ( _extraPathWidget - > getLabel ( ) ) ;
2010-08-23 19:45:14 +00:00
if ( ! extraPath . empty ( ) & & ( extraPath ! = _c ( " None " , " path " ) ) )
2004-06-29 14:23:39 +00:00
ConfMan . set ( " extrapath " , extraPath , _domain ) ;
2006-06-03 13:33:39 +00:00
String savePath ( _savePathWidget - > getLabel ( ) ) ;
2010-06-15 10:44:51 +00:00
if ( ! savePath . empty ( ) & & ( savePath ! = _ ( " Default " ) ) )
2004-07-01 10:24:42 +00:00
ConfMan . set ( " savepath " , savePath , _domain ) ;
2004-06-29 14:23:39 +00:00
2004-03-15 02:28:47 +00:00
Common : : Platform platform = ( Common : : Platform ) _platformPopUp - > getSelectedTag ( ) ;
if ( platform < 0 )
ConfMan . removeKey ( " platform " , _domain ) ;
else
ConfMan . set ( " platform " , Common : : getPlatformCode ( platform ) , _domain ) ;
}
OptionsDialog : : close ( ) ;
2003-11-05 12:25:42 +00:00
}
2003-03-06 19:52:54 +00:00
void EditGameDialog : : handleCommand ( CommandSender * sender , uint32 cmd , uint32 data ) {
2003-11-07 16:01:51 +00:00
switch ( cmd ) {
case kCmdGlobalGraphicsOverride :
setGraphicSettingsState ( data ! = 0 ) ;
draw ( ) ;
break ;
case kCmdGlobalAudioOverride :
setAudioSettingsState ( data ! = 0 ) ;
2006-05-13 17:30:04 +00:00
setSubtitleSettingsState ( data ! = 0 ) ;
2006-07-14 13:33:58 +00:00
if ( _globalVolumeOverride = = NULL )
2006-06-15 13:18:28 +00:00
setVolumeSettingsState ( data ! = 0 ) ;
2003-11-07 16:01:51 +00:00
draw ( ) ;
break ;
2005-04-13 00:11:49 +00:00
case kCmdGlobalMIDIOverride :
setMIDISettingsState ( data ! = 0 ) ;
draw ( ) ;
break ;
2010-07-24 22:29:17 +00:00
case kCmdGlobalMT32Override :
setMT32SettingsState ( data ! = 0 ) ;
draw ( ) ;
break ;
2003-11-07 16:01:51 +00:00
case kCmdGlobalVolumeOverride :
setVolumeSettingsState ( data ! = 0 ) ;
draw ( ) ;
break ;
2005-05-16 06:33:33 +00:00
case kCmdChooseSoundFontCmd : {
2010-06-15 10:44:51 +00:00
BrowserDialog browser ( _ ( " Select SoundFont " ) , false ) ;
2005-05-16 06:33:33 +00:00
if ( browser . runModal ( ) > 0 ) {
// User made this choice...
2008-10-02 16:58:59 +00:00
Common : : FSNode file ( browser . getResult ( ) ) ;
2007-06-05 21:02:35 +00:00
_soundFont - > setLabel ( file . getPath ( ) ) ;
2007-02-13 21:41:49 +00:00
2010-08-23 19:45:14 +00:00
if ( ! file . getPath ( ) . empty ( ) & & ( file . getPath ( ) ! = _c ( " None " , " path " ) ) )
2007-02-13 21:41:49 +00:00
_soundFontClearButton - > setEnabled ( true ) ;
else
_soundFontClearButton - > setEnabled ( false ) ;
2005-05-16 06:33:33 +00:00
draw ( ) ;
}
break ;
}
2004-06-29 14:23:39 +00:00
// Change path for the game
case kCmdGameBrowser : {
2010-06-15 10:44:51 +00:00
BrowserDialog browser ( _ ( " Select directory with game data " ) , true ) ;
2005-04-16 17:55:09 +00:00
if ( browser . runModal ( ) > 0 ) {
2004-11-20 21:35:49 +00:00
// User made his choice...
2008-10-02 16:58:59 +00:00
Common : : FSNode dir ( browser . getResult ( ) ) ;
2004-06-29 14:23:39 +00:00
// TODO: Verify the game can be found in the new directory... Best
// done with optional specific gameid to pluginmgr detectgames?
2008-10-02 16:58:59 +00:00
// FSList files = dir.listDir(FSNode::kListFilesOnly);
2004-06-29 14:23:39 +00:00
2007-06-05 21:02:35 +00:00
_gamePathWidget - > setLabel ( dir . getPath ( ) ) ;
2005-04-16 17:55:09 +00:00
draw ( ) ;
2004-06-29 14:23:39 +00:00
}
draw ( ) ;
break ;
}
// Change path for extra game data (eg, using sword cutscenes when playing via CD)
2005-07-30 21:11:48 +00:00
case kCmdExtraBrowser : {
2010-06-15 10:44:51 +00:00
BrowserDialog browser ( _ ( " Select additional game directory " ) , true ) ;
2005-04-16 17:55:09 +00:00
if ( browser . runModal ( ) > 0 ) {
2004-11-20 21:35:49 +00:00
// User made his choice...
2008-10-02 16:58:59 +00:00
Common : : FSNode dir ( browser . getResult ( ) ) ;
2007-06-05 21:02:35 +00:00
_extraPathWidget - > setLabel ( dir . getPath ( ) ) ;
2005-04-16 17:55:09 +00:00
draw ( ) ;
2004-06-29 14:23:39 +00:00
}
draw ( ) ;
break ;
}
// Change path for stored save game (perm and temp) data
case kCmdSaveBrowser : {
2010-06-15 10:44:51 +00:00
BrowserDialog browser ( _ ( " Select directory for saved games " ) , true ) ;
2005-04-16 17:55:09 +00:00
if ( browser . runModal ( ) > 0 ) {
2004-11-20 21:35:49 +00:00
// User made his choice...
2008-10-02 16:58:59 +00:00
Common : : FSNode dir ( browser . getResult ( ) ) ;
2007-06-05 21:02:35 +00:00
_savePathWidget - > setLabel ( dir . getPath ( ) ) ;
2005-04-16 17:55:09 +00:00
draw ( ) ;
2004-06-29 14:23:39 +00:00
}
draw ( ) ;
break ;
}
2004-03-15 02:28:47 +00:00
case kOKCmd : {
2002-11-21 16:56:29 +00:00
// Write back changes made to config object
2005-01-29 18:04:34 +00:00
String newDomain ( _domainWidget - > getEditString ( ) ) ;
2002-11-21 17:25:31 +00:00
if ( newDomain ! = _domain ) {
2008-08-03 08:05:19 +00:00
if ( newDomain . empty ( )
| | newDomain . hasPrefix ( " _ " )
| | newDomain = = ConfigManager : : kApplicationDomain
| | ConfMan . hasGameDomain ( newDomain ) ) {
2010-06-15 10:44:51 +00:00
MessageDialog alert ( _ ( " This game ID is already taken. Please choose another one. " ) ) ;
2002-11-21 17:25:31 +00:00
alert . runModal ( ) ;
return ;
}
2003-10-08 21:59:23 +00:00
ConfMan . renameGameDomain ( _domain , newDomain ) ;
2003-11-05 12:25:42 +00:00
_domain = newDomain ;
2002-11-21 17:25:31 +00:00
}
2003-11-07 16:01:51 +00:00
}
// FALL THROUGH to default case
default :
OptionsDialog : : handleCommand ( sender , cmd , data ) ;
2003-11-05 12:25:42 +00:00
}
}
2003-11-05 00:59:03 +00:00
2003-11-05 12:25:42 +00:00
# pragma mark -
2003-11-05 00:59:03 +00:00
2006-05-04 22:52:18 +00:00
LauncherDialog : : LauncherDialog ( )
2007-03-17 16:05:16 +00:00
: Dialog ( 0 , 0 , 320 , 200 ) {
2008-11-10 11:24:55 +00:00
_backgroundType = GUI : : ThemeEngine : : kDialogBackgroundMain ;
2005-05-16 00:26:23 +00:00
const int screenW = g_system - > getOverlayWidth ( ) ;
const int screenH = g_system - > getOverlayHeight ( ) ;
2005-07-30 21:11:48 +00:00
2005-05-16 00:26:23 +00:00
_w = screenW ;
_h = screenH ;
2006-03-14 02:19:38 +00:00
# ifndef DISABLE_FANCY_THEMES
2006-04-20 12:25:25 +00:00
_logo = 0 ;
2008-08-08 18:30:16 +00:00
if ( g_gui . xmlEval ( ) - > getVar ( " Globals.ShowLauncherLogo " ) = = 1 & & g_gui . theme ( ) - > supportsImages ( ) ) {
2008-08-05 16:23:17 +00:00
_logo = new GraphicsWidget ( this , " Launcher.Logo " ) ;
2006-05-29 14:55:43 +00:00
_logo - > useThemeTransparency ( true ) ;
2008-11-10 11:24:55 +00:00
_logo - > setGfx ( g_gui . theme ( ) - > getImageSurface ( ThemeEngine : : kImageLogo ) ) ;
2006-03-14 03:08:14 +00:00
2008-08-05 16:23:17 +00:00
new StaticTextWidget ( this , " Launcher.Version " , gScummVMVersionDate ) ;
2006-03-14 03:08:14 +00:00
} else
2008-08-05 16:23:17 +00:00
new StaticTextWidget ( this , " Launcher.Version " , gScummVMFullVersion ) ;
2006-03-14 03:08:14 +00:00
# else
// Show ScummVM version
2008-08-05 16:23:17 +00:00
new StaticTextWidget ( this , " Launcher.Version " , gScummVMFullVersion ) ;
2006-03-14 02:19:38 +00:00
# endif
2010-06-15 10:53:30 +00:00
new ButtonWidget ( this , " Launcher.QuitButton " , _ ( " ~Q~uit " ) , _ ( " Quit ScummVM " ) , kQuitCmd ) ;
new ButtonWidget ( this , " Launcher.AboutButton " , _ ( " A~b~out... " ) , _ ( " About ScummVM " ) , kAboutCmd ) ;
new ButtonWidget ( this , " Launcher.OptionsButton " , _ ( " ~O~ptions... " ) , _ ( " Change global ScummVM options " ) , kOptionsCmd ) ;
2006-03-07 05:39:52 +00:00
_startButton =
2010-06-15 10:53:30 +00:00
new ButtonWidget ( this , " Launcher.StartButton " , _ ( " ~S~tart " ) , _ ( " Start selected game " ) , kStartCmd ) ;
2005-05-16 00:26:23 +00:00
2008-09-14 18:19:22 +00:00
_loadButton =
2010-06-15 10:53:30 +00:00
new ButtonWidget ( this , " Launcher.LoadGameButton " , _ ( " ~L~oad... " ) , _ ( " Load savegame for selected game " ) , kLoadGameCmd ) ;
2005-05-16 00:26:23 +00:00
// Above the lowest button rows: two more buttons (directly below the list box)
2010-08-30 22:24:40 +00:00
if ( g_system - > getOverlayWidth ( ) > 320 ) {
_addButton =
new ButtonWidget ( this , " Launcher.AddGameButton " , _ ( " ~A~dd Game... " ) , _ ( " Hold Shift for Mass Add " ) , kAddGameCmd ) ;
_editButton =
new ButtonWidget ( this , " Launcher.EditGameButton " , _ ( " ~E~dit Game... " ) , _ ( " Change game options " ) , kEditGameCmd ) ;
_removeButton =
new ButtonWidget ( this , " Launcher.RemoveGameButton " , _ ( " ~R~emove Game " ) , _ ( " Remove game from the list. The game data files stay intact " ) , kRemoveGameCmd ) ;
} else {
_addButton =
new ButtonWidget ( this , " Launcher.AddGameButton " , _c ( " ~A~dd Game... " , " lowres " ) , _ ( " Hold Shift for Mass Add " ) , kAddGameCmd ) ;
_editButton =
new ButtonWidget ( this , " Launcher.EditGameButton " , _c ( " ~E~dit Game... " , " lowres " ) , _ ( " Change game options " ) , kEditGameCmd ) ;
_removeButton =
new ButtonWidget ( this , " Launcher.RemoveGameButton " , _c ( " ~R~emove Game " , " lowres " ) , _ ( " Remove game from the list. The game data files stay intact " ) , kRemoveGameCmd ) ;
}
2005-05-16 00:26:23 +00:00
2009-06-06 17:53:25 +00:00
// Search box
2009-06-06 17:54:08 +00:00
_searchDesc = 0 ;
# ifndef DISABLE_FANCY_THEMES
_searchPic = 0 ;
if ( g_gui . xmlEval ( ) - > getVar ( " Globals.ShowSearchPic " ) = = 1 & & g_gui . theme ( ) - > supportsImages ( ) ) {
2010-06-15 10:52:35 +00:00
_searchPic = new GraphicsWidget ( this , " Launcher.SearchPic " , _ ( " Search in game list " ) ) ;
2009-06-06 17:54:08 +00:00
_searchPic - > setGfx ( g_gui . theme ( ) - > getImageSurface ( ThemeEngine : : kImageSearch ) ) ;
} else
# endif
2010-06-15 10:44:51 +00:00
_searchDesc = new StaticTextWidget ( this , " Launcher.SearchDesc " , _ ( " Search: " ) ) ;
2009-06-06 17:54:08 +00:00
2010-06-15 10:54:22 +00:00
_searchWidget = new EditTextWidget ( this , " Launcher.Search " , _search , 0 , kSearchCmd ) ;
2010-06-15 10:52:35 +00:00
_searchClearButton = new ButtonWidget ( this , " Launcher.SearchClearButton " , " C " , _ ( " Clear value " ) , kSearchClearCmd ) ;
2002-09-27 23:27:14 +00:00
// Add list with game titles
2010-06-15 10:54:22 +00:00
_list = new ListWidget ( this , " Launcher.GameList " , 0 , kListSearchCmd ) ;
2002-09-30 12:56:59 +00:00
_list - > setEditable ( false ) ;
2002-09-30 00:55:47 +00:00
_list - > setNumberingMode ( kListNumberingOff ) ;
2003-03-06 19:52:54 +00:00
2002-12-01 12:47:13 +00:00
// Populate the list
updateListing ( ) ;
2004-10-01 21:12:18 +00:00
// Restore last selection
2006-06-03 13:33:39 +00:00
String last ( ConfMan . get ( " lastselectedgame " , ConfigManager : : kApplicationDomain ) ) ;
2009-12-15 08:19:34 +00:00
selectTarget ( last ) ;
2005-07-30 21:11:48 +00:00
2005-05-16 00:26:23 +00:00
// En-/disable the buttons depending on the list selection
2005-01-05 01:42:52 +00:00
updateButtons ( ) ;
// Create file browser dialog
2010-06-15 10:44:51 +00:00
_browser = new BrowserDialog ( _ ( " Select directory with game data " ) , true ) ;
2008-07-30 21:48:45 +00:00
2008-08-14 03:50:48 +00:00
// Create Load dialog
2010-06-15 10:44:51 +00:00
_loadDialog = new SaveLoadChooser ( _ ( " Load game: " ) , _ ( " Load " ) ) ;
2005-01-05 01:42:52 +00:00
}
2009-12-15 08:19:34 +00:00
void LauncherDialog : : selectTarget ( const String & target ) {
if ( ! target . empty ( ) ) {
2004-10-01 21:12:18 +00:00
int itemToSelect = 0 ;
2010-03-18 15:09:24 +00:00
StringArray : : const_iterator iter ;
2004-10-01 21:12:18 +00:00
for ( iter = _domains . begin ( ) ; iter ! = _domains . end ( ) ; + + iter , + + itemToSelect ) {
2009-12-15 08:19:34 +00:00
if ( target = = * iter ) {
2004-10-01 21:12:18 +00:00
_list - > setSelected ( itemToSelect ) ;
break ;
}
}
}
2002-11-21 02:19:02 +00:00
}
2003-03-06 19:52:54 +00:00
LauncherDialog : : ~ LauncherDialog ( ) {
2002-11-21 02:19:02 +00:00
delete _browser ;
2008-08-13 20:27:39 +00:00
delete _loadDialog ;
2002-11-21 02:19:02 +00:00
}
2006-07-22 21:23:49 +00:00
void LauncherDialog : : open ( ) {
// Clear the active domain, in case we return to the dialog from a
// failure to launch a game. Otherwise, pressing ESC will attempt to
// re-launch the same game again.
ConfMan . setActiveDomain ( " " ) ;
2008-06-16 18:47:32 +00:00
CursorMan . popAllCursors ( ) ;
2006-07-22 21:23:49 +00:00
Dialog : : open ( ) ;
2007-09-19 08:40:12 +00:00
2007-03-17 16:05:16 +00:00
updateButtons ( ) ;
2006-07-22 21:23:49 +00:00
}
2004-10-01 21:12:18 +00:00
void LauncherDialog : : close ( ) {
// Save last selection
const int sel = _list - > getSelected ( ) ;
if ( sel > = 0 )
2006-06-03 13:33:39 +00:00
ConfMan . set ( " lastselectedgame " , _domains [ sel ] , ConfigManager : : kApplicationDomain ) ;
2004-10-01 21:12:18 +00:00
else
2006-06-03 13:33:39 +00:00
ConfMan . removeKey ( " lastselectedgame " , ConfigManager : : kApplicationDomain ) ;
2005-07-30 21:11:48 +00:00
ConfMan . flushToDisk ( ) ;
2004-10-01 21:12:18 +00:00
Dialog : : close ( ) ;
}
2003-03-06 19:52:54 +00:00
void LauncherDialog : : updateListing ( ) {
2010-03-18 15:09:24 +00:00
StringArray l ;
2002-10-28 09:03:02 +00:00
2002-10-28 10:40:49 +00:00
// Retrieve a list of all games defined in the config file
2002-11-21 15:20:52 +00:00
_domains . clear ( ) ;
2003-10-08 21:59:23 +00:00
const ConfigManager : : DomainMap & domains = ConfMan . getGameDomains ( ) ;
2008-06-11 06:22:02 +00:00
ConfigManager : : DomainMap : : const_iterator iter ;
2003-10-05 14:03:07 +00:00
for ( iter = domains . begin ( ) ; iter ! = domains . end ( ) ; + + iter ) {
2008-06-11 06:22:02 +00:00
# ifdef __DS__
// DS port uses an extra section called 'ds'. This prevents the section from being
// detected as a game.
if ( iter - > _key = = " ds " ) {
continue ;
}
# endif
2010-03-29 20:31:23 +00:00
String gameid ( iter - > _value . getVal ( " gameid " ) ) ;
String description ( iter - > _value . getVal ( " description " ) ) ;
2003-03-06 19:52:54 +00:00
2006-03-28 09:42:54 +00:00
if ( gameid . empty ( ) )
2006-01-21 13:01:20 +00:00
gameid = iter - > _key ;
2006-03-28 09:42:54 +00:00
if ( description . empty ( ) ) {
2008-05-12 00:26:29 +00:00
GameDescriptor g = EngineMan . findGame ( gameid ) ;
2007-01-20 21:27:57 +00:00
if ( g . contains ( " description " ) )
description = g . description ( ) ;
2003-10-17 15:54:17 +00:00
}
2007-07-02 22:48:39 +00:00
2010-06-15 10:44:51 +00:00
if ( description . empty ( ) ) {
2011-06-01 22:07:18 +00:00
description = Common : : String : : format ( " Unknown (target %s, gameid %s) " , iter - > _key . c_str ( ) , gameid . c_str ( ) ) ;
2010-06-15 10:44:51 +00:00
}
2002-10-28 10:40:49 +00:00
2006-03-28 09:42:54 +00:00
if ( ! gameid . empty ( ) & & ! description . empty ( ) ) {
2002-10-28 10:40:49 +00:00
// Insert the game into the launcher list
int pos = 0 , size = l . size ( ) ;
2002-10-28 09:03:02 +00:00
2004-08-26 00:27:51 +00:00
while ( pos < size & & ( scumm_stricmp ( description . c_str ( ) , l [ pos ] . c_str ( ) ) > 0 ) )
2002-10-15 15:32:54 +00:00
pos + + ;
2002-10-28 10:40:49 +00:00
l . insert_at ( pos , description ) ;
2003-10-08 21:59:23 +00:00
_domains . insert_at ( pos , iter - > _key ) ;
2002-09-30 00:55:47 +00:00
}
2002-09-27 23:27:14 +00:00
}
2004-12-25 22:26:28 +00:00
const int oldSel = _list - > getSelected ( ) ;
2002-11-21 15:20:52 +00:00
_list - > setList ( l ) ;
2004-12-25 23:19:42 +00:00
if ( oldSel < ( int ) l . size ( ) )
2004-12-25 22:26:28 +00:00
_list - > setSelected ( oldSel ) ; // Restore the old selection
2006-11-13 16:29:14 +00:00
else if ( oldSel ! = - 1 )
// Select the last entry if the list has been reduced
_list - > setSelected ( _list - > getList ( ) . size ( ) - 1 ) ;
2002-12-01 12:47:13 +00:00
updateButtons ( ) ;
2009-07-15 17:07:45 +00:00
// Update the filter settings, those are lost when "setList"
// is called.
_list - > setFilter ( _searchWidget - > getEditString ( ) ) ;
2002-09-27 23:27:14 +00:00
}
2003-11-05 12:25:42 +00:00
void LauncherDialog : : addGame ( ) {
2007-03-17 16:05:16 +00:00
int modifiers = g_system - > getEventManager ( ) - > getModifierState ( ) ;
2011-06-01 13:15:31 +00:00
2011-05-21 14:45:51 +00:00
# ifndef DISABLE_MASS_ADD
2009-12-15 08:20:19 +00:00
const bool massAdd = ( modifiers & Common : : KBD_SHIFT ) ! = 0 ;
2007-09-19 08:40:12 +00:00
2006-10-02 22:28:02 +00:00
if ( massAdd ) {
2010-06-15 10:44:51 +00:00
MessageDialog alert ( _ ( " Do you really want to run the mass game detector? "
" This could potentially add a huge number of games. " ) , _ ( " Yes " ) , _ ( " No " ) ) ;
2006-10-02 22:28:02 +00:00
if ( alert . runModal ( ) = = GUI : : kMessageOK & & _browser - > runModal ( ) > 0 ) {
2007-02-18 18:23:52 +00:00
MassAddDialog massAddDlg ( _browser - > getResult ( ) ) ;
2009-06-06 17:49:59 +00:00
2007-02-18 18:23:52 +00:00
massAddDlg . runModal ( ) ;
2007-02-18 18:36:21 +00:00
2009-06-06 17:50:30 +00:00
// Update the ListWidget and force a redraw
2009-12-15 08:19:34 +00:00
// If new target(s) were added, update the ListWidget and move
// the selection to to first newly detected game.
2009-12-15 12:56:10 +00:00
Common : : String newTarget = massAddDlg . getFirstAddedTarget ( ) ;
2009-12-15 08:19:34 +00:00
if ( ! newTarget . empty ( ) ) {
updateListing ( ) ;
selectTarget ( newTarget ) ;
}
2009-06-06 17:49:59 +00:00
2007-02-18 18:36:21 +00:00
draw ( ) ;
2006-10-02 22:28:02 +00:00
}
2009-01-08 17:08:24 +00:00
// We need to update the buttons here, so "Mass add" will revert to "Add game"
// without any additional event.
updateButtons ( ) ;
2006-10-02 22:28:02 +00:00
return ;
}
2011-05-21 14:45:51 +00:00
# endif
2006-10-02 22:28:02 +00:00
2003-11-05 12:25:42 +00:00
// Allow user to add a new game to the list.
// 1) show a dir selection dialog which lets the user pick the directory
// the game data resides in.
// 2) try to auto detect which game is in the directory, if we cannot
2009-04-18 21:12:32 +00:00
// determine it uniquely present a list of candidates to the user
2003-11-05 12:25:42 +00:00
// to pick from
// 3) Display the 'Edit' dialog for that item, letting the user specify
// an alternate description (to distinguish multiple versions of the
// game, e.g. 'Monkey German' and 'Monkey English') and set default
2009-06-06 17:37:15 +00:00
// options for that game
// 4) If no game is found in the specified directory, return to the
// dialog.
2007-02-18 18:23:52 +00:00
2009-06-06 17:37:15 +00:00
bool looping ;
do {
looping = false ;
2007-02-18 18:23:52 +00:00
2009-06-06 17:37:15 +00:00
if ( _browser - > runModal ( ) > 0 ) {
// User made his choice...
Common : : FSNode dir ( _browser - > getResult ( ) ) ;
Common : : FSList files ;
if ( ! dir . getChildren ( files , Common : : FSNode : : kListAll ) ) {
2010-06-15 10:44:51 +00:00
MessageDialog alert ( _ ( " ScummVM couldn't open the specified directory! " ) ) ;
2009-06-06 17:37:15 +00:00
alert . runModal ( ) ;
return ;
}
2007-02-18 18:23:52 +00:00
2009-06-06 17:37:15 +00:00
// ...so let's determine a list of candidates, games that
// could be contained in the specified directory.
GameList candidates ( EngineMan . detectGames ( files ) ) ;
2007-09-19 08:40:12 +00:00
2009-06-06 17:37:15 +00:00
int idx ;
if ( candidates . empty ( ) ) {
// No game was found in the specified directory
2010-06-15 10:44:51 +00:00
MessageDialog alert ( _ ( " ScummVM could not find any game in the specified directory! " ) ) ;
2009-06-06 17:37:15 +00:00
alert . runModal ( ) ;
idx = - 1 ;
2007-09-19 08:40:12 +00:00
2009-06-06 17:37:15 +00:00
looping = true ;
} else if ( candidates . size ( ) = = 1 ) {
// Exact match
idx = 0 ;
2007-02-18 18:23:52 +00:00
} else {
2009-06-06 17:37:15 +00:00
// Display the candidates to the user and let her/him pick one
2010-03-18 15:09:24 +00:00
StringArray list ;
2009-06-06 17:37:15 +00:00
for ( idx = 0 ; idx < ( int ) candidates . size ( ) ; idx + + )
list . push_back ( candidates [ idx ] . description ( ) ) ;
2010-06-15 10:44:51 +00:00
ChooserDialog dialog ( _ ( " Pick the game: " ) ) ;
2009-06-06 17:37:15 +00:00
dialog . setList ( list ) ;
idx = dialog . runModal ( ) ;
2007-02-18 18:23:52 +00:00
}
2009-06-06 17:37:15 +00:00
if ( 0 < = idx & & idx < ( int ) candidates . size ( ) ) {
GameDescriptor result = candidates [ idx ] ;
2007-02-18 18:23:52 +00:00
2009-06-06 17:37:15 +00:00
// TODO: Change the detectors to set "path" !
result [ " path " ] = dir . getPath ( ) ;
Common : : String domain = addGameToConf ( result ) ;
// Display edit dialog for the new entry
EditGameDialog editDialog ( domain , result . description ( ) ) ;
if ( editDialog . runModal ( ) > 0 ) {
// User pressed OK, so make changes permanent
// Write config to disk
ConfMan . flushToDisk ( ) ;
// Update the ListWidget, select the new item, and force a redraw
updateListing ( ) ;
2009-12-15 08:19:34 +00:00
selectTarget ( editDialog . getDomain ( ) ) ;
2009-06-06 17:37:15 +00:00
draw ( ) ;
} else {
// User aborted, remove the the new domain again
ConfMan . removeGameDomain ( domain ) ;
}
}
2006-10-02 22:28:02 +00:00
}
2009-06-06 17:37:15 +00:00
} while ( looping ) ;
2006-10-02 22:28:02 +00:00
}
2007-02-18 18:23:52 +00:00
Common : : String addGameToConf ( const GameDescriptor & result ) {
2006-11-19 22:32:35 +00:00
// The auto detector or the user made a choice.
// Pick a domain name which does not yet exist (after all, we
// are *adding* a game to the config, not replacing).
2008-11-08 01:34:02 +00:00
Common : : String domain = result . preferredtarget ( ) ;
2007-01-29 23:25:51 +00:00
2007-01-28 10:38:23 +00:00
assert ( ! domain . empty ( ) ) ;
2006-11-19 22:32:35 +00:00
if ( ConfMan . hasGameDomain ( domain ) ) {
int suffixN = 1 ;
2008-11-08 01:34:02 +00:00
Common : : String gameid ( domain ) ;
2006-11-19 22:32:35 +00:00
while ( ConfMan . hasGameDomain ( domain ) ) {
2011-06-01 22:07:18 +00:00
domain = gameid + Common : : String : : format ( " -%d " , suffixN ) ;
2006-11-19 22:32:35 +00:00
suffixN + + ;
}
}
2006-04-16 13:58:11 +00:00
2006-11-19 22:32:35 +00:00
// Add the name domain
ConfMan . addGameDomain ( domain ) ;
2007-02-18 18:39:46 +00:00
// Copy all non-empty key/value pairs into the new domain
for ( GameDescriptor : : const_iterator iter = result . begin ( ) ; iter ! = result . end ( ) ; + + iter ) {
if ( ! iter - > _value . empty ( ) & & iter - > _key ! = " preferredtarget " )
ConfMan . set ( iter - > _key , iter - > _value , domain ) ;
}
2006-11-19 22:32:35 +00:00
// TODO: Setting the description field here has the drawback
// that the user does never notice when we upgrade our descriptions.
// It might be nice ot leave this field empty, and only set it to
2007-09-19 08:40:12 +00:00
// a value when the user edits the description string.
2006-11-19 22:32:35 +00:00
// However, at this point, that's impractical. Once we have a method
// to query all backends for the proper & full description of a given
// game target, we can change this (currently, you can only query
// for the generic gameid description; it's not possible to obtain
// a description which contains extended information like language, etc.).
2007-09-19 08:40:12 +00:00
2007-02-18 18:23:52 +00:00
return domain ;
2006-11-19 22:32:35 +00:00
}
2003-11-05 12:25:42 +00:00
void LauncherDialog : : removeGame ( int item ) {
2010-06-15 10:44:51 +00:00
MessageDialog alert ( _ ( " Do you really want to remove this game configuration? " ) , _ ( " Yes " ) , _ ( " No " ) ) ;
2005-07-30 21:11:48 +00:00
2004-08-11 21:49:58 +00:00
if ( alert . runModal ( ) = = GUI : : kMessageOK ) {
2003-11-05 12:25:42 +00:00
// Remove the currently selected game from the list
assert ( item > = 0 ) ;
ConfMan . removeGameDomain ( _domains [ item ] ) ;
// Write config to disk
ConfMan . flushToDisk ( ) ;
2005-07-30 21:11:48 +00:00
2003-11-05 12:25:42 +00:00
// Update the ListWidget and force a redraw
updateListing ( ) ;
draw ( ) ;
}
}
void LauncherDialog : : editGame ( int item ) {
2009-02-15 22:07:19 +00:00
// Set game specific options. Most of these should be "optional", i.e. by
2003-11-05 12:25:42 +00:00
// default set nothing and use the global ScummVM settings. E.g. the user
// can set here an optional alternate music volume, or for specific games
// a different music driver etc.
2010-01-25 00:13:32 +00:00
// This is useful because e.g. MonkeyVGA needs AdLib music to have decent
2003-11-05 12:25:42 +00:00
// music support etc.
assert ( item > = 0 ) ;
String gameId ( ConfMan . get ( " gameid " , _domains [ item ] ) ) ;
2006-03-28 09:42:54 +00:00
if ( gameId . empty ( ) )
2003-11-05 12:25:42 +00:00
gameId = _domains [ item ] ;
2008-05-12 00:26:29 +00:00
EditGameDialog editDialog ( _domains [ item ] , EngineMan . findGame ( gameId ) . description ( ) ) ;
2004-03-17 00:07:43 +00:00
if ( editDialog . runModal ( ) > 0 ) {
2003-11-05 12:25:42 +00:00
// User pressed OK, so make changes permanent
// Write config to disk
ConfMan . flushToDisk ( ) ;
2003-11-08 23:22:16 +00:00
2009-02-15 22:07:19 +00:00
// Update the ListWidget, reselect the edited game and force a redraw
2003-11-05 12:25:42 +00:00
updateListing ( ) ;
2009-12-15 08:19:34 +00:00
selectTarget ( editDialog . getDomain ( ) ) ;
2003-11-05 12:25:42 +00:00
draw ( ) ;
}
}
2008-07-30 21:48:45 +00:00
void LauncherDialog : : loadGame ( int item ) {
2008-08-06 01:48:46 +00:00
String gameId = ConfMan . get ( " gameid " , _domains [ item ] ) ;
if ( gameId . empty ( ) )
gameId = _domains [ item ] ;
const EnginePlugin * plugin = 0 ;
2011-06-01 13:15:31 +00:00
2008-09-11 20:20:02 +00:00
EngineMan . findGame ( gameId , & plugin ) ;
2008-08-14 03:50:48 +00:00
2008-09-11 20:20:02 +00:00
String target = _domains [ item ] ;
target . toLowercase ( ) ;
2008-08-14 06:51:04 +00:00
2008-08-06 01:48:46 +00:00
if ( plugin ) {
2008-12-22 11:22:15 +00:00
if ( ( * plugin ) - > hasFeature ( MetaEngine : : kSupportsListSaves ) & &
2008-10-26 16:42:08 +00:00
( * plugin ) - > hasFeature ( MetaEngine : : kSupportsLoadingDuringStartup ) ) {
2011-02-07 22:58:22 +00:00
int slot = _loadDialog - > runModalWithPluginAndTarget ( plugin , target ) ;
2008-09-11 20:20:02 +00:00
if ( slot > = 0 ) {
ConfMan . setActiveDomain ( _domains [ item ] ) ;
ConfMan . setInt ( " save_slot " , slot , Common : : ConfigManager : : kTransientDomain ) ;
close ( ) ;
}
2008-08-15 18:15:14 +00:00
} else {
MessageDialog dialog
2010-06-15 10:44:51 +00:00
( _ ( " This game does not support loading games from the launcher. " ) , _ ( " OK " ) ) ;
2008-08-15 18:15:14 +00:00
dialog . runModal ( ) ;
2008-08-06 01:48:46 +00:00
}
} else {
2010-06-15 10:44:51 +00:00
MessageDialog dialog ( _ ( " ScummVM could not find any engine capable of running the selected game! " ) , _ ( " OK " ) ) ;
2008-08-06 01:48:46 +00:00
dialog . runModal ( ) ;
}
2008-07-30 21:48:45 +00:00
}
2007-06-30 12:26:59 +00:00
void LauncherDialog : : handleKeyDown ( Common : : KeyState state ) {
2009-06-06 23:22:48 +00:00
if ( state . keycode = = Common : : KEYCODE_TAB ) {
// Toggle between the game list and the quick search field.
if ( getFocusWidget ( ) = = _searchWidget ) {
setFocusWidget ( _list ) ;
} else if ( getFocusWidget ( ) = = _list ) {
setFocusWidget ( _searchWidget ) ;
}
}
2007-06-30 12:26:59 +00:00
Dialog : : handleKeyDown ( state ) ;
2007-03-17 16:05:16 +00:00
updateButtons ( ) ;
2006-10-02 22:28:02 +00:00
}
2007-06-30 12:26:59 +00:00
void LauncherDialog : : handleKeyUp ( Common : : KeyState state ) {
Dialog : : handleKeyUp ( state ) ;
2007-03-17 16:05:16 +00:00
updateButtons ( ) ;
2006-10-02 22:28:02 +00:00
}
2003-11-05 12:25:42 +00:00
void LauncherDialog : : handleCommand ( CommandSender * sender , uint32 cmd , uint32 data ) {
2003-11-10 23:40:48 +00:00
int item = _list - > getSelected ( ) ;
2003-11-05 12:25:42 +00:00
switch ( cmd ) {
case kAddGameCmd :
addGame ( ) ;
2002-11-21 13:11:29 +00:00
break ;
2003-11-05 12:25:42 +00:00
case kRemoveGameCmd :
removeGame ( item ) ;
break ;
case kEditGameCmd :
editGame ( item ) ;
2002-10-17 22:43:13 +00:00
break ;
2008-07-30 21:48:45 +00:00
case kLoadGameCmd :
loadGame ( item ) ;
break ;
2002-11-21 13:11:29 +00:00
case kOptionsCmd : {
2006-03-09 05:18:00 +00:00
GlobalOptionsDialog options ;
2002-12-12 23:22:48 +00:00
options . runModal ( ) ;
2002-11-21 13:11:29 +00:00
}
2002-10-17 22:43:13 +00:00
break ;
2003-09-08 18:09:32 +00:00
case kAboutCmd : {
2003-11-02 02:18:16 +00:00
AboutDialog about ;
2003-09-08 18:09:32 +00:00
about . runModal ( ) ;
}
break ;
2002-09-30 00:55:47 +00:00
case kStartCmd :
2003-11-18 23:47:08 +00:00
case kListItemActivatedCmd :
2002-09-27 23:27:14 +00:00
case kListItemDoubleClickedCmd :
2009-12-15 08:19:34 +00:00
// Start the selected game.
2002-10-01 23:11:19 +00:00
assert ( item > = 0 ) ;
2006-05-05 00:26:03 +00:00
ConfMan . setActiveDomain ( _domains [ item ] ) ;
2002-10-01 23:11:19 +00:00
close ( ) ;
2007-07-17 21:59:44 +00:00
break ;
case kListItemRemovalRequestCmd :
removeGame ( item ) ;
2002-10-01 23:11:19 +00:00
break ;
2002-12-01 12:47:13 +00:00
case kListSelectionChangedCmd :
updateButtons ( ) ;
2002-09-27 23:27:14 +00:00
break ;
case kQuitCmd :
2006-06-11 21:41:04 +00:00
ConfMan . setActiveDomain ( " " ) ;
2004-12-25 22:13:44 +00:00
setResult ( - 1 ) ;
2003-04-30 13:57:57 +00:00
close ( ) ;
2002-09-27 23:27:14 +00:00
break ;
2009-06-06 17:53:25 +00:00
case kSearchCmd :
2009-12-15 08:19:34 +00:00
// Update the active search filter.
2009-06-06 17:54:08 +00:00
_list - > setFilter ( _searchWidget - > getEditString ( ) ) ;
2009-06-06 17:53:25 +00:00
break ;
2009-06-07 22:19:48 +00:00
case kSearchClearCmd :
2009-12-15 08:19:34 +00:00
// Reset the active search filter, thus showing all games again
2009-06-07 22:19:48 +00:00
_searchWidget - > setEditString ( " " ) ;
_list - > setFilter ( " " ) ;
break ;
2002-09-27 23:27:14 +00:00
default :
Dialog : : handleCommand ( sender , cmd , data ) ;
}
}
2002-12-01 12:47:13 +00:00
void LauncherDialog : : updateButtons ( ) {
bool enable = ( _list - > getSelected ( ) > = 0 ) ;
if ( enable ! = _startButton - > isEnabled ( ) ) {
_startButton - > setEnabled ( enable ) ;
_startButton - > draw ( ) ;
}
if ( enable ! = _editButton - > isEnabled ( ) ) {
_editButton - > setEnabled ( enable ) ;
_editButton - > draw ( ) ;
}
if ( enable ! = _removeButton - > isEnabled ( ) ) {
_removeButton - > setEnabled ( enable ) ;
_removeButton - > draw ( ) ;
}
2009-06-06 17:59:04 +00:00
int item = _list - > getSelected ( ) ;
bool en = enable ;
if ( item > = 0 )
en = ! ( Common : : checkGameGUIOption ( Common : : GUIO_NOLAUNCHLOAD , ConfMan . get ( " guioptions " , _domains [ item ] ) ) ) ;
if ( en ! = _loadButton - > isEnabled ( ) ) {
_loadButton - > setEnabled ( en ) ;
2008-09-14 18:19:22 +00:00
_loadButton - > draw ( ) ;
}
2007-03-17 16:05:16 +00:00
// Update the label of the "Add" button depending on whether shift is pressed or not
int modifiers = g_system - > getEventManager ( ) - > getModifierState ( ) ;
2009-12-15 08:20:19 +00:00
const bool massAdd = ( modifiers & Common : : KBD_SHIFT ) ! = 0 ;
2010-08-31 20:03:47 +00:00
const bool lowRes = g_system - > getOverlayWidth ( ) < = 320 ;
2010-10-12 02:18:11 +00:00
2009-12-15 08:20:19 +00:00
const char * newAddButtonLabel = massAdd
2010-08-31 20:03:47 +00:00
? ( lowRes ? _c ( " Mass Add... " , " lowres " ) : _ ( " Mass Add... " ) )
2011-08-06 09:13:21 +00:00
: ( lowRes ? _c ( " ~A~dd Game... " , " lowres " ) : _ ( " ~A~dd Game... " ) ) ;
2007-03-17 16:05:16 +00:00
2009-05-24 15:17:42 +00:00
if ( _addButton - > getLabel ( ) ! = newAddButtonLabel )
2007-03-17 16:05:16 +00:00
_addButton - > setLabel ( newAddButtonLabel ) ;
2002-12-01 12:47:13 +00:00
}
2003-11-10 23:40:48 +00:00
2006-08-04 13:55:53 +00:00
void LauncherDialog : : reflowLayout ( ) {
2006-04-16 20:33:52 +00:00
# ifndef DISABLE_FANCY_THEMES
2008-08-08 18:30:16 +00:00
if ( g_gui . xmlEval ( ) - > getVar ( " Globals.ShowLauncherLogo " ) = = 1 & & g_gui . theme ( ) - > supportsImages ( ) ) {
2008-08-09 18:34:16 +00:00
StaticTextWidget * ver = ( StaticTextWidget * ) findWidget ( " Launcher.Version " ) ;
2006-04-19 01:05:28 +00:00
if ( ver ) {
2008-11-12 14:30:16 +00:00
ver - > setAlign ( ( Graphics : : TextAlign ) g_gui . xmlEval ( ) - > getVar ( " Launcher.Version.Align " , Graphics : : kTextAlignCenter ) ) ;
2006-04-19 01:05:28 +00:00
ver - > setLabel ( gScummVMVersionDate ) ;
}
2006-04-17 18:50:33 +00:00
if ( ! _logo )
2008-08-08 18:30:16 +00:00
_logo = new GraphicsWidget ( this , " Launcher.Logo " ) ;
2006-05-29 14:55:43 +00:00
_logo - > useThemeTransparency ( true ) ;
2008-11-10 11:24:55 +00:00
_logo - > setGfx ( g_gui . theme ( ) - > getImageSurface ( ThemeEngine : : kImageLogo ) ) ;
2006-04-17 18:50:33 +00:00
} else {
2008-08-08 18:30:16 +00:00
StaticTextWidget * ver = ( StaticTextWidget * ) findWidget ( " Launcher.Version " ) ;
2006-04-19 01:05:28 +00:00
if ( ver ) {
2008-11-12 14:30:16 +00:00
ver - > setAlign ( ( Graphics : : TextAlign ) g_gui . xmlEval ( ) - > getVar ( " Launcher.Version.Align " , Graphics : : kTextAlignCenter ) ) ;
2006-04-19 01:05:28 +00:00
ver - > setLabel ( gScummVMFullVersion ) ;
}
if ( _logo ) {
2007-03-16 20:47:41 +00:00
removeWidget ( _logo ) ;
2006-04-19 01:05:28 +00:00
_logo - > setNext ( 0 ) ;
delete _logo ;
_logo = 0 ;
}
2006-04-16 20:33:52 +00:00
}
2009-06-06 17:54:08 +00:00
if ( g_gui . xmlEval ( ) - > getVar ( " Globals.ShowSearchPic " ) = = 1 & & g_gui . theme ( ) - > supportsImages ( ) ) {
if ( ! _searchPic )
_searchPic = new GraphicsWidget ( this , " Launcher.SearchPic " ) ;
_searchPic - > setGfx ( g_gui . theme ( ) - > getImageSurface ( ThemeEngine : : kImageSearch ) ) ;
if ( _searchDesc ) {
removeWidget ( _searchDesc ) ;
_searchDesc - > setNext ( 0 ) ;
delete _searchDesc ;
_searchDesc = 0 ;
}
} else {
if ( ! _searchDesc )
2010-06-15 10:44:51 +00:00
_searchDesc = new StaticTextWidget ( this , " Launcher.SearchDesc " , _ ( " Search: " ) ) ;
2009-06-06 17:54:08 +00:00
if ( _searchPic ) {
removeWidget ( _searchPic ) ;
_searchPic - > setNext ( 0 ) ;
delete _searchPic ;
_searchPic = 0 ;
}
}
2006-04-16 20:33:52 +00:00
# endif
2006-04-19 01:05:28 +00:00
_w = g_system - > getOverlayWidth ( ) ;
_h = g_system - > getOverlayHeight ( ) ;
2006-08-04 13:55:53 +00:00
Dialog : : reflowLayout ( ) ;
2006-04-16 20:33:52 +00:00
}
2003-11-10 23:40:48 +00:00
} // End of namespace GUI