Commit
This commit is contained in:
parent
99b22b3d7c
commit
8dc12df36b
78
gidro/FormPlaneCollection.Designer.cs
generated
78
gidro/FormPlaneCollection.Designer.cs
generated
@ -30,12 +30,18 @@
|
|||||||
{
|
{
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
|
groupBox2 = new GroupBox();
|
||||||
|
buttonDeleteObject = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
buttonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
buttonRefreshCollection = new Button();
|
buttonRefreshCollection = new Button();
|
||||||
buttonRemovePlane = new Button();
|
buttonRemovePlane = new Button();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
buttonAddPlane = new Button();
|
buttonAddPlane = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
|
groupBox2.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
@ -43,26 +49,77 @@
|
|||||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||||
pictureBoxCollection.Location = new Point(0, 0);
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(1026, 443);
|
pictureBoxCollection.Size = new Size(1026, 446);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
|
groupBox1.Controls.Add(groupBox2);
|
||||||
groupBox1.Controls.Add(buttonRefreshCollection);
|
groupBox1.Controls.Add(buttonRefreshCollection);
|
||||||
groupBox1.Controls.Add(buttonRemovePlane);
|
groupBox1.Controls.Add(buttonRemovePlane);
|
||||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
groupBox1.Controls.Add(buttonAddPlane);
|
groupBox1.Controls.Add(buttonAddPlane);
|
||||||
groupBox1.Location = new Point(852, 0);
|
groupBox1.Location = new Point(852, 0);
|
||||||
groupBox1.Name = "groupBox1";
|
groupBox1.Name = "groupBox1";
|
||||||
groupBox1.Size = new Size(174, 421);
|
groupBox1.Size = new Size(174, 439);
|
||||||
groupBox1.TabIndex = 2;
|
groupBox1.TabIndex = 2;
|
||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Инструменты";
|
groupBox1.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// groupBox2
|
||||||
|
//
|
||||||
|
groupBox2.Controls.Add(buttonDeleteObject);
|
||||||
|
groupBox2.Controls.Add(listBoxStorages);
|
||||||
|
groupBox2.Controls.Add(buttonAddObject);
|
||||||
|
groupBox2.Controls.Add(textBoxStorageName);
|
||||||
|
groupBox2.Location = new Point(12, 39);
|
||||||
|
groupBox2.Name = "groupBox2";
|
||||||
|
groupBox2.Size = new Size(150, 219);
|
||||||
|
groupBox2.TabIndex = 4;
|
||||||
|
groupBox2.TabStop = false;
|
||||||
|
groupBox2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// buttonDeleteObject
|
||||||
|
//
|
||||||
|
buttonDeleteObject.Location = new Point(6, 190);
|
||||||
|
buttonDeleteObject.Name = "buttonDeleteObject";
|
||||||
|
buttonDeleteObject.Size = new Size(138, 23);
|
||||||
|
buttonDeleteObject.TabIndex = 3;
|
||||||
|
buttonDeleteObject.Text = "Удалить набор";
|
||||||
|
buttonDeleteObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonDeleteObject.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 15;
|
||||||
|
listBoxStorages.Location = new Point(6, 85);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(138, 94);
|
||||||
|
listBoxStorages.TabIndex = 2;
|
||||||
|
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(6, 56);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(138, 23);
|
||||||
|
buttonAddObject.TabIndex = 1;
|
||||||
|
buttonAddObject.Text = "Добавить набор";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(6, 22);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(138, 23);
|
||||||
|
textBoxStorageName.TabIndex = 0;
|
||||||
|
//
|
||||||
// buttonRefreshCollection
|
// buttonRefreshCollection
|
||||||
//
|
//
|
||||||
buttonRefreshCollection.Location = new Point(14, 206);
|
buttonRefreshCollection.Location = new Point(14, 407);
|
||||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
buttonRefreshCollection.Size = new Size(149, 23);
|
buttonRefreshCollection.Size = new Size(149, 23);
|
||||||
buttonRefreshCollection.TabIndex = 3;
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
@ -72,7 +129,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemovePlane
|
// buttonRemovePlane
|
||||||
//
|
//
|
||||||
buttonRemovePlane.Location = new Point(14, 155);
|
buttonRemovePlane.Location = new Point(14, 377);
|
||||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||||
buttonRemovePlane.Size = new Size(149, 24);
|
buttonRemovePlane.Size = new Size(149, 24);
|
||||||
buttonRemovePlane.TabIndex = 2;
|
buttonRemovePlane.TabIndex = 2;
|
||||||
@ -82,14 +139,14 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(14, 101);
|
maskedTextBoxNumber.Location = new Point(14, 348);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(149, 23);
|
maskedTextBoxNumber.Size = new Size(149, 23);
|
||||||
maskedTextBoxNumber.TabIndex = 1;
|
maskedTextBoxNumber.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// buttonAddPlane
|
// buttonAddPlane
|
||||||
//
|
//
|
||||||
buttonAddPlane.Location = new Point(14, 45);
|
buttonAddPlane.Location = new Point(14, 317);
|
||||||
buttonAddPlane.Name = "buttonAddPlane";
|
buttonAddPlane.Name = "buttonAddPlane";
|
||||||
buttonAddPlane.Size = new Size(149, 25);
|
buttonAddPlane.Size = new Size(149, 25);
|
||||||
buttonAddPlane.TabIndex = 0;
|
buttonAddPlane.TabIndex = 0;
|
||||||
@ -101,7 +158,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1026, 443);
|
ClientSize = new Size(1026, 446);
|
||||||
Controls.Add(groupBox1);
|
Controls.Add(groupBox1);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Name = "FormPlaneCollection";
|
Name = "FormPlaneCollection";
|
||||||
@ -109,6 +166,8 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
groupBox1.ResumeLayout(false);
|
groupBox1.ResumeLayout(false);
|
||||||
groupBox1.PerformLayout();
|
groupBox1.PerformLayout();
|
||||||
|
groupBox2.ResumeLayout(false);
|
||||||
|
groupBox2.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,5 +179,10 @@
|
|||||||
private Button buttonRemovePlane;
|
private Button buttonRemovePlane;
|
||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
private Button buttonAddPlane;
|
private Button buttonAddPlane;
|
||||||
|
private GroupBox groupBox2;
|
||||||
|
private Button buttonDeleteObject;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,17 +18,85 @@ namespace ProjectSeaplane
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly PlanesGenericCollection<DrawningPlane,
|
private readonly PlanesGenericStorage _storage;
|
||||||
DrawningObjectPlane> _planes;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormPlaneCollection()
|
public FormPlaneCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_planes = new PlanesGenericCollection<DrawningPlane,
|
_storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
DrawningObjectPlane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
foreach (var key in _storage.Keys)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(key);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -36,13 +104,22 @@ namespace ProjectSeaplane
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonAddPlane_Click(object sender, EventArgs e)
|
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;
|
||||||
|
}
|
||||||
FormSeaplane form = new FormSeaplane();
|
FormSeaplane form = new FormSeaplane();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_planes + form.SelectedPlane != -1)
|
if (obj + form.SelectedPlane)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -57,21 +134,26 @@ namespace ProjectSeaplane
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonRemovePlane_Click(object sender, EventArgs e)
|
private void buttonRemovePlane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = -1;
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
try
|
if (obj == null)
|
||||||
{
|
{
|
||||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex) { }
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
if (_planes - pos)
|
MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -85,7 +167,18 @@ namespace ProjectSeaplane
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ namespace ProjectSeaplane.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int? operator +(PlanesGenericCollection<T, U> collect, T? obj)
|
public static bool operator +(PlanesGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect?._collection.Insert(obj);
|
return (bool)collect?._collection.Insert(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -67,14 +67,14 @@ namespace ProjectSeaplane.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="pos"></param>
|
/// <param name="pos"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator -(PlanesGenericCollection<T, U> collect, int pos)
|
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj == null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return false;
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return collect._collection.Remove(pos);
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -84,7 +84,7 @@ namespace ProjectSeaplane.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -125,21 +125,17 @@ namespace ProjectSeaplane.Generics
|
|||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
int i = 0;
|
||||||
|
foreach (var plane in _collection.GetPlanes())
|
||||||
{
|
{
|
||||||
// TODO получение объекта
|
if (plane != null)
|
||||||
DrawningPlane? plane = _collection.Get(i);
|
|
||||||
if (plane == null)
|
|
||||||
{
|
{
|
||||||
continue;
|
plane.SetPosition((width - 1 - (i % width)) * _placeSizeWidth, (width - (i / width) - 1) * _placeSizeHeight);
|
||||||
|
plane.DrawTransport(g);
|
||||||
}
|
}
|
||||||
int r = width - (i / width) - 1;
|
i++;
|
||||||
int s = width - 1 - (i % width);
|
|
||||||
// TODO установка позиции
|
|
||||||
plane.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight);
|
|
||||||
// TODO прорисовка объекта
|
|
||||||
plane.DrawTransport(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
48
gidro/PlanesGenericStorage.cs
Normal file
48
gidro/PlanesGenericStorage.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectSeaplane.DrawningObjects;
|
||||||
|
using ProjectSeaplane.MovementStrategy;
|
||||||
|
using ProjectSeaplane.Generics;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.Generics
|
||||||
|
{
|
||||||
|
internal class PlanesGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>> _planeStorages;
|
||||||
|
public List<string> Keys => _planeStorages.Keys.ToList();
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (_planeStorages.ContainsKey(name)) return;
|
||||||
|
_planeStorages[name] = new PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_planeStorages.ContainsKey(name)) return;
|
||||||
|
_planeStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_planeStorages.ContainsKey(ind)) return _planeStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,44 +16,32 @@ namespace ProjectSeaplane.Generics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Массив объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в массиве
|
/// Количество объектов в массиве
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _maxCount;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="car">Добавляемый автомобиль</param>
|
/// <param name="car">Добавляемый автомобиль</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T plane)
|
public bool Insert(T plane)
|
||||||
{
|
{
|
||||||
int index = -1;
|
return Insert(plane, 0);
|
||||||
for (int i = 0; i < _places.Length; i++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
index = i; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
for (int i = index; i > 0; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[0] = plane;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@ -61,31 +49,16 @@ namespace ProjectSeaplane.Generics
|
|||||||
/// <param name="car">Добавляемый автомобиль</param>
|
/// <param name="car">Добавляемый автомобиль</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T plane, int position)
|
public bool Insert(T plane, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
return -1;
|
return false;
|
||||||
if (_places[position] == null)
|
|
||||||
{
|
if (Count >= _maxCount)
|
||||||
_places[position] = plane;
|
return false;
|
||||||
return position;
|
_places.Insert(0, plane);
|
||||||
}
|
return true;
|
||||||
int index = -1;
|
|
||||||
for (int i = position; i < Count; i++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
index = i; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index < 0)
|
|
||||||
return -1;
|
|
||||||
for (int i = index; index > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[position] = plane;
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
@ -94,21 +67,50 @@ namespace ProjectSeaplane.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position > _maxCount)
|
||||||
return false;
|
return false;
|
||||||
_places[position] = null;
|
if (position >= Count)
|
||||||
|
return false;
|
||||||
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
get
|
||||||
return null;
|
{
|
||||||
return _places[position];
|
if (position < 0 || position > _maxCount)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return;
|
||||||
|
_places[position] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxPlanes.HasValue && i == maxPlanes.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user