@ -12,25 +12,24 @@
# include "saveload/saveload.h"
# include "saveload/saveload.h"
enum SettingGuiFlag : uint16 {
enum SettingFlag : uint16 {
/* 2 bytes allocated for a maximum of 16 flags. */
SF_NONE = 0 ,
SGF_NONE = 0 ,
SF_GUI_0_IS_SPECIAL = 1 < < 0 , ///< A value of zero is possible and has a custom string (the one after "strval").
SGF_0ISDISABLED = 1 < < 0 , ///< a value of zero means the feature is disabled
SF_GUI_NEGATIVE_IS_SPECIAL = 1 < < 1 , ///< A negative value has another string (the one after "strval").
SGF_DISPLAY_ABS = 1 < < 1 , ///< display absolute value of the setting
SF_GUI_DROPDOWN = 1 < < 2 , ///< The value represents a limited number of string-options (internally integer) presented as dropdown.
SGF_MULTISTRING = 1 < < 2 , ///< the value represents a limited number of string-options (internally integer)
SF_GUI_CURRENCY = 1 < < 3 , ///< The number represents money, so when reading value multiply by exchange rate.
SGF_NETWORK_ONLY = 1 < < 3 , ///< this setting only applies to network games
SF_NETWORK_ONLY = 1 < < 4 , ///< This setting only applies to network games.
SGF_CURRENCY = 1 < < 4 , ///< the number represents money, so when reading value multiply by exchange rate
SF_NO_NETWORK = 1 < < 5 , ///< This setting does not apply to network games; it may not be changed during the game.
SGF_NO_NETWORK = 1 < < 5 , ///< this setting does not apply to network games; it may not be changed during the game
SF_NEWGAME_ONLY = 1 < < 6 , ///< This setting cannot be changed in a game.
SGF_NEWGAME_ONLY = 1 < < 6 , ///< this setting cannot be changed in a game
SF_SCENEDIT_TOO = 1 < < 7 , ///< This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
SGF_SCENEDIT_TOO = 1 < < 7 , ///< this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
SF_SCENEDIT_ONLY = 1 < < 8 , ///< This setting can only be changed in the scenario editor.
SGF_PER_COMPANY = 1 < < 8 , ///< this setting can be different for each company (saved in company struct)
SF_PER_COMPANY = 1 < < 9 , ///< This setting can be different for each company (saved in company struct).
SGF_SCENEDIT_ONLY = 1 < < 9 , ///< this setting can only be changed in the scenario editor
SF_DECIMAL1 = 1 < < 10 , ///< display a decimal representation of the setting value divided by 10
SGF_DECIMAL1 = 1 < < 10 , ///< display a decimal representation of the setting value divided by 10
SF_ENUM = 1 < < 11 , ///< the setting can take one of the values given by an array of struct SettingDescEnumEntry
SGF_ENUM = 1 < < 11 , ///< the setting can take one of the values given by an array of struct SettingDescEnumEntry
SF_NO_NEWGAME = 1 < < 12 , ///< the setting does not apply and is not shown in a new game context
SGF_NO_NEWGAME = 1 < < 12 , ///< the setting does not apply and is not shown in a new game context
SF_DEC1SCALE = 1 < < 13 , ///< also display a float representation of the scale of a decimal1 scale parameter
SGF_DEC1SCALE = 1 < < 13 , ///< also display a float representation of the scale of a decimal1 scale parameter
} ;
} ;
DECLARE_ENUM_AS_BIT_SET ( Setting Gui Flag)
DECLARE_ENUM_AS_BIT_SET ( Setting Flag)
/**
/**
* A SettingCategory defines a grouping of the settings .
* A SettingCategory defines a grouping of the settings .
@ -69,7 +68,7 @@ enum SettingType {
enum SettingOnGuiCtrlType {
enum SettingOnGuiCtrlType {
SOGCT_DESCRIPTION_TEXT , ///< Description text callback
SOGCT_DESCRIPTION_TEXT , ///< Description text callback
SOGCT_ MULTISTRING_ORDER, ///< SGF_MULTISTRING reordering callback
SOGCT_ GUI_DROPDOWN_ORDER, ///< SF_GUI_DROPDOWN reordering callback
} ;
} ;
struct SettingOnGuiCtrlData {
struct SettingOnGuiCtrlData {
@ -99,16 +98,16 @@ struct SettingsXref {
/** Properties of config file settings. */
/** Properties of config file settings. */
struct SettingDesc {
struct SettingDesc {
struct XrefContructorTag { } ;
struct XrefContructorTag { } ;
SettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name ) :
SettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name ) :
name ( name ) , flags ( flags ) , guiproc ( guiproc ) , startup ( startup ) , save ( save ) , patx_name ( patx_name ) { }
name ( name ) , flags ( flags ) , guiproc ( guiproc ) , startup ( startup ) , save ( save ) , patx_name ( patx_name ) { }
SettingDesc ( XrefContructorTag tag , SaveLoad save , SettingsXref xref ) :
SettingDesc ( XrefContructorTag tag , SaveLoad save , SettingsXref xref ) :
name ( nullptr ) , flags ( S G F_NONE) , guiproc ( nullptr ) , startup ( false ) , save ( save ) , patx_name ( nullptr ) , xref ( xref ) { }
name ( nullptr ) , flags ( S F_NONE) , guiproc ( nullptr ) , startup ( false ) , save ( save ) , patx_name ( nullptr ) , xref ( xref ) { }
virtual ~ SettingDesc ( ) { }
virtual ~ SettingDesc ( ) { }
const char * name ; ///< n ame of the setting. Used in configuration file and for console
const char * name ; ///< N ame of the setting. Used in configuration file and for console
Setting GuiFlag flags ; ///< h andles how a setting would show up in the GUI (text/currency, etc.)
Setting Flag flags ; ///< H andles how a setting would show up in the GUI (text/currency, etc.)
OnGuiCtrl * guiproc ; ///< c allback procedure for GUI operations
OnGuiCtrl * guiproc ; ///< C allback procedure for GUI operations
bool startup ; ///< s etting has to be loaded directly at startup?
bool startup ; ///< S etting has to be loaded directly at startup?
SaveLoad save ; ///< Internal structure (going to savegame, parts to config)
SaveLoad save ; ///< Internal structure (going to savegame, parts to config)
const char * patx_name ; ///< Name to save/load setting from in PATX chunk, if nullptr save/load from PATS chunk as normal
const char * patx_name ; ///< Name to save/load setting from in PATX chunk, if nullptr save/load from PATS chunk as normal
@ -176,7 +175,7 @@ struct IntSettingDesc : SettingDesc {
*/
*/
typedef void PostChangeCallback ( int32 value ) ;
typedef void PostChangeCallback ( int32 value ) ;
IntSettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , int32 def ,
IntSettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , int32 def ,
int32 min , uint32 max , int32 interval , StringID str , StringID str_help , StringID str_val ,
int32 min , uint32 max , int32 interval , StringID str , StringID str_help , StringID str_val ,
SettingCategory cat , PreChangeCheck pre_check , PostChangeCallback post_callback , const SettingDescEnumEntry * enumlist ) :
SettingCategory cat , PreChangeCheck pre_check , PostChangeCallback post_callback , const SettingDescEnumEntry * enumlist ) :
SettingDesc ( save , name , flags , guiproc , startup , patx_name ) , def ( def ) , min ( min ) , max ( max ) , interval ( interval ) ,
SettingDesc ( save , name , flags , guiproc , startup , patx_name ) , def ( def ) , min ( min ) , max ( max ) , interval ( interval ) ,
@ -195,7 +194,7 @@ struct IntSettingDesc : SettingDesc {
PreChangeCheck * pre_check ; ///< Callback to check for the validity of the setting.
PreChangeCheck * pre_check ; ///< Callback to check for the validity of the setting.
PostChangeCallback * post_callback ; ///< Callback when the setting has been changed.
PostChangeCallback * post_callback ; ///< Callback when the setting has been changed.
const SettingDescEnumEntry * enumlist ; ///< For S G F_ENUM. The last entry must use STR_NULL
const SettingDescEnumEntry * enumlist ; ///< For S F_ENUM. The last entry must use STR_NULL
/**
/**
* Check whether this setting is a boolean type setting .
* Check whether this setting is a boolean type setting .
@ -220,7 +219,7 @@ private:
/** Boolean setting. */
/** Boolean setting. */
struct BoolSettingDesc : IntSettingDesc {
struct BoolSettingDesc : IntSettingDesc {
BoolSettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , bool def ,
BoolSettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , bool def ,
StringID str , StringID str_help , StringID str_val , SettingCategory cat ,
StringID str , StringID str_help , StringID str_val , SettingCategory cat ,
PreChangeCheck pre_check , PostChangeCallback post_callback ) :
PreChangeCheck pre_check , PostChangeCallback post_callback ) :
IntSettingDesc ( save , name , flags , guiproc , startup , patx_name , def , 0 , 1 , 0 , str , str_help , str_val , cat , pre_check , post_callback , nullptr ) { }
IntSettingDesc ( save , name , flags , guiproc , startup , patx_name , def , 0 , 1 , 0 , str , str_help , str_val , cat , pre_check , post_callback , nullptr ) { }
@ -235,7 +234,7 @@ struct BoolSettingDesc : IntSettingDesc {
struct OneOfManySettingDesc : IntSettingDesc {
struct OneOfManySettingDesc : IntSettingDesc {
typedef size_t OnConvert ( const char * value ) ; ///< callback prototype for conversion error
typedef size_t OnConvert ( const char * value ) ; ///< callback prototype for conversion error
OneOfManySettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name ,
OneOfManySettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name ,
int32 def , int32 max , StringID str , StringID str_help , StringID str_val , SettingCategory cat ,
int32 def , int32 max , StringID str , StringID str_help , StringID str_val , SettingCategory cat ,
PreChangeCheck pre_check , PostChangeCallback post_callback ,
PreChangeCheck pre_check , PostChangeCallback post_callback ,
std : : initializer_list < const char * > many , OnConvert * many_cnvt ) :
std : : initializer_list < const char * > many , OnConvert * many_cnvt ) :
@ -258,7 +257,7 @@ struct OneOfManySettingDesc : IntSettingDesc {
/** Many of many setting. */
/** Many of many setting. */
struct ManyOfManySettingDesc : OneOfManySettingDesc {
struct ManyOfManySettingDesc : OneOfManySettingDesc {
ManyOfManySettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name ,
ManyOfManySettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name ,
int32 def , StringID str , StringID str_help , StringID str_val , SettingCategory cat ,
int32 def , StringID str , StringID str_help , StringID str_val , SettingCategory cat ,
PreChangeCheck pre_check , PostChangeCallback post_callback ,
PreChangeCheck pre_check , PostChangeCallback post_callback ,
std : : initializer_list < const char * > many , OnConvert * many_cnvt ) :
std : : initializer_list < const char * > many , OnConvert * many_cnvt ) :
@ -287,7 +286,7 @@ struct StringSettingDesc : SettingDesc {
*/
*/
typedef void PostChangeCallback ( const std : : string & value ) ;
typedef void PostChangeCallback ( const std : : string & value ) ;
StringSettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , const char * def ,
StringSettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , const char * def ,
uint32 max_length , PreChangeCheck pre_check , PostChangeCallback post_callback ) :
uint32 max_length , PreChangeCheck pre_check , PostChangeCallback post_callback ) :
SettingDesc ( save , name , flags , guiproc , startup , patx_name ) , def ( def = = nullptr ? " " : def ) , max_length ( max_length ) ,
SettingDesc ( save , name , flags , guiproc , startup , patx_name ) , def ( def = = nullptr ? " " : def ) , max_length ( max_length ) ,
pre_check ( pre_check ) , post_callback ( post_callback ) { }
pre_check ( pre_check ) , post_callback ( post_callback ) { }
@ -313,7 +312,7 @@ private:
/** List/array settings. */
/** List/array settings. */
struct ListSettingDesc : SettingDesc {
struct ListSettingDesc : SettingDesc {
ListSettingDesc ( SaveLoad save , const char * name , Setting Gui Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , const char * def ) :
ListSettingDesc ( SaveLoad save , const char * name , Setting Flag flags , OnGuiCtrl * guiproc , bool startup , const char * patx_name , const char * def ) :
SettingDesc ( save , name , flags , guiproc , startup , patx_name ) , def ( def ) { }
SettingDesc ( save , name , flags , guiproc , startup , patx_name ) , def ( def ) { }
virtual ~ ListSettingDesc ( ) { }
virtual ~ ListSettingDesc ( ) { }
@ -327,7 +326,7 @@ struct ListSettingDesc : SettingDesc {
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
struct NullSettingDesc : SettingDesc {
struct NullSettingDesc : SettingDesc {
NullSettingDesc ( SaveLoad save ) :
NullSettingDesc ( SaveLoad save ) :
SettingDesc ( save , " " , S G F_NONE, nullptr , false , nullptr ) { }
SettingDesc ( save , " " , S F_NONE, nullptr , false , nullptr ) { }
virtual ~ NullSettingDesc ( ) { }
virtual ~ NullSettingDesc ( ) { }
void FormatValue ( char * buf , const char * last , const void * object ) const override { NOT_REACHED ( ) ; }
void FormatValue ( char * buf , const char * last , const void * object ) const override { NOT_REACHED ( ) ; }