From 8cb71ce5edf79c3ab62ba30c31a56c555374d035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 05:26:27 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningObject.cs | 4 +- AirBomber/AirBomber/FormAirBomber.cs | 8 ++- .../FormMapWithSetAirplanes.Designer.cs | 29 ++++++--- .../AirBomber/FormMapWithSetAirplanes.cs | 59 ++++++++++++------- 4 files changed, 66 insertions(+), 34 deletions(-) diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs index 3b12ec9..59087fe 100644 --- a/AirBomber/AirBomber/DrawningObject.cs +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirBomber { - internal class DrawningObject : IDrawningObject + public class DrawningObject : IDrawningObject { private DrawningAirplane _airplane; @@ -29,7 +29,7 @@ namespace AirBomber public void SetObject(int x, int y, int width, int height) { - _airplane.SetPosition(x, y, width, height); + _airplane?.SetPosition(x, y, width, height); } void IDrawningObject.DrawningObject(Graphics g) diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 757fbd9..7bea296 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -8,10 +8,11 @@ namespace AirBomber /// /// /// - public DrawningAirplane SelectedAirplane { get; private set; } + public DrawningObject SelectedAirplane { get; private set; } - public FormAirBomber() + public FormAirBomber(DrawningObject? airplane = null) { + SelectedAirplane = airplane; InitializeComponent(); } /// @@ -22,6 +23,7 @@ namespace AirBomber Bitmap bmp = new(pictureBoxCar.Width, pictureBoxCar.Height); Graphics gr = Graphics.FromImage(bmp); _airplane?.DrawTransport(gr); + pictureBoxCar.Image = bmp; } /// @@ -99,7 +101,7 @@ namespace AirBomber private void buttonSelectAirplane_Click(object sender, EventArgs e) { - SelectedAirplane = _airplane; + SelectedAirplane = new(_airplane); DialogResult = DialogResult.OK; } } diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs index 065664e..8ca3cf0 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs @@ -30,6 +30,7 @@ { this.comboTypeEngines = new System.Windows.Forms.ComboBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.btnAddDeletedObject = new System.Windows.Forms.Button(); this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.buttonAddMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button(); @@ -80,6 +81,7 @@ // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.btnAddDeletedObject); this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane); @@ -94,11 +96,21 @@ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(811, 0); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(204, 779); + this.groupBoxTools.Size = new System.Drawing.Size(204, 810); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; // + // btnAddDeletedObject + // + this.btnAddDeletedObject.Location = new System.Drawing.Point(17, 689); + this.btnAddDeletedObject.Name = "btnAddDeletedObject"; + this.btnAddDeletedObject.Size = new System.Drawing.Size(175, 45); + this.btnAddDeletedObject.TabIndex = 27; + this.btnAddDeletedObject.Text = "Добавить удаленный самолет"; + this.btnAddDeletedObject.UseVisualStyleBackColor = true; + this.btnAddDeletedObject.Click += new System.EventHandler(this.btnAddDeletedObject_Click); + // // groupBoxMaps // this.groupBoxMaps.Controls.Add(this.buttonAddMap); @@ -195,7 +207,7 @@ // this.buttonShowOnMap.Location = new System.Drawing.Point(17, 658); this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); + this.buttonShowOnMap.Size = new System.Drawing.Size(175, 25); this.buttonShowOnMap.TabIndex = 25; this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.UseVisualStyleBackColor = true; @@ -313,7 +325,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(91, 737); + this.buttonDown.Location = new System.Drawing.Point(90, 774); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 10; @@ -325,7 +337,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(127, 737); + this.buttonRight.Location = new System.Drawing.Point(126, 774); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 9; @@ -337,7 +349,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(55, 737); + this.buttonLeft.Location = new System.Drawing.Point(54, 774); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; @@ -349,7 +361,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(91, 701); + this.buttonUp.Location = new System.Drawing.Point(90, 738); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; @@ -361,7 +373,7 @@ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(811, 779); + this.pictureBox.Size = new System.Drawing.Size(811, 810); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -369,7 +381,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1015, 779); + this.ClientSize = new System.Drawing.Size(1015, 810); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Name = "FormMapWithSetAirplanes"; @@ -418,5 +430,6 @@ private Button buttonDeleteMap; private ListBox listBoxMaps; private TextBox textBoxNewMapName; + private Button btnAddDeletedObject; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index ecc3db4..a2b5abf 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -107,14 +107,21 @@ namespace AirBomber ReloadMaps(); } } - /// - /// Добавление самолета на карту - /// - /// самолет. - private void AddAirplaneInMap(DrawningObject airplane) + /// Добавление самолета на карту + /// Самолет + /// Текст MessageBox если самолета нет + /// Заголовок MessageBox если самолета нет + private void AddAirplaneInMap(DrawningObject? airplane, string? text = null, string? caption = null) { - if (airplane == null || - !(_mapsCollection[NameMap] + airplane)) + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (airplane == null) + { + MessageBox.Show(text, caption); + } + else if (!(_mapsCollection[NameMap] + airplane)) { MessageBox.Show("Не удалось добавить объект"); } @@ -180,19 +187,10 @@ namespace AirBomber /// private void btnGenerateAirplane_Click(object sender, EventArgs e) { - if (listBoxMaps.SelectedIndex == -1) - { - return; - } - var airplane = _generatorAirplane.Generate(); - if (airplane == null) - { - MessageBox.Show("Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации" - , "Генерация самолета"); - return; - } - AddAirplaneInMap(airplane); - + AddAirplaneInMap(_generatorAirplane.Generate(), + "Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации", + "Генерация самолета" + ); } /// /// Добавления сущности в генератор @@ -231,7 +229,7 @@ namespace AirBomber FormAirBomber form = new(); if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null) { - AddAirplaneInMap(new(form.SelectedAirplane)); + AddAirplaneInMap(form.SelectedAirplane); } } /// @@ -288,5 +286,24 @@ namespace AirBomber } pictureBox.Image = _mapsCollection[NameMap].ShowOnMap(); } + + private void btnAddDeletedObject_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (_deletedObjects.Count == 0) + { + MessageBox.Show("Нет удаленных объектов", "Добавление удаленного объекта"); + return; + } + FormAirBomber form = new(_deletedObjects.First()); + _deletedObjects.RemoveFirst(); + if (form.ShowDialog() == DialogResult.OK) + { + AddAirplaneInMap(form.SelectedAirplane); + } + } } } \ No newline at end of file