Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

userconfiguration.h

00001 /***************************************************************************
00002                           userconfiguration.h  -  description
00003                              -------------------
00004     begin                : Sat Feb 14 2004
00005     copyright            : (C) 2004 by Daroth-U 
00006     email                : daroth-u@ifrance.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef USER_CONFIGURATION_H
00019 #define USER_CONFIGURATION_H
00020 
00021 
00022 #include <fstream>
00023 #include <iostream>
00024 #include <string>
00025 #include <map>
00026 #include "constants.h"
00027 //#include "util.h"
00028 
00029 using namespace std;
00030 
00031 // Indice for the first debug engine action defined in engine_action_int
00032 //#define ENGINE_ACTION_DEBUG_IND 32
00033 
00034 // set to non-zero for debugging
00035 #define DEBUG_USER_CONFIG 0  
00036 
00037 // All engine action that can be binded
00038 // If you change this, ALSO change ENGINE_ACTION_NAMES in userconfiguration.cpp
00039 // AND update ENGINE_ACTION_DEBUG_IND (first indice of invisible engine actions)
00040 // AND add a corresponding bind line in config file (to have a default value)
00041 enum engine_action_int{
00042     
00043     SET_MOVE_DOWN = 0,
00044     SET_MOVE_RIGHT,
00045     SET_MOVE_UP,
00046     SET_MOVE_LEFT,
00047             
00048     SET_PLAYER_0,
00049     SET_PLAYER_1,
00050     SET_PLAYER_2,
00051     SET_PLAYER_3,
00052     SET_PLAYER_ONLY,      
00053     
00054     SHOW_INVENTORY, 
00055     SHOW_OPTIONS_MENU,
00056     SET_NEXT_FORMATION,
00057            
00058     MINIMAP_ZOOM_IN,
00059     MINIMAP_ZOOM_OUT,
00060     
00061     SET_ZOOM_IN,     
00062     SET_ZOOM_OUT,
00063     
00064     TOGGLE_MAP_CENTER, 
00065     INCREASE_GAME_SPEED, 
00066     DECREASE_GAME_SPEED, 
00067     
00068     START_ROUND, 
00069 
00070     LAYOUT_1,
00071     LAYOUT_2,
00072     LAYOUT_4,
00073 
00074     SHOW_PATH,
00075     SWITCH_COMBAT,
00076 
00077     QUICK_SPELL_1,
00078     QUICK_SPELL_2,
00079     QUICK_SPELL_3,      
00080     QUICK_SPELL_4,      
00081     QUICK_SPELL_5,      
00082     QUICK_SPELL_6,      
00083     QUICK_SPELL_7,      
00084     QUICK_SPELL_8,      
00085     QUICK_SPELL_9,      
00086     QUICK_SPELL_10,      
00087     QUICK_SPELL_11,      
00088     QUICK_SPELL_12,      
00089 
00090     // must be last
00091     ENGINE_ACTION_COUNT    
00092 };
00093 
00094 // All engine actions that have a corresponding keyup action
00095 // If you change this, ALSO change ENGINE_ACTION_UP_NAMES in userconfiguration.cpp
00096 enum engine_action_up_int{
00097 
00098     SET_MOVE_DOWN_STOP = 500,   // Must be first
00099     SET_MOVE_RIGHT_STOP, 
00100     SET_MOVE_UP_STOP,
00101     SET_MOVE_LEFT_STOP,
00102     SET_Y_ROT_PLUS_STOP,
00103     SET_Y_ROT_MINUS_STOP,    
00104     SET_Z_ROT_PLUS_STOP,        
00105     SET_Z_ROT_MINUS_STOP,
00106     SET_ZOOM_IN_STOP,     
00107     SET_ZOOM_OUT_STOP,
00108     SHOW_PATH_STOP,
00109     SET_NEXT_FORMATION_STOP,    
00110     
00111     // must be the last one
00112     ENGINE_ACTION_UP_COUNT
00113 };
00114 
00115 class UserConfiguration{
00116 
00117 private:
00118   static const char * ENGINE_ACTION_NAMES[];     
00119   static const char * ENGINE_ACTION_UP_NAMES[];
00120   static const char * ENGINE_ACTION_DESCRIPTION[];   
00121   static const char default_key[][20];
00122   
00123   // becomes true every time loadConfiguration is called  
00124   // and false every time getConfigurationChanged is called
00125   bool configurationChanged; 
00126   
00127   // mappings to speed-up search processing
00128   map<string, int> keyDownBindings;      // string keyName -> int ea
00129   map<string, int> keyUpBindings;        // string keyName -> int ea
00130   map<Uint8, int> mouseDownBindings;     // uint8 mouseButton -> int ea
00131   map<Uint8, int> mouseUpBindings;       // uint8 mouseButton -> int ea 
00132   map<string, int> engineActionUpNumber; // string ea -> int ea
00133   map<string, int> engineActionNumber;   // string ea -> int ea
00134   map<int, string> keyForEngineAction;   // int ea -> string keyName
00135   map<int, string> engineActionName;     // int ea -> string ea  
00136        
00137   // return next word from string or empty string
00138   string getNextWord(const string theInput, int fromPos, int &endWord);
00139   
00140   // replace " " by "_" in a string
00141   string replaceSpaces(string s);
00142   
00143   void writeFile(ofstream *fileOut, char *text);  
00144   
00145   // engine variables (video settings) 
00146   bool fullscreen;
00147   bool doublebuf;
00148   bool hwpal;
00149   bool resizeable;
00150   bool force_hwsurf;
00151   bool force_swsurf;
00152   bool hwaccel; 
00153   bool test;  
00154   bool multitexturing; 
00155   bool stencilbuf;
00156   int bpp;
00157   int w;
00158   int h;  
00159   int shadows;
00160   bool alwaysShowPath;
00161   bool tooltipEnabled;
00162   int tooltipInterval;
00163   
00164   // game settings
00165   int gamespeed;
00166   bool centermap;
00167   bool keepMapSize;
00168   bool frameOnFullScreen;
00169   bool turnBasedBattle;
00170   bool ovalCutoutShown;
00171 
00172   // was the stencil buf. initialized at start?
00173   bool stencilBufInitialized;
00174 
00175   // audio settings
00176   bool soundEnabled;
00177   int soundFreq;
00178   int musicVolume;
00179   int effectsVolume;
00180 
00181   int standAloneMode;
00182   char *host, *userName;
00183   int port;
00184    
00185  public:
00186 
00187   enum {
00188     NONE = 0,
00189     SERVER,
00190     CLIENT
00191   };
00192  
00193   UserConfiguration::UserConfiguration();
00194   UserConfiguration::~UserConfiguration();
00195   
00196   const char * getEngineActionDescription(int i);  
00197   const char * getEngineActionKeyName(int i);      
00198               
00199   // engine variables
00200   inline bool getFullscreen(){ return fullscreen; }
00201   inline bool getDoublebuf() { return doublebuf;  }
00202   inline bool getHwpal()     { return hwpal;      }
00203   inline bool getResizeable(){ return resizeable; }
00204   inline bool getForce_hwsurf() { return force_hwsurf; }
00205   inline bool getForce_swsurf() { return force_swsurf; }
00206   inline bool getHwaccel()   { return hwaccel;    }
00207   inline bool getTest()      { return test;       }
00208   inline bool getStencilbuf(){ return stencilbuf; }  
00209   inline bool getMultitexturing() { return Constants::multitexture; }     
00210   inline int getBpp()        { return bpp;        }
00211   inline int getW()          { return w;          }
00212   inline int getH()          { return h;          }
00213   inline int getShadows()    { return shadows;    }  
00214   inline int getGameSpeedLevel()  { return gamespeed;  } // [0, 1, 2, 3, 4] 
00215   inline bool getAlwaysCenterMap(){ return centermap;  }  
00216   inline bool getKeepMapSize() { return keepMapSize; }
00217   inline bool getFrameOnFullScreen() { return frameOnFullScreen; }
00218   inline bool isBattleTurnBased() { return turnBasedBattle; }
00219   inline bool isOvalCutoutShown() { return ovalCutoutShown; }
00220   inline int getSoundFreq() { return soundFreq; }
00221   inline bool isSoundEnabled() { return soundEnabled; }
00222   inline int getMusicVolume() { return musicVolume; }
00223   inline int getEffectsVolume() { return effectsVolume; }
00224   inline bool getAlwaysShowPath() { return alwaysShowPath; }
00225   inline bool getTooltipEnabled() { return tooltipEnabled; }
00226   inline int getTooltipInterval() { return tooltipInterval; }
00227   
00228   inline void setFullscreen(bool t){ fullscreen=t; }
00229   inline void setDoublebuf(bool t) { doublebuf=t;  }
00230   inline void setHwpal(bool t)     { hwpal=t;      }
00231   inline void setResizeable(bool t){ resizeable=t; }
00232   inline void setForce_hwsurf(bool t) { force_hwsurf=t; }
00233   inline void setForce_swsurf(bool t) { force_swsurf=t; }
00234   inline void setHwaccel(bool t)   { hwaccel=t;    }   
00235   inline void setStencilbuf(bool t){ stencilbuf=t; }
00236   inline void setMultitexturing(bool t){ Constants::multitexture=t; }
00237   inline void setBpp(int t)         { bpp=t;        }
00238   inline void setW(int t)           { w=t;          }
00239   inline void setH(int t)           { h=t;          }
00240   inline void setShadows(int t)     { shadows=t; }
00241   inline void setGameSpeedLevel(int t)   { if(t >= 0 && t <= 4) gamespeed=t; } // [0, 1, 2, 3, 4]
00242   inline void setAlwaysCenterMap(int t) { centermap=t; }
00243   inline void setKeepMapSize(int t) { keepMapSize = t; }
00244   inline void setFrameOnFullScreen(int t) { frameOnFullScreen = t; }
00245   inline void setBattleTurnBased(bool b) { turnBasedBattle = b; }
00246   inline void setOvalCutoutShown(bool b) { ovalCutoutShown = b; }
00247   inline void setSoundFreq(int n) { soundFreq = n; }
00248   inline void setSoundEnabled(bool b) { soundEnabled = b; }
00249   inline void setMusicVolume(int n) { musicVolume = n; }
00250   inline void setEffectsVolume(int n) { effectsVolume = n; }
00251   inline void setAlwaysShowPath( bool b ) { alwaysShowPath = b; }
00252   inline void setTooltipEnabled( bool b ) { tooltipEnabled = b; }
00253   inline void setTooltipInterval( int n ) { tooltipInterval = n; }
00254   
00255   // return gameSpeed in ticks
00256   int getGameSpeedTicks();           
00257   
00258   
00259   // reads the configuration file where keys are binded
00260   void loadConfiguration();
00261   
00262   // save configuration into file
00263   void saveConfiguration(); 
00264   
00265   // Associate SDL events to an engine action    
00266   void bind(string s1, string s2, int lineNumber);
00267   
00268   // Read in engine variables from file
00269   void set (string s1, string s2, int lineNumber); 
00270   
00271   // returns the action to do for this event
00272   int getEngineAction(SDL_Event *event); 
00273   
00274   void parseCommandLine(int argc, char *argv[]);  
00275   void setKeyForEngineAction(string keyName, int ea);
00276 
00277   inline void setStencilBufInitialized(bool b) { stencilBufInitialized = b; }
00278   inline bool getStencilBufInitialized() { return stencilBufInitialized; }
00279 
00280   inline int getStandAloneMode() { return standAloneMode; }
00281   inline char *getHost() { return host; }
00282   inline char *getUserName() { return userName; }
00283   inline int getPort() { return port; }
00284 
00285   void createConfigDir();
00286 
00287  protected:  
00288         void createDefaultConfigFile();
00289 };
00290 
00291 #endif
00292 

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0