215 lines
7.0 KiB
C#
215 lines
7.0 KiB
C#
using ProjectElectroTrans.Drawnings;
|
||
using ProjectElectroTrans.Entities;
|
||
|
||
|
||
namespace ProjectElectroTrans
|
||
{
|
||
/// <summary>
|
||
/// форма конфигурации объекта
|
||
/// </summary>
|
||
public partial class FormTransConfig : Form
|
||
{
|
||
|
||
private DrawingTrans? _trans;
|
||
|
||
/// <summary>
|
||
/// событие для передачи объекта
|
||
/// </summary>
|
||
|
||
private event Action<DrawingTrans>? ElectroTransDelegate;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormTransConfig()
|
||
{
|
||
InitializeComponent();
|
||
panelRed.MouseDown += Panel_MouseDown;
|
||
panelGreen.MouseDown += Panel_MouseDown;
|
||
panelBlue.MouseDown += Panel_MouseDown;
|
||
panelYellow.MouseDown += Panel_MouseDown;
|
||
panelWhite.MouseDown += Panel_MouseDown;
|
||
panelGray.MouseDown += Panel_MouseDown;
|
||
panelBlack.MouseDown += Panel_MouseDown;
|
||
panelPurple.MouseDown += Panel_MouseDown;
|
||
buttonCancel.Click += (sender, e) => Close();
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Привязка внешнего метода к событию
|
||
/// </summary>
|
||
/// <param name="carDelegate"></param>
|
||
public void AddEvent(Action<DrawingTrans> excavatorDelegate)
|
||
{
|
||
ElectroTransDelegate += excavatorDelegate;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Отрисовка объекта
|
||
/// </summary>
|
||
private void DrawObject()
|
||
{
|
||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_trans?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
_trans?.SetPosition(15, 15);
|
||
_trans?.DrawTransport(gr);
|
||
pictureBoxObject.Image = bmp;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Передаем информацию при нажатии на Labe
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||
{
|
||
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// действия при приеме перетаскиваемой информации
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
|
||
{
|
||
case "labelSimpleObject":
|
||
_trans = new DrawingTrans((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
||
break;
|
||
case "labelModifiedObject":
|
||
_trans = new DrawingElectroTrans((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value,
|
||
Color.White,
|
||
Color.Black, checkBoxBulldozerDump.Checked,
|
||
checkBoxSupport.Checked);
|
||
break;
|
||
}
|
||
labelBodyColor.BackColor = Color.Empty;
|
||
labelAdditionalColor.BackColor = Color.Empty;
|
||
DrawObject();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Передаем информацию при нажатии на Panel
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
||
{
|
||
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Проверка получаемой информации по основному цвету
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data.GetDataPresent(typeof(Color)))
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// действия при приеме перетаскиваемого основного цвета
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
if (_trans != null)
|
||
{
|
||
_trans.EntityTrans.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||
DrawObject();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// проверка получаемой информации по доп. цвету
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (_trans is DrawingElectroTrans)
|
||
{
|
||
if (e.Data.GetDataPresent(typeof(Color)))
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// действия при перетаскивании доп. цвета
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
if (_trans.EntityTrans is EntityElectroTrans _excavator)
|
||
{
|
||
_excavator.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||
}
|
||
DrawObject();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Передача объекта
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||
{
|
||
if (_trans != null)
|
||
{
|
||
ElectroTransDelegate?.Invoke(_trans);
|
||
Close();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|