PIBD-14_Lavrova_K.I._Simple/solution/lab1/FormTrackedVehicleConfig.cs

195 lines
6.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
/// <summary>
/// Форма конфигурации объекта
/// </summary>
public partial class FormTrackedVehicleConfig : Form
{
/// <summary>
/// Объект - прорисовка гусеничной машины
/// </summary>
private DrawningTrackedVehicle? _trackedVehicle;
/// <summary>
/// Событие для предачи объекта
/// </summary>
private event Action<DrawningTrackedVehicle>? TrackedVehicleDelegate;
/// <summary>
/// Конструктор
/// </summary>
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();
}
/// <summary>
/// Привязка внешнего метода к событию
/// </summary>
/// <param name="trackedVehicleDelegate"></param>
///
public void AddEvent(Action<DrawningTrackedVehicle> trackedVehicleDelegate)
{
if (TrackedVehicleDelegate == null)
{
TrackedVehicleDelegate = trackedVehicleDelegate;
}
else
{
TrackedVehicleDelegate += trackedVehicleDelegate;
}
}
/// <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>
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)
{
}
/// <summary>
/// Передаём информацию при нажатии на Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
}
/// <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)
{
}
}