2023-11-14 22:19:16 +04:00
|
|
|
|
|
2023-11-14 17:16:57 +04:00
|
|
|
|
using WarmlyLocomotive.DrawningObjects;
|
2023-11-14 22:19:16 +04:00
|
|
|
|
using WarmlyLocomotive.Entities;
|
2023-11-14 17:16:57 +04:00
|
|
|
|
|
|
|
|
|
namespace WarmlyLocomotive
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Делегат для передачи объекта-тепловоза
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="warmlylocomotive"></param>
|
|
|
|
|
public partial class FormWarmlyLocomotiveConfig : Form
|
|
|
|
|
{
|
2023-11-14 22:19:16 +04:00
|
|
|
|
public int _pictureWidth { get; private set; }
|
|
|
|
|
public int _pictureHeight { get; private set; }
|
2023-11-14 17:16:57 +04:00
|
|
|
|
/// <summary>
|
2023-11-14 22:19:16 +04:00
|
|
|
|
/// Переменная
|
2023-11-14 17:16:57 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
DrawningWarmlyLocomotive? _warmlylocomotive = null;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие
|
|
|
|
|
/// </summary>
|
2023-11-14 22:19:16 +04:00
|
|
|
|
public event Action<DrawningWarmlyLocomotive>? EventAddWarmlyLocomotive;
|
2023-11-14 17:16:57 +04:00
|
|
|
|
/// Добавление события
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ev">Привязанный метод</param>
|
2023-11-14 22:19:16 +04:00
|
|
|
|
public void AddEvent(Action<DrawningWarmlyLocomotive> ev)
|
2023-11-14 17:16:57 +04:00
|
|
|
|
{
|
|
|
|
|
if (EventAddWarmlyLocomotive == null)
|
|
|
|
|
{
|
|
|
|
|
EventAddWarmlyLocomotive = ev;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EventAddWarmlyLocomotive += ev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-11-14 22:19:16 +04:00
|
|
|
|
/// Передача цвета при нажатии на одну из Panel с цветом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
|
|
|
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-11-14 17:16:57 +04:00
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
2023-11-14 23:55:00 +04:00
|
|
|
|
public FormWarmlyLocomotiveConfig(int pictureWidth, int pictureHeight)
|
2023-11-14 17:16:57 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-11-14 23:55:00 +04:00
|
|
|
|
_pictureWidth = pictureWidth;
|
|
|
|
|
_pictureHeight = pictureHeight;
|
|
|
|
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelGray.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelRed.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
2023-11-14 17:16:57 +04:00
|
|
|
|
buttonCancel.Click += (s, e) => Close();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-11-14 23:55:00 +04:00
|
|
|
|
/// Отрисовать тепловоз
|
2023-11-14 17:16:57 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void DrawCar()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_warmlylocomotive?.SetPosition(5, 5);
|
|
|
|
|
_warmlylocomotive?.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, 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)
|
|
|
|
|
{
|
2023-11-15 11:16:10 +04:00
|
|
|
|
|
2023-11-14 17:16:57 +04:00
|
|
|
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
|
|
|
|
{
|
2023-11-15 11:16:10 +04:00
|
|
|
|
case "labelBasic":
|
|
|
|
|
_warmlylocomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value,
|
|
|
|
|
(int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
|
2023-11-14 17:16:57 +04:00
|
|
|
|
break;
|
2023-11-15 11:16:10 +04:00
|
|
|
|
case "labelAdvanced":
|
|
|
|
|
_warmlylocomotive = new DrawningWarmlyLocomotiveWithTrumpet((int)numericUpDownSpeed.Value,
|
2023-11-14 17:16:57 +04:00
|
|
|
|
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTrumpet.Checked,
|
2023-11-15 11:16:10 +04:00
|
|
|
|
checkBoxLuggage.Checked, _pictureWidth, _pictureHeight);
|
2023-11-14 17:16:57 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DrawCar();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-11-14 22:19:16 +04:00
|
|
|
|
/// Проверка для базового цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void labelMainColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)) && _warmlylocomotive != null)
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Действия при приеме перетаскиваемого цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void labelMainColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var color = (Color)e.Data.GetData(typeof(Color));
|
|
|
|
|
_warmlylocomotive.EntityWarmlyLocomotive.ChangeBodyColor(color);
|
|
|
|
|
DrawCar();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проверка для дополнительного цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)) && _warmlylocomotive != null && _warmlylocomotive is DrawningWarmlyLocomotiveWithTrumpet)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
var color = (Color)e.Data.GetData(typeof(Color));
|
|
|
|
|
EntityWarmlyLocomotiveWithTrumpet? _warmlylocomotivePro = _warmlylocomotive.EntityWarmlyLocomotive as EntityWarmlyLocomotiveWithTrumpet;
|
|
|
|
|
_warmlylocomotivePro.ChangeAdditionalColor(color);
|
|
|
|
|
DrawCar();
|
|
|
|
|
}
|
2023-11-14 17:16:57 +04:00
|
|
|
|
/// Добавление машины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonOk_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EventAddWarmlyLocomotive?.Invoke(_warmlylocomotive);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|