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
00042
00043 class GetVideoModes {
00044 public:
00045 typedef vector<ASCString> VList;
00046 private:
00047 SDL_Rect **modes;
00048 VList list;
00049
00050 vector <pair<int,int> > listedmodes;
00051
00052 public:
00053 GetVideoModes() {
00054 int i;
00055
00056
00057 SDL_PixelFormat format;
00058 format.palette = NULL;
00059 format.BitsPerPixel = 32;
00060 format.BytesPerPixel = 4;
00061 format.Rloss = format.Gloss = format.Bloss = format.Aloss = 0;
00062 format.Rshift = 0;
00063 format.Gshift = 8;
00064 format.Bshift = 16;
00065 format.Ashift = 24;
00066 format.Rmask = 0xff;
00067 format.Gmask = 0xff00;
00068 format.Bmask = 0xff0000;
00069 format.Amask = 0xff000000;
00070 format.colorkey = 0;
00071 format.alpha = 0;
00072
00073
00074
00075 modes=SDL_ListModes(&format, SDL_FULLSCREEN);
00076
00077
00078 list.push_back( "graphic mode not listed");
00079 listedmodes.push_back( make_pair( 0, 0));
00080
00081
00082 if(modes == (SDL_Rect **)0){
00083 return;
00084 }
00085
00086
00087 if(modes == (SDL_Rect **)-1){
00088 warning("All resolutions available.\n");
00089 return;
00090 }
00091 else{
00092 for(i=0;modes[i];++i) {
00093
00094 if ( find ( listedmodes.begin(), listedmodes.end(), make_pair( int(modes[i]->w), int(modes[i]->h ))) != listedmodes.end() )
00095 continue;
00096
00097 if ( modes[i]->w >= 800 && modes[i]->h >= 600 ) {
00098 ASCString s;
00099 s.format( "%d*%d", modes[i]->w, modes[i]->h );
00100 list.push_back ( s );
00101 listedmodes.push_back( make_pair( int(modes[i]->w), int(modes[i]->h )));
00102 }
00103 }
00104
00105 }
00106 return;
00107 };
00108
00109 VList& getList() { return list; };
00110
00111 int getx( int index ) {
00112 return listedmodes.at(index).first;
00113 };
00114
00115 int gety( int index ) {
00116 return listedmodes.at(index).second;
00117 };
00118
00119 int findmodenum( int x, int y ) {
00120 for ( int j = 0; j < listedmodes.size(); ++j )
00121 if ( listedmodes[j].first == x && listedmodes[j].second == y )
00122 return j;
00123 return 0;
00124 }
00125
00126 };
00127
00128
00129
00130
00131 const char* mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
00132
00133 const char* infoPanelNames[] = { "None", "Left (not recommended)", "Right", "Left+Right", NULL };
00134
00135 class EditGameOptions : public ASC_PG_Dialog {
00136 private:
00137 PG_PropertyEditor* propertyEditor;
00138
00139 GetVideoModes vmodes;
00140 ASCString defaultPassword;
00141
00142 int videoMode;
00143 bool ascmain;
00144
00145 bool ok()
00146 {
00147 if ( propertyEditor->Apply() ) {
00148
00149 int x = vmodes.getx( videoMode );
00150 int y = vmodes.gety( videoMode );
00151
00152 bool warn = false;
00153 bool fullscreen;
00154
00155
00156 if ( ascmain ) {
00157 if ( (x != CGameOptions::Instance()->xresolution || y != CGameOptions::Instance()->yresolution) && x && y ) {
00158 warn = true;
00159 CGameOptions::Instance()->xresolution = x;
00160 CGameOptions::Instance()->yresolution = y;
00161 }
00162
00163 fullscreen = !CGameOptions::Instance()->forceWindowedMode;
00164
00165 } else {
00166 if ( (x != CGameOptions::Instance()->mapeditor_xresolution || y != CGameOptions::Instance()->mapeditor_yresolution) && x && y ) {
00167 warn = true;
00168 CGameOptions::Instance()->mapeditor_xresolution = x;
00169 CGameOptions::Instance()->mapeditor_yresolution = y;
00170 }
00171 fullscreen = !CGameOptions::Instance()->mapeditWindowedMode;
00172 }
00173
00174 if ( warn )
00175 infoMessage( "The new graphic settings will be active after you restart ASC");
00176
00177 if ( getPGApplication().isFullscreen() != fullscreen )
00178 getPGApplication().toggleFullscreen();
00179
00180
00181 CGameOptions::Instance()->setChanged();
00182 if ( !defaultPassword.empty() && defaultPassword.find_first_not_of('*') != ASCString::npos ) {
00183 Password p;
00184 p.setUnencoded ( defaultPassword );
00185 CGameOptions::Instance()->defaultPassword = p.toString();
00186 }
00187
00188 quitModalLoop(0);
00189
00190 return true;
00191 } else
00192 return false;
00193 }
00194
00195 public:
00196 EditGameOptions( PG_Widget* parent, bool mainApp ) : ASC_PG_Dialog( parent, PG_Rect( 50, 50, 500, 550 ), "Edit Map Parameters"), videoMode(0), ascmain( mainApp )
00197 {
00198 CGameOptions* o = CGameOptions::Instance();
00199
00200 if ( !o->defaultPassword.empty() )
00201 defaultPassword = "******";
00202
00203
00204 if ( mainApp )
00205 videoMode = vmodes.findmodenum( CGameOptions::Instance()->xresolution, CGameOptions::Instance()->yresolution );
00206 else
00207 videoMode = vmodes.findmodenum( CGameOptions::Instance()->mapeditor_xresolution, CGameOptions::Instance()->mapeditor_yresolution );
00208
00209 propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight(), Width() - 20, Height() - GetTitlebarHeight() - 50 ), "PropertyEditor", 70 );
00210
00211 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Direct Movement", &o->fastmove );
00212 new PG_PropertyField_Integer<int>( propertyEditor , "Movement Speed (1/100 sec)", &o->movespeed );
00213 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Confirm EndOfTurn", &o->endturnquestion );
00214 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Units shaded after movement", &o->units_gray_after_move );
00215 new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog PreWait (1/100 sec)", &o->attackspeed1 );
00216 new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog Animate (1/100 sec)", &o->attackspeed2 );
00217 new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog PostWait 3 (1/100 sec)", &o->attackspeed3 );
00218 if ( mainApp ) {
00219 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Game running Fullscreen", &o->forceWindowedMode, true );
00220 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Produce Ammo when refuelling", &o->autoproduceammunition );
00221 new PG_PropertyField_IntDropDown<int>( propertyEditor, "InfoPanels", &o->panelColumns, infoPanelNames );
00222 } else {
00223 new PG_PropertyField_Checkbox<bool>( propertyEditor, "MapEd running Fullscreen", &o->mapeditWindowedMode, true );
00224 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Modal Selection Window", &o->maped_modalSelectionWindow );
00225 }
00226
00227 #ifdef WIN32
00228 static const char* graphicDrivers[] = { "default", "windib", "directx", NULL };
00229 new PG_PropertyField_DropDown<ASCString>( propertyEditor , "Graphics backend", &o->graphicsDriver, graphicDrivers );
00230 #endif
00231
00232
00233
00234 new PG_PropertyField_IntDropDown<int, GetVideoModes::VList::iterator>( propertyEditor, "Video Mode", &videoMode, vmodes.getList().begin(), vmodes.getList().end() );
00235
00236 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Automatic Training", &o->automaticTraining );
00237
00238 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Field Select", &o->mouse.fieldmarkbutton, mouseButtonNames );
00239 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Center View", &o->mouse.centerbutton, mouseButtonNames );
00240 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Drag'N'Drop", &o->mouse.dragndropbutton, mouseButtonNames );
00241 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Zoom Out", &o->mouse.zoomoutbutton, mouseButtonNames );
00242 new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Zoom In", &o->mouse.zoominbutton, mouseButtonNames );
00243 if ( mainApp )
00244 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Single click action", &o->mouse.singleClickAction );
00245
00246
00247 if ( !mainApp )
00248 new PG_PropertyField_String<ASCString>( propertyEditor , "BI3 directory", &o->BI3directory );
00249
00250 if ( mainApp )
00251 new PG_PropertyField_String<ASCString>( propertyEditor , "Startup Map", &o->startupMap );
00252
00253
00254 (new PG_PropertyField_String<ASCString>( propertyEditor , "Default Password", &defaultPassword ))->SetPassHidden('*');
00255
00256 new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: Cache GUI Definition (*.ascgui)", &o->cacheASCGUI );
00257 new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: View own replay", &o->debugReplay );
00258
00259 if ( mainApp ) {
00260 new PG_PropertyField_Checkbox<bool>( propertyEditor, "Replays as Movies (not saved)", &o->replayMovieMode );
00261
00262 new PG_PropertyField_String<ASCString>( propertyEditor, "PBEM server hostname", &o->pbemServer.hostname );
00263 new PG_PropertyField_String<ASCString>( propertyEditor, "PBEM server username", &o->pbemServer.username );
00264 new PG_PropertyField_Integer<int>( propertyEditor, "PBEM server port", &o->pbemServer.port);
00265 }
00266
00267
00268
00269 PG_Button* ok = new PG_Button( this, PG_Rect( Width() - 100, Height() - 40, 90, 30), "OK" );
00270 ok->sigClick.connect( SigC::slot( *this, &EditGameOptions::ok ));
00271 };
00272
00273 };
00274
00275
00276 void editGameOptions ( bool mainApp )
00277 {
00278 try {
00279 EditGameOptions ego ( NULL, mainApp );
00280 ego.Show();
00281 ego.RunModal();
00282 }
00283 catch ( ... ) {
00284 errorMessage( "An exception was caught" );
00285 }
00286 }