00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <sstream>
00023 #include <pgimage.h>
00024
00025 #include "../gameoptions.h"
00026 #include "../gamemap.h"
00027 #include "../paradialog.h"
00028 #include "importbi3map.h"
00029 #include "fileselector.h"
00030 #include "../itemrepository.h"
00031 #include "../loadbi3.h"
00032 #include "../widgets/textrenderer.h"
00033 #include "pglistboxitem.h"
00034
00035
00036 class ImportBI3MapDialog : public ASC_PG_Dialog {
00037
00038 GameMap* actmap;
00039 bool insert;
00040
00041 PG_LineEdit* directory;
00042 PG_ListBox* importTable;
00043
00044 vector<ASCString> importTables;
00045
00046
00047 bool checkBI3Path( ASCString filename )
00048 {
00049 filename += "mis";
00050 filename += pathdelimitterstring;
00051 filename += "*.dat";
00052
00053 if ( exist( filename ))
00054 return true;
00055 else {
00056 errorMessage("Could not find files in BI3 directory\nlooking for " + filename );
00057 return false;
00058 }
00059 }
00060
00061 bool ok() {
00062
00063 ASCString bi3Path = directory->GetText();
00064 appendbackslash( bi3Path );
00065
00066 if ( !checkBI3Path( bi3Path ))
00067 return false;
00068
00069
00070 if ( importTable->GetSelectedIndex() < 0 ) {
00071 if ( importTables.size() > 0 ) {
00072 errorMessage("No import table selected" );
00073 return false;
00074 } else {
00075 errorMessage("No import tables available. Aborting" );
00076 QuitModal();
00077 }
00078 }
00079
00080 if ( bi3Path != CGameOptions::Instance()->BI3directory ) {
00081 CGameOptions::Instance()->setChanged ( 1 );
00082 CGameOptions::Instance()->BI3directory = bi3Path;
00083 }
00084
00085 ASCString wildcard = bi3Path + "mis" + pathdelimitterstring + "*.dat" ;
00086
00087 ASCString filename = selectFile( wildcard, true );
00088 if ( !filename.empty() ) {
00089 ASCString errorOutput;
00090 try {
00091 if ( insert==false ) {
00092 importbattleislemap ( bi3Path, filename, terrainTypeRepository.getObject_byID(9999)->weather[0], getImportTable(), &errorOutput );
00093 if ( !errorOutput.empty() ) {
00094 ViewFormattedText vft( "Results of Import", errorOutput, PG_Rect(-1,-1,400,400));
00095 vft.Show();
00096 vft.RunModal();
00097 }
00098 } else {
00099 int x = actmap->getCursor().x;
00100 int y = actmap->getCursor().y;
00101 if ( x < 0 )
00102 x = 0;
00103
00104 if ( y < 0 )
00105 y = 0;
00106 insertbattleislemap ( x, y, bi3Path, filename, getImportTable() );
00107 }
00108 } catch ( ASCexception err ) {
00109 errorMessage("importing the map failed");
00110 }
00111 }
00112
00113 QuitModal();
00114 return true;
00115 }
00116
00117 bool cancel() {
00118 QuitModal();
00119 return true;
00120 }
00121
00122 public:
00123 ImportBI3MapDialog( GameMap* gamemap, bool insert );
00124
00125 ASCString getImportTable() {
00126 if ( importTable->GetSelectedIndex() >= 0 && importTable->GetSelectedIndex() < importTables.size() )
00127 return importTables[importTable->GetSelectedIndex()];
00128 else
00129 return "";
00130 }
00131 };
00132
00133
00134 ImportBI3MapDialog::ImportBI3MapDialog( GameMap* gamemap, bool insert ) : ASC_PG_Dialog( NULL, PG_Rect(-1,-1,450,370), "Import BI Map") , actmap(gamemap)
00135 {
00136 this->insert = insert;
00137 AddStandardButton("OK")->sigClick.connect( SigC::slot( *this, &ImportBI3MapDialog::ok ));
00138 AddStandardButton("Cancel")->sigClick.connect( SigC::slot( *this, &ImportBI3MapDialog::cancel ));
00139
00140 int ypos = 30;
00141 new PG_Label( this, PG_Rect( 20, ypos, Width()-40,20), "Directory of BI3 installation:");
00142 ypos += 25;
00143
00144 directory = new PG_LineEdit( this, PG_Rect( 20, ypos, Width() - 40, 20 ));
00145 directory->SetText( CGameOptions::Instance()->BI3directory );
00146 ypos += 40;
00147
00148
00149
00150 new PG_Label( this, PG_Rect( 20, ypos, Width()-40,20), "BI3 item translation table (note that data is only read at startup of ASC):");
00151 ypos += 25;
00152
00153 importTable = new PG_ListBox( this, PG_Rect(20, ypos, Width() - 40, 150 ));
00154
00155 importTables = getBI3ImportTables();
00156 for ( vector<ASCString>::iterator i = importTables.begin(); i != importTables.end(); ++i )
00157 new PG_ListBoxItem( importTable, 20, *i );
00158
00159 };
00160
00161 void importBI3Map( GameMap* gamemap, bool insert )
00162 {
00163 ImportBI3MapDialog ibi3md ( gamemap, insert );
00164 ibi3md.Show();
00165 ibi3md.RunModal();
00166 }
00167
00168