Back to index

supertuxkart  0.5+dfsg1
user_config.hpp
Go to the documentation of this file.
00001 // $Id: user_config.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 SuperTuxKart-Team
00005 //  Modelled after Supertux's configfile.h
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 2
00010 //  of the License, or (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 #ifndef HEADER_USERCONFIG_HPP
00022 #define HEADER_USERCONFIG_HPP
00023 
00024 #define PLAYERS 4
00025 
00026 /* The following config versions are currently used:
00027    0: the 0.2 release config file, without config-version number
00028       (so that defaults to 0)
00029    1: Removed singleWindowMenu, newKeyboardStyle, oldStatusDisplay,
00030       added config-version number
00031       Version 1 can read version 0 without any problems, so 
00032       SUPPORTED_CONFIG_VERSION is 0.
00033    2: Changed to SDL keyboard bindings
00034    3: Added username (userid was used for ALL players)
00035    4: Added username per player
00036    5: Enabled jumping, which might cause a problem with old
00037       config files (which have an unused entry for jump defined
00038       --> if a kart control for (say) player 2 uses the same key as
00039       jump for player 1, this problem is not noticed in 0.3, but will
00040       cause an undefined game action now
00041    6: Added stick configurations.
00042 */
00043 #define CURRENT_CONFIG_VERSION   6
00044 
00045 #include <string>
00046 #include <vector>
00047 #include "input.hpp"
00048 #include "player.hpp"
00049 #include "lisp/lisp.hpp"
00050 #include "lisp/parser.hpp"
00051 #include "lisp/writer.hpp"
00052 
00053 class ActionMap;
00054 
00055 /*class for managing general tuxkart configuration data*/
00056 class UserConfig
00057 {
00058 public:
00059               
00060        class StickConfig
00061        {
00062        public:
00063               std::string &id;
00064        
00065               int preferredIndex;
00066                             
00067               int deadzone;
00068                      
00069               StickConfig(std::string &);
00070                             
00071        };
00072 
00073 private:
00074                      
00075        std::vector <StickConfig *> m_stickconfigs;
00076                      
00077        typedef struct 
00078        {
00079               int count;
00080               Input *inputs;
00081        } InputMapEntry;
00082               
00083     std::string m_filename;
00084        
00092        InputMapEntry inputMap[GA_COUNT];
00093 
00094     void        setFilename      ();
00095     int         CheckAndCreateDir();
00096 
00097     // Attributes which have setter/getter
00098     int         m_sfx;
00099     int         m_music;
00100     std::string m_warning;
00101 
00102        void readStickConfigs(const lisp::Lisp *);
00103 
00104        void writeStickConfigs(lisp::Writer *);
00105                      
00106        void readPlayerInput(const lisp::Lisp *,
00107                                            const char *,
00108                                            KartAction ka,
00109                                            int);
00110 
00111        void writePlayerInput(lisp::Writer *,
00112                                             const char *,
00113                                             KartAction,
00114                                             int);
00115 
00116 
00117     void readInput(const lisp::Lisp *,
00118                    const char *,
00119                                GameAction);
00120 
00121     void writeInput(lisp::Writer *,
00122                     const char *,
00123                                    GameAction);
00124        
00125        
00131        void unsetDuplicates(GameAction, Input &);
00132        
00134        void set(GameAction, Input);
00135        
00137        void set(GameAction, Input, Input);
00138        
00140        void set(GameAction, Input, Input, Input);
00141        
00143        void set(GameAction, Input, Input, Input, Input);
00144 
00145        std::string getInputAsString(Input &);
00146 
00150        ActionMap *newActionMap(const int, const int);
00151        
00157        void setInput(GameAction, Input &);
00158 
00159 public:
00160     enum UC_Mode {UC_ENABLE, UC_DISABLE, UC_TEMPORARY_DISABLE};
00161 
00162     // Attributes that are accessed directly.
00163     bool        m_keyboard_debug;
00164     int         m_track_debug;
00165     bool        m_bullet_debug;
00166     bool        m_fullscreen;
00167     bool        m_no_start_screen;
00168     bool        m_smoke;
00169     bool        m_display_fps;
00170     int         m_profile;         // Positive number: time in seconds, neg: # laps
00171                                    // 0 if no profiling. Never saved in config file!
00172     bool        m_skidding;
00173     float       m_sfx_volume;
00174     int         m_max_fps;
00175     std::string m_herring_style;
00176     std::string m_username;
00177     std::string m_background_music;
00178     bool        m_replay_history;
00179     bool        m_use_kph;
00180     int         m_width;
00181     int         m_height;
00182     int                     m_prev_width;
00183     int                     m_prev_height;
00184     bool             m_prev_windowed;
00185     bool             m_crashed;
00186     std::vector<std::string> m_blacklist_res;
00187     int         m_karts;
00188     Player      m_player[PLAYERS];
00189     bool        m_log_errors;
00190 
00191     UserConfig();
00192     UserConfig(const std::string& filename);
00193     ~UserConfig();
00194     void setDefaults();
00195     void setMusic(int m)     { m_music        =  m;        }
00196     void setSFX  (int m)     { m_sfx          =  m;        }
00197     bool doMusic() const     { return m_music == UC_ENABLE;}
00198     bool doSFX()   const     { return m_sfx   == UC_ENABLE;}
00199     void loadConfig();
00200     void loadConfig(const std::string& filename);
00201     void saveConfig();
00202     void saveConfig(const std::string& filename);
00203                      
00204        void addStickConfig(UserConfig::StickConfig *);
00205                      
00206        const std::vector<StickConfig *> *getStickConfigs() const;
00207 
00208                      
00210     std::string getMappingAsString(GameAction);
00214        std::string getMappingAsString(int, KartAction);
00215        
00221        void setInput(int, KartAction, Input &);
00222        
00224        void clearInput(int, KartAction);
00225        
00226        bool isFixedInput(InputType, int, int, int);
00227     const std::string& getWarning() {return m_warning;}
00228     void  resetWarning() {m_warning="";}
00229        
00231        ActionMap *newMenuActionMap();
00232        
00234        ActionMap *newIngameActionMap();
00235                      
00236 };
00237 
00238 
00239 extern UserConfig *user_config;
00240 
00241 #endif
00242 
00243 /*EOF*/