00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "global.h"
00022 #include "gameoptions.h"
00023 #include "basestrm.h"
00024
00025
00026 CGameOptions* pStaticGameOptions=NULL;
00027
00028 class Destroyer
00029 {
00030 public:
00031 ~Destroyer()
00032 {
00033 delete pStaticGameOptions;
00034 };
00035 }
00036 destroyer;
00037
00038 CGameOptions* CGameOptions::Instance()
00039 {
00040 if (!pStaticGameOptions)
00041 pStaticGameOptions = new CGameOptions;
00042 return pStaticGameOptions;
00043 }
00044
00045 const int CGameOptions::maxSearchPathNum = 30;
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 const int mouseButtonNum = 6;
00061 const char* mouseButtons[mouseButtonNum] =
00062 { "none",
00063 "left",
00064 "center",
00065 "right",
00066 "4",
00067 "5" };
00068
00069
00070
00071 void CGameOptions::load( const ASCString& filename )
00072 {
00073 tnfilestream s ( filename, tnstream::reading );
00074
00075 TextFormatParser tfp ( &s );
00076 auto_ptr<TextPropertyGroup> tpg ( tfp.run());
00077
00078 PropertyReadingContainer pc ( "config", tpg.get() );
00079
00080 runTextIO( pc );
00081 }
00082
00083 void CGameOptions::save( const ASCString& filename )
00084 {
00085 tn_file_buf_stream s ( filename, tnstream::writing );
00086 PropertyWritingContainer pc ( "config", s );
00087 runTextIO( pc );
00088 }
00089
00090
00091
00092 void CGameOptions::runTextIO ( PropertyContainer& pc )
00093 {
00094
00095 pc.addInteger("XResolution", xresolution, xresolution);
00096 pc.addInteger("YResolution", yresolution, yresolution);
00097 pc.addString("GraphicsDriver", graphicsDriver, graphicsDriver );
00098 pc.addBool("HardwareSurface", hardwareSurface, hardwareSurface );
00099
00100 pc.addInteger("MapEditor_XResolution", mapeditor_xresolution, mapeditor_xresolution);
00101 pc.addInteger("MapEditor_YResolution", mapeditor_yresolution, mapeditor_yresolution);
00102
00103 pc.openBracket("Sound");
00104 pc.addBool("MuteEffects", sound.muteEffects, sound.muteEffects);
00105 pc.addBool("MuteMusic", sound.muteMusic, sound.muteMusic);
00106 pc.addBool("Sound.Off", sound.off, sound.off);
00107 pc.addInteger("EffectsVolume", sound.soundVolume, sound.soundVolume );
00108 pc.addInteger("MusicVolume", sound.musicVolume, sound.musicVolume );
00109 pc.closeBracket();
00110
00111 pc.addBool("FastMove", fastmove, fastmove);
00112 pc.addInteger("MovementSpeed", movespeed, movespeed );
00113 pc.addBool("EndTurnPrompt", endturnquestion, endturnquestion );
00114 pc.addBool("UnitsGrayAfterMove", units_gray_after_move, units_gray_after_move );
00115 pc.addInteger( "MapZoom", mapzoom, mapzoom);
00116 pc.addInteger( "MapZoomEditor", mapzoomeditor, mapzoomeditor );
00117 pc.addInteger( "AttackSpeed1", attackspeed1, 30 );
00118 pc.addInteger( "AttackSpeed2", attackspeed2, 50 );
00119 pc.addInteger( "AttackSpeed3", attackspeed3, 30 );
00120
00121 pc.addBool( "ForceWindowedMode", forceWindowedMode, forceWindowedMode );
00122 pc.addBool( "MapeditWindowedMode", mapeditWindowedMode, mapeditWindowedMode );
00123 pc.addBool( "MapeditModalSelectionWindow", maped_modalSelectionWindow, maped_modalSelectionWindow );
00124 pc.addBool( "AutomaticTraining", automaticTraining, automaticTraining );
00125
00126 pc.openBracket("Mouse");
00127
00128 pc.addNamedInteger("SelectFieldButton", mouse.fieldmarkbutton, mouseButtonNum, mouseButtons, mouse.fieldmarkbutton );
00129
00130
00131
00132 pc.addNamedInteger("MapCenterButton", mouse.centerbutton, mouseButtonNum, mouseButtons, mouse.centerbutton );
00133 pc.addNamedInteger("DragNdrop", mouse.dragndropbutton, mouseButtonNum, mouseButtons, mouse.dragndropbutton );
00134 pc.addNamedInteger("ZoomOut", mouse.zoomoutbutton, mouseButtonNum, mouseButtons, mouse.zoomoutbutton );
00135 pc.addNamedInteger("ZoomIn", mouse.zoominbutton, mouseButtonNum, mouseButtons, mouse.zoominbutton );
00136
00137 pc.addBool("SingleClickAction", mouse.singleClickAction, false );
00138
00139 pc.addBool("HideOnScreenUpdates",hideMouseOnScreenUpdates, hideMouseOnScreenUpdates );
00140 pc.closeBracket();
00141
00142 pc.addBool("AmmoProductionOnRefuelling", autoproduceammunition, autoproduceammunition );
00143
00144
00145
00146
00147 pc.addString("DefaultPassword", defaultPassword, defaultPassword );
00148 pc.addString("DefaultSupervisorPassword", defaultSuperVisorPassword, defaultSuperVisorPassword );
00149 pc.addInteger("ReplayDelay", replayspeed, replayspeed );
00150
00151 pc.addString("StartupMap", startupMap, startupMap );
00152 pc.addBool("DebugReplay", debugReplay, debugReplay );
00153
00154 pc.addString("BI3.path", BI3directory, BI3directory );
00155
00156 pc.openBracket("UnitProduction");
00157 pc.addBool("fillResources", unitProduction.fillResources, true );
00158 pc.addBool("fillAmmo", unitProduction.fillAmmo, true );
00159 pc.closeBracket();
00160
00161 pc.openBracket("replayVideo");
00162 pc.addInteger("FrameRate", video.framerate, video.framerate );
00163 pc.addInteger("Quality", video.quality, video.quality);
00164 pc.closeBracket();
00165
00166 if ( !pc.isReading() || pc.find("VisibleMapLayer" ))
00167 pc.addStringArray("VisibleMapLayer", visibleMapLayer );
00168
00169
00170 pc.openBracket("PBEMServer");
00171 pc.addString("hostname", pbemServer.hostname, pbemServer.hostname );
00172 pc.addString("username", pbemServer.username, pbemServer.username );
00173 pc.addInteger("port", pbemServer.port, pbemServer.port );
00174 pc.closeBracket();
00175
00176
00177
00178
00179
00180
00181
00182
00183 int spn = 0;
00184
00185 if ( pc.isReading() )
00186 pc.addInteger("SearchPathNum", spn, 0 );
00187 else {
00188 pc.addInteger("SearchPathNum", searchPathNum, 0 );
00189 spn = searchPathNum;
00190 }
00191
00192
00193 for ( int i = 0; i < min(spn, 30); ++i )
00194 pc.addString(ASCString("SearchPath") + strrr(i), searchPath[i] );
00195
00196 searchPathNum = spn;
00197
00198
00199 pc.addBool( "cacheASCGUI", cacheASCGUI, cacheASCGUI );
00200
00201
00202 vector<ASCString> panels;
00203 if ( pc.isReading() ) {
00204 if ( pc.find( "Panels"))
00205 pc.addStringArray( "Panels", panels );
00206 } else {
00207 for ( PanelDataContainer::iterator i = panelData.begin(); i != panelData.end(); ++i )
00208 panels.push_back( i->first );
00209 pc.addStringArray( "Panels", panels );
00210 }
00211
00212 for ( vector<ASCString>::iterator i = panels.begin(); i != panels.end(); ++i ){
00213 PanelData& pd = panelData[*i];
00214 pc.openBracket( *i );
00215 pc.addInteger( "x", pd.x );
00216 pc.addInteger( "y", pd.y );
00217 pc.addBool( "active", pd.visible );
00218 pc.closeBracket();
00219 }
00220
00221 pc.addInteger( "PanelColumns", panelColumns, 2 );
00222
00223 pc.addString("mailProgram", mailProgram, "");
00224
00225 }
00226
00227 CGameOptions::CGameOptions()
00228 {
00229 setDefaults();
00230 }
00231
00232
00233 void CGameOptions::setDefaults ( void )
00234 {
00235 hideMouseOnScreenUpdates = true;
00236 forceWindowedMode = false;
00237 mapeditWindowedMode = true;
00238 maped_modalSelectionWindow = true;
00239 fastmove = true;
00240 movespeed=15;
00241 endturnquestion=false;
00242
00243 units_gray_after_move=false;
00244 mapzoom=75;
00245 mapzoomeditor=60;
00246
00247
00248
00249 attackspeed1=30;
00250 attackspeed2=50;
00251 attackspeed3=30;
00252
00253 sound.off=false;
00254 sound.muteEffects=false;
00255 sound.muteMusic=false;
00256 sound.soundVolume=100;
00257 sound.musicVolume=100;
00258
00259
00260 mouse.fieldmarkbutton=1;
00261
00262
00263
00264 mouse.centerbutton=2;
00265 mouse.dragndropbutton = 3;
00266 mouse.zoomoutbutton = 4;
00267 mouse.zoominbutton = 5;
00268 mouse.singleClickAction = false;
00269
00270 replayspeed=0;
00271 debugReplay = 0;
00272
00273 autoproduceammunition = false;
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 startupMap = "asc001.map";
00284
00285 cacheASCGUI = true;
00286
00287 setDefaultDirectories();
00288
00289 xresolution = 1024;
00290 yresolution = 768;
00291
00292 mapeditor_xresolution = 1024;
00293 mapeditor_yresolution = 740;
00294
00295 graphicsDriver = "default";
00296 hardwareSurface = false;
00297
00298 automaticTraining = true;
00299
00300 replayMovieMode = false;
00301
00302 unitProduction.fillAmmo = true;
00303 unitProduction.fillResources = true;
00304
00305 video.quality = 100;
00306 video.framerate = 15;
00307
00308 panelColumns = 2;
00309
00310 pbemServer.username="";
00311 pbemServer.port = 8080;
00312 pbemServer.hostname="terdon.asc-hq.org";
00313
00314 setChanged();
00315 }
00316
00317
00318 void CGameOptions::setDefaultDirectories()
00319 {
00320 #if USE_HOME_DIRECTORY == 0
00321
00322 searchPathNum = 1;
00323 searchPath[0] = ".\\" ;
00324 #else
00325
00326 searchPathNum = 6;
00327
00328 searchPath[0] = "~/.asc/" ;
00329 searchPath[1] = GAME_DATADIR ;
00330 searchPath[2] = "/var/local/games/asc/" ;
00331 searchPath[3] = "/var/games/asc/" ;
00332 searchPath[4] = "/usr/local/share/games/asc/" ;
00333 searchPath[5] = "/usr/share/games/asc/" ;
00334 #endif
00335
00336 }
00337
00338 ASCString CGameOptions::Mouse::getButtonName(int button)
00339 {
00340 static const char* my_mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
00341 if ( button <= 3 )
00342 return my_mouseButtonNames[button];
00343 else
00344 return ASCString::toString( button );
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 int CGameOptions :: getSearchPathNum ( void )
00409 {
00410 return searchPathNum;
00411 }
00412
00413 void CGameOptions :: setSearchPath ( int i, const ASCString& path )
00414 {
00415 searchPath[i] = path;
00416 }
00417
00418 void CGameOptions :: addSearchPath ( const ASCString& path )
00419 {
00420 setSearchPath( searchPathNum++, path );
00421 }
00422
00423 ASCString CGameOptions :: getSearchPath( int i)
00424 {
00425 return searchPath[i];
00426 }
00427
00428
00429
00430 Password CGameOptions :: getDefaultPassword ( )
00431 {
00432 Password pwd;
00433 if ( !defaultPassword.empty() )
00434 pwd.setEncoded ( defaultPassword );
00435
00436 return pwd;
00437 }
00438
00439
00440 Password CGameOptions :: getDefaultSupervisorPassword ( )
00441 {
00442 Password pwd;
00443 if ( !defaultSuperVisorPassword.empty() )
00444 pwd.setEncoded ( defaultSuperVisorPassword );
00445
00446 return pwd;
00447 }
00448
00449 void CGameOptions :: updatePanelData( const ASCString& name, PanelData data )
00450 {
00451 panelData[name] = data;
00452 setChanged();
00453 }
00454
00455 bool CGameOptions :: getPanelData( const ASCString& name, PanelData& data )
00456 {
00457 if ( panelData.find( name ) != panelData.end() ) {
00458 data = panelData[name];
00459 return true;
00460 } else
00461 return false;
00462 }
00463