169 lines
5.5 KiB
C#
169 lines
5.5 KiB
C#
using ProjectFighterJet.Drawnings;
|
|
using ProjectFighterJet.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 ProjectFighterJet;
|
|
|
|
public partial class FormJetConfig : Form
|
|
{
|
|
/// <summary>
|
|
/// Объект - прорисовка истребителя
|
|
/// </summary>
|
|
private DrawningJet? _drawningjet;
|
|
private event Action<DrawningJet>? _jetDelegate;
|
|
|
|
/// <summary>
|
|
/// Событие для передачи объекта
|
|
/// </summary>
|
|
public void AddEvent(Action<DrawningJet> jetDelegate)
|
|
{
|
|
if (jetDelegate == null)
|
|
{
|
|
_jetDelegate = jetDelegate;
|
|
}
|
|
else
|
|
{
|
|
_jetDelegate += jetDelegate;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Конструктор
|
|
/// </summary>
|
|
public FormJetConfig()
|
|
{ InitializeComponent();
|
|
panelRed.MouseDown += panel_MouseDown;
|
|
panelGreen.MouseDown += panel_MouseDown;
|
|
panelBlue.MouseDown += panel_MouseDown;
|
|
panelYellow.MouseDown += panel_MouseDown;
|
|
panelBlack.MouseDown += panel_MouseDown;
|
|
panelPurple.MouseDown += panel_MouseDown;
|
|
panelWhite.MouseDown += panel_MouseDown;
|
|
panelGray.MouseDown += panel_MouseDown;
|
|
buttonCancel.Click += (sender, e) => Close();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Прорисовка объекта
|
|
/// </summary>
|
|
private void DrawObject()
|
|
{
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningjet?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
_drawningjet?.SetPosition(5, 5);
|
|
_drawningjet?.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":
|
|
_drawningjet = new DrawningJet((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|
break;
|
|
case "labelModifiedObject":
|
|
_drawningjet = new DrawningFighterJet((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxEngines.Checked, checkBoxRockets.Checked, checkBoxFuel.Checked);
|
|
break;
|
|
}
|
|
DrawObject();
|
|
}
|
|
|
|
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 (_drawningjet != null)
|
|
{
|
|
_drawningjet.EntityJet.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
|
DrawObject();
|
|
}
|
|
}
|
|
private void labelAdditionalColor_DragEnter(object? sender, DragEventArgs e)
|
|
{
|
|
if (_drawningjet is DrawningFighterJet)
|
|
{
|
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|
{
|
|
e.Effect = DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void labelAdditionalColor_DragDrop(object? sender, DragEventArgs e)
|
|
{
|
|
if (_drawningjet.EntityJet is EntityFighterJet jet)
|
|
{
|
|
jet.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 (_drawningjet != null)
|
|
{
|
|
_jetDelegate?.Invoke(_drawningjet);
|
|
Close();
|
|
}
|
|
}
|
|
}
|