Menu strip

This commit is contained in:
ShabOl 2023-11-25 23:09:40 +04:00
parent 44c20bbcfe
commit ae6e3cac02
4 changed files with 95 additions and 76 deletions

View File

@ -39,17 +39,24 @@
RemoveBomberButton = new Button(); RemoveBomberButton = new Button();
NumberMaskedTextBox = new MaskedTextBox(); NumberMaskedTextBox = new MaskedTextBox();
AddBomberButton = new Button(); AddBomberButton = new Button();
FormMenuStrip = new MenuStrip();
FileMenuStripItem = new ToolStripMenuItem();
SaveToolStripMenuItem = new ToolStripMenuItem();
LoadToolStripMenuItem = new ToolStripMenuItem();
OpenFileDialog = new OpenFileDialog();
SaveFileDialog = new SaveFileDialog();
((System.ComponentModel.ISupportInitialize)CollectionPictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)CollectionPictureBox).BeginInit();
ToolGroupBox.SuspendLayout(); ToolGroupBox.SuspendLayout();
SetsGroupBox.SuspendLayout(); SetsGroupBox.SuspendLayout();
FormMenuStrip.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// CollectionPictureBox // CollectionPictureBox
// //
CollectionPictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; CollectionPictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
CollectionPictureBox.Location = new Point(0, 0); CollectionPictureBox.Location = new Point(0, 27);
CollectionPictureBox.Name = "CollectionPictureBox"; CollectionPictureBox.Name = "CollectionPictureBox";
CollectionPictureBox.Size = new Size(812, 603); CollectionPictureBox.Size = new Size(812, 576);
CollectionPictureBox.TabIndex = 0; CollectionPictureBox.TabIndex = 0;
CollectionPictureBox.TabStop = false; CollectionPictureBox.TabStop = false;
// //
@ -61,9 +68,9 @@
ToolGroupBox.Controls.Add(RemoveBomberButton); ToolGroupBox.Controls.Add(RemoveBomberButton);
ToolGroupBox.Controls.Add(NumberMaskedTextBox); ToolGroupBox.Controls.Add(NumberMaskedTextBox);
ToolGroupBox.Controls.Add(AddBomberButton); ToolGroupBox.Controls.Add(AddBomberButton);
ToolGroupBox.Location = new Point(818, 12); ToolGroupBox.Location = new Point(818, 27);
ToolGroupBox.Name = "ToolGroupBox"; ToolGroupBox.Name = "ToolGroupBox";
ToolGroupBox.Size = new Size(176, 579); ToolGroupBox.Size = new Size(176, 564);
ToolGroupBox.TabIndex = 1; ToolGroupBox.TabIndex = 1;
ToolGroupBox.TabStop = false; ToolGroupBox.TabStop = false;
ToolGroupBox.Text = "Инструменты"; ToolGroupBox.Text = "Инструменты";
@ -121,7 +128,7 @@
// //
// RefreshCollectionButton // RefreshCollectionButton
// //
RefreshCollectionButton.Location = new Point(6, 543); RefreshCollectionButton.Location = new Point(6, 528);
RefreshCollectionButton.Name = "RefreshCollectionButton"; RefreshCollectionButton.Name = "RefreshCollectionButton";
RefreshCollectionButton.Size = new Size(164, 30); RefreshCollectionButton.Size = new Size(164, 30);
RefreshCollectionButton.TabIndex = 3; RefreshCollectionButton.TabIndex = 3;
@ -158,6 +165,45 @@
AddBomberButton.UseVisualStyleBackColor = true; AddBomberButton.UseVisualStyleBackColor = true;
AddBomberButton.Click += ButtonAddEntity_Click; AddBomberButton.Click += ButtonAddEntity_Click;
// //
// FormMenuStrip
//
FormMenuStrip.Items.AddRange(new ToolStripItem[] { FileMenuStripItem });
FormMenuStrip.Location = new Point(0, 0);
FormMenuStrip.Name = "FormMenuStrip";
FormMenuStrip.Size = new Size(1006, 24);
FormMenuStrip.TabIndex = 2;
FormMenuStrip.Text = "menuStrip1";
//
// FileMenuStripItem
//
FileMenuStripItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
FileMenuStripItem.Name = "FileMenuStripItem";
FileMenuStripItem.Size = new Size(48, 20);
FileMenuStripItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new Size(141, 22);
SaveToolStripMenuItem.Text = "Сохранение";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// LoadToolStripMenuItem
//
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new Size(141, 22);
LoadToolStripMenuItem.Text = "Загрузка";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// OpenFileDialog
//
OpenFileDialog.FileName = "openFileDialog1";
OpenFileDialog.Filter = "txt file | *.txt";
//
// SaveFileDialog
//
SaveFileDialog.Filter = "txt file | *.txt";
//
// FormEntityCollection // FormEntityCollection
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -165,6 +211,7 @@
ClientSize = new Size(1006, 603); ClientSize = new Size(1006, 603);
Controls.Add(ToolGroupBox); Controls.Add(ToolGroupBox);
Controls.Add(CollectionPictureBox); Controls.Add(CollectionPictureBox);
Controls.Add(FormMenuStrip);
Name = "FormEntityCollection"; Name = "FormEntityCollection";
Text = "Набор бомбардировщиков"; Text = "Набор бомбардировщиков";
((System.ComponentModel.ISupportInitialize)CollectionPictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)CollectionPictureBox).EndInit();
@ -172,7 +219,10 @@
ToolGroupBox.PerformLayout(); ToolGroupBox.PerformLayout();
SetsGroupBox.ResumeLayout(false); SetsGroupBox.ResumeLayout(false);
SetsGroupBox.PerformLayout(); SetsGroupBox.PerformLayout();
FormMenuStrip.ResumeLayout(false);
FormMenuStrip.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
@ -188,5 +238,11 @@
private ListBox StorageListBox; private ListBox StorageListBox;
private Button AddSetButton; private Button AddSetButton;
private Button RemoveSetButton; private Button RemoveSetButton;
private MenuStrip FormMenuStrip;
private ToolStripMenuItem FileMenuStripItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog OpenFileDialog;
private SaveFileDialog SaveFileDialog;
} }
} }

View File

@ -127,5 +127,29 @@ namespace AirBomber
{ {
CollectionPictureBox.Image = _storage[StorageListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowEntities(); CollectionPictureBox.Image = _storage[StorageListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowEntities();
} }
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (SaveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(SaveFileDialog.FileName))
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(OpenFileDialog.FileName))
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
ReloadObjects();
}
} }
} }

View File

@ -117,4 +117,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="FormMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="OpenFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>153, 17</value>
</metadata>
<metadata name="SaveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>288, 17</value>
</metadata>
</root> </root>

View File

@ -57,9 +57,6 @@ namespace AirBomber.Generics
public bool SaveData(string FileName) public bool SaveData(string FileName)
{ {
//if (File.Exists(FileName))
// File.Delete(FileName);
if (_entityStorages.Count == 0) if (_entityStorages.Count == 0)
return false; return false;
@ -78,33 +75,11 @@ namespace AirBomber.Generics
} }
} }
//StringBuilder Data = new();
//foreach (KeyValuePair<string, EntitiesGenericCollection<RendererBase, ObjectEntityRenderer>> Record in _entityStorages)
//{
// StringBuilder Records = new StringBuilder();
//
// foreach (RendererBase? Element in Record.Value.Entities)
// Records.Append($"{Element?.SerializeRenderer(_entityDelimiter)}{_recordsDelimiter}");
//
// Data.AppendLine($"{Record.Key}{_keyValueDelimiter}{Records}");
//}
//if (Data.Length == 0)
// return false;
//using FileStream fs = new(FileName, FileMode.Create);
//byte[] info = new
//UTF8Encoding(true).GetBytes($"BomberStorage{Environment.NewLine}{Data}");
//fs.Write(info, 0, info.Length);
return true; return true;
} }
public bool LoadData(string FileName) public bool LoadData(string FileName)
{ {
if (!File.Exists(FileName))
return false;
using (StreamReader reader = new StreamReader(FileName)) using (StreamReader reader = new StreamReader(FileName))
{ {
if (reader.ReadLine() != "BomberStorage") if (reader.ReadLine() != "BomberStorage")
@ -129,7 +104,7 @@ namespace AirBomber.Generics
if (Renderer != null) if (Renderer != null)
{ {
if ((Collection + Renderer) != -1) if ((Collection + Renderer) == -1)
return false; return false;
} }
} }
@ -138,51 +113,6 @@ namespace AirBomber.Generics
} }
} }
//string Buffer = string.Empty;
//using (FileStream fs = new(FileName, FileMode.Open))
//{
// byte[] b = new byte[fs.Length];
// UTF8Encoding temp = new(true);
//
// while (fs.Read(b, 0, b.Length) > 0)
// Buffer += temp.GetString(b);
//}
//
//var strs = Buffer.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
//
//if (strs == null || strs.Length == 0)
// return false;
//
//if (!strs[0].StartsWith("BomberStorage"))
// //если нет такой записи, то это не те данные
// return false;
//
//_entityStorages.Clear();
//
//foreach (string Data in strs)
//{
// string[] Record = Data.Split(_keyValueDelimiter, StringSplitOptions.RemoveEmptyEntries);
//
// if (Record.Length != 2)
// continue;
//
// EntitiesGenericCollection<RendererBase, ObjectEntityRenderer> Collection = new(_pictureWidth, _pictureHeight);
// string[] Set = Record[1].Split(_recordsDelimiter, StringSplitOptions.RemoveEmptyEntries);
//
// foreach (string Element in Set)
// {
// RendererBase? Renderer = Element?.DeserializeRenderer(_entityDelimiter, _pictureWidth, _pictureHeight);
//
// if (Renderer != null)
// {
// if ((Collection + Renderer) != -1)
// return false;
// }
// }
//
// _entityStorages.Add(Record[0], Collection);
//}
return true; return true;
} }
} }