Добавление удаленного объекта в форму

This commit is contained in:
Данияр Аглиуллов 2022-10-01 05:26:27 +04:00
parent 86bafe4f71
commit 8cb71ce5ed
4 changed files with 66 additions and 34 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirBomber namespace AirBomber
{ {
internal class DrawningObject : IDrawningObject public class DrawningObject : IDrawningObject
{ {
private DrawningAirplane _airplane; private DrawningAirplane _airplane;
@ -29,7 +29,7 @@ namespace AirBomber
public void SetObject(int x, int y, int width, int height) 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) void IDrawningObject.DrawningObject(Graphics g)

View File

@ -8,10 +8,11 @@ namespace AirBomber
/// <summary> /// <summary>
/// Âűáđŕííűé ńŕěîëĺň /// Âűáđŕííűé ńŕěîëĺň
/// </summary> /// </summary>
public DrawningAirplane SelectedAirplane { get; private set; } public DrawningObject SelectedAirplane { get; private set; }
public FormAirBomber() public FormAirBomber(DrawningObject? airplane = null)
{ {
SelectedAirplane = airplane;
InitializeComponent(); InitializeComponent();
} }
/// <summary> /// <summary>
@ -22,6 +23,7 @@ namespace AirBomber
Bitmap bmp = new(pictureBoxCar.Width, pictureBoxCar.Height); Bitmap bmp = new(pictureBoxCar.Width, pictureBoxCar.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_airplane?.DrawTransport(gr); _airplane?.DrawTransport(gr);
pictureBoxCar.Image = bmp; pictureBoxCar.Image = bmp;
} }
/// <summary> /// <summary>
@ -99,7 +101,7 @@ namespace AirBomber
private void buttonSelectAirplane_Click(object sender, EventArgs e) private void buttonSelectAirplane_Click(object sender, EventArgs e)
{ {
SelectedAirplane = _airplane; SelectedAirplane = new(_airplane);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
} }

View File

@ -30,6 +30,7 @@
{ {
this.comboTypeEngines = new System.Windows.Forms.ComboBox(); this.comboTypeEngines = new System.Windows.Forms.ComboBox();
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.btnAddDeletedObject = new System.Windows.Forms.Button();
this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.buttonAddMap = new System.Windows.Forms.Button(); this.buttonAddMap = new System.Windows.Forms.Button();
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button();
@ -80,6 +81,7 @@
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.btnAddDeletedObject);
this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane); this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
@ -94,11 +96,21 @@
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(811, 0); this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
this.groupBoxTools.Name = "groupBoxTools"; 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.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; 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 // groupBoxMaps
// //
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap);
@ -195,7 +207,7 @@
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 658); this.buttonShowOnMap.Location = new System.Drawing.Point(17, 658);
this.buttonShowOnMap.Name = "buttonShowOnMap"; 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.TabIndex = 25;
this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true; 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.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.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 10; 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.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.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 9; 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.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.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8; 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.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.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7; this.buttonUp.TabIndex = 7;
@ -361,7 +373,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox"; 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.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -369,7 +381,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetAirplanes"; this.Name = "FormMapWithSetAirplanes";
@ -418,5 +430,6 @@
private Button buttonDeleteMap; private Button buttonDeleteMap;
private ListBox listBoxMaps; private ListBox listBoxMaps;
private TextBox textBoxNewMapName; private TextBox textBoxNewMapName;
private Button btnAddDeletedObject;
} }
} }

View File

@ -107,14 +107,21 @@ namespace AirBomber
ReloadMaps(); ReloadMaps();
} }
} }
/// <summary> /// <summary>Добавление самолета на карту</summary>
/// Добавление самолета на карту /// <param name="airplane">Самолет</param>
/// </summary> /// <param name="text">Текст MessageBox если самолета нет</param>
/// <param name="airplane">самолет.</param> /// <param name="caption">Заголовок MessageBox если самолета нет</param>
private void AddAirplaneInMap(DrawningObject airplane) private void AddAirplaneInMap(DrawningObject? airplane, string? text = null, string? caption = null)
{ {
if (airplane == null || if (listBoxMaps.SelectedIndex == -1)
!(_mapsCollection[NameMap] + airplane)) {
return;
}
if (airplane == null)
{
MessageBox.Show(text, caption);
}
else if (!(_mapsCollection[NameMap] + airplane))
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
@ -180,19 +187,10 @@ namespace AirBomber
/// <param name="e"></param> /// <param name="e"></param>
private void btnGenerateAirplane_Click(object sender, EventArgs e) private void btnGenerateAirplane_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1) AddAirplaneInMap(_generatorAirplane.Generate(),
{ "Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации",
return; "Генерация самолета"
} );
var airplane = _generatorAirplane.Generate();
if (airplane == null)
{
MessageBox.Show("Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации"
, "Генерация самолета");
return;
}
AddAirplaneInMap(airplane);
} }
/// <summary> /// <summary>
/// Добавления сущности в генератор /// Добавления сущности в генератор
@ -231,7 +229,7 @@ namespace AirBomber
FormAirBomber form = new(); FormAirBomber form = new();
if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null) if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null)
{ {
AddAirplaneInMap(new(form.SelectedAirplane)); AddAirplaneInMap(form.SelectedAirplane);
} }
} }
/// <summary> /// <summary>
@ -288,5 +286,24 @@ namespace AirBomber
} }
pictureBox.Image = _mapsCollection[NameMap].ShowOnMap(); 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);
}
}
} }
} }