diff --git a/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs index fda869a..ef187b7 100644 --- a/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs @@ -12,7 +12,7 @@ namespace ProjectExcavator.DrawingObjects public class DrawingExcavator { /// - /// Получение объекта IMoveableObject из объекта DrawingExcavator + /// Получение объекта IMoveableObject из объекта DrawningCar /// public IMoveableObject GetMoveableObject => new DrawingObjectExcavator(this); /// @@ -22,11 +22,11 @@ namespace ProjectExcavator.DrawingObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// /// Левая координата прорисовки экскаватора /// @@ -62,7 +62,10 @@ namespace ProjectExcavator.DrawingObjects EntityExcavator = new EntityExcavator(speed, weight, bodyColor); } } - + public void bodyColor(Color color) + { + EntityExcavator.BodyColor = color; + } /// /// Конструктор /// @@ -199,7 +202,6 @@ namespace ProjectExcavator.DrawingObjects //цвета Pen pen = new(Color.Black); Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor); - Brush brBlack = new SolidBrush(Color.Black); //отрисовка экскаватора без ковша g.DrawRectangle(pen, _startPosX + 50, _startPosY + 35, 75, 25); @@ -229,13 +231,7 @@ namespace ProjectExcavator.DrawingObjects g.FillPie(bodyBrush, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180); g.FillPie(bodyBrush, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180); g.FillRectangle(bodyBrush, _startPosX + 44, _startPosY + 65, 86, 20); - g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 68, 15, 15); - g.FillEllipse(brBlack, _startPosX + 120, _startPosY + 68, 15, 15); - g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 76, 8, 8); - g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 76, 8, 8); - g.FillEllipse(brBlack, _startPosX + 100, _startPosY + 76, 8, 8); - g.FillEllipse(brBlack, _startPosX + 72, _startPosY + 68, 6, 6); - g.FillEllipse(brBlack, _startPosX + 92, _startPosY + 68, 6, 6); + } } } diff --git a/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs b/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs index 56239fa..c4e9323 100644 --- a/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs +++ b/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs @@ -32,60 +32,65 @@ namespace ProjectExcavator.DrawingObjects additionalColor, kovsh, katki); } } + public void additionalColor(Color color) + { + (EntityExcavator as EntityExcavatorKovsh).AdditionalColor = color; + } public override void DrawTransport(Graphics g) { if (EntityExcavator is not EntityExcavatorKovsh excavatorKovsh) { return; } - //цвета Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(excavatorKovsh.AdditionalColor); // ковш - g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10); - g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5); - g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7); - g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45); - g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45); - g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180); - g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY); - g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10); - g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12); - g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16); - g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29); + if (excavatorKovsh.Kovsh) + { + g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10); + g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5); + g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7); + g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45); + g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45); + g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180); + g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY); + g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10); + g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12); + g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16); + g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29); - g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7); - g.FillPie(additionalBrush, _startPosX, _startPosY + 44, 28, 30, 90, 180); - Point point1 = new Point(_startPosX + 50, _startPosY + 35); - Point point2 = new Point(_startPosX + 10, _startPosY + 10); - Point point3 = new Point(_startPosX + 12, _startPosY + 5); - Point point4 = new Point(_startPosX + 58, _startPosY + 35); - Point[] truba_1 = { point1, point2, point3, point4, point1 }; - g.FillPolygon(additionalBrush, truba_1); + g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7); + g.FillPie(additionalBrush, _startPosX, _startPosY + 44, 28, 30, 90, 180); + Point point1 = new Point(_startPosX + 50, _startPosY + 35); + Point point2 = new Point(_startPosX + 10, _startPosY + 10); + Point point3 = new Point(_startPosX + 12, _startPosY + 5); + Point point4 = new Point(_startPosX + 58, _startPosY + 35); + Point[] truba_1 = { point1, point2, point3, point4, point1 }; + g.FillPolygon(additionalBrush, truba_1); - Point point5 = new Point(_startPosX + 10, _startPosY + 10); - Point point6 = new Point(_startPosX + 10, _startPosY + 45); - Point point7 = new Point(_startPosX + 14, _startPosY + 45); - Point point8 = new Point(_startPosX + 14, _startPosY + 5); - Point[] truba_2 = { point5, point6, point7, point8, point5 }; - g.FillPolygon(additionalBrush, truba_2); + Point point5 = new Point(_startPosX + 10, _startPosY + 10); + Point point6 = new Point(_startPosX + 10, _startPosY + 45); + Point point7 = new Point(_startPosX + 14, _startPosY + 45); + Point point8 = new Point(_startPosX + 14, _startPosY + 5); + Point[] truba_2 = { point5, point6, point7, point8, point5 }; + g.FillPolygon(additionalBrush, truba_2); - Point point9 = new Point(_startPosX + 14, _startPosY + 5); - Point point10 = new Point(_startPosX + 14, _startPosY); - Point point11 = new Point(_startPosX + 7, _startPosY + 10); - Point[] triangle = { point9, point10, point11, point9 }; - g.FillPolygon(additionalBrush, triangle); - - Point point12 = new Point(_startPosX + 14, _startPosY); - Point point13 = new Point(_startPosX + 50, _startPosY + 12); - Point point14 = new Point(_startPosX + 50, _startPosY + 16); - Point point15 = new Point(_startPosX + 14, _startPosY); - Point[] krepl = { point12, point13, point14, point15, point12 }; - g.FillPolygon(additionalBrush, krepl); + Point point9 = new Point(_startPosX + 14, _startPosY + 5); + Point point10 = new Point(_startPosX + 14, _startPosY); + Point point11 = new Point(_startPosX + 7, _startPosY + 10); + Point[] triangle = { point9, point10, point11, point9 }; + g.FillPolygon(additionalBrush, triangle); + Point point12 = new Point(_startPosX + 14, _startPosY); + Point point13 = new Point(_startPosX + 50, _startPosY + 12); + Point point14 = new Point(_startPosX + 50, _startPosY + 16); + Point point15 = new Point(_startPosX + 14, _startPosY); + Point[] krepl = { point12, point13, point14, point15, point12 }; + g.FillPolygon(additionalBrush, krepl); + } base.DrawTransport(g); // катки diff --git a/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs index 74aa72c..f8fce06 100644 --- a/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs @@ -8,7 +8,7 @@ using ProjectExcavator.DrawingObjects; namespace ProjectExcavator.MovementStrategy { /// - /// Реализация интерфейса IDrawningObject для работы с объектом DrawingExcavator (паттерн Adapter) + /// Реализация интерфейса IDrawningObject для работы с объектом DrawningExcavator (паттерн Adapter) /// public class DrawingObjectExcavator : IMoveableObject { diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs index 188f112..e48b707 100644 --- a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs @@ -19,7 +19,7 @@ namespace ProjectExcavator.Entities /// /// Основной цвет /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг перемещения экскаватора /// diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs b/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs index 18feb4f..e61ecc5 100644 --- a/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs +++ b/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs @@ -14,7 +14,7 @@ namespace ProjectExcavator.Entities /// /// Дополнительный цвет (для опциональных элементов) /// - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } /// /// Ковш /// diff --git a/ProjectExcavator/ProjectExcavator/ExcavatorDelegate.cs b/ProjectExcavator/ProjectExcavator/ExcavatorDelegate.cs new file mode 100644 index 0000000..5a07d19 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/ExcavatorDelegate.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectExcavator.DrawingObjects; + +namespace ProjectExcavator.Excavators +{ + /// + /// Делегат для передачи объекта-экскаватора + /// + /// + public delegate void ExcavatorDelegate(DrawingExcavator excavator); +} diff --git a/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs b/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs index a904509..2c60978 100644 --- a/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs +++ b/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs @@ -56,7 +56,8 @@ namespace ProjectExcavator.Generics /// /// /// - public static bool operator +(ExcavatorGenericCollection collect, T? obj) + public static bool operator +(ExcavatorGenericCollection collect, T? + obj) { if (obj == null) { @@ -71,7 +72,8 @@ namespace ProjectExcavator.Generics /// /// /// - public static T? operator -(ExcavatorGenericCollection collect, int pos) + public static T? operator -(ExcavatorGenericCollection collect, int +pos) { T? obj = collect._collection[pos]; if (obj != null) @@ -133,12 +135,17 @@ namespace ProjectExcavator.Generics int height = _pictureHeight / _placeSizeHeight; for (int i = 0; i < _collection.Count; i++) { + // TODO получение объекта T? excavator = _collection[i]; if (excavator == null) continue; + excavator._pictureHeight = _pictureHeight; + excavator._pictureWidth = _pictureWidth; int r = i / width; int s = width - 1 - (i % width); + // TODO установка позиции excavator.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight); + // TODO прорисовка объекта excavator.DrawTransport(g); } } diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs index faae433..2c6cca7 100644 --- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs @@ -1,7 +1,7 @@ using ProjectExcavator.DrawingObjects; using ProjectExcavator.Generics; using ProjectExcavator.MovementStrategy; - +using ProjectExcavator.Excavators; namespace ProjectExcavator { /// @@ -41,6 +41,13 @@ namespace ProjectExcavator index < listBoxStorages.Items.Count) { listBoxStorages.SelectedIndex = index; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowExcavator(); } } /// @@ -87,12 +94,6 @@ namespace ProjectExcavator _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - if (obj == null) - { - return; - } - pictureBoxCollection.Image = obj.ShowExcavator(); } } /// @@ -112,10 +113,11 @@ namespace ProjectExcavator { return; } - FormExcavator form = new(); - if (form.ShowDialog() == DialogResult.OK) + FormExcavatorConfig form = new FormExcavatorConfig(); + Action? ExcavatorDelegate = (excavator) => { - if (obj + form.SelectedExcavator) + bool SelectedExcavator = obj + excavator; + if (SelectedExcavator) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowExcavator(); @@ -124,7 +126,9 @@ namespace ProjectExcavator { MessageBox.Show("Не удалось добавить объект"); } - } + }; + form.AddEvent(ExcavatorDelegate); + form.Show(); } /// /// Удаление объекта из набора diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs new file mode 100644 index 0000000..19d6baa --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.Designer.cs @@ -0,0 +1,385 @@ +namespace ProjectExcavator +{ + partial class FormExcavatorConfig + { + /// + /// 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() + { + this.groupBoxParam = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColor = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBox_Katki = new System.Windows.Forms.CheckBox(); + this.checkBox_Kovsh = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelweight = new System.Windows.Forms.Label(); + this.labelspeed = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelAdditionalColor = new System.Windows.Forms.Label(); + this.labelMainColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxParam.SuspendLayout(); + this.groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxParam + // + this.groupBoxParam.Controls.Add(this.labelModifiedObject); + this.groupBoxParam.Controls.Add(this.labelSimpleObject); + this.groupBoxParam.Controls.Add(this.groupBoxColor); + this.groupBoxParam.Controls.Add(this.checkBox_Katki); + this.groupBoxParam.Controls.Add(this.checkBox_Kovsh); + this.groupBoxParam.Controls.Add(this.numericUpDownWeight); + this.groupBoxParam.Controls.Add(this.numericUpDownSpeed); + this.groupBoxParam.Controls.Add(this.labelweight); + this.groupBoxParam.Controls.Add(this.labelspeed); + this.groupBoxParam.Location = new System.Drawing.Point(12, 12); + this.groupBoxParam.Name = "groupBoxParam"; + this.groupBoxParam.Size = new System.Drawing.Size(562, 437); + this.groupBoxParam.TabIndex = 0; + this.groupBoxParam.TabStop = false; + this.groupBoxParam.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(373, 258); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(100, 23); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(217, 258); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(100, 23); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBoxColor + // + this.groupBoxColor.Controls.Add(this.panelPurple); + this.groupBoxColor.Controls.Add(this.panelBlack); + this.groupBoxColor.Controls.Add(this.panelGray); + this.groupBoxColor.Controls.Add(this.panelWhite); + this.groupBoxColor.Controls.Add(this.panelYellow); + this.groupBoxColor.Controls.Add(this.panelGreen); + this.groupBoxColor.Controls.Add(this.panelBlue); + this.groupBoxColor.Controls.Add(this.panelRed); + this.groupBoxColor.Location = new System.Drawing.Point(201, 54); + this.groupBoxColor.Name = "groupBoxColor"; + this.groupBoxColor.Size = new System.Drawing.Size(292, 170); + this.groupBoxColor.TabIndex = 6; + this.groupBoxColor.TabStop = false; + this.groupBoxColor.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(222, 102); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(50, 50); + this.panelPurple.TabIndex = 7; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(156, 102); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(49, 50); + this.panelBlack.TabIndex = 6; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(87, 102); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(51, 50); + this.panelGray.TabIndex = 5; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(16, 102); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(53, 50); + this.panelWhite.TabIndex = 4; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(222, 36); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(50, 50); + this.panelYellow.TabIndex = 3; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(87, 36); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(51, 50); + this.panelGreen.TabIndex = 2; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(155, 36); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(50, 50); + this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(16, 37); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(51, 49); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBox_Katki + // + this.checkBox_Katki.AutoSize = true; + this.checkBox_Katki.Location = new System.Drawing.Point(0, 205); + this.checkBox_Katki.Name = "checkBox_Katki"; + this.checkBox_Katki.Size = new System.Drawing.Size(114, 19); + this.checkBox_Katki.TabIndex = 5; + this.checkBox_Katki.Text = "Наличие катков"; + this.checkBox_Katki.UseVisualStyleBackColor = true; + // + // checkBox_Kovsh + // + this.checkBox_Kovsh.AutoSize = true; + this.checkBox_Kovsh.Location = new System.Drawing.Point(0, 156); + this.checkBox_Kovsh.Name = "checkBox_Kovsh"; + this.checkBox_Kovsh.Size = new System.Drawing.Size(114, 19); + this.checkBox_Kovsh.TabIndex = 4; + this.checkBox_Kovsh.Text = "Наличие ковша"; + this.checkBox_Kovsh.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(74, 91); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 55); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelweight + // + this.labelweight.AutoSize = true; + this.labelweight.Location = new System.Drawing.Point(6, 95); + this.labelweight.Name = "labelweight"; + this.labelweight.Size = new System.Drawing.Size(29, 15); + this.labelweight.TabIndex = 1; + this.labelweight.Text = "Вес:"; + // + // labelspeed + // + this.labelspeed.AutoSize = true; + this.labelspeed.Location = new System.Drawing.Point(6, 57); + this.labelspeed.Name = "labelspeed"; + this.labelspeed.Size = new System.Drawing.Size(62, 15); + this.labelspeed.TabIndex = 0; + this.labelspeed.Text = "Скорость:"; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelAdditionalColor); + this.panelObject.Controls.Add(this.labelMainColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(593, 22); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(279, 343); + this.panelObject.TabIndex = 1; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // labelAdditionalColor + // + this.labelAdditionalColor.AllowDrop = true; + this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdditionalColor.Location = new System.Drawing.Point(166, 38); + this.labelAdditionalColor.Name = "labelAdditionalColor"; + this.labelAdditionalColor.Size = new System.Drawing.Size(100, 23); + this.labelAdditionalColor.TabIndex = 2; + this.labelAdditionalColor.Text = "Доп. цвет"; + this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // labelMainColor + // + this.labelMainColor.AllowDrop = true; + this.labelMainColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelMainColor.Location = new System.Drawing.Point(13, 38); + this.labelMainColor.Name = "labelMainColor"; + this.labelMainColor.Size = new System.Drawing.Size(100, 23); + this.labelMainColor.TabIndex = 1; + this.labelMainColor.Text = "Цвет"; + this.labelMainColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelMainColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(13, 68); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(253, 260); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(606, 382); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(75, 23); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(784, 382); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormExcavatorConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxParam); + this.Name = "FormExcavatorConfig"; + this.Text = "FormExcavatorConfig"; + this.groupBoxParam.ResumeLayout(false); + this.groupBoxParam.PerformLayout(); + this.groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxParam; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelweight; + private Label labelspeed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColor; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelGreen; + private Panel panelBlue; + private Panel panelRed; + private CheckBox checkBox_Katki; + private CheckBox checkBox_Kovsh; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelMainColor; + private PictureBox pictureBoxObject; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs new file mode 100644 index 0000000..46f04a1 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs @@ -0,0 +1,162 @@ +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; +using ProjectExcavator.DrawingObjects; +using ProjectExcavator.Excavators; + +namespace ProjectExcavator +{ + public partial class FormExcavatorConfig : Form + { + /// + /// Переменная-выбранного экскаватора + /// + DrawingExcavator? _excavator = null; + /// + /// Встроенный делегат + /// + private event Action? EventAddExcavator; + /// + /// Конструктор + /// + public FormExcavatorConfig() + { + 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 += (sender, e) => + { + Close(); + }; + } + /// + /// Отрисовать экскаватор + /// + private void DrawExcavator() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _excavator?.SetPosition(5, 5); + _excavator?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_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": + _excavator = new DrawingExcavator((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _excavator = new DrawingExcavatorKovsh((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBox_Kovsh.Checked, checkBox_Katki.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawExcavator(); + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddExcavator == null) + { + EventAddExcavator = ev; + } + else + { + EventAddExcavator += ev; + } + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + 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 LabelColor_DragDrop(object sender, DragEventArgs e) + { + if (_excavator == null) + return; + ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); + switch (((Label)sender).Name) + { + case "labelMainColor": + _excavator.bodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAdditionalColor": + if (!(_excavator is DrawingExcavatorKovsh)) + return; + (_excavator as DrawingExcavatorKovsh).additionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawExcavator(); + } + /// + /// Добавление экскаватора + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddExcavator?.Invoke(_excavator); + Close(); + } + } +} diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.resx b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.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