Второй шаг готов
This commit is contained in:
parent
8aa272b0cb
commit
402fb1d315
74
SelfPropelledArtilleryUnit/ArtilleryCompareByColor.cs
Normal file
74
SelfPropelledArtilleryUnit/ArtilleryCompareByColor.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class ArtilleryCompareByColor : IComparer<IDrawingObject>
|
||||
{
|
||||
public int Compare(IDrawingObject? first, IDrawingObject? second)
|
||||
{
|
||||
if (first == null && second == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (first == null && second != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (first != null && second == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var firstArtillery = first as DrawingObjectArtillery;
|
||||
var secondArtillery = second as DrawingObjectArtillery;
|
||||
|
||||
if (firstArtillery == null && secondArtillery == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (firstArtillery == null && secondArtillery != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (firstArtillery != null && secondArtillery == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int firstColor = firstArtillery.Artillery.Artillery.BodyColor.ToArgb();
|
||||
int secondColor = secondArtillery.Artillery.Artillery.BodyColor.ToArgb();
|
||||
|
||||
if (firstColor != secondColor)
|
||||
{
|
||||
return firstColor.CompareTo(secondColor);
|
||||
}
|
||||
|
||||
if (firstArtillery.Artillery.Artillery is EntityAdvancedArtillery firstAdvanced && secondArtillery.Artillery.Artillery is EntityAdvancedArtillery secondAdvanced)
|
||||
{
|
||||
firstColor = firstAdvanced.DopColor.ToArgb();
|
||||
secondColor = secondAdvanced.DopColor.ToArgb();
|
||||
|
||||
if (firstColor != secondColor)
|
||||
{
|
||||
return firstColor.CompareTo(secondColor);
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = firstArtillery.Artillery.Artillery.Speed.CompareTo(secondArtillery.Artillery.Artillery.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return firstArtillery.Artillery.Artillery.Weight.CompareTo(secondArtillery.Artillery.Artillery.Weight);
|
||||
}
|
||||
}
|
||||
}
|
64
SelfPropelledArtilleryUnit/ArtilleryCompareByType.cs
Normal file
64
SelfPropelledArtilleryUnit/ArtilleryCompareByType.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class ArtilleryCompareByType : IComparer<IDrawingObject>
|
||||
{
|
||||
public int Compare(IDrawingObject? first, IDrawingObject? second)
|
||||
{
|
||||
if (first == null && second == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (first == null && second != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (first != null && second == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var firstArtillery = first as DrawingObjectArtillery;
|
||||
var secondArtillery = second as DrawingObjectArtillery;
|
||||
|
||||
if (firstArtillery == null && secondArtillery == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (firstArtillery == null && secondArtillery != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (firstArtillery != null && secondArtillery == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (firstArtillery.Artillery.GetType() != secondArtillery.Artillery.GetType())
|
||||
{
|
||||
if (firstArtillery.Artillery.GetType().Name == "DrawningArtillery")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
var speedCompare = firstArtillery.Artillery.Artillery.Speed.CompareTo(secondArtillery.Artillery.Artillery.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return firstArtillery.Artillery.Artillery.Weight.CompareTo(secondArtillery.Artillery.Artillery.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ namespace Artilleries
|
||||
{
|
||||
private DrawingArtillery _artillery = null;
|
||||
|
||||
public DrawingArtillery Artillery => _artillery;
|
||||
|
||||
public DrawingObjectArtillery(DrawingArtillery artillery)
|
||||
{
|
||||
_artillery = artillery;
|
||||
|
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.toolsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||
this.mapsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
@ -59,6 +61,8 @@
|
||||
//
|
||||
// toolsGroupBox
|
||||
//
|
||||
this.toolsGroupBox.Controls.Add(this.buttonSortByColor);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonSortByType);
|
||||
this.toolsGroupBox.Controls.Add(this.mapsGroupBox);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonShowOnMap);
|
||||
this.toolsGroupBox.Controls.Add(this.buttonShowStorage);
|
||||
@ -72,11 +76,31 @@
|
||||
this.toolsGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.toolsGroupBox.Location = new System.Drawing.Point(600, 24);
|
||||
this.toolsGroupBox.Name = "toolsGroupBox";
|
||||
this.toolsGroupBox.Size = new System.Drawing.Size(200, 589);
|
||||
this.toolsGroupBox.Size = new System.Drawing.Size(200, 657);
|
||||
this.toolsGroupBox.TabIndex = 0;
|
||||
this.toolsGroupBox.TabStop = false;
|
||||
this.toolsGroupBox.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(13, 324);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonSortByColor.TabIndex = 27;
|
||||
this.buttonSortByColor.Text = "Сортировать по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(13, 286);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonSortByType.TabIndex = 26;
|
||||
this.buttonSortByType.Text = "Сортировать по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
|
||||
//
|
||||
// mapsGroupBox
|
||||
//
|
||||
this.mapsGroupBox.Controls.Add(this.buttonDeleteMap);
|
||||
@ -142,7 +166,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(13, 470);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(13, 526);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonShowOnMap.TabIndex = 24;
|
||||
@ -152,7 +176,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(13, 423);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(13, 488);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonShowStorage.TabIndex = 23;
|
||||
@ -162,7 +186,7 @@
|
||||
//
|
||||
// buttonRemoveArtillery
|
||||
//
|
||||
this.buttonRemoveArtillery.Location = new System.Drawing.Point(13, 376);
|
||||
this.buttonRemoveArtillery.Location = new System.Drawing.Point(13, 441);
|
||||
this.buttonRemoveArtillery.Name = "buttonRemoveArtillery";
|
||||
this.buttonRemoveArtillery.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonRemoveArtillery.TabIndex = 22;
|
||||
@ -172,7 +196,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 347);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 412);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
@ -180,7 +204,7 @@
|
||||
//
|
||||
// buttonAddArtillery
|
||||
//
|
||||
this.buttonAddArtillery.Location = new System.Drawing.Point(13, 309);
|
||||
this.buttonAddArtillery.Location = new System.Drawing.Point(13, 374);
|
||||
this.buttonAddArtillery.Name = "buttonAddArtillery";
|
||||
this.buttonAddArtillery.Size = new System.Drawing.Size(175, 32);
|
||||
this.buttonAddArtillery.TabIndex = 20;
|
||||
@ -193,7 +217,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(124, 538);
|
||||
this.buttonRight.Location = new System.Drawing.Point(124, 606);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 18;
|
||||
@ -205,7 +229,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(88, 538);
|
||||
this.buttonDown.Location = new System.Drawing.Point(88, 606);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 17;
|
||||
@ -217,7 +241,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(88, 505);
|
||||
this.buttonUp.Location = new System.Drawing.Point(88, 573);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 16;
|
||||
@ -229,7 +253,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(54, 538);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(54, 606);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 15;
|
||||
@ -241,7 +265,7 @@
|
||||
this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 24);
|
||||
this.pictureBoxArtilleries.Name = "pictureBoxArtilleries";
|
||||
this.pictureBoxArtilleries.Size = new System.Drawing.Size(600, 589);
|
||||
this.pictureBoxArtilleries.Size = new System.Drawing.Size(600, 657);
|
||||
this.pictureBoxArtilleries.TabIndex = 1;
|
||||
this.pictureBoxArtilleries.TabStop = false;
|
||||
//
|
||||
@ -291,7 +315,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 613);
|
||||
this.ClientSize = new System.Drawing.Size(800, 681);
|
||||
this.Controls.Add(this.pictureBoxArtilleries);
|
||||
this.Controls.Add(this.toolsGroupBox);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
@ -335,5 +359,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private OpenFileDialog loadFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -250,5 +250,25 @@ namespace Artilleries
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new ArtilleryCompareByType());
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new ArtilleryCompareByColor());
|
||||
pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Artilleries
|
||||
{
|
||||
internal class MapWithSetArtilleriesGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
@ -142,5 +142,10 @@ namespace Artilleries
|
||||
_setArtilleries.Insert(DrawingObjectArtillery.Create(record) as T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setArtilleries.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,5 +98,15 @@ namespace Artilleries
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user