2024-10-03 01:43:12 +04:00
|
|
|
|
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 ProjectGasolineTanker.Drawings;
|
|
|
|
|
using ProjectGasolineTanker.Entities;
|
|
|
|
|
|
|
|
|
|
namespace ProjectGasolineTanker
|
|
|
|
|
{
|
|
|
|
|
public partial class FormTruckConfig : Form
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DrawingTruck? _truck = null;
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие
|
|
|
|
|
/// </summary>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
private event Action<DrawingTruck>? EventAddTruck;
|
|
|
|
|
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
public FormTruckConfig()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
panelRed.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelOrange.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelLightBlue.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
panelGray.MouseDown += PanelColor_MouseDown;
|
|
|
|
|
buttonCancel.Click += (s, e) => Close();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Отрисовка объекта
|
|
|
|
|
/// </summary>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
private void DrawTruck()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_truck?.SetPosition(5, 5);
|
|
|
|
|
_truck?.DrawTransport(gr);
|
|
|
|
|
pictureBoxObject.Image = bmp;
|
|
|
|
|
}
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>labelSimpleObject
|
|
|
|
|
/// Добавление события
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ev">Привязанный методlabelSimpleObject</param>labelSimpleObject
|
2024-10-03 01:43:12 +04:00
|
|
|
|
public void AddEvent(Action<DrawingTruck> ev)
|
|
|
|
|
{
|
|
|
|
|
if (EventAddTruck == null)
|
|
|
|
|
{
|
|
|
|
|
EventAddTruck = ev;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EventAddTruck += ev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
|
|
|
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Действия при приеме перетаскиваемой информации (имени Label)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
|
|
|
|
{
|
|
|
|
|
case "labelSimpleObject":
|
|
|
|
|
_truck = new DrawingTruck(
|
|
|
|
|
(int)numericUpDownSpeed.Value,
|
|
|
|
|
(int)numericUpDownWeight.Value,
|
|
|
|
|
Color.White,
|
|
|
|
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "labelAdvancedObject":
|
|
|
|
|
_truck = new DrawingGasolineTanker(
|
|
|
|
|
(int)numericUpDownSpeed.Value,
|
|
|
|
|
(int)numericUpDownWeight.Value,
|
|
|
|
|
Color.White, Color.Black,
|
|
|
|
|
checkBoxTanker.Checked, checkBoxWheel.Checked,
|
|
|
|
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DrawTruck();
|
|
|
|
|
}
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача цвета при нажатии на одну из Panel с цветом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
|
|
|
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
|
}
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проверка получаемой информации (ее типа на соответствие требуемому: цвет) для Label с основным цветом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
private void LabelMainColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)) && _truck != null)
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 01:44:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Действия при приеме перетаскиваемого цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-10-03 01:43:12 +04:00
|
|
|
|
private void LabelMainColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var color = (Color)e.Data.GetData(typeof(Color));
|
|
|
|
|
_truck.EntityTruck.ChangeBodyColor(color);
|
|
|
|
|
DrawTruck();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(typeof(Color)) && _truck != null && _truck is DrawingGasolineTanker)
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var color = (Color)e.Data.GetData(typeof(Color));
|
|
|
|
|
|
|
|
|
|
EntityGasolineTanker? _gasolinetanker = _truck.EntityTruck as EntityGasolineTanker;
|
|
|
|
|
_gasolinetanker.ChangeAdditionalColor(color);
|
|
|
|
|
DrawTruck();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EventAddTruck?.Invoke(_truck);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|