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