134 lines
5.1 KiB
C#
134 lines
5.1 KiB
C#
|
using ProjectMonorail.Scripts.Monorail.Delegates;
|
|||
|
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
|||
|
using ProjectMonorail.Scripts.Monorail.Entities;
|
|||
|
|
|||
|
namespace ProjectMonorail
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Форма конфигурации объекта
|
|||
|
/// </summary>
|
|||
|
public partial class FormMonorailConfig : Form
|
|||
|
{
|
|||
|
#region Events & Delegates
|
|||
|
private event DelegateMonorail OnSendEvent_Monorail;
|
|||
|
#endregion
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Объект прорисовки монорельса
|
|||
|
/// </summary>
|
|||
|
private DrawingMonorail? _monorail;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
public FormMonorailConfig()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
panelColor_Red.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_Green.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_Blue.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_Yellow.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_Purple.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_White.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_Black.MouseDown += PanelColor_MouseDown;
|
|||
|
panelColor_Grey.MouseDown += PanelColor_MouseDown;
|
|||
|
|
|||
|
// TODO buttonCancel.Click with lambda
|
|||
|
buttonCancel.Click += (object? obj, EventArgs e) => Close();
|
|||
|
}
|
|||
|
|
|||
|
public void AddEventListener_Monorail(DelegateMonorail method)
|
|||
|
{
|
|||
|
OnSendEvent_Monorail += method;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Прорисовка объекта
|
|||
|
/// </summary>
|
|||
|
private void DrawObject()
|
|||
|
{
|
|||
|
Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
Graphics g = Graphics.FromImage(bmp);
|
|||
|
_monorail?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
_monorail?.SetPosition(10, 10);
|
|||
|
_monorail?.DrawTransport(g);
|
|||
|
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":
|
|||
|
_monorail = new DrawingMonorail((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|||
|
break;
|
|||
|
case "labelModifiedObject":
|
|||
|
_monorail = new DrawingModernMonorail((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
|
|||
|
Color.Black, checkBoxMonorailTrack.Checked, checkBoxCabin.Checked);
|
|||
|
break;
|
|||
|
}
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Передаем информацию при нажатии на Panel
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy);
|
|||
|
}
|
|||
|
|
|||
|
private void PanelColor_DragEnter(object? sender, DragEventArgs e)
|
|||
|
{
|
|||
|
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
|
|||
|
}
|
|||
|
|
|||
|
private void PanelColorBody_DragDrop(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
_monorail?.EntityMonorail?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
|||
|
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
|
|||
|
private void PanelColorAdditional_DragDrop(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
((_monorail as DrawingModernMonorail)?.EntityMonorail as EntityModernMonorail)?.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
|||
|
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_monorail != null) OnSendEvent_Monorail?.Invoke(_monorail);
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|