using lab1.Drawnings; using lab1.Entities; 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; /// /// Форма конфигурации объекта /// public partial class FormTrackedVehicleConfig : Form { /// /// Объект - прорисовка гусеничной машины /// private DrawningTrackedVehicle? _trackedVehicle; /// /// Событие для предачи объекта /// private event Action? TrackedVehicleDelegate; /// /// Конструктор /// public FormTrackedVehicleConfig() { InitializeComponent(); 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; buttonCancel.Click += (sender, e) => Close(); } /// /// Привязка внешнего метода к событию /// /// /// public void AddEvent(Action trackedVehicleDelegate) { if (TrackedVehicleDelegate == null) { TrackedVehicleDelegate = trackedVehicleDelegate; } else { TrackedVehicleDelegate += trackedVehicleDelegate; } } /// /// Прорисовка объекта /// 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; } /// /// Передаём информацию при нажатии на Label /// /// /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); } /// /// Проверка получаемой информации(ее типа на соответствие требуемому) /// /// /// private void PanelObject1_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None; } /// /// Действия при приёме перетаскиваемой информации /// /// /// private void PanelObject1_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text)?.ToString()) { case "LabelSimpleObject": _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) { } /// /// Передаём информацию при нажатии на Panel /// /// /// private void Panel_MouseDown(object? sender, MouseEventArgs e) { //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; } } 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; } } } /// /// Передача объекта /// /// /// private void buttonAdd_Click(object sender, EventArgs e) { if (_trackedVehicle != null) { TrackedVehicleDelegate?.Invoke(_trackedVehicle); Close(); } } private void labelAdditionalColor_Click(object sender, EventArgs e) { } }