176 lines
5.8 KiB
C#
176 lines
5.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using DumpTruck.DrawningObjects;
|
||
using DumpTruck.Generics;
|
||
using DumpTruck.MovementStrategy;
|
||
using DumpTruck.Entities;
|
||
|
||
namespace DumpTruck
|
||
{
|
||
public partial class FormTruckConfig : Form
|
||
{
|
||
/// <summary>
|
||
/// Переменная-выбранная машина
|
||
/// </summary>
|
||
DrawningTruck? _truck = null;
|
||
|
||
/// <summary>
|
||
/// Событие
|
||
/// </summary>
|
||
private event Action<DrawningTruck> EventAddTruck;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormTruckConfig()
|
||
{
|
||
InitializeComponent();
|
||
panelBlack.MouseDown += panelColor_MouseDown;
|
||
panelWrite.MouseDown += panelColor_MouseDown;
|
||
panelBlue.MouseDown += panelColor_MouseDown;
|
||
panelLime.MouseDown += panelColor_MouseDown;
|
||
panelRed.MouseDown += panelColor_MouseDown;
|
||
panelOrange.MouseDown += panelColor_MouseDown;
|
||
panelYellow.MouseDown += panelColor_MouseDown;
|
||
panelBrown.MouseDown += panelColor_MouseDown;
|
||
|
||
buttonCancel.Click += (sender, e) => Close();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Отрисовать машину
|
||
/// </summary>
|
||
private void DrawTruck()
|
||
{
|
||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_truck?.SetPosition(5, 5);
|
||
_truck?.DrawTransport(gr);
|
||
pictureBoxObject.Image = bmp;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Добавление события
|
||
/// </summary>
|
||
/// <param name="ev">Привязанный метод</param>
|
||
public void AddEvent(Action<DrawningTruck> ev)
|
||
{
|
||
if (EventAddTruck == null)
|
||
{
|
||
EventAddTruck = ev;
|
||
}
|
||
else
|
||
{
|
||
EventAddTruck += ev;
|
||
}
|
||
}
|
||
|
||
/// <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, DragDropEffects.Move | DragDropEffects.Copy);
|
||
}
|
||
|
||
private void panelColor_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 PanelObject_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
|
||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data?.GetDataPresent(typeof(Color)) ?? 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":
|
||
_truck = new DrawningTruck((int)numericUpDownSpeed.Value,
|
||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||
pictureBoxObject.Height);
|
||
break;
|
||
case "labelModifiedObject":
|
||
_truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value,
|
||
(int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||
checkBoxTrailer.Checked, pictureBoxObject.Width,
|
||
pictureBoxObject.Height);
|
||
break;
|
||
}
|
||
DrawTruck();
|
||
}
|
||
|
||
public void labelColor_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
if (_truck == null)
|
||
return;
|
||
|
||
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
|
||
switch (((Label)sender).Name)
|
||
{
|
||
case "labelBodyColor":
|
||
_truck.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||
break;
|
||
case "labelAdditionalColor":
|
||
if (!(_truck is DrawningDumpTruck))
|
||
{
|
||
return;
|
||
}
|
||
(_truck as DrawningDumpTruck).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||
break;
|
||
}
|
||
DrawTruck();
|
||
}
|
||
/// <summary>
|
||
/// Добавление машины
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void buttonOk_Click(object sender, EventArgs e)
|
||
{
|
||
EventAddTruck?.Invoke(_truck);
|
||
Close();
|
||
}
|
||
}
|
||
}
|
||
|