2024-04-01 12:43:18 +04:00

156 lines
5.8 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 ProjectStormTrooper.Drawnings;
using ProjectStormTrooper.Entities;
namespace ProjectStormTrooper
{
/// <summary>
/// форма конфигурации объекта
/// </summary>
public partial class FormWarPlaneConfig : Form
{
private DrawningWarPlane? warPlane;
/// <summary>
/// Событие для передачи объекта
/// </summary>
private event Action<DrawningWarPlane> _warPlaneDelegate;
/// <summary>
/// Конструктор
/// </summary>
public FormWarPlaneConfig()
{
InitializeComponent();
panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown;
panelYellow.MouseDown += Panel_MouseDown;
panelWhite.MouseDown += Panel_MouseDown;
panelGray.MouseDown += Panel_MouseDown;
panelBlack.MouseDown += Panel_MouseDown;
panelPurple.MouseDown += Panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Привязка внешнего метода к событию
/// </summary>
/// <param name="carDelegate"></param>
public void AddEvent(Action<DrawningWarPlane> warPlaneDelegate)
{
_warPlaneDelegate += warPlaneDelegate;
}
/// <summary>
/// Прорисовка объекта
/// </summary>
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
warPlane?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
warPlane?.SetPosition(15, 15);
warPlane?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>labelSimpleObjectlabelSimpleObject
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
{
case "labelSimpleObject":
warPlane = new DrawningWarPlane((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black);
break;
case "labelModifiedObject":
warPlane = new DrawningStormTrooper((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
Color.Black, Color.Black, checkBoxBombs.Checked, checkBoxRockets.Checked);
break;
}
DrawObject();
}
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
// TODO отправка цвета в Drag&Drop
}
private void LabelColors_DragEnter(object? sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
private void LabelColors_DragDrop(object? sender, DragEventArgs e)
{
if(warPlane == null)
{
return;
}
Label label = (Label)sender;
Color newColor = (Color) e.Data.GetData(typeof(Color).ToString());
switch (label.Name)
{
case "labelBodyColor":
warPlane.EntityWarPlane.SetBodyColor(newColor);
DrawObject();
break;
case "labelHeadColor":
warPlane.EntityWarPlane.SetColorOfHead(newColor);
DrawObject();
break;
case "labelAdditionalColor":
if(warPlane is DrawningStormTrooper)
{
(warPlane.EntityWarPlane as EntityStormTrooper).SetAdditionalColor(newColor);
DrawObject();
}
break;
}
}
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
/// <summary>
/// Передача объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (warPlane != null)
{
_warPlaneDelegate.Invoke(warPlane);
Close();
}
}
}
}