Робит нормально(все)

This commit is contained in:
Tonb73 2024-04-09 17:48:06 +03:00
parent e188ec33d9
commit e88452ca9b
5 changed files with 84 additions and 7 deletions

View File

@ -40,6 +40,10 @@ namespace ProjectElectricLocomotive.Entities
Pantograph = pantograph;
BatteryStorage = batteryStorage;
}
internal void setAdditionalColor(Color additionalColor)
{
AdditionalColor = additionalColor;
}
}
}

View File

@ -43,5 +43,9 @@ namespace ProjectElectricLocomotive.Entities
}
internal void setBodyColor(Color bodyColor)
{
BodyColor = bodyColor;
}
}
}

View File

@ -159,7 +159,6 @@
panelRed.Name = "panelRed";
panelRed.Size = new Size(48, 47);
panelRed.TabIndex = 9;
panelRed.MouseDown += panel_MouseDown;
//
// checkBoxBatteryStorage
//
@ -283,6 +282,7 @@
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(198, 15);
labelAdditionalColor.Name = "labelAdditionalColor";
@ -290,9 +290,12 @@
labelAdditionalColor.TabIndex = 12;
labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter;
//
// labelBodyColor
//
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Location = new Point(9, 15);
labelBodyColor.Name = "labelBodyColor";
@ -300,6 +303,8 @@
labelBodyColor.TabIndex = 9;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += labelBodyColor_DragDrop;
labelBodyColor.DragEnter += labelBodyColor_DragEnter;
//
// FormElectricLocomotiveConfig
//

View File

@ -1,4 +1,5 @@
using ProjectElectricLocomotive.Drawnings;
using ProjectElectricLocomotive.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -17,7 +18,7 @@ public partial class FormElectricLocomotiveConfig : Form
{
/// <summary>
/// Объект - прорисовкатавтомобиля
/// Объект - прорисовка
/// </summary>
private DrawningLocomotive? _locomotive;
@ -30,6 +31,8 @@ public partial class FormElectricLocomotiveConfig : Form
/// </summary>
public FormElectricLocomotiveConfig()
{
InitializeComponent();
panelRed.MouseDown += panel_MouseDown;
panelGreen.MouseDown += panel_MouseDown;
panelBlue.MouseDown += panel_MouseDown;
@ -40,7 +43,8 @@ public partial class FormElectricLocomotiveConfig : Form
panelPurple.MouseDown += panel_MouseDown;
//TODO buttonCancel.Click привязать анонимный метод через лямбда с закрытием формы
InitializeComponent();
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
@ -49,7 +53,8 @@ public partial class FormElectricLocomotiveConfig : Form
/// <param name="locomotiveDelegate"></param>
public void AddEvent(LocomotiveDelegate locomotiveDelegate)
{
if (_locomotiveDelegate == null) {
if (_locomotiveDelegate == null)
{
_locomotiveDelegate = locomotiveDelegate;
}
else
@ -120,14 +125,69 @@ public partial class FormElectricLocomotiveConfig : Form
checkBoxBatteryStorage.Checked);
break;
}
labelBodyColor.BackColor = Color.Empty;
labelAdditionalColor.BackColor = Color.Empty;
DrawObject();
}
private void panel_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
//TODO отпавка цвета в Dragdrop
}
//TODO реализовать логику смены цветов основного и дополнительного(для продвинутого)
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
{
if (_locomotive != null)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_locomotive != null)
{
_locomotive.EntityLocomotive.setBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (_locomotive != null && _locomotive.EntityLocomotive is EntityElectricLocomotive entityElectricLocomotive)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_locomotive != null && _locomotive.EntityLocomotive is EntityElectricLocomotive entityElectricLocomotive)
{
entityElectricLocomotive.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
DrawObject();
}
/// <summary>
/// Передача объекта
@ -136,10 +196,12 @@ public partial class FormElectricLocomotiveConfig : Form
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
if(_locomotive != null)
if (_locomotive != null)
{
_locomotiveDelegate?.Invoke(_locomotive);
Close();
}
}
}

View File

@ -62,20 +62,22 @@ public partial class FormLocomotiveCollection : Form
FormElectricLocomotiveConfig form = new();
//TODO передать метод
form.Show();
form.AddEvent(SetLocomotive);
form.Show();
}
/// <summary>
/// Добавление автомобиля в коллекцию
/// </summary>
/// <param name="locomotive"></param>
private void SetLocomotive(DrawningLocomotive locomotive)
private void SetLocomotive(DrawningLocomotive? locomotive)
{
if(_company == null || locomotive == null)
{
return;
}
if (_company + locomotive != null)
if (_company + locomotive != -1)
{
pictureBox.Image = _company.Show();
MessageBox.Show("Обьект добавлен");