2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2005 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2011 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
// Startup screen for non-parameterized engine start: Options dialog
# ifndef INC_C4StartupOptionsDlg
# define INC_C4StartupOptionsDlg
2016-04-03 18:07:56 +00:00
# include "gui/C4Startup.h"
2009-05-08 13:28:41 +00:00
// startup dialog: Options
class C4StartupOptionsDlg : public C4StartupDlg
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// main dlg stuff -----------------------------------------------------
2010-03-28 17:58:21 +00:00
public :
C4StartupOptionsDlg ( ) ; // ctor
2017-05-07 11:50:00 +00:00
~ C4StartupOptionsDlg ( ) override ; // dtor
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
private :
class C4KeyBinding * pKeyBack ;
2017-05-07 11:50:00 +00:00
bool fConfigSaved { false } ; // set when config has been saved because dlg is closed; prevents double save
bool fCanGoBack { true } ; // set if dlg has not been recreated yet, in which case going back to a previous dialog is not possible
2010-03-28 17:58:21 +00:00
C4GUI : : Tabular * pOptionsTabular ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
protected :
2017-05-07 11:50:00 +00:00
bool OnEnter ( ) override { return false ; } // Enter ignored
bool OnEscape ( ) override { DoBack ( ) ; return true ; }
2010-03-28 17:58:21 +00:00
bool KeyBack ( ) { DoBack ( ) ; return true ; }
2017-05-07 11:50:00 +00:00
void OnClosed ( bool fOK ) override ; // callback when dlg got closed - save config
void UserClose ( bool fOK ) override // callback when the user tried to close the dialog (e.g., by pressing Enter in an edit) - just ignore this and save config instead
2010-03-28 17:58:21 +00:00
{ if ( fOK ) SaveConfig ( false , true ) ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void OnBackBtn ( C4GUI : : Control * btn ) { DoBack ( ) ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
bool SaveConfig ( bool fForce , bool fKeepOpen ) ; // save any config fields that are not stored directly; return whether all values are OK
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
void DoBack ( ) ; // back to main menu
2011-03-30 20:11:47 +00:00
2017-05-07 11:50:00 +00:00
bool SetSubscreen ( const char * szToScreen ) override ; // go to specified property sheet
void OnKeyboardLayoutChanged ( ) override ; // keyboard layout changed: update keys from scan codes
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
void RecreateDialog ( bool fFade ) ;
2009-05-08 13:28:41 +00:00
// program tab --------------------------------------------------------
2010-03-28 17:58:21 +00:00
private :
// button without fancy background
class SmallButton : public C4GUI : : Button
{
protected :
2017-05-07 11:50:00 +00:00
void DrawElement ( C4TargetFacet & cgo ) override ; // draw the button
2010-03-28 17:58:21 +00:00
public :
SmallButton ( const char * szText , const C4Rect & rtBounds ) // ctor
: C4GUI : : Button ( szText , rtBounds ) { }
static int32_t GetDefaultButtonHeight ( ) ;
} ;
class C4GUI : : ComboBox * pLangCombo ;
class C4GUI : : Label * pLangInfoLabel ;
class C4GUI : : ComboBox * pFontFaceCombo , * pFontSizeCombo ;
void OnLangComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
bool OnLangComboSelChange ( C4GUI : : ComboBox * pForCombo , int32_t idNewSelection ) ;
void UpdateLanguage ( ) ;
void OnFontFaceComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
void OnFontSizeComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
bool OnFontComboSelChange ( C4GUI : : ComboBox * pForCombo , int32_t idNewSelection ) ;
void UpdateFontControls ( ) ;
bool SetGameFont ( const char * szFontFace , int32_t iFontSize ) ;
void OnResetConfigBtn ( C4GUI : : Control * btn ) ;
2009-05-08 13:28:41 +00:00
// graphics tab -------------------------------------------------------
2010-03-28 17:58:21 +00:00
private :
// checkbox that changes a config boolean directly
class BoolConfig : public C4GUI : : CheckBox
{
2009-05-08 13:28:41 +00:00
private :
2010-03-28 17:58:21 +00:00
bool * pbVal , fInvert ; int32_t * piVal , * piRestartChangeCfgVal ;
protected :
void OnCheckChange ( C4GUI : : Element * pCheckBox ) ;
public :
2016-11-02 23:58:02 +00:00
BoolConfig ( const C4Rect & rcBounds , const char * szName , bool * pbVal , int32_t * piVal , bool fInvert = false , int32_t * piRestartChangeCfgVal = nullptr ) ;
2010-03-28 17:58:21 +00:00
} ;
// editbox below descriptive label sharing one window for common tooltip
class EditConfig : public C4GUI : : LabeledEdit
{
public :
EditConfig ( const C4Rect & rcBounds , const char * szName , ValidatedStdCopyStrBufBase * psConfigVal , int32_t * piConfigVal , bool fMultiline ) ;
private :
ValidatedStdCopyStrBufBase * psConfigVal ;
int32_t * piConfigVal ;
public :
void Save2Config ( ) ; // control to config
static bool GetControlSize ( int * piWdt , int * piHgt , const char * szForText , bool fMultiline ) ;
int32_t GetIntVal ( ) { return atoi ( GetEdit ( ) - > GetText ( ) ) ; }
void SetIntVal ( int32_t iToVal ) { GetEdit ( ) - > SetText ( FormatString ( " %d " , ( int ) iToVal ) . getData ( ) , false ) ; }
} * pNetworkNickEdit ;
// message dialog with a timer; used to restore the resolution if the user didn't press anything for a while
class ResChangeConfirmDlg : public C4GUI : : Dialog , private C4ApplicationSec1Timer
{
private :
C4GUI : : Label * pOperationCancelLabel ; int32_t iResChangeSwitchTime ;
public :
ResChangeConfirmDlg ( ) ;
2017-05-07 11:50:00 +00:00
~ ResChangeConfirmDlg ( ) override ;
void OnSec1Timer ( ) override ; // update timer label
2010-03-28 17:58:21 +00:00
protected :
2017-05-07 11:50:00 +00:00
bool OnEnter ( ) override { return true ; } // Pressing Enter does not confirm this dialog, so "blind" users are less likely to accept their change
const char * GetID ( ) override { return " ResChangeConfirmDialog " ; }
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
2012-09-29 21:49:30 +00:00
void OnWindowedModeComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
bool OnWindowedModeComboSelChange ( C4GUI : : ComboBox * pForCombo , int32_t idNewSelection ) ;
2010-03-28 17:58:21 +00:00
void OnGfxResComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
bool OnGfxResComboSelChange ( C4GUI : : ComboBox * pForCombo , int32_t idNewSelection ) ;
2010-12-29 14:19:46 +00:00
void OnGfxMSComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
bool OnGfxMSComboSelChange ( C4GUI : : ComboBox * pForCombo , int32_t idNewSelection ) ;
2016-10-06 04:34:44 +00:00
bool TryNewResolution ( int32_t iResX , int32_t iResY , int32_t iRefreshRate ) ;
2010-03-28 17:58:21 +00:00
StdStrBuf GetGfxResString ( int32_t iResX , int32_t iResY ) ; // convert resolution to string to be displayed in resolution choice combobox
2012-09-29 21:49:30 +00:00
const char * GetWindowedName ( int32_t mode = - 1 ) ;
2010-03-28 17:58:21 +00:00
int32_t iGfxTexIndent ;
2009-05-08 13:28:41 +00:00
// sound tab ----------------------------------------------------------
2010-03-28 17:58:21 +00:00
private :
C4KeyBinding * pKeyToggleMusic ; // extra key binding for music: Must also update checkbox in real-time
BoolConfig * pFESoundCheck ;
C4GUI : : CheckBox * pFEMusicCheck ;
void OnFEMusicCheck ( C4GUI : : Element * pCheckBox ) ; // toggling frontend music is reflected immediately
void OnRXSoundCheck ( C4GUI : : Element * pCheckBox ) ; // toggling sounds on off must init/deinit sound system
void OnMusicVolumeSliderChange ( int32_t iNewVal ) ;
void OnSoundVolumeSliderChange ( int32_t iNewVal ) ;
protected :
bool KeyMusicToggle ( ) ;
// keyboard and gamepad control tabs ----------------------------------
private :
// dialog shown to user so he can select a key
class KeySelDialog : public C4GUI : : MessageDialog
{
2009-05-08 13:28:41 +00:00
private :
2018-01-17 23:40:39 +00:00
std : : unique_ptr < C4KeyBinding > KeyListeners ;
2011-03-30 20:11:47 +00:00
C4KeyCodeEx key ;
const class C4PlayerControlAssignment * assignment ;
const class C4PlayerControlAssignmentSet * assignment_set ;
static StdStrBuf GetDlgMessage ( const class C4PlayerControlAssignment * assignment , const class C4PlayerControlAssignmentSet * assignment_set ) ;
static C4GUI : : Icons GetDlgIcon ( const class C4PlayerControlAssignmentSet * assignment_set ) ;
2010-03-28 17:58:21 +00:00
protected :
2018-01-14 23:28:05 +00:00
bool KeyDown ( const C4KeyCodeEx & key ) { return KeyPress ( key , true ) ; } ;
bool KeyUp ( const C4KeyCodeEx & key ) { return KeyPress ( key , false ) ; } ;
bool KeyPress ( const C4KeyCodeEx & key , bool fDown ) ;
void MouseInput ( C4GUI : : CMouse & rMouse , int32_t iButton , int32_t iX , int32_t iY , DWORD dwKeyParam ) override ;
2010-03-28 17:58:21 +00:00
public :
2011-03-30 20:11:47 +00:00
KeySelDialog ( const class C4PlayerControlAssignment * assignment , const class C4PlayerControlAssignmentSet * assignment_set ) ;
2018-01-17 23:40:39 +00:00
~ KeySelDialog ( ) override = default ;
2009-05-08 13:28:41 +00:00
2011-03-30 20:11:47 +00:00
C4KeyCodeEx GetKeyCode ( ) { return key ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
} ;
2011-03-30 20:11:47 +00:00
// list box of definable keys
class ControlConfigListBox : public C4GUI : : ListBox
2010-03-28 17:58:21 +00:00
{
private :
2011-03-30 20:11:47 +00:00
// assignment key label - change key on click
class ControlAssignmentLabel : public C4GUI : : Label
{
private :
class C4PlayerControlAssignment * assignment ; // pointer into assignment set (not owned!)
class C4PlayerControlAssignmentSet * assignment_set ; // pointer to assignment set (not owned!)
void UpdateAssignmentString ( ) ;
2015-09-04 02:42:29 +00:00
public :
2017-05-07 11:50:00 +00:00
void MouseInput ( class C4GUI : : CMouse & rMouse , int32_t iButton , int32_t iX , int32_t iY , DWORD dwKeyParam ) override ;
2011-03-30 20:11:47 +00:00
ControlAssignmentLabel ( class C4PlayerControlAssignment * assignment , class C4PlayerControlAssignmentSet * assignment_set , const C4Rect & bounds ) ;
} ;
// item in list box
class ListItem : public C4GUI : : Window
{
private :
ControlConfigListBox * parent_list ;
ControlAssignmentLabel * assignment_label ;
2011-03-31 14:26:59 +00:00
bool has_extra_spacing ; // if true, add a bit of spacing on top of this item to group elements
2017-05-07 11:50:00 +00:00
int32_t GetListItemTopSpacing ( ) override { return C4GUI : : Window : : GetListItemTopSpacing ( ) + ( has_extra_spacing * GetBounds ( ) . Hgt / 2 ) ; }
2011-03-30 20:11:47 +00:00
public :
2012-10-09 21:59:32 +00:00
ListItem ( ControlConfigListBox * parent_list , class C4PlayerControlAssignment * assignment , class C4PlayerControlAssignmentSet * assignment_set , bool first_of_group ) ;
2011-03-30 20:11:47 +00:00
} ;
private :
class C4PlayerControlAssignmentSet * set ; // assignment set being configured by this box
2012-10-09 21:59:32 +00:00
static bool sort_by_group ( C4PlayerControlAssignment * i , C4PlayerControlAssignment * j ) { return i - > GetGUIGroup ( ) < j - > GetGUIGroup ( ) ; }
2011-03-30 20:11:47 +00:00
2010-03-28 17:58:21 +00:00
public :
2011-03-30 20:11:47 +00:00
ControlConfigListBox ( const C4Rect & rcBounds , class C4PlayerControlAssignmentSet * set ) ;
void SetAssignmentSet ( class C4PlayerControlAssignmentSet * new_set ) ;
static void SetUserKey ( class C4PlayerControlAssignmentSet * assignment_set , class C4PlayerControlAssignment * assignment , C4KeyCodeEx & key ) ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// config area to define a keyboard set
class ControlConfigArea : public C4GUI : : Window
{
2009-05-08 13:28:41 +00:00
private :
2010-03-28 17:58:21 +00:00
bool fGamepad ; // if set, gamepad control sets are being configured
int32_t iMaxControlSets ; // number of control sets configured in this area - must be smaller or equal to C4MaxControlSet
int32_t iSelectedCtrlSet ; // keyboard or gamepad set that is currently being configured
class C4GUI : : IconButton * * ppKeyControlSetBtns ; // buttons to select configured control set - array in length of iMaxControlSets
class KeySelButton * KeyControlBtns [ C4MaxKey ] ; // buttons to configure individual kbd set buttons
C4StartupOptionsDlg * pOptionsDlg ;
2011-03-30 20:11:47 +00:00
ControlConfigListBox * control_list ;
2010-03-28 17:58:21 +00:00
class C4GUI : : CheckBox * pGUICtrl ;
public :
ControlConfigArea ( const C4Rect & rcArea , int32_t iHMargin , int32_t iVMargin , bool fGamepad , C4StartupOptionsDlg * pOptionsDlg ) ;
2017-05-07 11:50:00 +00:00
~ ControlConfigArea ( ) override ;
2010-03-28 17:58:21 +00:00
void UpdateCtrlSet ( ) ;
2012-10-08 22:54:34 +00:00
protected :
2010-03-28 17:58:21 +00:00
void OnCtrlSetBtn ( C4GUI : : Control * btn ) ;
void OnResetKeysBtn ( C4GUI : : Control * btn ) ;
void OnGUIGamepadCheckChange ( C4GUI : : Element * pCheckBox ) ;
} ;
2012-10-08 22:54:34 +00:00
ControlConfigArea * pControlConfigArea ;
2010-03-28 17:58:21 +00:00
class C4GamePadControl * GamePadCon ;
2009-05-08 13:28:41 +00:00
// network tab --------------------------------------------------------
2010-03-28 17:58:21 +00:00
private :
// checkbox to enable protocol and editbox to input port number
class NetworkPortConfig : public C4GUI : : Window
{
public :
NetworkPortConfig ( const C4Rect & rcBounds , const char * szName , int32_t * pConfigValue , int32_t iDefault ) ; // ctor
2009-05-08 13:28:41 +00:00
private :
2010-03-28 17:58:21 +00:00
int32_t * pConfigValue ; // pointer into config set
C4GUI : : CheckBox * pEnableCheck ; // check box for whether port is enabled
C4GUI : : Edit * pPortEdit ; // edit field for port number
public :
void OnEnabledCheckChange ( C4GUI : : Element * pCheckBox ) ; // callback when checkbox is ticked
void SavePort ( ) ; // controls to config
int32_t GetPort ( ) ; // get port as currently configured by control (or -1 for deactivated)
static bool GetControlSize ( int * piWdt , int * piHgt ) ;
} * pPortCfgTCP , * pPortCfgUDP , * pPortCfgRef , * pPortCfgDsc ;
class NetworkServerAddressConfig : public C4GUI : : Window
{
public :
NetworkServerAddressConfig ( const C4Rect & rcBounds , const char * szName , int32_t * piConfigEnableValue , char * szConfigAddressValue , int iTabWidth ) ; // ctor
private :
int32_t * piConfigEnableValue ; char * szConfigAddressValue ;
C4GUI : : CheckBox * pEnableCheck ;
C4GUI : : Edit * pAddressEdit ;
public :
void OnEnabledCheckChange ( C4GUI : : Element * pCheckBox ) ; // callback when checkbox is ticked
void Save2Config ( ) ; // controls to config
static bool GetControlSize ( int * piWdt , int * piHgt , int * piTabPos , const char * szForText ) ;
} * pLeagueServerCfg ;
} ;
2009-05-08 13:28:41 +00:00
# endif // INC_C4StartupOptionsDlg