Фикс недочётов в форме.

This commit is contained in:
Артем Харламов 2022-12-17 19:27:39 +04:00
parent 22373809cd
commit d998522e56
6 changed files with 140 additions and 45 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Stormtrooper namespace Stormtrooper
{ {
internal abstract class AbstractMap internal abstract class AbstractMap : IEquatable<AbstractMap>
{ {
private IDrawningObject _drawningObject = null; private IDrawningObject _drawningObject = null;
protected int[,] _map = null; protected int[,] _map = null;
@ -154,5 +154,36 @@ namespace Stormtrooper
protected abstract void GenerateMap(); protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j);
public bool Equals(AbstractMap? other)
{
if (other == null)
{
return false;
}
if (_width == other._width && _height == other._height && _size_x == other._size_x && _size_y == other._size_y)
{
if (_map == null && other._map == null)
{
return true;
}
if (_map == null || other._map == null || _map.GetLength(0) != other._map.GetLength(0) || _map.GetLength(1) != other._map.GetLength(1))
{
return false;
}
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] != other._map[i, j])
{
return false;
}
}
}
return true;
}
return false;
}
} }
} }

View File

@ -42,52 +42,45 @@ namespace Stormtrooper
{ {
return false; return false;
} }
var otherStorm = other as DrawningObjectStorm; var otherStormtrooper = other as DrawningObjectStorm;
if (otherStorm == null) if (otherStormtrooper == null)
{ {
return false; return false;
} }
var storm = _storm.Storm; var stormtrooper = _storm.Storm;
var otherStormStorm = otherStorm._storm.Storm; var otherStormtrooperStormtrooper = otherStormtrooper._storm.Storm;
if (storm.Speed != otherStormStorm.Speed) if (stormtrooper.Speed != otherStormtrooperStormtrooper.Speed)
{ {
return false; return false;
} }
if (storm.Weight != otherStormStorm.Weight) if (stormtrooper.Weight != otherStormtrooperStormtrooper.Weight)
{ {
return false; return false;
} }
if (storm.BodyColor != otherStormStorm.BodyColor) if (stormtrooper.BodyColor != otherStormtrooperStormtrooper.BodyColor)
{ {
return false; return false;
} }
if (storm is EntityMilitaryStormtrooper milstorm) if (stormtrooper is EntityMilitaryStormtrooper militaryStorm && otherStormtrooperStormtrooper is EntityMilitaryStormtrooper othermilitaryStorm)
{ {
if (other is not EntityMilitaryStormtrooper othermilstorm) if (militaryStorm.DopColor != othermilitaryStorm.DopColor)
{ {
return false; return false;
} }
if (militaryStorm.BodyKit != othermilitaryStorm.BodyKit)
if (milstorm.DopColor != othermilstorm.DopColor)
{ {
return false; return false;
} }
if (militaryStorm.Rocket != othermilitaryStorm.Rocket)
if (milstorm.BodyKit != othermilstorm.BodyKit)
{ {
return false; return false;
} }
if (militaryStorm.SportLine != othermilitaryStorm.SportLine)
if (milstorm.Rocket != othermilstorm.Rocket)
{
return false;
}
if (milstorm.SportLine != othermilstorm.SportLine)
{ {
return false; return false;
} }
} }
else if (stormtrooper is EntityMilitaryStormtrooper || otherStormtrooperStormtrooper is EntityMilitaryStormtrooper) return false;
return true; return true;
} }
} }

View File

@ -29,6 +29,8 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.buttonSortByType = new System.Windows.Forms.Button();
this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox(); this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button();
@ -59,6 +61,8 @@
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.buttonSortByColor);
this.groupBoxTools.Controls.Add(this.buttonSortByType);
this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveCar); this.groupBoxTools.Controls.Add(this.buttonRemoveCar);
@ -74,11 +78,31 @@
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Size = new System.Drawing.Size(233, 856); this.groupBoxTools.Size = new System.Drawing.Size(233, 930);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
// //
// buttonSortByColor
//
this.buttonSortByColor.Location = new System.Drawing.Point(20, 446);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(198, 50);
this.buttonSortByColor.TabIndex = 13;
this.buttonSortByColor.Text = "Сортировать по цвету";
this.buttonSortByColor.UseVisualStyleBackColor = true;
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
//
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(21, 395);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(198, 45);
this.buttonSortByType.TabIndex = 12;
this.buttonSortByType.Text = "Сортировать по типу";
this.buttonSortByType.UseVisualStyleBackColor = true;
this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
//
// groupBoxMaps // groupBoxMaps
// //
this.groupBoxMaps.Controls.Add(this.listBoxMaps); this.groupBoxMaps.Controls.Add(this.listBoxMaps);
@ -148,7 +172,7 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 511); this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 571);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
@ -158,7 +182,7 @@
// //
// buttonRemoveCar // buttonRemoveCar
// //
this.buttonRemoveCar.Location = new System.Drawing.Point(21, 565); this.buttonRemoveCar.Location = new System.Drawing.Point(20, 625);
this.buttonRemoveCar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemoveCar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveCar.Name = "buttonRemoveCar"; this.buttonRemoveCar.Name = "buttonRemoveCar";
this.buttonRemoveCar.Size = new System.Drawing.Size(200, 47); this.buttonRemoveCar.Size = new System.Drawing.Size(200, 47);
@ -169,7 +193,7 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(21, 633); this.buttonShowStorage.Location = new System.Drawing.Point(20, 693);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47); this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
@ -183,7 +207,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowDown; this.buttonDown.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(104, 789); this.buttonDown.Location = new System.Drawing.Point(104, 863);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(34, 40); this.buttonDown.Size = new System.Drawing.Size(34, 40);
@ -196,7 +220,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowRight; this.buttonRight.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(145, 789); this.buttonRight.Location = new System.Drawing.Point(145, 863);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(34, 40); this.buttonRight.Size = new System.Drawing.Size(34, 40);
@ -209,7 +233,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(63, 789); this.buttonLeft.Location = new System.Drawing.Point(63, 863);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(34, 40); this.buttonLeft.Size = new System.Drawing.Size(34, 40);
@ -222,7 +246,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowUp; this.buttonUp.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(104, 741); this.buttonUp.Location = new System.Drawing.Point(104, 815);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(34, 40); this.buttonUp.Size = new System.Drawing.Size(34, 40);
@ -232,7 +256,7 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 700); this.buttonShowOnMap.Location = new System.Drawing.Point(20, 760);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47); this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
@ -243,7 +267,7 @@
// //
// buttonAddCar // buttonAddCar
// //
this.buttonAddCar.Location = new System.Drawing.Point(21, 443); this.buttonAddCar.Location = new System.Drawing.Point(20, 503);
this.buttonAddCar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddCar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddCar.Name = "buttonAddCar"; this.buttonAddCar.Name = "buttonAddCar";
this.buttonAddCar.Size = new System.Drawing.Size(200, 47); this.buttonAddCar.Size = new System.Drawing.Size(200, 47);
@ -258,7 +282,7 @@
this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Location = new System.Drawing.Point(0, 28);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(927, 856); this.pictureBox.Size = new System.Drawing.Size(927, 930);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -284,14 +308,14 @@
// SaveToolStripMenuItem // SaveToolStripMenuItem
// //
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.SaveToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
this.SaveToolStripMenuItem.Text = "Сохранение"; this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
// //
// LoadToolStripMenuItem // LoadToolStripMenuItem
// //
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.LoadToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
this.LoadToolStripMenuItem.Text = "Загрузка"; this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
// //
@ -307,7 +331,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1160, 884); this.ClientSize = new System.Drawing.Size(1160, 958);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);
@ -351,5 +375,7 @@
private ToolStripMenuItem LoadToolStripMenuItem; private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog; private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog; private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
} }
} }

View File

@ -52,6 +52,10 @@ namespace Stormtrooper
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddStorm_Click(object sender, EventArgs e) private void ButtonAddStorm_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
var formStormConfig = new FormStormtrooperConfig(); var formStormConfig = new FormStormtrooperConfig();
formStormConfig.AddEvent(AddStormtrooper); formStormConfig.AddEvent(AddStormtrooper);
formStormConfig.Show(); formStormConfig.Show();
@ -75,6 +79,11 @@ namespace Stormtrooper
MessageBox.Show($"Не удалось добавить объект: {ex.Message}"); MessageBox.Show($"Не удалось добавить объект: {ex.Message}");
_logger.LogWarning($"Ошибка добавления объекта: {ex.Message}"); _logger.LogWarning($"Ошибка добавления объекта: {ex.Message}");
} }
catch (ArgumentException ex)
{
MessageBox.Show($"Ошибка добавления объекта: {ex.Message}");
_logger.LogWarning($"Ошибка добавления объекта: {ex.Message}");
}
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
@ -276,5 +285,33 @@ namespace Stormtrooper
} }
} }
} }
/// <summary>
/// Сортировка по типу
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new StormtrooperCompareByType());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Сортировка по цвету
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByColor_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].Sort(new StormtrooperCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
} }
} }

View File

@ -13,7 +13,7 @@ namespace Stormtrooper
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam> /// <typeparam name="U"></typeparam>
internal class MapWithSetStormtroopersGeneric<T, U> internal class MapWithSetStormtroopersGeneric<T, U>
where T : class, IDrawningObject where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap where U : AbstractMap
{ {
/// <summary> /// <summary>
@ -204,5 +204,13 @@ namespace Stormtrooper
} }
} }
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T> comparer)
{
_setStormtroopers.SortSet(comparer);
}
} }
} }

View File

@ -49,9 +49,9 @@ namespace Stormtrooper
/// <returns></returns> /// <returns></returns>
public int Insert(T stormtrooper, int position) public int Insert(T stormtrooper, int position)
{ {
if (_places.Contains(stormtrooper)) foreach (var tec_storm in _places)
{ {
throw new ArgumentException("Такой самолёт уже есть"); if ((tec_storm as DrawningObjectStorm).Equals(stormtrooper as DrawningObjectStorm)) throw new ArgumentException("Такой самолёт уже есть");
} }
if (position < 0 || position >= _maxCount) if (position < 0 || position >= _maxCount)
throw new StorageOverflowException(_maxCount); throw new StorageOverflowException(_maxCount);