diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs index df0f2ea..21eb0cf 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs @@ -132,7 +132,7 @@ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(176, 23); this.comboBoxSelectorMap.TabIndex = 0; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + //this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // // maskedTextBoxPosition // diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index 3992e60..ee6dcad 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -8,15 +8,14 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WarmlyShip; +using static System.Windows.Forms.DataFormats; namespace WarmlyShip { public partial class FormMapWithSetShip : Form { - private MapWithSetShipGeneric _mapShipCollectionGeneric; - public bool ShipOnMap = false; - - private readonly Dictionary _mapsDict = new() { + private readonly Dictionary _mapsDict = new() + { { "Простая карта", new SimpleMap() }, { "Вторая карта", new SecondMap() }, { "Последняя карта", new LastMap() } @@ -33,7 +32,6 @@ namespace WarmlyShip { comboBoxSelectorMap.Items.Add(elem.Key); } - } private void ReloadMaps() @@ -54,25 +52,6 @@ namespace WarmlyShip } } - 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(); - } - } - private void ButtonAddMap_Click(object sender, EventArgs e) { if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) @@ -89,31 +68,25 @@ namespace WarmlyShip ReloadMaps(); } - - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + + private void ButtonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) { - case "Простая карта": - map = new SimpleMap(); - break; - case "Вторая карта": - map = new SecondMap(); - break; - case "Последняя карта": - map = new LastMap(); - break; + return; } - if (map != null) + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapShipCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapShipCollectionGeneric = null; + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? + string.Empty); + ReloadMaps(); } } + private void ButtonAddShip_Click(object sender, EventArgs e) { if (listBoxMaps.SelectedIndex == -1) @@ -124,10 +97,10 @@ namespace WarmlyShip if (form.ShowDialog() == DialogResult.OK) { DrawningObjectShip ship = new(form.SelectedShip); - if (_mapShipCollectionGeneric + ship == 1) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + ship == 1) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -154,13 +127,13 @@ namespace WarmlyShip if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos == 1) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { MessageBox.Show("Не удалось удалить объект"); } - } private void ButtonShowStorage_Click(object sender, EventArgs e) diff --git a/WarmlyShip/WarmlyShip/MapsCollection.cs b/WarmlyShip/WarmlyShip/MapsCollection.cs index c1e4535..5e82195 100644 --- a/WarmlyShip/WarmlyShip/MapsCollection.cs +++ b/WarmlyShip/WarmlyShip/MapsCollection.cs @@ -24,21 +24,15 @@ namespace WarmlyShip _pictureHeight = pictureHeight; } - private bool inDir(string name) - { - foreach(var key in Keys) - if (key == name) return true; - return false; - } - public void AddMap(string name, AbstractMap map) { - if (inDir(name)) return; + if (_mapStorages.ContainsKey(name)) return; _mapStorages.Add(name, new MapWithSetShipGeneric(_pictureWidth, _pictureHeight, map)); } + public void DelMap(string name) { - if (!inDir(name)) return; + if (_mapStorages.ContainsKey(name)) return; _mapStorages.Remove(name); } @@ -46,10 +40,7 @@ namespace WarmlyShip { get { - foreach (var map in _mapStorages) - { - if(map.Key == ind) return map.Value; - } + if(_mapStorages.ContainsKey(ind)) return _mapStorages[ind]; return null; } }