2024-05-13 09:59:48 +04:00

170 lines
5.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ProjectDumpTruck.Drawnings;
using ProjectDumpTruck.Entities;
namespace ProjectDumpTruck;
/// <summary>
/// Форма конфигурации объекта
/// </summary>
public partial class FormTruckConfig : Form
{
/// <summary>
/// Объект - прорисовка
/// </summary>
private DrawningTruck? _truck;
/// <summary>
/// Констурктор
/// </summary>
public FormTruckConfig()
{
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>
public event Action<DrawningTruck>? TruckDelegate;
// <summary>
/// Привязка внешнего метода к событию
/// </summary>
/// <param name="trackDelegate"></param>
public void AddEvent(Action<DrawningTruck> truckDelegate)
{
TruckDelegate += truckDelegate;
}
/// <summary>
/// Прорисовка объекта
/// </summary>
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_truck?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
_truck?.SetPosition(15, 15);
_truck?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </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)
{
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : 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":
_truck = new DrawningTruck((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.Aqua);
break;
case "labelModifiedObject":
_truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
Color.Black, Color.Red, checkBoxBodywork.Checked, checkBoxAwning.Checked);
break;
}
DrawObject();
}
/// <summary>
/// Передаем информацию при нажатии на Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Panel_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Передача объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_truck != null)
{
TruckDelegate?.Invoke(_truck);
Close();
}
}
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_truck == null)
{
return;
}
Color color = (Color)e.Data.GetData(typeof(Color));
if (_truck is DrawningTruck)
{
_truck?.EntityTruck?.SetBodyColor(color);
}
DrawObject();
}
private void LabelBodyColor_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_truck == null)
{
return;
}
Color color = (Color)e.Data.GetData(typeof(Color));
if (_truck is DrawningDumpTruck)
{
var dumpTruck = _truck.EntityTruck as EntityDumpTruck;
dumpTruck.SetAdditionalColor(color);
}
DrawObject();
}
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
}