diff --git a/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs b/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs
index 59c79c5..97f63d1 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs
@@ -19,7 +19,7 @@ namespace WarmlyLocomotive
///
/// Цвет кузова
///
- public Color BodyColor { get; private set; }
+ public Color BodyColor { get; set; }
///
/// Шаг перемещения локомотива
///
diff --git a/WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs b/WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
index 0b5707a..1621ebe 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
@@ -12,7 +12,7 @@ namespace WarmlyLocomotive
///
/// Дополнительный цвет
///
- public Color DopColor { get; private set; }
+ public Color DopColor { get; set; }
///
/// Признак наличия трубы
///
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.Designer.cs b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.Designer.cs
index 4ce3af1..f176feb 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.Designer.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.Designer.cs
@@ -121,6 +121,7 @@
//
// panelPurple
//
+ this.panelPurple.AllowDrop = true;
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(157, 68);
this.panelPurple.MaximumSize = new System.Drawing.Size(30, 30);
@@ -130,6 +131,7 @@
//
// panelBlack
//
+ this.panelBlack.AllowDrop = true;
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(111, 68);
this.panelBlack.MaximumSize = new System.Drawing.Size(30, 30);
@@ -139,6 +141,7 @@
//
// panelGray
//
+ this.panelGray.AllowDrop = true;
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(65, 68);
this.panelGray.MaximumSize = new System.Drawing.Size(30, 30);
@@ -148,6 +151,7 @@
//
// panelWhite
//
+ this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(19, 68);
this.panelWhite.MaximumSize = new System.Drawing.Size(30, 30);
@@ -157,6 +161,7 @@
//
// panelYellow
//
+ this.panelYellow.AllowDrop = true;
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(157, 22);
this.panelYellow.MaximumSize = new System.Drawing.Size(30, 30);
@@ -166,6 +171,7 @@
//
// panelBlue
//
+ this.panelBlue.AllowDrop = true;
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(111, 22);
this.panelBlue.MaximumSize = new System.Drawing.Size(30, 30);
@@ -175,6 +181,7 @@
//
// panelGreen
//
+ this.panelGreen.AllowDrop = true;
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(65, 22);
this.panelGreen.MaximumSize = new System.Drawing.Size(30, 30);
@@ -184,6 +191,7 @@
//
// panelRed
//
+ this.panelRed.AllowDrop = true;
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(19, 22);
this.panelRed.MaximumSize = new System.Drawing.Size(30, 30);
@@ -295,6 +303,7 @@
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.LabelDopColor_DragEnter);
//
// labelBaseColor
//
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.cs b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.cs
index 003260a..823dad6 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.cs
@@ -16,7 +16,7 @@ namespace WarmlyLocomotive
///
/// Событие
///
- private event LocomotiveDelegate EventAddLocomotive;
+ private event Action EventAddLocomotive;
public FormLocomotiveConfig()
{
InitializeComponent();
@@ -28,7 +28,7 @@ namespace WarmlyLocomotive
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
-
+ buttonCancel.Click += (object sender, EventArgs e) => Close();
// TODO buttonCancel.Click with lambda
}
///
@@ -46,11 +46,11 @@ namespace WarmlyLocomotive
/// Добавление события
///
///
- public void AddEvent(LocomotiveDelegate ev)
+ public void AddEvent(Action ev)
{
if (EventAddLocomotive == null)
{
- EventAddLocomotive = new LocomotiveDelegate(ev);
+ EventAddLocomotive = new Action(ev);
}
else
{
@@ -134,6 +134,29 @@ namespace WarmlyLocomotive
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
// TODO Call method from object _car and set color
+ if(_locomotive != null)
+ {
+ if (e.Data.GetDataPresent(typeof(Color))) {
+ _locomotive.Locomotive.BodyColor = (Color)e.Data.GetData(typeof(Color));
+ }
+ DrawLocomotive();
+ }
+ }
+ ///
+ /// Проверка получаемой информации (ее типа на соответствие требуемому)
+ ///
+ ///
+ ///
+ private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
}
///
/// Принимаем дополнительный цвет
@@ -143,6 +166,17 @@ namespace WarmlyLocomotive
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
// TODO Call method from object _car if _car is DrawningSportCar and set dop color
+ if (_locomotive != null && _locomotive is DrawningWarmlyLocomotive warmlyLocomotive)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ if(warmlyLocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
+ {
+ entityWarmlyLocomotive.DopColor = (Color)e.Data.GetData(typeof(Color));
+ }
+ }
+ DrawLocomotive();
+ }
}
///
/// Добавление локомотива
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
index 7149c62..727dfda 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
@@ -68,8 +68,26 @@ namespace WarmlyLocomotive
{
var formLocomotiveConfig = new FormLocomotiveConfig();
// TODO Call method AddEvent from formCarConfig
+ formLocomotiveConfig.AddEvent(AddLocomotive);
formLocomotiveConfig.Show();
}
+ private void AddLocomotive(DrawningLocomotive drawningLocomotive)
+ {
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
+ DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(drawningLocomotive);
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
///
/// Удаление объекта
///
diff --git a/WarmlyLocomotive/WarmlyLocomotive/LocomotiveDelegate.cs b/WarmlyLocomotive/WarmlyLocomotive/LocomotiveDelegate.cs
deleted file mode 100644
index e480a35..0000000
--- a/WarmlyLocomotive/WarmlyLocomotive/LocomotiveDelegate.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace WarmlyLocomotive
-{
- ///
- /// Делегат для передачи объекта-локомотива
- ///
- ///
- public delegate void LocomotiveDelegate(DrawningLocomotive locomotive);
-}