Done
This commit is contained in:
parent
6b6b89fcf0
commit
b8f5f48a24
63
ProjStormtrooper/ProjStormtrooper/DrawingPlaneEqutables.cs
Normal file
63
ProjStormtrooper/ProjStormtrooper/DrawingPlaneEqutables.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
public class DrawingPlaneEqutables : IEqualityComparer<DrawingPlane>
|
||||
{
|
||||
public bool Equals(DrawingPlane? x, DrawingPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityPlane.Speed != y.EntityPlane.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityPlane.Weight != y.EntityPlane.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityPlane.BodyColor != y.EntityPlane.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawingStormtrooper && y is DrawingStormtrooper)
|
||||
{
|
||||
var xStormtrooper = (x.EntityPlane as EntityStormtrooper);
|
||||
var yStormtrooper = (y.EntityPlane as EntityStormtrooper);
|
||||
if (xStormtrooper?.AdditionalColor != yStormtrooper?.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (xStormtrooper?.Bombs != yStormtrooper?.Bombs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (xStormtrooper?.Rockets != yStormtrooper?.Rockets)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawingPlane obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
groupBoxStorages = new GroupBox();
|
||||
buttonRemoveStorage = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
@ -53,42 +55,59 @@
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonSortByType);
|
||||
groupBoxTools.Controls.Add(buttonSortByColor);
|
||||
groupBoxTools.Controls.Add(groupBoxStorages);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(689, 24);
|
||||
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxTools.Location = new Point(787, 28);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxTools.Size = new Size(201, 380);
|
||||
groupBoxTools.Size = new Size(230, 510);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(6, 273);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(218, 29);
|
||||
buttonSortByType.TabIndex = 7;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Location = new Point(6, 305);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(218, 29);
|
||||
buttonSortByColor.TabIndex = 6;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||
//
|
||||
// groupBoxStorages
|
||||
//
|
||||
groupBoxStorages.Controls.Add(buttonRemoveStorage);
|
||||
groupBoxStorages.Controls.Add(listBoxStorages);
|
||||
groupBoxStorages.Controls.Add(buttonAddStorage);
|
||||
groupBoxStorages.Controls.Add(textBoxStorageName);
|
||||
groupBoxStorages.Location = new Point(5, 20);
|
||||
groupBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxStorages.Location = new Point(6, 26);
|
||||
groupBoxStorages.Name = "groupBoxStorages";
|
||||
groupBoxStorages.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxStorages.Size = new Size(191, 181);
|
||||
groupBoxStorages.Size = new Size(218, 241);
|
||||
groupBoxStorages.TabIndex = 5;
|
||||
groupBoxStorages.TabStop = false;
|
||||
groupBoxStorages.Text = "Наборы";
|
||||
//
|
||||
// buttonRemoveStorage
|
||||
//
|
||||
buttonRemoveStorage.Location = new Point(5, 153);
|
||||
buttonRemoveStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRemoveStorage.Location = new Point(6, 204);
|
||||
buttonRemoveStorage.Name = "buttonRemoveStorage";
|
||||
buttonRemoveStorage.Size = new Size(180, 22);
|
||||
buttonRemoveStorage.Size = new Size(206, 29);
|
||||
buttonRemoveStorage.TabIndex = 3;
|
||||
buttonRemoveStorage.Text = "Удалить набор";
|
||||
buttonRemoveStorage.UseVisualStyleBackColor = true;
|
||||
@ -97,20 +116,18 @@
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 15;
|
||||
listBoxStorages.Location = new Point(5, 70);
|
||||
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
||||
listBoxStorages.ItemHeight = 20;
|
||||
listBoxStorages.Location = new Point(6, 94);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(181, 79);
|
||||
listBoxStorages.Size = new Size(206, 104);
|
||||
listBoxStorages.TabIndex = 2;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddStorage
|
||||
//
|
||||
buttonAddStorage.Location = new Point(5, 44);
|
||||
buttonAddStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAddStorage.Location = new Point(6, 59);
|
||||
buttonAddStorage.Name = "buttonAddStorage";
|
||||
buttonAddStorage.Size = new Size(180, 22);
|
||||
buttonAddStorage.Size = new Size(206, 29);
|
||||
buttonAddStorage.TabIndex = 1;
|
||||
buttonAddStorage.Text = "Добавить набор";
|
||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||
@ -118,29 +135,26 @@
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(5, 20);
|
||||
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
|
||||
textBoxStorageName.Location = new Point(6, 26);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(181, 23);
|
||||
textBoxStorageName.Size = new Size(206, 27);
|
||||
textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(5, 303);
|
||||
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
|
||||
maskedTextBoxNumber.Location = new Point(6, 404);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(191, 23);
|
||||
maskedTextBoxNumber.Size = new Size(218, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(5, 373);
|
||||
buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRefreshCollection.Location = new Point(6, 497);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(191, 22);
|
||||
buttonRefreshCollection.Size = new Size(218, 29);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
@ -148,10 +162,9 @@
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
buttonRemovePlane.Location = new Point(5, 328);
|
||||
buttonRemovePlane.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRemovePlane.Location = new Point(6, 437);
|
||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
buttonRemovePlane.Size = new Size(191, 22);
|
||||
buttonRemovePlane.Size = new Size(218, 29);
|
||||
buttonRemovePlane.TabIndex = 2;
|
||||
buttonRemovePlane.Text = "Удалить самолет";
|
||||
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||
@ -159,10 +172,9 @@
|
||||
//
|
||||
// buttonAddPlane
|
||||
//
|
||||
buttonAddPlane.Location = new Point(5, 262);
|
||||
buttonAddPlane.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAddPlane.Location = new Point(6, 349);
|
||||
buttonAddPlane.Name = "buttonAddPlane";
|
||||
buttonAddPlane.Size = new Size(191, 22);
|
||||
buttonAddPlane.Size = new Size(218, 29);
|
||||
buttonAddPlane.TabIndex = 0;
|
||||
buttonAddPlane.Text = "Добавить самолет";
|
||||
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||
@ -171,10 +183,9 @@
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||
pictureBoxCollection.Location = new Point(0, 24);
|
||||
pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxCollection.Location = new Point(0, 28);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(689, 380);
|
||||
pictureBoxCollection.Size = new Size(787, 510);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
@ -184,8 +195,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Padding = new Padding(5, 2, 0, 2);
|
||||
menuStrip.Size = new Size(890, 24);
|
||||
menuStrip.Size = new Size(1017, 28);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -193,21 +203,20 @@
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem, загрузитьToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(48, 20);
|
||||
файлToolStripMenuItem.Size = new Size(59, 24);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
файлToolStripMenuItem.Click += файлToolStripMenuItem_Click;
|
||||
//
|
||||
// сохранитьToolStripMenuItem
|
||||
//
|
||||
сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
|
||||
сохранитьToolStripMenuItem.Size = new Size(180, 22);
|
||||
сохранитьToolStripMenuItem.Size = new Size(166, 26);
|
||||
сохранитьToolStripMenuItem.Text = "Сохранить";
|
||||
сохранитьToolStripMenuItem.Click += saveToFileToolStripMenuItem_Click;
|
||||
//
|
||||
// загрузитьToolStripMenuItem
|
||||
//
|
||||
загрузитьToolStripMenuItem.Name = "загрузитьToolStripMenuItem";
|
||||
загрузитьToolStripMenuItem.Size = new Size(180, 22);
|
||||
загрузитьToolStripMenuItem.Size = new Size(166, 26);
|
||||
загрузитьToolStripMenuItem.Text = "Загрузить";
|
||||
загрузитьToolStripMenuItem.Click += loadFromFileToolStripMenuItem_Click;
|
||||
//
|
||||
@ -220,17 +229,16 @@
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// PlaneCollection
|
||||
// FormPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(890, 404);
|
||||
ClientSize = new Size(1017, 538);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "PlaneCollection";
|
||||
Name = "FormPlaneCollection";
|
||||
Text = "Набор самолетов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
@ -262,5 +270,7 @@
|
||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByType;
|
||||
private Button buttonSortByColor;
|
||||
}
|
||||
}
|
@ -140,7 +140,12 @@ namespace ProjStormtrooper
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
MessageBox.Show(ex.Message, "Ошибка добавления", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Ошибка добавления: " + ex.Message);
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка добавления", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Ошибка добавления: " + ex.Message);
|
||||
}
|
||||
}
|
||||
@ -246,5 +251,26 @@ namespace ProjStormtrooper
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
private void ComparePlanes(IComparer<DrawingPlane?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
private void buttonSortByType_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByType());
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByColor());
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
|
35
ProjStormtrooper/ProjStormtrooper/PlaneCompareByColor.cs
Normal file
35
ProjStormtrooper/ProjStormtrooper/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
public class PlaneCompareByColor : IComparer<DrawingPlane?>
|
||||
{
|
||||
public int Compare(DrawingPlane? x, DrawingPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.EntityPlane.BodyColor != y.EntityPlane.BodyColor)
|
||||
{
|
||||
return x.EntityPlane.BodyColor.Name.CompareTo(y.EntityPlane.BodyColor.Name);
|
||||
}
|
||||
if (x.EntityPlane is EntityStormtrooper xStormtrooper && y.EntityPlane is EntityStormtrooper yStormtrooper)
|
||||
{
|
||||
if (xStormtrooper.AdditionalColor != yStormtrooper.AdditionalColor)
|
||||
{
|
||||
return xStormtrooper.AdditionalColor.Name.CompareTo(yStormtrooper.AdditionalColor.Name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
33
ProjStormtrooper/ProjStormtrooper/PlaneCompareByType.cs
Normal file
33
ProjStormtrooper/ProjStormtrooper/PlaneCompareByType.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
public class PlaneCompareByType : IComparer<DrawingPlane?>
|
||||
{
|
||||
public int Compare(DrawingPlane? x, DrawingPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityPlane.Speed.CompareTo(y.EntityPlane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityPlane.Weight.CompareTo(y.EntityPlane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -123,15 +123,5 @@ namespace ProjStormtrooper
|
||||
(_plane.EntityPlane as EntityStormtrooper).SetAdditionalColor((Color)e.Data.GetData(typeof(Color).ToString()));
|
||||
DrawPlane();
|
||||
}
|
||||
|
||||
private void panelColorPurple_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void panelColorPink_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
31
ProjStormtrooper/ProjStormtrooper/PlanesCollectionInfo.cs
Normal file
31
ProjStormtrooper/ProjStormtrooper/PlanesCollectionInfo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
public class PlanesCollectionInfo : IEquatable<PlanesCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public PlanesCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(PlanesCollectionInfo? other)
|
||||
{
|
||||
return Name == other.Name;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,8 +12,8 @@ namespace ProjStormtrooper
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class PlanesGenericCollection<T, U>
|
||||
where T : DrawingPlane
|
||||
where U : IMoveableObject
|
||||
where T : DrawingPlane
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
@ -49,6 +49,11 @@ namespace ProjStormtrooper
|
||||
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
@ -60,7 +65,7 @@ namespace ProjStormtrooper
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
return collect?._collection.Insert(obj, new DrawingPlaneEqutables()) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
@ -71,10 +76,7 @@ namespace ProjStormtrooper
|
||||
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
@ -102,45 +104,45 @@ namespace ProjStormtrooper
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{//линия разметки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
// Линия разметки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _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);
|
||||
}
|
||||
}
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
int placesColumnCount = _pictureHeight / _placeSizeHeight;
|
||||
int placesRowCount = _pictureWidth / _placeSizeWidth;
|
||||
int i = 0;
|
||||
foreach (var plane in _collection.GetPlanes())
|
||||
{
|
||||
var obj = _collection[i];
|
||||
obj?.SetPosition(
|
||||
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
||||
(int)((i / width) * _placeSizeHeight)
|
||||
);
|
||||
obj?.DrawTransport(g);
|
||||
if (plane != null)
|
||||
{
|
||||
// установка позиции
|
||||
plane.SetPosition(
|
||||
(int)((placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - plane.GetWidth) / 2),
|
||||
(int)(i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - plane.GetHeight) / 2)
|
||||
);
|
||||
// прорисовка объекта
|
||||
plane.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ namespace ProjStormtrooper
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
||||
readonly Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _planeStorages.Keys.ToList();
|
||||
public List<PlanesCollectionInfo> Keys => _planeStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -43,7 +43,7 @@ namespace ProjStormtrooper
|
||||
/// <param name="pictureHeight"></param>
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
|
||||
_planeStorages = new Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -53,7 +53,7 @@ namespace ProjStormtrooper
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_planeStorages.Add(name, new PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>(_pictureWidth, _pictureHeight));
|
||||
_planeStorages.Add(new PlanesCollectionInfo(name, ""), new PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
@ -61,8 +61,9 @@ namespace ProjStormtrooper
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_planeStorages.ContainsKey(name))
|
||||
_planeStorages.Remove(name);
|
||||
var info = new PlanesCollectionInfo(name, "");
|
||||
if (_planeStorages.ContainsKey(info))
|
||||
_planeStorages.Remove(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
@ -73,8 +74,9 @@ namespace ProjStormtrooper
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_planeStorages.ContainsKey(ind))
|
||||
return _planeStorages[ind];
|
||||
var info = new PlanesCollectionInfo(ind, "");
|
||||
if (_planeStorages.ContainsKey(info))
|
||||
return _planeStorages[info];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -104,7 +106,7 @@ namespace ProjStormtrooper
|
||||
{
|
||||
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
sw.WriteLine($"{storage.Key}{_separatorForKeyValue}{storageString}");
|
||||
sw.WriteLine($"{storage.Key.Name}{_separatorForKeyValue}{storageString}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -152,7 +154,7 @@ namespace ProjStormtrooper
|
||||
}
|
||||
}
|
||||
}
|
||||
_planeStorages.Add(record[0], collection);
|
||||
_planeStorages.Add(new PlanesCollectionInfo(record[0], ""), collection);
|
||||
currentLine = sr.ReadLine();
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +34,18 @@ namespace ProjStormtrooper
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
/// <summary>
|
||||
/// Добавления объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="plane"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane)
|
||||
public int Insert(T plane, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
return Insert(plane, 0);
|
||||
return Insert(plane, 0, equal);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -48,7 +53,7 @@ namespace ProjStormtrooper
|
||||
/// <param name="plane"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane, int position)
|
||||
public int Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
{
|
||||
@ -59,6 +64,16 @@ namespace ProjStormtrooper
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var otherPlane in _places)
|
||||
{
|
||||
if (equal.Equals(otherPlane, plane))
|
||||
{
|
||||
throw new ApplicationException("Такой объект уже есть в коллекции!");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Вставка по позиции
|
||||
_places.Insert(position, plane);
|
||||
return position;
|
||||
|
Loading…
x
Reference in New Issue
Block a user