175 lines
6.1 KiB
C#
175 lines
6.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;
|
||
|
||
namespace Ship
|
||
{
|
||
public partial class FormShipConfig : Form
|
||
{
|
||
/// <summary>
|
||
/// Переменная-выбранная машина
|
||
/// </summary>
|
||
DrawingShip _ship = null;
|
||
/// <summary>
|
||
/// Событие
|
||
/// </summary>
|
||
private event Action<DrawingShip> EventAddShip;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormShipConfig()
|
||
{
|
||
InitializeComponent();
|
||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||
panelGray.MouseDown += PanelColor_MouseDown;
|
||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||
panelRed.MouseDown += PanelColor_MouseDown;
|
||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||
|
||
buttonCancel.Click += (sender, e) => Close();
|
||
}
|
||
/// <summary>
|
||
/// Отрисовать машину
|
||
/// </summary>
|
||
private void DrawShip()
|
||
{
|
||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_ship?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||
_ship?.DrawTransport(gr);
|
||
pictureBoxObject.Image = bmp;
|
||
}
|
||
/// <summary>
|
||
/// Добавление события
|
||
/// </summary>
|
||
/// <param name="ev"></param>
|
||
public void AddEvent(Action<DrawingShip> ev)
|
||
{
|
||
if (EventAddShip == null)
|
||
{
|
||
EventAddShip = new Action<DrawingShip>(ev);
|
||
}
|
||
else
|
||
{
|
||
EventAddShip += ev;
|
||
}
|
||
}
|
||
/// <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, DragDropEffects.Move | DragDropEffects.Copy);
|
||
}
|
||
/// <summary>
|
||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = 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":
|
||
_ship = new DrawingShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||
break;
|
||
case "labelModifiedObject":
|
||
_ship = new DrawingMotorShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||
checkBoxPipes.Checked, checkBoxFuelTank.Checked);
|
||
break;
|
||
}
|
||
DrawShip();
|
||
}
|
||
/// <summary>
|
||
/// Отправляем цвет с панели
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||
{
|
||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||
}
|
||
/// <summary>
|
||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data.GetDataPresent(typeof(Color)))
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Принимаем основной цвет
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
_ship.SetColor((Color)e.Data.GetData(typeof(Color)));
|
||
DrawShip();
|
||
}
|
||
/// <summary>
|
||
/// Принимаем дополнительный цвет
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
if(_ship is DrawingMotorShip ship)
|
||
{
|
||
ship.SetDopColor((Color)e.Data.GetData(typeof(Color)));
|
||
}
|
||
DrawShip();
|
||
}
|
||
/// <summary>
|
||
/// Добавление машины
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonOk_Click(object sender, EventArgs e)
|
||
{
|
||
EventAddShip?.Invoke(_ship);
|
||
Close();
|
||
}
|
||
|
||
private void FormShipConfig_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|