152 lines
4.9 KiB
C#
152 lines
4.9 KiB
C#
using AirBomber.DrawningObjects;
|
||
using AirBomber.Generics;
|
||
using AirBomber.MovementStrategy;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace AirBomber
|
||
{
|
||
public partial class FormBomberCollection : Form
|
||
{
|
||
private readonly BomberGenericStorage _bomber;
|
||
|
||
public FormBomberCollection()
|
||
{
|
||
InitializeComponent();
|
||
_bomber = new BomberGenericStorage(PicBoxBomberCollection.Width, PicBoxBomberCollection.Height);
|
||
}
|
||
|
||
private void ReloadObjects()
|
||
{
|
||
int index = listBoxStorages.SelectedIndex;
|
||
listBoxStorages.Items.Clear();
|
||
for (int i = 0; i < _bomber.Keys.Count; i++)
|
||
{
|
||
listBoxStorages.Items.Add(_bomber.Keys[i]);
|
||
}
|
||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||
>= listBoxStorages.Items.Count))
|
||
{
|
||
listBoxStorages.SelectedIndex = 0;
|
||
}
|
||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||
index < listBoxStorages.Items.Count)
|
||
{
|
||
listBoxStorages.SelectedIndex = index;
|
||
}
|
||
}
|
||
|
||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _bomber[listBoxStorages.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
PicBoxBomberCollection.Image = obj.ShowBomber();
|
||
}
|
||
|
||
private void ButtonAddBomber_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var formBomberConfig = new FormBomberConfig();
|
||
|
||
formBomberConfig.AddEvent(bomber =>
|
||
{
|
||
if (listBoxStorages.SelectedIndex != -1)
|
||
{
|
||
var obj = _bomber[listBoxStorages.SelectedItem?.ToString() ?? string.Empty];
|
||
if (obj != null)
|
||
{
|
||
if (obj + bomber != 1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
PicBoxBomberCollection.Image = obj.ShowBomber();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
});
|
||
formBomberConfig.Show();
|
||
}
|
||
|
||
private void ButtonRemoveBomber_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _bomber[listBoxStorages.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
int pos = Convert.ToInt32(MessageBoxBomber.Text);
|
||
if (obj - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
PicBoxBomberCollection.Image = obj.ShowBomber();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
|
||
private void AddKit_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(KitTextbox.Text))
|
||
{
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
_bomber.AddSet(KitTextbox.Text);
|
||
ReloadObjects();
|
||
}
|
||
|
||
private void RemoveKit_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
_bomber.DelSet(listBoxStorages.SelectedItem.ToString()
|
||
?? string.Empty);
|
||
ReloadObjects();
|
||
}
|
||
}
|
||
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
PicBoxBomberCollection.Image =
|
||
_bomber[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBomber();
|
||
}
|
||
}
|
||
}
|