From 6d3d2b2283a75ad70bb443f81afdc0f2eda2b949 Mon Sep 17 00:00:00 2001 From: Stranni15k Date: Sat, 19 Nov 2022 23:06:12 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawningElectricLocomotive.cs | 11 +- .../ElectricLocomotive/DrawningLocomotive.cs | 4 + .../EntityElectricLocomotive.cs | 6 +- .../ElectricLocomotive/EntityLocomotive.cs | 9 +- .../ElectricLocomotive/FormLocomotive.cs | 2 +- .../FormLocomotiveConfig.Designer.cs | 398 ++++++++++++++++++ .../FormLocomotiveConfig.cs | 139 ++++++ .../FormLocomotiveConfig.resx | 60 +++ .../FormMapWithSetLocomotive.cs | 44 +- 9 files changed, 641 insertions(+), 32 deletions(-) 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 c087fe4..d698bcf 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs @@ -8,10 +8,10 @@ namespace ElectricLocomotive { internal class DrawningElectricLocomotive : DrawningLocomotive { - public DrawningElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : - base(speed, weight, bodyColor, 110, 60) + public DrawningElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool sportLine) : + base(speed, weight, bodyColor, 110, 60) { - Locomotive = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + Locomotive = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, bodyKit, sportLine); } public override void DrawTransport(Graphics g) { @@ -24,7 +24,6 @@ namespace ElectricLocomotive Pen window = new(Color.Blue); Brush dopBrush = new SolidBrush(sportCar.DopColor); - if (sportCar.BodyKit) { Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 15, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY)), new Point(Convert.ToInt32(_startPosX) + 75, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY) + 40) }; @@ -39,5 +38,9 @@ namespace ElectricLocomotive base.DrawTransport(g); } + public void SetExtraColor(Color color) + { + (Locomotive as EntityElectricLocomotive).DopColor = color; + } } } diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs index 8c9b34d..a086fd7 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs @@ -147,6 +147,10 @@ namespace ElectricLocomotive _startPosY = _pictureHeight.Value - _locomotiveHeight; } } + public void SetBodyColor(Color color) + { + (Locomotive as EntityLocomotive).setColor(color); + } public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight); diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs index 1eb3518..a82eb6f 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs @@ -8,16 +8,14 @@ namespace ElectricLocomotive { internal class EntityElectricLocomotive : EntityLocomotive { - public Color DopColor { get; private set; } + public Color DopColor { get; set; } public bool BodyKit { get; private set; } - public bool Wing { get; private set; } public bool SportLine { get; private set; } - public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool sportLine) : base(speed, weight, bodyColor) { DopColor = dopColor; BodyKit = bodyKit; - Wing = wing; SportLine = sportLine; } } diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs index 6452613..e58b360 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs @@ -11,7 +11,7 @@ namespace ElectricLocomotive { public int Speed { get; private set; } public float Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public float Step => Speed * 100 / Weight; public EntityLocomotive(int speed, float weight, Color bodyColor) { @@ -20,5 +20,10 @@ namespace ElectricLocomotive Weight = weight <= 0 ? rnd.Next(150, 200) : weight; BodyColor = bodyColor; } - } + + public void setColor(Color color) + { + BodyColor = color; + } } +} diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotive.cs index f09b942..5576511 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotive.cs @@ -98,7 +98,7 @@ namespace ElectricLocomotive _locomotive = new DrawningElectricLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, - 2)), Convert.ToBoolean(rnd.Next(0, 2))); + 2))); SetData(); Draw(); } diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs new file mode 100644 index 0000000..0de5f1c --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -0,0 +1,398 @@ +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() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.labelHardObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.checkBoxProvod = new System.Windows.Forms.CheckBox(); + this.checkBoxObv = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.panelobject = new System.Windows.Forms.Panel(); + this.LabelDopColor = new System.Windows.Forms.Label(); + this.LabelBaseColor = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelobject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.labelHardObject); + this.groupBox1.Controls.Add(this.labelSimpleObject); + this.groupBox1.Controls.Add(this.groupBox2); + this.groupBox1.Controls.Add(this.checkBoxProvod); + this.groupBox1.Controls.Add(this.checkBoxObv); + this.groupBox1.Controls.Add(this.numericUpDownWeight); + this.groupBox1.Controls.Add(this.numericUpDownSpeed); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(470, 201); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Параметры"; + // + // labelHardObject + // + this.labelHardObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelHardObject.Location = new System.Drawing.Point(334, 166); + this.labelHardObject.Name = "labelHardObject"; + this.labelHardObject.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.labelHardObject.Size = new System.Drawing.Size(100, 23); + this.labelHardObject.TabIndex = 9; + this.labelHardObject.Text = "Продвинутый"; + this.labelHardObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelHardObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelSimpleObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(228, 166); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(100, 23); + this.labelSimpleObject.TabIndex = 8; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelSimpleObject_MouseDown); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.panelWhite); + this.groupBox2.Controls.Add(this.panelYellow); + this.groupBox2.Controls.Add(this.panelGray); + this.groupBox2.Controls.Add(this.panelBlue); + this.groupBox2.Controls.Add(this.panelGreen); + this.groupBox2.Controls.Add(this.panelPurple); + this.groupBox2.Controls.Add(this.panelRed); + this.groupBox2.Controls.Add(this.panelBlack); + this.groupBox2.Location = new System.Drawing.Point(216, 22); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(228, 130); + this.groupBox2.TabIndex = 7; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Цвета"; + // + // panelWhite + // + this.panelWhite.AllowDrop = true; + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(167, 78); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(43, 44); + this.panelWhite.TabIndex = 3; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.AllowDrop = true; + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(167, 28); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(43, 44); + this.panelYellow.TabIndex = 1; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.AllowDrop = true; + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(118, 78); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(43, 44); + this.panelGray.TabIndex = 4; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.AllowDrop = true; + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(69, 78); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(43, 44); + this.panelBlue.TabIndex = 5; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.AllowDrop = true; + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(118, 28); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(43, 44); + this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelPurple + // + this.panelPurple.AllowDrop = true; + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(20, 78); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(43, 44); + this.panelPurple.TabIndex = 2; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.AllowDrop = true; + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(69, 28); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(43, 44); + this.panelRed.TabIndex = 1; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.AllowDrop = true; + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(20, 28); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(43, 44); + this.panelBlack.TabIndex = 0; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxProvod + // + this.checkBoxProvod.AutoSize = true; + this.checkBoxProvod.Location = new System.Drawing.Point(6, 145); + this.checkBoxProvod.Name = "checkBoxProvod"; + this.checkBoxProvod.Size = new System.Drawing.Size(163, 19); + this.checkBoxProvod.TabIndex = 5; + this.checkBoxProvod.Text = "Признак наличия отвала"; + this.checkBoxProvod.UseVisualStyleBackColor = true; + // + // checkBoxObv + // + this.checkBoxObv.AutoSize = true; + this.checkBoxObv.Location = new System.Drawing.Point(6, 120); + this.checkBoxObv.Name = "checkBoxObv"; + this.checkBoxObv.Size = new System.Drawing.Size(179, 19); + this.checkBoxObv.TabIndex = 4; + this.checkBoxObv.Text = "Признак наличия проводов"; + this.checkBoxObv.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(74, 71); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 42); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 73); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Вес:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 44); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Скорость:"; + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(12, 42); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(212, 122); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // panelobject + // + this.panelobject.AllowDrop = true; + this.panelobject.Controls.Add(this.LabelDopColor); + this.panelobject.Controls.Add(this.LabelBaseColor); + this.panelobject.Controls.Add(this.pictureBoxObject); + this.panelobject.Location = new System.Drawing.Point(525, 12); + this.panelobject.Name = "panelobject"; + this.panelobject.Size = new System.Drawing.Size(238, 172); + this.panelobject.TabIndex = 10; + this.panelobject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelobject_DragDrop); + this.panelobject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelobject_DragEnter); + // + // LabelDopColor + // + this.LabelDopColor.AllowDrop = true; + this.LabelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelDopColor.Location = new System.Drawing.Point(124, 9); + this.LabelDopColor.Name = "LabelDopColor"; + this.LabelDopColor.Size = new System.Drawing.Size(100, 23); + this.LabelDopColor.TabIndex = 3; + this.LabelDopColor.Text = "Доп.цвет"; + this.LabelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.LabelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); + this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter); + // + // LabelBaseColor + // + this.LabelBaseColor.AllowDrop = true; + this.LabelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelBaseColor.Location = new System.Drawing.Point(12, 9); + this.LabelBaseColor.Name = "LabelBaseColor"; + this.LabelBaseColor.Size = new System.Drawing.Size(100, 23); + this.LabelBaseColor.TabIndex = 2; + this.LabelBaseColor.Text = "Цвет"; + this.LabelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.LabelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop); + this.LabelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(537, 190); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(75, 23); + this.buttonOk.TabIndex = 11; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(674, 190); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 12; + this.button2.Text = "Отмена"; + this.button2.UseVisualStyleBackColor = true; + // + // FormLocomotiveConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(783, 221); + this.Controls.Add(this.button2); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panelobject); + this.Controls.Add(this.groupBox1); + this.Name = "FormLocomotiveConfig"; + this.Text = "FormLocomotiveConfig"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelobject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private Label labelHardObject; + private Label labelSimpleObject; + private GroupBox groupBox2; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelGray; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelPurple; + private Panel panelRed; + private Panel panelBlack; + private CheckBox checkBoxProvod; + private CheckBox checkBoxObv; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + private Label label1; + private PictureBox pictureBoxObject; + private Panel panelobject; + private Label LabelDopColor; + private Label LabelBaseColor; + private Button buttonOk; + private Button button2; + } +} \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs new file mode 100644 index 0000000..aa8e9ba --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs @@ -0,0 +1,139 @@ +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 + { + private event Action EventAddLocomotive; + DrawningLocomotive _locomotive = null; + public FormLocomotiveConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + } + + public void AddEvent(Action ev) + { + if (EventAddLocomotive == null) + { + EventAddLocomotive = new Action(ev); + } + else + { + EventAddLocomotive += ev; + } + } + + private void DrawLocomotive() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _locomotive?.SetPosition(5, 5, pictureBoxObject.Width, + pictureBoxObject.Height); + _locomotive?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + private void labelSimpleObject_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)) + { + 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.White); + } + break; + case "labelHardObject": + { + _locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxObv.Checked, checkBoxProvod.Checked); + } + break; + } + DrawLocomotive(); + } + + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddLocomotive?.Invoke(_locomotive); + Close(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) + { + _locomotive.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawLocomotive(); + } + + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_locomotive is not DrawningElectricLocomotive HardLocomotive) + { + return; + } + HardLocomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color))); + DrawLocomotive(); + } + + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelDopColor_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..f298a7b --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FormMapWithSetLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs index 903fcc8..6d4a64f 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs @@ -12,7 +12,7 @@ namespace ElectricLocomotive { public partial class FormMapWithSetLocomotive : Form { - private MapWithSetLocomotivGeneric _mapLocomotiveCollectionGeneric; + private MapWithSetLocomotivGeneric _mapShipCollectionGeneric; private readonly Dictionary _mapDict = new() { {"Простая карта", new SimpleMap() }, @@ -67,34 +67,37 @@ namespace ElectricLocomotive } if (map != null) { - _mapLocomotiveCollectionGeneric = new MapWithSetLocomotivGeneric( + _mapShipCollectionGeneric = new MapWithSetLocomotivGeneric( pictureBox1.Width, pictureBox1.Height, map); } else { - _mapLocomotiveCollectionGeneric = null; + _mapShipCollectionGeneric = null; } } private void ButtonAddLocomotive_Click(object sender, EventArgs e) + { + var FormLocmotiveConfig = new FormLocomotiveConfig(); + FormLocmotiveConfig.AddEvent(new(AddLocomotive)); + FormLocmotiveConfig.Show(); + } + public void AddLocomotive(DrawningLocomotive aircraft) { if (ListBoxMaps.SelectedIndex == -1) { return; } - FormLocomotive form = new(); - if (form.ShowDialog() == DialogResult.OK) + + if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(aircraft) != -1) { - DrawningObjectLocomotive Locomotive = new(form.SelectedLocomotive); - if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + Locomotive != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Object is added"); + pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } + else + { + MessageBox.Show("Unable to add object"); + } + } private void ButtonRemoveLocomotive_Click(object sender, EventArgs e) { @@ -131,11 +134,11 @@ namespace ElectricLocomotive } private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (ListBoxMaps.SelectedIndex == -1) - { - return; - } - pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); + if (ListBoxMaps.SelectedIndex == -1) + { + return; + } + pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) { @@ -182,7 +185,6 @@ namespace ElectricLocomotive { pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } - private void ButtonDeleteMap_Click(object sender, EventArgs e) { if (ListBoxMaps.SelectedIndex == -1) -- 2.25.1 From 227bfeed97dc7a5edebec31f716298f43904aff4 Mon Sep 17 00:00:00 2001 From: Stranni15k Date: Sat, 19 Nov 2022 23:10:17 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=965?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/FormMapWithSetLocomotive.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs index 6d4a64f..09199d9 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormMapWithSetLocomotive.cs @@ -12,7 +12,7 @@ namespace ElectricLocomotive { public partial class FormMapWithSetLocomotive : Form { - private MapWithSetLocomotivGeneric _mapShipCollectionGeneric; + private MapWithSetLocomotivGeneric _mapLocomotiveCollectionGeneric; private readonly Dictionary _mapDict = new() { {"Простая карта", new SimpleMap() }, @@ -67,12 +67,12 @@ namespace ElectricLocomotive } if (map != null) { - _mapShipCollectionGeneric = new MapWithSetLocomotivGeneric( + _mapLocomotiveCollectionGeneric = new MapWithSetLocomotivGeneric( pictureBox1.Width, pictureBox1.Height, map); } else { - _mapShipCollectionGeneric = null; + _mapLocomotiveCollectionGeneric = null; } } private void ButtonAddLocomotive_Click(object sender, EventArgs e) -- 2.25.1