00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "../sg.h"
00023 #include "../ascstring.h"
00024 #include "../vehicle.h"
00025 #include "../gamemap.h"
00026 #include "../spfst.h"
00027 #include "../spfst-legacy.h"
00028
00029 #include "../itemrepository.h"
00030 #include "../dlg_box.h"
00031 #include "../paradialog.h"
00032 #include "../gameeventsystem.h"
00033 #include "../loaders.h"
00034 #include "../accessconstraints.h"
00035
00036 #include <pgpropertyfield_integer.h>
00037 #include <pgpropertyfield_intdropdown.h>
00038 #include <pgpropertyfield_checkbox.h>
00039 #include <pgpropertyfield_string.h>
00040 #include <pgpropertyfield_button.h>
00041 #include <pgpropertyeditor.h>
00042
00043 #include "common.h"
00044
00045 GameMap* getActiveMap()
00046 {
00047 return actmap;
00048 }
00049
00050 const ObjectType* getObjectType( int id )
00051 {
00052 return objectTypeRepository.getObject_byID( id );
00053 }
00054
00055 const BuildingType* getBuildingType( int id )
00056 {
00057 return buildingTypeRepository.getObject_byID( id );
00058 }
00059
00060 const VehicleType* getUnitType( int id )
00061 {
00062 return vehicleTypeRepository.getObject_byID( id );
00063 }
00064
00065 const TerrainType* getTerrainType( int id )
00066 {
00067 return terrainTypeRepository.getObject_byID( id );
00068 }
00069
00070
00071 bool PropertyDialog :: ok() {
00072 result = true;
00073 propertyEditor->Apply();
00074 QuitModal();
00075 return true;
00076 }
00077
00078 bool PropertyDialog :: cancel() {
00079 result = false;
00080 QuitModal();
00081 return true;
00082 }
00083
00084
00085 void PropertyDialog :: setup()
00086 {
00087 propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight()+10, Width() - 20, Height() - GetTitlebarHeight() - 60 ), "PropertyEditor", 70 );
00088
00089 StandardButtonDirection( Horizontal );
00090 AddStandardButton("OK")->sigClick.connect( SigC::slot( *this, &PropertyDialog::ok ));
00091 AddStandardButton("Cancel")->sigClick.connect( SigC::slot( *this, &PropertyDialog::cancel ));
00092 }
00093
00094
00095 PropertyDialog :: PropertyDialog( const ASCString& title ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 400, 500 ), title ), propertyEditor(NULL), result(false)
00096 {
00097 setup();
00098 }
00099
00100 PropertyDialog :: PropertyDialog( const ASCString& title, const PG_Rect& pos ) : ASC_PG_Dialog( NULL, pos, title ), propertyEditor(NULL), result(false)
00101 {
00102 setup();
00103 }
00104
00105
00106 void PropertyDialog :: addBool( const ASCString& name, bool defaultValue )
00107 {
00108 boolValues[name] = defaultValue ;
00109 new PG_PropertyField_Checkbox<bool>( propertyEditor, name, &boolValues[name] );
00110 }
00111
00112 void PropertyDialog :: addInteger( const ASCString& name, int defaultValue )
00113 {
00114 intValues[name] = defaultValue;
00115 new PG_PropertyField_Integer<int>( propertyEditor, name, &intValues[name] );
00116 }
00117
00118 void PropertyDialog :: addIntDropdown( const ASCString& name, const StringArray& names, int defaultValue )
00119 {
00120 intValues[name] = defaultValue;
00121 new PG_PropertyField_IntDropDown<int,vector<ASCString>::const_iterator>( propertyEditor, name, &intValues[name], names.values.begin(), names.values.end() );
00122 }
00123
00124 void PropertyDialog :: addString( const ASCString& name, const ASCString& defaultValue )
00125 {
00126 stringValues[name] = defaultValue ;
00127 new PG_PropertyField_String<ASCString>( propertyEditor, name, &stringValues[name] );
00128 }
00129
00130 std::string PropertyDialog :: getString( const ASCString& name )
00131 {
00132 return stringValues[name];
00133 }
00134
00135 int PropertyDialog :: getInteger( const ASCString& name )
00136 {
00137 return intValues[name];
00138 }
00139
00140 bool PropertyDialog :: getBool( const ASCString& name )
00141 {
00142 return boolValues[name];
00143 }
00144
00145 bool PropertyDialog :: run() {
00146 Show();
00147 RunModal();
00148 Hide();
00149 return result;
00150 }
00151
00152
00153 int selectString ( const ASCString& title, const StringArray& entries, int defaultEntry )
00154 {
00155 vector<ASCString> buttons;
00156 buttons.push_back("OK" );
00157 buttons.push_back("Cancel" );
00158
00159 pair<int,int> r = new_chooseString ( title, entries.values, buttons, defaultEntry );
00160 if ( r.first == 1 )
00161 return -1;
00162 else
00163 return r.second;
00164 }
00165
00166 GameMap* getLoadingMap()
00167 {
00168 return eventLocalizationMap;
00169 }
00170
00171
00172 void setLocalizedEventMessage( GameMap* eventLocalizationMap, int eventID, const ASCString& message )
00173 {
00174 if ( !eventLocalizationMap )
00175 return;
00176
00177 for ( GameMap::Events::const_iterator i = eventLocalizationMap->events.begin(); i != eventLocalizationMap->events.end(); ++i )
00178 if ( (*i)->id == eventID )
00179 (*i)->action->setLocalizationString( message );
00180 }
00181
00182 void setLocalizedContainerName( GameMap* map, const MapCoordinate& pos, const std::string& name )
00183 {
00184 if ( !map )
00185 return;
00186
00187 MapField* fld = map->getField( pos );
00188 if ( !fld )
00189 return;
00190
00191 ContainerBase* c = fld->getContainer();
00192 if ( !c )
00193 return;
00194
00195 if ( !checkModificationConstraints( c ))
00196 return;
00197
00198 c->setName( name );
00199 }
00200
00201
00202
00203 MapCoordinate getCursorPosition( const GameMap* gamemap )
00204 {
00205 if ( gamemap )
00206 return gamemap->getCursor();
00207 else
00208 return MapCoordinate(-1,-1);
00209 }
00210
00211 void setCursorPosition( const GameMap* gamemap, const MapCoordinate& pos )
00212 {
00213 if ( gamemap && pos.valid() )
00214 if ( pos.x < gamemap->xsize && pos.y < gamemap->ysize )
00215 gamemap->getCursor() = pos;
00216 }
00217
00218 void assertSuccess( const ActionResult& result )
00219 {
00220 if ( result.successful() )
00221 throw ASCmsgException(result.getMessage() );
00222 }