PIbd-22_Shabunov_O.A._AirBo.../AirBomber/FormEntityCollection.cs

128 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AirBomber.Generics;
namespace AirBomber
{
public partial class FormEntityCollection : Form
{
private readonly EntitiesGenericStorage _storage;
public FormEntityCollection()
{
InitializeComponent();
_storage = new EntitiesGenericStorage(CollectionPictureBox.Width, CollectionPictureBox.Height);
}
private void ReloadObjects()
{
int index = StorageListBox.SelectedIndex;
StorageListBox.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
StorageListBox.Items.Add(_storage.Keys[i]);
if (StorageListBox.Items.Count > 0 && (index == -1 || index >= StorageListBox.Items.Count))
StorageListBox.SelectedIndex = 0;
else if (StorageListBox.Items.Count > 0 && index > -1 && index < StorageListBox.Items.Count)
StorageListBox.SelectedIndex = index;
}
public void ButtonAddEntity_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
if (obj is null)
return;
BomberForm Form = new BomberForm();
if (Form.ShowDialog() == DialogResult.OK)
{
if (obj + Form.SelectedRenderer != -1)
{
MessageBox.Show("Объект добавлен");
CollectionPictureBox.Image = obj.ShowEntities();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
public void ButtonRemoveEntity_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
if (obj is null)
return;
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
int Pos = Convert.ToInt32(NumberMaskedTextBox.Text);
if (obj - Pos == true)
{
MessageBox.Show("Объект удален");
CollectionPictureBox.Image = obj.ShowEntities();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
public void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
if (obj is null)
return;
CollectionPictureBox.Image = obj.ShowEntities();
}
private void ButtonAddSet_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(SetNameTextBox.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(SetNameTextBox.Text);
ReloadObjects();
}
private void ButtonRemoveSet_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
if (MessageBox.Show(
$"Удалить объект{StorageListBox.SelectedItem}?",
"Удаление",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
) == DialogResult.Yes)
{
_storage.RemoveSet(StorageListBox.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
}
}
private void StorageListBoxIndexChanged(object sender, EventArgs e)
{
CollectionPictureBox.Image = _storage[StorageListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowEntities();
}
}
}