diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneDelegate.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneDelegate.cs
new file mode 100644
index 0000000..9630e9e
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneDelegate.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirplaneWithRadar
+{
+ ///
+ /// Делегат для передачи объекта-самолета
+ ///
+ ///
+ public delegate void AirplaneDelegate(DrawingAirplane airplane);
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs
index c82432b..74e07d2 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs
@@ -63,6 +63,12 @@ namespace AirplaneWithRadar
_airplaneWidth = airplaneWidth;
_airplaneHeight = airplaneHeight;
}
+
+ public void SetColor(Color color)
+ {
+ Airplane.BodyColor = color;
+ }
+
///
/// Установка позиции самолета
///
diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs
index e0b4f4e..420ea0c 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs
@@ -21,6 +21,12 @@ namespace AirplaneWithRadar
{
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, extraFuelTank);
}
+
+ public void SetDopColor(Color dopColor)
+ {
+ ((EntityAirplaneWithRadar)Airplane).DopColor = dopColor;
+ }
+
public override void DrawTransport(Graphics g)
{
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
index 6502d80..ca3ada0 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
@@ -23,7 +23,7 @@ namespace AirplaneWithRadar
///
/// Цвет кузова
///
- public Color BodyColor { get; private set; }
+ public Color BodyColor { get; set; }
///
/// Шаг перемещения самолета
///
diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs
index 5c71fbd..6189568 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplaneWithRadar.cs
@@ -11,7 +11,7 @@ namespace AirplaneWithRadar
///
/// Дополнительный цвет
///
- public Color DopColor { get; private set; }
+ public Color DopColor { get; set; }
///
/// Признак наличия радара
///
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs
index f368a85..b63ec61 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs
@@ -51,7 +51,7 @@
this.labelDopColor = new System.Windows.Forms.Label();
this.labelBaseColor = new System.Windows.Forms.Label();
this.buttonOk = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
@@ -124,7 +124,6 @@
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);
//
// panelWhite
//
@@ -133,7 +132,6 @@
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);
//
// panelHotPink
//
@@ -142,7 +140,6 @@
this.panelHotPink.Name = "panelHotPink";
this.panelHotPink.Size = new System.Drawing.Size(50, 50);
this.panelHotPink.TabIndex = 1;
- this.panelHotPink.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlueViolet
//
@@ -151,7 +148,6 @@
this.panelBlueViolet.Name = "panelBlueViolet";
this.panelBlueViolet.Size = new System.Drawing.Size(50, 50);
this.panelBlueViolet.TabIndex = 1;
- this.panelBlueViolet.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelDodgerBlue
//
@@ -160,7 +156,6 @@
this.panelDodgerBlue.Name = "panelDodgerBlue";
this.panelDodgerBlue.Size = new System.Drawing.Size(50, 50);
this.panelDodgerBlue.TabIndex = 1;
- this.panelDodgerBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelYellowGreen
//
@@ -169,7 +164,6 @@
this.panelYellowGreen.Name = "panelYellowGreen";
this.panelYellowGreen.Size = new System.Drawing.Size(50, 50);
this.panelYellowGreen.TabIndex = 1;
- this.panelYellowGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGold
//
@@ -178,7 +172,6 @@
this.panelGold.Name = "panelGold";
this.panelGold.Size = new System.Drawing.Size(50, 50);
this.panelGold.TabIndex = 1;
- this.panelGold.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
@@ -187,7 +180,6 @@
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(50, 50);
this.panelRed.TabIndex = 0;
- this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBoxExtraFuelTank
//
@@ -306,22 +298,23 @@
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
+ this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
- // button2
+ // buttonCancel
//
- this.button2.Location = new System.Drawing.Point(822, 284);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(112, 34);
- this.button2.TabIndex = 4;
- this.button2.Text = "Отмена";
- this.button2.UseVisualStyleBackColor = true;
+ this.buttonCancel.Location = new System.Drawing.Point(822, 284);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(112, 34);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormAirplaneConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1025, 330);
- this.Controls.Add(this.button2);
+ this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
@@ -363,6 +356,6 @@
private Label labelDopColor;
private Label labelBaseColor;
private Button buttonOk;
- private Button button2;
+ private Button buttonCancel;
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs
index 9035a9c..30374d5 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs
@@ -20,6 +20,10 @@ namespace AirplaneWithRadar
///
DrawingAirplane _airplane = null;
///
+ /// Событие
+ ///
+ private event Action EventAddAirplane;
+ ///
/// Конструктор
///
public FormAirplaneConfig()
@@ -34,6 +38,7 @@ namespace AirplaneWithRadar
panelWhite.MouseDown += PanelColor_MouseDown;
panelBlack.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda
+ buttonCancel.Click += (object sender, EventArgs e) => Close();
}
///
@@ -48,6 +53,21 @@ namespace AirplaneWithRadar
pictureBoxObject.Image = bmp;
}
///
+ /// Добавление события
+ ///
+ ///
+ public void AddEvent(Action ev)
+ {
+ if (EventAddAirplane == null)
+ {
+ EventAddAirplane = ev;
+ }
+ else
+ {
+ EventAddAirplane += ev;
+ }
+ }
+ ///
/// Передаем информацию при нажатии на Label
///
///
@@ -98,8 +118,7 @@ namespace AirplaneWithRadar
///
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
- (sender as Control).DoDragDrop((sender as Control).BackColor,
- DragDropEffects.Move | DragDropEffects.Copy);
+ (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
///
/// Проверка получаемой информации (ее типа на соответствие требуемому)
@@ -125,6 +144,9 @@ namespace AirplaneWithRadar
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
// TODO Call method from object _car and set color
+ Color BodyColor = (Color)e.Data.GetData(typeof(Color));
+ _airplane.SetColor(BodyColor);
+ DrawAirplane();
}
///
/// Принимаем дополнительный цвет
@@ -134,6 +156,22 @@ namespace AirplaneWithRadar
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
// TODO Call method from object _car if _car is DrawningSportCar and set dop color
+ Color ModifColor = (Color)e.Data.GetData(typeof(Color));
+ if (_airplane is DrawingAirplaneWithRadar airplaneWithRadar)
+ {
+ airplaneWithRadar.SetDopColor(ModifColor);
+ DrawAirplane();
+ }
+ }
+ ///
+ /// Добавление машины
+ ///
+ ///
+ ///
+ private void ButtonOk_Click(object sender, EventArgs e)
+ {
+ EventAddAirplane?.Invoke(_airplane);
+ Close();
}
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
index 6dd4f47..33a4229 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
@@ -17,6 +17,7 @@ namespace AirplaneWithRadar
/// Объект от коллекции карт
///
private readonly MapsCollection _mapsCollection;
+ private Action AddAction;
///
/// Конструктор
///
@@ -102,24 +103,28 @@ namespace AirplaneWithRadar
///
///
private void ButtonAddAirplane_Click(object sender, EventArgs e)
+ {
+ // TODO Call method AddEvent from formCarConfig
+ var formAirplaneConfig = new FormAirplaneConfig();
+ formAirplaneConfig.AddEvent(AddAirplaneOnMap);
+ formAirplaneConfig.Show();
+
+ }
+ private void AddAirplaneOnMap(DrawingAirplane drawingAirplane)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- FormAirplaneWithRadar form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ DrawingObjectAirplane airplane = new(drawingAirplane);
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
{
- DrawingObjectAirplane airplane = new(form.SelectedAirplane);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
}
}
///