diff --git a/Sailboat/Sailboat/EntityBoat.cs b/Sailboat/Sailboat/EntityBoat.cs
index 53f3dca..1ec8804 100644
--- a/Sailboat/Sailboat/EntityBoat.cs
+++ b/Sailboat/Sailboat/EntityBoat.cs
@@ -30,6 +30,10 @@ namespace Sailboat.Entities
/// Шаг перемещения лодки
///
public double Step => (double)Speed * 100 / Weight;
+ public void ChangeColor(Color color)
+ {
+ BodyColor = color;
+ }
///
/// Конструктор с параметрами
diff --git a/Sailboat/Sailboat/EntitySailboat.cs b/Sailboat/Sailboat/EntitySailboat.cs
index 4568ffe..8e9f561 100644
--- a/Sailboat/Sailboat/EntitySailboat.cs
+++ b/Sailboat/Sailboat/EntitySailboat.cs
@@ -25,6 +25,10 @@ namespace Sailboat.Entities
/// Признак (опция) наличия паруса
///
public bool Sail { get; private set; }
+ public void ChangeAddColor(Color color)
+ {
+ AdditionalColor = color;
+ }
///
/// Инициализация полей объекта-класса парусной лодки
diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs
index 10332da..8a14039 100644
--- a/Sailboat/Sailboat/FormBoatCollection.cs
+++ b/Sailboat/Sailboat/FormBoatCollection.cs
@@ -56,10 +56,11 @@ namespace Sailboat
{
return;
}
- FormSailboat form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ FormBoatConfig form = new FormBoatConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ form.Show();
+ Action? boatDelegate = new((plane) =>
{
- if (obj + form.SelectedBoat)
+ if (obj + plane)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
@@ -68,7 +69,8 @@ namespace Sailboat
{
MessageBox.Show("Не удалось добавить объект");
}
- }
+ });
+ form.AddEvent(boatDelegate);
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)
diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs
new file mode 100644
index 0000000..34c6343
--- /dev/null
+++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs
@@ -0,0 +1,352 @@
+namespace Sailboat
+{
+ partial class FormBoatConfig
+ {
+ ///
+ /// 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()
+ {
+ groupBoxParameters = new GroupBox();
+ labelModifiedObject = new Label();
+ labelSimpleObject = new Label();
+ groupBoxColors = new GroupBox();
+ panelGray = new Panel();
+ panelBlack = new Panel();
+ panelPurple = new Panel();
+ panelWhite = new Panel();
+ panelRed = new Panel();
+ panelBlue = new Panel();
+ panelYellow = new Panel();
+ panelGreen = new Panel();
+ checkBoxSail = new CheckBox();
+ checkBoxHull = new CheckBox();
+ numericUpDownWeight = new NumericUpDown();
+ numericUpDownSpeed = new NumericUpDown();
+ labelWeight = new Label();
+ labelSpeed = new Label();
+ pictureBoxObject = new PictureBox();
+ PanelObject = new Panel();
+ labelAddColor = new Label();
+ labelColor = new Label();
+ buttonOk = new Button();
+ buttonCancel = new Button();
+ groupBoxParameters.SuspendLayout();
+ groupBoxColors.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
+ PanelObject.SuspendLayout();
+ SuspendLayout();
+ //
+ // groupBoxParameters
+ //
+ groupBoxParameters.Controls.Add(labelModifiedObject);
+ groupBoxParameters.Controls.Add(labelSimpleObject);
+ groupBoxParameters.Controls.Add(groupBoxColors);
+ groupBoxParameters.Controls.Add(checkBoxSail);
+ groupBoxParameters.Controls.Add(checkBoxHull);
+ groupBoxParameters.Controls.Add(numericUpDownWeight);
+ groupBoxParameters.Controls.Add(numericUpDownSpeed);
+ groupBoxParameters.Controls.Add(labelWeight);
+ groupBoxParameters.Controls.Add(labelSpeed);
+ groupBoxParameters.Location = new Point(12, 0);
+ groupBoxParameters.Name = "groupBoxParameters";
+ groupBoxParameters.Size = new Size(620, 283);
+ groupBoxParameters.TabIndex = 0;
+ groupBoxParameters.TabStop = false;
+ groupBoxParameters.Text = "Параметры";
+ //
+ // labelModifiedObject
+ //
+ labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
+ labelModifiedObject.Location = new Point(484, 219);
+ labelModifiedObject.Name = "labelModifiedObject";
+ labelModifiedObject.Size = new Size(109, 29);
+ labelModifiedObject.TabIndex = 8;
+ labelModifiedObject.Text = "Продвинутый";
+ labelModifiedObject.MouseDown += LableObject_MouseDown;
+ //
+ // labelSimpleObject
+ //
+ labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
+ labelSimpleObject.Location = new Point(375, 219);
+ labelSimpleObject.Name = "labelSimpleObject";
+ labelSimpleObject.Size = new Size(72, 29);
+ labelSimpleObject.TabIndex = 7;
+ labelSimpleObject.Text = "Простой";
+ labelSimpleObject.MouseDown += LableObject_MouseDown;
+ //
+ // groupBoxColors
+ //
+ groupBoxColors.Controls.Add(panelGray);
+ groupBoxColors.Controls.Add(panelBlack);
+ groupBoxColors.Controls.Add(panelPurple);
+ groupBoxColors.Controls.Add(panelWhite);
+ groupBoxColors.Controls.Add(panelRed);
+ groupBoxColors.Controls.Add(panelBlue);
+ groupBoxColors.Controls.Add(panelYellow);
+ groupBoxColors.Controls.Add(panelGreen);
+ groupBoxColors.Location = new Point(332, 35);
+ groupBoxColors.Name = "groupBoxColors";
+ groupBoxColors.Size = new Size(282, 172);
+ groupBoxColors.TabIndex = 6;
+ groupBoxColors.TabStop = false;
+ groupBoxColors.Text = "Цвета";
+ //
+ // panelGray
+ //
+ panelGray.BackColor = Color.Silver;
+ panelGray.Location = new Point(91, 102);
+ panelGray.Name = "panelGray";
+ panelGray.Size = new Size(40, 40);
+ panelGray.TabIndex = 0;
+ //
+ // panelBlack
+ //
+ panelBlack.BackColor = Color.Black;
+ panelBlack.Location = new Point(156, 102);
+ panelBlack.Name = "panelBlack";
+ panelBlack.Size = new Size(40, 40);
+ panelBlack.TabIndex = 0;
+ //
+ // panelPurple
+ //
+ panelPurple.BackColor = Color.Purple;
+ panelPurple.Location = new Point(225, 102);
+ panelPurple.Name = "panelPurple";
+ panelPurple.Size = new Size(40, 40);
+ panelPurple.TabIndex = 0;
+ //
+ // panelWhite
+ //
+ panelWhite.BackColor = Color.White;
+ panelWhite.Location = new Point(19, 102);
+ panelWhite.Name = "panelWhite";
+ panelWhite.Size = new Size(40, 40);
+ panelWhite.TabIndex = 15;
+ //
+ // panelRed
+ //
+ panelRed.BackColor = Color.Red;
+ panelRed.Location = new Point(19, 34);
+ panelRed.Name = "panelRed";
+ panelRed.Size = new Size(40, 40);
+ panelRed.TabIndex = 0;
+ //
+ // panelBlue
+ //
+ panelBlue.BackColor = Color.Blue;
+ panelBlue.Location = new Point(156, 34);
+ panelBlue.Name = "panelBlue";
+ panelBlue.Size = new Size(40, 40);
+ panelBlue.TabIndex = 14;
+ //
+ // panelYellow
+ //
+ panelYellow.BackColor = Color.Yellow;
+ panelYellow.Location = new Point(225, 34);
+ panelYellow.Name = "panelYellow";
+ panelYellow.Size = new Size(40, 40);
+ panelYellow.TabIndex = 0;
+ //
+ // panelGreen
+ //
+ panelGreen.BackColor = Color.Green;
+ panelGreen.Location = new Point(89, 34);
+ panelGreen.Name = "panelGreen";
+ panelGreen.Size = new Size(40, 40);
+ panelGreen.TabIndex = 0;
+ //
+ // checkBoxSail
+ //
+ checkBoxSail.AutoSize = true;
+ checkBoxSail.Location = new Point(17, 203);
+ checkBoxSail.Name = "checkBoxSail";
+ checkBoxSail.Size = new Size(206, 24);
+ checkBoxSail.TabIndex = 5;
+ checkBoxSail.Text = "Признак наличия паруса";
+ checkBoxSail.UseVisualStyleBackColor = true;
+ //
+ // checkBoxHull
+ //
+ checkBoxHull.AutoSize = true;
+ checkBoxHull.Location = new Point(17, 173);
+ checkBoxHull.Name = "checkBoxHull";
+ checkBoxHull.Size = new Size(299, 24);
+ checkBoxHull.TabIndex = 4;
+ checkBoxHull.Text = "Признак наличия усиленного корпуса";
+ checkBoxHull.UseVisualStyleBackColor = true;
+ //
+ // numericUpDownWeight
+ //
+ numericUpDownWeight.Location = new Point(137, 112);
+ 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(150, 27);
+ numericUpDownWeight.TabIndex = 3;
+ numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
+ //
+ // numericUpDownSpeed
+ //
+ numericUpDownSpeed.Location = new Point(137, 71);
+ 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(150, 27);
+ numericUpDownSpeed.TabIndex = 2;
+ numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
+ //
+ // labelWeight
+ //
+ labelWeight.AutoSize = true;
+ labelWeight.Location = new Point(42, 114);
+ labelWeight.Name = "labelWeight";
+ labelWeight.Size = new Size(36, 20);
+ labelWeight.TabIndex = 1;
+ labelWeight.Text = "Вес:";
+ //
+ // labelSpeed
+ //
+ labelSpeed.AutoSize = true;
+ labelSpeed.Location = new Point(42, 73);
+ labelSpeed.Name = "labelSpeed";
+ labelSpeed.Size = new Size(76, 20);
+ labelSpeed.TabIndex = 0;
+ labelSpeed.Text = "Скорость:";
+ //
+ // pictureBoxObject
+ //
+ pictureBoxObject.Location = new Point(14, 37);
+ pictureBoxObject.Name = "pictureBoxObject";
+ pictureBoxObject.Size = new Size(213, 191);
+ pictureBoxObject.TabIndex = 9;
+ pictureBoxObject.TabStop = false;
+ //
+ // PanelObject
+ //
+ PanelObject.AllowDrop = true;
+ PanelObject.Controls.Add(labelAddColor);
+ PanelObject.Controls.Add(labelColor);
+ PanelObject.Controls.Add(pictureBoxObject);
+ PanelObject.Location = new Point(638, 12);
+ PanelObject.Name = "PanelObject";
+ PanelObject.Size = new Size(239, 236);
+ PanelObject.TabIndex = 9;
+ PanelObject.DragDrop += PanelObject_DragDrop;
+ PanelObject.DragEnter += PanelObject_DragEnter;
+ //
+ // labelAddColor
+ //
+ labelAddColor.AllowDrop = true;
+ labelAddColor.BorderStyle = BorderStyle.FixedSingle;
+ labelAddColor.Location = new Point(133, 9);
+ labelAddColor.Name = "labelAddColor";
+ labelAddColor.Size = new Size(86, 25);
+ labelAddColor.TabIndex = 11;
+ labelAddColor.Text = "Доп. цвет";
+ labelAddColor.DragDrop += addColorLabel_DragDrop;
+ labelAddColor.DragEnter += LabelColor_DragEnter;
+ //
+ // labelColor
+ //
+ labelColor.AllowDrop = true;
+ labelColor.BorderStyle = BorderStyle.FixedSingle;
+ labelColor.Location = new Point(41, 9);
+ labelColor.Name = "labelColor";
+ labelColor.Size = new Size(48, 25);
+ labelColor.TabIndex = 10;
+ labelColor.Text = "Цвет";
+ labelColor.DragDrop += LabelColor_DragDrop;
+ labelColor.DragEnter += LabelColor_DragEnter;
+ //
+ // buttonOk
+ //
+ buttonOk.Location = new Point(652, 254);
+ buttonOk.Name = "buttonOk";
+ buttonOk.Size = new Size(94, 29);
+ buttonOk.TabIndex = 12;
+ buttonOk.Text = "Добавить";
+ buttonOk.UseVisualStyleBackColor = true;
+ buttonOk.Click += buttonOk_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(763, 254);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(94, 29);
+ buttonCancel.TabIndex = 13;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ //
+ // FormBoatConfig
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(887, 298);
+ Controls.Add(buttonOk);
+ Controls.Add(buttonCancel);
+ Controls.Add(PanelObject);
+ Controls.Add(groupBoxParameters);
+ Name = "FormBoatConfig";
+ Text = "Создание объекта";
+ groupBoxParameters.ResumeLayout(false);
+ groupBoxParameters.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 groupBoxParameters;
+ private CheckBox checkBoxSail;
+ private CheckBox checkBoxHull;
+ private NumericUpDown numericUpDownWeight;
+ private NumericUpDown numericUpDownSpeed;
+ private Label labelWeight;
+ private Label labelSpeed;
+ private GroupBox groupBoxColors;
+ private Label labelModifiedObject;
+ private Label labelSimpleObject;
+ private PictureBox pictureBoxObject;
+ private Panel PanelObject;
+ private Label labelAddColor;
+ private Label labelColor;
+ private Button buttonOk;
+ private Button buttonCancel;
+ private Panel panelGray;
+ private Panel panelBlack;
+ private Panel panelPurple;
+ private Panel panelWhite;
+ private Panel panelRed;
+ private Panel panelBlue;
+ private Panel panelYellow;
+ private Panel panelGreen;
+ }
+}
\ No newline at end of file
diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs
new file mode 100644
index 0000000..db143ce
--- /dev/null
+++ b/Sailboat/Sailboat/FormBoatConfig.cs
@@ -0,0 +1,130 @@
+using Sailboat.DrawingObjects;
+using Sailboat.Entities;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Sailboat
+{
+ public partial class FormBoatConfig : Form
+ {
+ DrawingBoat? _boat = null;
+ private event Action? EventAddBoat;
+ public int _pictureWidth { get; private set; }
+ public int _pictureHeight { get; private set; }
+ public FormBoatConfig(int pictureWidth, int pictureHeight)
+ {
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ InitializeComponent();
+ panelBlack.MouseDown += PanelColor_MouseDown;
+ panelPurple.MouseDown += PanelColor_MouseDown;
+ panelGray.MouseDown += PanelColor_MouseDown;
+ panelGreen.MouseDown += PanelColor_MouseDown;
+ panelRed.MouseDown += PanelColor_MouseDown;
+ panelWhite.MouseDown += PanelColor_MouseDown;
+ panelYellow.MouseDown += PanelColor_MouseDown;
+ panelBlue.MouseDown += PanelColor_MouseDown;
+
+ buttonCancel.Click += (s, e) => Close();
+ }
+
+ private void DrawBoat()
+ {
+ Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _boat?.SetPosition(5, 5);
+ _boat?.DrawTransport(gr);
+ pictureBoxObject.Image = bmp;
+ }
+ internal void AddEvent(Action ev)
+ {
+ if (EventAddBoat == null)
+ {
+ EventAddBoat = ev;
+ }
+ else
+ {
+ EventAddBoat += ev;
+ }
+ }
+
+ private void PanelColor_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ private void LableObject_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Label)?.DoDragDrop((sender as Label)?.Name,
+ DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ private void PanelObject_DragEnter(object sender, DragEventArgs e)
+ {
+
+ if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+
+ private void PanelObject_DragDrop(object sender, DragEventArgs e)
+ {
+ switch (e.Data?.GetData(DataFormats.Text).ToString())
+ {
+ case "labelSimpleObject":
+ _boat = new DrawingBoat((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
+ break;
+ case "labelModifiedObject":
+ _boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
+ checkBoxSail.Checked, _pictureWidth, _pictureHeight);
+ break;
+ }
+ DrawBoat();
+ }
+ private void LabelColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_boat?.EntityBoat == null)
+ return;
+ Color bodyColor = (Color)e.Data.GetData(typeof(Color));
+ _boat.EntityBoat.ChangeColor(bodyColor);
+ DrawBoat();
+ }
+ private void addColorLabel_DragDrop(object sender, DragEventArgs e)
+ {
+ if ((_boat?.EntityBoat == null) || (_boat is DrawingSailboat == false))
+ return;
+ ((EntitySailboat)_boat.EntityBoat).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
+ DrawBoat();
+ }
+ private void LabelColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+ private void buttonOk_Click(object sender, EventArgs e)
+ {
+ EventAddBoat?.Invoke(_boat);
+ Close();
+ }
+ }
+}
diff --git a/Sailboat/Sailboat/FormBoatConfig.resx b/Sailboat/Sailboat/FormBoatConfig.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Sailboat/Sailboat/FormBoatConfig.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