Релизована логика изменения типов двигателей у самолета

This commit is contained in:
Данияр Аглиуллов 2022-10-18 04:51:49 +04:00
parent 639df36fd9
commit 0a5d9819bc
2 changed files with 32 additions and 6 deletions

View File

@ -111,7 +111,7 @@
this.labelRoundedEngines.TabIndex = 24; this.labelRoundedEngines.TabIndex = 24;
this.labelRoundedEngines.Text = "Закругленный"; this.labelRoundedEngines.Text = "Закругленный";
this.labelRoundedEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelRoundedEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelRoundedEngines.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelTypesOfEngines_MouseDown); this.labelRoundedEngines.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelsTypeOfEngines_MouseDown);
// //
// labelRectEngines // labelRectEngines
// //
@ -122,7 +122,7 @@
this.labelRectEngines.TabIndex = 23; this.labelRectEngines.TabIndex = 23;
this.labelRectEngines.Text = "Квадратный"; this.labelRectEngines.Text = "Квадратный";
this.labelRectEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelRectEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelRectEngines.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelTypesOfEngines_MouseDown); this.labelRectEngines.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelsTypeOfEngines_MouseDown);
// //
// labelArrowEngines // labelArrowEngines
// //
@ -133,7 +133,7 @@
this.labelArrowEngines.TabIndex = 22; this.labelArrowEngines.TabIndex = 22;
this.labelArrowEngines.Text = "Стрелка"; this.labelArrowEngines.Text = "Стрелка";
this.labelArrowEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelArrowEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelArrowEngines.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelTypesOfEngines_MouseDown); this.labelArrowEngines.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelsTypeOfEngines_MouseDown);
// //
// numericUpDownCountEngines // numericUpDownCountEngines
// //
@ -147,7 +147,7 @@
this.numericUpDownCountEngines.Size = new System.Drawing.Size(79, 23); this.numericUpDownCountEngines.Size = new System.Drawing.Size(79, 23);
this.numericUpDownCountEngines.TabIndex = 18; this.numericUpDownCountEngines.TabIndex = 18;
this.numericUpDownCountEngines.Value = new decimal(new int[] { this.numericUpDownCountEngines.Value = new decimal(new int[] {
9, 2,
0, 0,
0, 0,
0}); 0});
@ -371,6 +371,8 @@
this.labelTypesOfEngines.TabIndex = 3; this.labelTypesOfEngines.TabIndex = 3;
this.labelTypesOfEngines.Text = "Тип двигателей"; this.labelTypesOfEngines.Text = "Тип двигателей";
this.labelTypesOfEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelTypesOfEngines.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelTypesOfEngines.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelTypesOfEngines_DragDrop);
this.labelTypesOfEngines.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelTypesOfEngines_DragEnter);
// //
// labelDopColor // labelDopColor
// //

View File

@ -7,6 +7,7 @@ namespace AirBomber
/// </summary> /// </summary>
public partial class FormAirplaneConfig : Form public partial class FormAirplaneConfig : Form
{ {
private Type _currTypeEngines = typeof(DrawningAirplaneEngines);
/// <summary> /// <summary>
/// Переменная-выбранная самолет /// Переменная-выбранная самолет
/// </summary> /// </summary>
@ -181,8 +182,12 @@ namespace AirBomber
EventAddAirplane?.Invoke(_airplane); EventAddAirplane?.Invoke(_airplane);
Close(); Close();
} }
/// <summary>
private void labelTypesOfEngines_MouseDown(object sender, MouseEventArgs e) /// Создание DragAndDrop перемещения по нажатию мыши
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelsTypeOfEngines_MouseDown(object sender, MouseEventArgs e)
{ {
string text = ((Label)sender)?.Text ?? string.Empty; string text = ((Label)sender)?.Text ?? string.Empty;
IAirplaneEngines typesOfEngines; IAirplaneEngines typesOfEngines;
@ -200,7 +205,26 @@ namespace AirBomber
default: default:
return; return;
} }
_currTypeEngines = typesOfEngines.GetType();
(sender as Label).DoDragDrop(typesOfEngines, DragDropEffects.Move | DragDropEffects.Copy); (sender as Label).DoDragDrop(typesOfEngines, DragDropEffects.Move | DragDropEffects.Copy);
} }
private void labelTypesOfEngines_DragDrop(object sender, DragEventArgs e)
{
var engines = (IAirplaneEngines)e.Data.GetData(_currTypeEngines);
engines.CountEngines = _airplane.DrawningEngines.CountEngines;
if (_airplane is DrawningAirBomber)
{
var a = (EntityAirBomber)_airplane.Airplane;
_airplane = new DrawningAirBomber(a.Speed, a.Weight, a.BodyColor, a.DopColor, a.HasBombs, a.HasFuelTanks, engines);
}
else if (_airplane is DrawningAirplane)
{
_airplane = new DrawningAirplane(_airplane.Airplane.Speed, _airplane.Airplane.Weight, _airplane.Airplane.BodyColor, engines);
}
DrawAirplane();
}
private void labelTypesOfEngines_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, _currTypeEngines, _airplane != null);
} }
} }