172 lines
5.7 KiB
C#
172 lines
5.7 KiB
C#
|
using ProjectMonorail.Drawings;
|
|||
|
using ProjectMonorail.Entities;
|
|||
|
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 ProjectMonorail;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Форма конфигурации объекта
|
|||
|
/// </summary>
|
|||
|
public partial class FormTrainConfig : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Объект - прорисовка поезда
|
|||
|
/// </summary>
|
|||
|
private DrawingTrain? _train;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Событие для передачи объекта
|
|||
|
/// </summary>
|
|||
|
private event Action<DrawingTrain>? TrainDelegate;
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
public FormTrainConfig()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
panelRed.MouseDown += Panel_MouseDown;
|
|||
|
panelGreen.MouseDown += Panel_MouseDown;
|
|||
|
panelBlue.MouseDown += Panel_MouseDown;
|
|||
|
panelYellow.MouseDown += Panel_MouseDown;
|
|||
|
panelWhite.MouseDown += Panel_MouseDown;
|
|||
|
panelGray.MouseDown += Panel_MouseDown;
|
|||
|
panelBlack.MouseDown += Panel_MouseDown;
|
|||
|
panelPurple.MouseDown += Panel_MouseDown;
|
|||
|
|
|||
|
buttonCancel.Click += (sender, e) => Close();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Привязка внешнего метода к событию
|
|||
|
/// </summary>
|
|||
|
/// <param name="trainDelegate"></param>
|
|||
|
public void AddEvent(Action<DrawingTrain> trainDelegate)
|
|||
|
{
|
|||
|
TrainDelegate += trainDelegate;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Прорисовка объекта
|
|||
|
/// </summary>
|
|||
|
private void DrawObject()
|
|||
|
{
|
|||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_train?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
_train?.SetPosition(20, 50);
|
|||
|
_train?.DrawTransport(gr);
|
|||
|
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":
|
|||
|
_train = new DrawingTrain((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
|||
|
break;
|
|||
|
case "labelModifiedObject":
|
|||
|
_train = new DrawingMonorail((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, (int)numericUpDownWheels.Value, Color.White,
|
|||
|
Color.Black, checkBoxRail.Checked, checkBoxSecondСarriage.Checked);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Передаем информацию при нажатии на Panel
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void LabelColor_DragEnter(object? sender, DragEventArgs e)
|
|||
|
{
|
|||
|
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Действия при приеме перетаскиваемой информации
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void LabelColor_DragDrop(object? sender, DragEventArgs e)
|
|||
|
{
|
|||
|
if (_train == null || sender == null) { return; }
|
|||
|
Label colorof = (Label)sender;
|
|||
|
Color color = (Color)e.Data?.GetData(typeof(Color));
|
|||
|
|
|||
|
switch (colorof?.Name)
|
|||
|
{
|
|||
|
case "labelMainColor":
|
|||
|
_train.EntityTrain?.SetMainColor(color);
|
|||
|
DrawObject();
|
|||
|
break;
|
|||
|
case "labelAdditionalColor":
|
|||
|
if (_train is DrawingMonorail)
|
|||
|
{
|
|||
|
(_train.EntityTrain as EntityMonorail).SetAdditionalColor(color);
|
|||
|
DrawObject();
|
|||
|
}
|
|||
|
break;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Передача объекта
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ButtonAdd_Click(object? sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_train != null)
|
|||
|
{
|
|||
|
TrainDelegate?.Invoke(_train);
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|