2024-05-23 08:43:54 +04:00
|
|
|
|
using lab1.Drawnings;
|
2024-08-29 19:32:46 +04:00
|
|
|
|
using lab1.Entities;
|
2024-05-23 08:43:54 +04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace lab1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма конфигурации объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormTrackedVehicleConfig : Form
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Объект - прорисовка гусеничной машины
|
|
|
|
|
/// </summary>
|
2024-08-29 19:32:46 +04:00
|
|
|
|
private DrawningTrackedVehicle? _trackedVehicle;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие для предачи объекта
|
|
|
|
|
/// </summary>
|
2024-10-22 13:26:55 +04:00
|
|
|
|
private event Action<DrawningTrackedVehicle>? TrackedVehicleDelegate;
|
2024-05-23 08:43:54 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormTrackedVehicleConfig()
|
|
|
|
|
{
|
2024-08-29 19:32:46 +04:00
|
|
|
|
InitializeComponent();
|
2024-05-23 08:43:54 +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-08-29 19:32:46 +04:00
|
|
|
|
buttonCancel.Click += (sender, e) => Close();
|
2024-05-23 08:43:54 +04:00
|
|
|
|
}
|
2024-08-29 19:32:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Привязка внешнего метода к событию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="trackedVehicleDelegate"></param>
|
|
|
|
|
///
|
2024-10-22 13:26:55 +04:00
|
|
|
|
public void AddEvent(Action<DrawningTrackedVehicle> trackedVehicleDelegate)
|
|
|
|
|
{
|
|
|
|
|
if (TrackedVehicleDelegate == null)
|
|
|
|
|
{
|
|
|
|
|
TrackedVehicleDelegate = trackedVehicleDelegate;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TrackedVehicleDelegate += trackedVehicleDelegate;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-29 19:32:46 +04:00
|
|
|
|
|
2024-05-23 08:43:54 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void DrawObject()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_trackedVehicle?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
_trackedVehicle?.SetPosition(25, 25);
|
|
|
|
|
_trackedVehicle?.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 PanelObject1_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>
|
2024-08-29 19:32:46 +04:00
|
|
|
|
private void PanelObject1_DragDrop(object sender, DragEventArgs e)
|
2024-05-23 08:43:54 +04:00
|
|
|
|
{
|
|
|
|
|
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
|
|
|
|
|
{
|
|
|
|
|
|
2024-08-29 19:32:46 +04:00
|
|
|
|
case "LabelSimpleObject":
|
2024-05-23 08:43:54 +04:00
|
|
|
|
_trackedVehicle = new DrawningTrackedVehicle((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|
|
|
|
break;
|
|
|
|
|
case "LabelModifiedObject":
|
|
|
|
|
_trackedVehicle = new DrawningEntityFighter((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value,
|
|
|
|
|
Color.White,
|
|
|
|
|
Color.Black, checkBoxKovsh.Checked,
|
|
|
|
|
checkBoxOtval.Checked);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DrawObject();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormTrackedVehicleConfig_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передаём информацию при нажатии на Panel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-08-29 19:32:46 +04:00
|
|
|
|
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
2024-05-23 08:43:54 +04:00
|
|
|
|
{
|
|
|
|
|
//TODO отправка цвета в Drag&Drop
|
|
|
|
|
(sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
|
}
|
|
|
|
|
//TODO реализовать логику смены цветов: основного и дополнительного ( для продвинутого объекта)
|
|
|
|
|
private void LabelBodyColor_DragEnter(object? sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-29 19:32:46 +04:00
|
|
|
|
|
|
|
|
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_trackedVehicle.EntityTrackedVehicle is EntityFighter _rockets)
|
|
|
|
|
{
|
|
|
|
|
_rockets.setBodyTankColor((Color)e.Data.GetData(typeof(Color)));
|
|
|
|
|
}
|
|
|
|
|
DrawObject();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_trackedVehicle != null)
|
|
|
|
|
{
|
|
|
|
|
_trackedVehicle.EntityTrackedVehicle.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_trackedVehicle is DrawningEntityFighter)
|
|
|
|
|
{
|
|
|
|
|
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(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_trackedVehicle != null)
|
|
|
|
|
{
|
|
|
|
|
TrackedVehicleDelegate?.Invoke(_trackedVehicle);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void labelAdditionalColor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-23 08:43:54 +04:00
|
|
|
|
}
|