diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs index 07ffd1b..db8f44f 100644 --- a/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs @@ -24,6 +24,15 @@ namespace ProjectLocomotive Locomotivе = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, electroLines, electroBattery); } + public void SetExtraColor(Color color) + { + var LocomotiveElectro = Locomotivе as EntityElectricLocomotive; + if (LocomotiveElectro is not null) + { + LocomotiveElectro = new EntityElectricLocomotive(LocomotiveElectro.Speed, LocomotiveElectro.Weight, LocomotiveElectro.BodyColor, color, LocomotiveElectro.ElectroLines, LocomotiveElectro.ElectroBattery); + Locomotivе = LocomotiveElectro; + } + } public override void DrawTransport(Graphics g) { if (Locomotivе is not EntityElectricLocomotive elLocc) @@ -31,7 +40,7 @@ namespace ProjectLocomotive return; } Pen pen = new(Color.Black); - Brush dopBrush = new SolidBrush(elLocc.DopColor); + if (elLocc.ElectroLines) { g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12); @@ -43,10 +52,10 @@ namespace ProjectLocomotive base.DrawTransport(g); if (elLocc.ElectroBattery) { - Brush brblack = new SolidBrush(Color.Black); - g.FillRectangle(brblack, _startPosX + 40, _startPosY + 25, 15, 5); - g.FillRectangle(brblack, _startPosX + 60, _startPosY + 25, 15, 5); - g.FillRectangle(brblack, _startPosX + 5, _startPosY + 25, 15, 5); + Brush dopBrush = new SolidBrush(elLocc.DopColor); + g.FillRectangle(dopBrush, _startPosX + 40, _startPosY + 25, 15, 5); + g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 25, 15, 5); + g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 25, 15, 5); } } } diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs index 0797b22..48ccbf7 100644 --- a/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/DrawningLocomotive.cs @@ -64,6 +64,18 @@ namespace ProjectLocomotive _LocWidth = carWidth; _LocHeight = carHeight; } + public void SetBaseColor(Color color) + { + if (Locomotivе is EntityElectricLocomotive) + { + Locomotivе = (EntityElectricLocomotive)Locomotivе; + if (Locomotivе is not null) + { + Locomotivе = new EntityElectricLocomotive(Locomotivе.Speed, Locomotivе.Weight, color, (Locomotivе as EntityElectricLocomotive).DopColor, (Locomotivе as EntityElectricLocomotive).ElectroLines, (Locomotivе as EntityElectricLocomotive).ElectroBattery); + return; + } + } + } /// /// Установка позиции автомобиля /// diff --git a/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs index 096cbc9..9edc44c 100644 --- a/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/EntityElectricLocomotive.cs @@ -11,7 +11,7 @@ namespace ProjectLocomotive /// /// Дополнительный цвет /// - public Color DopColor { get; private set; } + public Color DopColor { get; set; } /// /// Признак наличия "рогов" для подключения /// @@ -34,8 +34,8 @@ namespace ProjectLocomotive base(speed, weight, bodyColor) { DopColor = dopColor; - ElectroLines = electroLines = true; - ElectroBattery = electroBattery = true; + ElectroLines = electroLines; + ElectroBattery = electroBattery; } } } diff --git a/ProjectLocomotive/ProjectLocomotive/EntityLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/EntityLocomotive.cs index add3955..4782ac2 100644 --- a/ProjectLocomotive/ProjectLocomotive/EntityLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/EntityLocomotive.cs @@ -19,7 +19,7 @@ namespace ProjectLocomotive /// /// Цвет кузова /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг передвижения локомотива /// diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs index 63c3771..bd67b24 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs @@ -188,9 +188,7 @@ this.ResumeLayout(false); this.PerformLayout(); } - #endregion - private PictureBox pictureBoxLocomotive; private Button buttonCreate; private Button buttonUp; diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs new file mode 100644 index 0000000..9057d41 --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs @@ -0,0 +1,391 @@ +namespace ProjectLocomotive +{ + 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.groupBoxConfig = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxFuelStorage = new System.Windows.Forms.CheckBox(); + this.checkBoxPipe = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelDopColor = new System.Windows.Forms.Label(); + this.labelBaseColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxConfig.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelModifiedObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColors); + this.groupBoxConfig.Controls.Add(this.checkBoxFuelStorage); + this.groupBoxConfig.Controls.Add(this.checkBoxPipe); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(15, 15); + this.groupBoxConfig.Margin = new System.Windows.Forms.Padding(4); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Padding = new System.Windows.Forms.Padding(4); + this.groupBoxConfig.Size = new System.Drawing.Size(566, 325); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Конфигурация"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(390, 250); + this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(143, 56); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Модифицированный"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(224, 250); + this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(143, 56); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); + // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(224, 32); + this.groupBoxColors.Margin = new System.Windows.Forms.Padding(4); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Padding = new System.Windows.Forms.Padding(4); + this.groupBoxColors.Size = new System.Drawing.Size(310, 195); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Fuchsia; + this.panelPurple.Location = new System.Drawing.Point(241, 128); + this.panelPurple.Margin = new System.Windows.Forms.Padding(4); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(54, 50); + this.panelPurple.TabIndex = 3; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(165, 128); + this.panelBlack.Margin = new System.Windows.Forms.Padding(4); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(54, 50); + this.panelBlack.TabIndex = 2; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(90, 128); + this.panelGray.Margin = new System.Windows.Forms.Padding(4); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(54, 50); + this.panelGray.TabIndex = 3; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(14, 128); + this.panelWhite.Margin = new System.Windows.Forms.Padding(4); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(54, 50); + this.panelWhite.TabIndex = 2; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(241, 39); + this.panelYellow.Margin = new System.Windows.Forms.Padding(4); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(54, 50); + this.panelYellow.TabIndex = 1; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.Location = new System.Drawing.Point(90, 39); + this.panelGreen.Margin = new System.Windows.Forms.Padding(4); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(54, 50); + this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(166, 39); + this.panelBlue.Margin = new System.Windows.Forms.Padding(4); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(54, 50); + this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(14, 39); + this.panelRed.Margin = new System.Windows.Forms.Padding(4); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(54, 50); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxFuelStorage + // + this.checkBoxFuelStorage.AutoSize = true; + this.checkBoxFuelStorage.Location = new System.Drawing.Point(9, 198); + this.checkBoxFuelStorage.Margin = new System.Windows.Forms.Padding(4); + this.checkBoxFuelStorage.Name = "checkBoxFuelStorage"; + this.checkBoxFuelStorage.Size = new System.Drawing.Size(207, 29); + this.checkBoxFuelStorage.TabIndex = 5; + this.checkBoxFuelStorage.Text = "Добавление батарей"; + this.checkBoxFuelStorage.UseVisualStyleBackColor = true; + // + // checkBoxPipe + // + this.checkBoxPipe.AutoSize = true; + this.checkBoxPipe.Location = new System.Drawing.Point(9, 160); + this.checkBoxPipe.Margin = new System.Windows.Forms.Padding(4); + this.checkBoxPipe.Name = "checkBoxPipe"; + this.checkBoxPipe.Size = new System.Drawing.Size(192, 29); + this.checkBoxPipe.TabIndex = 4; + this.checkBoxPipe.Text = "Добавление рогов"; + this.checkBoxPipe.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(94, 94); + this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(4); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(85, 31); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(9, 96); + this.labelWeight.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(48, 25); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Вес: "; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(92, 39); + this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(4); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(86, 31); + this.numericUpDownSpeed.TabIndex = 1; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(8, 41); + this.labelSpeed.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(98, 25); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость: "; + // + // 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(589, 28); + this.panelObject.Margin = new System.Windows.Forms.Padding(4); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(524, 312); + this.panelObject.TabIndex = 1; + 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(290, 20); + this.labelDopColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelDopColor.Name = "labelDopColor"; + this.labelDopColor.Size = new System.Drawing.Size(143, 56); + this.labelDopColor.TabIndex = 9; + 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.LabelColor_DragEnter); + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(86, 20); + this.labelBaseColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(143, 56); + this.labelBaseColor.TabIndex = 8; + this.labelBaseColor.Text = "Базовый цвет"; + this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(20, 84); + this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(4); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(482, 210); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(609, 348); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(210, 36); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(879, 348); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(212, 36); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormLocomotiveConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1128, 394); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Margin = new System.Windows.Forms.Padding(4); + this.Name = "FormLocomotiveConfig"; + this.Text = "Object Creation"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + private GroupBox groupBoxConfig; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private CheckBox checkBoxFuelStorage; + private CheckBox checkBoxPipe; + private GroupBox groupBoxColors; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelGreen; + private Panel panelBlue; + private Label labelSimpleObject; + private Label labelModifiedObject; + private Panel panelObject; + private PictureBox pictureBoxObject; + private Label labelDopColor; + private Label labelBaseColor; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.cs new file mode 100644 index 0000000..b53d43c --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.cs @@ -0,0 +1,124 @@ +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 ProjectLocomotive +{ + public partial class FormLocomotiveConfig : Form + { + DrawningLocomotive _locomotive = null; + private event Action eventAddLocomotive; + public void AddEvent(Action ev) + { + if (eventAddLocomotive == null) + { + eventAddLocomotive = new Action(ev); + } + else + { + eventAddLocomotive += ev; + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + eventAddLocomotive?.Invoke(_locomotive); + Close(); + } + 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; + buttonCancel.Click += (object sender, EventArgs e) => Close(); + } + 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)) + { + 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 "labelModifiedObject": + _locomotive = new DrawningElectroLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + Color.White, Color.Black, + checkBoxPipe.Checked, checkBoxFuelStorage.Checked); + break; + } + DrawLocomotive(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + 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 labelDopColor_DragDrop(object sender, DragEventArgs e) + { + // ! - TODO + if (_locomotive is DrawningElectroLocomotive) + { + var locomotive = _locomotive as DrawningElectroLocomotive; + locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color))); + } + DrawLocomotive(); + } + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + var color = e.Data.GetData(typeof(Color)); + if (color != null) + { + (sender as Label).BackColor = (Color)color; + } + DrawLocomotive(); + if (_locomotive != null) + { + _locomotive.Locomotivе.BodyColor = (Color)color; + DrawLocomotive(); + } + } + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.resx b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/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/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs index b0207a1..bb232b1 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs @@ -262,9 +262,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); } - #endregion - private GroupBox groupBoxTools; private PictureBox pictureBox; private ComboBox comboBoxSelectorMap; diff --git a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs index 2a9b9cd..5385cb3 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs @@ -54,25 +54,28 @@ namespace ProjectLocomotive } /// Добавление объекта private void buttonAddLocomotive_Click(object sender, EventArgs e) + { + var formCarConfig = new FormLocomotiveConfig(); + formCarConfig.AddEvent(new(AddLocomotive)); + formCarConfig.Show(); + } + private void AddLocomotive(DrawningLocomotive locomotive) { if (listBoxMaps.SelectedIndex == -1) { return; } - FormLocomotive form = new(); - if (form.ShowDialog() == DialogResult.OK) + + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(locomotive) != -1) { - DrawningObject locomotive = new(form.SelectedLocomotive); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } + else + { + MessageBox.Show("Ошибка при добавлении объекта"); + } + } /// Удаление объекта private void buttonRemoveLocomotive_Click(object sender, EventArgs e)