Прописана логика в методах DragDrop для основного и дополнительного цвета
This commit is contained in:
parent
1a1ea1e996
commit
f62db7d97c
@ -22,7 +22,7 @@ namespace AccordionBus
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event BusDelegate EventAddBus;
|
||||
private event Action<DrawningBus> EventAddBus;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -37,6 +37,7 @@ namespace AccordionBus
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать автобус
|
||||
@ -53,11 +54,11 @@ namespace AccordionBus
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev"></param>
|
||||
public void AddEvent(BusDelegate ev)
|
||||
public void AddEvent(Action<DrawningBus> ev)
|
||||
{
|
||||
if (EventAddBus == null)
|
||||
{
|
||||
EventAddBus = new BusDelegate(ev);
|
||||
EventAddBus = new(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -118,13 +119,14 @@ namespace AccordionBus
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// Устанавливает статус перемещаемых данных
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
|
||||
/// <param name="needTypeData">Тип которого должны соответствовать перемещаемые данные</param>
|
||||
/// <param name="condition">Условие на возможность копирования данных</param>
|
||||
private void SetDragEffect(DragEventArgs e, Type needTypeData, bool condition)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
if (e.Data.GetDataPresent(needTypeData) && condition)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
@ -134,13 +136,30 @@ namespace AccordionBus
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) => SetDragEffect(e, typeof(Color), _bus != null);
|
||||
private void LabelDopColor_DragEnter(object sender, DragEventArgs e) => SetDragEffect(e, typeof(Color), _bus != null && _bus is DrawningAccordionBus);
|
||||
/// <summary>
|
||||
/// Принимаем основной цвет
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
// TODO Call method from object _car and set color
|
||||
var color = (Color)e.Data.GetData(typeof(Color));
|
||||
if (_bus is DrawningAccordionBus)
|
||||
{
|
||||
var a = (EntityAccordionBus)_bus.Bus;
|
||||
_bus = new DrawningAccordionBus(a.Speed, a.Weight, color, a.DopColor, a.Compartment, a.RearviewMirror, a.BusNumber);
|
||||
}
|
||||
else if (_bus is DrawningBus)
|
||||
{
|
||||
_bus = new DrawningBus(_bus.Bus.Speed, _bus.Bus.Weight, color);
|
||||
}
|
||||
DrawBus();
|
||||
}
|
||||
/// <summary>
|
||||
/// Принимаем дополнительный цвет
|
||||
@ -149,7 +168,13 @@ namespace AccordionBus
|
||||
/// <param name="e"></param>
|
||||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
// TODO Call method from object _car if _car is DrawningSportCar and set dop color
|
||||
var color = (Color)e.Data.GetData(typeof(Color));
|
||||
if (_bus is DrawningAccordionBus)
|
||||
{
|
||||
var a = (EntityAccordionBus)_bus.Bus;
|
||||
_bus = new DrawningAccordionBus(a.Speed, a.Weight, a.BodyColor, color, a.Compartment, a.RearviewMirror, a.BusNumber);
|
||||
}
|
||||
DrawBus();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление автобуса
|
||||
|
@ -106,33 +106,35 @@ namespace AccordionBus
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// Вызов формы для создания автобуса
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formBusConfig = new FormBusConfig();
|
||||
// TODO Call method AddEvent from formCarConfig
|
||||
formBusConfig.Show();
|
||||
//if (listBoxMaps.SelectedIndex == -1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//FormBus form = new();
|
||||
//if (form.ShowDialog() == DialogResult.OK)
|
||||
//{
|
||||
// DrawningObjectBus bus = new(form.SelectedBus);
|
||||
// if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1)
|
||||
// {
|
||||
// MessageBox.Show("Объект добавлен");
|
||||
// pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageBox.Show("Не удалось добавить объект");
|
||||
// }
|
||||
//}
|
||||
FormBusConfig formBus = new();
|
||||
formBus.AddEvent(new(AddBus));
|
||||
formBus.Show();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="bus"></param>
|
||||
private void AddBus(DrawningBus bus)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
|
||||
}
|
||||
else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectBus(bus) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
|
Loading…
x
Reference in New Issue
Block a user