diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs index c6fab16..073c34e 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs @@ -63,6 +63,7 @@ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.SaveMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.groupBoxTools.SuspendLayout(); this.groupBoxMaps.SuspendLayout(); this.groupBoxGenerate.SuspendLayout(); @@ -70,6 +71,7 @@ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericWeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // // comboTypeEngines @@ -100,9 +102,9 @@ this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(811, 0); + this.groupBoxTools.Location = new System.Drawing.Point(811, 24); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(204, 810); + this.groupBoxTools.Size = new System.Drawing.Size(204, 786); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -331,7 +333,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(90, 774); + this.buttonDown.Location = new System.Drawing.Point(90, 750); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 10; @@ -343,7 +345,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(126, 774); + this.buttonRight.Location = new System.Drawing.Point(126, 750); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 9; @@ -355,7 +357,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(54, 774); + this.buttonLeft.Location = new System.Drawing.Point(54, 750); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; @@ -367,7 +369,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(90, 738); + this.buttonUp.Location = new System.Drawing.Point(90, 714); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; @@ -377,9 +379,9 @@ // pictureBox // 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, 24); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(811, 810); + this.pictureBox.Size = new System.Drawing.Size(811, 786); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -396,6 +398,7 @@ // this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.SaveToolStripMenuItem, + this.SaveMapToolStripMenuItem, this.LoadToolStripMenuItem}); this.файлToolStripMenuItem.Name = "файлToolStripMenuItem"; this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20); @@ -404,14 +407,14 @@ // SaveToolStripMenuItem // this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.SaveToolStripMenuItem.Size = new System.Drawing.Size(280, 22); this.SaveToolStripMenuItem.Text = "Сохранение"; this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); // // LoadToolStripMenuItem // this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.LoadToolStripMenuItem.Size = new System.Drawing.Size(280, 22); this.LoadToolStripMenuItem.Text = "Загрузка"; this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); // @@ -423,6 +426,13 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // + // SaveMapToolStripMenuItem + // + this.SaveMapToolStripMenuItem.Name = "SaveMapToolStripMenuItem"; + this.SaveMapToolStripMenuItem.Size = new System.Drawing.Size(280, 22); + this.SaveMapToolStripMenuItem.Text = "Сохранение Выбранного хранилища"; + this.SaveMapToolStripMenuItem.Click += new System.EventHandler(this.SaveMapToolStripMenuItem_Click); + // // FormMapWithSetAirplanes // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -447,6 +457,7 @@ this.menuStrip.ResumeLayout(false); this.menuStrip.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -487,5 +498,6 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private ToolStripMenuItem SaveMapToolStripMenuItem; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index 0fba014..fb182f6 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -304,6 +304,20 @@ namespace AirBomber AddAirplaneInMap(form.SelectedAirplane); } } + /// + /// В зависимости от успешности сохранения показывает разные всплывающие окна + /// + private void ShowStatusSaveFile(bool succesfullSave) + { + if (succesfullSave) + { + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } /// /// Обработка нажатия "Сохранение" @@ -314,14 +328,7 @@ namespace AirBomber { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.SaveData(saveFileDialog.FileName)) - { - MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + ShowStatusSaveFile(_mapsCollection.SaveData(saveFileDialog.FileName)); } } /// @@ -344,5 +351,14 @@ namespace AirBomber } } } + + private void SaveMapToolStripMenuItem_Click(object sender, EventArgs e) + { + saveFileDialog.FileName = NameMap; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + ShowStatusSaveFile(_mapsCollection.SaveMap(saveFileDialog.FileName, NameMap)); + } + } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.resx b/AirBomber/AirBomber/FormMapWithSetAirplanes.resx index f298a7b..1d824c7 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.resx +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.resx @@ -57,4 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 125, 17 + + + 258, 17 + \ No newline at end of file diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index ca33b83..1959822 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -110,6 +110,43 @@ namespace AirBomber } return true; } + + public bool SaveMap(string filename, string nameMap) + { + if (!_mapStorages.ContainsKey(nameMap)) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter fs = new(filename)) + { + fs.Write($"Map{Environment.NewLine}"); + fs.Write($"Name: {nameMap}{Environment.NewLine}"); + fs.Write(_mapStorages[nameMap].GetData(separatorDict, separatorData)); + } + return true; + } + + private bool LoadMap(string nameMapStorage, string nameMap, string lineData) + { + AbstractMap map = null; + switch (nameMap) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "WallMap": + map = new WallMap(); + break; + } + _mapStorages[nameMapStorage] = new(_pictureWidth, _pictureHeight, map); + _mapStorages[nameMapStorage].LoadData(lineData.Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + return true; + } + /// /// Загрузка информации по самолетам в ангарах из файла /// @@ -129,7 +166,13 @@ namespace AirBomber strs.Add(fs.ReadLine()); } } - if (!strs[0].Contains("MapsCollection")) + bool isNotMapsCollection = !strs[0].Contains("MapsCollection"); + if (strs[0].Contains("Map") && isNotMapsCollection) + { + var elem = strs[2].Split(separatorDict); + return LoadMap(strs[1].Replace("Name: ", ""), elem[0], elem[1]); + } + else if (isNotMapsCollection) { //если нет такой записи, то это не те данные return false; @@ -139,20 +182,7 @@ namespace AirBomber for (int i = 1; i < strs.Count; ++i) { var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) - { - case "SimpleMap": - map = new SimpleMap(); - break; - case "WallMap": - map = new WallMap(); - break; - } - _mapStorages.Add(elem[0], new - MapWithSetAirplanesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, - StringSplitOptions.RemoveEmptyEntries)); + LoadMap(elem[0], elem[1], elem[2]); } return true; }