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

importbi3map.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 
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 

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