Добавление сохранения и загрузки
This commit is contained in:
parent
6e9883932e
commit
7bb0be419d
@ -27,6 +27,9 @@ namespace AirPlaneWithRadar
|
|||||||
return _plain?.GetCurrentPosition() ?? default;
|
return _plain?.GetCurrentPosition() ?? default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetInfo() => _plain?.GetDataForSave();
|
||||||
|
public static IDrawingObject Create(string data) => new DrawingObjectPlane(data.CreateDrawningPlain());
|
||||||
|
|
||||||
public void MoveObject(Direction direction)
|
public void MoveObject(Direction direction)
|
||||||
{
|
{
|
||||||
_plain?.MoveTransport(direction);
|
_plain?.MoveTransport(direction);
|
||||||
|
42
AirPlaneWithRadar/AirPlaneWithRadar/ExtentionPlain.cs
Normal file
42
AirPlaneWithRadar/AirPlaneWithRadar/ExtentionPlain.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirPlaneWithRadar
|
||||||
|
{
|
||||||
|
internal static class ExtentionPlain
|
||||||
|
{
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
|
public static DrawingPlain CreateDrawningPlain(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingPlain(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingRadarPlane(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetDataForSave(this DrawingPlain drawningPlain)
|
||||||
|
{
|
||||||
|
var plain = drawningPlain.Plain;
|
||||||
|
var str = $"{plain.Speed}{_separatorForObject}{plain.Weight}{_separatorForObject}{plain.BodyColor.Name}";
|
||||||
|
if (plain is not RadioPlane radioPlane)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{_separatorForObject}{radioPlane.DopColor.Name}{_separatorForObject}{radioPlane.Radar}{_separatorForObject}{radioPlane.OilBox}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -45,9 +45,16 @@
|
|||||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
this.buttonAddPlain = new System.Windows.Forms.Button();
|
this.buttonAddPlain = new System.Windows.Forms.Button();
|
||||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.SaveToolStrip = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.loadToolStrip = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
this.groupBoxTools.SuspendLayout();
|
this.groupBoxTools.SuspendLayout();
|
||||||
this.groupBoxMaps.SuspendLayout();
|
this.groupBoxMaps.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.menuStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
@ -63,9 +70,11 @@
|
|||||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonAddPlain);
|
this.groupBoxTools.Controls.Add(this.buttonAddPlain);
|
||||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
this.groupBoxTools.Location = new System.Drawing.Point(927, 28);
|
||||||
|
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.groupBoxTools.Name = "groupBoxTools";
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 632);
|
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(233, 815);
|
||||||
this.groupBoxTools.TabIndex = 0;
|
this.groupBoxTools.TabIndex = 0;
|
||||||
this.groupBoxTools.TabStop = false;
|
this.groupBoxTools.TabStop = false;
|
||||||
this.groupBoxTools.Text = "Инструменты";
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
@ -77,18 +86,21 @@
|
|||||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||||
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||||
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||||
this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
|
this.groupBoxMaps.Location = new System.Drawing.Point(7, 29);
|
||||||
|
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||||
this.groupBoxMaps.Size = new System.Drawing.Size(192, 248);
|
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.groupBoxMaps.Size = new System.Drawing.Size(219, 331);
|
||||||
this.groupBoxMaps.TabIndex = 0;
|
this.groupBoxMaps.TabIndex = 0;
|
||||||
this.groupBoxMaps.TabStop = false;
|
this.groupBoxMaps.TabStop = false;
|
||||||
this.groupBoxMaps.Text = "Карты";
|
this.groupBoxMaps.Text = "Карты";
|
||||||
//
|
//
|
||||||
// buttonAddMap
|
// buttonAddMap
|
||||||
//
|
//
|
||||||
this.buttonAddMap.Location = new System.Drawing.Point(11, 80);
|
this.buttonAddMap.Location = new System.Drawing.Point(13, 107);
|
||||||
|
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonAddMap.Name = "buttonAddMap";
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
this.buttonAddMap.Size = new System.Drawing.Size(175, 35);
|
this.buttonAddMap.Size = new System.Drawing.Size(200, 47);
|
||||||
this.buttonAddMap.TabIndex = 2;
|
this.buttonAddMap.TabIndex = 2;
|
||||||
this.buttonAddMap.Text = "Добавить карту";
|
this.buttonAddMap.Text = "Добавить карту";
|
||||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
@ -96,9 +108,10 @@
|
|||||||
//
|
//
|
||||||
// buttonDeleteMap
|
// buttonDeleteMap
|
||||||
//
|
//
|
||||||
this.buttonDeleteMap.Location = new System.Drawing.Point(11, 206);
|
this.buttonDeleteMap.Location = new System.Drawing.Point(13, 275);
|
||||||
|
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35);
|
this.buttonDeleteMap.Size = new System.Drawing.Size(200, 47);
|
||||||
this.buttonDeleteMap.TabIndex = 4;
|
this.buttonDeleteMap.TabIndex = 4;
|
||||||
this.buttonDeleteMap.Text = "Удалить карту";
|
this.buttonDeleteMap.Text = "Удалить карту";
|
||||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
@ -107,18 +120,20 @@
|
|||||||
// listBoxMaps
|
// listBoxMaps
|
||||||
//
|
//
|
||||||
this.listBoxMaps.FormattingEnabled = true;
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
this.listBoxMaps.ItemHeight = 15;
|
this.listBoxMaps.ItemHeight = 20;
|
||||||
this.listBoxMaps.Location = new System.Drawing.Point(11, 121);
|
this.listBoxMaps.Location = new System.Drawing.Point(13, 161);
|
||||||
|
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.listBoxMaps.Name = "listBoxMaps";
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
this.listBoxMaps.Size = new System.Drawing.Size(175, 79);
|
this.listBoxMaps.Size = new System.Drawing.Size(199, 104);
|
||||||
this.listBoxMaps.TabIndex = 3;
|
this.listBoxMaps.TabIndex = 3;
|
||||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
// textBoxNewMapName
|
// textBoxNewMapName
|
||||||
//
|
//
|
||||||
this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22);
|
this.textBoxNewMapName.Location = new System.Drawing.Point(13, 29);
|
||||||
|
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
this.textBoxNewMapName.Size = new System.Drawing.Size(175, 23);
|
this.textBoxNewMapName.Size = new System.Drawing.Size(199, 27);
|
||||||
this.textBoxNewMapName.TabIndex = 0;
|
this.textBoxNewMapName.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// comboBoxSelectorMap
|
// comboBoxSelectorMap
|
||||||
@ -127,25 +142,28 @@
|
|||||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
"Простая карта"});
|
"Простая карта"});
|
||||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 51);
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 68);
|
||||||
|
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
|
||||||
this.comboBoxSelectorMap.TabIndex = 1;
|
this.comboBoxSelectorMap.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355);
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 473);
|
||||||
|
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
|
||||||
this.maskedTextBoxPosition.TabIndex = 2;
|
this.maskedTextBoxPosition.TabIndex = 2;
|
||||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
//
|
//
|
||||||
// buttonRemovePlain
|
// buttonRemovePlain
|
||||||
//
|
//
|
||||||
this.buttonRemovePlain.Location = new System.Drawing.Point(17, 384);
|
this.buttonRemovePlain.Location = new System.Drawing.Point(19, 512);
|
||||||
|
this.buttonRemovePlain.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonRemovePlain.Name = "buttonRemovePlain";
|
this.buttonRemovePlain.Name = "buttonRemovePlain";
|
||||||
this.buttonRemovePlain.Size = new System.Drawing.Size(175, 35);
|
this.buttonRemovePlain.Size = new System.Drawing.Size(200, 47);
|
||||||
this.buttonRemovePlain.TabIndex = 3;
|
this.buttonRemovePlain.TabIndex = 3;
|
||||||
this.buttonRemovePlain.Text = "Удалить самолет";
|
this.buttonRemovePlain.Text = "Удалить самолет";
|
||||||
this.buttonRemovePlain.UseVisualStyleBackColor = true;
|
this.buttonRemovePlain.UseVisualStyleBackColor = true;
|
||||||
@ -153,9 +171,10 @@
|
|||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 437);
|
this.buttonShowStorage.Location = new System.Drawing.Point(19, 583);
|
||||||
|
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
|
||||||
this.buttonShowStorage.TabIndex = 4;
|
this.buttonShowStorage.TabIndex = 4;
|
||||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
@ -166,9 +185,10 @@
|
|||||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down;
|
this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down;
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonDown.Location = new System.Drawing.Point(91, 582);
|
this.buttonDown.Location = new System.Drawing.Point(104, 748);
|
||||||
|
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonDown.Name = "buttonDown";
|
this.buttonDown.Name = "buttonDown";
|
||||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||||
this.buttonDown.TabIndex = 10;
|
this.buttonDown.TabIndex = 10;
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
@ -178,9 +198,10 @@
|
|||||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right;
|
this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right;
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonRight.Location = new System.Drawing.Point(127, 582);
|
this.buttonRight.Location = new System.Drawing.Point(145, 748);
|
||||||
|
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonRight.Name = "buttonRight";
|
this.buttonRight.Name = "buttonRight";
|
||||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||||
this.buttonRight.TabIndex = 9;
|
this.buttonRight.TabIndex = 9;
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
@ -190,9 +211,10 @@
|
|||||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left;
|
this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left;
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonLeft.Location = new System.Drawing.Point(55, 582);
|
this.buttonLeft.Location = new System.Drawing.Point(63, 748);
|
||||||
|
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||||
this.buttonLeft.TabIndex = 8;
|
this.buttonLeft.TabIndex = 8;
|
||||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
@ -202,18 +224,20 @@
|
|||||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up;
|
this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up;
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonUp.Location = new System.Drawing.Point(91, 546);
|
this.buttonUp.Location = new System.Drawing.Point(104, 700);
|
||||||
|
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonUp.Name = "buttonUp";
|
this.buttonUp.Name = "buttonUp";
|
||||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||||
this.buttonUp.TabIndex = 7;
|
this.buttonUp.TabIndex = 7;
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487);
|
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 649);
|
||||||
|
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
|
||||||
this.buttonShowOnMap.TabIndex = 5;
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
@ -221,9 +245,10 @@
|
|||||||
//
|
//
|
||||||
// buttonAddPlain
|
// buttonAddPlain
|
||||||
//
|
//
|
||||||
this.buttonAddPlain.Location = new System.Drawing.Point(17, 314);
|
this.buttonAddPlain.Location = new System.Drawing.Point(19, 419);
|
||||||
|
this.buttonAddPlain.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.buttonAddPlain.Name = "buttonAddPlain";
|
this.buttonAddPlain.Name = "buttonAddPlain";
|
||||||
this.buttonAddPlain.Size = new System.Drawing.Size(175, 35);
|
this.buttonAddPlain.Size = new System.Drawing.Size(200, 47);
|
||||||
this.buttonAddPlain.TabIndex = 1;
|
this.buttonAddPlain.TabIndex = 1;
|
||||||
this.buttonAddPlain.Text = "Добавить самолет";
|
this.buttonAddPlain.Text = "Добавить самолет";
|
||||||
this.buttonAddPlain.UseVisualStyleBackColor = true;
|
this.buttonAddPlain.UseVisualStyleBackColor = true;
|
||||||
@ -232,19 +257,65 @@
|
|||||||
// pictureBox
|
// pictureBox
|
||||||
//
|
//
|
||||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||||
|
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.pictureBox.Name = "pictureBox";
|
this.pictureBox.Name = "pictureBox";
|
||||||
this.pictureBox.Size = new System.Drawing.Size(811, 632);
|
this.pictureBox.Size = new System.Drawing.Size(927, 815);
|
||||||
this.pictureBox.TabIndex = 1;
|
this.pictureBox.TabIndex = 1;
|
||||||
this.pictureBox.TabStop = false;
|
this.pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.файлToolStripMenuItem});
|
||||||
|
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.menuStrip.Name = "menuStrip";
|
||||||
|
this.menuStrip.Size = new System.Drawing.Size(1160, 28);
|
||||||
|
this.menuStrip.TabIndex = 2;
|
||||||
|
this.menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.SaveToolStrip,
|
||||||
|
this.loadToolStrip});
|
||||||
|
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
this.файлToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
|
||||||
|
this.файлToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStrip
|
||||||
|
//
|
||||||
|
this.SaveToolStrip.Name = "SaveToolStrip";
|
||||||
|
this.SaveToolStrip.Size = new System.Drawing.Size(224, 26);
|
||||||
|
this.SaveToolStrip.Text = "Сохранение";
|
||||||
|
this.SaveToolStrip.Click += new System.EventHandler(this.SaveToolStrip_Click);
|
||||||
|
//
|
||||||
|
// loadToolStrip
|
||||||
|
//
|
||||||
|
this.loadToolStrip.Name = "loadToolStrip";
|
||||||
|
this.loadToolStrip.Size = new System.Drawing.Size(224, 26);
|
||||||
|
this.loadToolStrip.Text = "Загрузка";
|
||||||
|
this.loadToolStrip.Click += new System.EventHandler(this.loadToolStrip_Click);
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
this.openFileDialog.Filter = "txt file |*.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
this.saveFileDialog.Filter = "txt file |*.txt";
|
||||||
|
//
|
||||||
// FormMapWithSetPlains
|
// FormMapWithSetPlains
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1015, 632);
|
this.ClientSize = new System.Drawing.Size(1160, 843);
|
||||||
this.Controls.Add(this.pictureBox);
|
this.Controls.Add(this.pictureBox);
|
||||||
this.Controls.Add(this.groupBoxTools);
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Controls.Add(this.menuStrip);
|
||||||
|
this.MainMenuStrip = this.menuStrip;
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.Name = "FormMapWithSetPlains";
|
this.Name = "FormMapWithSetPlains";
|
||||||
this.Text = "Карта с набором объектов";
|
this.Text = "Карта с набором объектов";
|
||||||
this.groupBoxTools.ResumeLayout(false);
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
@ -252,7 +323,11 @@
|
|||||||
this.groupBoxMaps.ResumeLayout(false);
|
this.groupBoxMaps.ResumeLayout(false);
|
||||||
this.groupBoxMaps.PerformLayout();
|
this.groupBoxMaps.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.menuStrip.ResumeLayout(false);
|
||||||
|
this.menuStrip.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -273,5 +348,12 @@
|
|||||||
private ListBox listBoxMaps;
|
private ListBox listBoxMaps;
|
||||||
private TextBox textBoxNewMapName;
|
private TextBox textBoxNewMapName;
|
||||||
private Button buttonAddMap;
|
private Button buttonAddMap;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStrip;
|
||||||
|
private ToolStripMenuItem loadToolStrip;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -173,6 +173,25 @@ namespace AirPlaneWithRadar
|
|||||||
}
|
}
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||||
}
|
}
|
||||||
|
private void SaveToolStrip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadToolStrip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@
|
|||||||
this.labelDopColor.Text = "Доп. цвет";
|
this.labelDopColor.Text = "Доп. цвет";
|
||||||
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
||||||
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
|
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
|
||||||
//
|
//
|
||||||
// labelBaseColor
|
// labelBaseColor
|
||||||
@ -302,7 +302,7 @@
|
|||||||
this.labelBaseColor.Text = "Цвет";
|
this.labelBaseColor.Text = "Цвет";
|
||||||
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||||
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
|
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
//
|
//
|
||||||
// pictureBoxObject
|
// pictureBoxObject
|
||||||
//
|
//
|
||||||
|
@ -95,18 +95,7 @@ namespace AirPlaneWithRadar
|
|||||||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
{
|
|
||||||
if (e.Data.GetDataPresent(typeof(Color)))
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
|
|
||||||
{
|
{
|
||||||
if (e.Data.GetDataPresent(typeof(Color)))
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
{
|
{
|
||||||
@ -117,6 +106,7 @@ namespace AirPlaneWithRadar
|
|||||||
e.Effect = DragDropEffects.None;
|
e.Effect = DragDropEffects.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -15,5 +15,6 @@ namespace AirPlaneWithRadar
|
|||||||
void DrawningObject(Graphics g);
|
void DrawningObject(Graphics g);
|
||||||
|
|
||||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||||
|
string GetInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,25 @@ namespace AirPlaneWithRadar
|
|||||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetData(char separatorType, char separatorData)
|
||||||
|
{
|
||||||
|
string data = $"{_map.GetType().Name}{separatorType}";
|
||||||
|
foreach (var plain in _setPlains.GetPlains())
|
||||||
|
{
|
||||||
|
data += $"{plain.GetInfo()}{separatorData}";
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadData(string[] records)
|
||||||
|
{
|
||||||
|
foreach (var rec in records)
|
||||||
|
{
|
||||||
|
_setPlains.Insert(DrawingObjectPlane.Create(rec) as T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawPlains(Graphics g)
|
private void DrawPlains(Graphics g)
|
||||||
{
|
{
|
||||||
int CountWidth = _pictureWidth / _placeSizeWidth;
|
int CountWidth = _pictureWidth / _placeSizeWidth;
|
||||||
|
@ -8,7 +8,7 @@ namespace AirPlaneWithRadar
|
|||||||
{
|
{
|
||||||
internal class MapsCollection
|
internal class MapsCollection
|
||||||
{
|
{
|
||||||
readonly Dictionary<string, MapWithSetPlainGeneric<DrawingObjectPlane, AbstractMap>> _mapStorages;
|
readonly Dictionary<string, MapWithSetPlainGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||||
|
|
||||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
|
||||||
@ -16,9 +16,13 @@ namespace AirPlaneWithRadar
|
|||||||
|
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
private readonly char separatorDict = '|';
|
||||||
|
|
||||||
|
private readonly char separatorData = ';';
|
||||||
|
|
||||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_mapStorages = new Dictionary<string, MapWithSetPlainGeneric<DrawingObjectPlane, AbstractMap>>();
|
_mapStorages = new Dictionary<string, MapWithSetPlainGeneric<IDrawingObject, AbstractMap>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -28,7 +32,7 @@ namespace AirPlaneWithRadar
|
|||||||
|
|
||||||
if (_mapStorages.ContainsKey(name))
|
if (_mapStorages.ContainsKey(name))
|
||||||
return;
|
return;
|
||||||
_mapStorages.Add(name, new MapWithSetPlainGeneric<DrawingObjectPlane, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
_mapStorages.Add(name, new MapWithSetPlainGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +42,7 @@ namespace AirPlaneWithRadar
|
|||||||
_mapStorages.Remove(name);
|
_mapStorages.Remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapWithSetPlainGeneric<DrawingObjectPlane, AbstractMap> this[string ind]
|
public MapWithSetPlainGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -49,5 +53,68 @@ namespace AirPlaneWithRadar
|
|||||||
return _mapStorages[ind];
|
return _mapStorages[ind];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static void WriteToFile(string text, FileStream stream)
|
||||||
|
{
|
||||||
|
byte[] info = new UTF8Encoding(true).GetBytes(text);
|
||||||
|
stream.Write(info, 0, info.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
using (FileStream fs = new(filename, FileMode.Create))
|
||||||
|
{
|
||||||
|
WriteToFile($"MapsCollection{Environment.NewLine}", fs);
|
||||||
|
foreach (var storage in _mapStorages)
|
||||||
|
{
|
||||||
|
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string bufferTextFromFile = "";
|
||||||
|
using (FileStream fs = new(filename, FileMode.Open))
|
||||||
|
{
|
||||||
|
byte[] b = new byte[fs.Length];
|
||||||
|
UTF8Encoding temp = new(true);
|
||||||
|
while (fs.Read(b, 0, b.Length) > 0)
|
||||||
|
{
|
||||||
|
bufferTextFromFile += temp.GetString(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (!strs[0].Contains("MapsCollection"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//очищаем записи
|
||||||
|
_mapStorages.Clear();
|
||||||
|
for (int i = 1; i < strs.Length; ++i)
|
||||||
|
{
|
||||||
|
var elem = strs[i].Split(separatorDict);
|
||||||
|
AbstractMap map = null;
|
||||||
|
switch (elem[1])
|
||||||
|
{
|
||||||
|
case "SimpleMap":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_mapStorages.Add(elem[0], new MapWithSetPlainGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user