Compare commits

..

3 Commits

5 changed files with 379 additions and 155 deletions

View File

@ -31,6 +31,12 @@ 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();
@ -40,14 +46,15 @@ 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);
@ -57,109 +64,66 @@ 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(832, 0); this.groupBox1.Location = new System.Drawing.Point(596, 0);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(250, 518); this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
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 = "Инструменты";
// //
// buttonUp // groupBoxMaps
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw; this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.buttonUp.Location = new System.Drawing.Point(55, 426); this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.buttonUp.Name = "buttonUp"; this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.buttonUp.Size = new System.Drawing.Size(40, 40); this.groupBoxMaps.Location = new System.Drawing.Point(7, 20);
this.buttonUp.TabIndex = 7; this.groupBoxMaps.Name = "groupBoxMaps";
this.buttonUp.UseVisualStyleBackColor = true; this.groupBoxMaps.Size = new System.Drawing.Size(200, 244);
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); this.groupBoxMaps.TabIndex = 2;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
// //
// buttonLeft // listBoxMaps
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.listBoxMaps.FormattingEnabled = true;
this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g; this.listBoxMaps.ItemHeight = 15;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.listBoxMaps.Location = new System.Drawing.Point(6, 109);
this.buttonLeft.Location = new System.Drawing.Point(15, 466); this.listBoxMaps.Name = "listBoxMaps";
this.buttonLeft.Name = "buttonLeft"; this.listBoxMaps.Size = new System.Drawing.Size(188, 94);
this.buttonLeft.Size = new System.Drawing.Size(40, 40); this.listBoxMaps.TabIndex = 4;
this.buttonLeft.TabIndex = 8; this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonDown // buttonDeleteMap
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDeleteMap.Location = new System.Drawing.Point(6, 215);
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM; this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDeleteMap.Size = new System.Drawing.Size(188, 23);
this.buttonDown.Location = new System.Drawing.Point(55, 466); this.buttonDeleteMap.TabIndex = 3;
this.buttonDown.Name = "buttonDown"; this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDown.Size = new System.Drawing.Size(40, 40); this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDown.TabIndex = 9; this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonRight // buttonAddMap
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonAddMap.Location = new System.Drawing.Point(6, 80);
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ; this.buttonAddMap.Name = "buttonAddMap";
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonAddMap.Size = new System.Drawing.Size(188, 23);
this.buttonRight.Location = new System.Drawing.Point(95, 466); this.buttonAddMap.TabIndex = 2;
this.buttonRight.Name = "buttonRight"; this.buttonAddMap.Text = " Добавить карту";
this.buttonRight.Size = new System.Drawing.Size(40, 40); this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonRight.TabIndex = 10; this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonShowOnMap // textBoxNewMapName
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(6, 281); this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.textBoxNewMapName.Name = "textBoxNewMapName";
this.buttonShowOnMap.Size = new System.Drawing.Size(193, 29); this.textBoxNewMapName.Size = new System.Drawing.Size(188, 23);
this.buttonShowOnMap.TabIndex = 5; this.textBoxNewMapName.TabIndex = 1;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(6, 246);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(193, 29);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 122);
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27);
this.maskedTextBoxPosition.TabIndex = 11;
//
// buttonRemoveTraktor
//
this.buttonRemoveTraktor.Location = new System.Drawing.Point(6, 155);
this.buttonRemoveTraktor.Name = "buttonRemoveTraktor";
this.buttonRemoveTraktor.Size = new System.Drawing.Size(151, 32);
this.buttonRemoveTraktor.TabIndex = 2;
this.buttonRemoveTraktor.Text = "Удалить трактор";
this.buttonRemoveTraktor.UseVisualStyleBackColor = true;
this.buttonRemoveTraktor.Click += new System.EventHandler(this.ButtonRemoveTraktor_Click);
//
// buttonAddTraktor
//
this.buttonAddTraktor.Location = new System.Drawing.Point(6, 83);
this.buttonAddTraktor.Name = "buttonAddTraktor";
this.buttonAddTraktor.Size = new System.Drawing.Size(151, 33);
this.buttonAddTraktor.TabIndex = 1;
this.buttonAddTraktor.Text = "Добавить трактор";
this.buttonAddTraktor.UseVisualStyleBackColor = true;
this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click);
// //
// comboBoxSelectorMap // comboBoxSelectorMap
// //
@ -167,32 +131,141 @@ namespace WinFormsApp1
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта", "Простая карта",
"Поле"}); "Поле"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26); 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.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
this.comboBoxSelectorMap.TabIndex = 0; this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); 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
//
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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(91, 405);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(35, 30);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 380);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(207, 22);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(7, 353);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(207, 22);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 298);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(207, 23);
this.maskedTextBoxPosition.TabIndex = 11;
//
// buttonRemoveTraktor
//
this.buttonRemoveTraktor.Location = new System.Drawing.Point(7, 325);
this.buttonRemoveTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRemoveTraktor.Name = "buttonRemoveTraktor";
this.buttonRemoveTraktor.Size = new System.Drawing.Size(207, 24);
this.buttonRemoveTraktor.TabIndex = 2;
this.buttonRemoveTraktor.Text = "Удалить трактор";
this.buttonRemoveTraktor.UseVisualStyleBackColor = true;
this.buttonRemoveTraktor.Click += new System.EventHandler(this.ButtonRemoveTraktor_Click);
//
// buttonAddTraktor
//
this.buttonAddTraktor.Location = new System.Drawing.Point(7, 269);
this.buttonAddTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAddTraktor.Name = "buttonAddTraktor";
this.buttonAddTraktor.Size = new System.Drawing.Size(207, 25);
this.buttonAddTraktor.TabIndex = 1;
this.buttonAddTraktor.Text = "Добавить трактор";
this.buttonAddTraktor.UseVisualStyleBackColor = true;
this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click);
//
// 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(832, 518); this.pictureBox.Size = new System.Drawing.Size(596, 476);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// FormMapWithSetTraktor // FormMapWithSetTraktor
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1082, 518); this.ClientSize = new System.Drawing.Size(815, 476);
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);
@ -212,5 +285,10 @@ 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,17 +15,46 @@ namespace WinFormsApp1
{ {
private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric; private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric;
//DrawingBus SelectedBus { get; private set; } private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{"Простая карта", new SimpleMap() },
{"Поле", new FieldMap() }
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetTraktor() public FormMapWithSetTraktor()
{ {
InitializeComponent(); InitializeComponent();
AbstractMap map = new SimpleMap(); _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
_mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>( comboBoxSelectorMap.Items.Clear();
pictureBox.Width, pictureBox.Height, map); foreach (var item in _mapsDict)
{
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;
@ -52,7 +81,7 @@ namespace WinFormsApp1
private void ButtonAddTraktor_Click(object sender, EventArgs e) private void ButtonAddTraktor_Click(object sender, EventArgs e)
{ {
if (_mapTraktorCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -67,10 +96,10 @@ namespace WinFormsApp1
DrawningObjectTractor bus = new(form.SelectedTractor); DrawningObjectTractor bus = new(form.SelectedTractor);
if (_mapTraktorCollectionGeneric + bus != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -81,21 +110,29 @@ 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 (_mapTraktorCollectionGeneric - pos != null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
@ -108,7 +145,7 @@ namespace WinFormsApp1
{ {
return; return;
} }
pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
@ -117,7 +154,7 @@ namespace WinFormsApp1
{ {
return; return;
} }
pictureBox.Image = _mapTraktorCollectionGeneric.ShowOnMap(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
@ -146,5 +183,40 @@ 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,13 +50,9 @@ namespace WinFormsApp1
public Bitmap ShowOnMap() public Bitmap ShowOnMap()
{ {
Shaking(); Shaking();
for (int i = 0; i < _setTraktors.Count; i++) foreach (var traktor in _setTraktors.GetTraktor())
{ {
var bus = _setTraktors.Get(i); return _map.CreateMap(_pictureWidth, _pictureHeight, traktor);
if (bus != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
}
} }
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
} }
@ -75,11 +71,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.Get(i) == null) if (_setTraktors[i] == null)
{ {
for (; j > i; j--) for (; j > i; j--)
{ {
var bus = _setTraktors.Get(j); var bus = _setTraktors[j];
if (bus != null) if (bus != null)
{ {
_setTraktors.Insert(bus, i); _setTraktors.Insert(bus, i);
@ -113,31 +109,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())
{ {
_setTraktors.Get(i)?.SetObject( traktor?.SetObject(
_pictureWidth - _placeSizeWidth * curWidth - 60, currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight); traktor?.DrawningObject(g);
_setTraktors.Get(i)?.DrawningObject(g);
if (curWidth < widthEl) if (currentWidth > 0)
curWidth++; {
currentWidth -= 1;
}
else else
{ {
curWidth = 1; if (currentHeight > 0)
curHeight++; {
currentHeight -= 1;
currentWidth = _pictureWidth / _placeSizeWidth - 1;
}
else return;
} }
if (curHeight > heightEl)
{
return;
}
} }
} }
} }

View File

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