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
|
/*
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 "../gameoptions.h"
#include "../gamemap.h"
#include "../paradialog.h"
#include "importbi3map.h"
#include "fileselector.h"
#include "../itemrepository.h"
#include "../loadbi3.h"
#include "../widgets/textrenderer.h"
#include "pglistboxitem.h"
class ImportBI3MapDialog : public ASC_PG_Dialog {
GameMap* actmap;
bool insert;
PG_LineEdit* directory;
PG_ListBox* importTable;
vector<ASCString> importTables;
bool checkBI3Path( ASCString filename )
{
filename += "mis";
filename += pathdelimitterstring;
filename += "*.dat";
if ( exist( filename ))
return true;
else {
errorMessage("Could not find files in BI3 directory\nlooking for " + filename );
return false;
}
}
bool ok() {
ASCString bi3Path = directory->GetText();
appendbackslash( bi3Path );
if ( !checkBI3Path( bi3Path ))
return false;
if ( importTable->GetSelectedIndex() < 0 ) {
if ( importTables.size() > 0 ) {
errorMessage("No import table selected" );
return false;
} else {
errorMessage("No import tables available. Aborting" );
QuitModal();
}
}
if ( bi3Path != CGameOptions::Instance()->BI3directory ) {
CGameOptions::Instance()->setChanged ( 1 );
CGameOptions::Instance()->BI3directory = bi3Path;
}
ASCString wildcard = bi3Path + "mis" + pathdelimitterstring + "*.dat" ;
ASCString filename = selectFile( wildcard, true );
if ( !filename.empty() ) {
ASCString errorOutput;
try {
if ( insert==false ) {
importbattleislemap ( bi3Path, filename, terrainTypeRepository.getObject_byID(9999)->weather[0], getImportTable(), &errorOutput );
if ( !errorOutput.empty() ) {
ViewFormattedText vft( "Results of Import", errorOutput, PG_Rect(-1,-1,400,400));
vft.Show();
vft.RunModal();
}
} else {
int x = actmap->getCursor().x;
int y = actmap->getCursor().y;
if ( x < 0 )
x = 0;
if ( y < 0 )
y = 0;
insertbattleislemap ( x, y, bi3Path, filename, getImportTable() );
}
} catch ( ASCexception ) {
errorMessage("importing the map failed");
}
}
QuitModal();
return true;
}
bool cancel() {
QuitModal();
return true;
}
public:
ImportBI3MapDialog( GameMap* gamemap, bool insert );
ASCString getImportTable() {
if ( importTable->GetSelectedIndex() >= 0 && importTable->GetSelectedIndex() < importTables.size() )
return importTables[importTable->GetSelectedIndex()];
else
return "";
}
};
ImportBI3MapDialog::ImportBI3MapDialog( GameMap* gamemap, bool insert ) : ASC_PG_Dialog( NULL, PG_Rect(-1,-1,450,370), "Import BI Map") , actmap(gamemap)
{
this->insert = insert;
AddStandardButton("OK")->sigClick.connect( SigC::slot( *this, &ImportBI3MapDialog::ok ));
AddStandardButton("Cancel")->sigClick.connect( SigC::slot( *this, &ImportBI3MapDialog::cancel ));
int ypos = 30;
new PG_Label( this, PG_Rect( 20, ypos, Width()-40,20), "Directory of BI3 installation:");
ypos += 25;
directory = new PG_LineEdit( this, PG_Rect( 20, ypos, Width() - 40, 20 ));
directory->SetText( CGameOptions::Instance()->BI3directory );
ypos += 40;
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):");
ypos += 25;
importTable = new PG_ListBox( this, PG_Rect(20, ypos, Width() - 40, 150 ));
importTables = getBI3ImportTables();
for ( vector<ASCString>::iterator i = importTables.begin(); i != importTables.end(); ++i )
new PG_ListBoxItem( importTable, 20, *i );
};
void importBI3Map( GameMap* gamemap, bool insert )
{
ImportBI3MapDialog ibi3md ( gamemap, insert );
ibi3md.Show();
ibi3md.RunModal();
}
|