diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs index a2add34..639d5bd 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs @@ -4,7 +4,7 @@ { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public double Step => (double)Speed * 100 / Weight; public AirplaneEntity(int speed, double weight, Color bodyColor) diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs index c531730..8f7a711 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadarEntity.cs @@ -2,7 +2,7 @@ { public class AirplaneWithRadarEntity : AirplaneEntity { - public Color AdditColor { get; private set; } + public Color AdditColor { get; set; } public bool RadarOnBoard { get; private set; } public bool AdditFuelPod { get; private set; } diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs index e590196..e407259 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs @@ -67,19 +67,28 @@ namespace AirplaneWithRadar { return; } - PlaneVisual form = new(); - if (form.ShowDialog() == DialogResult.OK) + var formAirplaneConfig = new FormAirplaneConfig(); + + formAirplaneConfig.AddEvent(airplane => { - if (!(obj + form.SelectedAirplane == -1)) + if (listBoxStorages.SelectedIndex != -1) { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowAirplanes(); + var obj = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]; + if (obj != null) + { + if (obj + airplane != 1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowAirplanes(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + }); + formAirplaneConfig.Show(); } private void ButtonDeleteAirplane_Click(object sender, EventArgs e) diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs new file mode 100644 index 0000000..a3fa2f0 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.Designer.cs @@ -0,0 +1,367 @@ +namespace AirplaneWithRadar +{ + partial class FormAirplaneConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBox1 = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + groupBox2 = new GroupBox(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxAdditFuelPod = new CheckBox(); + checkBoxRadar = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + panelColor = new Panel(); + labelAdditColor = new Label(); + labelMainColor = new Label(); + pictureBoxObject = new PictureBox(); + buttonOk = new Button(); + buttonCancel = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(labelModifiedObject); + groupBox1.Controls.Add(labelSimpleObject); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(checkBoxAdditFuelPod); + groupBox1.Controls.Add(checkBoxRadar); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(label1); + groupBox1.Location = new Point(10, 11); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(428, 427); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(282, 197); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(91, 41); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += labelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(174, 197); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(91, 41); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelObject_MouseDown; + // + // groupBox2 + // + groupBox2.Controls.Add(panelPurple); + groupBox2.Controls.Add(panelBlack); + groupBox2.Controls.Add(panelGray); + groupBox2.Controls.Add(panelWhite); + groupBox2.Controls.Add(panelYellow); + groupBox2.Controls.Add(panelBlue); + groupBox2.Controls.Add(panelGreen); + groupBox2.Controls.Add(panelRed); + groupBox2.Location = new Point(140, 27); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(274, 150); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Цвет"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(209, 86); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(47, 48); + panelPurple.TabIndex = 4; + panelPurple.MouseClick += PanelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(142, 86); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(47, 48); + panelBlack.TabIndex = 3; + panelBlack.MouseClick += PanelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(78, 86); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(47, 48); + panelGray.TabIndex = 2; + panelGray.MouseClick += PanelColor_MouseDown; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(13, 86); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(47, 48); + panelWhite.TabIndex = 1; + panelWhite.MouseClick += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(209, 24); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(47, 48); + panelYellow.TabIndex = 3; + panelYellow.MouseClick += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(142, 24); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(47, 48); + panelBlue.TabIndex = 2; + panelBlue.MouseClick += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(78, 24); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(47, 48); + panelGreen.TabIndex = 1; + panelGreen.MouseClick += PanelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(13, 24); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(47, 48); + panelRed.TabIndex = 0; + panelRed.MouseClick += PanelColor_MouseDown; + // + // checkBoxAdditFuelPod + // + checkBoxAdditFuelPod.AutoSize = true; + checkBoxAdditFuelPod.Location = new Point(19, 167); + checkBoxAdditFuelPod.Name = "checkBoxAdditFuelPod"; + checkBoxAdditFuelPod.Size = new Size(97, 19); + checkBoxAdditFuelPod.TabIndex = 5; + checkBoxAdditFuelPod.Text = "Есть доп. бак"; + checkBoxAdditFuelPod.UseVisualStyleBackColor = true; + // + // checkBoxRadar + // + checkBoxRadar.AutoSize = true; + checkBoxRadar.Location = new Point(19, 142); + checkBoxRadar.Name = "checkBoxRadar"; + checkBoxRadar.Size = new Size(84, 19); + checkBoxRadar.TabIndex = 4; + checkBoxRadar.Text = "Есть радар"; + checkBoxRadar.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(19, 89); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(65, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(19, 45); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(65, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(15, 71); + label2.Name = "label2"; + label2.Size = new Size(26, 15); + label2.TabIndex = 1; + label2.Text = "Вес"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 27); + label1.Name = "label1"; + label1.Size = new Size(59, 15); + label1.TabIndex = 0; + label1.Text = "Скорость"; + // + // panelColor + // + panelColor.AllowDrop = true; + panelColor.Controls.Add(labelAdditColor); + panelColor.Controls.Add(labelMainColor); + panelColor.Controls.Add(pictureBoxObject); + panelColor.Location = new Point(444, 11); + panelColor.Name = "panelColor"; + panelColor.Size = new Size(344, 344); + panelColor.TabIndex = 1; + panelColor.DragDrop += PanelObject_DragDrop; + panelColor.DragEnter += PanelObject_DragEnter; + panelColor.MouseDown += PanelColor_MouseDown; + // + // labelAdditColor + // + labelAdditColor.AllowDrop = true; + labelAdditColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditColor.Location = new Point(193, 21); + labelAdditColor.Name = "labelAdditColor"; + labelAdditColor.Size = new Size(131, 33); + labelAdditColor.TabIndex = 10; + labelAdditColor.Text = "Доп. цвет"; + labelAdditColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditColor.DragDrop += labelAdditColor_DragDrop; + labelAdditColor.DragEnter += labelColor_DragEnter; + labelAdditColor.MouseDown += labelObject_MouseDown; + // + // labelMainColor + // + labelMainColor.AllowDrop = true; + labelMainColor.BorderStyle = BorderStyle.FixedSingle; + labelMainColor.Location = new Point(26, 21); + labelMainColor.Name = "labelMainColor"; + labelMainColor.Size = new Size(128, 33); + labelMainColor.TabIndex = 9; + labelMainColor.Text = "Цвет"; + labelMainColor.TextAlign = ContentAlignment.MiddleCenter; + labelMainColor.DragDrop += labelMainColor_DragDrop; + labelMainColor.DragEnter += labelColor_DragEnter; + labelMainColor.MouseDown += labelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(26, 65); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(298, 264); + pictureBoxObject.TabIndex = 11; + pictureBoxObject.TabStop = false; + // + // buttonOk + // + buttonOk.Location = new Point(470, 379); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(128, 44); + buttonOk.TabIndex = 2; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += buttonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(623, 379); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(128, 44); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormAirplaneConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonOk); + Controls.Add(panelColor); + Controls.Add(groupBox1); + Name = "FormAirplaneConfig"; + Text = "FormAirplaneConfig"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private Label label1; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + private GroupBox groupBox2; + private CheckBox checkBoxAdditFuelPod; + private CheckBox checkBoxRadar; + private Label labelModifiedObject; + private Label labelSimpleObject; + private Panel panelColor; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Label labelAdditColor; + private Label labelMainColor; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs new file mode 100644 index 0000000..0bee073 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.cs @@ -0,0 +1,135 @@ +using AirplaneWithRadar.PaintObjects; +using AirplaneWithRadar.Entities; + +namespace AirplaneWithRadar +{ + public partial class FormAirplaneConfig : Form + { + PaintAirplane? airplane = null; + + private event Action EventAddAirplane; + public FormAirplaneConfig() + { + 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(); + } + + public void DrawAirplane() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + airplane?.SetPosition(5, 5); + airplane?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + public void AddEvent(Action ev) + { + if (EventAddAirplane == null) + { + EventAddAirplane = new Action(ev); + } + else + { + EventAddAirplane += ev; + } + } + + 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) ?? 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 "labelSimpleObject": + airplane = new PaintAirplane((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + airplane = new PaintAirplaneWithRadar((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRadar.Checked, + checkBoxAdditFuelPod.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawAirplane(); + } + + private void labelColor_DragEnter(object sender, DragEventArgs e) + { + if (airplane != null && airplane.AirplaneEntity is AirplaneWithRadarEntity entityAirplane) + { + labelAdditColor.AllowDrop = true; + } + else + { + labelAdditColor.AllowDrop = false; + } + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void labelMainColor_DragDrop(object sender, DragEventArgs e) + { + if (airplane != null) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + airplane.AirplaneEntity.BodyColor = (Color)e.Data.GetData(typeof(Color)); + } + DrawAirplane(); + } + } + + private void labelAdditColor_DragDrop(object sender, DragEventArgs e) + { + if (airplane != null && airplane.AirplaneEntity is AirplaneWithRadarEntity airplaneWithRadarEntity) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + airplaneWithRadarEntity.AdditColor = (Color)e.Data.GetData(typeof(Color)); + } + DrawAirplane(); + } + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddAirplane?.Invoke(airplane); + Close(); + } + } +} \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.resx b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file