diff --git a/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs b/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs index 5c38d7b..304626d 100644 --- a/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs @@ -60,5 +60,10 @@ namespace Project_DumpTruck.DrawningObjects } } } + + public void SetAdditionalColor(Color color) + { + (EntityTruck as EntityDumpTruck).SetAdditionalColor(color); + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs b/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs index 75a9eeb..5604c1f 100644 --- a/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs @@ -21,11 +21,11 @@ namespace Project_DumpTruck.DrawningObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// Левая координата прорисовки автомобиля /// @@ -224,5 +224,10 @@ namespace Project_DumpTruck.DrawningObjects g.DrawEllipse(penBlack, _startPosX + 22, _startPosY + 35, 20, 20); g.DrawEllipse(penBlack, _startPosX + 80, _startPosY + 35, 20, 20); } + + public void SetBodyColor(Color color) + { + EntityTruck.SetBodyColor(color); + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs b/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs index 0c223e8..4b482a4 100644 --- a/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs @@ -39,5 +39,10 @@ namespace Project_DumpTruck.Entities BodyKit = bodyKit; Tent = tent; } + + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs b/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs index 582ca5a..4499d5a 100644 --- a/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs @@ -40,5 +40,10 @@ namespace Project_DumpTruck.Entities Weight = weight; BodyColor = bodyColor; } + + public void SetBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs index fdd8e02..aa95623 100644 --- a/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -51,32 +52,39 @@ namespace Project_DumpTruck } } - - private void buttonAddTruck_Click(object sender, EventArgs e) + private void AddTruck(DrawningTruck truck) { + truck._pictureWidth = pictureBoxCollection.Width; + truck._pictureHeight = pictureBoxCollection.Height; + if (listBoxStorages.SelectedIndex == -1) { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) { return; } - FormDumpTruck form = new(); - if (form.ShowDialog() == DialogResult.OK) + + if (obj + truck != -1) { - if (obj + form.selectedTruck != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTrucks(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTrucks(); } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + private void buttonAddTruck_Click(object sender, EventArgs e) + { + var formTruckConfig = new FormTruckConfig(); + formTruckConfig.AddEvent(AddTruck); + formTruckConfig.Show(); } private void buttonRemoveTruck_Click(object sender, EventArgs e) diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs new file mode 100644 index 0000000..fa89313 --- /dev/null +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs @@ -0,0 +1,364 @@ +namespace Project_DumpTruck +{ + partial class FormTruckConfig + { + /// + /// 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(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + groupBox2 = new GroupBox(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxTent = new CheckBox(); + checkBoxBodyKit = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + panelObject = new Panel(); + pictureBoxObject = new PictureBox(); + labelAdditionalColor = new Label(); + labelColor = new Label(); + buttonOk = new Button(); + buttonCancel = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(labelModifiedObject); + groupBox1.Controls.Add(labelSimpleObject); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(checkBoxTent); + groupBox1.Controls.Add(checkBoxBodyKit); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(label1); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(444, 196); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(344, 156); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(94, 23); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(238, 156); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(100, 23); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBox2 + // + 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(238, 22); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(200, 127); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(137, 70); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(33, 32); + panelPurple.TabIndex = 1; + panelPurple.MouseDown += panelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(98, 70); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(33, 32); + panelBlack.TabIndex = 1; + panelBlack.MouseDown += panelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(59, 70); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(33, 32); + panelGray.TabIndex = 1; + panelGray.MouseDown += panelColor_MouseDown; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(20, 70); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(33, 32); + panelWhite.TabIndex = 1; + panelWhite.MouseDown += panelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(137, 32); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(33, 32); + panelYellow.TabIndex = 1; + panelYellow.MouseDown += panelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(98, 32); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(33, 32); + panelBlue.TabIndex = 1; + panelBlue.MouseDown += panelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(59, 32); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(33, 32); + panelGreen.TabIndex = 1; + panelGreen.MouseDown += panelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(20, 32); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(33, 32); + panelRed.TabIndex = 0; + panelRed.MouseDown += panelColor_MouseDown; + // + // checkBoxTent + // + checkBoxTent.AutoSize = true; + checkBoxTent.Location = new Point(15, 156); + checkBoxTent.Name = "checkBoxTent"; + checkBoxTent.Size = new Size(155, 19); + checkBoxTent.TabIndex = 5; + checkBoxTent.Text = "Признак наличия тента"; + checkBoxTent.UseVisualStyleBackColor = true; + // + // checkBoxBodyKit + // + checkBoxBodyKit.AutoSize = true; + checkBoxBodyKit.Location = new Point(15, 117); + checkBoxBodyKit.Name = "checkBoxBodyKit"; + checkBoxBodyKit.Size = new Size(162, 19); + checkBoxBodyKit.TabIndex = 4; + checkBoxBodyKit.Text = "Признак наличия кузова"; + checkBoxBodyKit.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(83, 77); + 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(120, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(83, 31); + 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(120, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(15, 79); + label2.Name = "label2"; + label2.Size = new Size(29, 15); + label2.TabIndex = 1; + label2.Text = "Вес:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 33); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 0; + label1.Text = "Скорость:"; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelColor); + panelObject.Location = new Point(462, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(214, 175); + panelObject.TabIndex = 2; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(13, 50); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(188, 122); + pictureBoxObject.TabIndex = 10; + pictureBoxObject.TabStop = false; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(107, 9); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(94, 38); + labelAdditionalColor.TabIndex = 9; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(13, 9); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(88, 38); + labelColor.TabIndex = 8; + labelColor.Text = "Цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += labelColor_DragDrop; + labelColor.DragEnter += labelColor_DragEnter; + // + // buttonOk + // + buttonOk.Location = new Point(475, 193); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(75, 23); + buttonOk.TabIndex = 3; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += buttonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(588, 193); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormTruckConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(690, 227); + Controls.Add(buttonCancel); + Controls.Add(buttonOk); + Controls.Add(panelObject); + Controls.Add(groupBox1); + Name = "FormTruckConfig"; + Text = "Создание объекта"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private GroupBox groupBox2; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private CheckBox checkBoxTent; + private CheckBox checkBoxBodyKit; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + private Label label1; + private Label labelModifiedObject; + private Label labelSimpleObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelColor; + private Button buttonOk; + private Button buttonCancel; + private PictureBox pictureBoxObject; + } +} \ No newline at end of file diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs new file mode 100644 index 0000000..bc48611 --- /dev/null +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs @@ -0,0 +1,172 @@ +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; +using Project_DumpTruck.DrawningObjects; + +namespace Project_DumpTruck +{ + public partial class FormTruckConfig : Form + { + /// + /// Переменная-выбранная машина + /// + DrawningTruck? _truck = null; + + /// + /// Событие + /// + private event Action EventAddTruck; + /// + /// Конструктор + /// + public FormTruckConfig() + { + 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 += (sender, e) => Close(); + } + + /// + /// Отрисовать машину + /// + private void DrawTruck() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _truck?.SetPosition(5, 5); + _truck?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddTruck == null) + { + EventAddTruck = ev; + } + else + { + EventAddTruck += ev; + } + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, 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 labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? 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": + _truck = new DrawningTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBodyKit.Checked, + checkBoxTent.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawTruck(); + } + + private void labelColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck == null) + return; + + ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); + switch (((Label)sender).Name) + { + case "labelColor": + _truck.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAdditionalColor": + if (!(_truck is DrawningDumpTruck)) + { + return; + } + (_truck as DrawningDumpTruck).SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawTruck(); + } + + /// + /// Добавление машины + /// + /// + /// + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddTruck?.Invoke(_truck); + Close(); + } + } +} diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.resx b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.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