Event work

This commit is contained in:
crum61kg 2023-01-23 02:12:44 +04:00
parent c58ecbd47e
commit a51a6a2102
3 changed files with 52 additions and 54 deletions

View File

@ -20,6 +20,10 @@ namespace WarmlyShip
/// </summary> /// </summary>
DrawningShip _ship = null; DrawningShip _ship = null;
/// <summary> /// <summary>
/// Событие
/// </summary>
private event ShipDelegate EventAddShip;
/// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormLinerConfig() public FormLinerConfig()
@ -33,6 +37,9 @@ namespace WarmlyShip
panelWhite.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda
} }
/// <summary> /// <summary>
/// Отрисовать машину /// Отрисовать машину
@ -46,6 +53,22 @@ namespace WarmlyShip
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(ShipDelegate ev)
{
if (EventAddShip == null)
{
EventAddShip = new ShipDelegate(ev);
}
else
{
EventAddShip += ev;
}
}
/// <summary> /// <summary>
/// Передаем информацию при нажатии на Label /// Передаем информацию при нажатии на Label
/// </summary> /// </summary>
@ -136,5 +159,16 @@ namespace WarmlyShip
// TODO Call method from object _car if _car is DrawningSportCar and set dop color // TODO Call method from object _car if _car is DrawningSportCar and set dop color
} }
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddShip?.Invoke(_ship);
Close();
}
} }
} }

View File

@ -26,13 +26,6 @@ namespace WarmlyShip
/// </summary> /// </summary>
private readonly MapsCollection _mapsCollection; private readonly MapsCollection _mapsCollection;
///// <summary>
///// Объект от класса карты с набором объектов
///// </summary>
//private MapWithSetWarmlyShipGeneric<DrawningObjectShip, AbstractMap> _mapWarmlyShipCollectionGeneric;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -96,35 +89,6 @@ namespace WarmlyShip
pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
///// <summary>
///// Выбор карты
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void ComboBoxSelectorShip_SelectedIndexChanged(object sender, EventArgs e)
//{
// AbstractMap map = null;
// switch (comboBoxSelectorMap.Text)
// {
// case "Простая карта":
// map = new SimpleMap();
// break;
// case "Море":
// map = new MyMap();
// break;
// }
// if (map != null)
// {
// _mapWarmlyShipCollectionGeneric = new MapWithSetWarmlyShipGeneric<DrawningObjectShip, AbstractMap>(
// pictureBox1.Width, pictureBox1.Height, map);
// }
// else
// {
// _mapWarmlyShipCollectionGeneric = null;
// }
//}
/// <summary> /// <summary>
/// Удаление карты /// Удаление карты
/// </summary> /// </summary>
@ -149,24 +113,9 @@ namespace WarmlyShip
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddShip_Click(object sender, EventArgs e) private void ButtonAddShip_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1) var formCarConfig = new FormLinerConfig();
{ // TODO Call method AddEvent from formCarConfig
return; formCarConfig.Show();
}
FormShip form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectShip ship = new(form.SelectedShip);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + ship!=null)
{
MessageBox.Show("Объект добавлен");
pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
} }

View File

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