1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/*
This file is part of Advanced Strategic Command; http://www.asc-hq.de
Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#include <sstream>
#include <pgimage.h>
#include <pgpropertyeditor.h>
#include <pgpropertyfield_integer.h>
#include <pgpropertyfield_string.h>
#include <pgpropertyfield_checkbox.h>
#include <pgpropertyfield_button.h>
#include <pgpropertyfield_intdropdown.h>
#include "newmap.h"
#include "editmapparam.h"
#include "../gamemap.h"
#include "../paradialog.h"
#include "../itemrepository.h"
#include "../edselfnt.h"
#include "../edgen.h"
class NewMap: public ASC_PG_Dialog {
private:
PG_PropertyEditor* properties;
GameMap* gamemap;
bool create;
int xsize,ysize;
bool random;
PG_Button* terrainButton;
int terrainid;
bool success;
bool selectTerrain() {
selectItemID( terrainid, terrainTypeRepository );
updateButton();
return true;
}
void updateButton()
{
TerrainType::Weather* w = terrainTypeRepository.getObject_byID( terrainid)->weather[0];
if ( w )
terrainButton->SetIcon( w->image.getBaseSurface() );
else
terrainButton->SetIcon( NULL );
}
bool ok()
{
if ( !properties->Apply() )
return false;
if ( ysize & 1 ) {
warningMessage( "Height must be an even number!" );
return false;
}
if ( create ) {
TerrainType::Weather* w = terrainTypeRepository.getObject_byID( terrainid)->weather[0];
if ( !w ) {
warningMessage( "please choose a terrain!" );
return false;
}
gamemap->allocateFields( xsize, ysize, w );
if ( random)
mapgenerator();
}
success = true;
QuitModal();
return true;
}
bool cancel()
{
if ( create ) {
delete gamemap;
gamemap = NULL;
}
QuitModal();
return true;
}
public:
NewMap( GameMap* map ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 500, 400 ), "Map Properties" ), terrainid( 2998 ), success(false)
{
if ( map ) {
create = false;
gamemap = map;
} else {
create = true;
gamemap = new GameMap;
}
int ypos = 40;
xsize = 10;
ysize = 20;
random = false;
properties = new ASC_PropertyEditor( this, PG_Rect( 20 , ypos, Width()-20, Height() - ypos - 60 ));
new PG_PropertyField_String<ASCString>( properties, "Title", &gamemap->maptitle );
if ( create ) {
new PG_PropertyField_Integer<int>( properties, "Width", &xsize );
new PG_PropertyField_Integer<int>( properties, "Height", &ysize );
new PG_PropertyField_Checkbox<bool>( properties, "Random", &ysize );
}
new PG_PropertyField_Checkbox<bool>( properties, "Campaign", &gamemap->campaign.avail );
new PG_PropertyField_Integer<int>( properties, "Map ID", &gamemap->campaign.id );
new PG_PropertyField_Checkbox<bool>( properties, "Direct Access", &gamemap->campaign.directaccess );
(new PG_PropertyField_String<ASCString>( properties, "Password", &gamemap->codeWord )); //->SetPassHidden('*');
terrainButton = (new PG_PropertyField_Button( properties, "Terrain", "", 50 ))->GetButton();
terrainButton->sigClick.connect( SigC::slot( *this, &NewMap::selectTerrain ));
(new PG_PropertyField_Integer<int>( properties, "Wind Speed", &gamemap->weather.windSpeed ))->SetRange(0,255);
static const char* directionNames[7] = { "South", "SouthWest", "NorthWest", "North", "NorthEast", "SouthEast", NULL };
new PG_PropertyField_IntDropDown<int>( properties, "Wind Direction", &gamemap->weather.windDirection, directionNames );
new PG_PropertyField_String<ASCString>( properties, "Native Event Language", &gamemap->nativeMessageLanguage );
updateButton();
ypos += 200;
StandardButtonDirection ( ASC_PG_Dialog::Horizontal );
AddStandardButton ( "Cancel" )->sigClick.connect( SigC::slot( *this, &NewMap::cancel ));
AddStandardButton ( "OK" )->sigClick.connect( SigC::slot( *this, &NewMap::ok ));
};
GameMap* GetResult()
{
if ( !success )
return NULL;
GameMap* res = gamemap;
gamemap = NULL;
return res;
}
~NewMap()
{
if ( create ) {
delete gamemap;
gamemap = NULL;
}
}
};
GameMap* createNewMap()
{
NewMap nm(NULL);
nm.Show();
nm.RunModal();
return nm.GetResult();
}
void editMap( GameMap* map )
{
NewMap nm(map);
nm.Show();
nm.RunModal();
}
|