2024-03-31 13:32:38 +04:00
|
|
|
|
using AntiAircraftGun.Drawnings;
|
2024-04-01 18:15:58 +04:00
|
|
|
|
using AntiAircraftGun.Entities;
|
2024-03-31 13:32:38 +04:00
|
|
|
|
|
|
|
|
|
namespace AntiAircraftGun;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма конфигурации объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormCarConfig : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Объект - прорисовка бронемашины
|
|
|
|
|
/// </summary>
|
2024-04-02 22:41:10 +04:00
|
|
|
|
private DrawningArmoredCar? _armoredCar;
|
2024-03-31 13:32:38 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие для передачи объекта
|
|
|
|
|
/// </summary>
|
2024-04-02 22:41:10 +04:00
|
|
|
|
private event Action<DrawningArmoredCar>? _armoredCarDelegate;
|
2024-03-31 13:32:38 +04:00
|
|
|
|
public FormCarConfig()
|
|
|
|
|
{
|
2024-04-01 18:15:58 +04:00
|
|
|
|
InitializeComponent();
|
2024-03-31 13:32:38 +04:00
|
|
|
|
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;
|
2024-04-02 22:06:45 +04:00
|
|
|
|
|
2024-03-31 13:32:38 +04:00
|
|
|
|
buttonCancel.Click += (sender, e) => Close();
|
2024-04-02 22:06:45 +04:00
|
|
|
|
|
2024-03-31 13:32:38 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Привязка внешнего метода к событию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="carDelegate"></param>
|
2024-04-02 22:41:10 +04:00
|
|
|
|
public void AddEvent(Action<DrawningArmoredCar> carDelegate)
|
2024-03-31 13:32:38 +04:00
|
|
|
|
{
|
2024-04-02 22:41:10 +04:00
|
|
|
|
_armoredCarDelegate += carDelegate;
|
2024-03-31 13:32:38 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void DrawObject()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_armoredCar?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
_armoredCar?.SetPosition(15, 15);
|
|
|
|
|
_armoredCar?.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":
|
|
|
|
|
_armoredCar = new DrawningArmoredCar((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|
|
|
|
break;
|
|
|
|
|
case "labelModifiedObject":
|
|
|
|
|
_armoredCar = new DrawningAntiAircraftGun((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
|
|
|
|
|
Color.Black, checkBoxTower.Checked, checkBoxRadar.Checked);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передаем информацию при нажатии на Panel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
|
|
|
|
{
|
2024-04-01 18:15:58 +04:00
|
|
|
|
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
2024-03-31 13:32:38 +04:00
|
|
|
|
}
|
2024-04-02 22:06:45 +04:00
|
|
|
|
|
|
|
|
|
|
2024-04-05 23:17:58 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача основного цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-31 13:32:38 +04:00
|
|
|
|
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 23:17:58 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка основным цветом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-31 13:32:38 +04:00
|
|
|
|
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_armoredCar != null)
|
|
|
|
|
{
|
2024-04-01 18:15:58 +04:00
|
|
|
|
_armoredCar.EntityAircraftGun?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
2024-03-31 13:32:38 +04:00
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-05 23:17:58 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка основным цветом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-31 13:32:38 +04:00
|
|
|
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
2024-04-02 09:21:56 +04:00
|
|
|
|
if (_armoredCar?.EntityAircraftGun is EntityAntiAircraftGun _car)
|
2024-03-31 13:32:38 +04:00
|
|
|
|
{
|
2024-04-02 09:21:56 +04:00
|
|
|
|
_car.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
2024-03-31 13:32:38 +04:00
|
|
|
|
}
|
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
2024-04-05 23:17:58 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача дополнительного цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-31 13:32:38 +04:00
|
|
|
|
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_armoredCar is DrawningAntiAircraftGun)
|
|
|
|
|
{
|
|
|
|
|
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 buttonAdd_Click_1(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_armoredCar != null)
|
|
|
|
|
{
|
2024-04-02 22:41:10 +04:00
|
|
|
|
_armoredCarDelegate?.Invoke(_armoredCar);
|
2024-03-31 13:32:38 +04:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|