157 lines
5.1 KiB
C#
157 lines
5.1 KiB
C#
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;
|
|
using ProjectAirbus.Drawnings;
|
|
using ProjectAirbus.Entities;
|
|
|
|
namespace ProjectAirbus
|
|
{
|
|
public partial class FormAirbusConfig : Form
|
|
{
|
|
// выбранный самолёт
|
|
DrawningAirbus? _airbus = null;
|
|
|
|
// событие
|
|
private event Action<DrawningAirbus> EventAddAirbus;
|
|
// конструктор
|
|
public FormAirbusConfig()
|
|
{
|
|
InitializeComponent();
|
|
panelRed.MouseDown += PanelColor_MouseDown;
|
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
|
panelOrange.MouseDown += PanelColor_MouseDown;
|
|
panelViolet.MouseDown += PanelColor_MouseDown;
|
|
panelSilver.MouseDown += PanelColor_MouseDown;
|
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
|
|
|
buttonCancel.Click += (sender, e) => Close();
|
|
}
|
|
|
|
// добавить событие
|
|
public void AddEvent(Action<DrawningAirbus> ev)
|
|
{
|
|
if (EventAddAirbus == null)
|
|
{
|
|
EventAddAirbus = ev;
|
|
}
|
|
else
|
|
{
|
|
EventAddAirbus += ev;
|
|
}
|
|
}
|
|
|
|
// цвета
|
|
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
|
{
|
|
e.Effect = DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
|
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
|
}
|
|
|
|
// перекрашиваем базовый
|
|
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
if (_airbus == null)
|
|
return;
|
|
|
|
Color bodyColor = (Color)e.Data?.GetData(typeof(Color));
|
|
_airbus.EntityAirbus.ChangeBodyColor(bodyColor);
|
|
DrawAirbus();
|
|
}
|
|
|
|
// перекрашиваем доп
|
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
if (_airbus == null)
|
|
return;
|
|
|
|
Color addColor = (Color)e.Data?.GetData(typeof(Color));
|
|
if (_airbus is DrawningPlane)
|
|
{
|
|
EntityPlane _plane = _airbus.EntityAirbus as EntityPlane;
|
|
_plane.ChangeColorAdditional(addColor);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Нельзя задать доп. цвет обычному самолёту");
|
|
}
|
|
DrawAirbus();
|
|
}
|
|
|
|
// объект
|
|
private void panelObject_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
|
{
|
|
e.Effect = DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
|
|
// передаём информацию при нажатии на label
|
|
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
|
}
|
|
|
|
// что делаем при приеме информации
|
|
private void panelObject_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
|
{
|
|
case "labelSimpleObject":
|
|
_airbus = new DrawningAirbus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
|
Color.White, pictureBoxObject.Width, pictureBoxObject.Height);
|
|
break;
|
|
case "labelComplexObject":
|
|
_airbus = new DrawningPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
|
Color.White, Color.Black, checkBoxCompartment.Checked, checkBoxAdditionalEngine.Checked,
|
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|
break;
|
|
}
|
|
DrawAirbus();
|
|
}
|
|
|
|
// добавить самолёт
|
|
private void buttonOk_Click(object sender, EventArgs e)
|
|
{
|
|
if (_airbus == null)
|
|
return;
|
|
|
|
EventAddAirbus?.Invoke(_airbus);
|
|
Close();
|
|
}
|
|
|
|
// отрисовать самолёт
|
|
private void DrawAirbus()
|
|
{
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_airbus?.SetPosition(5, 5);
|
|
_airbus?.DrawTransport(gr);
|
|
pictureBoxObject.Image = bmp;
|
|
}
|
|
|
|
}
|
|
} |