diff --git a/AirBomber/AirBomber/FormAirplaneConfig.Designer.cs b/AirBomber/AirBomber/FormAirplaneConfig.Designer.cs index d5efde8..6308062 100644 --- a/AirBomber/AirBomber/FormAirplaneConfig.Designer.cs +++ b/AirBomber/AirBomber/FormAirplaneConfig.Designer.cs @@ -40,7 +40,6 @@ this.panelGreen = new System.Windows.Forms.Panel(); this.panelWhite = new System.Windows.Forms.Panel(); this.panelRed = new System.Windows.Forms.Panel(); - this.checkBoxSportLine = new System.Windows.Forms.CheckBox(); this.checkBoxHasFuelTanks = new System.Windows.Forms.CheckBox(); this.checkBoxHasBombs = new System.Windows.Forms.CheckBox(); this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); @@ -66,7 +65,6 @@ this.groupBoxConfig.Controls.Add(this.labelModifiedObject); this.groupBoxConfig.Controls.Add(this.labelSimpleObject); this.groupBoxConfig.Controls.Add(this.groupBoxColors); - this.groupBoxConfig.Controls.Add(this.checkBoxSportLine); this.groupBoxConfig.Controls.Add(this.checkBoxHasFuelTanks); this.groupBoxConfig.Controls.Add(this.checkBoxHasBombs); this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); @@ -183,34 +181,25 @@ this.panelRed.Size = new System.Drawing.Size(40, 40); this.panelRed.TabIndex = 0; // - // checkBoxSportLine - // - this.checkBoxSportLine.AutoSize = true; - this.checkBoxSportLine.Location = new System.Drawing.Point(22, 185); - this.checkBoxSportLine.Name = "checkBoxSportLine"; - this.checkBoxSportLine.Size = new System.Drawing.Size(226, 19); - this.checkBoxSportLine.TabIndex = 13; - this.checkBoxSportLine.Text = "Признак наличия гоночной полосы"; - this.checkBoxSportLine.UseVisualStyleBackColor = true; - // // checkBoxHasFuelTanks // this.checkBoxHasFuelTanks.AutoSize = true; - this.checkBoxHasFuelTanks.Location = new System.Drawing.Point(22, 149); + this.checkBoxHasFuelTanks.Location = new System.Drawing.Point(22, 165); this.checkBoxHasFuelTanks.Name = "checkBoxHasFuelTanks"; - this.checkBoxHasFuelTanks.Size = new System.Drawing.Size(186, 19); + this.checkBoxHasFuelTanks.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.checkBoxHasFuelTanks.Size = new System.Drawing.Size(222, 19); this.checkBoxHasFuelTanks.TabIndex = 12; - this.checkBoxHasFuelTanks.Text = "Признак наличия антикрыла"; + this.checkBoxHasFuelTanks.Text = "Признак наличия топливных баков"; this.checkBoxHasFuelTanks.UseVisualStyleBackColor = true; // // checkBoxHasBombs // this.checkBoxHasBombs.AutoSize = true; - this.checkBoxHasBombs.Location = new System.Drawing.Point(22, 115); + this.checkBoxHasBombs.Location = new System.Drawing.Point(22, 130); this.checkBoxHasBombs.Name = "checkBoxHasBombs"; - this.checkBoxHasBombs.Size = new System.Drawing.Size(164, 19); + this.checkBoxHasBombs.Size = new System.Drawing.Size(156, 19); this.checkBoxHasBombs.TabIndex = 11; - this.checkBoxHasBombs.Text = "Признак наличия обвеса"; + this.checkBoxHasBombs.Text = "Признак наличия бомб"; this.checkBoxHasBombs.UseVisualStyleBackColor = true; // // numericUpDownWeight @@ -298,6 +287,8 @@ this.labelDopColor.TabIndex = 2; this.labelDopColor.Text = "Доп. цвет"; this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); + this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter); // // labelBaseColor // @@ -309,6 +300,8 @@ this.labelBaseColor.TabIndex = 1; this.labelBaseColor.Text = "Цвет"; this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); // // pictureBoxObject // @@ -362,7 +355,6 @@ #endregion private GroupBox groupBoxConfig; - private CheckBox checkBoxSportLine; private CheckBox checkBoxHasFuelTanks; private CheckBox checkBoxHasBombs; private NumericUpDown numericUpDownWeight; diff --git a/AirBomber/AirBomber/FormAirplaneConfig.cs b/AirBomber/AirBomber/FormAirplaneConfig.cs index cdfb01b..4a088ad 100644 --- a/AirBomber/AirBomber/FormAirplaneConfig.cs +++ b/AirBomber/AirBomber/FormAirplaneConfig.cs @@ -6,13 +6,13 @@ public partial class FormAirplaneConfig : Form { /// - /// Переменная-выбранная машина + /// Переменная-выбранная самолет /// - DrawningAirplane _car = null; + DrawningAirplane _airplane = null; /// /// Событие /// - private event AirplaneDelegate EventAddAirplane; + private event Action EventAddAirplane; /// /// Конструктор /// @@ -28,28 +28,28 @@ panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - // TODO buttonCancel.Click with lambda + buttonCancel.Click += (s, e) => Close(); } /// - /// Отрисовать машину + /// Отрисовать самолет /// private void DrawAirplane() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); - _car?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); - _car?.DrawTransport(gr); + _airplane?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); + _airplane?.DrawTransport(gr); pictureBoxObject.Image = bmp; } /// /// Добавление события /// /// - public void AddEvent(AirplaneDelegate ev) + public void AddEvent(Action ev) { if (EventAddAirplane == null) { - EventAddAirplane = new AirplaneDelegate(ev); + EventAddAirplane = new(ev); } else { @@ -91,10 +91,10 @@ switch (e.Data.GetData(DataFormats.Text).ToString()) { case "labelSimpleObject": - _car = new DrawningAirplane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); + _airplane = new DrawningAirplane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); break; case "labelModifiedObject": - _car = new DrawningAirBomber((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, + _airplane = new DrawningAirBomber((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHasBombs.Checked, checkBoxHasFuelTanks.Checked); break; } @@ -110,13 +110,14 @@ (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); } /// - /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// Установливает статус перемещаемых данных /// - /// /// - private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + /// Тип которого должны соответствовать перемещаемые данные + /// условие на возможность копирования данных + private void setDragEffect(DragEventArgs e, Type needTypeData, bool condition) { - if (e.Data.GetDataPresent(typeof(Color))) + if (e.Data.GetDataPresent(needTypeData) && condition) { e.Effect = DragDropEffects.Copy; } @@ -126,13 +127,30 @@ } } /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _airplane != null); + private void LabelDopColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _airplane != null && _airplane is DrawningAirBomber); + /// /// Принимаем основной цвет /// /// /// private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { - // TODO Call method from object _car and set color + var color = (Color)e.Data.GetData(typeof(Color)); + if (_airplane is DrawningAirBomber) + { + var a = (EntityAirBomber)_airplane.Airplane; + _airplane = new DrawningAirBomber(a.Speed, a.Weight, color, a.DopColor, a.HasBombs, a.HasFuelTanks); + } + else if (_airplane is DrawningAirplane) + { + _airplane = new DrawningAirplane(_airplane.Airplane.Speed, _airplane.Airplane.Weight, color); + } + DrawAirplane(); } /// /// Принимаем дополнительный цвет @@ -141,16 +159,22 @@ /// private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - // TODO Call method from object _car if _car is DrawningSportAirplane and set dop color + var color = (Color)e.Data.GetData(typeof(Color)); + if (_airplane is DrawningAirBomber) + { + var a = (EntityAirBomber)_airplane.Airplane; + _airplane = new DrawningAirBomber(a.Speed, a.Weight, a.BodyColor, color, a.HasBombs, a.HasFuelTanks); + } + DrawAirplane(); } /// - /// Добавление машины + /// Добавление самолета /// /// /// private void ButtonOk_Click(object sender, EventArgs e) { - EventAddAirplane?.Invoke(_car); + EventAddAirplane?.Invoke(_airplane); Close(); } } diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index 201c42d..0423e3f 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -104,7 +104,7 @@ private void ButtonAddAirplane_Click(object sender, EventArgs e) { FormAirplaneConfig formAirplane = new(); - formAirplane.AddEvent(new AirplaneDelegate(AddAirplane)); + formAirplane.AddEvent(new(AddAirplane)); formAirplane.Show(); } /// @@ -115,9 +115,9 @@ { if (listBoxMaps.SelectedIndex == -1) { - return; + MessageBox.Show("Перед добавлением объекта необходимо создать карту"); } - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(airplane) != -1) + else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(airplane) != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();