Выполнена
This commit is contained in:
parent
456bbc76a9
commit
35ffb3bc7f
@ -25,6 +25,8 @@ public class EntityBoat
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
//public string SetBodyColor => BodyColor.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
@ -37,4 +39,9 @@ public class EntityBoat
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color name)
|
||||
{
|
||||
BodyColor = name;
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +43,9 @@ public class EntityMotorBoat : EntityBoat
|
||||
Oar = oar;
|
||||
ProtectiveGlass = protectiveGlass;
|
||||
}
|
||||
|
||||
public void SetAdditionalColor(Color name)
|
||||
{
|
||||
AdditionalColor = name;
|
||||
}
|
||||
}
|
@ -45,14 +45,15 @@ public partial class FormBoatCollection : Form
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormBoatConfig form = new();
|
||||
// TODO передать метод
|
||||
form.Show();
|
||||
// передать метод ✔
|
||||
form.AddEvent(SetBoat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление лодки в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="car"></param>
|
||||
/// <param name="boat"></param>
|
||||
private void SetBoat(DrawingBoat boat)
|
||||
{
|
||||
if (_company == null || boat == null)
|
||||
@ -60,7 +61,7 @@ public partial class FormBoatCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + boat > 0)
|
||||
if (_company + boat >= 0)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
@ -105,6 +105,7 @@
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(28, 28);
|
||||
panelBlack.TabIndex = 3;
|
||||
panelBlack.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
@ -113,6 +114,7 @@
|
||||
panelWhite.Name = "panelWhite";
|
||||
panelWhite.Size = new Size(28, 28);
|
||||
panelWhite.TabIndex = 4;
|
||||
panelWhite.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelPink
|
||||
//
|
||||
@ -121,6 +123,7 @@
|
||||
panelPink.Name = "panelPink";
|
||||
panelPink.Size = new Size(28, 28);
|
||||
panelPink.TabIndex = 1;
|
||||
panelPink.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
@ -129,6 +132,7 @@
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(28, 28);
|
||||
panelRed.TabIndex = 5;
|
||||
panelRed.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
@ -137,6 +141,7 @@
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(28, 28);
|
||||
panelYellow.TabIndex = 1;
|
||||
panelYellow.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
@ -145,6 +150,7 @@
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(28, 28);
|
||||
panelBlue.TabIndex = 2;
|
||||
panelBlue.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
@ -153,6 +159,7 @@
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(28, 28);
|
||||
panelGreen.TabIndex = 1;
|
||||
panelGreen.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelOrange
|
||||
//
|
||||
@ -161,6 +168,7 @@
|
||||
panelOrange.Name = "panelOrange";
|
||||
panelOrange.Size = new Size(28, 28);
|
||||
panelOrange.TabIndex = 0;
|
||||
panelOrange.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// checkBoxProtectiveGlass
|
||||
//
|
||||
@ -255,6 +263,7 @@
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
panelObject.AllowDrop = true;
|
||||
panelObject.Controls.Add(labelAdditionalColor);
|
||||
panelObject.Controls.Add(labelBodyColor);
|
||||
panelObject.Controls.Add(pictureBoxObject);
|
||||
@ -267,6 +276,7 @@
|
||||
//
|
||||
// labelAdditionalColor
|
||||
//
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new Point(109, 6);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
@ -274,9 +284,12 @@
|
||||
labelAdditionalColor.TabIndex = 11;
|
||||
labelAdditionalColor.Text = "Доп. цвет";
|
||||
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop;
|
||||
labelAdditionalColor.DragEnter += LabelColor_DragEnter;
|
||||
//
|
||||
// labelBodyColor
|
||||
//
|
||||
labelBodyColor.AllowDrop = true;
|
||||
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelBodyColor.Location = new Point(14, 6);
|
||||
labelBodyColor.Name = "labelBodyColor";
|
||||
@ -284,12 +297,14 @@
|
||||
labelBodyColor.TabIndex = 10;
|
||||
labelBodyColor.Text = "Цвет";
|
||||
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelBodyColor.DragDrop += LabelBodyColor_DragDrop;
|
||||
labelBodyColor.DragEnter += LabelColor_DragEnter;
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(14, 37);
|
||||
pictureBoxObject.Location = new Point(14, 47);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(185, 127);
|
||||
pictureBoxObject.Size = new Size(185, 117);
|
||||
pictureBoxObject.TabIndex = 0;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectMotorBoat.Drawings;
|
||||
using ProjectMotorBoat.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Форма конфигурации объекта
|
||||
@ -15,13 +16,14 @@ namespace ProjectMotorBoat
|
||||
/// <summary>
|
||||
/// Событие для предачи объекта
|
||||
/// </summary>
|
||||
private event BoatDelegate BoatDelegate;
|
||||
Action<DrawingBoat> BoatDelegate;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBoatConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelPink.MouseDown += Panel_MouseDown;
|
||||
panelOrange.MouseDown += Panel_MouseDown;
|
||||
panelYellow.MouseDown += Panel_MouseDown;
|
||||
@ -31,15 +33,15 @@ namespace ProjectMotorBoat
|
||||
panelWhite.MouseDown += Panel_MouseDown;
|
||||
panelRed.MouseDown += Panel_MouseDown;
|
||||
|
||||
// TODO buttonCancel.Click привязать анонимный метод через lambda с закрытием формы
|
||||
InitializeComponent();
|
||||
// buttonCancel.Click привязать анонимный метод через lambda с закрытием формы ✔
|
||||
buttonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Привязка внешнего метода к событию
|
||||
/// </summary>
|
||||
/// <param name="carDelegate"></param>
|
||||
public void AddEvent(BoatDelegate boatDelegate)
|
||||
/// <param name="boatDelegate"></param>
|
||||
public void AddEvent(Action<DrawingBoat> boatDelegate)
|
||||
{
|
||||
BoatDelegate += boatDelegate;
|
||||
}
|
||||
@ -77,6 +79,11 @@ namespace ProjectMotorBoat
|
||||
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
|
||||
@ -100,10 +107,40 @@ namespace ProjectMotorBoat
|
||||
/// <param name="e"></param>
|
||||
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
||||
{
|
||||
// TODO отправка цвета в Drag&Drop
|
||||
// отправка цвета в Drag&Drop ✔
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
|
||||
// Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) ✔
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_boat != null)
|
||||
{
|
||||
_boat?.EntityBoat?.SetBodyColor(Color.FromName(e.Data?.GetData(DataFormats.Text)?.ToString()));
|
||||
DrawObject();
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_boat?.EntityBoat is EntityMotorBoat _motorBoat)
|
||||
{
|
||||
_motorBoat?.SetAdditionalColor(Color.FromName(e.Data?.GetData(DataFormats.Text)?.ToString()));
|
||||
DrawObject();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передача объекта
|
||||
|
Loading…
Reference in New Issue
Block a user