diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs
index ba2b1e2..4308f24 100644
--- a/AirBomber/AirBomber/DrawningAirPlane.cs
+++ b/AirBomber/AirBomber/DrawningAirPlane.cs
@@ -274,6 +274,5 @@ namespace AirBomber
///
public IMoveableObject GetMoveableObject => new
DrawningObjectAirPlane(this);
-
}
}
diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs
index f762bda..b670071 100644
--- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs
+++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs
@@ -29,13 +29,19 @@
private void InitializeComponent()
{
pictureBoxCollection = new PictureBox();
- panelTools = new Panel();
- maskedTextBoxNumber = new MaskedTextBox();
- buttonRefreshCollection = new Button();
- buttonRemovePlane = new Button();
buttonAddPlane = new Button();
+ buttonRemovePlane = new Button();
+ buttonRefreshCollection = new Button();
+ maskedTextBoxNumber = new MaskedTextBox();
+ groupBoxTools = new GroupBox();
+ groupBoxStorages = new GroupBox();
+ textBoxStorageName = new TextBox();
+ buttonDelObject = new Button();
+ buttonAddObject = new Button();
+ listBoxStorages = new ListBox();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
- panelTools.SuspendLayout();
+ groupBoxTools.SuspendLayout();
+ groupBoxStorages.SuspendLayout();
SuspendLayout();
//
// pictureBoxCollection
@@ -44,54 +50,13 @@
pictureBoxCollection.Dock = DockStyle.Left;
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
- pictureBoxCollection.Size = new Size(708, 548);
+ pictureBoxCollection.Size = new Size(708, 746);
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
//
- // panelTools
- //
- panelTools.Controls.Add(maskedTextBoxNumber);
- panelTools.Controls.Add(buttonRefreshCollection);
- panelTools.Controls.Add(buttonRemovePlane);
- panelTools.Controls.Add(buttonAddPlane);
- panelTools.Dock = DockStyle.Right;
- panelTools.Location = new Point(719, 0);
- panelTools.Name = "panelTools";
- panelTools.Size = new Size(237, 548);
- panelTools.TabIndex = 1;
- //
- // maskedTextBoxNumber
- //
- maskedTextBoxNumber.Location = new Point(37, 218);
- maskedTextBoxNumber.Mask = "00";
- maskedTextBoxNumber.Name = "maskedTextBoxNumber";
- maskedTextBoxNumber.Size = new Size(160, 31);
- maskedTextBoxNumber.TabIndex = 3;
- maskedTextBoxNumber.ValidatingType = typeof(int);
- //
- // buttonRefreshCollection
- //
- buttonRefreshCollection.Location = new Point(37, 394);
- buttonRefreshCollection.Name = "buttonRefreshCollection";
- buttonRefreshCollection.Size = new Size(160, 86);
- buttonRefreshCollection.TabIndex = 2;
- buttonRefreshCollection.Text = "Обновить коллекцию";
- buttonRefreshCollection.UseVisualStyleBackColor = true;
- buttonRefreshCollection.Click += buttonRefreshCollection_Click;
- //
- // buttonRemovePlane
- //
- buttonRemovePlane.Location = new Point(37, 266);
- buttonRemovePlane.Name = "buttonRemovePlane";
- buttonRemovePlane.Size = new Size(160, 60);
- buttonRemovePlane.TabIndex = 1;
- buttonRemovePlane.Text = "Удалить самолет";
- buttonRemovePlane.UseVisualStyleBackColor = true;
- buttonRemovePlane.Click += buttonRemovePlane_Click;
- //
// buttonAddPlane
//
- buttonAddPlane.Location = new Point(37, 94);
+ buttonAddPlane.Location = new Point(76, 417);
buttonAddPlane.Name = "buttonAddPlane";
buttonAddPlane.Size = new Size(160, 64);
buttonAddPlane.TabIndex = 0;
@@ -99,28 +64,128 @@
buttonAddPlane.UseVisualStyleBackColor = true;
buttonAddPlane.Click += buttonAddPlane_Click;
//
+ // buttonRemovePlane
+ //
+ buttonRemovePlane.Location = new Point(76, 549);
+ buttonRemovePlane.Name = "buttonRemovePlane";
+ buttonRemovePlane.Size = new Size(160, 60);
+ buttonRemovePlane.TabIndex = 1;
+ buttonRemovePlane.Text = "Удалить самолет";
+ buttonRemovePlane.UseVisualStyleBackColor = true;
+ buttonRemovePlane.Click += buttonRemovePlane_Click;
+ //
+ // buttonRefreshCollection
+ //
+ buttonRefreshCollection.Location = new Point(76, 648);
+ buttonRefreshCollection.Name = "buttonRefreshCollection";
+ buttonRefreshCollection.Size = new Size(160, 86);
+ buttonRefreshCollection.TabIndex = 2;
+ buttonRefreshCollection.Text = "Обновить коллекцию";
+ buttonRefreshCollection.UseVisualStyleBackColor = true;
+ buttonRefreshCollection.Click += buttonRefreshCollection_Click;
+ //
+ // maskedTextBoxNumber
+ //
+ maskedTextBoxNumber.Location = new Point(76, 501);
+ maskedTextBoxNumber.Mask = "00";
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(160, 31);
+ maskedTextBoxNumber.TabIndex = 3;
+ maskedTextBoxNumber.ValidatingType = typeof(int);
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(groupBoxStorages);
+ groupBoxTools.Controls.Add(buttonAddPlane);
+ groupBoxTools.Controls.Add(buttonRefreshCollection);
+ groupBoxTools.Controls.Add(buttonRemovePlane);
+ groupBoxTools.Controls.Add(maskedTextBoxNumber);
+ groupBoxTools.Location = new Point(714, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(305, 746);
+ groupBoxTools.TabIndex = 4;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // groupBoxStorages
+ //
+ groupBoxStorages.Controls.Add(textBoxStorageName);
+ groupBoxStorages.Controls.Add(buttonDelObject);
+ groupBoxStorages.Controls.Add(buttonAddObject);
+ groupBoxStorages.Controls.Add(listBoxStorages);
+ groupBoxStorages.Location = new Point(5, 30);
+ groupBoxStorages.Name = "groupBoxStorages";
+ groupBoxStorages.Size = new Size(294, 368);
+ groupBoxStorages.TabIndex = 4;
+ groupBoxStorages.TabStop = false;
+ groupBoxStorages.Text = "Наборы";
+ //
+ // textBoxStorageName
+ //
+ textBoxStorageName.Location = new Point(6, 54);
+ textBoxStorageName.Name = "textBoxStorageName";
+ textBoxStorageName.Size = new Size(281, 31);
+ textBoxStorageName.TabIndex = 3;
+ //
+ // buttonDelObject
+ //
+ buttonDelObject.Location = new Point(44, 305);
+ buttonDelObject.Name = "buttonDelObject";
+ buttonDelObject.Size = new Size(209, 34);
+ buttonDelObject.TabIndex = 2;
+ buttonDelObject.Text = "Удалить набор";
+ buttonDelObject.UseVisualStyleBackColor = true;
+ buttonDelObject.Click += buttonDelObject_Click;
+ //
+ // buttonAddObject
+ //
+ buttonAddObject.Location = new Point(44, 106);
+ buttonAddObject.Name = "buttonAddObject";
+ buttonAddObject.Size = new Size(209, 34);
+ buttonAddObject.TabIndex = 1;
+ buttonAddObject.Text = "Добавить набор";
+ buttonAddObject.UseVisualStyleBackColor = true;
+ buttonAddObject.Click += buttonAddObject_Click;
+ //
+ // listBoxStorages
+ //
+ listBoxStorages.FormattingEnabled = true;
+ listBoxStorages.ItemHeight = 25;
+ listBoxStorages.Location = new Point(6, 160);
+ listBoxStorages.Name = "listBoxStorages";
+ listBoxStorages.Size = new Size(281, 129);
+ listBoxStorages.TabIndex = 0;
+ listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
+ //
// FormPlaneCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(956, 548);
- Controls.Add(panelTools);
+ ClientSize = new Size(1030, 746);
+ Controls.Add(groupBoxTools);
Controls.Add(pictureBoxCollection);
Name = "FormPlaneCollection";
Text = "Набор самолетов";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
- panelTools.ResumeLayout(false);
- panelTools.PerformLayout();
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ groupBoxStorages.ResumeLayout(false);
+ groupBoxStorages.PerformLayout();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxCollection;
- private Panel panelTools;
- private MaskedTextBox maskedTextBoxNumber;
- private Button buttonRefreshCollection;
- private Button buttonRemovePlane;
private Button buttonAddPlane;
+ private Button buttonRemovePlane;
+ private Button buttonRefreshCollection;
+ private MaskedTextBox maskedTextBoxNumber;
+ private GroupBox groupBoxTools;
+ private GroupBox groupBoxStorages;
+ private TextBox textBoxStorageName;
+ private Button buttonDelObject;
+ private Button buttonAddObject;
+ private ListBox listBoxStorages;
}
}
\ No newline at end of file
diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs
index eba8446..49ce1c9 100644
--- a/AirBomber/AirBomber/FormPlaneCollection.cs
+++ b/AirBomber/AirBomber/FormPlaneCollection.cs
@@ -15,13 +15,41 @@ namespace AirBomber
///
/// Набор объектов
///
- private readonly PlanesGenericCollection _planes;
-
+ private readonly PlanesGenericStorage _storage;
public FormPlaneCollection()
{
InitializeComponent();
- _planes = new PlanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ _storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+ ///
+ /// Заполнение listBoxObjects
+ ///
+ private void ReloadObjects()
+ {
+ int index = listBoxStorages.SelectedIndex;
+ listBoxStorages.Items.Clear();
+ for (int i = 0; i < _storage.Keys.Count; i++)
+ {
+ listBoxStorages.Items.Add(_storage.Keys[i]);
+ }
+ if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
+ {
+ listBoxStorages.SelectedIndex = 0;
+ }
+ else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
+ {
+ listBoxStorages.SelectedIndex = index;
+ }
+ }
+ ///
+ /// Выбор набора
+ ///
+ ///
+ ///
+ private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes();
}
///
/// Добавление объекта в набор
@@ -30,13 +58,22 @@ namespace AirBomber
///
private void buttonAddPlane_Click(object sender, EventArgs e)
{
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString()?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
FormAirBomber form = new();
if (form.ShowDialog() == DialogResult.OK)
{
- if (_planes + form.SelectedPlane != -1)
+ if (obj + form.SelectedPlane > -1)
{
MessageBox.Show("Объект добавлен");
- pictureBoxCollection.Image = _planes.ShowPlanes();
+ pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
@@ -51,15 +88,24 @@ namespace AirBomber
///
private void buttonRemovePlane_Click(object sender, EventArgs e)
{
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
- if (_planes - pos != null)
+ if (obj - pos != null)
{
MessageBox.Show("Объект удален");
- pictureBoxCollection.Image = _planes.ShowPlanes();
+ pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
@@ -73,7 +119,44 @@ namespace AirBomber
///
private void buttonRefreshCollection_Click(object sender, EventArgs e)
{
- pictureBoxCollection.Image = _planes.ShowPlanes();
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
+ pictureBoxCollection.Image = obj.ShowPlanes();
+ }
+ ///
+ /// Добавление набора в коллекцию
+ ///
+ ///
+ ///
+ private void buttonAddObject_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxStorageName.Text))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _storage.AddSet(textBoxStorageName.Text);
+ ReloadObjects();
+ }
+ private void buttonDelObject_Click(object sender, EventArgs e)
+ {
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+{
+ _storage.DelSet(listBoxStorages.SelectedItem.ToString()?? string.Empty);
+ ReloadObjects();
+ }
}
}
}
diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs
index 5d4cbf8..b9950a1 100644
--- a/AirBomber/AirBomber/PlanesGenericCollection.cs
+++ b/AirBomber/AirBomber/PlanesGenericCollection.cs
@@ -65,7 +65,7 @@ namespace AirBomber
///
public static bool operator -(PlanesGenericCollection collect, int pos)
{
- T? obj = collect._collection.Get(pos);
+ T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
@@ -80,7 +80,7 @@ namespace AirBomber
///
public U? GetU(int pos)
{
- return (U?)_collection.Get(pos)?.GetMoveableObject;
+ return (U?)_collection[pos]?.GetMoveableObject;
}
///
/// Вывод всего набора объектов
@@ -103,15 +103,13 @@ namespace AirBomber
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
- for (int j = 0; j < _pictureHeight / _placeSizeHeight +
- 1; ++j)
- {//линия рамзетки места
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {
+ //линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j *
- _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
- _placeSizeHeight);
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
- g.DrawLine(pen, i * _placeSizeWidth, 0, i *
- _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
///
@@ -123,7 +121,7 @@ namespace AirBomber
int widthObjCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
- T? type = _collection.Get(i);
+ T? type = _collection[i];
if (type != null)
{
int row = i / widthObjCount;
diff --git a/AirBomber/AirBomber/PlanesGenericStorage.cs b/AirBomber/AirBomber/PlanesGenericStorage.cs
new file mode 100644
index 0000000..40918b3
--- /dev/null
+++ b/AirBomber/AirBomber/PlanesGenericStorage.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal class PlanesGenericStorage
+ {
+ ///
+ /// Словарь (хранилище)
+ ///
+ readonly Dictionary> _planeStorages;
+ ///
+ /// Возвращение списка названий наборов
+ ///
+ public List Keys => _planeStorages.Keys.ToList();
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public PlanesGenericStorage(int pictureWidth, int pictureHeight)
+ {
+ _planeStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ ///
+ /// Добавление набора
+ ///
+ /// Название набора
+ public void AddSet(string name)
+ {
+ // TODO Прописать логику для добавления DONE
+ if (!_planeStorages.ContainsKey(name))
+ {
+ _planeStorages.Add(name, new PlanesGenericCollection(_pictureWidth, _pictureHeight));
+ }
+ }
+ ///
+ /// Удаление набора
+ ///
+ /// Название набора
+ public void DelSet(string name)
+ {
+ // TODO Прописать логику для удаления DONE
+ if (_planeStorages.ContainsKey(name))
+ {
+ _planeStorages.Remove(name);
+ }
+ }
+ ///
+ /// Доступ к набору
+ ///
+ ///
+ ///
+ public PlanesGenericCollection?
+ this[string ind]
+ {
+ get
+ {
+ // TODO Продумать логику получения набора DONE
+ if (_planeStorages.ContainsKey(ind))
+ {
+ return _planeStorages[ind];
+ }
+ return null;
+ }
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs
index b1b0f54..ca8d15b 100644
--- a/AirBomber/AirBomber/SetGeneric.cs
+++ b/AirBomber/AirBomber/SetGeneric.cs
@@ -12,18 +12,23 @@ namespace AirBomber
///
/// Массив объектов, которые храним
///
- private readonly T?[] _places;
+ private readonly List _places;
///
/// Количество объектов в массиве
///
- public int Count => _places.Length;
+ public int Count => _places.Count;
+ ///
+ /// Максимальное количество объектов в списке
+ ///
+ private readonly int _maxCount;
///
/// Конструктор
///
///
public SetGeneric(int count)
{
- _places = new T?[count];
+ _maxCount = count;
+ _places = new List(count);
}
///
/// Добавление объекта в набор
@@ -48,32 +53,9 @@ namespace AirBomber
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
- int NoEmpty = 0, temp = 0;
- for (int i = position; i < Count; i++)
- {
- if (_places[i] != null) NoEmpty++;
- }
- if (NoEmpty == Count - position) return -1;
-
- if (position < Count && position >= 0)
- {
- for (int j = position; j < Count; j++)
- {
- if (_places[j] == null)
- {
- temp = j;
- break;
- }
- }
-
- for (int i = temp; i > position; i--)
- {
- _places[i] = _places[i - 1];
- }
- _places[position] = plane;
- return position;
- }
- return -1;
+ if (position < 0 || position >= _maxCount) return -1;
+ _places.Insert(position, plane);
+ return position;
}
///
/// Удаление объекта из набора с конкретной позиции
@@ -96,15 +78,40 @@ namespace AirBomber
///
///
///
- public T? Get(int position)
+ public T? this[int position]
{
- // TODO проверка позиции DONE
- if (position < 0 || position >= Count)
+ get
{
- return null;
+ // TODO проверка позиции DONE
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ set
+ {
+ // TODO проверка позиции DONE
+ // TODO проверка свободных мест в списке DONE
+ // TODO вставка в список по позиции DONE
+ if (position < 0 || position >= Count || Count == _maxCount) return;
+ _places.Insert(position, value);
+ }
+ }
+ ///
+ /// Проход по списку
+ ///
+ ///
+ public IEnumerable GetPlanes(int? maxPlanes = null)
+ {
+ for (int i = 0; i < _places.Count; ++i)
+ {
+ yield return _places[i];
+ if (maxPlanes.HasValue && i == maxPlanes.Value)
+ {
+ yield break;
+ }
}
- return _places[position];
}
-
}
}