From 5a1cdcd4b234b1483cd4139461eabf687fd52e4b Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 21 Nov 2022 19:27:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Locomotive/DrawningObjectLocomotive.cs | 4 +- .../FormMapWithSetLocomotives.Designer.cs | 44 ++++++++--- .../Locomotive/FormMapWithSetLocomotives.cs | 20 +++++ .../Locomotive/FormMapWithSetLocomotives.resx | 2 +- .../Locomotive/LocomotiveCompareByColor.cs | 78 +++++++++++++++++++ .../Locomotive/LocomotiveCompareByType.cs | 55 +++++++++++++ .../MapWithSetLocomotivesGeneric.cs | 5 +- .../Locomotive/SetLocomotivesGeneric.cs | 10 +++ Locomotive/log.clef | 17 ++++ 9 files changed, 223 insertions(+), 12 deletions(-) create mode 100644 Locomotive/Locomotive/LocomotiveCompareByColor.cs create mode 100644 Locomotive/Locomotive/LocomotiveCompareByType.cs create mode 100644 Locomotive/log.clef diff --git a/Locomotive/Locomotive/DrawningObjectLocomotive.cs b/Locomotive/Locomotive/DrawningObjectLocomotive.cs index 5ac2785..8abd23b 100644 --- a/Locomotive/Locomotive/DrawningObjectLocomotive.cs +++ b/Locomotive/Locomotive/DrawningObjectLocomotive.cs @@ -17,6 +17,8 @@ namespace Locomotive public float Step => _locomotive?.Locomotive?.Step ?? 0; + public DrawningLocomotive GetLocomotive => _locomotive; + public void DrawningObject(Graphics g) { _locomotive?.DrawTransport(g); @@ -54,7 +56,7 @@ namespace Locomotive var locomotive = _locomotive.Locomotive; var otherLocomotiveLocomotive = otherLocomotive._locomotive.Locomotive; - if (locomotive.GetType() != otherLocomotiveLocomotive.GetType()) return false; + if (locomotive.GetType().Name != otherLocomotiveLocomotive.GetType().Name) return false; if (locomotive.Speed != otherLocomotiveLocomotive.Speed) { diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs index 5242822..3397daa 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.ButtonSortByType = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.buttonDeleteMap = new System.Windows.Forms.Button(); this.listBoxMaps = new System.Windows.Forms.ListBox(); @@ -51,6 +52,7 @@ this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.loadFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.ButtonSortByColor = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); @@ -59,6 +61,8 @@ // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.ButtonSortByColor); + this.groupBoxTools.Controls.Add(this.ButtonSortByType); this.groupBoxTools.Controls.Add(this.groupBox1); this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonRight); @@ -72,11 +76,21 @@ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(580, 28); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(220, 540); + this.groupBoxTools.Size = new System.Drawing.Size(220, 637); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; // + // ButtonSortByType + // + this.ButtonSortByType.Location = new System.Drawing.Point(7, 456); + this.ButtonSortByType.Name = "ButtonSortByType"; + this.ButtonSortByType.Size = new System.Drawing.Size(207, 29); + this.ButtonSortByType.TabIndex = 9; + this.ButtonSortByType.Text = "Sort By Type"; + this.ButtonSortByType.UseVisualStyleBackColor = true; + this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click); + // // groupBox1 // this.groupBox1.Controls.Add(this.buttonDeleteMap); @@ -144,7 +158,7 @@ // this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(42, 502); + this.buttonLeft.Location = new System.Drawing.Point(48, 591); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(40, 40); this.buttonLeft.TabIndex = 7; @@ -155,7 +169,7 @@ // this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(134, 502); + this.buttonRight.Location = new System.Drawing.Point(140, 591); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(40, 40); this.buttonRight.TabIndex = 7; @@ -166,7 +180,7 @@ // this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(88, 502); + this.buttonDown.Location = new System.Drawing.Point(94, 591); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(40, 40); this.buttonDown.TabIndex = 7; @@ -177,7 +191,7 @@ // this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(88, 456); + this.buttonUp.Location = new System.Drawing.Point(94, 545); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(40, 40); this.buttonUp.TabIndex = 6; @@ -237,7 +251,7 @@ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(580, 540); + this.pictureBox.Size = new System.Drawing.Size(580, 637); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -263,14 +277,14 @@ // saveToolStripMenuItem // this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(125, 26); this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // // loadToolStripMenuItem // this.loadToolStripMenuItem.Name = "loadToolStripMenuItem"; - this.loadToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.loadToolStripMenuItem.Size = new System.Drawing.Size(125, 26); this.loadToolStripMenuItem.Text = "Load"; this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click); // @@ -282,11 +296,21 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // + // ButtonSortByColor + // + this.ButtonSortByColor.Location = new System.Drawing.Point(7, 491); + this.ButtonSortByColor.Name = "ButtonSortByColor"; + this.ButtonSortByColor.Size = new System.Drawing.Size(207, 29); + this.ButtonSortByColor.TabIndex = 10; + this.ButtonSortByColor.Text = "Sort By Color"; + this.ButtonSortByColor.UseVisualStyleBackColor = true; + this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click); + // // FormMapWithSetLocomotives // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 568); + this.ClientSize = new System.Drawing.Size(800, 665); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.menuStrip); @@ -330,5 +354,7 @@ private ToolStripMenuItem loadToolStripMenuItem; private OpenFileDialog loadFileDialog; private SaveFileDialog saveFileDialog; + private Button ButtonSortByType; + private Button ButtonSortByColor; } } \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index a4d16e9..ef12bc4 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -254,5 +254,25 @@ namespace Locomotive } } } + + private void ButtonSortByType_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new LocomotiveCompareByType()); + pictureBox.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 LocomotiveCompareByColor()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } } } diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.resx b/Locomotive/Locomotive/FormMapWithSetLocomotives.resx index a0c7756..3f94c35 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.resx +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.resx @@ -67,6 +67,6 @@ 311, 17 - 33 + 25 \ No newline at end of file diff --git a/Locomotive/Locomotive/LocomotiveCompareByColor.cs b/Locomotive/Locomotive/LocomotiveCompareByColor.cs new file mode 100644 index 0000000..53342fa --- /dev/null +++ b/Locomotive/Locomotive/LocomotiveCompareByColor.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class LocomotiveCompareByColor : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xLocomotive = x as DrawningObjectLocomotive; + var yLocomotive = y as DrawningObjectLocomotive; + if (xLocomotive == null && yLocomotive == null) + { + return 0; + } + if (xLocomotive == null && yLocomotive != null) + { + return 1; + } + if (xLocomotive != null && yLocomotive == null) + { + return -1; + } + + if (xLocomotive.GetLocomotive.Locomotive.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.R) != 0) + { + return xLocomotive.GetLocomotive.Locomotive.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.R); + } + if (xLocomotive.GetLocomotive.Locomotive.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.G) != 0) + { + return xLocomotive.GetLocomotive.Locomotive.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.G); + } + if (xLocomotive.GetLocomotive.Locomotive.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.B) != 0) + { + return xLocomotive.GetLocomotive.Locomotive.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.B); + } + + if (xLocomotive.GetLocomotive.Locomotive is EntityWarmlyLocomotive xWarmlyEntity && yLocomotive.GetLocomotive.Locomotive is EntityWarmlyLocomotive yWarmlyEntity) + { + if (xWarmlyEntity.ExtraColor.R.CompareTo(yWarmlyEntity.ExtraColor.R) != 0) + { + return xWarmlyEntity.ExtraColor.R.CompareTo(yWarmlyEntity.ExtraColor.R); + } + if (xWarmlyEntity.ExtraColor.G.CompareTo(yWarmlyEntity.ExtraColor.G) != 0) + { + return xWarmlyEntity.ExtraColor.G.CompareTo(yWarmlyEntity.ExtraColor.G); + } + if (xWarmlyEntity.ExtraColor.B.CompareTo(yWarmlyEntity.ExtraColor.B) != 0) + { + return xWarmlyEntity.ExtraColor.B.CompareTo(yWarmlyEntity.ExtraColor.B); + } + } + + var speedCompare = xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight); + + } + } +} diff --git a/Locomotive/Locomotive/LocomotiveCompareByType.cs b/Locomotive/Locomotive/LocomotiveCompareByType.cs new file mode 100644 index 0000000..a324498 --- /dev/null +++ b/Locomotive/Locomotive/LocomotiveCompareByType.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class LocomotiveCompareByType : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xLocomotive = x as DrawningObjectLocomotive; + var yLocomotive = y as DrawningObjectLocomotive; + if (xLocomotive == null && yLocomotive == null) + { + return 0; + } + if (xLocomotive == null && yLocomotive != null) + { + return 1; + } + if (xLocomotive != null && yLocomotive == null) + { + return -1; + } + if (xLocomotive.GetLocomotive.GetType().Name != yLocomotive.GetLocomotive.GetType().Name) + { + if (xLocomotive.GetLocomotive.GetType().Name == "DrawningLocomotive") + { + return -1; + } + return 1; + } + var speedCompare = xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight); + } + } +} diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index e6642a3..d58cab9 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -178,6 +178,9 @@ namespace Locomotive } } - + public void Sort(IComparer comparer) + { + _setLocomotives.SortSet(comparer); + } } } diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index add448c..eafee89 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -77,5 +77,15 @@ namespace Locomotive } } + + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } + } } diff --git a/Locomotive/log.clef b/Locomotive/log.clef new file mode 100644 index 0000000..2507a53 --- /dev/null +++ b/Locomotive/log.clef @@ -0,0 +1,17 @@ +{"@t":"2022-11-21T15:23:13.2775821Z","@mt":"Map lalaland added"} +{"@t":"2022-11-21T15:23:13.3466012Z","@mt":"Map switched to lalaland"} +{"@t":"2022-11-21T15:23:31.6565447Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:23:57.7770111Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:25:01.0533266Z","@mt":"Map lalaland added"} +{"@t":"2022-11-21T15:25:01.0794891Z","@mt":"Map switched to lalaland"} +{"@t":"2022-11-21T15:25:01.4998647Z","@mt":"Map switched to lalaland"} +{"@t":"2022-11-21T15:25:06.1595618Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:25:18.9994738Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:25:31.8129464Z","@mt":"Map lalaland added"} +{"@t":"2022-11-21T15:25:31.8344280Z","@mt":"Map switched to lalaland"} +{"@t":"2022-11-21T15:25:37.1362070Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:25:46.1930394Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:26:02.0790751Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:26:24.6631252Z","@mt":"Object Locomotive.DrawningWarmlyLocomotive added"} +{"@t":"2022-11-21T15:26:31.0236570Z","@mt":"Object Locomotive.DrawningLocomotive added"} +{"@t":"2022-11-21T15:26:36.0331011Z","@mt":"Object Locomotive.DrawningWarmlyLocomotive added"}