diff --git a/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.Designer.cs b/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.Designer.cs index 554be16..5c24eb2 100644 --- a/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.Designer.cs +++ b/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.Designer.cs @@ -47,6 +47,76 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // + // groupBoxMaps + // + this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); + this.groupBoxMaps.Controls.Add(this.listBoxMaps); + this.groupBoxMaps.Controls.Add(this.buttonAddMap); + this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); + this.groupBoxMaps.Location = new System.Drawing.Point(13, 28); + this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxMaps.Name = "groupBoxMaps"; + this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxMaps.Size = new System.Drawing.Size(229, 326); + this.groupBoxMaps.TabIndex = 11; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Карты"; + // + // buttonDeleteMap + // + this.buttonDeleteMap.Location = new System.Drawing.Point(7, 271); + this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(200, 47); + this.buttonDeleteMap.TabIndex = 5; + this.buttonDeleteMap.Text = "Удалить карту"; + this.buttonDeleteMap.UseVisualStyleBackColor = true; + this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click); + // + // listBoxMaps + // + this.listBoxMaps.FormattingEnabled = true; + this.listBoxMaps.ItemHeight = 20; + this.listBoxMaps.Location = new System.Drawing.Point(7, 157); + this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(199, 104); + this.listBoxMaps.TabIndex = 4; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(7, 107); + this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(200, 43); + this.buttonAddMap.TabIndex = 3; + this.buttonAddMap.Text = "Добавить карту"; + this.buttonAddMap.UseVisualStyleBackColor = true; + this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click_1); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Моя вторая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 68); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(200, 28); + this.comboBoxSelectorMap.TabIndex = 0; + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(7, 29); + this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(200, 27); + this.textBoxNewMapName.TabIndex = 0; + // // groupBoxTools // this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); diff --git a/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs index 58dc09c..b88cb93 100644 --- a/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs @@ -12,37 +12,109 @@ namespace HoistingCrane { public partial class FormMapWithSetHoistingCrane : Form { - - private MapWithSetHoistingCraneGeneric _mapHoistingCraneCollectionGeneric; - - public FormMapWithSetHoistingCrane() + /// Словарь для выпадающего списка + /// + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap() }, + { "Вторая карта", new SecondMap() }, + }; + /// + /// Объект от коллекции карт + /// + /// Логер + /// + private readonly ILogger _logger; + /// + private readonly MapsCollection _mapsCollection; + /// + public FormMapWithSetHoistingCrane(ILogger logger) { InitializeComponent(); } + 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) { AbstractMap map = null; switch (comboBoxSelectorMap.Text) { - case "Первая карта": + case "Простая карта": map = new SimpleMap(); break; case "Вторая карта": map = new SecondMap(); - break; + break; + } if (map != null) { _mapHoistingCraneCollectionGeneric = new MapWithSetHoistingCraneGeneric( - pictureBox.Width, pictureBox.Height, map); + pictureBox.Width, pictureBox.Height, map); } else { _mapHoistingCraneCollectionGeneric = null; } } - + /// + /// Добавление карты + /// + /// + /// + private void buttonAddMap_Click_1(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(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); + } + private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Переход на карту {listBoxMaps.SelectedItem?.ToString()}"); + } + /// + /// Удаление карты + /// + /// + /// + 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(); + _logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem?.ToString()}"); + } + } private void ButtonAddHoistingCrane_Click(object sender, EventArgs e) { if (_mapHoistingCraneCollectionGeneric == null) @@ -130,7 +202,7 @@ namespace HoistingCrane enums = Direction.Right; break; } - pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(enums); } private void pictureBox_Click(object sender, EventArgs e)