2023-11-19 17:11:10 +04:00
|
|
|
|
using AirBomber.Generics;
|
2023-11-19 18:24:41 +04:00
|
|
|
|
using AirBomber.Rendering;
|
2023-11-19 17:11:10 +04:00
|
|
|
|
|
|
|
|
|
namespace AirBomber
|
|
|
|
|
{
|
|
|
|
|
public partial class FormEntityCollection : Form
|
|
|
|
|
{
|
2023-11-19 17:56:27 +04:00
|
|
|
|
private readonly EntitiesGenericStorage _storage;
|
2023-11-19 17:11:10 +04:00
|
|
|
|
|
|
|
|
|
public FormEntityCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2023-11-19 17:56:27 +04:00
|
|
|
|
_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;
|
2023-11-19 17:11:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ButtonAddEntity_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-19 17:56:27 +04:00
|
|
|
|
if (StorageListBox.SelectedIndex == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-19 18:24:41 +04:00
|
|
|
|
FormBomberConfig ConfigForm = new FormBomberConfig();
|
|
|
|
|
ConfigForm.AddEvent(OnEntityAdded);
|
|
|
|
|
|
|
|
|
|
ConfigForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEntityAdded(BomberRendererBase Renderer)
|
|
|
|
|
{
|
2023-11-19 17:56:27 +04:00
|
|
|
|
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj is null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-19 18:24:41 +04:00
|
|
|
|
if (obj + (Renderer) != -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
CollectionPictureBox.Image = obj.ShowEntities();
|
|
|
|
|
}
|
2023-11-19 17:11:10 +04:00
|
|
|
|
|
2023-11-19 18:24:41 +04:00
|
|
|
|
else
|
2023-11-19 17:11:10 +04:00
|
|
|
|
{
|
2023-11-19 18:24:41 +04:00
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
2023-11-19 17:11:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ButtonRemoveEntity_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-19 17:56:27 +04:00
|
|
|
|
if (StorageListBox.SelectedIndex == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj is null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-19 17:11:10 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int Pos = Convert.ToInt32(NumberMaskedTextBox.Text);
|
2023-11-19 17:56:27 +04:00
|
|
|
|
if (obj - Pos == true)
|
2023-11-19 17:11:10 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-11-19 17:56:27 +04:00
|
|
|
|
CollectionPictureBox.Image = obj.ShowEntities();
|
2023-11-19 17:11:10 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-19 17:56:27 +04:00
|
|
|
|
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();
|
2023-11-19 17:11:10 +04:00
|
|
|
|
}
|
2023-11-25 23:09:40 +04:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2023-11-19 17:11:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|