PIbd-21_MalafeevL.S._Cruise.../Cruiser/FormCruiserConfig.cs

161 lines
6.0 KiB
C#
Raw Permalink 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 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 Cruiser.Drawing;
namespace Cruiser
{
public partial class FormCruiserConfig : Form
{
/// <summary>
/// Переменная-выбранная лайнера
/// </summary>
DrawingCruiser? _cruiser = null;
/// <summary>
/// Событие
/// </summary>
private event Action<DrawingCruiser>? EventAddCruiser;
/// <summary>
/// Конструктор
/// </summary>
public FormCruiserConfig()
{
InitializeComponent();
panelColorRed.MouseDown += panelColor_MouseDown;
panelColorSienna.MouseDown += panelColor_MouseDown;
panelColorForestGreen.MouseDown += panelColor_MouseDown;
panelColorAquamarine.MouseDown += panelColor_MouseDown;
panelColorCrimson.MouseDown += panelColor_MouseDown;
panelColorDodgerBlue.MouseDown += panelColor_MouseDown;
panelColorGold.MouseDown += panelColor_MouseDown;
panelColorPlum.MouseDown += panelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
/// <summary>
/// Отрисовать лайнер
/// </summary>
private void DrawCruiser()
{
Bitmap bmp = new(pictureBoxToCruiser.Width, pictureBoxToCruiser.Height);
Graphics gr = Graphics.FromImage(bmp);
_cruiser?.SetPosition(15, 15);
_cruiser?.DrawTransport(gr);
pictureBoxToCruiser.Image = bmp;
}
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawingCruiser> ev)
{
if (EventAddCruiser == null)
{
EventAddCruiser = ev;
}
else
{
EventAddCruiser += ev;
}
}
/// <summary>
/// Добавление лайнера
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddCruiser?.Invoke(_cruiser);
Close();
}
/// <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) ?? false)
{
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 "labelCruiser": //переделал из за изменения конструкторов (см. комментарии там)
_cruiser = new DrawingCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
Color.Orchid,
pictureBoxToCruiser.Width,
pictureBoxToCruiser.Height);
break;
case "labelProCruiser": //переделал из за изменения конструкторов (см. комментарии там)
_cruiser = new DrawingProCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
Color.Orchid, Color.Aquamarine,
checkBoxRockMines.Checked, checkBoxHelipad.Checked,
pictureBoxToCruiser.Width,
pictureBoxToCruiser.Height);
break;
}
DrawCruiser();
}
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
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 labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_cruiser == null)
return;
switch (((Label)sender).Name)
{
case "labelColor":
_cruiser.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelDopColor":
if (!(_cruiser is DrawingProCruiser))
return;
(_cruiser as DrawingProCruiser).setElementColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawCruiser();
}
}
}