settings_internal.h

Go to the documentation of this file.
00001 /* $Id: settings_internal.h 24787 2012-12-05 19:35:09Z frosch $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef SETTINGS_INTERNAL_H
00013 #define SETTINGS_INTERNAL_H
00014 
00015 #include "saveload/saveload.h"
00016 
00023 enum SettingDescTypeLong {
00024   /* 4 bytes allocated a maximum of 16 types for GenericType */
00025   SDT_BEGIN       = 0,
00026   SDT_NUMX        = 0, 
00027   SDT_BOOLX       = 1, 
00028   SDT_ONEOFMANY   = 2, 
00029   SDT_MANYOFMANY  = 3, 
00030   SDT_INTLIST     = 4, 
00031   SDT_STRING      = 5, 
00032   SDT_END,
00033   /* 10 more possible primitives */
00034 };
00035 typedef SimpleTinyEnumT<SettingDescTypeLong, byte> SettingDescType;
00036 
00037 
00038 enum SettingGuiFlagLong {
00039   /* 1 byte allocated for a maximum of 8 flags
00040    * Flags directing saving/loading of a variable */
00041   SGF_NONE = 0,
00042   SGF_0ISDISABLED  = 1 << 0, 
00043   SGF_DISPLAY_ABS  = 1 << 1, 
00044   SGF_MULTISTRING  = 1 << 2, 
00045   SGF_NETWORK_ONLY = 1 << 3, 
00046   SGF_CURRENCY     = 1 << 4, 
00047   SGF_NO_NETWORK   = 1 << 5, 
00048   SGF_NEWGAME_ONLY = 1 << 6, 
00049   SGF_SCENEDIT_TOO = 1 << 7, 
00050   SGF_PER_COMPANY  = 1 << 8, 
00051 };
00052 DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong)
00053 typedef SimpleTinyEnumT<SettingGuiFlagLong, uint16> SettingGuiFlag;
00054 
00063 enum SettingCategory {
00064   SC_NONE = 0,
00065 
00066   /* Filters for the list */
00067   SC_BASIC_LIST      = 1 << 0,    
00068   SC_ADVANCED_LIST   = 1 << 1,    
00069   SC_EXPERT_LIST     = 1 << 2,    
00070 
00071   /* Setting classification */
00072   SC_BASIC           = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST,  
00073   SC_ADVANCED        = SC_ADVANCED_LIST | SC_EXPERT_LIST,                  
00074   SC_EXPERT          = SC_EXPERT_LIST,                                     
00075 
00076   SC_END,
00077 };
00078 
00079 
00080 typedef bool OnChange(int32 var);           
00081 typedef size_t OnConvert(const char *value); 
00082 
00084 struct SettingDescBase {
00085   const char *name;       
00086   const void *def;        
00087   SettingDescType cmd;    
00088   SettingGuiFlag flags;   
00089   int32 min;              
00090   uint32 max;             
00091   int32 interval;         
00092   const char *many;       
00093   StringID str;           
00094   StringID str_help;      
00095   StringID str_val;       
00096   OnChange *proc;         
00097   OnConvert *proc_cnvt;   
00098   SettingCategory cat;    
00099 };
00100 
00101 struct SettingDesc {
00102   SettingDescBase desc;   
00103   SaveLoad save;          
00104 
00105   bool IsEditable(bool do_command = false) const;
00106 };
00107 
00108 /* NOTE: The only difference between SettingDesc and SettingDescGlob is
00109  * that one uses global variables as a source and the other offsets
00110  * in a struct which are bound to a certain variable during runtime.
00111  * The only way to differentiate between these two is to check if an object
00112  * has been passed to the function or not. If not, then it is a global variable
00113  * and save->variable has its address, otherwise save->variable only holds the
00114  * offset in a certain struct */
00115 typedef SettingDesc SettingDescGlobVarList;
00116 
00117 const SettingDesc *GetSettingFromName(const char *name, uint *i);
00118 bool SetSettingValue(uint index, int32 value, bool force_newgame = false);
00119 bool SetSettingValue(uint index, const char *value, bool force_newgame = false);
00120 void SetCompanySetting(uint index, int32 value);
00121 
00122 #endif /* SETTINGS_INTERNAL_H */