Subversion Repositories spk

Rev

Rev 68 | Rev 94 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
36 cycrow 1
#include "../StdAfx.h"
2
#include "Form1.h"
3
 
4
namespace Creator {
5
 
6
Form1::Form1(array<System::String ^> ^args)
7
{
8
	InitializeComponent();
9
 
10
	m_bAutoClose = false;
11
	m_pWait = nullptr;
12
	m_bTextLoaded = false;
13
	this->shipToolStripMenuItem->Image = this->imageList1->Images[1];
14
	this->shipToolStripMenuItem1->Image = this->imageList1->Images[1];
15
	this->multiPackageToolStripMenuItem->Image = this->imageList1->Images[this->imageList1->Images->IndexOfKey("multi")];
16
	this->Closed += gcnew System::EventHandler(this, &Form1::CloseEvent);
17
 
18
	this->Text = "Package Creator " + GetVersionString();
19
	m_pLoadedList = new CyStringList;
20
	m_pGameDir = new CLinkList<SGameDir>;
21
 
22
	// default settings
23
	m_settings = new SSettings;
24
	m_settings->bGenerateUpdate = false;
25
 
26
	m_pComponents = NULL;
27
	m_pDummies = NULL;
28
	m_pBodies = NULL;
29
	m_pShields = NULL;
30
	m_pCockpits = new CLinkList<CyStringList>;
31
	m_pLasers = new CLinkList<CyStringList>;
32
	m_pMissiles = new CLinkList<CyStringList>;
33
 
34
	m_iLocX = m_iLocY = -1;
35
 
36
	this->toolTip1->SetToolTip(this->button1, "Closes all open windows, will ask about saving any that have been modified when they close");
37
 
38
	m_pPackages = new CPackages;
39
	m_pPackages->Startup(".", CyStringFromSystemString(IO::Path::GetTempPath()), CyStringFromSystemString(Environment::GetFolderPath(Environment::SpecialFolder::Personal )));
40
	m_pPackages->SetLanguage(44);
41
 
42
	this->LoadData();
43
 
44
	this->UpdateDisplay();
45
 
46
	// parse any switches
47
	this->parseCommandArguments(args);
48
}
49
 
50
void Form1::parseCommandArguments(array<System::String ^> ^args)
51
{
52
	int switchType = SWITCH_NONE;
53
 
54
	if ( args ) {
55
		ArrayList ^list = gcnew ArrayList();
56
		for ( int i = 0; i < args->Length; i++ ) {
57
			String ^str = args[i];
58
			if ( switchType != SWITCH_NONE ) {
59
				switch(switchType) {
60
					case SWITCH_CREATE:
61
						this->SavePackagerScript(str);
62
						m_bAutoClose = true;
63
						break;
64
					case SWITCH_EXTRACT:
65
						this->ExtractPackage(str, false);
66
						m_bAutoClose = true;
67
						break;
68
					case SWITCH_EXTRACTHERE:
69
						this->ExtractPackage(str, true);
70
						m_bAutoClose = true;
71
						break;
72
					case SWITCH_EXPORT:
73
						this->ExportPackage(str);
74
						m_bAutoClose = true;
75
						break;
76
				}
77
				switchType = SWITCH_NONE;
78
			}
79
			else if ( !String::Compare(str, "--create", true) ) {
80
				switchType = SWITCH_CREATE;			
81
			}
82
			else if ( !String::Compare(str, "--extract", true) ) {
83
				switchType = SWITCH_EXTRACT;
84
			}
85
			else if ( !String::Compare(str, "--extracthere", true) ) {
86
				switchType = SWITCH_EXTRACTHERE;
87
			}
88
			else if ( !String::Compare(str, "--export", true) ) {
89
				switchType = SWITCH_EXPORT;
90
			}
91
			else {
92
				list->Add(args[i]);
93
			}
94
		}
95
 
96
		if ( list->Count ) {
97
			this->OpenFiles(list, true, true);
98
			m_bAutoClose = false;
99
		}
100
	}
101
}
102
 
103
 
104
String ^Form1::getShipSelection(CVirtualFileSystem *pVfs)
105
{
106
	CyStringList list;
107
	if ( pVfs->loadShipData(&list) ) {
108
		LoadShip ^ls = gcnew LoadShip();
109
		for ( SStringList *str = list.Head(); str; str = str->next )
110
		{
111
			int tId = str->data.GetToken(";", 7, 7).ToInt();
112
			String ^name;
113
			if ( pVfs->textExists(44, 17, tId) )
114
				name = SystemStringFromCyString(pVfs->findText(44, 17, tId));
115
			else
116
				name = this->FindText(-1, 17, tId);
117
			String ^text = this->FindText(-1, 1266, str->data.GetToken(";", 46, 46).ToInt()) + " " + name;
118
			int variation = str->data.GetToken(";", 51, 51).ToInt();
119
			if ( variation )
120
				text = text + " " + this->FindText(-1, 17, 10000 + variation);
121
			ls->AddShip(SystemStringFromCyString(str->str), text);
122
		}
123
 
124
		if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )	{
125
			SStringList *str = list.FindString(CyStringFromSystemString(ls->GetData()));
126
			if ( str )	{
127
				return ls->GetData();
128
			}
129
		}
130
		else return "";
131
	}
132
 
133
	return nullptr;
134
}
135
 
136
void Form1::ImportShip()
137
{
138
	OpenFileDialog ^ofd = gcnew OpenFileDialog();
139
	ofd->Filter = "X Catalog Files (*.cat)|*.cat";
140
	ofd->Title = "Select the mod file to import a ship from";
141
	ofd->FilterIndex = 1;
142
	ofd->RestoreDirectory = true;
143
	ofd->Multiselect = false;
144
 
145
	CVirtualFileSystem *vfs = new CVirtualFileSystem();
146
 
147
	if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
148
	{
149
		if ( !vfs->loadMod(CyStringFromSystemString(ofd->FileName).ToString()) ) {
150
			MessageBox::Show(this, "There was a problem when trying to import the ship\n" + ofd->FileName + "\n\nError: Unable to open mod file", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
151
			return;
152
		}
153
		this->UseWaitCursor = true;
154
 
155
		vfs->updateModTexts(17);
156
 
157
		String ^shipID = getShipSelection(vfs);
39 cycrow 158
		if ( !shipID ) {
77 cycrow 159
			MessageBox::Show(this, "There was a problem trying to load the mod file\n" + ofd->FileName + "\n\nNo TShips file found", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
39 cycrow 160
		}
161
		else if ( shipID->Length ) {
36 cycrow 162
			String ^loadMod = ofd->FileName;
163
			CXspFile *newShip = NULL;
164
 
165
			while ( true ) {
166
				Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, vfs);
167
				import->ShowDialog(this);
168
				newShip = (import->Error()) ? NULL : import->GetShip();
169
				if ( !newShip ) {
170
					if ( MessageBox::Show(this, "There was a problem when trying to import the ship\n" + ofd->FileName + " (" + shipID + ")\n\nError: " + import->getErrorString() + "\n\nWould you like to read files from another mod as well?", "Error Importing Ship", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes ) {
171
						// load in another file
172
						if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK ) {
173
							loadMod = ofd->FileName;
174
							if ( !vfs->loadMod(CyStringFromSystemString(loadMod).ToString()) ) {
175
								MessageBox::Show(this, "There was a problem when trying to import the ship\n" + ofd->FileName + " (" + shipID + ")\n\nError: Unable to open mod file", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
176
								break;
177
							}
178
						}
179
						else break;
180
					}
181
					else break;
182
				}
183
				else break;	
184
			}
185
 
186
			if ( newShip ) {
187
				PackageForm ^childForm = this->OpenPackage(true, newShip, "", "Imported Ship");
188
				childForm->Text = "Imported Ship";
50 cycrow 189
				newShip->adjustChanged(true);
36 cycrow 190
				childForm->UpdateChanged();
191
			}
192
 
193
		}
194
 
195
		this->UseWaitCursor = false;
196
	}
197
 
198
	delete vfs;
199
}
200
 
201
 
202
void Form1::ImportShipFromVFS()
203
{
204
	// some way to select the VFS to use
205
	SelectFilesystem ^Filesystem = gcnew SelectFilesystem(m_pGameDir, this->GetHighestGame());
206
	if ( Filesystem->ShowDialog(this) != System::Windows::Forms::DialogResult::OK ) {
207
		return;
208
	}
209
 
210
	SGameDir *pDir = Filesystem->gameDir();
211
	CyString mod;
212
	if ( Filesystem->gameMod() ) {
68 cycrow 213
		mod = CyString(pDir->dir) + "/mods/" + CyStringFromSystemString(Filesystem->gameMod()) + ".cat";
36 cycrow 214
	}
215
 
216
	// load a mod on top of the VFS
217
	if ( !mod.Empty() ) {
218
		if ( !pDir->pVfs->loadMod(mod.ToString()) ) {
219
			MessageBox::Show(this, "There was a problem trying to open the mod file\n" + Filesystem->gameMod(), "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
220
			return;
221
		}
222
		pDir->pVfs->updateModTexts(17);
223
	}
224
 
225
	// get the ship id to load
226
	String ^shipID = getShipSelection(pDir->pVfs);
227
	if ( !shipID ) {
228
		MessageBox::Show(this, "There was a problem trying to load ship data from VFS\n", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
229
	}
230
	else if ( shipID->Length ) {
231
		// import the ship
232
		Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, pDir->pVfs);
233
		import->ShowDialog(this);
234
 
235
		// create the new form with ship data
236
		if ( !import->Error() ) {
237
			PackageForm ^childForm = this->OpenPackage(true, import->GetShip(), "", "Imported Ship");
238
			childForm->Text = "Imported Ship";
50 cycrow 239
			import->GetShip()->adjustChanged(true);
36 cycrow 240
			childForm->UpdateChanged();
241
		}
242
	}
243
 
244
	// remove any mods that we have loaded
245
	pDir->pVfs->clearMods();
246
}
247
 
248
} //NAMESPACE