From 26a589af930c3c6f63a250cf4cbb7351f27c838d Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sat, 4 Nov 2023 13:18:36 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=BA=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D0=BF=D0=B4=D1=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveConfig.Designer.cs | 343 ++++++++++++++++++ ElectricLocomotive/FormLocomotiveConfig.cs | 16 + ElectricLocomotive/FormLocomotiveConfig.resx | 120 ++++++ .../LogicFormLocomotiveCollection.cs | 37 +- .../LogicFormLocomotiveConfig.cs | 133 +++++++ 5 files changed, 615 insertions(+), 34 deletions(-) create mode 100644 ElectricLocomotive/FormLocomotiveConfig.Designer.cs create mode 100644 ElectricLocomotive/FormLocomotiveConfig.cs create mode 100644 ElectricLocomotive/FormLocomotiveConfig.resx create mode 100644 ElectricLocomotive/LogicFormLocomotiveConfig.cs diff --git a/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs new file mode 100644 index 0000000..1cce53c --- /dev/null +++ b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -0,0 +1,343 @@ +namespace ProjectElectricLocomotive +{ + partial class FormLocomotiveConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBox1 = new GroupBox(); + label4 = 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(); + checkBoxBattery = new CheckBox(); + checkBoxHorns = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + pictureBoxObject = new PictureBox(); + label5 = new Label(); + label6 = new Label(); + label7 = new Label(); + button1 = new Button(); + button2 = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(label4); + groupBox1.Controls.Add(labelSimpleObject); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(checkBoxBattery); + groupBox1.Controls.Add(checkBoxHorns); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(label1); + groupBox1.Location = new Point(12, 31); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(568, 293); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // label4 + // + 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; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(278, 219); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(113, 35); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + // + // 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.Location = new Point(278, 57); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(239, 135); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Цвета"; + // + // panel8 + // + panel8.BackColor = Color.Purple; + panel8.Location = new Point(184, 81); + panel8.Name = "panel8"; + panel8.Size = new Size(40, 40); + panel8.TabIndex = 3; + // + // panel7 + // + panel7.BackColor = Color.Black; + panel7.Location = new Point(129, 81); + panel7.Name = "panel7"; + panel7.Size = new Size(40, 40); + panel7.TabIndex = 3; + // + // panel6 + // + panel6.BackColor = Color.Gray; + panel6.Location = new Point(73, 81); + panel6.Name = "panel6"; + panel6.Size = new Size(40, 40); + panel6.TabIndex = 3; + // + // panel5 + // + panel5.BackColor = Color.White; + panel5.Location = new Point(15, 81); + panel5.Name = "panel5"; + panel5.Size = new Size(40, 40); + panel5.TabIndex = 4; + // + // panel4 + // + panel4.BackColor = Color.Yellow; + panel4.Location = new Point(184, 26); + panel4.Name = "panel4"; + panel4.Size = new Size(40, 40); + panel4.TabIndex = 3; + // + // panel3 + // + panel3.BackColor = Color.Blue; + panel3.Location = new Point(129, 26); + panel3.Name = "panel3"; + panel3.Size = new Size(40, 40); + panel3.TabIndex = 2; + // + // panel2 + // + panel2.BackColor = Color.Green; + panel2.Location = new Point(73, 26); + panel2.Name = "panel2"; + panel2.Size = new Size(40, 40); + panel2.TabIndex = 1; + // + // panel1 + // + panel1.BackColor = Color.Red; + panel1.Location = new Point(15, 26); + panel1.Name = "panel1"; + panel1.Size = new Size(40, 40); + panel1.TabIndex = 0; + // + // checkBoxBattery + // + checkBoxBattery.AutoSize = true; + checkBoxBattery.Location = new Point(27, 230); + checkBoxBattery.Name = "checkBoxBattery"; + checkBoxBattery.Size = new Size(215, 24); + checkBoxBattery.TabIndex = 5; + checkBoxBattery.Text = "Признак наличия батареи"; + checkBoxBattery.UseVisualStyleBackColor = true; + // + // checkBoxHorns + // + checkBoxHorns.AutoSize = true; + checkBoxHorns.Location = new Point(27, 186); + checkBoxHorns.Name = "checkBoxHorns"; + checkBoxHorns.Size = new Size(199, 24); + checkBoxHorns.TabIndex = 4; + checkBoxHorns.Text = "Признак наличия рогов"; + checkBoxHorns.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(109, 105); + 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(86, 27); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(109, 57); + 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(86, 27); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(27, 107); + label2.Name = "label2"; + label2.Size = new Size(36, 20); + label2.TabIndex = 1; + label2.Text = "Вес:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(27, 59); + label1.Name = "label1"; + label1.Size = new Size(76, 20); + label1.TabIndex = 0; + label1.Text = "Скорость:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(608, 90); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(244, 181); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // label5 + // + label5.BorderStyle = BorderStyle.FixedSingle; + label5.Location = new Point(586, 42); + label5.Name = "label5"; + label5.Size = new Size(287, 243); + label5.TabIndex = 2; + // + // label6 + // + 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; + // + // label7 + // + 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; + // + // button1 + // + button1.Location = new Point(608, 295); + button1.Name = "button1"; + button1.Size = new Size(113, 29); + button1.TabIndex = 10; + button1.Text = "Добавить"; + button1.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(739, 295); + button2.Name = "button2"; + button2.Size = new Size(113, 29); + button2.TabIndex = 11; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // 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); + Controls.Add(groupBox1); + Controls.Add(label5); + Name = "FormLocomotiveConfig"; + Text = "FormLocomotiveConfig"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private Label label1; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + 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 Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Label label5; + private Label label6; + private Label label7; + private Button button1; + private Button button2; + } +} \ No newline at end of file diff --git a/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/FormLocomotiveConfig.cs new file mode 100644 index 0000000..c44623e --- /dev/null +++ b/ElectricLocomotive/FormLocomotiveConfig.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectElectricLocomotive +{ + public partial class FormLocomotiveConfig + { + } +} diff --git a/ElectricLocomotive/FormLocomotiveConfig.resx b/ElectricLocomotive/FormLocomotiveConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ElectricLocomotive/FormLocomotiveConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index faa123f..826e691 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -97,17 +97,6 @@ namespace ProjectElectricLocomotive ReloadObjects(); } } - /// - /// Добавление набора в коллекцию - /// - /// - /// - - /// - /// Выбор набора - /// - /// - /// /// /// Добавление объекта в набор @@ -116,29 +105,9 @@ namespace ProjectElectricLocomotive /// private void ButtonAddLocomotive_Click(object sender, EventArgs e) { - if (listBoxStorages.SelectedIndex == -1) - { - return; - } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - if (obj == null) - { - return; - } - - FormLocomotive form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedLocomotive > 0) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowLocomotives(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + var formCarConfig = new FormLocomotiveConfig(); + // TODO Call method AddEvent from formCarConfig + formCarConfig.Show(); } /// /// Удаление объекта из набора diff --git a/ElectricLocomotive/LogicFormLocomotiveConfig.cs b/ElectricLocomotive/LogicFormLocomotiveConfig.cs new file mode 100644 index 0000000..4c62816 --- /dev/null +++ b/ElectricLocomotive/LogicFormLocomotiveConfig.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectElectricLocomotive.DrawningObjects; + +namespace ProjectElectricLocomotive +{ + partial class FormLocomotiveConfig : Form + { + /// + /// Переменная-выбранный локомотив + /// + DrawningLocomotive? _locomotive = null; + + /// + /// Событие + /// + private event Action? EventAddLocomotive; + + /// + /// Конструктор + /// + 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; + // TODO buttonCancel.Click with lambda + } + + /// + /// Отрисовать локомотив + /// + private void DrawLocomotive() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _locomotive?.SetPosition(5, 5); + _locomotive?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action? ev) + { + if (EventAddLocomotive == null) + { + EventAddLocomotive = ev; + } + else + { + EventAddLocomotive += ev; + } + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + 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.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, + checkBoxHorns.Checked, checkBoxBattery.Checked, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawLocomotive(); + // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + } + + + /// + /// Добавление локомотива + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddLocomotive?.Invoke(_locomotive); + Close(); + } + + } +} \ No newline at end of file -- 2.25.1 From e5a45732e953dc04b0cbc1356c73c6c27d0e9613 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Mon, 6 Nov 2023 20:02:11 +0400 Subject: [PATCH 2/4] =?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 -- 2.25.1 From d03960db7987150fcee9a33ba93fe7afac5d8d4e Mon Sep 17 00:00:00 2001 From: bekodeg Date: Tue, 7 Nov 2023 12:23:36 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BB=D1=8F=D0=BC=D0=B1=D0=B4=D1=83=20=D0=B8=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B3=D0=B0=20=D1=81=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveConfig.Designer.cs | 1 - ElectricLocomotive/FormLocomotiveConfig.cs | 5 ----- ElectricLocomotive/LogicFormLocomotiveConfig.cs | 17 +++++------------ 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs index 752b6e0..02093e8 100644 --- a/ElectricLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -299,7 +299,6 @@ buttonClose.TabIndex = 11; buttonClose.Text = "Отмена"; buttonClose.UseVisualStyleBackColor = true; - buttonClose.Click += buttonClose_Click; // // panelObject // diff --git a/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/FormLocomotiveConfig.cs index b0415ae..03afa28 100644 --- a/ElectricLocomotive/FormLocomotiveConfig.cs +++ b/ElectricLocomotive/FormLocomotiveConfig.cs @@ -50,10 +50,5 @@ namespace ProjectElectricLocomotive { ButtonOk_Click(sender, e); } - - private void buttonClose_Click(object sender, EventArgs e) - { - ButtonClose_Click(sender, e); - } } } diff --git a/ElectricLocomotive/LogicFormLocomotiveConfig.cs b/ElectricLocomotive/LogicFormLocomotiveConfig.cs index 14193fb..49f39df 100644 --- a/ElectricLocomotive/LogicFormLocomotiveConfig.cs +++ b/ElectricLocomotive/LogicFormLocomotiveConfig.cs @@ -36,6 +36,7 @@ namespace ProjectElectricLocomotive panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; // TODO buttonCancel.Click with lambda + buttonClose.Click += (sender, e) => Close(); } /// @@ -192,18 +193,10 @@ namespace ProjectElectricLocomotive /// private void ButtonOk_Click(object sender, EventArgs e) { - EventAddLocomotive?.Invoke(_locomotive); - Close(); - } - - /// - /// Отмена Добавления локомотива - /// - /// - /// - private void ButtonClose_Click(object sender, EventArgs e) - { - EventAddLocomotive?.Invoke(_locomotive); + if (_locomotive is not null) + { + EventAddLocomotive?.Invoke(_locomotive); + } Close(); } } -- 2.25.1 From 59a0baa1aa5dbcc2e54da64f5f258c590c23e2f6 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 8 Nov 2023 08:47:24 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20TUD?= =?UTF-8?q?O?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ElectricLocomotive/LogicFormLocomotiveConfig.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ElectricLocomotive/LogicFormLocomotiveConfig.cs b/ElectricLocomotive/LogicFormLocomotiveConfig.cs index 49f39df..a62e59e 100644 --- a/ElectricLocomotive/LogicFormLocomotiveConfig.cs +++ b/ElectricLocomotive/LogicFormLocomotiveConfig.cs @@ -35,7 +35,6 @@ namespace ProjectElectricLocomotive panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - // TODO buttonCancel.Click with lambda buttonClose.Click += (sender, e) => Close(); } @@ -118,7 +117,6 @@ namespace ProjectElectricLocomotive } DrawLocomotive(); } - // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) private void LabelObject_DragEnter(object sender, DragEventArgs e) { -- 2.25.1