Compare commits

..

No commits in common. "2a53b2840c71ff0dc766373f7a05c7c481f016c1" and "19b93bd2ee6655184bdb8f6346bd96807a03c6b7" have entirely different histories.

5 changed files with 128 additions and 352 deletions

View File

@ -31,12 +31,6 @@ namespace WinFormsApp1
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
@ -46,15 +40,14 @@ namespace WinFormsApp1
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveTraktor = new System.Windows.Forms.Button(); this.buttonRemoveTraktor = new System.Windows.Forms.Button();
this.buttonAddTraktor = new System.Windows.Forms.Button(); this.buttonAddTraktor = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.buttonRight); this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonDown); this.groupBox1.Controls.Add(this.buttonDown);
this.groupBox1.Controls.Add(this.buttonLeft); this.groupBox1.Controls.Add(this.buttonLeft);
@ -64,138 +57,68 @@ namespace WinFormsApp1
this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonRemoveTraktor); this.groupBox1.Controls.Add(this.buttonRemoveTraktor);
this.groupBox1.Controls.Add(this.buttonAddTraktor); this.groupBox1.Controls.Add(this.buttonAddTraktor);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(596, 0); this.groupBox1.Location = new System.Drawing.Point(832, 0);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); this.groupBox1.Size = new System.Drawing.Size(250, 518);
this.groupBox1.Size = new System.Drawing.Size(219, 476);
this.groupBox1.TabIndex = 0; this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты"; this.groupBox1.Text = "Инструменты";
// //
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(7, 20);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(200, 244);
this.groupBoxMaps.TabIndex = 2;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15;
this.listBoxMaps.Location = new System.Drawing.Point(6, 109);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(188, 94);
this.listBoxMaps.TabIndex = 4;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 215);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(188, 23);
this.buttonDeleteMap.TabIndex = 3;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 80);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(188, 23);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = " Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(188, 23);
this.textBoxNewMapName.TabIndex = 1;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Поле"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 52);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(126, 435);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(35, 30);
this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(91, 435);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(35, 30);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(56, 435);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(35, 30);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp // buttonUp
// //
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::Tractors.Properties.Resources._2EdzyM4iEKw; this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(91, 405); this.buttonUp.Location = new System.Drawing.Point(55, 426);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(35, 30); this.buttonUp.Size = new System.Drawing.Size(40, 40);
this.buttonUp.TabIndex = 7; this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(15, 466);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(55, 466);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(40, 40);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(95, 466);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(40, 40);
this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 380); this.buttonShowOnMap.Location = new System.Drawing.Point(6, 281);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(207, 22); this.buttonShowOnMap.Size = new System.Drawing.Size(193, 29);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -203,10 +126,9 @@ namespace WinFormsApp1
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(7, 353); this.buttonShowStorage.Location = new System.Drawing.Point(6, 246);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(207, 22); this.buttonShowStorage.Size = new System.Drawing.Size(193, 29);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -214,18 +136,16 @@ namespace WinFormsApp1
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 298); this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 122);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(207, 23); this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27);
this.maskedTextBoxPosition.TabIndex = 11; this.maskedTextBoxPosition.TabIndex = 11;
// //
// buttonRemoveTraktor // buttonRemoveTraktor
// //
this.buttonRemoveTraktor.Location = new System.Drawing.Point(7, 325); this.buttonRemoveTraktor.Location = new System.Drawing.Point(6, 155);
this.buttonRemoveTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRemoveTraktor.Name = "buttonRemoveTraktor"; this.buttonRemoveTraktor.Name = "buttonRemoveTraktor";
this.buttonRemoveTraktor.Size = new System.Drawing.Size(207, 24); this.buttonRemoveTraktor.Size = new System.Drawing.Size(151, 32);
this.buttonRemoveTraktor.TabIndex = 2; this.buttonRemoveTraktor.TabIndex = 2;
this.buttonRemoveTraktor.Text = "Удалить трактор"; this.buttonRemoveTraktor.Text = "Удалить трактор";
this.buttonRemoveTraktor.UseVisualStyleBackColor = true; this.buttonRemoveTraktor.UseVisualStyleBackColor = true;
@ -233,39 +153,46 @@ namespace WinFormsApp1
// //
// buttonAddTraktor // buttonAddTraktor
// //
this.buttonAddTraktor.Location = new System.Drawing.Point(7, 269); this.buttonAddTraktor.Location = new System.Drawing.Point(6, 83);
this.buttonAddTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAddTraktor.Name = "buttonAddTraktor"; this.buttonAddTraktor.Name = "buttonAddTraktor";
this.buttonAddTraktor.Size = new System.Drawing.Size(207, 25); this.buttonAddTraktor.Size = new System.Drawing.Size(151, 33);
this.buttonAddTraktor.TabIndex = 1; this.buttonAddTraktor.TabIndex = 1;
this.buttonAddTraktor.Text = "Добавить трактор"; this.buttonAddTraktor.Text = "Добавить трактор";
this.buttonAddTraktor.UseVisualStyleBackColor = true; this.buttonAddTraktor.UseVisualStyleBackColor = true;
this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click); this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click);
// //
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Поле"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(596, 476); this.pictureBox.Size = new System.Drawing.Size(832, 518);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// FormMapWithSetTraktor // FormMapWithSetTraktor
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); 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(815, 476); this.ClientSize = new System.Drawing.Size(1082, 518);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormMapWithSetTraktor"; this.Name = "FormMapWithSetTraktor";
this.Text = "Автобус"; this.Text = "Трактор";
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -285,10 +212,5 @@ namespace WinFormsApp1
private Button buttonDown; private Button buttonDown;
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private GroupBox groupBoxMaps;
private Button buttonDeleteMap;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
private ListBox listBoxMaps;
} }
} }

View File

@ -15,46 +15,17 @@ namespace WinFormsApp1
{ {
private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric; private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapsDict = new() //DrawingBus SelectedBus { get; private set; }
{
{"Простая карта", new SimpleMap() },
{"Поле", new FieldMap() }
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetTraktor() public FormMapWithSetTraktor()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); AbstractMap map = new SimpleMap();
comboBoxSelectorMap.Items.Clear(); _mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(
foreach (var item in _mapsDict) pictureBox.Width, pictureBox.Height, map);
{
comboBoxSelectorMap.Items.Add(item.Key);
}
} }
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{ {
AbstractMap map = null; AbstractMap map = null;
@ -81,7 +52,7 @@ namespace WinFormsApp1
private void ButtonAddTraktor_Click(object sender, EventArgs e) private void ButtonAddTraktor_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1) if (_mapTraktorCollectionGeneric == null)
{ {
return; return;
} }
@ -96,10 +67,10 @@ namespace WinFormsApp1
DrawningObjectTractor bus = new(form.SelectedTractor); DrawningObjectTractor bus = new(form.SelectedTractor);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1) if (_mapTraktorCollectionGeneric + bus != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet();
} }
else else
{ {
@ -110,29 +81,21 @@ namespace WinFormsApp1
private void ButtonRemoveTraktor_Click(object sender, EventArgs e) private void ButtonRemoveTraktor_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
} }
if (MessageBox.Show("Удалить объект?", "Удаление", if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{ {
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) if (_mapTraktorCollectionGeneric - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
@ -145,7 +108,7 @@ namespace WinFormsApp1
{ {
return; return;
} }
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet();
} }
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
@ -154,7 +117,7 @@ namespace WinFormsApp1
{ {
return; return;
} }
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); pictureBox.Image = _mapTraktorCollectionGeneric.ShowOnMap();
} }
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
@ -183,40 +146,5 @@ namespace WinFormsApp1
} }
pictureBox.Image = _mapTraktorCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapTraktorCollectionGeneric.MoveObject(dir);
} }
private void buttonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
} }
} }

View File

@ -50,9 +50,13 @@ namespace WinFormsApp1
public Bitmap ShowOnMap() public Bitmap ShowOnMap()
{ {
Shaking(); Shaking();
foreach (var traktor in _setTraktors.GetTraktor()) for (int i = 0; i < _setTraktors.Count; i++)
{ {
return _map.CreateMap(_pictureWidth, _pictureHeight, traktor); var bus = _setTraktors.Get(i);
if (bus != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
}
} }
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
} }
@ -71,11 +75,11 @@ namespace WinFormsApp1
int j = _setTraktors.Count - 1; int j = _setTraktors.Count - 1;
for (int i = 0; i < _setTraktors.Count; i++) for (int i = 0; i < _setTraktors.Count; i++)
{ {
if (_setTraktors[i] == null) if (_setTraktors.Get(i) == null)
{ {
for (; j > i; j--) for (; j > i; j--)
{ {
var bus = _setTraktors[j]; var bus = _setTraktors.Get(j);
if (bus != null) if (bus != null)
{ {
_setTraktors.Insert(bus, i); _setTraktors.Insert(bus, i);
@ -109,31 +113,31 @@ namespace WinFormsApp1
private void DrawTraktors(Graphics g) private void DrawTraktors(Graphics g)
{ {
int widthEl = _pictureWidth / _placeSizeWidth;
int heightEl = _pictureHeight / _placeSizeHeight;
int curWidth = 0;
int curHeight = 0;
for (int i = _setTraktors.Count; i >= 0; i--)
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
foreach (var traktor in _setTraktors.GetTraktor())
{ {
traktor?.SetObject( _setTraktors.Get(i)?.SetObject(
currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); _pictureWidth - _placeSizeWidth * curWidth - 60,
traktor?.DrawningObject(g); curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight);
_setTraktors.Get(i)?.DrawningObject(g);
if (currentWidth > 0) if (curWidth < widthEl)
{ curWidth++;
currentWidth -= 1;
}
else else
{ {
if (currentHeight > 0) curWidth = 1;
curHeight++;
}
if (curHeight > heightEl)
{ {
currentHeight -= 1; return;
currentWidth = _pictureWidth / _placeSizeWidth - 1;
}
else return;
} }
} }
} }
} }

View File

@ -1,53 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsApp1
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
else
{
_mapStorages.Add(name, new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name))
{
_mapStorages.Remove(name);
}
}
public MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> this[string ind]
{
get
{
_mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric);
return MapWithSetDoubleDeckerBusGeneric;
}
}
}
}

View File

@ -9,15 +9,13 @@ namespace WinFormsApp1
internal class SetTraktorGeneric<T> internal class SetTraktorGeneric<T>
where T : class where T : class
{ {
private readonly List<T> _places; private readonly T[] _places;
public int Count => _places.Count; public int Count => _places.Length;
private readonly int _maxCount;
private int TractorPlaces = 0; private int TractorPlaces = 0;
public SetTraktorGeneric(int count) public SetTraktorGeneric(int count)
{ {
_maxCount = count; _places = new T[count];
_places = new List<T>(); ;
} }
public int Insert(T tractor) public int Insert(T tractor)
@ -27,61 +25,38 @@ namespace WinFormsApp1
public int Insert(T tractor, int position) public int Insert(T tractor, int position)
{ {
if (position < 0 && position > _maxCount) if (position < 0 || position >= _places.Length || TractorPlaces == _places.Length)
{ {
return -1; return -1;
} }
else TractorPlaces++;
while (_places[position] != null)
{ {
_places.Insert(position, tractor); for (int i = _places.Length - 1; i > 0; --i)
return position; {
if (_places[i] == null && _places[i - 1] != null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
} }
} }
}
_places[position] = tractor;
return position;
}
public T Remove(int position) public T Remove(int position)
{ {
if (position < 0 || position >= _maxCount) if (position < 0 || position >= _places.Length) return null;
{ T savedTractor = _places[position];
return null; _places[position] = null;
} return savedTractor;
var result = _places[position];
_places.RemoveAt(position);
return result;
} }
public T Get(int position)
public T this[int position]
{
get
{
if (position >= 0 && position < _maxCount && position < Count)
{ {
if (position < 0 || position >= _places.Length) return null;
return _places[position]; return _places[position];
} }
else
{
return null;
}
}
set
{
Insert(value, position);
}
}
public IEnumerable<T> GetTraktor()
{
foreach (var traktor in _places)
{
if (traktor != null)
{
yield return traktor;
}
else
{
yield break;
}
}
}
} }
} }