diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs index 1136dd0..2f8b278 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs @@ -38,9 +38,15 @@ this.buttonRemoveAirplane = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddAirplane = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.ButtonDeleteMap = new System.Windows.Forms.Button(); + this.ListBoxMaps = new System.Windows.Forms.ListBox(); + this.ButtonAddMap = new System.Windows.Forms.Button(); + this.textBoxNewMapName = new System.Windows.Forms.TextBox(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBox.SuspendLayout(); + this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // @@ -55,13 +61,13 @@ this.groupBox.Controls.Add(this.buttonRemoveAirplane); this.groupBox.Controls.Add(this.maskedTextBoxPosition); this.groupBox.Controls.Add(this.buttonAddAirplane); - this.groupBox.Controls.Add(this.comboBoxSelectorMap); + this.groupBox.Controls.Add(this.groupBox1); this.groupBox.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox.Location = new System.Drawing.Point(685, 0); this.groupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBox.Name = "groupBox"; this.groupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupBox.Size = new System.Drawing.Size(229, 600); + this.groupBox.Size = new System.Drawing.Size(229, 653); this.groupBox.TabIndex = 0; this.groupBox.TabStop = false; this.groupBox.Text = "Инструменты"; @@ -71,7 +77,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(99, 537); + this.buttonDown.Location = new System.Drawing.Point(98, 605); this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(34, 40); @@ -84,7 +90,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(141, 537); + this.buttonRight.Location = new System.Drawing.Point(140, 605); this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(34, 40); @@ -97,7 +103,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(58, 537); + this.buttonLeft.Location = new System.Drawing.Point(57, 605); this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(34, 40); @@ -110,7 +116,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(99, 489); + this.buttonUp.Location = new System.Drawing.Point(98, 557); this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(34, 40); @@ -121,7 +127,7 @@ // buttonShowOnMap // this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonShowOnMap.Location = new System.Drawing.Point(22, 416); + this.buttonShowOnMap.Location = new System.Drawing.Point(22, 509); this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(193, 40); @@ -133,7 +139,7 @@ // buttonShowStorage // this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonShowStorage.Location = new System.Drawing.Point(22, 311); + this.buttonShowStorage.Location = new System.Drawing.Point(22, 461); this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(193, 40); @@ -145,7 +151,7 @@ // buttonRemoveAirplane // this.buttonRemoveAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRemoveAirplane.Location = new System.Drawing.Point(22, 228); + this.buttonRemoveAirplane.Location = new System.Drawing.Point(22, 413); this.buttonRemoveAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemoveAirplane.Name = "buttonRemoveAirplane"; this.buttonRemoveAirplane.Size = new System.Drawing.Size(193, 40); @@ -157,7 +163,7 @@ // maskedTextBoxPosition // this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 189); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 378); this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; @@ -167,7 +173,7 @@ // buttonAddAirplane // this.buttonAddAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAddAirplane.Location = new System.Drawing.Point(22, 120); + this.buttonAddAirplane.Location = new System.Drawing.Point(22, 330); this.buttonAddAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddAirplane.Name = "buttonAddAirplane"; this.buttonAddAirplane.Size = new System.Drawing.Size(193, 40); @@ -176,20 +182,69 @@ this.buttonAddAirplane.UseVisualStyleBackColor = true; this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click); // + // groupBox1 + // + this.groupBox1.Controls.Add(this.ButtonDeleteMap); + this.groupBox1.Controls.Add(this.ListBoxMaps); + this.groupBox1.Controls.Add(this.ButtonAddMap); + this.groupBox1.Controls.Add(this.textBoxNewMapName); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + this.groupBox1.Location = new System.Drawing.Point(6, 26); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(250, 300); + this.groupBox1.TabIndex = 18; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Карты"; + // + // ButtonDeleteMap + // + this.ButtonDeleteMap.Location = new System.Drawing.Point(10, 255); + this.ButtonDeleteMap.Name = "ButtonDeleteMap"; + this.ButtonDeleteMap.Size = new System.Drawing.Size(207, 29); + this.ButtonDeleteMap.TabIndex = 13; + 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(10, 136); + this.ListBoxMaps.Name = "ListBoxMaps"; + this.ListBoxMaps.Size = new System.Drawing.Size(207, 104); + this.ListBoxMaps.TabIndex = 12; + this.ListBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // ButtonAddMap + // + this.ButtonAddMap.Location = new System.Drawing.Point(10, 101); + this.ButtonAddMap.Name = "ButtonAddMap"; + this.ButtonAddMap.Size = new System.Drawing.Size(207, 29); + this.ButtonAddMap.TabIndex = 11; + this.ButtonAddMap.Text = "Добавить карту"; + this.ButtonAddMap.UseVisualStyleBackColor = true; + this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click); + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(10, 34); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(207, 27); + this.textBoxNewMapName.TabIndex = 10; + // // comboBoxSelectorMap // - this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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(22, 44); - this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(10, 67); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(193, 28); - this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(207, 28); + this.comboBoxSelectorMap.TabIndex = 9; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // // pictureBox @@ -198,7 +253,7 @@ this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(685, 600); + this.pictureBox.Size = new System.Drawing.Size(685, 653); this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; @@ -207,7 +262,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(914, 600); + this.ClientSize = new System.Drawing.Size(914, 653); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); @@ -215,6 +270,8 @@ this.Text = "FormMapWithSetAirplane"; this.groupBox.ResumeLayout(false); this.groupBox.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -235,5 +292,10 @@ private Button buttonAddAirplane; private ComboBox comboBoxSelectorMap; private PictureBox pictureBox; + private GroupBox groupBox1; + private Button ButtonDeleteMap; + private ListBox ListBoxMaps; + private Button ButtonAddMap; + private TextBox textBoxNewMapName; } } \ No newline at end of file diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs index b5eba7a..5256dda 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs @@ -17,9 +17,41 @@ namespace AirplaneWithRadar /// Объект от класса карты с набором объектов /// private MapWithSetAirplaneGeneric _mapAirplaneCollectionGeneric; + private readonly Dictionary _mapDict = new() + { + {"Простая карта", new SimpleMap() }, + {"Карта неба с облаками", new SkyMap() }, + {"Карта туманного неба с грозой", new FoggySkyMap() } + }; + private readonly MapsCollection _mapsCollection; public FormMapWithSetAirplane() { InitializeComponent(); + _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); + comboBoxSelectorMap.Items.Clear(); + foreach (var elem in _mapDict) + { + comboBoxSelectorMap.Items.Add(elem.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; + } } /// /// Выбор карты @@ -58,7 +90,7 @@ namespace AirplaneWithRadar /// private void ButtonAddAirplane_Click(object sender, EventArgs e) { - if (_mapAirplaneCollectionGeneric == null) + if (ListBoxMaps.SelectedIndex == -1) { return; } @@ -66,10 +98,10 @@ namespace AirplaneWithRadar if (form.ShowDialog() == DialogResult.OK) { DrawningObjectAirplane airplane = new(form.SelectedAirplane); - if (_mapAirplaneCollectionGeneric + airplane != -1) + if ((_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -84,6 +116,10 @@ namespace AirplaneWithRadar /// private void ButtonRemoveAirplane_Click(object sender, EventArgs e) { + if (ListBoxMaps.SelectedIndex == -1) + { + return; + } if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; @@ -96,7 +132,7 @@ namespace AirplaneWithRadar if (_mapAirplaneCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -110,11 +146,11 @@ namespace AirplaneWithRadar /// private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapAirplaneCollectionGeneric == null) + if (ListBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// /// Вывод карты @@ -123,11 +159,11 @@ namespace AirplaneWithRadar /// private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapAirplaneCollectionGeneric == null) + if (ListBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapAirplaneCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } /// /// Перемещение @@ -136,7 +172,7 @@ namespace AirplaneWithRadar /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapAirplaneCollectionGeneric == null) + if (ListBoxMaps.SelectedIndex == -1) { return; } @@ -158,7 +194,40 @@ namespace AirplaneWithRadar dir = Direction.Right; break; } - pictureBox.Image = _mapAirplaneCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].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 (!_mapDict.ContainsKey(comboBoxSelectorMap.Text)) + { + MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _mapsCollection.AddMap(textBoxNewMapName.Text, _mapDict[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(); + } } } }