From f8259e694944e1ac24215686fa91832bddac60cf Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Thu, 10 Nov 2022 21:28:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/DrawningAirbus.cs | 8 ++++-- Airbus/Airbus/DrawningPlane.cs | 5 ++++ Airbus/Airbus/FormMapWithSetPlanes.cs | 18 +++++++++++++ Airbus/Airbus/FormPlaneConfig.Designer.cs | 32 ++++++++++++++++------- Airbus/Airbus/FormPlaneConfig.cs | 19 +++++++++++++- 5 files changed, 69 insertions(+), 13 deletions(-) diff --git a/Airbus/Airbus/DrawningAirbus.cs b/Airbus/Airbus/DrawningAirbus.cs index 6392333..6547f55 100644 --- a/Airbus/Airbus/DrawningAirbus.cs +++ b/Airbus/Airbus/DrawningAirbus.cs @@ -24,6 +24,7 @@ namespace Airbus { Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); } + public override void DrawTransport(Graphics g) { if (Plane is not EntityAirbus Airbus) @@ -75,8 +76,11 @@ namespace Airbus g.FillEllipse(WindowBrush, _startPosX + 110, _startPosY + 40, 9, 9); } - - + } + public DrawningAirbus SetDopColor(int? speed = null, float? weight = null, Color? bodyColor = null, Color? dopColor = null, bool? bodyKit = null, bool? wing = null, bool? sportLine = null) + { + var b = (EntityAirbus)Plane; + return new DrawningAirbus(speed ?? b.Speed, weight ?? b.Weight, bodyColor ?? b.BodyColor, dopColor ?? b.DopColor,bodyKit ?? b.BodyKit, wing ?? b.Wing, sportLine ?? b.SportLine); } } diff --git a/Airbus/Airbus/DrawningPlane.cs b/Airbus/Airbus/DrawningPlane.cs index b981fe1..dbd5fd9 100644 --- a/Airbus/Airbus/DrawningPlane.cs +++ b/Airbus/Airbus/DrawningPlane.cs @@ -185,5 +185,10 @@ namespace Airbus { return (_startPosX, _startPosY, _startPosX + _PlaneWidth, _startPosY + _PlaneHeight); } + + public DrawningPlane SetBaseColor(int? speed = null, float? weight = null, Color? bodyColor = null) + { + return new DrawningPlane(speed ?? Plane.Speed, weight ?? Plane.Weight, bodyColor ?? Plane.BodyColor); + } } } diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index bf525ee..7d0a9a2 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -113,9 +113,27 @@ namespace Airbus private void buttonAddPlane_Click_1(object sender, EventArgs e) { var formPlaneConfig = new FormPlaneConfig(); + formPlaneConfig.AddEvent(new PlaneDelegate(AddPlane)); // TODO formPlaneConfig.Show(); } + + private void AddPlane(DrawningPlane plane) + { + if (listBoxMaps.SelectedIndex == -1) + { + MessageBox.Show("Перед добавлением объекта необходимо создать карту"); + } + else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectPlane(plane) != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } /// /// Удаление объекта /// diff --git a/Airbus/Airbus/FormPlaneConfig.Designer.cs b/Airbus/Airbus/FormPlaneConfig.Designer.cs index 53630d5..cd00a54 100644 --- a/Airbus/Airbus/FormPlaneConfig.Designer.cs +++ b/Airbus/Airbus/FormPlaneConfig.Designer.cs @@ -52,7 +52,7 @@ this.labelBaseColor = new System.Windows.Forms.Label(); this.labelDopColor = new System.Windows.Forms.Label(); this.buttonOk = new System.Windows.Forms.Button(); - this.buttonNo = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxConfig.SuspendLayout(); this.groupBoxColor.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); @@ -126,6 +126,7 @@ this.panelBlack.Name = "panelBlack"; this.panelBlack.Size = new System.Drawing.Size(40, 40); this.panelBlack.TabIndex = 1; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelPink // @@ -134,6 +135,7 @@ this.panelPink.Name = "panelPink"; this.panelPink.Size = new System.Drawing.Size(40, 40); this.panelPink.TabIndex = 1; + this.panelPink.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGol // @@ -142,6 +144,7 @@ this.panelGol.Name = "panelGol"; this.panelGol.Size = new System.Drawing.Size(40, 40); this.panelGol.TabIndex = 1; + this.panelGol.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelBlue // @@ -150,6 +153,7 @@ this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(40, 40); this.panelBlue.TabIndex = 2; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelOrange // @@ -158,6 +162,7 @@ this.panelOrange.Name = "panelOrange"; this.panelOrange.Size = new System.Drawing.Size(40, 40); this.panelOrange.TabIndex = 1; + this.panelOrange.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelYellow // @@ -166,6 +171,7 @@ this.panelYellow.Name = "panelYellow"; this.panelYellow.Size = new System.Drawing.Size(40, 40); this.panelYellow.TabIndex = 1; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGreen // @@ -174,6 +180,7 @@ this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(40, 40); this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelRed // @@ -182,6 +189,7 @@ this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(40, 40); this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // checkBoxSportLine // @@ -276,6 +284,8 @@ this.labelBaseColor.TabIndex = 9; this.labelBaseColor.Text = "Цвет"; this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); // // labelDopColor // @@ -287,6 +297,8 @@ this.labelDopColor.TabIndex = 8; this.labelDopColor.Text = "Доп. цвет"; this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); + this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); // // buttonOk // @@ -298,21 +310,21 @@ this.buttonOk.UseVisualStyleBackColor = true; this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); // - // buttonNo + // buttonCancel // - this.buttonNo.Location = new System.Drawing.Point(639, 168); - this.buttonNo.Name = "buttonNo"; - this.buttonNo.Size = new System.Drawing.Size(96, 23); - this.buttonNo.TabIndex = 3; - this.buttonNo.Text = "Отмена"; - this.buttonNo.UseVisualStyleBackColor = true; + this.buttonCancel.Location = new System.Drawing.Point(639, 168); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(96, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; // // FormPlaneConfig // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(764, 193); - this.Controls.Add(this.buttonNo); + this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonOk); this.Controls.Add(this.panelObject); this.Controls.Add(this.groupBoxConfig); @@ -354,7 +366,7 @@ private Panel panelObject; private Label labelDopColor; private Button buttonOk; - private Button buttonNo; + private Button buttonCancel; private Label labelBaseColor; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormPlaneConfig.cs b/Airbus/Airbus/FormPlaneConfig.cs index fa0396c..dcdeecd 100644 --- a/Airbus/Airbus/FormPlaneConfig.cs +++ b/Airbus/Airbus/FormPlaneConfig.cs @@ -35,6 +35,7 @@ namespace Airbus panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; // TODO buttonCancel.Click with lambda + buttonCancel.Click += (s, e) => Close(); } /// /// Отрисовать машину @@ -141,6 +142,17 @@ namespace Airbus private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { // TODO Call method from object _car and set color + var color = (Color)e.Data.GetData(typeof(Color)); + if (_plane is DrawningAirbus) + { + _plane = ((DrawningAirbus)_plane).SetBaseColor(bodyColor: color); + } + + else if (_plane is DrawningAirbus) + { + _plane = _plane.SetBaseColor(bodyColor: color); + } + DrawPlane(); } /// /// Принимаем дополнительный цвет @@ -149,7 +161,12 @@ namespace Airbus /// private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - // TODO Call method from object _car if _car is DrawningSportCar and set dop color + var color = (Color)e.Data.GetData(typeof(Color)); + if (_plane is DrawningAirbus) + { + _plane = ((DrawningAirbus)_plane).SetDopColor(dopColor: color); + } + DrawPlane(); } /// /// Добавление машины