2024-05-06 21:29:03 +04:00
|
|
|
|
using AirBomber.Drawnings;
|
2024-05-07 02:36:19 +04:00
|
|
|
|
using AirBomber.Entities;
|
2024-05-06 21:29:03 +04:00
|
|
|
|
|
|
|
|
|
namespace AirBomber;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма конфигурации объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormAirPlaneConfig : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Объект - прорисовка самолета
|
|
|
|
|
/// </summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
private DrawningAirPlane? _airplane = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// События для передачи объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
private event Action<DrawningAirPlane> AirPlaneDelegate;
|
2024-05-06 21:29:03 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormAirPlaneConfig()
|
|
|
|
|
{
|
2024-05-07 02:36:19 +04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2024-05-06 21:29:03 +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-05-07 02:36:19 +04:00
|
|
|
|
buttonCancel.Click += (sender, e) => Close();
|
2024-05-06 21:29:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// Привязка внешнего метода к событию
|
2024-05-06 21:29:03 +04:00
|
|
|
|
/// </summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// <param name="airplaneDelegate"></param>
|
|
|
|
|
public void AddEvent(Action<DrawningAirPlane> airplaneDelegate)
|
|
|
|
|
{
|
|
|
|
|
AirPlaneDelegate += airplaneDelegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void DrawObject()
|
2024-05-06 21:29:03 +04:00
|
|
|
|
{
|
2024-05-07 02:36:19 +04:00
|
|
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2024-05-06 21:29:03 +04:00
|
|
|
|
_airplane?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
_airplane?.SetPosition(5, 5);
|
2024-05-07 02:36:19 +04:00
|
|
|
|
_airplane?.DrawTransport(gr);
|
|
|
|
|
pictureBoxObject.Image = bmp;
|
2024-05-06 21:29:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// Передаем информацию при нажатии на Label
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-05-06 21:29:03 +04:00
|
|
|
|
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
2024-05-06 21:29:03 +04:00
|
|
|
|
{
|
|
|
|
|
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// Действия при приеме перетаскиваемой информации
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
2024-05-06 21:29:03 +04:00
|
|
|
|
{
|
|
|
|
|
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
|
|
|
|
|
{
|
|
|
|
|
case "labelSimpleObject":
|
|
|
|
|
_airplane = new DrawningAirPlane((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|
|
|
|
break;
|
|
|
|
|
case "labelModifiedObject":
|
|
|
|
|
_airplane = new DrawningAirBomber((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
|
|
|
|
|
Color.Black, checkBoxBombs.Checked, checkBoxFuelTanks.Checked);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-05-07 02:36:19 +04:00
|
|
|
|
labelBodyColor.BackColor = Color.Empty;
|
|
|
|
|
labelAdditionalColor.BackColor = Color.Empty;
|
2024-05-06 21:29:03 +04:00
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// Передаем информацию при нажатии на Panel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
2024-05-06 21:29:03 +04:00
|
|
|
|
{
|
2024-05-07 02:36:19 +04:00
|
|
|
|
// TODO отправка цвета в Drag&Drop
|
|
|
|
|
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
|
}
|
2024-05-06 21:29:03 +04:00
|
|
|
|
|
2024-05-07 02:36:19 +04:00
|
|
|
|
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
|
|
|
|
|
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_airplane != null)
|
|
|
|
|
{
|
|
|
|
|
_airplane.EntityAirPlane.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_airplane is DrawningAirBomber)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-06 21:29:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-07 02:36:19 +04:00
|
|
|
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
2024-05-06 21:29:03 +04:00
|
|
|
|
{
|
2024-05-07 02:36:19 +04:00
|
|
|
|
if (_airplane?.EntityAirPlane is EntityAirBomber _airbomber)
|
|
|
|
|
{
|
|
|
|
|
_airbomber.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
|
|
|
|
}
|
|
|
|
|
DrawObject();
|
2024-05-06 21:29:03 +04:00
|
|
|
|
|
|
|
|
|
}
|
2024-05-07 02:36:19 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_airplane != null)
|
|
|
|
|
{
|
|
|
|
|
AirPlaneDelegate?.Invoke(_airplane);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-06 21:29:03 +04:00
|
|
|
|
}
|
2024-05-07 02:36:19 +04:00
|
|
|
|
|