using ProjectLainer.DrawningObjects; using ProjectLainer.Entities; namespace ProjectLainer { public partial class FormLainerConfig : Form { DrawingEntity? _lainer = null; Action? EventAddLainer; public FormLainerConfig() { InitializeComponent(); panelColorBlack.MouseDown += PanelColor_MouseDown; panelColorPurple.MouseDown += PanelColor_MouseDown; panelColorGray.MouseDown += PanelColor_MouseDown; panelColorGreen.MouseDown += PanelColor_MouseDown; panelColorRed.MouseDown += PanelColor_MouseDown; panelColorCyan.MouseDown += PanelColor_MouseDown; panelColorYellow.MouseDown += PanelColor_MouseDown; panelColorBlue.MouseDown += PanelColor_MouseDown; buttonCancel.Click += (sender, e) => Close(); } private void PanelColor_MouseDown(object? sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); } private void DrawLainer() { Bitmap bmp = new(pictureBoxDragAndDrop.Width, pictureBoxDragAndDrop.Height); Graphics gr = Graphics.FromImage(bmp); _lainer?.SetPosition(5, 5); _lainer?.DrawTransport(gr); pictureBoxDragAndDrop.Image = bmp; } public void AddEvent(Action ev) { if (EventAddLainer == null) { EventAddLainer = ev; } else { EventAddLainer += ev; } } private void labelObject_mouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } private void buttonDone_Click(object sender, EventArgs e) { if (_lainer == null) return; EventAddLainer?.Invoke(_lainer); Close(); } 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 "labelBase": _lainer = new DrawingEntity((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, 729, 397); break; case "labelSuper": _lainer = new DrawningSuperLainer((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPool.Checked, checkBoxDecks.Checked, pictureBoxDragAndDrop.Width, pictureBoxDragAndDrop.Height); break; } DrawLainer(); } private void labelColor_DragDrop(object sender, DragEventArgs e) { if (_lainer?.EntityLainer == null) return; Color bodyColor = (Color)e.Data.GetData(typeof(Color)); _lainer.EntityLainer.ChangeColor(bodyColor); DrawLainer(); } 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 labelAddColor_DragDrop(object sender, DragEventArgs e) { if ((_lainer?.EntityLainer == null) || (_lainer is DrawningSuperLainer == false)) return; Color additionalColor = (Color)e.Data.GetData(typeof(Color)); ((EntitySuperLainer)_lainer.EntityLainer).ChangeAddColor(additionalColor); DrawLainer(); } } }