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 Artilleries { public partial class FormArtilleryConfig : Form { DrawingArtillery _artillery = null; private event ArtilleryDelegate EventAddArtillery; public FormArtilleryConfig() { InitializeComponent(); panelBlack.MouseDown += panelColor_MouseDown; panelPurple.MouseDown += panelColor_MouseDown; panelGray.MouseDown += panelColor_MouseDown; panelGreen.MouseDown += panelColor_MouseDown; panelRed.MouseDown += panelColor_MouseDown; panelWhite.MouseDown += panelColor_MouseDown; panelYellow.MouseDown += panelColor_MouseDown; panelBlue.MouseDown += panelColor_MouseDown; buttonCancel.Click += (sender, e) => Close(); } private void DrawArtillery() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); _artillery?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); _artillery?.DrawTransport(gr); pictureBoxObject.Image = bmp; } private void labelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); } private void panelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) { 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 "labelSimpleObject": _artillery = new DrawingArtillery((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); break; case "labelAdvancedObject": _artillery = new DrawingAdvancedArtillery((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWeapon.Checked, checkBoxSalvoBattery.Checked); break; } DrawArtillery(); } private void panelColor_MouseDown(object sender, MouseEventArgs e) { (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); } private void labelColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } private void labelBaseColor_DragDrop(object sender, DragEventArgs e) { _artillery.SetBodyColor((Color) e.Data.GetData(typeof(Color))); DrawArtillery(); } private void labelDopColor_DragDrop(object sender, DragEventArgs e) { if (_artillery is DrawingAdvancedArtillery artillery) { artillery.SetDopColor((Color)e.Data.GetData(typeof(Color))); } DrawArtillery(); } public void AddEvent(ArtilleryDelegate ev) { if (EventAddArtillery == null) { EventAddArtillery = new ArtilleryDelegate(ev); } else { EventAddArtillery += ev; } } private void buttonOk_Click(object sender, EventArgs e) { EventAddArtillery?.Invoke(_artillery); Close(); } } }