From 62b4c50aeeeda1b5b4b6ae1c5c3b7ade3755376a Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Mon, 20 Nov 2023 23:15:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=87=D0=B0=D1=8F=205=D0=B0=D1=8F=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 9 ++ .../WarmlyShip/DrawingWarmlyShipWithPipes.cs | 4 + WarmlyShip/WarmlyShip/EntityWarmlyShip.cs | 2 +- .../WarmlyShip/EntityWarmlyShipWithPipes.cs | 2 +- WarmlyShip/WarmlyShip/FormShipCollection.cs | 52 ++++++- .../WarmlyShip/FormShipConfig.Designer.cs | 145 ++++++++++-------- WarmlyShip/WarmlyShip/FormShipConfig.cs | 43 +++++- 7 files changed, 180 insertions(+), 77 deletions(-) diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index 3d62f00..1764284 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -128,6 +128,15 @@ namespace WarmlyShip.DrawingObjects /// Получение объекта IMoveableObject из объекта DrawingCar /// public IMoveableObject GetMoveableObject => new DrawingObjectShip(this); + public void SetBodyColor(Color color) + { + EntityWarmlyShip.BodyColor = color; + } + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + _pictureWidth = pictureBoxWidth; + _pictureHeight = pictureBoxHeight; + } } } diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShipWithPipes.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShipWithPipes.cs index 6e264c6..c3b63c1 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShipWithPipes.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShipWithPipes.cs @@ -44,5 +44,9 @@ namespace WarmlyShip.DrawingObjects g.DrawRectangle(pen, _startPosX + 90, _startPosY + 20, 25, 60); } } + public void SetAddColor(Color color) + { + (EntityWarmlyShip as EntityWarmlyShipWithPipes).AdditionalColor = color; + } } } diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs index c7152c3..f929583 100644 --- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs @@ -10,7 +10,7 @@ namespace WarmlyShip.Entities { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public double Step => (double)Speed * 100 / Weight; public EntityWarmlyShip(int speed, double weight, Color bodyColor) { diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShipWithPipes.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShipWithPipes.cs index 211be31..0de748f 100644 --- a/WarmlyShip/WarmlyShip/EntityWarmlyShipWithPipes.cs +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShipWithPipes.cs @@ -8,7 +8,7 @@ namespace WarmlyShip.Entities { public class EntityWarmlyShipWithPipes : EntityWarmlyShip { - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } public bool Pipes { get; private set; } public bool Section { get; private set; } public EntityWarmlyShipWithPipes(int speed, double weight, Color bodyColor, Color diff --git a/WarmlyShip/WarmlyShip/FormShipCollection.cs b/WarmlyShip/WarmlyShip/FormShipCollection.cs index 56a2da8..09740f7 100644 --- a/WarmlyShip/WarmlyShip/FormShipCollection.cs +++ b/WarmlyShip/WarmlyShip/FormShipCollection.cs @@ -105,9 +105,57 @@ namespace WarmlyShip /// private void ButtonAddShip_Click(object sender, EventArgs e) { - var formCarConfig = new FormShipConfig(); - // TODO Call method AddEvent from formCarConfig + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + + var formShipConfig = new FormShipConfig(); formShipConfig.Show(); + Action? shipDelegate = new((m) => + { + bool isAddSuccessful = (obj + m); + if (isAddSuccessful) + { + MessageBox.Show("Объект добавлен"); + m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); + pictureBoxCollection.Image = obj.ShowShips(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + }); + formShipConfig.AddEvent(shipDelegate); + } + private void AddShip(DrawingWarmlyShip drawningShip) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + + if (obj + drawningShip) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowShips(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } /// /// Удаление объекта из набора diff --git a/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs b/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs index 33dd9bf..f11d6a3 100644 --- a/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormShipConfig.Designer.cs @@ -29,6 +29,8 @@ private void InitializeComponent() { this.groupBoxParameters = 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.panelRed = new System.Windows.Forms.Panel(); this.panelBlue = new System.Windows.Forms.Panel(); @@ -44,14 +46,12 @@ this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); this.labelWeight = new System.Windows.Forms.Label(); this.labelSpeed = new System.Windows.Forms.Label(); - this.labelSimpleObject = new System.Windows.Forms.Label(); - this.labelModifiedObject = new System.Windows.Forms.Label(); this.panelColor = new System.Windows.Forms.Panel(); - this.pictureBoxObject = new System.Windows.Forms.PictureBox(); - this.labelBodyColor = new System.Windows.Forms.Label(); - this.labelAddColor = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); + this.labelAddColor = new System.Windows.Forms.Label(); + this.labelBodyColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); this.groupBoxParameters.SuspendLayout(); this.groupBoxColor.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); @@ -78,6 +78,30 @@ this.groupBoxParameters.TabStop = false; this.groupBoxParameters.Text = "Параметры"; // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelModifiedObject.Location = new System.Drawing.Point(456, 273); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(121, 36); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelSimpleObject.Location = new System.Drawing.Point(313, 273); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(124, 36); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // // groupBoxColor // this.groupBoxColor.Controls.Add(this.panelRed); @@ -129,6 +153,7 @@ this.panelWhite.Name = "panelWhite"; this.panelWhite.Size = new System.Drawing.Size(50, 50); this.panelWhite.TabIndex = 1; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGray // @@ -137,6 +162,7 @@ this.panelGray.Name = "panelGray"; this.panelGray.Size = new System.Drawing.Size(50, 50); this.panelGray.TabIndex = 1; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelBlack // @@ -145,6 +171,7 @@ this.panelBlack.Name = "panelBlack"; this.panelBlack.Size = new System.Drawing.Size(50, 50); this.panelBlack.TabIndex = 1; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelPurple // @@ -153,6 +180,7 @@ this.panelPurple.Name = "panelPurple"; this.panelPurple.Size = new System.Drawing.Size(50, 50); this.panelPurple.TabIndex = 1; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGreen // @@ -245,34 +273,10 @@ this.labelSpeed.TabIndex = 0; this.labelSpeed.Text = "Скорость"; // - // labelSimpleObject - // - this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelSimpleObject.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelSimpleObject.Location = new System.Drawing.Point(313, 273); - this.labelSimpleObject.Name = "labelSimpleObject"; - this.labelSimpleObject.Size = new System.Drawing.Size(124, 36); - this.labelSimpleObject.TabIndex = 7; - this.labelSimpleObject.Text = "Простой"; - this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); - // - // labelModifiedObject - // - this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelModifiedObject.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelModifiedObject.Location = new System.Drawing.Point(456, 273); - this.labelModifiedObject.Name = "labelModifiedObject"; - this.labelModifiedObject.Size = new System.Drawing.Size(121, 36); - this.labelModifiedObject.TabIndex = 8; - this.labelModifiedObject.Text = "Продвинутый"; - this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); - // // panelColor // this.panelColor.AllowDrop = true; - this.panelColor.Controls.Add(this.button2); + this.panelColor.Controls.Add(this.buttonCancel); this.panelColor.Controls.Add(this.button1); this.panelColor.Controls.Add(this.labelAddColor); this.panelColor.Controls.Add(this.labelBodyColor); @@ -284,35 +288,14 @@ this.panelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); this.panelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // - // pictureBoxObject + // buttonCancel // - this.pictureBoxObject.Location = new System.Drawing.Point(15, 78); - this.pictureBoxObject.Name = "pictureBoxObject"; - this.pictureBoxObject.Size = new System.Drawing.Size(332, 213); - this.pictureBoxObject.TabIndex = 0; - this.pictureBoxObject.TabStop = false; - // - // labelBodyColor - // - this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelBodyColor.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelBodyColor.Location = new System.Drawing.Point(44, 30); - this.labelBodyColor.Name = "labelBodyColor"; - this.labelBodyColor.Size = new System.Drawing.Size(124, 36); - this.labelBodyColor.TabIndex = 9; - this.labelBodyColor.Text = "Цвет"; - this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // labelAddColor - // - this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelAddColor.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelAddColor.Location = new System.Drawing.Point(200, 30); - this.labelAddColor.Name = "labelAddColor"; - this.labelAddColor.Size = new System.Drawing.Size(124, 36); - this.labelAddColor.TabIndex = 10; - this.labelAddColor.Text = "Доп. цвет"; - this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.buttonCancel.Location = new System.Drawing.Point(200, 297); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(124, 32); + this.buttonCancel.TabIndex = 12; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; // // button1 // @@ -322,15 +305,43 @@ this.button1.TabIndex = 11; this.button1.Text = "Добавить"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.ButtonOk_Click); // - // button2 + // labelAddColor // - this.button2.Location = new System.Drawing.Point(200, 297); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(124, 32); - this.button2.TabIndex = 12; - this.button2.Text = "Отмена"; - this.button2.UseVisualStyleBackColor = true; + this.labelAddColor.AllowDrop = true; + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelAddColor.Location = new System.Drawing.Point(200, 30); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(124, 36); + this.labelAddColor.TabIndex = 10; + this.labelAddColor.Text = "Доп. цвет"; + this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // labelBodyColor + // + this.labelBodyColor.AllowDrop = true; + this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBodyColor.Font = new System.Drawing.Font("Segoe UI", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelBodyColor.Location = new System.Drawing.Point(44, 30); + this.labelBodyColor.Name = "labelBodyColor"; + this.labelBodyColor.Size = new System.Drawing.Size(124, 36); + this.labelBodyColor.TabIndex = 9; + this.labelBodyColor.Text = "Цвет"; + this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(15, 78); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(332, 213); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; // // FormShipConfig // @@ -377,6 +388,6 @@ private Label labelAddColor; private Label labelBodyColor; private PictureBox pictureBoxObject; - private Button button2; + private Button buttonCancel; } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormShipConfig.cs b/WarmlyShip/WarmlyShip/FormShipConfig.cs index 0579d51..f7fab4d 100644 --- a/WarmlyShip/WarmlyShip/FormShipConfig.cs +++ b/WarmlyShip/WarmlyShip/FormShipConfig.cs @@ -1,4 +1,6 @@ -using System; +using Microsoft.VisualBasic.Devices; +using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -25,7 +27,7 @@ namespace WarmlyShip /// /// Событие /// - private event ShipDelegate? EventAddShip; + private event Action? EventAddShip; /// /// Конструктор /// @@ -40,7 +42,8 @@ namespace WarmlyShip panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - // TODO buttonCancel.Click with lambda + + buttonCancel.Click += (s, e) => Close(); } /// /// Отрисовать машину @@ -57,7 +60,7 @@ namespace WarmlyShip /// Добавление события /// /// Привязанный метод - internal void AddEvent(ShipDelegate ev) + internal void AddEvent(Action ev) { if (EventAddShip == null) { @@ -75,8 +78,7 @@ namespace WarmlyShip /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { - (sender as Label)?.DoDragDrop((sender as Label)?.Name, - DragDropEffects.Move | DragDropEffects.Copy); + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } /// /// Проверка получаемой информации (ее типа на соответствие требуемому) @@ -122,6 +124,35 @@ namespace WarmlyShip { (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 (_ship == null) + return; + switch (((Label)sender).Name) + { + case "labelBodyColor": + _ship.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAdditionalColor": + if (!(_ship is DrawingWarmlyShipWithPipes)) + return; + (_ship as DrawingWarmlyShipWithPipes).SetAddColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawShip(); + } /// /// Добавление машины ///