Дополнения, правки, сделаны TODO
This commit is contained in:
parent
7adc066c5c
commit
906637e4b8
@ -24,7 +24,7 @@ namespace AirBomber
|
|||||||
return new DrawningAirPlane(Convert.ToInt32(strs[0]),
|
return new DrawningAirPlane(Convert.ToInt32(strs[0]),
|
||||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
}
|
}
|
||||||
if (strs.Length == 7)
|
if (strs.Length == 6)
|
||||||
{
|
{
|
||||||
return new DrawningAirBomber(Convert.ToInt32(strs[0]),
|
return new DrawningAirBomber(Convert.ToInt32(strs[0]),
|
||||||
Convert.ToInt32(strs[1]),
|
Convert.ToInt32(strs[1]),
|
||||||
@ -53,8 +53,12 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return $"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.FuelTanks}";
|
return $"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.FuelTanks}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
62
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
62
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
@ -39,18 +39,25 @@
|
|||||||
buttonDelObject = new Button();
|
buttonDelObject = new Button();
|
||||||
buttonAddObject = new Button();
|
buttonAddObject = new Button();
|
||||||
listBoxStorages = new ListBox();
|
listBoxStorages = new ListBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
сохранениеToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
загрузкаToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
groupBoxStorages.SuspendLayout();
|
groupBoxStorages.SuspendLayout();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.BackColor = SystemColors.Control;
|
pictureBoxCollection.BackColor = SystemColors.Control;
|
||||||
pictureBoxCollection.Dock = DockStyle.Left;
|
pictureBoxCollection.Dock = DockStyle.Left;
|
||||||
pictureBoxCollection.Location = new Point(0, 0);
|
pictureBoxCollection.Location = new Point(0, 33);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(708, 746);
|
pictureBoxCollection.Size = new Size(708, 713);
|
||||||
pictureBoxCollection.TabIndex = 0;
|
pictureBoxCollection.TabIndex = 0;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -157,6 +164,46 @@
|
|||||||
listBoxStorages.TabIndex = 0;
|
listBoxStorages.TabIndex = 0;
|
||||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.ImageScalingSize = new Size(24, 24);
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(1030, 33);
|
||||||
|
menuStrip.TabIndex = 5;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// ToolStripMenuItem
|
||||||
|
//
|
||||||
|
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранениеToolStripMenuItem, загрузкаToolStripMenuItem });
|
||||||
|
ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||||
|
ToolStripMenuItem.Size = new Size(69, 29);
|
||||||
|
ToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// сохранениеToolStripMenuItem
|
||||||
|
//
|
||||||
|
сохранениеToolStripMenuItem.Name = "сохранениеToolStripMenuItem";
|
||||||
|
сохранениеToolStripMenuItem.Size = new Size(270, 34);
|
||||||
|
сохранениеToolStripMenuItem.Text = "Сохранение";
|
||||||
|
сохранениеToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// загрузкаToolStripMenuItem
|
||||||
|
//
|
||||||
|
загрузкаToolStripMenuItem.Name = "загрузкаToolStripMenuItem";
|
||||||
|
загрузкаToolStripMenuItem.Size = new Size(270, 34);
|
||||||
|
загрузкаToolStripMenuItem.Text = "Загрузка";
|
||||||
|
загрузкаToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
// FormPlaneCollection
|
// FormPlaneCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
@ -164,6 +211,8 @@
|
|||||||
ClientSize = new Size(1030, 746);
|
ClientSize = new Size(1030, 746);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
Name = "FormPlaneCollection";
|
Name = "FormPlaneCollection";
|
||||||
Text = "Набор самолетов";
|
Text = "Набор самолетов";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
@ -171,7 +220,10 @@
|
|||||||
groupBoxTools.PerformLayout();
|
groupBoxTools.PerformLayout();
|
||||||
groupBoxStorages.ResumeLayout(false);
|
groupBoxStorages.ResumeLayout(false);
|
||||||
groupBoxStorages.PerformLayout();
|
groupBoxStorages.PerformLayout();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -187,5 +239,11 @@
|
|||||||
private Button buttonDelObject;
|
private Button buttonDelObject;
|
||||||
private Button buttonAddObject;
|
private Button buttonAddObject;
|
||||||
private ListBox listBoxStorages;
|
private ListBox listBoxStorages;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem сохранениеToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem загрузкаToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,7 +49,7 @@ namespace AirBomber
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes();
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -157,11 +157,51 @@ namespace AirBomber
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()?? string.Empty);
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Сохранение"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.SaveData(saveFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Загрузка"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// TODO продумать логику DONE
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.LoadData(openFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Загрузка прошла успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не загрузилось!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,4 +57,16 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>163, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>357, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>71</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
2
AirBomber/AirBomber/FormPlaneConfig.Designer.cs
generated
2
AirBomber/AirBomber/FormPlaneConfig.Designer.cs
generated
@ -175,7 +175,7 @@
|
|||||||
//
|
//
|
||||||
// panelGreen
|
// panelGreen
|
||||||
//
|
//
|
||||||
panelGreen.BackColor = Color.FromArgb(0, 192, 0);
|
panelGreen.BackColor = Color.Green;
|
||||||
panelGreen.Location = new Point(96, 43);
|
panelGreen.Location = new Point(96, 43);
|
||||||
panelGreen.Name = "panelGreen";
|
panelGreen.Name = "panelGreen";
|
||||||
panelGreen.Size = new Size(54, 54);
|
panelGreen.Size = new Size(54, 54);
|
||||||
|
@ -25,6 +25,18 @@ namespace AirBomber
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pictureWidth"></param>
|
/// <param name="pictureWidth"></param>
|
||||||
@ -77,5 +89,95 @@ namespace AirBomber
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по самолетам в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>record in _planeStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawningAirPlane? elem in record.Value.GetPlanes)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamWriter sw = new(filename);
|
||||||
|
sw.Write($"PlaneStorage{Environment.NewLine}{data}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по самолетам в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamReader sr = new(filename))
|
||||||
|
{
|
||||||
|
string str = sr.ReadLine();
|
||||||
|
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!str.StartsWith("PlaneStorage"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_planeStorages.Clear();
|
||||||
|
string strs = "";
|
||||||
|
|
||||||
|
while ((strs = sr.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
if (strs == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawningAirPlane? plane = elem?.CreateDrawningAirPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
if ((collection + plane) == -1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_planeStorages.Add(record[0], collection);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user