diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs
index 73ad088..4a20e8c 100644
--- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs
@@ -56,9 +56,9 @@ public abstract class AbstractCompany
/// Компания
/// Добавляемый объект
///
- public static bool operator +(AbstractCompany company, DrawningShip boat)
+ public static int operator +(AbstractCompany company, DrawningShip boat)
{
- return company._collection?.Insert(boat) ?? false;
+ return company._collection?.Insert(boat) ?? -1;
}
///
@@ -67,9 +67,9 @@ public abstract class AbstractCompany
/// Компания
/// Номер удаляемого объекта
///
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningShip operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection?.Remove(position) ?? null;
}
///
diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs
index 6c3cb97..2dc17b3 100644
--- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -19,7 +19,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert (T obj);
+ int Insert (T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -27,14 +27,14 @@ public interface ICollectionGenericObjects
/// /// Добавляемый объект
/// /// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert (T obj, int position);
+ int Insert (T obj, int position);
///
/// Удаление объекта из коллекции с конктретной позиции
///
/// /// Добавляемый объект
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove (int position);
+ T Remove (int position);
///
/// Получение объекта по позиции
diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs
index 7ca3490..9c601bf 100644
--- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ListGenericObjects.cs
@@ -16,8 +16,8 @@ public class ListGenericObjects : ICollectionGenericObjects
///
/// Список объектов, которые храним
///
- //private readonly List _collection;
- private readonly Dictionary _collection;
+ private readonly List _collection;
+
///
/// Максимально допустимое число объектов в списке
@@ -33,8 +33,7 @@ public class ListGenericObjects : ICollectionGenericObjects
///
public ListGenericObjects()
{
- //_collection = new();
- _collection = new Dictionary();
+ _collection = new();
}
public T? Get(int position)
@@ -49,78 +48,33 @@ public class ListGenericObjects : ICollectionGenericObjects
}
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
- if (Count == _maxCount) { return false; }
- //_collection.Add(obj);
- //return true;
-
- //допка
- int position = FindFirstNullPosition();
- if (position == -1)
- {
- return false;
- }
+ if (Count == _maxCount) { return -1; }
+ _collection.Add(obj);
+ return Count;
- _collection[position] = obj;
- return true;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
- //if (position < 0 || position >= Count || Count == _maxCount)
- //{
- // return false;
- //}
- //_collection.Insert(position, obj);
-
- //return false;
-
- //допка
- if (position < 0 || position >= _maxCount || Count == _maxCount || _collection.ContainsKey(position))
+ if (position < 0 || position >= Count || Count == _maxCount)
{
- return false;
+ return -1;
}
+ _collection.Insert(position, obj);
+
+ return position;
- _collection[position] = obj;
- return true;
}
- public bool Remove(int position)
+ public T Remove(int position)
{
- // if (position < 0 || position >= Count)
- // {
- // return false;
- // }
- // _collection.RemoveAt(position);
- // return true;
+ if (position >= Count || position < 0) return null;
+ T obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
- //допка
- if (!_collection.ContainsKey(position))
- {
- return false;
- }
-
- _collection.Remove(position);
- return true;
}
- ///
- /// Находит первую пустую позицию в словаре
- ///
- /// Индекс первой пустой позиции или -1, если такой не найдено
-
-
- //допка
- private int FindFirstNullPosition()
- {
- for (int i = 0; i < _maxCount; i++)
- {
- if (!_collection.ContainsKey(i) || _collection[i] == null)
- {
- return i;
- }
- }
- return -1;
- }
-
+
}
diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs
index 13f4640..42e883b 100644
--- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -50,21 +50,21 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return null;
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
return Insert(obj, 0);
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
if (position < 0 || position >= Count)
{
- return false;
+ return -1;
}
if (_collection[position] == null)
{
_collection[position] = obj;
- return true;
+ return position;
}
for (int i = position + 1; i < Count; i++)
@@ -72,7 +72,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
for (int i = position - 1; i >= 0; i--)
@@ -80,21 +80,21 @@ public class MassiveGenericObjects : ICollectionGenericObjects
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
- return false;
+ return -1;
}
- public bool Remove(int position)
+ public T Remove(int position)
{
if (position < 0 || position >= Count)
{
- return false;
+ return null ;
}
T obj = _collection[position];
_collection[position] = null;
- return true;
+ return obj;
}
}
\ No newline at end of file
diff --git a/ProjectContainerShip/ProjectContainerShip/Entities/EntityContainerShip.cs b/ProjectContainerShip/ProjectContainerShip/Entities/EntityContainerShip.cs
index 53ab768..3fe15a1 100644
--- a/ProjectContainerShip/ProjectContainerShip/Entities/EntityContainerShip.cs
+++ b/ProjectContainerShip/ProjectContainerShip/Entities/EntityContainerShip.cs
@@ -10,6 +10,8 @@ public class EntityContainerShip : EntityShip
///
public Color AdditionalColor { get; private set; }
+ public void SetAdditionalColor(Color color) => AdditionalColor = color;
+
///
/// Признак (опция) наличия крана
///
diff --git a/ProjectContainerShip/ProjectContainerShip/Entities/EntityShip.cs b/ProjectContainerShip/ProjectContainerShip/Entities/EntityShip.cs
index d223d46..90a3fd0 100644
--- a/ProjectContainerShip/ProjectContainerShip/Entities/EntityShip.cs
+++ b/ProjectContainerShip/ProjectContainerShip/Entities/EntityShip.cs
@@ -22,6 +22,8 @@ public class EntityShip
///
public Color BodyColor { get; private set; }
+ public void SetBodyColor(Color color) => BodyColor = color;
+
///
/// Шаг перемещения корабля
///
diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs
index babf245..fe7acee 100644
--- a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs
+++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs
@@ -31,7 +31,6 @@
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonAddShip = new Button();
- buttonAddContainerShip = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonRefresh = new Button();
buttonDelShip = new Button();
@@ -70,7 +69,6 @@
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddShip);
- panelCompanyTools.Controls.Add(buttonAddContainerShip);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonDelShip);
@@ -92,17 +90,6 @@
buttonAddShip.UseVisualStyleBackColor = true;
buttonAddShip.Click += ButtonAddShip_Click;
//
- // buttonAddContainerShip
- //
- buttonAddContainerShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddContainerShip.Location = new Point(3, 52);
- buttonAddContainerShip.Name = "buttonAddContainerShip";
- buttonAddContainerShip.Size = new Size(191, 34);
- buttonAddContainerShip.TabIndex = 2;
- buttonAddContainerShip.Text = "Добавление контейнеровоза";
- buttonAddContainerShip.UseVisualStyleBackColor = true;
- buttonAddContainerShip.Click += ButtonAddContainerShip_Click;
- //
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(3, 92);
@@ -285,7 +272,6 @@
private Button buttonAddShip;
private ComboBox comboBoxSelectorCompany;
private MaskedTextBox maskedTextBoxPosition;
- private Button buttonAddContainerShip;
private PictureBox pictureBox;
private Button buttonDelShip;
private Button buttonRefresh;
diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs
index f8bf5aa..1e3320b 100644
--- a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs
+++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs
@@ -9,16 +9,16 @@ namespace ProjectContainerShip
///
public partial class FormShipCollection : Form
{
- ///
- /// Компания
- ///
- private AbstractCompany? _company;
-
///
/// Хранилище коллекций
///
private readonly StorageCollection _storageCollection;
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
///
/// Конструктор
///
@@ -38,34 +38,32 @@ namespace ProjectContainerShip
panelCompanyTools.Enabled = false;
}
+
///
- /// Создание объекта класса-перемещения
+ /// Добавление корабля
///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
+ ///
+ ///
+ private void ButtonAddShip_Click(object sender, EventArgs e)
{
- if (_company == null)
+ FormShipConfig form = new();
+ // TODO передать метод
+ form.Show();
+ form.AddEvent(SetShip);
+ }
+
+ ///
+ /// Добавление лодки в коллекцию
+ ///
+ ///
+ private void SetShip(DrawningShip? ship)
+ {
+ if (_company == null || ship == null)
{
return;
}
- DrawningShip _drawningShip;
- Random random = new();
- switch (type)
- {
- case nameof(DrawningShip):
- _drawningShip = new DrawningShip(random.Next(30, 70), random.Next(100, 500),
- GetColor(random));
- break;
- case nameof(DrawningContainerShip):
- _drawningShip = new DrawningContainerShip(random.Next(30, 70), random.Next(100, 500),
- GetColor(random), GetColor(random),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
- if (_company + _drawningShip)
+ if (_company + ship != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -76,38 +74,6 @@ namespace ProjectContainerShip
}
}
-
- ///
- /// Добавление обычного корабля
- ///
- ///
- ///
- private void ButtonAddShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip));
-
- ///
- /// Добавление контейнеровоза
- ///
- ///
- ///
- private void ButtonAddContainerShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningContainerShip));
-
- ///
- /// Получение цвета
- ///
- /// Генератор случайных чисел
- ///
- private static Color GetColor(Random random)
- {
- Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- ColorDialog dialog = new();
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- color = dialog.Color;
- }
-
- return color;
- }
-
///
/// Удаление объекта
///
diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipConfig.Designer.cs b/ProjectContainerShip/ProjectContainerShip/FormShipConfig.Designer.cs
new file mode 100644
index 0000000..0237699
--- /dev/null
+++ b/ProjectContainerShip/ProjectContainerShip/FormShipConfig.Designer.cs
@@ -0,0 +1,357 @@
+namespace ProjectContainerShip
+{
+ partial class FormShipConfig
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBoxConfig = new GroupBox();
+ groupBoxColors = new GroupBox();
+ panelIndigo = new Panel();
+ panelViolet = new Panel();
+ panelGray = new Panel();
+ panelBlack = new Panel();
+ panelBlue = new Panel();
+ panelGreen = new Panel();
+ panelYellow = new Panel();
+ panelRed = new Panel();
+ checkBoxContainer = new CheckBox();
+ checkBoxCrane = new CheckBox();
+ numericUpDownWeight = new NumericUpDown();
+ numericUpDownSpeed = new NumericUpDown();
+ labelWeight = new Label();
+ labelSpeed = new Label();
+ labelModifiedObject = new Label();
+ labelSimpleObject = new Label();
+ pictureBoxObject = new PictureBox();
+ buttonAdd = new Button();
+ buttonCancel = new Button();
+ panelObject = new Panel();
+ labelAdditionalColor = new Label();
+ labelBodyColor = new Label();
+ groupBoxConfig.SuspendLayout();
+ groupBoxColors.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
+ panelObject.SuspendLayout();
+ SuspendLayout();
+ //
+ // groupBoxConfig
+ //
+ groupBoxConfig.Controls.Add(groupBoxColors);
+ groupBoxConfig.Controls.Add(checkBoxContainer);
+ groupBoxConfig.Controls.Add(checkBoxCrane);
+ groupBoxConfig.Controls.Add(numericUpDownWeight);
+ groupBoxConfig.Controls.Add(numericUpDownSpeed);
+ groupBoxConfig.Controls.Add(labelWeight);
+ groupBoxConfig.Controls.Add(labelSpeed);
+ groupBoxConfig.Controls.Add(labelModifiedObject);
+ groupBoxConfig.Controls.Add(labelSimpleObject);
+ groupBoxConfig.Dock = DockStyle.Left;
+ groupBoxConfig.Location = new Point(0, 0);
+ groupBoxConfig.Name = "groupBoxConfig";
+ groupBoxConfig.Size = new Size(522, 221);
+ groupBoxConfig.TabIndex = 0;
+ groupBoxConfig.TabStop = false;
+ groupBoxConfig.Text = "Параметры:";
+ //
+ // groupBoxColors
+ //
+ groupBoxColors.Controls.Add(panelIndigo);
+ groupBoxColors.Controls.Add(panelViolet);
+ groupBoxColors.Controls.Add(panelGray);
+ groupBoxColors.Controls.Add(panelBlack);
+ groupBoxColors.Controls.Add(panelBlue);
+ groupBoxColors.Controls.Add(panelGreen);
+ groupBoxColors.Controls.Add(panelYellow);
+ groupBoxColors.Controls.Add(panelRed);
+ groupBoxColors.Location = new Point(241, 19);
+ groupBoxColors.Name = "groupBoxColors";
+ groupBoxColors.Size = new Size(246, 109);
+ groupBoxColors.TabIndex = 8;
+ groupBoxColors.TabStop = false;
+ groupBoxColors.Text = "Цвета";
+ //
+ // panelIndigo
+ //
+ panelIndigo.BackColor = Color.Indigo;
+ panelIndigo.Location = new Point(192, 71);
+ panelIndigo.Name = "panelIndigo";
+ panelIndigo.Size = new Size(33, 32);
+ panelIndigo.TabIndex = 7;
+ //
+ // panelViolet
+ //
+ panelViolet.BackColor = Color.Violet;
+ panelViolet.Location = new Point(134, 71);
+ panelViolet.Name = "panelViolet";
+ panelViolet.Size = new Size(33, 32);
+ panelViolet.TabIndex = 6;
+ //
+ // panelGray
+ //
+ panelGray.BackColor = Color.Gray;
+ panelGray.Location = new Point(77, 71);
+ panelGray.Name = "panelGray";
+ panelGray.Size = new Size(33, 32);
+ panelGray.TabIndex = 5;
+ //
+ // panelBlack
+ //
+ panelBlack.BackColor = Color.Black;
+ panelBlack.Location = new Point(19, 71);
+ panelBlack.Name = "panelBlack";
+ panelBlack.Size = new Size(35, 32);
+ panelBlack.TabIndex = 4;
+ //
+ // panelBlue
+ //
+ panelBlue.BackColor = Color.Blue;
+ panelBlue.Location = new Point(192, 24);
+ panelBlue.Name = "panelBlue";
+ panelBlue.Size = new Size(33, 32);
+ panelBlue.TabIndex = 3;
+ //
+ // panelGreen
+ //
+ panelGreen.BackColor = Color.Green;
+ panelGreen.Location = new Point(134, 24);
+ panelGreen.Name = "panelGreen";
+ panelGreen.Size = new Size(33, 32);
+ panelGreen.TabIndex = 2;
+ //
+ // panelYellow
+ //
+ panelYellow.BackColor = Color.Yellow;
+ panelYellow.Location = new Point(77, 24);
+ panelYellow.Name = "panelYellow";
+ panelYellow.Size = new Size(33, 32);
+ panelYellow.TabIndex = 1;
+ //
+ // panelRed
+ //
+ panelRed.BackColor = Color.Red;
+ panelRed.Location = new Point(19, 24);
+ panelRed.Name = "panelRed";
+ panelRed.Size = new Size(35, 32);
+ panelRed.TabIndex = 0;
+ //
+ // checkBoxContainer
+ //
+ checkBoxContainer.AutoSize = true;
+ checkBoxContainer.Location = new Point(12, 138);
+ checkBoxContainer.Name = "checkBoxContainer";
+ checkBoxContainer.Size = new Size(211, 21);
+ checkBoxContainer.TabIndex = 7;
+ checkBoxContainer.Text = "Признак наличия контейнеров";
+ checkBoxContainer.UseVisualStyleBackColor = true;
+ //
+ // checkBoxCrane
+ //
+ checkBoxCrane.AutoSize = true;
+ checkBoxCrane.Location = new Point(12, 111);
+ checkBoxCrane.Name = "checkBoxCrane";
+ checkBoxCrane.Size = new Size(169, 21);
+ checkBoxCrane.TabIndex = 6;
+ checkBoxCrane.Text = "Признак наличия крана";
+ checkBoxCrane.UseVisualStyleBackColor = true;
+ //
+ // numericUpDownWeight
+ //
+ numericUpDownWeight.Location = new Point(79, 64);
+ numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
+ numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
+ numericUpDownWeight.Name = "numericUpDownWeight";
+ numericUpDownWeight.Size = new Size(120, 25);
+ numericUpDownWeight.TabIndex = 5;
+ numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
+ //
+ // numericUpDownSpeed
+ //
+ numericUpDownSpeed.Location = new Point(79, 19);
+ numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
+ numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
+ numericUpDownSpeed.Name = "numericUpDownSpeed";
+ numericUpDownSpeed.Size = new Size(120, 25);
+ numericUpDownSpeed.TabIndex = 4;
+ numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
+ //
+ // labelWeight
+ //
+ labelWeight.AutoSize = true;
+ labelWeight.Location = new Point(12, 66);
+ labelWeight.Name = "labelWeight";
+ labelWeight.Size = new Size(31, 17);
+ labelWeight.TabIndex = 3;
+ labelWeight.Text = "Вес:";
+ //
+ // labelSpeed
+ //
+ labelSpeed.AutoSize = true;
+ labelSpeed.Location = new Point(6, 27);
+ labelSpeed.Name = "labelSpeed";
+ labelSpeed.Size = new Size(67, 17);
+ labelSpeed.TabIndex = 2;
+ labelSpeed.Text = "Скорость:";
+ //
+ // labelModifiedObject
+ //
+ labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
+ labelModifiedObject.Location = new Point(366, 149);
+ labelModifiedObject.Name = "labelModifiedObject";
+ labelModifiedObject.Size = new Size(100, 32);
+ labelModifiedObject.TabIndex = 1;
+ labelModifiedObject.Text = "Продвинутый";
+ labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
+ labelModifiedObject.MouseDown += LabelObject_MouseDown;
+ //
+ // labelSimpleObject
+ //
+ labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
+ labelSimpleObject.Location = new Point(260, 149);
+ labelSimpleObject.Name = "labelSimpleObject";
+ labelSimpleObject.Size = new Size(100, 32);
+ labelSimpleObject.TabIndex = 0;
+ labelSimpleObject.Text = "Простой";
+ labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
+ labelSimpleObject.MouseDown += LabelObject_MouseDown;
+ //
+ // pictureBoxObject
+ //
+ pictureBoxObject.Location = new Point(13, 47);
+ pictureBoxObject.Name = "pictureBoxObject";
+ pictureBoxObject.Size = new Size(262, 128);
+ pictureBoxObject.TabIndex = 1;
+ pictureBoxObject.TabStop = false;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(828, 33);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(90, 50);
+ buttonAdd.TabIndex = 2;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += ButtonAdd_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(828, 131);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(90, 50);
+ buttonCancel.TabIndex = 3;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ //
+ // panelObject
+ //
+ panelObject.AllowDrop = true;
+ panelObject.Controls.Add(labelAdditionalColor);
+ panelObject.Controls.Add(labelBodyColor);
+ panelObject.Controls.Add(pictureBoxObject);
+ panelObject.Location = new Point(534, 19);
+ panelObject.Name = "panelObject";
+ panelObject.Size = new Size(288, 190);
+ panelObject.TabIndex = 4;
+ panelObject.DragDrop += PanelObject_DragDrop;
+ panelObject.DragEnter += PanelObject_DragEnter;
+ //
+ // labelAdditionalColor
+ //
+ labelAdditionalColor.AllowDrop = true;
+ labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
+ labelAdditionalColor.Location = new Point(175, 8);
+ labelAdditionalColor.Name = "labelAdditionalColor";
+ labelAdditionalColor.Size = new Size(100, 32);
+ labelAdditionalColor.TabIndex = 3;
+ labelAdditionalColor.Text = "Доп. цвет";
+ labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
+ labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
+ labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter;
+ //
+ // labelBodyColor
+ //
+ labelBodyColor.AllowDrop = true;
+ labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
+ labelBodyColor.Location = new Point(13, 8);
+ labelBodyColor.Name = "labelBodyColor";
+ labelBodyColor.Size = new Size(100, 32);
+ labelBodyColor.TabIndex = 2;
+ labelBodyColor.Text = "Цвет";
+ labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
+ labelBodyColor.DragDrop += labelBodyColor_DragDrop;
+ labelBodyColor.DragEnter += labelBodyColor_DragEnter;
+ //
+ // FormShipConfig
+ //
+ AutoScaleDimensions = new SizeF(7F, 17F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(964, 221);
+ Controls.Add(panelObject);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonAdd);
+ Controls.Add(groupBoxConfig);
+ Name = "FormShipConfig";
+ Text = "Создание объекта";
+ groupBoxConfig.ResumeLayout(false);
+ groupBoxConfig.PerformLayout();
+ groupBoxColors.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
+ panelObject.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxConfig;
+ private Label labelModifiedObject;
+ private Label labelSimpleObject;
+ private NumericUpDown numericUpDownWeight;
+ private NumericUpDown numericUpDownSpeed;
+ private Label labelWeight;
+ private Label labelSpeed;
+ private CheckBox checkBoxCrane;
+ private CheckBox checkBoxContainer;
+ private GroupBox groupBoxColors;
+ private Panel panelRed;
+ private Panel panelIndigo;
+ private Panel panelViolet;
+ private Panel panelGray;
+ private Panel panelBlack;
+ private Panel panelBlue;
+ private Panel panelGreen;
+ private Panel panelYellow;
+ private PictureBox pictureBoxObject;
+ private Button buttonAdd;
+ private Button buttonCancel;
+ private Panel panelObject;
+ private Label labelAdditionalColor;
+ private Label labelBodyColor;
+ }
+}
\ No newline at end of file
diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipConfig.cs b/ProjectContainerShip/ProjectContainerShip/FormShipConfig.cs
new file mode 100644
index 0000000..051d231
--- /dev/null
+++ b/ProjectContainerShip/ProjectContainerShip/FormShipConfig.cs
@@ -0,0 +1,168 @@
+using ProjectContainerShip.Drawnings;
+using ProjectContainerShip.Entities;
+
+namespace ProjectContainerShip;
+
+
+///
+/// Форма конфигурации объекта
+///
+public partial class FormShipConfig : Form
+{
+ ///
+ /// Объект - прорисовка корабля
+ ///
+ private DrawningShip? _ship = null;
+
+ private event Action? _shipDelegate;
+ public FormShipConfig()
+ {
+ InitializeComponent();
+
+ panelRed.MouseDown += Panel_MouseDown;
+ panelGreen.MouseDown += Panel_MouseDown;
+ panelBlue.MouseDown += Panel_MouseDown;
+ panelYellow.MouseDown += Panel_MouseDown;
+ panelViolet.MouseDown += Panel_MouseDown;
+ panelGray.MouseDown += Panel_MouseDown;
+ panelBlack.MouseDown += Panel_MouseDown;
+ panelIndigo.MouseDown += Panel_MouseDown;
+
+ buttonCancel.Click += (sender, e) => Close();
+ }
+
+ ///
+ /// Привязка внешнего метода к событию
+ ///
+ ///
+ public void AddEvent(Action shipDelegate)
+ {
+ _shipDelegate += shipDelegate;
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ private void DrawObject()
+ {
+ Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _ship?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
+ _ship?.SetPosition(15, 15);
+ _ship?.DrawTransport(gr);
+ pictureBoxObject.Image = bmp;
+ }
+
+ ///
+ /// Передаем информацию при нажатии на Label
+ ///
+ ///
+ ///
+ private void LabelObject_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ ///
+ /// Проверка получаемой информации (ее типа на соответствие требуемому)
+ ///
+ ///
+ ///
+ private void PanelObject_DragEnter(object sender, DragEventArgs e)
+ {
+ e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
+ }
+
+ ///
+ /// Действия при приеме перетаскиваемой информации
+ ///
+ ///
+ ///
+ private void PanelObject_DragDrop(object sender, DragEventArgs e)
+ {
+ switch (e.Data?.GetData(DataFormats.Text)?.ToString())
+ {
+ case "labelSimpleObject":
+ _ship = new DrawningShip((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
+ break;
+ case "labelModifiedObject":
+ _ship = new DrawningContainerShip((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
+ Color.Black, checkBoxCrane.Checked, checkBoxContainer.Checked);
+ break;
+ }
+ labelBodyColor.BackColor = Color.Empty;
+ labelAdditionalColor.BackColor = Color.Empty;
+ DrawObject();
+ }
+
+ ///
+ /// Передаем информацию при нажатии на Panel
+ ///
+ ///
+ ///
+ private void Panel_MouseDown(object? sender, MouseEventArgs e)
+ {
+ // TODO отправка цвета в Drag&Drop
+ (sender as Control)?.DoDragDrop((sender as Control)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
+ private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+
+ private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_ship != null)
+ {
+ _ship.EntityShip.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
+ DrawObject();
+ }
+ }
+
+ private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (_ship is DrawningContainerShip)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+ }
+
+ private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_ship?.EntityShip is EntityContainerShip _catamaran)
+ {
+ _catamaran.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
+ }
+ DrawObject();
+
+ }
+ ///
+ /// Передача объекта
+ ///
+ ///
+ ///
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ if (_ship != null)
+ {
+ _shipDelegate?.Invoke(_ship);
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipConfig.resx b/ProjectContainerShip/ProjectContainerShip/FormShipConfig.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectContainerShip/ProjectContainerShip/FormShipConfig.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file