/*
* This file is part of OpenTTD .
* OpenTTD 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 , version 2.
* OpenTTD 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 OpenTTD . If not , see < http : //www.gnu.org/licenses/>.
*/
/** @file settings_internal.h Functions and types used internally for the settings configurations. */
# ifndef SETTINGS_INTERNAL_H
# define SETTINGS_INTERNAL_H
# include "saveload/saveload.h"
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
/**
* Convention / Type of settings . This is then further specified if necessary
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
* with the SLE_ ( SLE_VAR / SLE_FILE ) enums in saveload . h
* @ see VarTypes
* @ see SettingDescBase
*/
enum SettingDescType : byte {
SDT_NUMX = 0 , ///< any number-type
SDT_BOOLX = 1 , ///< a boolean number
SDT_ONEOFMANY = 2 , ///< bitmasked number where only ONE bit may be set
SDT_MANYOFMANY = 3 , ///< bitmasked number where MULTIPLE bits may be set
SDT_INTLIST = 4 , ///< list of integers separated by a comma ','
SDT_STDSTRING = 6 , ///< \c std::string
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
} ;
enum SettingGuiFlag : uint16 {
/* 2 bytes allocated for a maximum of 16 flags. */
SGF_NONE = 0 ,
SGF_0ISDISABLED = 1 < < 0 , ///< a value of zero means the feature is disabled
SGF_DISPLAY_ABS = 1 < < 1 , ///< display absolute value of the setting
SGF_MULTISTRING = 1 < < 2 , ///< the value represents a limited number of string-options (internally integer)
SGF_NETWORK_ONLY = 1 < < 3 , ///< this setting only applies to network games
SGF_CURRENCY = 1 < < 4 , ///< the number represents money, so when reading value multiply by exchange rate
SGF_NO_NETWORK = 1 < < 5 , ///< this setting does not apply to network games; it may not be changed during the game
SGF_NEWGAME_ONLY = 1 < < 6 , ///< this setting cannot be changed in a game
SGF_SCENEDIT_TOO = 1 < < 7 , ///< this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
SGF_PER_COMPANY = 1 < < 8 , ///< 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
SGF_DECIMAL1 = 1 < < 10 , ///< display a decimal representation of the setting value divided by 10
SGF_ENUM = 1 < < 11 , ///< the setting can take one of the values given by an array of struct SettingDescEnumEntry
SGF_NO_NEWGAME = 1 < < 12 , ///< the setting does not apply and is not shown in a new game context
SGF_DEC1SCALE = 1 < < 13 , ///< also display a float representation of the scale of a decimal1 scale parameter
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
} ;
DECLARE_ENUM_AS_BIT_SET ( SettingGuiFlag )
/**
* A SettingCategory defines a grouping of the settings .
* The group # SC_BASIC is intended for settings which also a novice player would like to change and is able to understand .
* The group # SC_ADVANCED is intended for settings which an experienced player would like to use . This is the case for most settings .
* Finally # SC_EXPERT settings only few people want to see in rare cases .
* The grouping is meant to be inclusive , i . e . all settings in # SC_BASIC also will be included
* in the set of settings in # SC_ADVANCED . The group # SC_EXPERT contains all settings .
*/
enum SettingCategory {
SC_NONE = 0 ,
/* Filters for the list */
SC_BASIC_LIST = 1 < < 0 , ///< Settings displayed in the list of basic settings.
SC_ADVANCED_LIST = 1 < < 1 , ///< Settings displayed in the list of advanced settings.
SC_EXPERT_LIST = 1 < < 2 , ///< Settings displayed in the list of expert settings.
/* Setting classification */
SC_BASIC = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST , ///< Basic settings are part of all lists.
SC_ADVANCED = SC_ADVANCED_LIST | SC_EXPERT_LIST , ///< Advanced settings are part of advanced and expert list.
SC_EXPERT = SC_EXPERT_LIST , ///< Expert settings can only be seen in the expert list.
SC_END ,
} ;
/**
* Type of settings for filtering .
*/
enum SettingType {
ST_GAME , ///< Game setting.
ST_COMPANY , ///< Company setting.
ST_CLIENT , ///< Client setting.
ST_ALL , ///< Used in setting filter to match all types.
} ;
enum SettingOnGuiCtrlType {
SOGCT_DESCRIPTION_TEXT , ///< Description text callback
SOGCT_MULTISTRING_ORDER , ///< SGF_MULTISTRING reordering callback
} ;
struct SettingOnGuiCtrlData {
SettingOnGuiCtrlType type ;
StringID text ;
int val ;
} ;
typedef bool OnChange ( int32 var ) ; ///< callback prototype on data modification
typedef size_t OnConvert ( const char * value ) ; ///< callback prototype for conversion error
typedef bool OnGuiCtrl ( SettingOnGuiCtrlData & data ) ; ///< callback prototype for GUI operations
typedef int64 OnXrefValueConvert ( int64 val ) ; ///< callback prototype for xref value conversion
/** The last entry in an array of struct SettingDescEnumEntry must use STR_NULL. */
struct SettingDescEnumEntry {
int32 val ;
StringID str ;
} ;
/** Properties of config file settings. */
struct SettingDescBase {
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
const char * name ; ///< name of the setting. Used in configuration file and for console
const void * def ; ///< default value given when none is present
SettingDescType cmd ; ///< various flags for the variable
SettingGuiFlag flags ; ///< handles how a setting would show up in the GUI (text/currency, etc.)
int32 min ; ///< minimum values
uint32 max ; ///< maximum values
int32 interval ; ///< the interval to use between settings in the 'settings' window. If interval is '0' the interval is dynamically determined
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
const char * many ; ///< ONE/MANY_OF_MANY: string of possible values for this type
StringID str ; ///< (translated) string with descriptive text; gui and console
StringID str_help ; ///< (Translated) string with help text; gui only.
StringID str_val ; ///< (Translated) first string describing the value.
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
OnChange * proc ; ///< callback procedure for when the value is changed
OnGuiCtrl * guiproc ; ///< callback procedure for GUI operations
OnConvert * proc_cnvt ; ///< callback procedure when loading value mechanism fails
SettingCategory cat ; ///< assigned categories of the setting
bool startup ; ///< setting has to be loaded directly at startup?
const SettingDescEnumEntry * enumlist ; ///< For SGF_ENUM. The last entry must use STR_NULL
} ;
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
struct SettingsXref {
const char * target ;
OnXrefValueConvert * conv ;
SettingsXref ( ) : target ( nullptr ) , conv ( nullptr ) { }
SettingsXref ( const char * target_ , OnXrefValueConvert * conv_ ) : target ( target_ ) , conv ( conv_ ) { }
} ;
struct SettingDesc : SettingDescBase {
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
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
SettingsXref xref ; ///< Details of SettingDesc to use instead of the contents of this one, useful for loading legacy savegames, if target field nullptr save/load as normal
bool IsEditable ( bool do_command = false ) const ;
SettingType GetType ( ) const ;
} ;
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
19 years ago
typedef std : : initializer_list < const SettingDesc > SettingTable ;
const SettingDesc * GetSettingFromName ( const char * name , bool ignore_version = false ) ;
bool SetSettingValue ( const SettingDesc * sd , int32 value , bool force_newgame = false ) ;
bool SetSettingValue ( const SettingDesc * sd , const char * value , bool force_newgame = false ) ;
uint GetSettingIndex ( const SettingDesc * sd ) ;
# endif /* SETTINGS_INTERNAL_H */