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

125 lines
4.1 KiB
C#
Raw Normal View History

using AirBomber.Rendering;
namespace AirBomber
{
public partial class FormBomberConfig : Form
{
BomberRendererBase? _renderer = null;
private event Action<BomberRendererBase>? OnBomberAdded;
public FormBomberConfig()
{
InitializeComponent();
RedPanel.MouseDown += PanelColor_MouseDown;
GreenPanel.MouseDown += PanelColor_MouseDown;
BluePanel.MouseDown += PanelColor_MouseDown;
OrangePanel.MouseDown += PanelColor_MouseDown;
WhitePanel.MouseDown += PanelColor_MouseDown;
GrayPanel.MouseDown += PanelColor_MouseDown;
BlackPanel.MouseDown += PanelColor_MouseDown;
VioletPanel.MouseDown += PanelColor_MouseDown;
ConfigCancelButton.Click += (sender, e) => { Close(); };
}
private void DrawBomber()
{
Bitmap bmp = new Bitmap(EntityPictureBox.Width, EntityPictureBox.Height);
Graphics g = Graphics.FromImage(bmp);
_renderer?.SetPosition(5, 5);
_renderer?.DrawEntity(g);
EntityPictureBox.Image = bmp;
}
public void AddEvent(Action<BomberRendererBase> ev)
{
if (OnBomberAdded is null)
OnBomberAdded = ev;
else
OnBomberAdded += ev;
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent("System.Drawing.Color") ?? false)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "BaseEntityLabel":
_renderer = new BomberRendererBase(
(int)SpeedNumericUpDown.Value,
(int)WeightNumericUpDown.Value,
Color.White,
EntityPictureBox.Width, EntityPictureBox.Height
);
break;
case "AdvancedEntityLabel":
_renderer = new BomberRenderer(
(int)SpeedNumericUpDown.Value,
(int)WeightNumericUpDown.Value,
Color.White, Color.Black,
FuelTanksCheckbox.Checked,
BombsCheckBox.Checked,
EntityPictureBox.Width, EntityPictureBox.Height
);
break;
}
DrawBomber();
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
Color SelectedColor = (Color)e.Data?.GetData("System.Drawing.Color")!;
_renderer?.SetBaseColor(SelectedColor);
DrawBomber();
}
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
Color SelectedColor = (Color)e.Data?.GetData("System.Drawing.Color")!;
(_renderer as BomberRenderer)?.SetAdditionalColor(SelectedColor);
DrawBomber();
}
private void OkButtonClick(object sender, EventArgs e)
{
if (_renderer is not null)
OnBomberAdded?.Invoke(_renderer);
Close();
}
}
}