From e5a45732e953dc04b0cbc1356c73c6c27d0e9613 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 6 Nov 2023 20:02:11 +0400 Subject: [PATCH] =?UTF-8?q?5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/EntityElectricLocomotive.cs | 4 + .../Entities/EntityLocomotive.cs | 5 + .../FormLocomotiveConfig.Designer.cs | 298 ++++++++++-------- ElectricLocomotive/FormLocomotiveConfig.cs | 43 +++ .../LogicFormLocomotiveCollection.cs | 39 ++- .../LogicFormLocomotiveConfig.cs | 79 ++++- 6 files changed, 325 insertions(+), 143 deletions(-) diff --git a/ElectricLocomotive/Entities/EntityElectricLocomotive.cs b/ElectricLocomotive/Entities/EntityElectricLocomotive.cs index fb7cb99..c8bdf72 100644 --- a/ElectricLocomotive/Entities/EntityElectricLocomotive.cs +++ b/ElectricLocomotive/Entities/EntityElectricLocomotive.cs @@ -42,5 +42,9 @@ namespace ProjectElectricLocomotive.Entities Battery = battery; } + public void ChangeAdditionalColor(Color additionalColor) + { + AdditionalColor = additionalColor; + } } } diff --git a/ElectricLocomotive/Entities/EntityLocomotive.cs b/ElectricLocomotive/Entities/EntityLocomotive.cs index f115bac..becb8e7 100644 --- a/ElectricLocomotive/Entities/EntityLocomotive.cs +++ b/ElectricLocomotive/Entities/EntityLocomotive.cs @@ -42,5 +42,10 @@ namespace ProjectElectricLocomotive.Entities Weight = weight; BodyColor = bodyColor; } + + public void ChangeBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs index 1cce53c..752b6e0 100644 --- a/ElectricLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -29,17 +29,17 @@ private void InitializeComponent() { groupBox1 = new GroupBox(); - label4 = new Label(); + labelModifiedObject = new Label(); labelSimpleObject = new Label(); groupBox2 = new GroupBox(); - panel8 = new Panel(); - panel7 = new Panel(); - panel6 = new Panel(); - panel5 = new Panel(); - panel4 = new Panel(); - panel3 = new Panel(); - panel2 = new Panel(); - panel1 = new Panel(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); checkBoxBattery = new CheckBox(); checkBoxHorns = new CheckBox(); numericUpDownWeight = new NumericUpDown(); @@ -47,21 +47,22 @@ label2 = new Label(); label1 = new Label(); pictureBoxObject = new PictureBox(); - label5 = new Label(); - label6 = new Label(); - label7 = new Label(); - button1 = new Button(); - button2 = new Button(); + labelBodyColor = new Label(); + labelAdditionalColor = new Label(); + buttonOK = new Button(); + buttonClose = new Button(); + panelObject = new Panel(); groupBox1.SuspendLayout(); groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); SuspendLayout(); // // groupBox1 // - groupBox1.Controls.Add(label4); + groupBox1.Controls.Add(labelModifiedObject); groupBox1.Controls.Add(labelSimpleObject); groupBox1.Controls.Add(groupBox2); groupBox1.Controls.Add(checkBoxBattery); @@ -77,15 +78,16 @@ groupBox1.TabStop = false; groupBox1.Text = "Параметры"; // - // label4 + // labelModifiedObject // - label4.BorderStyle = BorderStyle.FixedSingle; - label4.Location = new Point(404, 219); - label4.Name = "label4"; - label4.Size = new Size(113, 35); - label4.TabIndex = 8; - label4.Text = "Продвинутый"; - label4.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(397, 219); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(113, 35); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += labelObject_MouseDown; // // labelSimpleObject // @@ -96,17 +98,18 @@ labelSimpleObject.TabIndex = 7; labelSimpleObject.Text = "Простой"; labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelObject_MouseDown; // // groupBox2 // - groupBox2.Controls.Add(panel8); - groupBox2.Controls.Add(panel7); - groupBox2.Controls.Add(panel6); - groupBox2.Controls.Add(panel5); - groupBox2.Controls.Add(panel4); - groupBox2.Controls.Add(panel3); - groupBox2.Controls.Add(panel2); - groupBox2.Controls.Add(panel1); + groupBox2.Controls.Add(panelPurple); + groupBox2.Controls.Add(panelBlack); + groupBox2.Controls.Add(panelGray); + groupBox2.Controls.Add(panelWhite); + groupBox2.Controls.Add(panelYellow); + groupBox2.Controls.Add(panelBlue); + groupBox2.Controls.Add(panelGreen); + groupBox2.Controls.Add(panelRed); groupBox2.Location = new Point(278, 57); groupBox2.Name = "groupBox2"; groupBox2.Size = new Size(239, 135); @@ -114,69 +117,77 @@ groupBox2.TabStop = false; groupBox2.Text = "Цвета"; // - // panel8 + // panelPurple // - panel8.BackColor = Color.Purple; - panel8.Location = new Point(184, 81); - panel8.Name = "panel8"; - panel8.Size = new Size(40, 40); - panel8.TabIndex = 3; + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(184, 81); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(40, 40); + panelPurple.TabIndex = 3; + panelPurple.MouseDown += panelObject_MouseDown; // - // panel7 + // panelBlack // - panel7.BackColor = Color.Black; - panel7.Location = new Point(129, 81); - panel7.Name = "panel7"; - panel7.Size = new Size(40, 40); - panel7.TabIndex = 3; + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(129, 81); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(40, 40); + panelBlack.TabIndex = 3; + panelBlack.MouseDown += panelObject_MouseDown; // - // panel6 + // panelGray // - panel6.BackColor = Color.Gray; - panel6.Location = new Point(73, 81); - panel6.Name = "panel6"; - panel6.Size = new Size(40, 40); - panel6.TabIndex = 3; + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(73, 81); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(40, 40); + panelGray.TabIndex = 3; + panelGray.MouseDown += panelObject_MouseDown; // - // panel5 + // panelWhite // - panel5.BackColor = Color.White; - panel5.Location = new Point(15, 81); - panel5.Name = "panel5"; - panel5.Size = new Size(40, 40); - panel5.TabIndex = 4; + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(15, 81); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(40, 40); + panelWhite.TabIndex = 4; + panelWhite.MouseDown += panelObject_MouseDown; // - // panel4 + // panelYellow // - panel4.BackColor = Color.Yellow; - panel4.Location = new Point(184, 26); - panel4.Name = "panel4"; - panel4.Size = new Size(40, 40); - panel4.TabIndex = 3; + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(184, 26); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(40, 40); + panelYellow.TabIndex = 3; + panelYellow.MouseDown += panelObject_MouseDown; // - // panel3 + // panelBlue // - panel3.BackColor = Color.Blue; - panel3.Location = new Point(129, 26); - panel3.Name = "panel3"; - panel3.Size = new Size(40, 40); - panel3.TabIndex = 2; + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(129, 26); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(40, 40); + panelBlue.TabIndex = 2; + panelBlue.MouseDown += panelObject_MouseDown; // - // panel2 + // panelGreen // - panel2.BackColor = Color.Green; - panel2.Location = new Point(73, 26); - panel2.Name = "panel2"; - panel2.Size = new Size(40, 40); - panel2.TabIndex = 1; + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(73, 26); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(40, 40); + panelGreen.TabIndex = 1; + panelGreen.MouseDown += panelObject_MouseDown; // - // panel1 + // panelRed // - panel1.BackColor = Color.Red; - panel1.Location = new Point(15, 26); - panel1.Name = "panel1"; - panel1.Size = new Size(40, 40); - panel1.TabIndex = 0; + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(15, 26); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(40, 40); + panelRed.TabIndex = 0; + panelRed.MouseDown += panelObject_MouseDown; // // checkBoxBattery // @@ -238,70 +249,80 @@ // // pictureBoxObject // - pictureBoxObject.Location = new Point(608, 90); + pictureBoxObject.Location = new Point(11, 60); pictureBoxObject.Name = "pictureBoxObject"; - pictureBoxObject.Size = new Size(244, 181); + pictureBoxObject.Size = new Size(244, 194); pictureBoxObject.TabIndex = 1; pictureBoxObject.TabStop = false; // - // label5 + // labelBodyColor // - label5.BorderStyle = BorderStyle.FixedSingle; - label5.Location = new Point(586, 42); - label5.Name = "label5"; - label5.Size = new Size(287, 243); - label5.TabIndex = 2; + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(11, 14); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(113, 35); + labelBodyColor.TabIndex = 8; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += labelBodyColor_DragDrop; + labelBodyColor.DragEnter += labelObject_DragEnter; // - // label6 + // labelAdditionalColor // - label6.BorderStyle = BorderStyle.FixedSingle; - label6.Location = new Point(608, 52); - label6.Name = "label6"; - label6.Size = new Size(113, 35); - label6.TabIndex = 8; - label6.Text = "Цвет"; - label6.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(142, 14); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(113, 35); + labelAdditionalColor.TabIndex = 9; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelObject_DragEnter; // - // label7 + // buttonOK // - label7.BorderStyle = BorderStyle.FixedSingle; - label7.Location = new Point(739, 52); - label7.Name = "label7"; - label7.Size = new Size(113, 35); - label7.TabIndex = 9; - label7.Text = "Доп. цвет"; - label7.TextAlign = ContentAlignment.MiddleCenter; + buttonOK.Location = new Point(608, 295); + buttonOK.Name = "buttonOK"; + buttonOK.Size = new Size(113, 29); + buttonOK.TabIndex = 10; + buttonOK.Text = "Добавить"; + buttonOK.UseVisualStyleBackColor = true; + buttonOK.Click += buttonOk_Click; // - // button1 + // buttonClose // - button1.Location = new Point(608, 295); - button1.Name = "button1"; - button1.Size = new Size(113, 29); - button1.TabIndex = 10; - button1.Text = "Добавить"; - button1.UseVisualStyleBackColor = true; + buttonClose.Location = new Point(739, 295); + buttonClose.Name = "buttonClose"; + buttonClose.Size = new Size(113, 29); + buttonClose.TabIndex = 11; + buttonClose.Text = "Отмена"; + buttonClose.UseVisualStyleBackColor = true; + buttonClose.Click += buttonClose_Click; // - // button2 + // panelObject // - button2.Location = new Point(739, 295); - button2.Name = "button2"; - button2.Size = new Size(113, 29); - button2.TabIndex = 11; - button2.Text = "Отмена"; - button2.UseVisualStyleBackColor = true; + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelBodyColor); + panelObject.Location = new Point(597, 31); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(266, 254); + panelObject.TabIndex = 12; + panelObject.DragDrop += panelObject_DragDrop; + panelObject.DragEnter += panelObject_DragEnter; // // FormLocomotiveConfig // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1149, 339); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(label7); - Controls.Add(label6); - Controls.Add(pictureBoxObject); + ClientSize = new Size(911, 339); + Controls.Add(buttonClose); + Controls.Add(buttonOK); Controls.Add(groupBox1); - Controls.Add(label5); + Controls.Add(panelObject); Name = "FormLocomotiveConfig"; Text = "FormLocomotiveConfig"; groupBox1.ResumeLayout(false); @@ -310,6 +331,7 @@ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); ResumeLayout(false); } @@ -323,21 +345,21 @@ private CheckBox checkBoxBattery; private CheckBox checkBoxHorns; private GroupBox groupBox2; - private Panel panel1; - private Panel panel8; - private Panel panel7; - private Panel panel6; - private Panel panel5; - private Panel panel4; - private Panel panel3; - private Panel panel2; - private Label label4; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Label labelModifiedObject; private Label labelSimpleObject; private PictureBox pictureBoxObject; - private Label label5; - private Label label6; - private Label label7; - private Button button1; - private Button button2; + private Label labelBodyColor; + private Label labelAdditionalColor; + private Button buttonOK; + private Button buttonClose; + private Panel panelObject; } } \ No newline at end of file diff --git a/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/FormLocomotiveConfig.cs index c44623e..b0415ae 100644 --- a/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/FormLocomotiveConfig.cs @@ -12,5 +12,48 @@ namespace ProjectElectricLocomotive { public partial class FormLocomotiveConfig { + private void labelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void panelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void panelObject_DragEnter(object sender, DragEventArgs e) + { + PanelObject_DragEnter(sender, e); + } + private void labelObject_DragEnter(object sender, DragEventArgs e) + { + LabelObject_DragEnter(sender, e); + } + + private void labelBodyColor_DragDrop(object sender, DragEventArgs e) + { + LabelBodyColor_DragDrop(sender, e); + } + + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + LabelAdditionalColor_DragDrop(sender, e); + } + + private void panelObject_DragDrop(object sender, DragEventArgs e) + { + PanelObject_DragDrop(sender, e); + } + + private void buttonOk_Click(object sender, EventArgs e) + { + ButtonOk_Click(sender, e); + } + + private void buttonClose_Click(object sender, EventArgs e) + { + ButtonClose_Click(sender, e); + } } } diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index 826e691..524dabb 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -105,10 +105,34 @@ namespace ProjectElectricLocomotive /// private void ButtonAddLocomotive_Click(object sender, EventArgs e) { - var formCarConfig = new FormLocomotiveConfig(); - // TODO Call method AddEvent from formCarConfig - formCarConfig.Show(); + var formLocomotiveConfig = new FormLocomotiveConfig(); + formLocomotiveConfig.AddEvent(addLocomotive); + formLocomotiveConfig.Show(); } + private void addLocomotive(DrawningLocomotive SelectedLocomotive) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + SelectedLocomotive.SetPictureSize(pictureBoxCollection.Size); + if (obj + SelectedLocomotive > 0) + { + MessageBox.Show("Объект добавлен"); + + pictureBoxCollection.Image = obj.ShowLocomotives(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + /// /// Удаление объекта из набора /// @@ -131,7 +155,14 @@ namespace ProjectElectricLocomotive { return; } - int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + int pos; + try + { + pos = Convert.ToInt32(maskedTextBoxNumber.Text); + } catch(System.FormatException ex) + { + pos = 0; + } if (obj - pos != -1) { MessageBox.Show("Объект удален"); diff --git a/ElectricLocomotive/LogicFormLocomotiveConfig.cs b/ElectricLocomotive/LogicFormLocomotiveConfig.cs index 4c62816..14193fb 100644 --- a/ElectricLocomotive/LogicFormLocomotiveConfig.cs +++ b/ElectricLocomotive/LogicFormLocomotiveConfig.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectElectricLocomotive.DrawningObjects; +using ProjectElectricLocomotive.Entities; namespace ProjectElectricLocomotive { @@ -114,10 +116,75 @@ namespace ProjectElectricLocomotive break; } DrawLocomotive(); - // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + } + // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + + private void LabelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } } + /// + /// Передаем информацию при нажатии на Panel + /// + /// + /// + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Передача базового цвета + /// + /// + /// + private void LabelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_locomotive is null) + { + MessageBox.Show("Локомотив не задан"); + return; + } + Color bodyColor = (Color)e.Data?.GetData(typeof(Color)); + + _locomotive?.EntityLocomotive.ChangeBodyColor(bodyColor); + DrawLocomotive(); + } + + /// + /// Передача дополнительного цвета цвета + /// + /// + /// + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_locomotive is null) + { + MessageBox.Show("Локомотив не задан"); + return; + } + Color addColor = (Color)e.Data?.GetData(typeof(Color)); + + if (_locomotive is DrawningElectricLocomotive) + { + (_locomotive?.EntityLocomotive as EntityElectricLocomotive).ChangeAdditionalColor(addColor); + } + else + { + MessageBox.Show("Нельзя задать доп. цвет обычному локомотиву"); + } + DrawLocomotive(); + } + /// /// Добавление локомотива /// @@ -129,5 +196,15 @@ namespace ProjectElectricLocomotive Close(); } + /// + /// Отмена Добавления локомотива + /// + /// + /// + private void ButtonClose_Click(object sender, EventArgs e) + { + EventAddLocomotive?.Invoke(_locomotive); + Close(); + } } } \ No newline at end of file