diff --git a/Warship/Warship/DrawingObjectWarship.cs b/Warship/Warship/DrawingObjectWarship.cs
index 6c77dee..169357e 100644
--- a/Warship/Warship/DrawingObjectWarship.cs
+++ b/Warship/Warship/DrawingObjectWarship.cs
@@ -16,6 +16,8 @@ namespace Warship
}
public float Step => _warship?.Warship?.Step ?? 0;
+ public DrawingWarship GetWarship => _warship;
+
void IDrawingObject.DrawingObject(Graphics g)
{
_warship.DrawTransport(g);
diff --git a/Warship/Warship/FormMapWithSetWarships.Designer.cs b/Warship/Warship/FormMapWithSetWarships.Designer.cs
index 8eab89f..46250b8 100644
--- a/Warship/Warship/FormMapWithSetWarships.Designer.cs
+++ b/Warship/Warship/FormMapWithSetWarships.Designer.cs
@@ -51,6 +51,8 @@
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog();
+ this.ButtonSortType = new System.Windows.Forms.Button();
+ this.ButtonSortColor = new System.Windows.Forms.Button();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
@@ -59,6 +61,8 @@
//
// groupBoxTools
//
+ this.groupBoxTools.Controls.Add(this.ButtonSortColor);
+ this.groupBoxTools.Controls.Add(this.ButtonSortType);
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveWarship);
@@ -72,7 +76,7 @@
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(859, 24);
this.groupBoxTools.Name = "groupBoxTools";
- this.groupBoxTools.Size = new System.Drawing.Size(204, 628);
+ this.groupBoxTools.Size = new System.Drawing.Size(204, 677);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
@@ -142,7 +146,7 @@
//
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(15, 358);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 344);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
@@ -151,7 +155,7 @@
//
// buttonRemoveWarship
//
- this.buttonRemoveWarship.Location = new System.Drawing.Point(15, 387);
+ this.buttonRemoveWarship.Location = new System.Drawing.Point(20, 373);
this.buttonRemoveWarship.Name = "buttonRemoveWarship";
this.buttonRemoveWarship.Size = new System.Drawing.Size(175, 35);
this.buttonRemoveWarship.TabIndex = 3;
@@ -161,7 +165,7 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(15, 452);
+ this.buttonShowStorage.Location = new System.Drawing.Point(20, 427);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
this.buttonShowStorage.TabIndex = 4;
@@ -174,7 +178,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Warship.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(91, 578);
+ this.buttonDown.Location = new System.Drawing.Point(92, 641);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 10;
@@ -186,7 +190,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Warship.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(127, 578);
+ this.buttonRight.Location = new System.Drawing.Point(128, 641);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 9;
@@ -198,7 +202,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Warship.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(55, 578);
+ this.buttonLeft.Location = new System.Drawing.Point(56, 641);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8;
@@ -210,7 +214,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Warship.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(91, 542);
+ this.buttonUp.Location = new System.Drawing.Point(92, 605);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7;
@@ -219,7 +223,7 @@
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(15, 493);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(20, 468);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
this.buttonShowOnMap.TabIndex = 5;
@@ -229,7 +233,7 @@
//
// buttonAddWarship
//
- this.buttonAddWarship.Location = new System.Drawing.Point(15, 317);
+ this.buttonAddWarship.Location = new System.Drawing.Point(20, 303);
this.buttonAddWarship.Name = "buttonAddWarship";
this.buttonAddWarship.Size = new System.Drawing.Size(175, 35);
this.buttonAddWarship.TabIndex = 1;
@@ -242,7 +246,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(859, 628);
+ this.pictureBox.Size = new System.Drawing.Size(859, 677);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@@ -267,14 +271,14 @@
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
- this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
- this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.LoadToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
@@ -286,11 +290,31 @@
//
this.SaveFileDialog.Filter = "txt file | *.txt";
//
+ // ButtonSortType
+ //
+ this.ButtonSortType.Location = new System.Drawing.Point(22, 523);
+ this.ButtonSortType.Name = "ButtonSortType";
+ this.ButtonSortType.Size = new System.Drawing.Size(173, 35);
+ this.ButtonSortType.TabIndex = 12;
+ this.ButtonSortType.Text = "Сортировать по типу";
+ this.ButtonSortType.UseVisualStyleBackColor = true;
+ this.ButtonSortType.Click += new System.EventHandler(this.ButtonSortType_Click);
+ //
+ // ButtonSortColor
+ //
+ this.ButtonSortColor.Location = new System.Drawing.Point(22, 564);
+ this.ButtonSortColor.Name = "ButtonSortColor";
+ this.ButtonSortColor.Size = new System.Drawing.Size(173, 35);
+ this.ButtonSortColor.TabIndex = 13;
+ this.ButtonSortColor.Text = "Сортировать по цвету";
+ this.ButtonSortColor.UseVisualStyleBackColor = true;
+ this.ButtonSortColor.Click += new System.EventHandler(this.ButtonSortColor_Click);
+ //
// FormMapWithSetWarships
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1063, 652);
+ this.ClientSize = new System.Drawing.Size(1063, 701);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.MenuStrip);
@@ -334,5 +358,7 @@
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog OpenFileDialog;
private SaveFileDialog SaveFileDialog;
+ private Button ButtonSortColor;
+ private Button ButtonSortType;
}
}
\ No newline at end of file
diff --git a/Warship/Warship/FormMapWithSetWarships.cs b/Warship/Warship/FormMapWithSetWarships.cs
index e4b918b..330340f 100644
--- a/Warship/Warship/FormMapWithSetWarships.cs
+++ b/Warship/Warship/FormMapWithSetWarships.cs
@@ -248,5 +248,23 @@ namespace Warship
}
}
}
+
+ private void ButtonSortType_Click(object sender, EventArgs e)
+ {
+ if (listBoxMaps.SelectedIndex == -1)
+ return;
+
+ _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new WarshipCompareByType());
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+
+ private void ButtonSortColor_Click(object sender, EventArgs e)
+ {
+ if (listBoxMaps.SelectedIndex == -1)
+ return;
+
+ _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new WarshipCompareByColor());
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
}
}
diff --git a/Warship/Warship/FormMapWithSetWarships.resx b/Warship/Warship/FormMapWithSetWarships.resx
index ef5b21a..08717da 100644
--- a/Warship/Warship/FormMapWithSetWarships.resx
+++ b/Warship/Warship/FormMapWithSetWarships.resx
@@ -66,4 +66,7 @@
265, 17
+
+ 25
+
\ No newline at end of file
diff --git a/Warship/Warship/MapWithSetWarshipsGeneric.cs b/Warship/Warship/MapWithSetWarshipsGeneric.cs
index f15a69c..b8012d8 100644
--- a/Warship/Warship/MapWithSetWarshipsGeneric.cs
+++ b/Warship/Warship/MapWithSetWarshipsGeneric.cs
@@ -83,6 +83,11 @@ namespace Warship
}
}
+ public void Sort(IComparer comparer)
+ {
+ _setWarship.SortSet(comparer);
+ }
+
public void Shaking()
{
int j = _setWarship.Count - 1;
diff --git a/Warship/Warship/SetWarshipsGeneric.cs b/Warship/Warship/SetWarshipsGeneric.cs
index 5362761..e5be7a7 100644
--- a/Warship/Warship/SetWarshipsGeneric.cs
+++ b/Warship/Warship/SetWarshipsGeneric.cs
@@ -87,5 +87,13 @@ namespace Warship
}
}
}
+
+ public void SortSet(IComparer comparer)
+ {
+ if (comparer == null)
+ return;
+
+ _places.Sort(comparer);
+ }
}
}
diff --git a/Warship/Warship/WarshipCompareByColor.cs b/Warship/Warship/WarshipCompareByColor.cs
new file mode 100644
index 0000000..8837bc6
--- /dev/null
+++ b/Warship/Warship/WarshipCompareByColor.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Warship
+{
+ internal class WarshipCompareByColor : IComparer
+ {
+ public int Compare(IDrawingObject? x, IDrawingObject? y)
+ {
+ if (x == null && y == null)
+ return 0;
+
+
+ if (x == null && y != null)
+ return 1;
+
+
+ if (x != null && y == null)
+ return -1;
+
+
+ var xWarship = x as DrawingObjectWarship;
+ var yWarship = y as DrawingObjectWarship;
+
+ if (xWarship == null && yWarship == null)
+ return 0;
+
+
+ if (xWarship == null && yWarship != null)
+ return 1;
+
+
+ if (xWarship != null && yWarship == null)
+ return -1;
+
+
+ int xColor = xWarship.GetWarship.Warship.BodyColor.ToArgb();
+ int yColor = yWarship.GetWarship.Warship.BodyColor.ToArgb();
+
+ if (xColor != yColor)
+ return xColor.CompareTo(yColor);
+
+
+ if (xWarship.GetWarship.Warship is EntityAdvancedWarship xAdvanced && yWarship.GetWarship.Warship is EntityAdvancedWarship yAdvanced)
+ {
+ xColor = xAdvanced.DopColor.ToArgb();
+ yColor = yAdvanced.DopColor.ToArgb();
+
+ if (xColor != yColor)
+ return xColor.CompareTo(yColor);
+
+ }
+
+ var speedCompare = xWarship.GetWarship.Warship.Speed.CompareTo(yWarship.GetWarship.Warship.Speed);
+ if (speedCompare != 0)
+ return speedCompare;
+
+
+ return xWarship.GetWarship.Warship.Weight.CompareTo(yWarship.GetWarship.Warship.Weight);
+ }
+ }
+}
diff --git a/Warship/Warship/WarshipCompareByType.cs b/Warship/Warship/WarshipCompareByType.cs
new file mode 100644
index 0000000..a87a79e
--- /dev/null
+++ b/Warship/Warship/WarshipCompareByType.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Warship
+{
+ internal class WarshipCompareByType : IComparer
+ {
+ public int Compare(IDrawingObject? x, IDrawingObject? y)
+ {
+ if (x == null && y == null)
+ return 0;
+
+ if (x == null && y != null)
+ return 1;
+
+ if (x != null && y == null)
+ return -1;
+
+ var xWarship = x as DrawingObjectWarship;
+ var yWarship = y as DrawingObjectWarship;
+
+ if (xWarship == null && yWarship == null)
+ return 0;
+
+ if (xWarship == null && yWarship != null)
+ return 1;
+
+ if (xWarship != null && yWarship == null)
+ return -1;
+
+ if (xWarship.GetWarship.GetType().Name != yWarship.GetWarship.GetType().Name)
+ {
+ if (xWarship.GetWarship.GetType().Name == "DrawingWarship")
+ return -1;
+
+ return 1;
+ }
+
+ var speedCompare = xWarship.GetWarship.Warship.Speed.CompareTo(yWarship.GetWarship.Warship.Speed);
+
+ if (speedCompare != 0)
+ return speedCompare;
+
+ return xWarship.GetWarship.Warship.Weight.CompareTo(yWarship.GetWarship.Warship.Weight);
+ }
+ }
+}