From c0d668010641d578427f3c40565c5c370b57e87b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?=
=?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com>
Date: Wed, 29 Nov 2023 18:43:18 +0400
Subject: [PATCH 1/2] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?=
=?UTF-8?q?=D1=82=D0=BA=D0=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DrawningElectricLocomotive.cs | 5 +
.../ElectricLocomotive/DrawningLocomotive.cs | 5 +
.../EntityElectricLocomotive.cs | 4 +
.../ElectricLocomotive/EntityLocomotive.cs | 4 +
.../FormLocomotiveCollection.cs | 7 +-
.../FormLocomotiveConfig.Designer.cs | 356 ++++++++++++++++++
.../FormLocomotiveConfig.cs | 130 +++++++
.../FormLocomotiveConfig.resx | 120 ++++++
8 files changed, 630 insertions(+), 1 deletion(-)
create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
index 17d3263..88f372e 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
@@ -60,6 +60,11 @@ namespace ElectricLocomotive
}
base.DrawTransport(g);
}
+
+ public void SetAdditionalColor(Color color)
+ {
+ (EntityLocomotive as EntityElectroLocomotive).SetAdditionalColor(color);
+ }
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
index ef15a0e..8e0ef98 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
@@ -209,5 +209,10 @@ namespace ElectricLocomotive.DrawningObject
}
public IMoveableObject GetMoveableObject => new DrawningObjectLocomotive(this);
+
+ public void SetBodyColor(Color color)
+ {
+ EntityLocomotive?.SetBodyColor(color);
+ }
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
index df3aeb2..2ee3d96 100644
--- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
@@ -20,6 +20,10 @@ namespace ElectricLocomotive.Entities
AdditionalColor = additionalColor;
Horns = horns;
}
+ public void SetAdditionalColor(Color color)
+ {
+ AdditionalColor = color;
+ }
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
index 9e45f19..ca13588 100644
--- a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
@@ -36,5 +36,9 @@ namespace ElectricLocomotive.Entities
Weight = weight;
BodyColor = bodyColor;
}
+ public void SetBodyColor(Color color)
+ {
+ BodyColor = color;
+ }
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
index 9fd61dc..77e4364 100644
--- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
@@ -76,7 +76,12 @@ namespace ElectricLocomotive
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
-
+ var formLocomotiveConfig = new FormLocomotiveConfig();
+ formLocomotiveConfig.AddEvent(NAddLocomotive);
+ formLocomotiveConfig.Show();
+ }
+ public void NAddLocomotive(DrawningLocomotive loco)
+ {
if (listBoxStorage.SelectedIndex == -1) return;
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
new file mode 100644
index 0000000..002cbb3
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
@@ -0,0 +1,356 @@
+namespace ElectricLocomotive
+{
+ 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();
+ 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(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 = "Параметры";
+ //
+ // labelAdvancedObject
+ //
+ labelAdvancedObject.AllowDrop = true;
+ 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.AllowDrop = true;
+ 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.AllowDrop = true;
+ panelColorPurple.BackColor = Color.Purple;
+ panelColorPurple.Location = new Point(199, 84);
+ panelColorPurple.Name = "panelColorPurple";
+ panelColorPurple.Size = new Size(50, 50);
+ panelColorPurple.TabIndex = 7;
+ //
+ // panelColorBlack
+ //
+ panelColorBlack.AllowDrop = true;
+ panelColorBlack.BackColor = Color.Black;
+ panelColorBlack.Location = new Point(143, 84);
+ panelColorBlack.Name = "panelColorBlack";
+ panelColorBlack.Size = new Size(50, 50);
+ panelColorBlack.TabIndex = 6;
+ //
+ // panelColorGray
+ //
+ panelColorGray.AllowDrop = true;
+ panelColorGray.BackColor = Color.Silver;
+ panelColorGray.Location = new Point(87, 84);
+ panelColorGray.Name = "panelColorGray";
+ panelColorGray.Size = new Size(50, 50);
+ panelColorGray.TabIndex = 5;
+ //
+ // panelColorWhite
+ //
+ panelColorWhite.AllowDrop = true;
+ panelColorWhite.BackColor = Color.White;
+ panelColorWhite.Location = new Point(31, 84);
+ panelColorWhite.Name = "panelColorWhite";
+ panelColorWhite.Size = new Size(50, 50);
+ panelColorWhite.TabIndex = 4;
+ //
+ // panelColorYellow
+ //
+ panelColorYellow.AllowDrop = true;
+ panelColorYellow.BackColor = Color.Yellow;
+ panelColorYellow.Location = new Point(199, 28);
+ panelColorYellow.Name = "panelColorYellow";
+ panelColorYellow.Size = new Size(50, 50);
+ panelColorYellow.TabIndex = 3;
+ //
+ // panelColorBlue
+ //
+ panelColorBlue.AllowDrop = true;
+ panelColorBlue.BackColor = Color.Blue;
+ panelColorBlue.Location = new Point(143, 28);
+ panelColorBlue.Name = "panelColorBlue";
+ panelColorBlue.Size = new Size(50, 50);
+ panelColorBlue.TabIndex = 2;
+ //
+ // panelColorGreen
+ //
+ panelColorGreen.AllowDrop = true;
+ 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.AllowDrop = true;
+ 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 = 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";
+ 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.AllowDrop = true;
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
new file mode 100644
index 0000000..8e6ea2f
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
@@ -0,0 +1,130 @@
+using ElectricLocomotive.DrawningObject;
+using Microsoft.VisualBasic.Devices;
+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 ElectricLocomotive
+{
+ public partial class FormLocomotiveConfig : Form
+ {
+ DrawningLocomotive? _locomotive = null;
+ private event Action? 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 += (s, e) => Close();
+
+ }
+ public void AddEvent(Action 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 DrawningLocomotive((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.Blue, pictureBoxLoco.Width,
+ pictureBoxLoco.Height);
+ break;
+ case "labelAdvancedObject":
+ _locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.Blue, Color.Red, checkBoxPantograph.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)
+ {
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ private void LabelColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_locomotive == null)
+ return;
+ switch (((Label)sender).Name)
+ {
+ case "labelSimpleColor":
+ _locomotive.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
+ break;
+ case "labelAdvancedColor":
+ if (!(_locomotive is DrawningElectricLocomotive))
+ {
+ return;
+ }
+ (_locomotive as DrawningElectricLocomotive).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
+ break;
+ }
+ DrawLocomotive();
+ }
+ private void LabelColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if ((e.Data?.GetDataPresent(typeof(Color)) ?? false))
+ {
+ 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
--
2.25.1
From 790766694c3a7457b438574f4f9a40f7559e6a6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?=
=?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com>
Date: Fri, 1 Dec 2023 16:56:49 +0400
Subject: [PATCH 2/2] =?UTF-8?q?=D0=91=D0=B5=D0=B7=20=D1=82=D0=B5=D0=BE?=
=?UTF-8?q?=D1=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DrawningElectricLocomotive.cs | 11 +++---
.../ElectricLocomotive/DrawningLocomotive.cs | 4 +--
.../ElectricLocomotive/ElectricLocomotive.cs | 6 ++--
.../EntityElectricLocomotive.cs | 10 ++++--
.../FormLocomotiveCollection.cs | 23 ++++++------
.../FormLocomotiveConfig.Designer.cs | 35 +++++++++++++------
.../FormLocomotiveConfig.cs | 2 +-
7 files changed, 56 insertions(+), 35 deletions(-)
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
index 88f372e..aa3c61e 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
@@ -10,13 +10,13 @@ namespace ElectricLocomotive
{
public class DrawningElectricLocomotive : DrawningLocomotive
{
- public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool Horns, int width, int height)
+ public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool Horns_1,bool Horns_2, int width, int height)
: base (speed, weight, bodyColor, width , height)
{
if (EntityLocomotive != null)
{
EntityLocomotive = new EntityElectroLocomotive(speed, weight, bodyColor,
- additionalColor, Horns);
+ additionalColor, Horns_1,Horns_2);
}
}
@@ -29,7 +29,7 @@ namespace ElectricLocomotive
Pen pen = new(electroLocomotive.BodyColor) ;
Brush brush = new SolidBrush(electroLocomotive.AdditionalColor);
// обвесы
- if (electroLocomotive.Horns)
+ if (electroLocomotive.Horns_1)
{
g.FillRectangle(brush, _startPosX + 25, _startPosY + 5, 15, 5);
@@ -44,7 +44,9 @@ namespace ElectricLocomotive
new Point(_startPosX+40,_startPosY+10)
};
g.DrawPolygon(pen, horns);
-
+ }
+ if (electroLocomotive.Horns_2)
+ {
g.FillRectangle(brush, _startPosX + 65, _startPosY + 5, 15, 5);
Point[] horns2 =
{
@@ -57,6 +59,7 @@ namespace ElectricLocomotive
new Point(_startPosX+80,_startPosY+10)
};
g.DrawPolygon(pen, horns2);
+
}
base.DrawTransport(g);
}
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
index 8e0ef98..77d2d9a 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
@@ -15,9 +15,9 @@ namespace ElectricLocomotive.DrawningObject
{
public EntityLocomotive? EntityLocomotive { get; protected set; }
- protected int _pictureWidth;
+ public int _pictureWidth;
- protected int _pictureHeight;
+ public int _pictureHeight;
protected int _startPosX;
diff --git a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
index 108187d..37a0170 100644
--- a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
@@ -50,13 +50,15 @@ namespace ElectricLocomotive
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- bool Horns = Convert.ToBoolean(random.Next(0, 2));
+ bool Horns_1 = Convert.ToBoolean(random.Next(0, 2));
+ bool Horns_2 = Convert.ToBoolean(random.Next(0, 2));
+
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
color = dialog.Color;
if (dialog.ShowDialog() == DialogResult.OK)
dopColor = dialog.Color;
- _drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Horns, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
+ _drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Horns_1,Horns_2, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
index 2ee3d96..392cd33 100644
--- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
@@ -11,14 +11,18 @@ namespace ElectricLocomotive.Entities
{
public Color AdditionalColor { get; private set; }
- public bool Horns { get; private set; }
+ public bool Horns_1 { get; private set; }
///
/// Признак (опция) roga
///
- public EntityElectroLocomotive(int Speed, double weight, Color bodyColor, Color additionalColor, bool horns) : base(Speed,weight,bodyColor)
+ ///
+ public bool Horns_2 { get; private set; }
+
+ public EntityElectroLocomotive(int Speed, double weight, Color bodyColor, Color additionalColor, bool horns_1, bool horns_2) : base(Speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
- Horns = horns;
+ Horns_1 = horns_1;
+ Horns_2 = horns_2;
}
public void SetAdditionalColor(Color color)
{
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
index 77e4364..f2ccf7b 100644
--- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
@@ -82,6 +82,9 @@ namespace ElectricLocomotive
}
public void NAddLocomotive(DrawningLocomotive loco)
{
+ loco._pictureWidth = CollectionPictureBox.Width;
+ loco._pictureHeight = CollectionPictureBox.Height;
+
if (listBoxStorage.SelectedIndex == -1) return;
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
@@ -90,19 +93,15 @@ namespace ElectricLocomotive
return;
}
- ElectricLocomotive form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ //проверяем, удалось ли нам загрузить объект
+ if (obj + loco > -1)
{
- //проверяем, удалось ли нам загрузить объект
- if (obj + form.SelectedLocomotive > -1)
- {
- MessageBox.Show("Объект добавлен");
- CollectionPictureBox.Image = obj.ShowLocomotives();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+ MessageBox.Show("Объект добавлен");
+ CollectionPictureBox.Image = obj.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
index 002cbb3..84e698a 100644
--- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
@@ -40,7 +40,7 @@
panelColorBlue = new Panel();
panelColorGreen = new Panel();
panelColorRed = new Panel();
- checkBoxPantograph = new CheckBox();
+ checkBoxPantograph_1 = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
labelWeight = new Label();
@@ -51,6 +51,7 @@
labelSimpleColor = new Label();
buttonAddObject = new Button();
buttonCancelObject = new Button();
+ checkBoxPantograph_2 = new CheckBox();
groupBoxConfig.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
@@ -61,10 +62,11 @@
//
// groupBoxConfig
//
+ groupBoxConfig.Controls.Add(checkBoxPantograph_2);
groupBoxConfig.Controls.Add(labelAdvancedObject);
groupBoxConfig.Controls.Add(labelSimpleObject);
groupBoxConfig.Controls.Add(groupBoxColors);
- groupBoxConfig.Controls.Add(checkBoxPantograph);
+ groupBoxConfig.Controls.Add(checkBoxPantograph_1);
groupBoxConfig.Controls.Add(numericUpDownWeight);
groupBoxConfig.Controls.Add(numericUpDownSpeed);
groupBoxConfig.Controls.Add(labelWeight);
@@ -190,15 +192,15 @@
panelColorRed.TabIndex = 0;
panelColorRed.MouseDown += PanelColor_MouseDown;
//
- // checkBoxPantograph
+ // checkBoxPantograph_1
//
- 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;
+ checkBoxPantograph_1.AutoSize = true;
+ checkBoxPantograph_1.Location = new Point(10, 124);
+ checkBoxPantograph_1.Name = "checkBoxPantograph_1";
+ checkBoxPantograph_1.Size = new Size(154, 19);
+ checkBoxPantograph_1.TabIndex = 4;
+ checkBoxPantograph_1.Text = "Первый токоприемник";
+ checkBoxPantograph_1.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
@@ -304,6 +306,16 @@
buttonCancelObject.Text = "Отмена";
buttonCancelObject.UseVisualStyleBackColor = true;
//
+ // checkBoxPantograph_2
+ //
+ checkBoxPantograph_2.AutoSize = true;
+ checkBoxPantograph_2.Location = new Point(10, 149);
+ checkBoxPantograph_2.Name = "checkBoxPantograph_2";
+ checkBoxPantograph_2.Size = new Size(150, 19);
+ checkBoxPantograph_2.TabIndex = 10;
+ checkBoxPantograph_2.Text = "Второй токоприемник";
+ checkBoxPantograph_2.UseVisualStyleBackColor = true;
+ //
// FormLocomotiveConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -332,7 +344,7 @@
private Label labelSpeed;
private CheckBox checkBox3;
private CheckBox checkBox2;
- private CheckBox checkBoxPantograph;
+ private CheckBox checkBoxPantograph_1;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private GroupBox groupBoxColors;
@@ -352,5 +364,6 @@
private Label labelSimpleColor;
private Button buttonAddObject;
private Button buttonCancelObject;
+ private CheckBox checkBoxPantograph_2;
}
}
\ No newline at end of file
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
index 8e6ea2f..33c1044 100644
--- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
@@ -78,7 +78,7 @@ namespace ElectricLocomotive
break;
case "labelAdvancedObject":
_locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value,
- (int)numericUpDownWeight.Value, Color.Blue, Color.Red, checkBoxPantograph.Checked,
+ (int)numericUpDownWeight.Value, Color.Blue, Color.Red, checkBoxPantograph_1.Checked, checkBoxPantograph_2.Checked,
pictureBoxLoco.Width, pictureBoxLoco.Height);
break;
}
--
2.25.1