Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

newmap.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include <sstream>
00022 #include <pgimage.h>
00023 #include <pgpropertyeditor.h>
00024 #include <pgpropertyfield_integer.h>
00025 #include <pgpropertyfield_string.h>
00026 #include <pgpropertyfield_checkbox.h>
00027 #include <pgpropertyfield_button.h>
00028 #include <pgpropertyfield_intdropdown.h>
00029 
00030 #include "newmap.h"
00031 #include "editmapparam.h"
00032 #include "../gamemap.h"
00033 #include "../paradialog.h"
00034 #include "../itemrepository.h"
00035 #include "../edselfnt.h"
00036 #include "../edgen.h"
00037 
00038 
00039 class NewMap: public ASC_PG_Dialog {
00040    private:
00041       PG_PropertyEditor* properties;
00042       GameMap* gamemap;
00043       bool create;
00044       int xsize,ysize;
00045       bool random;
00046       PG_Button* terrainButton;
00047       int terrainid;
00048       bool success;
00049 
00050 
00051       bool selectTerrain() {
00052          selectItemID( terrainid, terrainTypeRepository );
00053          updateButton();
00054          return true;
00055       }
00056 
00057       void updateButton()
00058       {
00059          TerrainType::Weather* w = terrainTypeRepository.getObject_byID( terrainid)->weather[0];
00060          if ( w )
00061             terrainButton->SetIcon( w->image.getBaseSurface() );
00062          else
00063             terrainButton->SetIcon( NULL );
00064       }
00065       
00066       
00067       bool ok()
00068       {
00069          if ( !properties->Apply() )
00070             return false;
00071 
00072         
00073          if ( ysize & 1 ) {
00074             warning( "Height must be an even number!" );
00075             return false;
00076          }
00077          
00078 
00079          if ( create ) {
00080             TerrainType::Weather* w = terrainTypeRepository.getObject_byID( terrainid)->weather[0];
00081             if ( !w ) {
00082                warning( "please chose a terrain!" );
00083                return false;
00084             }
00085             
00086             gamemap->allocateFields( xsize, ysize, w );
00087 
00088             if ( random)
00089                mapgenerator();
00090             
00091          }
00092          success = true;
00093          
00094          QuitModal();
00095          
00096          return true;
00097       }
00098       
00099       bool cancel()
00100       {
00101          if ( create ) {
00102             delete gamemap;
00103             gamemap = NULL;
00104          }
00105             
00106          QuitModal();
00107          return true;
00108       }
00109       
00110    public:
00111       NewMap( GameMap* map ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 500, 400 ), "Map Properties" ), terrainid( 2998 ), success(false)
00112       {
00113          if ( map ) {
00114             create = false;
00115             gamemap = map;
00116          } else {
00117             create = true;
00118             gamemap = new GameMap;
00119          }
00120 
00121          int ypos = 40;
00122 
00123          xsize = 10;
00124          ysize = 20;
00125          random = false;
00126          
00127          properties = new ASC_PropertyEditor( this, PG_Rect( 20 , ypos, Width()-20, Height() - ypos - 60  ));
00128          new PG_PropertyField_String<ASCString>( properties, "Title", &gamemap->maptitle );
00129          if ( create ) {
00130             new PG_PropertyField_Integer<int>( properties, "Width", &xsize );
00131             new PG_PropertyField_Integer<int>( properties, "Height", &ysize );
00132             new PG_PropertyField_Checkbox<bool>( properties, "Random", &ysize );
00133          }
00134          
00135          new PG_PropertyField_Checkbox<bool>( properties, "Campaign", &gamemap->campaign.avail );
00136          new PG_PropertyField_Integer<int>( properties, "Map ID", &gamemap->campaign.id );
00137          new PG_PropertyField_Checkbox<bool>( properties, "Direct Access", &gamemap->campaign.directaccess );
00138          (new PG_PropertyField_String<ASCString>( properties, "Password", &gamemap->codeWord ))->SetPassHidden('*');
00139          terrainButton = (new PG_PropertyField_Button( properties, "Terrain", "", 50 ))->GetButton();
00140          terrainButton->sigClick.connect( SigC::slot( *this, &NewMap::selectTerrain ));
00141 
00142          (new PG_PropertyField_Integer<int>( properties, "Wind Speed", &gamemap->weather.windSpeed ))->SetRange(0,255);
00143 
00144          static const char* directionNames[7] = { "South", "SouthWest", "NorthWest", "North", "NorthEast", "SouthEast", NULL };
00145          
00146          new PG_PropertyField_IntDropDown<int>( properties, "Wind Direction", &gamemap->weather.windDirection, directionNames );
00147          
00148          updateButton();
00149          
00150          ypos += 200;
00151 
00152          StandardButtonDirection ( ASC_PG_Dialog::Horizontal );
00153 
00154          AddStandardButton ( "Cancel" )->sigClick.connect( SigC::slot( *this, &NewMap::cancel ));
00155          AddStandardButton ( "OK" )->sigClick.connect( SigC::slot( *this, &NewMap::ok ));
00156          
00157       };
00158 
00159       GameMap* GetResult()
00160       {
00161          if ( !success )
00162             return NULL;
00163 
00164          GameMap* res = gamemap;
00165          gamemap = NULL;
00166          return res;
00167       }
00168 
00169       ~NewMap()
00170       {
00171          if ( create ) {
00172             delete gamemap;
00173             gamemap = NULL;
00174          }
00175       }
00176 };
00177 
00178 
00179 
00180 
00181 GameMap* createNewMap()
00182 {
00183    NewMap nm(NULL);
00184    nm.Show();
00185    nm.RunModal();
00186    return nm.GetResult();
00187 }
00188 
00189 void editMap( GameMap* map )
00190 {
00191    NewMap nm(map);
00192    nm.Show();
00193    nm.RunModal();
00194 }

Generated on Tue Jun 24 01:27:46 2008 for Advanced Strategic Command by  doxygen 1.4.2