diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs index e25c083..e889451 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs @@ -39,7 +39,6 @@ labelCollectionName = new Label(); buttonCompanyCreate = new Button(); panelCompanyTools = new Panel(); - buttonAddDumpTruck = new Button(); buttonAddTruck = new Button(); buttonRemoveTruck = new Button(); buttonRefresh = new Button(); @@ -158,7 +157,6 @@ // // panelCompanyTools // - panelCompanyTools.Controls.Add(buttonAddDumpTruck); panelCompanyTools.Controls.Add(buttonAddTruck); panelCompanyTools.Controls.Add(buttonRemoveTruck); panelCompanyTools.Controls.Add(buttonRefresh); @@ -171,19 +169,9 @@ panelCompanyTools.Size = new Size(232, 300); panelCompanyTools.TabIndex = 10; // - // buttonAddDumpTruck - // - buttonAddDumpTruck.Location = new Point(3, 51); - buttonAddDumpTruck.Name = "buttonAddDumpTruck"; - buttonAddDumpTruck.Size = new Size(226, 48); - buttonAddDumpTruck.TabIndex = 2; - buttonAddDumpTruck.Text = "Добавление самосвала"; - buttonAddDumpTruck.UseVisualStyleBackColor = true; - buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click; - // // buttonAddTruck // - buttonAddTruck.Location = new Point(3, 3); + buttonAddTruck.Location = new Point(3, 35); buttonAddTruck.Name = "buttonAddTruck"; buttonAddTruck.Size = new Size(226, 42); buttonAddTruck.TabIndex = 0; @@ -271,7 +259,6 @@ #endregion private GroupBox groupBoxTools; - private Button buttonAddDumpTruck; private Button buttonGoToCheck; private Button buttonRemoveTruck; private MaskedTextBox maskedTextBoxPosition; diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs index ec67500..1e74ff6 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs @@ -50,31 +50,29 @@ public partial class FormTruckCollection : Form } /// - /// Создание объекта класса-перемещения + /// Добавление грузовика /// - /// Тип создаваемого объекта - private void CreateObject(string type) + /// + /// + private void ButtonAddTruck_Click(object sender, EventArgs e) { - if (_company == null) + FormTruckConfig form = new FormTruckConfig(); + form.Show(); + form.AddEvent(SetTruck); + } + + /// + /// Добавление грузовика в автомобиль + /// + /// + private void SetTruck(DrawningTruck truck) + { + if (_company == null || truck == null) { return; } - Random random = new(); - DrawningTruck drawningTruck; - switch (type) - { - case nameof(DrawningTruck): - drawningTruck = new DrawningTruck(random.Next(100, 300), - random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningDumpTruck): - drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - if (_company + drawningTruck != -1) + + if (_company + truck != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -84,35 +82,6 @@ public partial class FormTruckCollection : Form MessageBox.Show("Не удалось добавить объект"); } } - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - private static Color GetColor(Random random) - { - Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - color = dialog.Color; - } - return color; - } - - /// - /// Добавление грузовика - /// - /// - /// - private void ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck)); - - /// - /// Добавление самосвала - /// - /// - /// - private void ButtonAddDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck)); /// /// Удаление объекта diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.Designer.cs index 98d6bc5..b71b8b1 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.Designer.cs @@ -29,7 +29,6 @@ private void InitializeComponent() { groupBoxConfig = new GroupBox(); - panel1 = new Panel(); groupBoxColours = new GroupBox(); panelPurple = new Panel(); panelWhite = new Panel(); @@ -65,7 +64,6 @@ // // groupBoxConfig // - groupBoxConfig.Controls.Add(panel1); groupBoxConfig.Controls.Add(groupBoxColours); groupBoxConfig.Controls.Add(checkBoxTent); groupBoxConfig.Controls.Add(checkBoxAwning); @@ -83,13 +81,6 @@ groupBoxConfig.TabStop = false; groupBoxConfig.Text = "Параметры"; // - // panel1 - // - panel1.Location = new Point(621, 33); - panel1.Name = "panel1"; - panel1.Size = new Size(224, 125); - panel1.TabIndex = 4; - // // groupBoxColours // groupBoxColours.Controls.Add(panelPurple); @@ -281,9 +272,9 @@ // // pictureBoxObject // - pictureBoxObject.Location = new Point(3, 76); + pictureBoxObject.Location = new Point(3, 61); pictureBoxObject.Name = "pictureBoxObject"; - pictureBoxObject.Size = new Size(226, 114); + pictureBoxObject.Size = new Size(226, 143); pictureBoxObject.TabIndex = 1; pictureBoxObject.TabStop = false; // @@ -295,6 +286,7 @@ buttonAdd.TabIndex = 2; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // buttonCancel // @@ -321,28 +313,32 @@ // labelAdditionalColor // labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; - labelAdditionalColor.Location = new Point(122, 14); + labelAdditionalColor.Location = new Point(122, 9); labelAdditionalColor.Name = "labelAdditionalColor"; labelAdditionalColor.Size = new Size(102, 44); labelAdditionalColor.TabIndex = 3; labelAdditionalColor.Text = "Доп. цвет"; labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += LabelAdditionalColor_DragEnter; // // labelBaseColor // labelBaseColor.BorderStyle = BorderStyle.FixedSingle; - labelBaseColor.Location = new Point(6, 14); + labelBaseColor.Location = new Point(14, 9); labelBaseColor.Name = "labelBaseColor"; labelBaseColor.Size = new Size(102, 44); labelBaseColor.TabIndex = 2; labelBaseColor.Text = "Цвет"; labelBaseColor.TextAlign = ContentAlignment.MiddleCenter; + labelBaseColor.DragDrop += LabelBaseColor_DragDrop; + labelBaseColor.DragEnter += LabelBaseColor_DragEnter; // // FormTruckConfig // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(857, 266); + ClientSize = new Size(863, 266); Controls.Add(panelObject); Controls.Add(buttonCancel); Controls.Add(buttonAdd); @@ -384,7 +380,6 @@ private PictureBox pictureBoxObject; private Button buttonAdd; private Button buttonCancel; - private Panel panel1; private Panel panelObject; private Label labelBaseColor; private Label labelAdditionalColor; diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs index 745bf71..7eb92fe 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ProjectDumpTruck.Drawnings; +using ProjectDumpTruck.Entities; namespace ProjectDumpTruck; @@ -20,13 +21,19 @@ public partial class FormTruckConfig : Form /// /// Объект - прорисовка грузовика /// - private DrawningTruck _truck = null; + private DrawningTruck? _truck; + + /// + /// Событие для передачи объекта + /// + private event TruckDelegate? TruckDelegate; /// /// Конструктор /// public FormTruckConfig() { + InitializeComponent(); panelRed.MouseDown += Panel_MouseDown; @@ -39,6 +46,16 @@ public partial class FormTruckConfig : Form panelGray.MouseDown += Panel_MouseDown; panelBlack.MouseDown += Panel_MouseDown; panelWhite.MouseDown += Panel_MouseDown; + + + + buttonCancel.Click += (sender, e) => Close(); + + } + + public void AddEvent(TruckDelegate truckDelegate) + { + TruckDelegate += truckDelegate; } /// @@ -49,7 +66,7 @@ public partial class FormTruckConfig : Form Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); _truck?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); - _truck?.SetPosition(5, 5); + _truck?.SetPosition(30, 30); _truck?.DrawTransport(gr); pictureBoxObject.Image = bmp; } @@ -107,4 +124,61 @@ public partial class FormTruckConfig : Form { (sender as Control)?.DoDragDrop((sender as Control)?.BackColor!, DragDropEffects.Move | DragDropEffects.Copy); } + + /// + /// Передача объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_truck != null) + { + TruckDelegate?.Invoke(_truck); + Close(); + } + } + + private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck == null) return; + _truck.EntityTruck?.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck?.EntityTruck is EntityDumpTruck _dumpTruck) + { + _dumpTruck.SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + } + + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (_truck is DrawningDumpTruck) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs b/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs new file mode 100644 index 0000000..002ab38 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs @@ -0,0 +1,15 @@ +using ProjectDumpTruck.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck; + +/// +/// Делегат переадчи объекта класса-прорисовки +/// +/// +public delegate void TruckDelegate(DrawningTruck truck); + diff --git a/ProjectDumpTruck/Visual Studio 2022/Visualizers/attribcache140.bin b/ProjectDumpTruck/Visual Studio 2022/Visualizers/attribcache140.bin new file mode 100644 index 0000000..42108e4 Binary files /dev/null and b/ProjectDumpTruck/Visual Studio 2022/Visualizers/attribcache140.bin differ