This commit is contained in:
marusya 2023-12-16 20:14:18 +04:00
parent 1a8269e81b
commit 4751e54ae1
10 changed files with 300 additions and 61 deletions

View File

@ -95,7 +95,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
// TODO: Изменение x, y, если при установке объект выходит за границы // TODO: Изменение x, y, если при установке объект выходит за границы
if (x < 0 || y < 0 ) if (x < 0 || y < 0 || x + _ustaWidth > _pictureWidth || y + _ustaHeight > _pictureHeight)
{ {
x = 10; x = 10;
y = 10; y = 10;

View File

@ -0,0 +1,59 @@
using SelfPropelledArtilleryUnit.DrawningObjects;
using SelfPropelledArtilleryUnit.Entities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit
{
internal class DrawningUstaEqutables : IEqualityComparer<DrawningUsta?>
{
public bool Equals(DrawningUsta? x, DrawningUsta? y)
{
if (x == null || x.EntityUsta == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityUsta == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityUsta.Speed != y.EntityUsta.Speed)
{
return false;
}
if (x.EntityUsta.Weight != y.EntityUsta.Weight)
{
return false;
}
if (x.EntityUsta.BodyColor != y.EntityUsta.BodyColor)
{
return false;
}
if (x is EntityUstaBat && y is EntityUstaBat)
{
EntityUstaBat EntityX = (EntityUstaBat)x.EntityUsta;
EntityUstaBat EntityY = (EntityUstaBat)y.EntityUsta;
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
return false;
if (EntityX.Pushka != EntityY.Pushka)
return false;
if (EntityX.BodyKit != EntityY.BodyKit)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawningUsta obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -34,6 +34,8 @@
pictureBoxCollection = new PictureBox(); pictureBoxCollection = new PictureBox();
maskedTextBoxNumber = new MaskedTextBox(); maskedTextBoxNumber = new MaskedTextBox();
groupBox1 = new GroupBox(); groupBox1 = new GroupBox();
ButtonSortByType = new Button();
ButtonSortByColor = new Button();
groupBox2 = new GroupBox(); groupBox2 = new GroupBox();
listBoxStorage = new ListBox(); listBoxStorage = new ListBox();
ButtonDelObject = new Button(); ButtonDelObject = new Button();
@ -53,9 +55,10 @@
// //
// ButtonAddUsta // ButtonAddUsta
// //
ButtonAddUsta.Location = new Point(26, 366); ButtonAddUsta.Location = new Point(30, 557);
ButtonAddUsta.Margin = new Padding(3, 4, 3, 4);
ButtonAddUsta.Name = "ButtonAddUsta"; ButtonAddUsta.Name = "ButtonAddUsta";
ButtonAddUsta.Size = new Size(166, 40); ButtonAddUsta.Size = new Size(190, 35);
ButtonAddUsta.TabIndex = 0; ButtonAddUsta.TabIndex = 0;
ButtonAddUsta.Text = "Добавить арт. установку"; ButtonAddUsta.Text = "Добавить арт. установку";
ButtonAddUsta.UseVisualStyleBackColor = true; ButtonAddUsta.UseVisualStyleBackColor = true;
@ -63,9 +66,10 @@
// //
// ButtonRemoveUsta // ButtonRemoveUsta
// //
ButtonRemoveUsta.Location = new Point(26, 457); ButtonRemoveUsta.Location = new Point(30, 643);
ButtonRemoveUsta.Margin = new Padding(3, 4, 3, 4);
ButtonRemoveUsta.Name = "ButtonRemoveUsta"; ButtonRemoveUsta.Name = "ButtonRemoveUsta";
ButtonRemoveUsta.Size = new Size(166, 39); ButtonRemoveUsta.Size = new Size(190, 37);
ButtonRemoveUsta.TabIndex = 1; ButtonRemoveUsta.TabIndex = 1;
ButtonRemoveUsta.Text = "Удалить арт. установку"; ButtonRemoveUsta.Text = "Удалить арт. установку";
ButtonRemoveUsta.UseVisualStyleBackColor = true; ButtonRemoveUsta.UseVisualStyleBackColor = true;
@ -73,9 +77,10 @@
// //
// ButtonRefreshCollection // ButtonRefreshCollection
// //
ButtonRefreshCollection.Location = new Point(26, 502); ButtonRefreshCollection.Location = new Point(30, 695);
ButtonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
ButtonRefreshCollection.Name = "ButtonRefreshCollection"; ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(166, 40); ButtonRefreshCollection.Size = new Size(190, 41);
ButtonRefreshCollection.TabIndex = 2; ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = "Обновить коллекцию"; ButtonRefreshCollection.Text = "Обновить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = true; ButtonRefreshCollection.UseVisualStyleBackColor = true;
@ -84,8 +89,9 @@
// pictureBoxCollection // pictureBoxCollection
// //
pictureBoxCollection.Location = new Point(0, 0); pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
pictureBoxCollection.Name = "pictureBoxCollection"; pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(637, 583); pictureBoxCollection.Size = new Size(728, 777);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom; pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
pictureBoxCollection.TabIndex = 3; pictureBoxCollection.TabIndex = 3;
pictureBoxCollection.TabStop = false; pictureBoxCollection.TabStop = false;
@ -93,37 +99,66 @@
// maskedTextBoxNumber // maskedTextBoxNumber
// //
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point); maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
maskedTextBoxNumber.Location = new Point(58, 429); maskedTextBoxNumber.Location = new Point(66, 604);
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
maskedTextBoxNumber.Mask = "00"; maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber"; maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(100, 22); maskedTextBoxNumber.Size = new Size(114, 26);
maskedTextBoxNumber.TabIndex = 4; maskedTextBoxNumber.TabIndex = 4;
maskedTextBoxNumber.ValidatingType = typeof(int); maskedTextBoxNumber.ValidatingType = typeof(int);
// //
// groupBox1 // groupBox1
// //
groupBox1.Controls.Add(ButtonSortByType);
groupBox1.Controls.Add(ButtonSortByColor);
groupBox1.Controls.Add(groupBox2); groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(ButtonAddUsta); groupBox1.Controls.Add(ButtonAddUsta);
groupBox1.Controls.Add(ButtonRefreshCollection); groupBox1.Controls.Add(ButtonRefreshCollection);
groupBox1.Controls.Add(maskedTextBoxNumber); groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(ButtonRemoveUsta); groupBox1.Controls.Add(ButtonRemoveUsta);
groupBox1.Controls.Add(menuStrip); groupBox1.Controls.Add(menuStrip);
groupBox1.Location = new Point(643, 12); groupBox1.Location = new Point(735, 16);
groupBox1.Margin = new Padding(3, 4, 3, 4);
groupBox1.Name = "groupBox1"; groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(209, 560); groupBox1.Padding = new Padding(3, 4, 3, 4);
groupBox1.Size = new Size(239, 747);
groupBox1.TabIndex = 5; groupBox1.TabIndex = 5;
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Инструменты"; groupBox1.Text = "Инструменты";
// //
// ButtonSortByType
//
ButtonSortByType.Location = new Point(30, 471);
ButtonSortByType.Margin = new Padding(3, 4, 3, 4);
ButtonSortByType.Name = "ButtonSortByType";
ButtonSortByType.Size = new Size(190, 35);
ButtonSortByType.TabIndex = 9;
ButtonSortByType.Text = "Сортировка по типу";
ButtonSortByType.UseVisualStyleBackColor = true;
ButtonSortByType.Click += ButtonSortByType_Click;
//
// ButtonSortByColor
//
ButtonSortByColor.Location = new Point(30, 514);
ButtonSortByColor.Margin = new Padding(3, 4, 3, 4);
ButtonSortByColor.Name = "ButtonSortByColor";
ButtonSortByColor.Size = new Size(190, 35);
ButtonSortByColor.TabIndex = 8;
ButtonSortByColor.Text = "Сортировка по цвету";
ButtonSortByColor.UseVisualStyleBackColor = true;
ButtonSortByColor.Click += ButtonSortByColor_Click;
//
// groupBox2 // groupBox2
// //
groupBox2.Controls.Add(listBoxStorage); groupBox2.Controls.Add(listBoxStorage);
groupBox2.Controls.Add(ButtonDelObject); groupBox2.Controls.Add(ButtonDelObject);
groupBox2.Controls.Add(ButtonAddObject); groupBox2.Controls.Add(ButtonAddObject);
groupBox2.Controls.Add(textBoxStorageName); groupBox2.Controls.Add(textBoxStorageName);
groupBox2.Location = new Point(6, 64); groupBox2.Location = new Point(7, 85);
groupBox2.Margin = new Padding(3, 4, 3, 4);
groupBox2.Name = "groupBox2"; groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(197, 274); groupBox2.Padding = new Padding(3, 4, 3, 4);
groupBox2.Size = new Size(225, 365);
groupBox2.TabIndex = 6; groupBox2.TabIndex = 6;
groupBox2.TabStop = false; groupBox2.TabStop = false;
groupBox2.Text = "Наборы"; groupBox2.Text = "Наборы";
@ -131,18 +166,20 @@
// listBoxStorage // listBoxStorage
// //
listBoxStorage.FormattingEnabled = true; listBoxStorage.FormattingEnabled = true;
listBoxStorage.ItemHeight = 15; listBoxStorage.ItemHeight = 20;
listBoxStorage.Location = new Point(20, 106); listBoxStorage.Location = new Point(23, 141);
listBoxStorage.Margin = new Padding(3, 4, 3, 4);
listBoxStorage.Name = "listBoxStorage"; listBoxStorage.Name = "listBoxStorage";
listBoxStorage.Size = new Size(158, 109); listBoxStorage.Size = new Size(180, 144);
listBoxStorage.TabIndex = 9; listBoxStorage.TabIndex = 9;
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged; listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
// //
// ButtonDelObject // ButtonDelObject
// //
ButtonDelObject.Location = new Point(33, 235); ButtonDelObject.Location = new Point(38, 313);
ButtonDelObject.Margin = new Padding(3, 4, 3, 4);
ButtonDelObject.Name = "ButtonDelObject"; ButtonDelObject.Name = "ButtonDelObject";
ButtonDelObject.Size = new Size(136, 33); ButtonDelObject.Size = new Size(155, 44);
ButtonDelObject.TabIndex = 8; ButtonDelObject.TabIndex = 8;
ButtonDelObject.Text = "Удалить набор"; ButtonDelObject.Text = "Удалить набор";
ButtonDelObject.UseVisualStyleBackColor = true; ButtonDelObject.UseVisualStyleBackColor = true;
@ -150,9 +187,10 @@
// //
// ButtonAddObject // ButtonAddObject
// //
ButtonAddObject.Location = new Point(33, 54); ButtonAddObject.Location = new Point(38, 72);
ButtonAddObject.Margin = new Padding(3, 4, 3, 4);
ButtonAddObject.Name = "ButtonAddObject"; ButtonAddObject.Name = "ButtonAddObject";
ButtonAddObject.Size = new Size(136, 33); ButtonAddObject.Size = new Size(155, 44);
ButtonAddObject.TabIndex = 7; ButtonAddObject.TabIndex = 7;
ButtonAddObject.Text = "Добавить набор"; ButtonAddObject.Text = "Добавить набор";
ButtonAddObject.UseVisualStyleBackColor = true; ButtonAddObject.UseVisualStyleBackColor = true;
@ -160,17 +198,20 @@
// //
// textBoxStorageName // textBoxStorageName
// //
textBoxStorageName.Location = new Point(20, 22); textBoxStorageName.Location = new Point(23, 29);
textBoxStorageName.Margin = new Padding(3, 4, 3, 4);
textBoxStorageName.Name = "textBoxStorageName"; textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(158, 23); textBoxStorageName.Size = new Size(180, 27);
textBoxStorageName.TabIndex = 0; textBoxStorageName.TabIndex = 0;
// //
// menuStrip // menuStrip
// //
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
menuStrip.Location = new Point(3, 19); menuStrip.Location = new Point(3, 24);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(203, 24); menuStrip.Padding = new Padding(7, 3, 0, 3);
menuStrip.Size = new Size(233, 30);
menuStrip.TabIndex = 7; menuStrip.TabIndex = 7;
menuStrip.Text = "menuStrip1"; menuStrip.Text = "menuStrip1";
// //
@ -178,20 +219,20 @@
// //
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
fileToolStripMenuItem.Name = "fileToolStripMenuItem"; fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new Size(48, 20); fileToolStripMenuItem.Size = new Size(59, 24);
fileToolStripMenuItem.Text = "Файл"; fileToolStripMenuItem.Text = "Файл";
// //
// SaveToolStripMenuItem // SaveToolStripMenuItem
// //
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new Size(180, 22); SaveToolStripMenuItem.Size = new Size(177, 26);
SaveToolStripMenuItem.Text = "Сохранение"; SaveToolStripMenuItem.Text = "Сохранение";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
// //
// LoadToolStripMenuItem // LoadToolStripMenuItem
// //
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new Size(180, 22); LoadToolStripMenuItem.Size = new Size(177, 26);
LoadToolStripMenuItem.Text = "Загрузка"; LoadToolStripMenuItem.Text = "Загрузка";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
// //
@ -208,12 +249,13 @@
// //
// FormSelfPropelledArtilleryUnitCollection // FormSelfPropelledArtilleryUnitCollection
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(867, 584); ClientSize = new Size(991, 779);
Controls.Add(groupBox1); Controls.Add(groupBox1);
Controls.Add(pictureBoxCollection); Controls.Add(pictureBoxCollection);
MainMenuStrip = menuStrip; MainMenuStrip = menuStrip;
Margin = new Padding(3, 4, 3, 4);
Name = "FormSelfPropelledArtilleryUnitCollection"; Name = "FormSelfPropelledArtilleryUnitCollection";
Text = "Набор арт. установок"; Text = "Набор арт. установок";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
@ -245,5 +287,7 @@
private ToolStripMenuItem LoadToolStripMenuItem; private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog; private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog; private SaveFileDialog saveFileDialog;
private Button ButtonSortByType;
private Button ButtonSortByColor;
} }
} }

View File

@ -41,7 +41,7 @@ namespace SelfPropelledArtilleryUnit
listBoxStorage.Items.Clear(); listBoxStorage.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++) for (int i = 0; i < _storage.Keys.Count; i++)
{ {
listBoxStorage.Items.Add(_storage.Keys[i]); listBoxStorage.Items.Add(_storage.Keys[i].Name);
} }
if (listBoxStorage.Items.Count > 0 && (index == -1 || index if (listBoxStorage.Items.Count > 0 && (index == -1 || index
>= listBoxStorage.Items.Count)) >= listBoxStorage.Items.Count))
@ -70,7 +70,7 @@ namespace SelfPropelledArtilleryUnit
} }
_storage.AddSet(textBoxStorageName.Text); _storage.AddSet(textBoxStorageName.Text);
ReloadObjects(); ReloadObjects();
_logger.LogInformation($"Добавлен набор:{ textBoxStorageName.Text}"); _logger.LogInformation($"Добавлен набор:{textBoxStorageName.Text}");
} }
/// <summary> /// <summary>
@ -254,11 +254,31 @@ namespace SelfPropelledArtilleryUnit
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}"); _logger.LogWarning($"Не удалось загрузить наборы с ошибкой: {ex.Message}");
} }
} }
} }
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareUsta(new UstaCompareByType());
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareUsta(new UstaCompareByColor());
private void CompareUsta(IComparer<DrawningUsta?> comparer)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
obj.Sort(comparer);
pictureBoxCollection.Image = obj.ShowUsta();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using SelfPropelledArtilleryUnit.Exceptions;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -26,6 +27,7 @@ namespace SelfPropelledArtilleryUnit.Generics
/// Максимальное количество объектов в списке /// Максимальное количество объектов в списке
/// </summary> /// </summary>
private readonly int _maxCount; private readonly int _maxCount;
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -33,29 +35,31 @@ namespace SelfPropelledArtilleryUnit.Generics
public SetGeneric(int count) public SetGeneric(int count)
{ {
_maxCount = count; _maxCount = count;
_places = new List<T?>(count); _places = new List<T?>(_maxCount);
} }
/// <summary> /// <summary>
/// Добавление объекта в набор /// Добавление объекта в набор
public int Insert(T usta) public bool Insert(T usta, IEqualityComparer<T>? equal = null)
{ {
Insert(usta, 0, equal);
return Insert(usta, 0); return true;
} }
/// <returns></returns> /// <returns></returns>
public int Insert(T usta, int position) public bool Insert(T usta, int position, IEqualityComparer<T>? equal = null)
{ {
if (position < 0 || position >= _maxCount) if (position < 0 || position >= _maxCount)
return -1; throw new UstaNotFoundException(position);
if (Count >= _maxCount) if (Count >= _maxCount)
return -1; throw new StorageOverflowException(position);
if (equal != null)
{
if (_places.Contains(usta, equal))
throw new ArgumentException(nameof(usta));
}
_places.Insert(position, usta); _places.Insert(position, usta);
return position; return true;
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit
{
internal class UstaCollectionInfo : IEquatable<UstaCollectionInfo>
{
public string Name { get; private set; }
public string Description { get; private set; }
public UstaCollectionInfo(string name, string description)
{
Name = name;
Description = description;
}
public bool Equals(UstaCollectionInfo? other)
{
return Name == other.Name;
}
public override int GetHashCode()
{
return this.Name.GetHashCode();
}
}
}

View File

@ -0,0 +1,50 @@
using SelfPropelledArtilleryUnit.DrawningObjects;
using SelfPropelledArtilleryUnit.Entities;
using SelfPropelledArtilleryUnit.Generics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit
{
internal class UstaCompareByColor : IComparer<DrawningUsta?>
{
public int Compare(DrawningUsta? x, DrawningUsta? y)
{
if (x == null || x.EntityUsta == null)
throw new ArgumentNullException(nameof(x));
if (y == null || y.EntityUsta == null)
throw new ArgumentNullException(nameof(y));
if (x.EntityUsta.BodyColor.Name != y.EntityUsta.BodyColor.Name)
{
return x.EntityUsta.BodyColor.Name.CompareTo(y.EntityUsta.BodyColor.Name);
}
if (x.GetType().Name != y.GetType().Name)
{
if (x is EntityUsta)
return -1;
else
return 1;
}
if (x.GetType().Name == y.GetType().Name && x is DrawningUstaBat)
{
EntityUstaBat EntityX = (EntityUstaBat)x.EntityUsta;
EntityUstaBat EntityY = (EntityUstaBat)y.EntityUsta;
if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name)
{
return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name);
}
}
var speedCompare = x.EntityUsta.Speed.CompareTo(y.EntityUsta.Speed);
if (speedCompare != 0)
return speedCompare;
return x.EntityUsta.Weight.CompareTo(y.EntityUsta.Weight);
}
}
}

View File

@ -0,0 +1,32 @@
using SelfPropelledArtilleryUnit.DrawningObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit
{
internal class UstaCompareByType : IComparer<DrawningUsta?>
{
public int Compare(DrawningUsta? x, DrawningUsta? y)
{
if (x == null || x.EntityUsta == null)
throw new ArgumentNullException(nameof(x));
if (y == null || y.EntityUsta == null)
throw new ArgumentNullException(nameof(y));
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityUsta.Speed.CompareTo(y.EntityUsta.Speed);
if (speedCompare != 0)
return speedCompare;
return x.EntityUsta.Weight.CompareTo(y.EntityUsta.Weight);
}
}
}

View File

@ -38,6 +38,7 @@ namespace SelfPropelledArtilleryUnit.Generics
/// Набор объектов /// Набор объектов
/// </summary> /// </summary>
private readonly SetGeneric<T> _collection; private readonly SetGeneric<T> _collection;
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -57,14 +58,14 @@ namespace SelfPropelledArtilleryUnit.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 +(UstaGenericCollection<T, U> collect, T? public static bool operator +(UstaGenericCollection<T, U> collect, T?
obj) obj)
{ {
if (obj == null) if (obj == null)
{ {
return -1; return false;
} }
return collect?._collection.Insert(obj) ?? -1; return collect?._collection.Insert(obj, new DrawningUstaEqutables()) ?? false;
} }
/// <summary> /// <summary>
/// Перегрузка оператора вычитания /// Перегрузка оператора вычитания
@ -72,7 +73,7 @@ namespace SelfPropelledArtilleryUnit.Generics
/// <param name="collect"></param> /// <param name="collect"></param>
/// <param name="pos"></param> /// <param name="pos"></param>
/// <returns></returns> /// <returns></returns>
public static T operator -(UstaGenericCollection<T, U> collect, int public static T? operator -(UstaGenericCollection<T, U> collect, int
pos) pos)
{ {
T obj = collect._collection[pos]; T obj = collect._collection[pos];

View File

@ -16,12 +16,12 @@ namespace SelfPropelledArtilleryUnit.Generics
/// <summary> /// <summary>
/// Словарь (хранилище) /// Словарь (хранилище)
/// </summary> /// </summary>
readonly Dictionary<string, UstaGenericCollection<DrawningUsta, readonly Dictionary<UstaCollectionInfo, UstaGenericCollection<DrawningUsta,
DrawningObjectUsta>> _ustaStorages; DrawningObjectUsta>> _ustaStorages;
/// <summary> /// <summary>
/// Возвращение списка названий наборов /// Возвращение списка названий наборов
/// </summary> /// </summary>
public List<string> Keys => _ustaStorages.Keys.ToList(); public List<UstaCollectionInfo> Keys => _ustaStorages.Keys.ToList();
/// <summary> /// <summary>
/// Ширина окна отрисовки /// Ширина окна отрисовки
/// </summary> /// </summary>
@ -49,7 +49,7 @@ namespace SelfPropelledArtilleryUnit.Generics
/// <param name="pictureHeight"></param> /// <param name="pictureHeight"></param>
public UstaGenericStorage(int pictureWidth, int pictureHeight) public UstaGenericStorage(int pictureWidth, int pictureHeight)
{ {
_ustaStorages = new Dictionary<string, _ustaStorages = new Dictionary<UstaCollectionInfo,
UstaGenericCollection<DrawningUsta, DrawningObjectUsta>>(); UstaGenericCollection<DrawningUsta, DrawningObjectUsta>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
@ -61,10 +61,10 @@ namespace SelfPropelledArtilleryUnit.Generics
public void AddSet(string name) public void AddSet(string name)
{ {
// TODO Прописать логику для добавления // TODO Прописать логику для добавления
if (!_ustaStorages.ContainsKey(name)) if (!_ustaStorages.ContainsKey(new UstaCollectionInfo(name, string.Empty)))
{ {
var ustaCollection = new UstaGenericCollection<DrawningUsta, DrawningObjectUsta>(_pictureWidth, _pictureHeight); var ustaCollection = new UstaGenericCollection<DrawningUsta, DrawningObjectUsta>(_pictureWidth, _pictureHeight);
_ustaStorages.Add(name, ustaCollection); _ustaStorages.Add(new UstaCollectionInfo(name, string.Empty), ustaCollection);
} }
} }
/// <summary> /// <summary>
@ -74,9 +74,9 @@ namespace SelfPropelledArtilleryUnit.Generics
public void DelSet(string name) public void DelSet(string name)
{ {
// TODO Прописать логику для удаления // TODO Прописать логику для удаления
if (_ustaStorages.ContainsKey(name)) if (_ustaStorages.ContainsKey(new UstaCollectionInfo(name, string.Empty)))
{ {
_ustaStorages.Remove(name); _ustaStorages.Remove(new UstaCollectionInfo(name, string.Empty));
} }
} }
/// <summary> /// <summary>
@ -88,10 +88,11 @@ namespace SelfPropelledArtilleryUnit.Generics
{ {
get get
{ {
UstaCollectionInfo indObj = new UstaCollectionInfo(ind, string.Empty);
// TODO Продумать логику получения набора // TODO Продумать логику получения набора
if (_ustaStorages.ContainsKey(ind)) if (_ustaStorages.ContainsKey(indObj))
{ {
return _ustaStorages[ind]; return _ustaStorages[indObj];
} }
return null; return null;
@ -109,14 +110,14 @@ namespace SelfPropelledArtilleryUnit.Generics
File.Delete(filename); File.Delete(filename);
} }
StringBuilder data = new(); StringBuilder data = new();
foreach (KeyValuePair<string, UstaGenericCollection<DrawningUsta, DrawningObjectUsta>> record in _ustaStorages) foreach (KeyValuePair<UstaCollectionInfo, UstaGenericCollection<DrawningUsta, DrawningObjectUsta>> record in _ustaStorages)
{ {
StringBuilder records = new(); StringBuilder records = new();
foreach (DrawningUsta? elem in record.Value.GetUsta) foreach (DrawningUsta? elem in record.Value.GetUsta)
{ {
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
} }
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
} }
if (data.Length == 0) if (data.Length == 0)
{ {
@ -185,7 +186,7 @@ namespace SelfPropelledArtilleryUnit.Generics
} }
} }
} }
_ustaStorages.Add(name, collection); _ustaStorages.Add(new UstaCollectionInfo(name, string.Empty), collection);
} }
} }
} }