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; } 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": EntityBase ship = new EntityBase((int)SpeedN.Value, (double)WeightN.Value, Color.White); _cruiser = new DrawningBase(ship); break; case "AdvLabel": Random rn = new Random(); EntityCruiser cruiser = new EntityCruiser((int)SpeedN.Value, (double)WeightN.Value, Color.White, Color.Black, checkBoxPads.Checked, checkBoxHangars.Checked); _cruiser = new DrawningCruiser(cruiser); break; } labelMcolor.BackColor = Color.Empty; labelAcolor.BackColor = Color.Empty; DrawObject(); } // Логика смены цветов: основного и дополнительного (для продвинутого объекта) 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(); } } }