Ejemplo n.º 1
0
		private void btnSave_Click(object sender, System.EventArgs e)
		{
			if (SaveButtonEnabled())
			{
				if (dlgSave.ShowDialog(this) == DialogResult.OK)
				{
					ShipTemplate	template	= new ShipTemplate(shipyard.ShipSpec, txtName.Text);

					if (imgIndex > Consts.MaxShip)
					{
						template.ImageIndex	= (int)ShipType.Custom;
						template.Images			= customImages;
					}
					else
						template.ImageIndex	= imgIndex;

					Functions.SaveFile(dlgSave.FileName, template.Serialize(), this);

					LoadTemplateList();
				}
			}
		}
Ejemplo n.º 2
0
		private void LoadTemplateList()
		{
			ShipTemplate	currentShip	= new ShipTemplate(game.Commander.Ship, Strings.ShipNameCurrentShip);
			selTemplate.Items.Add(currentShip);

			selTemplate.Items.Add(Consts.ShipTemplateSeparator);

			// Add the minimal sizes templates.
			foreach (Size size in sizes)
				selTemplate.Items.Add(new ShipTemplate(size, Strings.Sizes[(int)size] + Strings.ShipNameTemplateSuffixMinimum));

			selTemplate.Items.Add(Consts.ShipTemplateSeparator);

			// Add the purchasable ship spec templates.
			foreach (ShipSpec spec in Consts.ShipSpecs)
			{
				if (sizes.Contains(spec.Size) && (int)spec.Type <= Consts.MaxShip)
					selTemplate.Items.Add(new ShipTemplate(spec, spec.Name + Strings.ShipNameTemplateSuffixDefault));
			}

			selTemplate.Items.Add(Consts.ShipTemplateSeparator);

			// Add the user-created templates.
			ArrayList	userTemplates	= new ArrayList();
			foreach (string fileName in Directory.GetFiles(Consts.CustomTemplatesDirectory, "*.sst"))
			{
				ShipTemplate	template	= new ShipTemplate((Hashtable)Functions.LoadFile(fileName, true, this));
				if (sizes.Contains(template.Size))
					userTemplates.Add(template);
			}
			userTemplates.Sort();
			selTemplate.Items.AddRange((ShipTemplate[])userTemplates.ToArray(typeof(ShipTemplate)));

			selTemplate.SelectedIndex	= 0;
		}