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()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
groupBoxStorages = new GroupBox();
|
groupBoxStorages = new GroupBox();
|
||||||
buttonRemoveStorage = new Button();
|
buttonRemoveStorage = new Button();
|
||||||
listBoxStorages = new ListBox();
|
listBoxStorages = new ListBox();
|
||||||
@ -53,42 +55,59 @@
|
|||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
|
groupBoxTools.Controls.Add(buttonSortByType);
|
||||||
|
groupBoxTools.Controls.Add(buttonSortByColor);
|
||||||
groupBoxTools.Controls.Add(groupBoxStorages);
|
groupBoxTools.Controls.Add(groupBoxStorages);
|
||||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||||
groupBoxTools.Controls.Add(buttonRemovePlane);
|
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||||
groupBoxTools.Controls.Add(buttonAddPlane);
|
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(689, 24);
|
groupBoxTools.Location = new Point(787, 28);
|
||||||
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
|
groupBoxTools.Size = new Size(230, 510);
|
||||||
groupBoxTools.Size = new Size(201, 380);
|
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
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
|
||||||
//
|
//
|
||||||
groupBoxStorages.Controls.Add(buttonRemoveStorage);
|
groupBoxStorages.Controls.Add(buttonRemoveStorage);
|
||||||
groupBoxStorages.Controls.Add(listBoxStorages);
|
groupBoxStorages.Controls.Add(listBoxStorages);
|
||||||
groupBoxStorages.Controls.Add(buttonAddStorage);
|
groupBoxStorages.Controls.Add(buttonAddStorage);
|
||||||
groupBoxStorages.Controls.Add(textBoxStorageName);
|
groupBoxStorages.Controls.Add(textBoxStorageName);
|
||||||
groupBoxStorages.Location = new Point(5, 20);
|
groupBoxStorages.Location = new Point(6, 26);
|
||||||
groupBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
groupBoxStorages.Name = "groupBoxStorages";
|
groupBoxStorages.Name = "groupBoxStorages";
|
||||||
groupBoxStorages.Padding = new Padding(3, 2, 3, 2);
|
groupBoxStorages.Size = new Size(218, 241);
|
||||||
groupBoxStorages.Size = new Size(191, 181);
|
|
||||||
groupBoxStorages.TabIndex = 5;
|
groupBoxStorages.TabIndex = 5;
|
||||||
groupBoxStorages.TabStop = false;
|
groupBoxStorages.TabStop = false;
|
||||||
groupBoxStorages.Text = "Наборы";
|
groupBoxStorages.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// buttonRemoveStorage
|
// buttonRemoveStorage
|
||||||
//
|
//
|
||||||
buttonRemoveStorage.Location = new Point(5, 153);
|
buttonRemoveStorage.Location = new Point(6, 204);
|
||||||
buttonRemoveStorage.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonRemoveStorage.Name = "buttonRemoveStorage";
|
buttonRemoveStorage.Name = "buttonRemoveStorage";
|
||||||
buttonRemoveStorage.Size = new Size(180, 22);
|
buttonRemoveStorage.Size = new Size(206, 29);
|
||||||
buttonRemoveStorage.TabIndex = 3;
|
buttonRemoveStorage.TabIndex = 3;
|
||||||
buttonRemoveStorage.Text = "Удалить набор";
|
buttonRemoveStorage.Text = "Удалить набор";
|
||||||
buttonRemoveStorage.UseVisualStyleBackColor = true;
|
buttonRemoveStorage.UseVisualStyleBackColor = true;
|
||||||
@ -97,20 +116,18 @@
|
|||||||
// listBoxStorages
|
// listBoxStorages
|
||||||
//
|
//
|
||||||
listBoxStorages.FormattingEnabled = true;
|
listBoxStorages.FormattingEnabled = true;
|
||||||
listBoxStorages.ItemHeight = 15;
|
listBoxStorages.ItemHeight = 20;
|
||||||
listBoxStorages.Location = new Point(5, 70);
|
listBoxStorages.Location = new Point(6, 94);
|
||||||
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
listBoxStorages.Name = "listBoxStorages";
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
listBoxStorages.Size = new Size(181, 79);
|
listBoxStorages.Size = new Size(206, 104);
|
||||||
listBoxStorages.TabIndex = 2;
|
listBoxStorages.TabIndex = 2;
|
||||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// buttonAddStorage
|
// buttonAddStorage
|
||||||
//
|
//
|
||||||
buttonAddStorage.Location = new Point(5, 44);
|
buttonAddStorage.Location = new Point(6, 59);
|
||||||
buttonAddStorage.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonAddStorage.Name = "buttonAddStorage";
|
buttonAddStorage.Name = "buttonAddStorage";
|
||||||
buttonAddStorage.Size = new Size(180, 22);
|
buttonAddStorage.Size = new Size(206, 29);
|
||||||
buttonAddStorage.TabIndex = 1;
|
buttonAddStorage.TabIndex = 1;
|
||||||
buttonAddStorage.Text = "Добавить набор";
|
buttonAddStorage.Text = "Добавить набор";
|
||||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||||
@ -118,29 +135,26 @@
|
|||||||
//
|
//
|
||||||
// textBoxStorageName
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
textBoxStorageName.Location = new Point(5, 20);
|
textBoxStorageName.Location = new Point(6, 26);
|
||||||
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
textBoxStorageName.Name = "textBoxStorageName";
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
textBoxStorageName.Size = new Size(181, 23);
|
textBoxStorageName.Size = new Size(206, 27);
|
||||||
textBoxStorageName.TabIndex = 0;
|
textBoxStorageName.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(5, 303);
|
maskedTextBoxNumber.Location = new Point(6, 404);
|
||||||
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
maskedTextBoxNumber.Mask = "00";
|
maskedTextBoxNumber.Mask = "00";
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(191, 23);
|
maskedTextBoxNumber.Size = new Size(218, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 4;
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
|
maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
|
||||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||||
//
|
//
|
||||||
// buttonRefreshCollection
|
// buttonRefreshCollection
|
||||||
//
|
//
|
||||||
buttonRefreshCollection.Location = new Point(5, 373);
|
buttonRefreshCollection.Location = new Point(6, 497);
|
||||||
buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
buttonRefreshCollection.Size = new Size(191, 22);
|
buttonRefreshCollection.Size = new Size(218, 29);
|
||||||
buttonRefreshCollection.TabIndex = 3;
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
@ -148,10 +162,9 @@
|
|||||||
//
|
//
|
||||||
// buttonRemovePlane
|
// buttonRemovePlane
|
||||||
//
|
//
|
||||||
buttonRemovePlane.Location = new Point(5, 328);
|
buttonRemovePlane.Location = new Point(6, 437);
|
||||||
buttonRemovePlane.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||||
buttonRemovePlane.Size = new Size(191, 22);
|
buttonRemovePlane.Size = new Size(218, 29);
|
||||||
buttonRemovePlane.TabIndex = 2;
|
buttonRemovePlane.TabIndex = 2;
|
||||||
buttonRemovePlane.Text = "Удалить самолет";
|
buttonRemovePlane.Text = "Удалить самолет";
|
||||||
buttonRemovePlane.UseVisualStyleBackColor = true;
|
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||||
@ -159,10 +172,9 @@
|
|||||||
//
|
//
|
||||||
// buttonAddPlane
|
// buttonAddPlane
|
||||||
//
|
//
|
||||||
buttonAddPlane.Location = new Point(5, 262);
|
buttonAddPlane.Location = new Point(6, 349);
|
||||||
buttonAddPlane.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonAddPlane.Name = "buttonAddPlane";
|
buttonAddPlane.Name = "buttonAddPlane";
|
||||||
buttonAddPlane.Size = new Size(191, 22);
|
buttonAddPlane.Size = new Size(218, 29);
|
||||||
buttonAddPlane.TabIndex = 0;
|
buttonAddPlane.TabIndex = 0;
|
||||||
buttonAddPlane.Text = "Добавить самолет";
|
buttonAddPlane.Text = "Добавить самолет";
|
||||||
buttonAddPlane.UseVisualStyleBackColor = true;
|
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||||
@ -171,10 +183,9 @@
|
|||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||||
pictureBoxCollection.Location = new Point(0, 24);
|
pictureBoxCollection.Location = new Point(0, 28);
|
||||||
pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(689, 380);
|
pictureBoxCollection.Size = new Size(787, 510);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -184,8 +195,7 @@
|
|||||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Padding = new Padding(5, 2, 0, 2);
|
menuStrip.Size = new Size(1017, 28);
|
||||||
menuStrip.Size = new Size(890, 24);
|
|
||||||
menuStrip.TabIndex = 2;
|
menuStrip.TabIndex = 2;
|
||||||
menuStrip.Text = "menuStrip1";
|
menuStrip.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
@ -193,21 +203,20 @@
|
|||||||
//
|
//
|
||||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem, загрузитьToolStripMenuItem });
|
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem, загрузитьToolStripMenuItem });
|
||||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
файлToolStripMenuItem.Size = new Size(48, 20);
|
файлToolStripMenuItem.Size = new Size(59, 24);
|
||||||
файлToolStripMenuItem.Text = "Файл";
|
файлToolStripMenuItem.Text = "Файл";
|
||||||
файлToolStripMenuItem.Click += файлToolStripMenuItem_Click;
|
|
||||||
//
|
//
|
||||||
// сохранитьToolStripMenuItem
|
// сохранитьToolStripMenuItem
|
||||||
//
|
//
|
||||||
сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
|
сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
|
||||||
сохранитьToolStripMenuItem.Size = new Size(180, 22);
|
сохранитьToolStripMenuItem.Size = new Size(166, 26);
|
||||||
сохранитьToolStripMenuItem.Text = "Сохранить";
|
сохранитьToolStripMenuItem.Text = "Сохранить";
|
||||||
сохранитьToolStripMenuItem.Click += saveToFileToolStripMenuItem_Click;
|
сохранитьToolStripMenuItem.Click += saveToFileToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// загрузитьToolStripMenuItem
|
// загрузитьToolStripMenuItem
|
||||||
//
|
//
|
||||||
загрузитьToolStripMenuItem.Name = "загрузитьToolStripMenuItem";
|
загрузитьToolStripMenuItem.Name = "загрузитьToolStripMenuItem";
|
||||||
загрузитьToolStripMenuItem.Size = new Size(180, 22);
|
загрузитьToolStripMenuItem.Size = new Size(166, 26);
|
||||||
загрузитьToolStripMenuItem.Text = "Загрузить";
|
загрузитьToolStripMenuItem.Text = "Загрузить";
|
||||||
загрузитьToolStripMenuItem.Click += loadFromFileToolStripMenuItem_Click;
|
загрузитьToolStripMenuItem.Click += loadFromFileToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -220,17 +229,16 @@
|
|||||||
//
|
//
|
||||||
saveFileDialog.Filter = "txt file | *.txt";
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
// PlaneCollection
|
// FormPlaneCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(890, 404);
|
ClientSize = new Size(1017, 538);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(menuStrip);
|
Controls.Add(menuStrip);
|
||||||
MainMenuStrip = menuStrip;
|
MainMenuStrip = menuStrip;
|
||||||
Margin = new Padding(3, 2, 3, 2);
|
Name = "FormPlaneCollection";
|
||||||
Name = "PlaneCollection";
|
|
||||||
Text = "Набор самолетов";
|
Text = "Набор самолетов";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
groupBoxTools.PerformLayout();
|
groupBoxTools.PerformLayout();
|
||||||
@ -262,5 +270,7 @@
|
|||||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
private Button buttonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -140,7 +140,12 @@ namespace ProjStormtrooper
|
|||||||
}
|
}
|
||||||
catch (StorageOverflowException ex)
|
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);
|
_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="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, 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="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">
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
</data>
|
</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()));
|
(_plane.EntityPlane as EntityStormtrooper).SetAdditionalColor((Color)e.Data.GetData(typeof(Color).ToString()));
|
||||||
DrawPlane();
|
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="T"></typeparam>
|
||||||
/// <typeparam name="U"></typeparam>
|
/// <typeparam name="U"></typeparam>
|
||||||
internal class PlanesGenericCollection<T, U>
|
internal class PlanesGenericCollection<T, U>
|
||||||
where T : DrawingPlane
|
where T : DrawingPlane
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна прорисовки
|
/// Ширина окна прорисовки
|
||||||
@ -49,6 +49,11 @@ namespace ProjStormtrooper
|
|||||||
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Сортировка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
|
/// <summary>
|
||||||
/// Перегрузка оператора сложения
|
/// Перегрузка оператора сложения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
@ -60,7 +65,7 @@ namespace ProjStormtrooper
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return collect?._collection.Insert(obj) ?? -1;
|
return collect?._collection.Insert(obj, new DrawingPlaneEqutables()) ?? -1;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@ -71,10 +76,7 @@ namespace ProjStormtrooper
|
|||||||
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
|
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection[pos];
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
collect._collection.Remove(pos);
|
||||||
{
|
|
||||||
collect._collection.Remove(pos);
|
|
||||||
}
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -102,45 +104,45 @@ namespace ProjStormtrooper
|
|||||||
/// Метод отрисовки фона
|
/// Метод отрисовки фона
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
|
|
||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 3);
|
Pen pen = new(Color.Black, 3);
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
1; ++j)
|
{
|
||||||
{//линия разметки места
|
// Линия разметки места
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, 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 *
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Метод прорисовки объектов
|
/// Метод прорисовки объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
|
|
||||||
|
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
int placesColumnCount = _pictureHeight / _placeSizeHeight;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int placesRowCount = _pictureWidth / _placeSizeWidth;
|
||||||
|
int i = 0;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
foreach (var plane in _collection.GetPlanes())
|
||||||
{
|
{
|
||||||
var obj = _collection[i];
|
if (plane != null)
|
||||||
obj?.SetPosition(
|
{
|
||||||
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
// установка позиции
|
||||||
(int)((i / width) * _placeSizeHeight)
|
plane.SetPosition(
|
||||||
);
|
(int)((placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - plane.GetWidth) / 2),
|
||||||
obj?.DrawTransport(g);
|
(int)(i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - plane.GetHeight) / 2)
|
||||||
|
);
|
||||||
|
// прорисовка объекта
|
||||||
|
plane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объектов коллекции
|
||||||
|
/// </summary>
|
||||||
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ namespace ProjStormtrooper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище)
|
/// Словарь (хранилище)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
readonly Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий наборов
|
/// Возвращение списка названий наборов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Keys => _planeStorages.Keys.ToList();
|
public List<PlanesCollectionInfo> Keys => _planeStorages.Keys.ToList();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -43,7 +43,7 @@ namespace ProjStormtrooper
|
|||||||
/// <param name="pictureHeight"></param>
|
/// <param name="pictureHeight"></param>
|
||||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
|
_planeStorages = new Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ namespace ProjStormtrooper
|
|||||||
/// <param name="name">Название набора</param>
|
/// <param name="name">Название набора</param>
|
||||||
public void AddSet(string name)
|
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>
|
/// <summary>
|
||||||
/// Удаление набора
|
/// Удаление набора
|
||||||
@ -61,8 +61,9 @@ namespace ProjStormtrooper
|
|||||||
/// <param name="name">Название набора</param>
|
/// <param name="name">Название набора</param>
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
if (_planeStorages.ContainsKey(name))
|
var info = new PlanesCollectionInfo(name, "");
|
||||||
_planeStorages.Remove(name);
|
if (_planeStorages.ContainsKey(info))
|
||||||
|
_planeStorages.Remove(info);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Доступ к набору
|
/// Доступ к набору
|
||||||
@ -73,8 +74,9 @@ namespace ProjStormtrooper
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_planeStorages.ContainsKey(ind))
|
var info = new PlanesCollectionInfo(ind, "");
|
||||||
return _planeStorages[ind];
|
if (_planeStorages.ContainsKey(info))
|
||||||
|
return _planeStorages[info];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +106,7 @@ namespace ProjStormtrooper
|
|||||||
{
|
{
|
||||||
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
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();
|
currentLine = sr.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,18 @@ namespace ProjStormtrooper
|
|||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Сортировка набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
|
/// <summary>
|
||||||
/// Добавления объекта в набор
|
/// Добавления объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plane"></param>
|
/// <param name="plane"></param>
|
||||||
/// <returns></returns>
|
/// <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>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@ -48,7 +53,7 @@ namespace ProjStormtrooper
|
|||||||
/// <param name="plane"></param>
|
/// <param name="plane"></param>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T plane, int position)
|
public int Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (_places.Count == _maxCount)
|
if (_places.Count == _maxCount)
|
||||||
{
|
{
|
||||||
@ -59,6 +64,16 @@ namespace ProjStormtrooper
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (equal != null)
|
||||||
|
{
|
||||||
|
foreach (var otherPlane in _places)
|
||||||
|
{
|
||||||
|
if (equal.Equals(otherPlane, plane))
|
||||||
|
{
|
||||||
|
throw new ApplicationException("Такой объект уже есть в коллекции!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Вставка по позиции
|
// Вставка по позиции
|
||||||
_places.Insert(position, plane);
|
_places.Insert(position, plane);
|
||||||
return position;
|
return position;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user