последний вариант

This commit is contained in:
ikswi 2024-04-04 09:42:34 +04:00
parent 4909a7ffea
commit 12dd60db3f
4 changed files with 35 additions and 57 deletions

View File

@ -7,7 +7,7 @@ public class EntityAirFighter : EntityMilitaryAircraft
{ {
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public void ChooseAdditionalColor(Color additionalColor) public void SetAdditionalColor(Color additionalColor)
{ {
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
} }

View File

@ -11,7 +11,7 @@ public class EntityMilitaryAircraft
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public void ChooseBodyColor(Color bodyColor) public void SetBodyColor(Color bodyColor)
{ {
BodyColor = bodyColor; BodyColor = bodyColor;
} }

View File

@ -163,21 +163,21 @@
// checkBoxRockets // checkBoxRockets
// //
checkBoxRockets.AutoSize = true; checkBoxRockets.AutoSize = true;
checkBoxRockets.Location = new Point(12, 154); checkBoxRockets.Location = new Point(6, 154);
checkBoxRockets.Name = "checkBoxRockets"; checkBoxRockets.Name = "checkBoxRockets";
checkBoxRockets.Size = new Size(318, 24); checkBoxRockets.Size = new Size(339, 24);
checkBoxRockets.TabIndex = 7; checkBoxRockets.TabIndex = 7;
checkBoxRockets.Text = "Признак наличия дополнительных ракет"; checkBoxRockets.Text = "Признак наличия дополнительных крыльев";
checkBoxRockets.UseVisualStyleBackColor = true; checkBoxRockets.UseVisualStyleBackColor = true;
// //
// checkBoxWings // checkBoxWings
// //
checkBoxWings.AutoSize = true; checkBoxWings.AutoSize = true;
checkBoxWings.Location = new Point(12, 124); checkBoxWings.Location = new Point(6, 124);
checkBoxWings.Name = "checkBoxWings"; checkBoxWings.Name = "checkBoxWings";
checkBoxWings.Size = new Size(339, 24); checkBoxWings.Size = new Size(318, 24);
checkBoxWings.TabIndex = 6; checkBoxWings.TabIndex = 6;
checkBoxWings.Text = "Признак наличия дополнительных крыльев"; checkBoxWings.Text = "Признак наличия дополнительных ракет";
checkBoxWings.UseVisualStyleBackColor = true; checkBoxWings.UseVisualStyleBackColor = true;
// //
// numericUpDownWeight // numericUpDownWeight
@ -282,27 +282,29 @@
// //
// labelAdditionalColor // labelAdditionalColor
// //
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(100, 12); labelAdditionalColor.Location = new Point(100, 9);
labelAdditionalColor.Name = "labelAdditionalColor"; labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(88, 24); labelAdditionalColor.Size = new Size(88, 36);
labelAdditionalColor.TabIndex = 2; labelAdditionalColor.TabIndex = 2;
labelAdditionalColor.Text = "Доп. цвет"; labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += LabelColor_DragDrop; labelAdditionalColor.DragDrop += LabelColors_DragDrop;
labelAdditionalColor.DragEnter += LabelColor_DragEnter; labelAdditionalColor.DragEnter += LabelColors_DragEnter;
// //
// labelBodyColor // labelBodyColor
// //
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle; labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Location = new Point(3, 12); labelBodyColor.Location = new Point(3, 9);
labelBodyColor.Name = "labelBodyColor"; labelBodyColor.Name = "labelBodyColor";
labelBodyColor.Size = new Size(88, 24); labelBodyColor.Size = new Size(88, 36);
labelBodyColor.TabIndex = 1; labelBodyColor.TabIndex = 1;
labelBodyColor.Text = "Цвет"; labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += LabelColor_DragDrop; labelBodyColor.DragDrop += LabelColors_DragDrop;
labelBodyColor.DragEnter += LabelColor_DragEnter; labelBodyColor.DragEnter += LabelColors_DragEnter;
// //
// FormMilitaryAircraftConfig // FormMilitaryAircraftConfig
// //

View File

@ -41,14 +41,7 @@ public partial class FormMilitaryAircraftConfig : Form
/// <param name="militaryAircraftDelegate"></param> /// <param name="militaryAircraftDelegate"></param>
public void AddEvent(Action<DrawningMilitaryAircraft> militaryAircraftDelegate) public void AddEvent(Action<DrawningMilitaryAircraft> militaryAircraftDelegate)
{ {
if (MilitaryAircraftDelegate == null) MilitaryAircraftDelegate += militaryAircraftDelegate;
{
MilitaryAircraftDelegate = militaryAircraftDelegate;
}
else
{
MilitaryAircraftDelegate += militaryAircraftDelegate;
}
} }
/// <summary> /// <summary>
@ -71,8 +64,6 @@ public partial class FormMilitaryAircraftConfig : Form
/// <param name="e"></param> /// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e) private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{ {
//var label = sender as Label;
//label.DoDragDrop(label.Name, DragDropEffects.Move);
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
} }
@ -83,14 +74,7 @@ public partial class FormMilitaryAircraftConfig : Form
/// <param name="e"></param> /// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e) private void PanelObject_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
} }
/// <summary> /// <summary>
@ -118,31 +102,22 @@ public partial class FormMilitaryAircraftConfig : Form
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param>2 /// <param name="e"></param>2
private void Panel_MouseDown(object? sender, MouseEventArgs e) private void Panel_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
} }
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
/// <summary> /// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому) /// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void LabelColor_DragEnter(object sender, DragEventArgs e) private void LabelColors_DragEnter(object sender, DragEventArgs e)
{ {
//if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
//{
// e.Effect = DragDropEffects.Copy;
//}
//else
//{
// e.Effect = DragDropEffects.None;
//}
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
} }
@ -151,27 +126,28 @@ public partial class FormMilitaryAircraftConfig : Form
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void LabelColor_DragDrop(object sender, DragEventArgs e) private void LabelColors_DragDrop(object sender, DragEventArgs e)
{ {
if (_militaryAircraft == null) if (_militaryAircraft == null)
{ {
return; return;
} }
Label label = (Label)sender; Label label = (Label)sender;
switch (((Label)sender).Name) Color newColor = (Color)e.Data.GetData(typeof(Color).ToString());
switch (label.Name)
{ {
case "labelBodyColor": case "labelBodyColor":
_militaryAircraft.EntityMilitaryAircraft.ChooseBodyColor((Color)e.Data.GetData(typeof(Color))); _militaryAircraft.EntityMilitaryAircraft.SetBodyColor(newColor);
DrawObject();
break; break;
case "labelAdditionalColor": case "labelAdditionalColor":
if (_militaryAircraft is DrawningAirFighter) if (_militaryAircraft is DrawningAirFighter)
{ {
return; (_militaryAircraft.EntityMilitaryAircraft as EntityAirFighter).SetAdditionalColor(newColor);
DrawObject();
} }
(_militaryAircraft.EntityMilitaryAircraft as EntityAirFighter).ChooseAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break; break;
} }
DrawObject();
} }