152 lines
5.8 KiB
C#
152 lines
5.8 KiB
C#
using System.Windows.Forms;
|
||
using WarmlyLocomotive.DrawningObjects;
|
||
using WarmlyLocomotive.Entities;
|
||
|
||
namespace WarmlyLocomotive
|
||
{
|
||
/// <summary>
|
||
/// Делегат для передачи объекта-тепловоза
|
||
/// </summary>
|
||
/// <param name="warmlylocomotive"></param>
|
||
public partial class FormWarmlyLocomotiveConfig : Form
|
||
{
|
||
/// <summary>
|
||
/// Переменная
|
||
/// </summary>
|
||
DrawningWarmlyLocomotive? _warmlylocomotive = null;
|
||
/// <summary>
|
||
/// Событие
|
||
/// </summary>
|
||
public event Action<DrawningWarmlyLocomotive>? EventAddWarmlyLocomotive;
|
||
public FormWarmlyLocomotiveConfig()
|
||
{
|
||
InitializeComponent();
|
||
panelRed.MouseDown += PanelColor_MouseDown;
|
||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||
panelGray.MouseDown += PanelColor_MouseDown;
|
||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||
buttonCancel.Click += (s, e) => Close();
|
||
}
|
||
private void DrawWarmlyLocomotive()
|
||
{
|
||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_warmlylocomotive?.SetPosition(5, 5);
|
||
_warmlylocomotive?.DrawTransport(gr);
|
||
pictureBoxObject.Image = bmp;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Добавление события
|
||
/// </summary>
|
||
/// <param name="ev">Привязанный метод</param>
|
||
internal void AddEvent(Action<DrawningWarmlyLocomotive> ev)
|
||
{
|
||
if (EventAddWarmlyLocomotive == null)
|
||
{
|
||
EventAddWarmlyLocomotive = ev;
|
||
}
|
||
else
|
||
{
|
||
EventAddWarmlyLocomotive += 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) ?? 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 "labelBasic":
|
||
_warmlylocomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value,
|
||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||
pictureBoxObject.Height);
|
||
break;
|
||
case "labelAdvanced":
|
||
_warmlylocomotive = new DrawningWarmlyLocomotiveWithTrumpet((int)numericUpDownSpeed.Value,
|
||
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTrumpet.Checked,
|
||
checkBoxLuggage.Checked, pictureBoxObject.Width,
|
||
pictureBoxObject.Height);
|
||
break;
|
||
}
|
||
DrawWarmlyLocomotive();
|
||
}
|
||
|
||
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 (_warmlylocomotive == null)
|
||
return;
|
||
switch (((Label)sender).Name)
|
||
{
|
||
case "labelMainColor":
|
||
_warmlylocomotive.EntityWarmlyLocomotive.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||
break;
|
||
case "labelAdditionalColor":
|
||
if (!(_warmlylocomotive is DrawningWarmlyLocomotiveWithTrumpet))
|
||
return;
|
||
(_warmlylocomotive.EntityWarmlyLocomotive as EntityWarmlyLocomotiveWithTrumpet).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||
break;
|
||
}
|
||
DrawWarmlyLocomotive();
|
||
}
|
||
/// <summary>
|
||
/// Добавление машины
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||
{
|
||
EventAddWarmlyLocomotive?.Invoke(_warmlylocomotive);
|
||
Close();
|
||
}
|
||
}
|
||
} |