179 lines
6.2 KiB
C#
179 lines
6.2 KiB
C#
|
using ProjectStormtrooper.Drawnings;
|
|||
|
using ProjectStormtrooper.Entities;
|
|||
|
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 ProjectStormtrooper;
|
|||
|
/// <summary>
|
|||
|
/// Форма конфигурации объекта
|
|||
|
/// </summary>
|
|||
|
public partial class FormStormtrooperConfig : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Объект - прорисовка штурмовика
|
|||
|
/// </summary>
|
|||
|
private DrawningStormtrooperBase? _drawningStormtrooperBase;
|
|||
|
private event Action<DrawningStormtrooperBase>? _stormtrooperDelegate;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Привязка внешнего метода к событию
|
|||
|
/// </summary>
|
|||
|
/// <param name="stormtrooperDelegate"></param>
|
|||
|
public void AddEvent(Action<DrawningStormtrooperBase> stormtrooperDelegate)
|
|||
|
{
|
|||
|
if (_stormtrooperDelegate == null)
|
|||
|
{
|
|||
|
_stormtrooperDelegate = stormtrooperDelegate;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_stormtrooperDelegate += stormtrooperDelegate;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
public FormStormtrooperConfig()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
panelRed.MouseDown += Panel_MouseDown;
|
|||
|
panelGreen.MouseDown += Panel_MouseDown;
|
|||
|
panelBlue.MouseDown += Panel_MouseDown;
|
|||
|
panelVellow.MouseDown += Panel_MouseDown;
|
|||
|
panelWhite.MouseDown += Panel_MouseDown;
|
|||
|
panelGray.MouseDown += Panel_MouseDown;
|
|||
|
panelBlack.MouseDown += Panel_MouseDown;
|
|||
|
panelPurple.MouseDown += Panel_MouseDown;
|
|||
|
//TODO buttonCancel.Click with lambda с закрытием формы
|
|||
|
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Прорисовка объекта
|
|||
|
/// </summary>
|
|||
|
private void DrawObject()
|
|||
|
{
|
|||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_drawningStormtrooperBase?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
_drawningStormtrooperBase?.SetPosition(5, 5);
|
|||
|
_drawningStormtrooperBase?.DrawTransport(gr);
|
|||
|
pictureBoxObject.Image = bmp;
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Передаем информацию при нажатии на Label
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
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":
|
|||
|
_drawningStormtrooperBase = new DrawningStormtrooperBase((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|||
|
break;
|
|||
|
case "labelModifiedObject":
|
|||
|
_drawningStormtrooperBase = new DrawingStormtrooper((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBombs.Checked, checkBoxRockets.Checked);
|
|||
|
break;
|
|||
|
}
|
|||
|
DrawObject();
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Передаем информацию при нажатии Panel_MouseDown
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
//TODO отправка цвета в Drag&Drop
|
|||
|
(sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
|||
|
}
|
|||
|
//TODO реализовать логику смены цветов: основного и дополнительного ( для продвинутого объекта)
|
|||
|
private void LabelBodyColor_DragEnter(object? sender, DragEventArgs e)
|
|||
|
{
|
|||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|||
|
{
|
|||
|
e.Effect = DragDropEffects.Copy;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
e.Effect = DragDropEffects.None;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
if (_drawningStormtrooperBase != null)
|
|||
|
{
|
|||
|
_drawningStormtrooperBase.EntityStormtrooperBase.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
if (_drawningStormtrooperBase is DrawingStormtrooper)
|
|||
|
{
|
|||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|||
|
{
|
|||
|
e.Effect = DragDropEffects.Copy;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
e.Effect = DragDropEffects.None;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
if (_drawningStormtrooperBase.EntityStormtrooperBase is EntityStormtrooper stormtrooper)
|
|||
|
{
|
|||
|
stormtrooper.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Передача объекта
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_drawningStormtrooperBase != null)
|
|||
|
{
|
|||
|
_stormtrooperDelegate?.Invoke(_drawningStormtrooperBase);
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|