00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <sstream>
00022 #include <pgimage.h>
00023
00024 #include <pgpropertyeditor.h>
00025 #include <pgpropertyfield_integer.h>
00026 #include <pgpropertyfield_intdropdown.h>
00027 #include <pgpropertyfield_dropdown.h>
00028 #include <pgpropertyfield_checkbox.h>
00029 #include <pgpropertyfield_string.h>
00030
00031
00032 #include "selectionwindow.h"
00033 #include "sigc++/retype.h"
00034 #include "editmapparam.h"
00035 #include "fileselector.h"
00036 #include "../ascstring.h"
00037
00038 #include "../textfileparser.h"
00039 #include "../textfile_evaluation.h"
00040
00041 #include "editgameoptions.h"
00042
00043
00044 bool GetVideoModes::comparator( const ModeRes& a, const ModeRes& b )
00045 {
00046 if ( a.first == 0 )
00047 return true;
00048
00049 if ( b.first == 0 )
00050 return false;
00051
00052 if ( a.first > b.first ) {
00053 return true;
00054 } else {
00055 if ( a.first < b.first )
00056 return false;
00057 else {
00058 if ( a.second > b.second )
00059 return true;
00060 else {
00061 return false;
00062 }
00063 }
00064
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 GetVideoModes::GetVideoModes()
00092 {
00093 int i;
00094
00095
00096 SDL_PixelFormat format;
00097 format.palette = NULL;
00098 format.BitsPerPixel = 32;
00099 format.BytesPerPixel = 4;
00100 format.Rloss = format.Gloss = format.Bloss = format.Aloss = 0;
00101 format.Rshift = 0;
00102 format.Gshift = 8;
00103 format.Bshift = 16;
00104 format.Ashift = 24;
00105 format.Rmask = 0xff;
00106 format.Gmask = 0xff00;
00107 format.Bmask = 0xff0000;
00108 format.Amask = 0xff000000;
00109 format.colorkey = 0;
00110 format.alpha = 0;
00111
00112
00113
00114 modes=SDL_ListModes(&format, SDL_FULLSCREEN);
00115
00116
00117 listedmodes.push_back( make_pair( 0, 0));
00118
00119
00120 if(modes == (SDL_Rect **)0){
00121 return;
00122 }
00123
00124
00125 if(modes == (SDL_Rect **)-1){
00126 warningMessage("All resolutions available.\n");
00127 return;
00128 }
00129 else{
00130 for(i=0;modes[i];++i) {
00131
00132 if ( find ( listedmodes.begin(), listedmodes.end(), make_pair( int(modes[i]->w), int(modes[i]->h ))) != listedmodes.end() )
00133 continue;
00134
00135 if ( modes[i]->w >= 800 && modes[i]->h >= 600 ) {
00136 listedmodes.push_back( make_pair( int(modes[i]->w), int(modes[i]->h )));
00137 }
00138 }
00139 sort ( listedmodes.begin(), listedmodes.end(), &GetVideoModes::comparator );
00140
00141 for ( vector <ModeRes > ::iterator i = listedmodes.begin(); i != listedmodes.end(); ++i ) {
00142 ASCString s;
00143 if ( i->first )
00144 s.format( "%d*%d", i->first, i->second );
00145 else
00146 s = "graphic mode not listed";
00147
00148 list.push_back ( s );
00149 }
00150
00151 }
00152 return;
00153 };
00154
00155 int GetVideoModes::getx( int index ) {
00156 return listedmodes.at(index).first;
00157 };
00158
00159 int GetVideoModes::gety( int index ) {
00160 return listedmodes.at(index).second;
00161 };
00162
00163 int GetVideoModes::findmodenum( int x, int y ) {
00164 for ( int j = 0; j < listedmodes.size(); ++j )
00165 if ( listedmodes[j].first == x && listedmodes[j].second == y )
00166 return j;
00167 return 0;
00168 }
00169
00170
00171 GetVideoModes::ModeRes GetVideoModes::getBest()
00172 {
00173 ModeRes res = make_pair(-1,-1);
00174
00175 for ( int j = 0; j < listedmodes.size(); ++j )
00176 if ( listedmodes[j].first >= res.first && listedmodes[j].second >= res.second )
00177 res = listedmodes[j];
00178
00179 return res;
00180 }
00181
00182
00183
00184 const char* mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
00185
00186 const char* infoPanelNames[] = { "None", "Left (not recommended)", "Right", "Left+Right", NULL };
00187
00188 class EditGameOptions : public ASC_PG_Dialog {
00189 private:
00190 PG_PropertyEditor* propertyEditor;
00191
00192 GetVideoModes vmodes;
00193 ASCString defaultPassword;
00194
00195 int videoMode;
00196 bool ascmain;
00197
00198 bool ok()
00199 {
00200 if ( propertyEditor->Apply() ) {
00201
00202 int x = vmodes.getx( videoMode );
00203 int y = vmodes.gety( videoMode );
00204
00205 bool warn = false;
00206 bool fullscreen;
00207
00208
00209 if ( ascmain ) {
00210 if ( (x != CGameOptions::Instance()->xresolution || y != CGameOptions::Instance()->yresolution) && x && y ) {
00211 warn = true;
00212 CGameOptions::Instance()->xresolution = x;
00213 CGameOptions::Instance()->yresolution = y;
00214 }
00215
00216 fullscreen = !CGameOptions::Instance()->forceWindowedMode;
00217
00218 } else {
00219 if ( (x != CGameOptions::Instance()->mapeditor_xresolution || y != CGameOptions::Instance()->mapeditor_yresolution) && x && y ) {
00220 warn = true;
00221 CGameOptions::Instance()->mapeditor_xresolution = x;
00222 CGameOptions::Instance()->mapeditor_yresolution = y;
00223 }
00224 fullscreen = !CGameOptions::Instance()->mapeditWindowedMode;
00225 }
00226
00227 if ( warn )
00228 infoMessage( "The new graphic settings will be active after you restart ASC");
00229
00230 if ( getPGApplication().isFullscreen() != fullscreen )
00231 getPGApplication().toggleFullscreen();
00232
00233
00234 CGameOptions::Instance()->setChanged();
00235 if ( !defaultPassword.empty() && defaultPassword.find_first_not_of('*') != ASCString::npos ) {
00236 Password p;
00237 p.setUnencoded ( defaultPassword );
00238 CGameOptions::Instance()->defaultPassword = p.toString();
00239 }
00240
00241 quitModalLoop(0);
00242
00243 return true;
00244 } else
00245 return false;
00246 }
00247
00248 public:
00249 EditGameOptions( PG_Widget* parent, bool mainApp ) : ASC_PG_Dialog( parent, PG_Rect( 50, 50, 500, 550 ), "Edit Map Parameters"), videoMode(0), ascmain( mainApp )
00250 {
00251 CGameOptions* o = CGameOptions::Instance();
00252
00253 if ( !o->defaultPassword.empty() )
00254 defaultPassword = "******";
00255
00256
00257 if ( mainApp )
00258 videoMode = vmodes.findmodenum( CGameOptions::Instance()->xresolution, CGameOptions::Instance()->yresolution );
00259 else
00260 videoMode = vmodes.findmodenum( CGameOptions::Instance()->mapeditor_xresolution, CGameOptions::Instance()->mapeditor_yresolution );
00261
00262 propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight(), Width() - 20, Height() - GetTitlebarHeight() - 50 ), "PropertyEditor", 70 );
00263
00264 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Direct Movement", &o->fastmove );
00265 new PG_PropertyField_Integer<int>( propertyEditor , "Movement Speed (1/100 sec)", &o->movespeed );
00266 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Confirm EndOfTurn", &o->endturnquestion );
00267 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Units shaded after movement", &o->units_gray_after_move );
00268 new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog PreWait (1/100 sec)", &o->attackspeed1 );
00269 new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog Animate (1/100 sec)", &o->attackspeed2 );
00270 new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog PostWait 3 (1/100 sec)", &o->attackspeed3 );
00271 if ( mainApp ) {
00272 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Game running Fullscreen", &o->forceWindowedMode, true );
00273 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Produce Ammo when refuelling", &o->autoproduceammunition );
00274 new PG_PropertyField_IntDropDown<int>( propertyEditor, "InfoPanels", &o->panelColumns, infoPanelNames );
00275 new PG_PropertyField_Integer<int>( propertyEditor, "Aircraft Crash Warning Time", &o->aircraftCrashWarningTime );
00276 } else {
00277 new PG_PropertyField_Checkbox<bool>( propertyEditor, "MapEd running Fullscreen", &o->mapeditWindowedMode, true );
00278 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Modal Selection Window", &o->maped_modalSelectionWindow );
00279 }
00280
00281 #ifdef WIN32
00282 static const char* graphicDrivers[] = { "default", "windib", "directx", NULL };
00283 new PG_PropertyField_DropDown<ASCString>( propertyEditor , "Graphics backend", &o->graphicsDriver, graphicDrivers );
00284 #endif
00285
00286
00287
00288 new PG_PropertyField_IntDropDown<int, GetVideoModes::VList::iterator>( propertyEditor, "Video Mode", &videoMode, vmodes.getList().begin(), vmodes.getList().end() );
00289
00290 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Automatic Training", &o->automaticTraining );
00291
00292 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Field Select", &o->mouse.fieldmarkbutton, mouseButtonNames );
00293 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Center View", &o->mouse.centerbutton, mouseButtonNames );
00294 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Drag'N'Drop", &o->mouse.dragndropbutton, mouseButtonNames );
00295 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Zoom Out", &o->mouse.zoomoutbutton, mouseButtonNames );
00296 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Zoom In", &o->mouse.zoominbutton, mouseButtonNames );
00297 if ( mainApp )
00298 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Single click action", &o->mouse.singleClickAction );
00299
00300
00301 if ( !mainApp )
00302 new PG_PropertyField_String<ASCString>( propertyEditor , "BI3 directory", &o->BI3directory );
00303
00304 if ( mainApp )
00305 new PG_PropertyField_String<ASCString>( propertyEditor , "Startup Map", &o->startupMap );
00306
00307
00308 (new PG_PropertyField_String<ASCString>( propertyEditor , "Default Password", &defaultPassword ))->SetPassHidden('*');
00309
00310 new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: Cache GUI Definition (*.ascgui)", &o->cacheASCGUI );
00311 new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: View own replay", &o->debugReplay );
00312
00313 if ( mainApp ) {
00314 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Replays as Movies (not saved)", &o->replayMovieMode );
00315
00316 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Record Campaign Map solutions", &o->recordCampaignMaps );
00317
00318 new PG_PropertyField_String<ASCString>( propertyEditor, "PBEM server hostname", &o->pbemServer.hostname );
00319 new PG_PropertyField_String<ASCString>( propertyEditor, "PBEM server username", &o->pbemServer.username );
00320 new PG_PropertyField_Integer<int>( propertyEditor, "PBEM server port", &o->pbemServer.port);
00321
00322 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Log kills to console", &o->logKillsToConsole );
00323 }
00324
00325 (new PG_PropertyField_String<ASCString>( propertyEditor , "Language Override", &o->languageOverride ));
00326
00327 if ( !mainApp )
00328 new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: Save event message seperately", &o->saveEventMessagesExternal );
00329
00330
00331 PG_Button* ok = new PG_Button( this, PG_Rect( Width() - 100, Height() - 40, 90, 30), "OK" );
00332 ok->sigClick.connect( SigC::slot( *this, &EditGameOptions::ok ));
00333 };
00334
00335 };
00336
00337
00338 void editGameOptions ( bool mainApp )
00339 {
00340 try {
00341 EditGameOptions ego ( NULL, mainApp );
00342 ego.Show();
00343 ego.RunModal();
00344 }
00345 catch ( ... ) {
00346 errorMessage( "An exception was caught" );
00347 }
00348 }