using ProjectCruiser.DrawningSamples; using ProjectCruiser.Entities; using System; namespace ProjectCruiser; public partial class EditorForm3 : Form { private DrawningBase _cruiser; // private event Action? shipDelegate; private event ShipDelegate? shipDelegate; public EditorForm3() { InitializeComponent(); BlueP.MouseDown += Panel_MouseDown; RedP.MouseDown += Panel_MouseDown; PinkP.MouseDown += Panel_MouseDown; YellowP.MouseDown += Panel_MouseDown; CyanP.MouseDown += Panel_MouseDown; PurpleP.MouseDown += Panel_MouseDown; GreenP.MouseDown += Panel_MouseDown; OrangeP.MouseDown += Panel_MouseDown; btnCancel.Click += (sender, e) => Close(); } public void AddEvent(ShipDelegate del)// Action delegator) { if (shipDelegate == null) shipDelegate = del; else shipDelegate += del; //shipDelegate += del; } private void DrawObject() { Bitmap bmp = new(Showcase.Width, Showcase.Height); Graphics gr = Graphics.FromImage(bmp); _cruiser?.SetPictureSize(Showcase.Width, Showcase.Height); _cruiser?.SetPosition(Showcase.Width - 400, Showcase.Height - 120); _cruiser?.DrawTransport(gr); Showcase.Image = bmp; } private void Panel_MouseDown(object? sender, MouseEventArgs e) { // TODO отправка цвета в Drag&Drop (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); } private void BaseAdvLabel_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) { if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void PanelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text)?.ToString()) { case "BaseLabel": _cruiser = new DrawningBase((int)SpeedN.Value, (double)WeightN.Value, Color.White); break; case "AdvLabel": Random rn = new Random(); _cruiser = new DrawningCruiser((int)SpeedN.Value, (double)WeightN.Value, Color.White, Color.Black,checkBoxHangars.Checked); // ADD helicopter PAD as NOT DEFAULT - checkBoxPads.Checked [!] // Convert.ToBoolean(rn.Next(0, 2))); break; } labelMcolor.BackColor = Color.Empty; labelAcolor.BackColor = Color.Empty; DrawObject(); } // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) private void BodyColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void BodyColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser != null) { _cruiser.EntityTransport.setMainColor((Color)e.Data.GetData(typeof(Color))); DrawObject(); } } private void AdditionalColor_DragEnter(object sender, DragEventArgs e) { if (_cruiser is DrawningCruiser) { if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } } private void AdditionalColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser.EntityTransport is EntityCruiser _ship) { _ship.setAdditionalColor((Color)e.Data.GetData(typeof(Color))); } DrawObject(); } private void AddButton_Click(object sender, EventArgs e) { if (_cruiser != null) { shipDelegate?.Invoke(_cruiser); Close(); } } }