Готовая сданная Лабороторная работа 5

This commit is contained in:
Sem730 2022-11-09 09:00:00 +03:00
parent 13a3089093
commit 9957a82e36
9 changed files with 187 additions and 110 deletions

View File

@ -24,6 +24,15 @@ namespace ProjectLocomotive
Locomotivе = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, electroLines, Locomotivе = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, electroLines,
electroBattery); electroBattery);
} }
public void SetExtraColor(Color color)
{
var LocomotiveElectro = Locomotivе as EntityElectricLocomotive;
if (LocomotiveElectro is not null)
{
LocomotiveElectro = new EntityElectricLocomotive(LocomotiveElectro.Speed, LocomotiveElectro.Weight, LocomotiveElectro.BodyColor, color, LocomotiveElectro.ElectroLines, LocomotiveElectro.ElectroBattery);
Locomotivе = LocomotiveElectro;
}
}
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (Locomotivе is not EntityElectricLocomotive elLocc) if (Locomotivе is not EntityElectricLocomotive elLocc)
@ -31,7 +40,7 @@ namespace ProjectLocomotive
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(elLocc.DopColor);
if (elLocc.ElectroLines) if (elLocc.ElectroLines)
{ {
g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12); g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12);
@ -43,10 +52,10 @@ namespace ProjectLocomotive
base.DrawTransport(g); base.DrawTransport(g);
if (elLocc.ElectroBattery) if (elLocc.ElectroBattery)
{ {
Brush brblack = new SolidBrush(Color.Black); Brush dopBrush = new SolidBrush(elLocc.DopColor);
g.FillRectangle(brblack, _startPosX + 40, _startPosY + 25, 15, 5); g.FillRectangle(dopBrush, _startPosX + 40, _startPosY + 25, 15, 5);
g.FillRectangle(brblack, _startPosX + 60, _startPosY + 25, 15, 5); g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 25, 15, 5);
g.FillRectangle(brblack, _startPosX + 5, _startPosY + 25, 15, 5); g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 25, 15, 5);
} }
} }
} }

View File

@ -64,6 +64,18 @@ namespace ProjectLocomotive
_LocWidth = carWidth; _LocWidth = carWidth;
_LocHeight = carHeight; _LocHeight = carHeight;
} }
public void SetBaseColor(Color color)
{
if (Locomotivе is EntityElectricLocomotive)
{
Locomotivе = (EntityElectricLocomotive)Locomotivе;
if (Locomotivе is not null)
{
Locomotivе = new EntityElectricLocomotive(Locomotivе.Speed, Locomotivе.Weight, color, (Locomotivе as EntityElectricLocomotive).DopColor, (Locomotivе as EntityElectricLocomotive).ElectroLines, (Locomotivе as EntityElectricLocomotive).ElectroBattery);
return;
}
}
}
/// <summary> /// <summary>
/// Установка позиции автомобиля /// Установка позиции автомобиля
/// </summary> /// </summary>

View File

@ -11,7 +11,7 @@ namespace ProjectLocomotive
/// <summary> /// <summary>
/// Дополнительный цвет /// Дополнительный цвет
/// </summary> /// </summary>
public Color DopColor { get; private set; } public Color DopColor { get; set; }
/// <summary> /// <summary>
/// Признак наличия "рогов" для подключения /// Признак наличия "рогов" для подключения
/// </summary> /// </summary>
@ -34,8 +34,8 @@ namespace ProjectLocomotive
base(speed, weight, bodyColor) base(speed, weight, bodyColor)
{ {
DopColor = dopColor; DopColor = dopColor;
ElectroLines = electroLines = true; ElectroLines = electroLines;
ElectroBattery = electroBattery = true; ElectroBattery = electroBattery;
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace ProjectLocomotive
/// <summary> /// <summary>
/// Цвет кузова /// Цвет кузова
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
/// <summary> /// <summary>
/// Шаг передвижения локомотива /// Шаг передвижения локомотива
/// </summary> /// </summary>

View File

@ -188,9 +188,7 @@
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
} }
#endregion #endregion
private PictureBox pictureBoxLocomotive; private PictureBox pictureBoxLocomotive;
private Button buttonCreate; private Button buttonCreate;
private Button buttonUp; private Button buttonUp;

View File

@ -6,7 +6,6 @@
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
@ -19,9 +18,7 @@
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
@ -71,32 +68,36 @@
this.groupBoxConfig.Controls.Add(this.labelWeight); this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.labelSpeed); this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12); this.groupBoxConfig.Location = new System.Drawing.Point(15, 15);
this.groupBoxConfig.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxConfig.Name = "groupBoxConfig"; this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(453, 260); this.groupBoxConfig.Padding = new System.Windows.Forms.Padding(4);
this.groupBoxConfig.Size = new System.Drawing.Size(566, 325);
this.groupBoxConfig.TabIndex = 0; this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false; this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Configuration"; this.groupBoxConfig.Text = "Конфигурация";
// //
// labelModifiedObject // labelModifiedObject
// //
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(312, 200); this.labelModifiedObject.Location = new System.Drawing.Point(390, 250);
this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelModifiedObject.Name = "labelModifiedObject"; this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(115, 45); this.labelModifiedObject.Size = new System.Drawing.Size(143, 56);
this.labelModifiedObject.TabIndex = 8; this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Modified"; this.labelModifiedObject.Text = "Модифицированный";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
// //
// labelSimpleObject // labelSimpleObject
// //
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(179, 200); this.labelSimpleObject.Location = new System.Drawing.Point(224, 250);
this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelSimpleObject.Name = "labelSimpleObject"; this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(115, 45); this.labelSimpleObject.Size = new System.Drawing.Size(143, 56);
this.labelSimpleObject.TabIndex = 7; this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Simple"; this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
// //
@ -110,102 +111,123 @@
this.groupBoxColors.Controls.Add(this.panelGreen); this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelBlue); this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelRed); this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(179, 26); this.groupBoxColors.Location = new System.Drawing.Point(224, 32);
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxColors.Name = "groupBoxColors"; this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(248, 156); this.groupBoxColors.Padding = new System.Windows.Forms.Padding(4);
this.groupBoxColors.Size = new System.Drawing.Size(310, 195);
this.groupBoxColors.TabIndex = 6; this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false; this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Colors"; this.groupBoxColors.Text = "Цвета";
// //
// panelPurple // panelPurple
// //
this.panelPurple.BackColor = System.Drawing.Color.Fuchsia; this.panelPurple.BackColor = System.Drawing.Color.Fuchsia;
this.panelPurple.Location = new System.Drawing.Point(193, 102); this.panelPurple.Location = new System.Drawing.Point(241, 128);
this.panelPurple.Margin = new System.Windows.Forms.Padding(4);
this.panelPurple.Name = "panelPurple"; this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(43, 40); this.panelPurple.Size = new System.Drawing.Size(54, 50);
this.panelPurple.TabIndex = 3; this.panelPurple.TabIndex = 3;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelBlack // panelBlack
// //
this.panelBlack.BackColor = System.Drawing.Color.Black; this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(132, 102); this.panelBlack.Location = new System.Drawing.Point(165, 128);
this.panelBlack.Margin = new System.Windows.Forms.Padding(4);
this.panelBlack.Name = "panelBlack"; this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(43, 40); this.panelBlack.Size = new System.Drawing.Size(54, 50);
this.panelBlack.TabIndex = 2; this.panelBlack.TabIndex = 2;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelGray // panelGray
// //
this.panelGray.BackColor = System.Drawing.Color.Gray; this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(72, 102); this.panelGray.Location = new System.Drawing.Point(90, 128);
this.panelGray.Margin = new System.Windows.Forms.Padding(4);
this.panelGray.Name = "panelGray"; this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(43, 40); this.panelGray.Size = new System.Drawing.Size(54, 50);
this.panelGray.TabIndex = 3; this.panelGray.TabIndex = 3;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelWhite // panelWhite
// //
this.panelWhite.BackColor = System.Drawing.Color.White; this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(11, 102); this.panelWhite.Location = new System.Drawing.Point(14, 128);
this.panelWhite.Margin = new System.Windows.Forms.Padding(4);
this.panelWhite.Name = "panelWhite"; this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(43, 40); this.panelWhite.Size = new System.Drawing.Size(54, 50);
this.panelWhite.TabIndex = 2; this.panelWhite.TabIndex = 2;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelYellow // panelYellow
// //
this.panelYellow.BackColor = System.Drawing.Color.Yellow; this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(193, 31); this.panelYellow.Location = new System.Drawing.Point(241, 39);
this.panelYellow.Margin = new System.Windows.Forms.Padding(4);
this.panelYellow.Name = "panelYellow"; this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(43, 40); this.panelYellow.Size = new System.Drawing.Size(54, 50);
this.panelYellow.TabIndex = 1; this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelGreen // panelGreen
// //
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.panelGreen.Location = new System.Drawing.Point(72, 31); this.panelGreen.Location = new System.Drawing.Point(90, 39);
this.panelGreen.Margin = new System.Windows.Forms.Padding(4);
this.panelGreen.Name = "panelGreen"; this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(43, 40); this.panelGreen.Size = new System.Drawing.Size(54, 50);
this.panelGreen.TabIndex = 1; this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelBlue // panelBlue
// //
this.panelBlue.BackColor = System.Drawing.Color.Blue; this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(133, 31); this.panelBlue.Location = new System.Drawing.Point(166, 39);
this.panelBlue.Margin = new System.Windows.Forms.Padding(4);
this.panelBlue.Name = "panelBlue"; this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(43, 40); this.panelBlue.Size = new System.Drawing.Size(54, 50);
this.panelBlue.TabIndex = 1; this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelRed // panelRed
// //
this.panelRed.BackColor = System.Drawing.Color.Red; this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(11, 31); this.panelRed.Location = new System.Drawing.Point(14, 39);
this.panelRed.Margin = new System.Windows.Forms.Padding(4);
this.panelRed.Name = "panelRed"; this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(43, 40); this.panelRed.Size = new System.Drawing.Size(54, 50);
this.panelRed.TabIndex = 0; this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// checkBoxFuelStorage // checkBoxFuelStorage
// //
this.checkBoxFuelStorage.AutoSize = true; this.checkBoxFuelStorage.AutoSize = true;
this.checkBoxFuelStorage.Location = new System.Drawing.Point(7, 158); this.checkBoxFuelStorage.Location = new System.Drawing.Point(9, 198);
this.checkBoxFuelStorage.Margin = new System.Windows.Forms.Padding(4);
this.checkBoxFuelStorage.Name = "checkBoxFuelStorage"; this.checkBoxFuelStorage.Name = "checkBoxFuelStorage";
this.checkBoxFuelStorage.Size = new System.Drawing.Size(146, 24); this.checkBoxFuelStorage.Size = new System.Drawing.Size(207, 29);
this.checkBoxFuelStorage.TabIndex = 5; this.checkBoxFuelStorage.TabIndex = 5;
this.checkBoxFuelStorage.Text = "Add Fuel Storage"; this.checkBoxFuelStorage.Text = "Добавление батарей";
this.checkBoxFuelStorage.UseVisualStyleBackColor = true; this.checkBoxFuelStorage.UseVisualStyleBackColor = true;
// //
// checkBoxPipe // checkBoxPipe
// //
this.checkBoxPipe.AutoSize = true; this.checkBoxPipe.AutoSize = true;
this.checkBoxPipe.Location = new System.Drawing.Point(7, 128); this.checkBoxPipe.Location = new System.Drawing.Point(9, 160);
this.checkBoxPipe.Margin = new System.Windows.Forms.Padding(4);
this.checkBoxPipe.Name = "checkBoxPipe"; this.checkBoxPipe.Name = "checkBoxPipe";
this.checkBoxPipe.Size = new System.Drawing.Size(92, 24); this.checkBoxPipe.Size = new System.Drawing.Size(192, 29);
this.checkBoxPipe.TabIndex = 4; this.checkBoxPipe.TabIndex = 4;
this.checkBoxPipe.Text = "Add Pipe"; this.checkBoxPipe.Text = "Добавление рогов";
this.checkBoxPipe.UseVisualStyleBackColor = true; this.checkBoxPipe.UseVisualStyleBackColor = true;
// //
// numericUpDownWeight // numericUpDownWeight
// //
this.numericUpDownWeight.Location = new System.Drawing.Point(75, 75); this.numericUpDownWeight.Location = new System.Drawing.Point(94, 94);
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(4);
this.numericUpDownWeight.Name = "numericUpDownWeight"; this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(68, 27); this.numericUpDownWeight.Size = new System.Drawing.Size(85, 31);
this.numericUpDownWeight.TabIndex = 3; this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] { this.numericUpDownWeight.Value = new decimal(new int[] {
100, 100,
@ -216,17 +238,19 @@
// labelWeight // labelWeight
// //
this.labelWeight.AutoSize = true; this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(7, 77); this.labelWeight.Location = new System.Drawing.Point(9, 96);
this.labelWeight.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelWeight.Name = "labelWeight"; this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(63, 20); this.labelWeight.Size = new System.Drawing.Size(48, 25);
this.labelWeight.TabIndex = 2; this.labelWeight.TabIndex = 2;
this.labelWeight.Text = "Weight: "; this.labelWeight.Text = "Вес: ";
// //
// numericUpDownSpeed // numericUpDownSpeed
// //
this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 31); this.numericUpDownSpeed.Location = new System.Drawing.Point(92, 39);
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(4);
this.numericUpDownSpeed.Name = "numericUpDownSpeed"; this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(69, 27); this.numericUpDownSpeed.Size = new System.Drawing.Size(86, 31);
this.numericUpDownSpeed.TabIndex = 1; this.numericUpDownSpeed.TabIndex = 1;
this.numericUpDownSpeed.Value = new decimal(new int[] { this.numericUpDownSpeed.Value = new decimal(new int[] {
100, 100,
@ -237,11 +261,12 @@
// labelSpeed // labelSpeed
// //
this.labelSpeed.AutoSize = true; this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(6, 33); this.labelSpeed.Location = new System.Drawing.Point(8, 41);
this.labelSpeed.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelSpeed.Name = "labelSpeed"; this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(62, 20); this.labelSpeed.Size = new System.Drawing.Size(98, 25);
this.labelSpeed.TabIndex = 0; this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = " Speed: "; this.labelSpeed.Text = "Скорость: ";
// //
// panelObject // panelObject
// //
@ -249,9 +274,10 @@
this.panelObject.Controls.Add(this.labelDopColor); this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelBaseColor); this.panelObject.Controls.Add(this.labelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject); this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(471, 22); this.panelObject.Location = new System.Drawing.Point(589, 28);
this.panelObject.Margin = new System.Windows.Forms.Padding(4);
this.panelObject.Name = "panelObject"; this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(419, 250); this.panelObject.Size = new System.Drawing.Size(524, 312);
this.panelObject.TabIndex = 1; this.panelObject.TabIndex = 1;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter); this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
@ -260,62 +286,70 @@
// //
this.labelDopColor.AllowDrop = true; this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(232, 16); this.labelDopColor.Location = new System.Drawing.Point(290, 20);
this.labelDopColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelDopColor.Name = "labelDopColor"; this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(115, 45); this.labelDopColor.Size = new System.Drawing.Size(143, 56);
this.labelDopColor.TabIndex = 9; this.labelDopColor.TabIndex = 9;
this.labelDopColor.Text = "Extra Color"; this.labelDopColor.Text = "Доп Цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop); this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
// //
// labelBaseColor // labelBaseColor
// //
this.labelBaseColor.AllowDrop = true; this.labelBaseColor.AllowDrop = true;
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBaseColor.Location = new System.Drawing.Point(69, 16); this.labelBaseColor.Location = new System.Drawing.Point(86, 20);
this.labelBaseColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labelBaseColor.Name = "labelBaseColor"; this.labelBaseColor.Name = "labelBaseColor";
this.labelBaseColor.Size = new System.Drawing.Size(115, 45); this.labelBaseColor.Size = new System.Drawing.Size(143, 56);
this.labelBaseColor.TabIndex = 8; this.labelBaseColor.TabIndex = 8;
this.labelBaseColor.Text = "Base Color"; this.labelBaseColor.Text = "Базовый цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragDrop); this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragEnter); this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
// //
// pictureBoxObject // pictureBoxObject
// //
this.pictureBoxObject.Location = new System.Drawing.Point(16, 67); this.pictureBoxObject.Location = new System.Drawing.Point(20, 84);
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(4);
this.pictureBoxObject.Name = "pictureBoxObject"; this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(386, 168); this.pictureBoxObject.Size = new System.Drawing.Size(482, 210);
this.pictureBoxObject.TabIndex = 0; this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false; this.pictureBoxObject.TabStop = false;
// //
// buttonAdd // buttonAdd
// //
this.buttonAdd.Location = new System.Drawing.Point(487, 278); this.buttonAdd.Location = new System.Drawing.Point(609, 348);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(4);
this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(168, 29); this.buttonAdd.Size = new System.Drawing.Size(210, 36);
this.buttonAdd.TabIndex = 2; this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Add"; this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
// //
// buttonCancel // buttonCancel
// //
this.buttonCancel.Location = new System.Drawing.Point(703, 278); this.buttonCancel.Location = new System.Drawing.Point(879, 348);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(4);
this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(170, 29); this.buttonCancel.Size = new System.Drawing.Size(212, 36);
this.buttonCancel.TabIndex = 3; this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Cancel"; this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
// //
// FormLocomotiveConfig // FormLocomotiveConfig
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(902, 315); this.ClientSize = new System.Drawing.Size(1128, 394);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.panelObject); this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig); this.Controls.Add(this.groupBoxConfig);
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "FormLocomotiveConfig"; this.Name = "FormLocomotiveConfig";
this.Text = "Object Creation"; this.Text = "Object Creation";
this.groupBoxConfig.ResumeLayout(false); this.groupBoxConfig.ResumeLayout(false);
@ -328,9 +362,7 @@
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxConfig; private GroupBox groupBoxConfig;
private NumericUpDown numericUpDownSpeed; private NumericUpDown numericUpDownSpeed;
private Label labelSpeed; private Label labelSpeed;

View File

@ -13,7 +13,23 @@ namespace ProjectLocomotive
public partial class FormLocomotiveConfig : Form public partial class FormLocomotiveConfig : Form
{ {
DrawningLocomotive _locomotive = null; DrawningLocomotive _locomotive = null;
private event Action<DrawningLocomotive> eventAddLocomotive;
public void AddEvent(Action<DrawningLocomotive> ev)
{
if (eventAddLocomotive == null)
{
eventAddLocomotive = new Action<DrawningLocomotive>(ev);
}
else
{
eventAddLocomotive += ev;
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
eventAddLocomotive?.Invoke(_locomotive);
Close();
}
public FormLocomotiveConfig() public FormLocomotiveConfig()
{ {
InitializeComponent(); InitializeComponent();
@ -25,13 +41,12 @@ namespace ProjectLocomotive
panelWhite.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (object sender, EventArgs e) => Close();
} }
private void labelObject_MouseDown(object sender, MouseEventArgs e) private void labelObject_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
} }
private void panelObject_DragEnter(object sender, DragEventArgs e) private void panelObject_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data.GetDataPresent(DataFormats.Text)) if (e.Data.GetDataPresent(DataFormats.Text))
@ -43,7 +58,6 @@ namespace ProjectLocomotive
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
private void panelObject_DragDrop(object sender, DragEventArgs e) private void panelObject_DragDrop(object sender, DragEventArgs e)
{ {
switch (e.Data.GetData(DataFormats.Text).ToString()) switch (e.Data.GetData(DataFormats.Text).ToString())
@ -59,12 +73,10 @@ namespace ProjectLocomotive
} }
DrawLocomotive(); DrawLocomotive();
} }
private void PanelColor_MouseDown(object sender, MouseEventArgs e) private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
} }
private void DrawLocomotive() private void DrawLocomotive()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
@ -73,8 +85,17 @@ namespace ProjectLocomotive
_locomotive?.DrawTransport(gr); _locomotive?.DrawTransport(gr);
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
private void labelBaseColor_DragEnter(object sender, DragEventArgs e) {
// ! - TODO
if (_locomotive is DrawningElectroLocomotive)
{
var locomotive = _locomotive as DrawningElectroLocomotive;
locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color)));
}
DrawLocomotive();
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data.GetDataPresent(typeof(Color))) if (e.Data.GetDataPresent(typeof(Color)))
{ {
@ -85,15 +106,19 @@ namespace ProjectLocomotive
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
private void LabelColor_DragDrop(object sender, DragEventArgs e)
private void labelBaseColor_DragDrop(object sender, DragEventArgs e)
{ {
// ! - TODO var color = e.Data.GetData(typeof(Color));
} if (color != null)
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
{ {
// ! - TODO (sender as Label).BackColor = (Color)color;
}
DrawLocomotive();
if (_locomotive != null)
{
_locomotive.Locomotivе.BodyColor = (Color)color;
DrawLocomotive();
}
} }
} }
} }

View File

@ -262,9 +262,7 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
private PictureBox pictureBox; private PictureBox pictureBox;
private ComboBox comboBoxSelectorMap; private ComboBox comboBoxSelectorMap;

View File

@ -54,25 +54,28 @@ namespace ProjectLocomotive
} }
/// Добавление объекта /// Добавление объекта
private void buttonAddLocomotive_Click(object sender, EventArgs e) private void buttonAddLocomotive_Click(object sender, EventArgs e)
{
var formCarConfig = new FormLocomotiveConfig();
formCarConfig.AddEvent(new(AddLocomotive));
formCarConfig.Show();
}
private void AddLocomotive(DrawningLocomotive locomotive)
{ {
if (listBoxMaps.SelectedIndex == -1) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
FormLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(locomotive) != -1)
{
DrawningObject locomotive = new(form.SelectedLocomotive);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Ошибка при добавлении объекта");
}
} }
} }
/// Удаление объекта /// Удаление объекта
private void buttonRemoveLocomotive_Click(object sender, EventArgs e) private void buttonRemoveLocomotive_Click(object sender, EventArgs e)