146 lines
4.7 KiB
C#
146 lines
4.7 KiB
C#
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 DoubleDeckerbus.Drawing;
|
|
using DoubleDeckerbus.Entities;
|
|
|
|
namespace DoubleDeckerbus
|
|
{
|
|
public partial class FormBusConfig : Form
|
|
{
|
|
|
|
DrawingBus? _bus = null;
|
|
private event Action<DrawingBus>? EventAddBus;
|
|
public FormBusConfig()
|
|
{
|
|
InitializeComponent();
|
|
panelFirebrick.MouseDown += PanelColor_MouseDown;
|
|
panelRoyalBlue.MouseDown += PanelColor_MouseDown;
|
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
|
panelPink.MouseDown += PanelColor_MouseDown;
|
|
panelGray.MouseDown += PanelColor_MouseDown;
|
|
buttonCancel.Click += (s, e) => Close();
|
|
}
|
|
private void DrawBus()
|
|
{
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_bus?.SetPosition(5, 5);
|
|
_bus?.DrawTransport(gr);
|
|
pictureBoxObject.Image = bmp;
|
|
}
|
|
public void AddEvent(Action<DrawingBus> ev)
|
|
{
|
|
if (EventAddBus == null)
|
|
{
|
|
EventAddBus = ev;
|
|
}
|
|
else
|
|
{
|
|
EventAddBus += 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;
|
|
}
|
|
}
|
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
|
{
|
|
case "labelSimpleObject":
|
|
_bus = new DrawingBus(
|
|
(int)numericUpDownSpeed.Value,
|
|
(int)numericUpDownWeight.Value,
|
|
Color.White,
|
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|
break;
|
|
|
|
case "labelAdvancedObject":
|
|
_bus = new DrawingDoubleDeckerbus(
|
|
(int)numericUpDownSpeed.Value,
|
|
(int)numericUpDownWeight.Value,
|
|
Color.White, Color.Black,
|
|
checkBoxSecondFloor.Checked, checkBoxLadder.Checked,
|
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|
break;
|
|
}
|
|
DrawBus();
|
|
}
|
|
|
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|
}
|
|
|
|
private void LabelMainColor_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(typeof(Color)) && _bus != null)
|
|
{
|
|
e.Effect = DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
|
|
private void LabelMainColor_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
var color = (Color)e.Data.GetData(typeof(Color));
|
|
_bus.EntityBus.ChangeBodyColor(color);
|
|
DrawBus();
|
|
}
|
|
|
|
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(typeof(Color)) && _bus != null && _bus is DrawingDoubleDeckerbus)
|
|
{
|
|
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));
|
|
|
|
EntityDoubleDeckerbus? _doubledeckerbus = _bus.EntityBus as EntityDoubleDeckerbus;
|
|
_doubledeckerbus.ChangeAdditionalColor(color);
|
|
DrawBus();
|
|
}
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
{
|
|
EventAddBus?.Invoke(_bus);
|
|
Close();
|
|
}
|
|
}
|
|
}
|