Advanced Strategic Command
editgameoptions.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include <sstream>
22 #include <pgimage.h>
23 
24 #include <pgpropertyeditor.h>
25 #include <pgpropertyfield_integer.h>
26 #include <pgpropertyfield_intdropdown.h>
27 #include <pgpropertyfield_dropdown.h>
28 #include <pgpropertyfield_checkbox.h>
29 #include <pgpropertyfield_string.h>
30 
31 
32 #include "selectionwindow.h"
33 #include "sigc++/adaptors/retype.h"
34 #include "editmapparam.h"
35 #include "fileselector.h"
36 #include "../ascstring.h"
37 
38 #include "../textfileparser.h"
39 #include "../textfile_evaluation.h"
40 
41 #include "editgameoptions.h"
42 
43 
44 bool GetVideoModes::comparator( const ModeRes& a, const ModeRes& b )
45 {
46  if ( a.first == 0 )
47  return true;
48 
49  if ( b.first == 0 )
50  return false;
51 
52  if ( a.first > b.first ) {
53  return true;
54  } else {
55  if ( a.first < b.first )
56  return false;
57  else {
58  if ( a.second > b.second )
59  return true;
60  else {
61  return false;
62  }
63  }
64 
65  }
66 }
67 
68 /*
69 bool GetVideoModes::comparator( const ModeRes& a, const ModeRes& b )
70 {
71  if ( a.first > b.first ) {
72  return 1;
73  } else {
74  if ( a.first < b.first )
75  return -1;
76  else {
77  if ( a.second > b.second )
78  return 1;
79  else {
80  if ( a.second < b.second )
81  return -1;
82  else
83  return 0;
84  }
85  }
86 
87  }
88 }
89 */
90 
92 {
93  int i;
94 
95 
96  SDL_PixelFormat format;
97  format.palette = NULL;
98  format.BitsPerPixel = 32;
99  format.BytesPerPixel = 4;
100  format.Rloss = format.Gloss = format.Bloss = format.Aloss = 0;
101  format.Rshift = 0;
102  format.Gshift = 8;
103  format.Bshift = 16;
104  format.Ashift = 24;
105  format.Rmask = 0xff;
106  format.Gmask = 0xff00;
107  format.Bmask = 0xff0000;
108  format.Amask = 0xff000000;
109  format.colorkey = 0;
110  format.alpha = 0;
111 
112 
113  /* Get available fullscreen/hardware modes */
114  modes=SDL_ListModes(&format, SDL_FULLSCREEN);
115 
116 
117  listedmodes.push_back( make_pair( 0, 0));
118 
119  /* Check is there are any modes available */
120  if(modes == (SDL_Rect **)0){
121  return;
122  }
123 
124  /* Check if our resolution is restricted */
125  if(modes == (SDL_Rect **)-1){
126  warningMessage("All resolutions available.\n");
127  return;
128  }
129  else{
130  for(i=0;modes[i];++i) {
131 
132  if ( find ( listedmodes.begin(), listedmodes.end(), make_pair( int(modes[i]->w), int(modes[i]->h ))) != listedmodes.end() )
133  continue;
134 
135  if ( modes[i]->w >= 800 && modes[i]->h >= 600 ) {
136  listedmodes.push_back( make_pair( int(modes[i]->w), int(modes[i]->h )));
137  }
138  }
139  sort ( listedmodes.begin(), listedmodes.end(), &GetVideoModes::comparator );
140 
141  for ( vector <ModeRes > ::iterator i = listedmodes.begin(); i != listedmodes.end(); ++i ) {
142  ASCString s;
143  if ( i->first )
144  s.format( "%d*%d", i->first, i->second );
145  else
146  s = "graphic mode not listed";
147 
148  list.push_back ( s );
149  }
150 
151  }
152  return;
153 };
154 
155 int GetVideoModes::getx( int index ) {
156  return listedmodes.at(index).first;
157 };
158 
159 int GetVideoModes::gety( int index ) {
160  return listedmodes.at(index).second;
161 };
162 
163 int GetVideoModes::findmodenum( int x, int y ) {
164  for ( int j = 0; j < listedmodes.size(); ++j )
165  if ( listedmodes[j].first == x && listedmodes[j].second == y )
166  return j;
167  return 0;
168 }
169 
170 
172 {
173  ModeRes res = make_pair(-1,-1);
174 
175  for ( int j = 0; j < listedmodes.size(); ++j )
176  if ( listedmodes[j].first >= res.first && listedmodes[j].second >= res.second )
177  res = listedmodes[j];
178 
179  return res;
180 }
181 
182 
183 
184 const char* mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
185 
186 const char* infoPanelNames[] = { "None", "Left (not recommended)", "Right", "Left+Right", NULL };
187 
189  private:
190  PG_PropertyEditor* propertyEditor;
191 
192  GetVideoModes vmodes;
193  ASCString defaultPassword;
194 
195  int videoMode;
196  bool ascmain;
197 
198  bool ok()
199  {
200  if ( propertyEditor->Apply() ) {
201 
202  int x = vmodes.getx( videoMode );
203  int y = vmodes.gety( videoMode );
204 
205  bool warn = false;
206  bool fullscreen;
207 
208 
209  if ( ascmain ) {
210  if ( (x != CGameOptions::Instance()->xresolution || y != CGameOptions::Instance()->yresolution) && x && y ) {
211  warn = true;
214  }
215 
216  fullscreen = !CGameOptions::Instance()->forceWindowedMode;
217 
218  } else {
219  if ( (x != CGameOptions::Instance()->mapeditor_xresolution || y != CGameOptions::Instance()->mapeditor_yresolution) && x && y ) {
220  warn = true;
223  }
225  }
226 
227  if ( warn )
228  infoMessage( "The new graphic settings will be active after you restart ASC");
229 
230  if ( getPGApplication().isFullscreen() != fullscreen )
232 
233 
235  if ( !defaultPassword.empty() && defaultPassword.find_first_not_of('*') != ASCString::npos ) {
236  Password p;
237  p.setUnencoded ( defaultPassword );
239  }
240 
241  quitModalLoop(0);
242 
243  return true;
244  } else
245  return false;
246  }
247 
248  public:
249  EditGameOptions( PG_Widget* parent, bool mainApp ) : ASC_PG_Dialog( parent, PG_Rect( 50, 50, 500, 550 ), "Edit Map Parameters"), videoMode(0), ascmain( mainApp )
250  {
252 
253  if ( !o->defaultPassword.empty() )
254  defaultPassword = "******";
255 
256 
257  if ( mainApp )
258  videoMode = vmodes.findmodenum( CGameOptions::Instance()->xresolution, CGameOptions::Instance()->yresolution );
259  else
260  videoMode = vmodes.findmodenum( CGameOptions::Instance()->mapeditor_xresolution, CGameOptions::Instance()->mapeditor_yresolution );
261 
262  propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight(), Width() - 20, Height() - GetTitlebarHeight() - 50 ), "PropertyEditor", 70 );
263 
264  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Direct Movement", &o->fastmove );
265  new PG_PropertyField_Integer<int>( propertyEditor , "Movement Speed (1/100 sec)", &o->movespeed );
266  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Confirm EndOfTurn", &o->endturnquestion );
267  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Units shaded after movement", &o->units_gray_after_move );
268  new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog PreWait (1/100 sec)", &o->attackspeed1 );
269  new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog Animate (1/100 sec)", &o->attackspeed2 );
270  new PG_PropertyField_Integer<int>( propertyEditor , "Attack Dialog PostWait 3 (1/100 sec)", &o->attackspeed3 );
271  if ( mainApp ) {
272  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Game running Fullscreen", &o->forceWindowedMode, true );
273  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Produce Ammo when refuelling", &o->autoproduceammunition );
274  new PG_PropertyField_IntDropDown<int>( propertyEditor, "InfoPanels", &o->panelColumns, infoPanelNames );
275  new PG_PropertyField_Integer<int>( propertyEditor, "Aircraft Crash Warning Time", &o->aircraftCrashWarningTime );
276  } else {
277  new PG_PropertyField_Checkbox<bool>( propertyEditor, "MapEd running Fullscreen", &o->mapeditWindowedMode, true );
278  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Modal Selection Window", &o->maped_modalSelectionWindow );
279  }
280 
281 #ifdef WIN32
282  static const char* graphicDrivers[] = { "default", "windib", "directx", NULL };
283  new PG_PropertyField_DropDown<ASCString>( propertyEditor , "Graphics backend", &o->graphicsDriver, graphicDrivers );
284 #endif
285 
286 
287 
288  new PG_PropertyField_IntDropDown<int, GetVideoModes::VList::iterator>( propertyEditor, "Video Mode", &videoMode, vmodes.getList().begin(), vmodes.getList().end() );
289 
290  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Automatic Training", &o->automaticTraining );
291 
292  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Field Select", &o->mouse.fieldmarkbutton, mouseButtonNames );
293  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Center View", &o->mouse.centerbutton, mouseButtonNames );
294  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Drag'N'Drop", &o->mouse.dragndropbutton, mouseButtonNames );
295  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Zoom Out", &o->mouse.zoomoutbutton, mouseButtonNames );
296  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Mouse: Zoom In", &o->mouse.zoominbutton, mouseButtonNames );
297  if ( mainApp )
298  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Single click action", &o->mouse.singleClickAction );
299 
300 
301  if ( !mainApp )
302  new PG_PropertyField_String<ASCString>( propertyEditor , "BI3 directory", &o->BI3directory );
303 
304  if ( mainApp )
305  new PG_PropertyField_String<ASCString>( propertyEditor , "Startup Map", &o->startupMap );
306 
307  //if ( mainApp )
308  (new PG_PropertyField_String<ASCString>( propertyEditor , "Default Password", &defaultPassword ))->SetPassHidden('*');
309 
310  new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: Cache GUI Definition (*.ascgui)", &o->cacheASCGUI );
311  new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: View own replay", &o->debugReplay );
312 
313  if ( mainApp ) {
314  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Replays as Movies (not saved)", &o->replayMovieMode );
315 
316  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Record Campaign Map solutions", &o->recordCampaignMaps );
317 
318  new PG_PropertyField_String<ASCString>( propertyEditor, "PBEM server hostname", &o->pbemServer.hostname );
319  new PG_PropertyField_String<ASCString>( propertyEditor, "PBEM server username", &o->pbemServer.username );
320  new PG_PropertyField_Integer<int>( propertyEditor, "PBEM server port", &o->pbemServer.port);
321 
322  new PG_PropertyField_Checkbox<bool>( propertyEditor, "Log kills to console", &o->logKillsToConsole );
323  }
324 
325  (new PG_PropertyField_String<ASCString>( propertyEditor , "Language Override", &o->languageOverride ));
326 
327  if ( !mainApp )
328  new PG_PropertyField_Checkbox<bool>( propertyEditor, "DEV: Save event message separately", &o->saveEventMessagesExternal );
329 
330 
331  PG_Button* ok = new PG_Button( this, PG_Rect( Width() - 100, Height() - 40, 90, 30), "OK" );
332  ok->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &EditGameOptions::ok )));
333  };
334 
335 };
336 
337 
338 void editGameOptions ( bool mainApp )
339 {
340  try {
341  EditGameOptions ego ( NULL, mainApp );
342  ego.Show();
343  ego.RunModal();
344  }
345  catch ( ... ) {
346  errorMessage( "An exception was caught" );
347  }
348 }
int aircraftCrashWarningTime
the number of turns after which a unit will crash until the player is warned
Definition: gameoptions.h:209
int movespeed
1/100 sec for a unit to move from one field to the next
Definition: gameoptions.h:63
bool forceWindowedMode
force ASC to run in windowed mode (and not fullscreen, which is default)
Definition: gameoptions.h:93
int centerbutton
the button to select a field and open the menu there
Definition: gameoptions.h:146
bool units_gray_after_move
are units that cannot move but shoot displayed in gray ?
Definition: gameoptions.h:72
pair< int, int > ModeRes
bool recordCampaignMaps
Definition: gameoptions.h:204
ASCString defaultPassword
Definition: gameoptions.h:236
int mapeditor_xresolution
the horizontal resolution the mapeditor uses
Definition: gameoptions.h:114
int fieldmarkbutton
the button to select a field without opening the menu
Definition: gameoptions.h:130
VList & getList()
const char * mouseButtonNames[]
void warningMessage(const ASCString &str)
int yresolution
the vertical resolution ASC uses
Definition: gameoptions.h:111
bool endturnquestion
question "do you want to end your turn"
Definition: gameoptions.h:69
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
void setUnencoded(const string &s)
Definition: password.cpp:27
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool fastmove
the number of steps to perform a move: 0 -> 3 step; != 0 -> 2 steps
Definition: gameoptions.h:60
bool debugReplay
enables the option to review your own replay to find replay bugs
Definition: gameoptions.h:102
bool saveEventMessagesExternal
will save all Immediate Game Event messages into a seperate file for doing translations ...
Definition: gameoptions.h:257
bool autoproduceammunition
produce required ammo upon refuelling
Definition: gameoptions.h:191
bool automaticTraining
are units automatically trained in training centers
Definition: gameoptions.h:122
bool mapeditWindowedMode
force the mapeditor to run in fullscreen mode (and not windowed, which is default) ...
Definition: gameoptions.h:105
ASCString BI3directory
Definition: gameoptions.h:223
EditGameOptions(PG_Widget *parent, bool mainApp)
ASC_PG_App & getPGApplication()
Definition: paradialog.cpp:294
void setChanged(bool flag=true)
Definition: gameoptions.h:272
bool replayMovieMode
Definition: gameoptions.h:203
bool quitModalLoop(int value)
Definition: paradialog.cpp:545
ASCString hostname
Definition: gameoptions.h:226
int dragndropbutton
used in the container dialog
Definition: gameoptions.h:149
void editGameOptions(bool mainApp)
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
int getx(int index)
int attackspeed1
are fields marked that a unit could move to if there was no other unit standing
Definition: gameoptions.h:84
int mapeditor_yresolution
the vertical resolution the mapeditor uses
Definition: gameoptions.h:117
bool singleClickAction
marks a field and opens the small gui buttons with a single click (default: first click mark...
Definition: gameoptions.h:161
void errorMessage(const ASCString &string)
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
struct CGameOptions::@10 pbemServer
bool toggleFullscreen()
Definition: paradialog.cpp:258
struct CGameOptions::Mouse mouse
ASCString username
Definition: gameoptions.h:228
int findmodenum(int x, int y)
bool maped_modalSelectionWindow
Definition: gameoptions.h:119
int attackspeed3
second delay in attack display
Definition: gameoptions.h:90
const char * infoPanelNames[]
ASCString graphicsDriver
Definition: gameoptions.h:233
bool logKillsToConsole
Definition: gameoptions.h:259
int attackspeed2
speed of moving bars in attack display
Definition: gameoptions.h:87
string toString() const
Definition: password.cpp:94
int zoomoutbutton
the button to display the vehicle information
Definition: gameoptions.h:157
ASCString languageOverride
Definition: gameoptions.h:254
ASCString startupMap
Definition: gameoptions.h:235
int xresolution
the horizontal resolution ASC uses
Definition: gameoptions.h:108
bool cacheASCGUI
Definition: gameoptions.h:201
int gety(int index)
void infoMessage(const ASCString &string)