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;
using Hydroplane.DrawningObjects;
using Hydroplane.Entities;
namespace Hydroplane
{
public partial class FormPlaneConfig : Form
{
///
/// Переменная-выбранная машина
///
DrawningPlane? _plane = null;
///
/// Событие
///
public event Action? EventAddPlane;
///
/// Конструктор
///
public FormPlaneConfig()
{
InitializeComponent();
panelBlack.MouseDown += panelColor_MouseDown;
panelPurple.MouseDown += panelColor_MouseDown;
panelGray.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelCian.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
button_close.Click += (s, e) => Close();
}
///
/// Отрисовать машину
///
private void DrawPlane()
{
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
Graphics gr = Graphics.FromImage(bmp);
_plane?.SetPosition(5, 5);
_plane?.DrawTransport(gr);
pictureBox.Image = bmp;
}
///
/// Добавление события
///
/// Привязанный метод
public void AddEvent(Action ev)
{
if (EventAddPlane == null)
{
EventAddPlane = ev;
}
else
{
EventAddPlane += ev;
}
}
///
/// Передаем информацию при нажатии на Label
///
///
///
private void Label_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
///
/// Проверка получаемой информации (ее типа на соответствие требуемому)
///
///
///
private void panel_dragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
///
/// Действия при приеме перетаскиваемой информации
///
///
///
private void panel_dragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelOriginalObject":
_plane = new DrawningPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, pictureBox.Width, pictureBox.Height);
break;
case "labelModifiedObject":
_plane = new DrawningHydroplane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBox_boat.Checked, checkBox_bobber.Checked, pictureBox.Width, pictureBox.Height);
break;
}
DrawPlane();
}
public void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void labelColor_dragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelColor_dragDrop(object sender, DragEventArgs e)
{
if (_plane == null)
return;
switch (((Panel)sender).Name)
{
case "panel_color":
_plane?.EntityPlane?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "panel_addit_color":
if (!(_plane is DrawningHydroplane))
return;
(_plane.EntityPlane as EntityHydroplane)?.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawPlane();
}
///
/// Добавление машины
///
///
///
private void button_add_Click(object sender, EventArgs e)
{
EventAddPlane?.Invoke(_plane);
Close();
}
}
}