using ProjectPlane.Drawnings; using ProjectPlane.Entities; namespace ProjectPlane; public partial class FormShipConfig : Form { private DrawningShip? _ship; private event Action? ShipDelegate; public FormShipConfig() { 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(); } private void DrawObject() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); _ship?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); _ship?.SetPosition(15, 15); _ship?.DrawTransport(gr); pictureBoxObject.Image = bmp; } public void AddEvent(Action shipDelegate) { ShipDelegate += shipDelegate; } private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); } private void PanelObject_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None; } private void PanelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text)?.ToString()) { case "labelSimpleObject": _ship = new DrawningShip((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); break; case "labelModifiedObject": _ship = new DrawCont((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxContainer.Checked, checkBoxCrane.Checked); break; } DrawObject(); } private void Panel_MouseDown(object? sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy); } private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; } /// /// Действия при приеме перетаскиваемой информации(Основной цвет) /// /// /// private void LabelBodyColor_DragDrop(object sender, DragEventArgs e) { _ship?.EntityShip?.ShipColorChange((Color)e.Data?.GetData(typeof(Color))); DrawObject(); } /// /// Проверка получаемой информации(Доп. цвет) (ее типа на соответствие требуемому) /// /// /// private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; } /// /// Действия при приеме перетаскиваемой информации(Доп. цвет) /// /// /// private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) { if (_ship?.EntityShip is EntityContainer _container) { _container.ContainerColorChange((Color)e.Data?.GetData(typeof(Color))); } DrawObject(); } private void ButtonAdd_Click(object sender, EventArgs e) { if (_ship != null) { ShipDelegate?.Invoke(_ship); Close(); } } }