Laba5 PIbd-22 Kalyshev Y V #8

Closed
Zyzf wants to merge 3 commits from Laba5 into Laba4
3 changed files with 28 additions and 22 deletions
Showing only changes of commit 37d7812381 - Show all commits

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
/// <summary>
/// Делегат для передачи объекта-автомобиля
/// </summary>
/// <param name="car"></param>
public delegate void BoatDelegate(DrawningBoat boat);
}

View File

@ -22,7 +22,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
/// <summary>
/// Событие
/// </summary>
private event BoatDelegate EventAddBoat;
private event Action<DrawningBoat> EventAddBoat;
/// <summary>
/// Конструктор
/// </summary>
@ -38,7 +38,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Отрисовать машину
@ -55,11 +55,11 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(BoatDelegate ev)
public void AddEvent(Action<DrawningBoat> ev)
{
if (EventAddBoat == null)
{
EventAddBoat = new BoatDelegate(ev);
EventAddBoat = new Action<DrawningBoat>(ev);
}
else
{
@ -142,7 +142,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
/// <param name="e"></param>
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat == null)
if (_boat == null || !e.Data.GetDataPresent(typeof(Color)))
{
return;
}
@ -156,11 +156,14 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
/// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat == null || _boat.GetType() != typeof(DrawningSpeedboat))
if (_boat == null || _boat.GetType() != typeof(DrawningSpeedboat) || !e.Data.GetDataPresent(typeof(Color)))
{
return;
}
//TODO
if (_boat.Boat is EntitySpeedboat advboat)
{
advboat.DopColor = (Color)e.Data.GetData(typeof(Color));
}
DrawBoat();
}
/// <summary>

View File

@ -103,9 +103,26 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
private void ButtonAddBoat_Click(object sender, EventArgs e)
{
var formBoatConfig = new FormBoatConfig();
//TODO Call method AddEvent from formBoatConfig
formBoatConfig.AddEvent(AddBoat);
formBoatConfig.Show();
}
private void AddBoat(DrawningBoat drawingBoats)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawningObjectBoat boat = new DrawningObjectBoat(drawingBoats);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != -1)
{
MessageBox.Show("Object added");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Cant add object");
}
}
/// <summary>
/// Удаление объекта
/// </summary>