From a63bca3d279a714935cc66fcd89d795d6fad76f6 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 21:28:31 +0400 Subject: [PATCH 1/8] =?UTF-8?q?5=20=D0=9B=D0=B0=D0=B1=D0=B0.=20=D0=A1?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=8B,=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Delegate?= =?UTF-8?q?,=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingElectricLocomotive.cs | 4 + .../ElectricLocomotive/DrawingLocomotive.cs | 4 + .../EntityElectricLocomotive.cs | 4 + .../ElectricLocomotive/EntityLocomotive.cs | 4 + .../FormLocomotiveCollection.cs | 6 + .../FormLocomotiveConfig.Designer.cs | 355 ++++++++++++++++++ .../FormLocomotiveConfig.cs | 131 +++++++ .../FormLocomotiveConfig.resx | 120 ++++++ .../ElectricLocomotive/LocomotiveDelegate.cs | 11 + 9 files changed, 639 insertions(+) create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx create mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs index ffd4619..f7e8831 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs @@ -46,5 +46,9 @@ namespace ProjectElectricLocomotive.DrawingObjects g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2); base.DrawTransport(g); } + public void SetAddColor(Color color) + { + (EntityLocomotive as EntityElectricLocomotive).SetAdditionalColor(color); + } } } diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs index 946417c..115e12f 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs @@ -166,5 +166,9 @@ namespace ProjectElectricLocomotive.DrawingObjects } public IMoveableObject GetMoveableObject => new DrawingObjectLocomotive(this); + public void SetColor(Color color) + { + (EntityLocomotive as EntityLocomotive).SetColor(color); + } } } diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs index 1f148e3..0f7f96d 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs @@ -23,5 +23,9 @@ namespace ProjectElectricLocomotive.Entities Pantograph = pantograph; Compartment = compartment; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs index da602cf..f469e77 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs @@ -22,5 +22,9 @@ namespace ProjectElectricLocomotive.Entities Weight = weight; BodyColor = bodyColor; } + public void SetColor(Color color) + { + BodyColor = color; + } } } diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index ae6a12f..46defbc 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -41,6 +41,12 @@ namespace ProjectElectricLocomotive } } private void buttonAddLocomotive_Click(object sender, EventArgs e) + { + var formLocomotiveConfig = new FormLocomotiveConfig(); + formLocomotiveConfig.AddEvent(AddLocomotive); + formLocomotiveConfig.Show(); + } + public void AddLocomotive(DrawingLocomotive loco) { if (listBoxStorages.SelectedIndex == -1) return; diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs new file mode 100644 index 0000000..d4b13ef --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -0,0 +1,355 @@ +namespace ProjectElectricLocomotive +{ + partial class FormLocomotiveConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxConfig = new GroupBox(); + checkBoxCompartment = new CheckBox(); + labelAdvancedObject = new Label(); + labelSimpleObject = new Label(); + groupBoxColors = new GroupBox(); + panelColorPurple = new Panel(); + panelColorBlack = new Panel(); + panelColorGray = new Panel(); + panelColorWhite = new Panel(); + panelColorYellow = new Panel(); + panelColorBlue = new Panel(); + panelColorGreen = new Panel(); + panelColorRed = new Panel(); + checkBoxPantograph = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + pictureBoxLoco = new PictureBox(); + panelWithPictureBox = new Panel(); + labelAdvancedColor = new Label(); + labelSimpleColor = new Label(); + buttonAddObject = new Button(); + buttonCancelObject = new Button(); + groupBoxConfig.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLoco).BeginInit(); + panelWithPictureBox.SuspendLayout(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(checkBoxCompartment); + groupBoxConfig.Controls.Add(labelAdvancedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(checkBoxPantograph); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Location = new Point(2, 4); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(474, 255); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // checkBoxCompartment + // + checkBoxCompartment.AutoSize = true; + checkBoxCompartment.Location = new Point(10, 149); + checkBoxCompartment.Name = "checkBoxCompartment"; + checkBoxCompartment.Size = new Size(121, 19); + checkBoxCompartment.TabIndex = 10; + checkBoxCompartment.Text = "Наличие отсеков"; + checkBoxCompartment.UseVisualStyleBackColor = true; + // + // labelAdvancedObject + // + labelAdvancedObject.BorderStyle = BorderStyle.FixedSingle; + labelAdvancedObject.Location = new Point(324, 175); + labelAdvancedObject.Name = "labelAdvancedObject"; + labelAdvancedObject.Size = new Size(119, 51); + labelAdvancedObject.TabIndex = 9; + labelAdvancedObject.Text = "Продвинутый"; + labelAdvancedObject.TextAlign = ContentAlignment.MiddleCenter; + labelAdvancedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(181, 174); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(119, 51); + labelSimpleObject.TabIndex = 8; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelColorPurple); + groupBoxColors.Controls.Add(panelColorBlack); + groupBoxColors.Controls.Add(panelColorGray); + groupBoxColors.Controls.Add(panelColorWhite); + groupBoxColors.Controls.Add(panelColorYellow); + groupBoxColors.Controls.Add(panelColorBlue); + groupBoxColors.Controls.Add(panelColorGreen); + groupBoxColors.Controls.Add(panelColorRed); + groupBoxColors.Location = new Point(181, 18); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(287, 150); + groupBoxColors.TabIndex = 7; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelColorPurple + // + panelColorPurple.BackColor = Color.Purple; + panelColorPurple.Location = new Point(199, 84); + panelColorPurple.Name = "panelColorPurple"; + panelColorPurple.Size = new Size(50, 50); + panelColorPurple.TabIndex = 7; + // + // panelColorBlack + // + panelColorBlack.BackColor = Color.Black; + panelColorBlack.Location = new Point(143, 84); + panelColorBlack.Name = "panelColorBlack"; + panelColorBlack.Size = new Size(50, 50); + panelColorBlack.TabIndex = 6; + // + // panelColorGray + // + panelColorGray.BackColor = Color.Silver; + panelColorGray.Location = new Point(87, 84); + panelColorGray.Name = "panelColorGray"; + panelColorGray.Size = new Size(50, 50); + panelColorGray.TabIndex = 5; + // + // panelColorWhite + // + panelColorWhite.BackColor = Color.White; + panelColorWhite.Location = new Point(31, 84); + panelColorWhite.Name = "panelColorWhite"; + panelColorWhite.Size = new Size(50, 50); + panelColorWhite.TabIndex = 4; + // + // panelColorYellow + // + panelColorYellow.BackColor = Color.Yellow; + panelColorYellow.Location = new Point(199, 28); + panelColorYellow.Name = "panelColorYellow"; + panelColorYellow.Size = new Size(50, 50); + panelColorYellow.TabIndex = 3; + // + // panelColorBlue + // + panelColorBlue.BackColor = Color.Blue; + panelColorBlue.Location = new Point(143, 28); + panelColorBlue.Name = "panelColorBlue"; + panelColorBlue.Size = new Size(50, 50); + panelColorBlue.TabIndex = 2; + // + // panelColorGreen + // + panelColorGreen.BackColor = Color.FromArgb(0, 192, 0); + panelColorGreen.Location = new Point(87, 28); + panelColorGreen.Name = "panelColorGreen"; + panelColorGreen.Size = new Size(50, 50); + panelColorGreen.TabIndex = 1; + // + // panelColorRed + // + panelColorRed.BackColor = Color.Red; + panelColorRed.Location = new Point(31, 28); + panelColorRed.Name = "panelColorRed"; + panelColorRed.Size = new Size(50, 50); + panelColorRed.TabIndex = 0; + panelColorRed.MouseDown += PanelColor_MouseDown; + // + // checkBoxPantograph + // + checkBoxPantograph.AutoSize = true; + checkBoxPantograph.Location = new Point(10, 124); + checkBoxPantograph.Name = "checkBoxPantograph"; + checkBoxPantograph.Size = new Size(172, 19); + checkBoxPantograph.TabIndex = 4; + checkBoxPantograph.Text = "Наличие токоприемников"; + checkBoxPantograph.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(10, 95); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(120, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(10, 51); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(120, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(10, 77); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(26, 15); + labelWeight.TabIndex = 1; + labelWeight.Text = "Вес"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(10, 33); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(59, 15); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость"; + // + // pictureBoxLoco + // + pictureBoxLoco.Location = new Point(14, 38); + pictureBoxLoco.Name = "pictureBoxLoco"; + pictureBoxLoco.Size = new Size(284, 147); + pictureBoxLoco.TabIndex = 1; + pictureBoxLoco.TabStop = false; + // + // panelWithPictureBox + // + panelWithPictureBox.AllowDrop = true; + panelWithPictureBox.Controls.Add(labelAdvancedColor); + panelWithPictureBox.Controls.Add(labelSimpleColor); + panelWithPictureBox.Controls.Add(pictureBoxLoco); + panelWithPictureBox.Location = new Point(482, 12); + panelWithPictureBox.Name = "panelWithPictureBox"; + panelWithPictureBox.Size = new Size(316, 195); + panelWithPictureBox.TabIndex = 2; + // + // labelAdvancedColor + // + labelAdvancedColor.BorderStyle = BorderStyle.FixedSingle; + labelAdvancedColor.Location = new Point(159, 10); + labelAdvancedColor.Name = "labelAdvancedColor"; + labelAdvancedColor.Size = new Size(139, 23); + labelAdvancedColor.TabIndex = 3; + labelAdvancedColor.Text = "Доп. Цвет"; + labelAdvancedColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdvancedColor.DragDrop += LabelColor_DragDrop; + labelAdvancedColor.DragEnter += LabelColor_DragDrop; + // + // labelSimpleColor + // + labelSimpleColor.BorderStyle = BorderStyle.FixedSingle; + labelSimpleColor.Location = new Point(14, 10); + labelSimpleColor.Name = "labelSimpleColor"; + labelSimpleColor.Size = new Size(139, 23); + labelSimpleColor.TabIndex = 2; + labelSimpleColor.Text = "Цвет"; + labelSimpleColor.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleColor.DragDrop += LabelColor_DragDrop; + labelSimpleColor.DragEnter += LabelColor_DragDrop; + // + // buttonAddObject + // + buttonAddObject.Location = new Point(496, 213); + buttonAddObject.Name = "buttonAddObject"; + buttonAddObject.Size = new Size(139, 41); + buttonAddObject.TabIndex = 3; + buttonAddObject.Text = "Добавить"; + buttonAddObject.UseVisualStyleBackColor = true; + buttonAddObject.Click += buttonAddObject_Click; + // + // buttonCancelObject + // + buttonCancelObject.Location = new Point(641, 213); + buttonCancelObject.Name = "buttonCancelObject"; + buttonCancelObject.Size = new Size(139, 41); + buttonCancelObject.TabIndex = 4; + buttonCancelObject.Text = "Отмена"; + buttonCancelObject.UseVisualStyleBackColor = true; + // + // FormLocomotiveConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 266); + Controls.Add(buttonCancelObject); + Controls.Add(buttonAddObject); + Controls.Add(panelWithPictureBox); + Controls.Add(groupBoxConfig); + Name = "FormLocomotiveConfig"; + Text = "FormLocomotiveConfig"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLoco).EndInit(); + panelWithPictureBox.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelWeight; + private Label labelSpeed; + private CheckBox checkBox3; + private CheckBox checkBox2; + private CheckBox checkBoxPantograph; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private GroupBox groupBoxColors; + private Panel panelColorYellow; + private Panel panelColorBlue; + private Panel panelColorGreen; + private Panel panelColorRed; + private Panel panelColorPurple; + private Panel panelColorBlack; + private Panel panelColorGray; + private Panel panelColorWhite; + private Label labelAdvancedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxLoco; + private Panel panelWithPictureBox; + private Label labelAdvancedColor; + private Label labelSimpleColor; + private Button buttonAddObject; + private Button buttonCancelObject; + private CheckBox checkBoxCompartment; + } +} \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs new file mode 100644 index 0000000..88f472d --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -0,0 +1,131 @@ +using Microsoft.VisualBasic.Devices; +using ProjectElectricLocomotive.DrawingObjects; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectElectricLocomotive +{ + public partial class FormLocomotiveConfig : Form + { + DrawingLocomotive? _locomotive = null; + private event LocomotiveDelegate? EventAddLocomotive; + + public FormLocomotiveConfig() + { + InitializeComponent(); + panelColorBlack.MouseDown += PanelColor_MouseDown; + panelColorPurple.MouseDown += PanelColor_MouseDown; + panelColorGray.MouseDown += PanelColor_MouseDown; + panelColorGreen.MouseDown += PanelColor_MouseDown; + panelColorRed.MouseDown += PanelColor_MouseDown; + panelColorWhite.MouseDown += PanelColor_MouseDown; + panelColorYellow.MouseDown += PanelColor_MouseDown; + panelColorBlue.MouseDown += PanelColor_MouseDown; + + buttonCancelObject.Click += (sender, e) => Close(); + + } + public void AddEvent(LocomotiveDelegate ev) + { + if (EventAddLocomotive == null) + { + EventAddLocomotive = ev; + } + else + { + EventAddLocomotive += ev; + } + } + private void DrawLocomotive() + { + Bitmap bmp = new(pictureBoxLoco.Width, pictureBoxLoco.Height); + Graphics gr = Graphics.FromImage(bmp); + _locomotive?.SetPosition(5, 5); + _locomotive?.DrawTransport(gr); + pictureBoxLoco.Image = bmp; + } + + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _locomotive = new DrawingLocomotive((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxLoco.Width, + pictureBoxLoco.Height); + break; + case "labelModifiedObject": + _locomotive = new DrawingElectricLocomotive((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPantograph.Checked, + checkBoxCompartment.Checked, pictureBoxLoco.Width, + pictureBoxLoco.Height); + break; + } + DrawLocomotive(); + } + + private void buttonAddObject_Click(object sender, EventArgs e) + { + EventAddLocomotive?.Invoke(_locomotive); + Close(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + + } + + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); + switch (((Label)sender).Name) + { + case "labelColor": + _locomotive.SetColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAddColor": + if (_locomotive is not DrawingLocomotive) return; + else + { + (_locomotive as DrawingElectricLocomotive).SetAddColor((Color)e.Data.GetData(typeof(Color))); + } + break; + } + DrawLocomotive(); + } + + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } +} diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs b/ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs new file mode 100644 index 0000000..5139dd2 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectElectricLocomotive.DrawingObjects; + +namespace ProjectElectricLocomotive +{ + public delegate void LocomotiveDelegate(DrawingLocomotive locomotive); +} -- 2.25.1 From 0feb1800b43c88c6393588f415770b3d4aca4188 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 21:46:24 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20/=20?= =?UTF-8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveConfig.Designer.cs | 16 +++++++++++++++- .../ElectricLocomotive/FormLocomotiveConfig.cs | 12 ++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs index d4b13ef..f851898 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -90,6 +90,7 @@ // // labelAdvancedObject // + labelAdvancedObject.AllowDrop = true; labelAdvancedObject.BorderStyle = BorderStyle.FixedSingle; labelAdvancedObject.Location = new Point(324, 175); labelAdvancedObject.Name = "labelAdvancedObject"; @@ -101,6 +102,7 @@ // // labelSimpleObject // + labelSimpleObject.AllowDrop = true; labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; labelSimpleObject.Location = new Point(181, 174); labelSimpleObject.Name = "labelSimpleObject"; @@ -129,6 +131,7 @@ // // panelColorPurple // + panelColorPurple.AllowDrop = true; panelColorPurple.BackColor = Color.Purple; panelColorPurple.Location = new Point(199, 84); panelColorPurple.Name = "panelColorPurple"; @@ -137,6 +140,7 @@ // // panelColorBlack // + panelColorBlack.AllowDrop = true; panelColorBlack.BackColor = Color.Black; panelColorBlack.Location = new Point(143, 84); panelColorBlack.Name = "panelColorBlack"; @@ -145,6 +149,7 @@ // // panelColorGray // + panelColorGray.AllowDrop = true; panelColorGray.BackColor = Color.Silver; panelColorGray.Location = new Point(87, 84); panelColorGray.Name = "panelColorGray"; @@ -153,6 +158,7 @@ // // panelColorWhite // + panelColorWhite.AllowDrop = true; panelColorWhite.BackColor = Color.White; panelColorWhite.Location = new Point(31, 84); panelColorWhite.Name = "panelColorWhite"; @@ -161,6 +167,7 @@ // // panelColorYellow // + panelColorYellow.AllowDrop = true; panelColorYellow.BackColor = Color.Yellow; panelColorYellow.Location = new Point(199, 28); panelColorYellow.Name = "panelColorYellow"; @@ -169,6 +176,7 @@ // // panelColorBlue // + panelColorBlue.AllowDrop = true; panelColorBlue.BackColor = Color.Blue; panelColorBlue.Location = new Point(143, 28); panelColorBlue.Name = "panelColorBlue"; @@ -177,6 +185,7 @@ // // panelColorGreen // + panelColorGreen.AllowDrop = true; panelColorGreen.BackColor = Color.FromArgb(0, 192, 0); panelColorGreen.Location = new Point(87, 28); panelColorGreen.Name = "panelColorGreen"; @@ -185,6 +194,7 @@ // // panelColorRed // + panelColorRed.AllowDrop = true; panelColorRed.BackColor = Color.Red; panelColorRed.Location = new Point(31, 28); panelColorRed.Name = "panelColorRed"; @@ -257,10 +267,13 @@ panelWithPictureBox.Location = new Point(482, 12); panelWithPictureBox.Name = "panelWithPictureBox"; panelWithPictureBox.Size = new Size(316, 195); - panelWithPictureBox.TabIndex = 2; + panelWithPictureBox.TabIndex = 1; + panelWithPictureBox.DragDrop += PanelObject_DragDrop; + panelWithPictureBox.DragEnter += PanelObject_DragEnter; // // labelAdvancedColor // + labelAdvancedColor.AllowDrop = true; labelAdvancedColor.BorderStyle = BorderStyle.FixedSingle; labelAdvancedColor.Location = new Point(159, 10); labelAdvancedColor.Name = "labelAdvancedColor"; @@ -273,6 +286,7 @@ // // labelSimpleColor // + labelSimpleColor.AllowDrop = true; labelSimpleColor.BorderStyle = BorderStyle.FixedSingle; labelSimpleColor.Location = new Point(14, 10); labelSimpleColor.Name = "labelSimpleColor"; diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs index 88f472d..ee2f971 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -51,7 +51,6 @@ namespace ProjectElectricLocomotive _locomotive?.DrawTransport(gr); pictureBoxLoco.Image = bmp; } - private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); @@ -85,27 +84,25 @@ namespace ProjectElectricLocomotive } DrawLocomotive(); } - private void buttonAddObject_Click(object sender, EventArgs e) { EventAddLocomotive?.Invoke(_locomotive); Close(); } - private void PanelColor_MouseDown(object sender, MouseEventArgs e) { - + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); } - private void LabelColor_DragDrop(object sender, DragEventArgs e) { ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); switch (((Label)sender).Name) { - case "labelColor": + case "labelSimpleObject": _locomotive.SetColor((Color)e.Data.GetData(typeof(Color))); break; - case "labelAddColor": + case "labelAdvancedObject": if (_locomotive is not DrawingLocomotive) return; else { @@ -115,7 +112,6 @@ namespace ProjectElectricLocomotive } DrawLocomotive(); } - private void LabelColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) -- 2.25.1 From 26e3503e00224aef0340663d4bc60ba63b894408 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 22:01:56 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/DrawingLocomotive.cs | 4 ++-- .../FormLocomotiveCollection.cs | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs index 115e12f..c16041b 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs @@ -15,8 +15,8 @@ namespace ProjectElectricLocomotive.DrawingObjects { public EntityLocomotive? EntityLocomotive { get; protected set; } - protected int _pictureWidth; - protected int _pictureHeight; + public int _pictureWidth; + public int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _locomWidth = 80; diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 46defbc..9f5fe1d 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -48,6 +48,9 @@ namespace ProjectElectricLocomotive } public void AddLocomotive(DrawingLocomotive loco) { + loco._pictureWidth = pictureBoxCollection.Width; + loco._pictureHeight = pictureBoxCollection.Height; + if (listBoxStorages.SelectedIndex == -1) return; var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; @@ -55,19 +58,16 @@ namespace ProjectElectricLocomotive { return; } - FormElectricLocomotive form = new(); - if (form.ShowDialog() == DialogResult.OK) + + //проверяем, удалось ли нам загрузить объект + if (obj + loco > -1) { - //проверяем, удалось ли нам загрузить объект - if (obj + form.SelectedLocomotive > -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowLocomotives(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowLocomotives(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } private void buttonRemoveLocomotive_Click(object sender, EventArgs e) -- 2.25.1 From 0dfabf5f19777183698f9361d644cf452c166565 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 22:25:06 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/FormLocomotiveConfig.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs index ee2f971..cc162f7 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -28,8 +28,10 @@ namespace ProjectElectricLocomotive panelColorWhite.MouseDown += PanelColor_MouseDown; panelColorYellow.MouseDown += PanelColor_MouseDown; panelColorBlue.MouseDown += PanelColor_MouseDown; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + labelAdvancedObject.MouseDown += LabelObject_MouseDown; - buttonCancelObject.Click += (sender, e) => Close(); + buttonCancelObject.Click += (s, e) => Close(); } public void AddEvent(LocomotiveDelegate ev) @@ -55,6 +57,7 @@ namespace ProjectElectricLocomotive { (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } + private void PanelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) @@ -75,7 +78,7 @@ namespace ProjectElectricLocomotive (int)numericUpDownWeight.Value, Color.White, pictureBoxLoco.Width, pictureBoxLoco.Height); break; - case "labelModifiedObject": + case "labelAdvancedObject": _locomotive = new DrawingElectricLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPantograph.Checked, checkBoxCompartment.Checked, pictureBoxLoco.Width, @@ -84,16 +87,19 @@ namespace ProjectElectricLocomotive } DrawLocomotive(); } + private void buttonAddObject_Click(object sender, EventArgs e) { EventAddLocomotive?.Invoke(_locomotive); Close(); } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); } + private void LabelColor_DragDrop(object sender, DragEventArgs e) { ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); -- 2.25.1 From 559876c90b7393f77a97ee7e74b2bb5e22aadc61 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 23:04:05 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=86=D0=B2=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingElectricLocomotive.cs | 2 +- .../ElectricLocomotive/DrawingLocomotive.cs | 6 +++--- .../EntityElectricLocomotive.cs | 4 ++-- .../ElectricLocomotive/EntityLocomotive.cs | 4 ++-- .../FormLocomotiveConfig.cs | 20 +++++++++---------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs index f7e8831..0617c6e 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs @@ -46,7 +46,7 @@ namespace ProjectElectricLocomotive.DrawingObjects g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2); base.DrawTransport(g); } - public void SetAddColor(Color color) + public void SetAdditionalColor(Color color) { (EntityLocomotive as EntityElectricLocomotive).SetAdditionalColor(color); } diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs index c16041b..e22cc39 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs @@ -13,7 +13,7 @@ namespace ProjectElectricLocomotive.DrawingObjects { public class DrawingLocomotive { - public EntityLocomotive? EntityLocomotive { get; protected set; } + public EntityLocomotive? EntityLocomotive { get; protected set;} public int _pictureWidth; public int _pictureHeight; @@ -166,9 +166,9 @@ namespace ProjectElectricLocomotive.DrawingObjects } public IMoveableObject GetMoveableObject => new DrawingObjectLocomotive(this); - public void SetColor(Color color) + public void SetBodyColor(Color color) { - (EntityLocomotive as EntityLocomotive).SetColor(color); + EntityLocomotive.SetBodyColor(color); } } } diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs index 0f7f96d..dbb6eaa 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs @@ -10,8 +10,8 @@ namespace ProjectElectricLocomotive.Entities public class EntityElectricLocomotive : EntityLocomotive { public Color AdditionalColor { get; private set; } - public bool Pantograph { get; private set; } - public bool Compartment { get; private set; } + public bool Pantograph { get; set; } + public bool Compartment { get; set; } /// Дополнительный цвет /// Признак наличия токоприемника diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs index f469e77..aacfbfe 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs @@ -10,7 +10,7 @@ namespace ProjectElectricLocomotive.Entities { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; protected set; } public double Step => (double)Speed * 100 / Weight; /// Скорость @@ -22,7 +22,7 @@ namespace ProjectElectricLocomotive.Entities Weight = weight; BodyColor = bodyColor; } - public void SetColor(Color color) + public void SetBodyColor(Color color) { BodyColor = color; } diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs index cc162f7..162119a 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ProjectElectricLocomotive.Entities; namespace ProjectElectricLocomotive { @@ -28,8 +29,6 @@ namespace ProjectElectricLocomotive panelColorWhite.MouseDown += PanelColor_MouseDown; panelColorYellow.MouseDown += PanelColor_MouseDown; panelColorBlue.MouseDown += PanelColor_MouseDown; - labelSimpleObject.MouseDown += LabelObject_MouseDown; - labelAdvancedObject.MouseDown += LabelObject_MouseDown; buttonCancelObject.Click += (s, e) => Close(); @@ -81,8 +80,7 @@ namespace ProjectElectricLocomotive case "labelAdvancedObject": _locomotive = new DrawingElectricLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPantograph.Checked, - checkBoxCompartment.Checked, pictureBoxLoco.Width, - pictureBoxLoco.Height); + checkBoxCompartment.Checked, pictureBoxLoco.Width, pictureBoxLoco.Height); break; } DrawLocomotive(); @@ -102,18 +100,20 @@ namespace ProjectElectricLocomotive private void LabelColor_DragDrop(object sender, DragEventArgs e) { + if (_locomotive == null) + return; ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); switch (((Label)sender).Name) { - case "labelSimpleObject": - _locomotive.SetColor((Color)e.Data.GetData(typeof(Color))); + case "labelSimpleColor": + _locomotive.SetBodyColor((Color)e.Data.GetData(typeof(Color))); break; - case "labelAdvancedObject": - if (_locomotive is not DrawingLocomotive) return; - else + case "labelAdvancedColor": + if (!(_locomotive is DrawingElectricLocomotive)) { - (_locomotive as DrawingElectricLocomotive).SetAddColor((Color)e.Data.GetData(typeof(Color))); + return; } + (_locomotive as DrawingElectricLocomotive).SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); break; } DrawLocomotive(); -- 2.25.1 From 15f09ac2429524005ffa09eaaea4afd584ede4ed Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 23:30:16 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/DrawingElectricLocomotive.cs | 3 +-- .../ElectricLocomotive/FormLocomotiveConfig.cs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs index 0617c6e..64921f7 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs @@ -10,8 +10,7 @@ namespace ProjectElectricLocomotive.DrawingObjects { public class DrawingElectricLocomotive : DrawingLocomotive { - public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, - bool pantograph, bool compartment, int width, int height) : base(speed, weight, bodyColor, width, height, 80, 52) + public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment, int width, int height) : base(speed, weight, bodyColor, width, height, 80, 52) { if (EntityLocomotive != null) { diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs index 162119a..c9c7157 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -94,8 +94,7 @@ namespace ProjectElectricLocomotive private void PanelColor_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); } private void LabelColor_DragDrop(object sender, DragEventArgs e) @@ -120,7 +119,7 @@ namespace ProjectElectricLocomotive } private void LabelColor_DragEnter(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(typeof(Color))) + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) { e.Effect = DragDropEffects.Copy; } -- 2.25.1 From a258fe0f848fb4273b55d5289a033405bcfc9b53 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 12 Nov 2023 23:38:39 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=205=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/DrawingElectricLocomotive.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs index 64921f7..16b18ec 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs @@ -30,6 +30,7 @@ namespace ProjectElectricLocomotive.DrawingObjects Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor); Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor); g.DrawRectangle(pen, _startPosX + 40, _startPosY + 24, 25, 11); + if (electricLocomotive.Compartment) g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 61, _startPosY + 25), @@ -39,11 +40,13 @@ namespace ProjectElectricLocomotive.DrawingObjects new Point(_startPosX + 61, _startPosY + 25), } ); - - g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5); - g.DrawLine(pen, _startPosX + 30, _startPosY + 15, _startPosX + 50, _startPosY + 2); - g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2); - base.DrawTransport(g); + if (electricLocomotive.Pantograph) + { + g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5); + g.DrawLine(pen, _startPosX + 30, _startPosY + 15, _startPosX + 50, _startPosY + 2); + g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2); + } + base.DrawTransport(g); } public void SetAdditionalColor(Color color) { -- 2.25.1 From c918183e43047456958550ea6c529a8298ab30dc Mon Sep 17 00:00:00 2001 From: tellsense Date: Fri, 17 Nov 2023 21:42:11 +0400 Subject: [PATCH 8/8] =?UTF-8?q?5=20=D0=BB=D0=B0=D0=B1=D0=B0=20(=D0=BE?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=87=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/DrawingElectricLocomotive.cs | 11 ++++++----- .../ElectricLocomotive/DrawingLocomotive.cs | 3 ++- .../ElectricLocomotive/EntityElectricLocomotive.cs | 2 +- .../ElectricLocomotive/EntityLocomotive.cs | 4 ++-- .../ElectricLocomotive/FormLocomotiveConfig.cs | 7 +++---- .../ElectricLocomotive/LocomotiveDelegate.cs | 11 ----------- 6 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs index 16b18ec..38d51aa 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingElectricLocomotive.cs @@ -31,22 +31,22 @@ namespace ProjectElectricLocomotive.DrawingObjects Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor); g.DrawRectangle(pen, _startPosX + 40, _startPosY + 24, 25, 11); if (electricLocomotive.Compartment) - g.FillPolygon(additionalBrush, new Point[] - { + g.FillPolygon(additionalBrush, new Point[] + { new Point(_startPosX + 61, _startPosY + 25), new Point(_startPosX + 85, _startPosY + 25), new Point(_startPosX + 85, _startPosY + 35), new Point(_startPosX + 61, _startPosY + 35), new Point(_startPosX + 61, _startPosY + 25), - } - ); + } + ); if (electricLocomotive.Pantograph) { g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5); g.DrawLine(pen, _startPosX + 30, _startPosY + 15, _startPosX + 50, _startPosY + 2); g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2); } - base.DrawTransport(g); + base.DrawTransport(g); } public void SetAdditionalColor(Color color) { @@ -54,3 +54,4 @@ namespace ProjectElectricLocomotive.DrawingObjects } } } + diff --git a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs index e22cc39..a1e5607 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs @@ -13,7 +13,7 @@ namespace ProjectElectricLocomotive.DrawingObjects { public class DrawingLocomotive { - public EntityLocomotive? EntityLocomotive { get; protected set;} + public EntityLocomotive? EntityLocomotive { get; protected set; } public int _pictureWidth; public int _pictureHeight; @@ -172,3 +172,4 @@ namespace ProjectElectricLocomotive.DrawingObjects } } } + diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs index dbb6eaa..4bfde99 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs @@ -10,7 +10,7 @@ namespace ProjectElectricLocomotive.Entities public class EntityElectricLocomotive : EntityLocomotive { public Color AdditionalColor { get; private set; } - public bool Pantograph { get; set; } + public bool Pantograph { get; set; } public bool Compartment { get; set; } /// Дополнительный цвет diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs index aacfbfe..b7b7d30 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs @@ -16,7 +16,7 @@ namespace ProjectElectricLocomotive.Entities /// Скорость /// Вес локомотива /// Основной цвет - public EntityLocomotive (int speed, double weight, Color bodyColor) + public EntityLocomotive(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; @@ -27,4 +27,4 @@ namespace ProjectElectricLocomotive.Entities BodyColor = color; } } -} +} \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs index c9c7157..b856337 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -16,7 +16,7 @@ namespace ProjectElectricLocomotive public partial class FormLocomotiveConfig : Form { DrawingLocomotive? _locomotive = null; - private event LocomotiveDelegate? EventAddLocomotive; + private event Action? EventAddLocomotive; public FormLocomotiveConfig() { @@ -33,7 +33,7 @@ namespace ProjectElectricLocomotive buttonCancelObject.Click += (s, e) => Close(); } - public void AddEvent(LocomotiveDelegate ev) + public void AddEvent(Action ev) { if (EventAddLocomotive == null) { @@ -101,7 +101,6 @@ namespace ProjectElectricLocomotive { if (_locomotive == null) return; - ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); switch (((Label)sender).Name) { case "labelSimpleColor": @@ -119,7 +118,7 @@ namespace ProjectElectricLocomotive } private void LabelColor_DragEnter(object sender, DragEventArgs e) { - if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + if ((e.Data?.GetDataPresent(typeof(Color)) ?? false)) { e.Effect = DragDropEffects.Copy; } diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs b/ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs deleted file mode 100644 index 5139dd2..0000000 --- a/ElectricLocomotive/ElectricLocomotive/LocomotiveDelegate.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ProjectElectricLocomotive.DrawingObjects; - -namespace ProjectElectricLocomotive -{ - public delegate void LocomotiveDelegate(DrawingLocomotive locomotive); -} -- 2.25.1