From 0d223f8de88bb48e80d1443b9ce66af5460e363a Mon Sep 17 00:00:00 2001 From: russell Date: Fri, 24 Nov 2023 20:27:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=205?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DumpTruck/DrawingObjects/DrawingTruck.cs | 6 +- DumpTruck/Entities/EntityDumpTruck.cs | 4 +- DumpTruck/Entities/EntityTruck.cs | 2 +- DumpTruck/FormTruckCollection.cs | 43 ++- DumpTruck/FormTruckConfig.Designer.cs | 405 +++++++++++++++++++++++ DumpTruck/FormTruckConfig.cs | 177 ++++++++++ DumpTruck/FormTruckConfig.resx | 60 ++++ 7 files changed, 674 insertions(+), 23 deletions(-) create mode 100644 DumpTruck/FormTruckConfig.Designer.cs create mode 100644 DumpTruck/FormTruckConfig.cs create mode 100644 DumpTruck/FormTruckConfig.resx diff --git a/DumpTruck/DrawingObjects/DrawingTruck.cs b/DumpTruck/DrawingObjects/DrawingTruck.cs index f419bce..573da7d 100644 --- a/DumpTruck/DrawingObjects/DrawingTruck.cs +++ b/DumpTruck/DrawingObjects/DrawingTruck.cs @@ -17,11 +17,11 @@ namespace DumpTruck.DrawingObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// Левая координата прорисовки грузовика /// @@ -56,7 +56,7 @@ namespace DumpTruck.DrawingObjects /// public int GetHeight => _truckHeight; /// - /// Получение объекта IMoveableObject из объекта DrawingTruck + /// Получение объекта IMoveableObject из объекта DrawningCar /// public IMoveableObject GetMoveableObject => new DrawningObjectTruck(this); diff --git a/DumpTruck/Entities/EntityDumpTruck.cs b/DumpTruck/Entities/EntityDumpTruck.cs index 514226c..31ef175 100644 --- a/DumpTruck/Entities/EntityDumpTruck.cs +++ b/DumpTruck/Entities/EntityDumpTruck.cs @@ -19,11 +19,11 @@ namespace DumpTruck.Entities /// /// Цвет кузова /// - public Color DumpBoxColor { get; private set; } + public Color DumpBoxColor { get; set; } /// /// Цвет тента /// - public Color TentColor { get; private set; } + public Color TentColor { get; set; } /// /// Конструктор /// diff --git a/DumpTruck/Entities/EntityTruck.cs b/DumpTruck/Entities/EntityTruck.cs index 488d044..ca74da0 100644 --- a/DumpTruck/Entities/EntityTruck.cs +++ b/DumpTruck/Entities/EntityTruck.cs @@ -19,7 +19,7 @@ namespace DumpTruck.Entities /// /// Основной цвет /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг /// diff --git a/DumpTruck/FormTruckCollection.cs b/DumpTruck/FormTruckCollection.cs index 01d7c55..502c319 100644 --- a/DumpTruck/FormTruckCollection.cs +++ b/DumpTruck/FormTruckCollection.cs @@ -94,8 +94,10 @@ namespace DumpTruck } } - private void buttonAddTruck_Click(object sender, EventArgs e) - { + private void AddTruck(DrawingTruck truck) + { + truck._pictureWidth = pictureBoxCollection.Width; + truck._pictureHeight = pictureBoxCollection.Height; if (listBoxStorages.SelectedIndex == -1) { return; @@ -105,22 +107,29 @@ namespace DumpTruck { return; } - FormDumpTruck form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedTruck != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTrucks(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - } + if (obj + truck != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTrucks(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } - private void buttonRemoveTruck_Click(object sender, EventArgs e) + private void buttonAddTruck_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var formTruckConfig = new FormTruckConfig(); + formTruckConfig.AddEvent(AddTruck); + formTruckConfig.Show(); + } + + private void buttonRemoveTruck_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) { diff --git a/DumpTruck/FormTruckConfig.Designer.cs b/DumpTruck/FormTruckConfig.Designer.cs new file mode 100644 index 0000000..959c1c1 --- /dev/null +++ b/DumpTruck/FormTruckConfig.Designer.cs @@ -0,0 +1,405 @@ +namespace 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() + { + this.groupBoxParameters = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxTent = new System.Windows.Forms.CheckBox(); + this.checkBoxDumpBox = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.PanelObject = new System.Windows.Forms.Panel(); + this.labelTentColor = new System.Windows.Forms.Label(); + this.labelDumpBoxColor = new System.Windows.Forms.Label(); + this.labelBaseColor = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxParameters.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.PanelObject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxParameters + // + this.groupBoxParameters.Controls.Add(this.labelModifiedObject); + this.groupBoxParameters.Controls.Add(this.labelSimpleObject); + this.groupBoxParameters.Controls.Add(this.groupBoxColors); + this.groupBoxParameters.Controls.Add(this.checkBoxTent); + this.groupBoxParameters.Controls.Add(this.checkBoxDumpBox); + this.groupBoxParameters.Controls.Add(this.numericUpDownWeight); + this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed); + this.groupBoxParameters.Controls.Add(this.labelWeight); + this.groupBoxParameters.Controls.Add(this.labelSpeed); + this.groupBoxParameters.Location = new System.Drawing.Point(12, 12); + this.groupBoxParameters.Name = "groupBoxParameters"; + this.groupBoxParameters.Size = new System.Drawing.Size(463, 246); + this.groupBoxParameters.TabIndex = 0; + this.groupBoxParameters.TabStop = false; + this.groupBoxParameters.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(335, 158); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(100, 23); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(229, 158); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(100, 23); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(229, 38); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(206, 100); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(136, 55); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(30, 30); + this.panelPurple.TabIndex = 2; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(100, 55); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(30, 30); + this.panelBlack.TabIndex = 2; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(64, 55); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(30, 30); + this.panelGray.TabIndex = 2; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(28, 55); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(30, 30); + this.panelWhite.TabIndex = 2; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(136, 19); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(30, 30); + this.panelYellow.TabIndex = 2; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(100, 19); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(30, 30); + this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(64, 19); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(30, 30); + this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(28, 19); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(30, 30); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxTent + // + this.checkBoxTent.AutoSize = true; + this.checkBoxTent.Location = new System.Drawing.Point(23, 158); + this.checkBoxTent.Name = "checkBoxTent"; + this.checkBoxTent.Size = new System.Drawing.Size(155, 19); + this.checkBoxTent.TabIndex = 5; + this.checkBoxTent.Text = "Признак наличия тента"; + this.checkBoxTent.UseVisualStyleBackColor = true; + // + // checkBoxDumpBox + // + this.checkBoxDumpBox.AutoSize = true; + this.checkBoxDumpBox.Location = new System.Drawing.Point(23, 119); + this.checkBoxDumpBox.Name = "checkBoxDumpBox"; + this.checkBoxDumpBox.Size = new System.Drawing.Size(162, 19); + this.checkBoxDumpBox.TabIndex = 4; + this.checkBoxDumpBox.Text = "Признак наличия кузова"; + this.checkBoxDumpBox.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(71, 62); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(82, 23); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(71, 19); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(82, 23); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(6, 64); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(26, 15); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(6, 19); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(59, 15); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость"; + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(46, 56); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(226, 131); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // PanelObject + // + this.PanelObject.AllowDrop = true; + this.PanelObject.Controls.Add(this.labelTentColor); + this.PanelObject.Controls.Add(this.labelDumpBoxColor); + this.PanelObject.Controls.Add(this.labelBaseColor); + this.PanelObject.Controls.Add(this.pictureBoxObject); + this.PanelObject.Location = new System.Drawing.Point(481, 12); + this.PanelObject.Name = "PanelObject"; + this.PanelObject.Size = new System.Drawing.Size(307, 196); + this.PanelObject.TabIndex = 2; + this.PanelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.PanelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // labelTentColor + // + this.labelTentColor.AllowDrop = true; + this.labelTentColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelTentColor.Location = new System.Drawing.Point(202, 13); + this.labelTentColor.Name = "labelTentColor"; + this.labelTentColor.Size = new System.Drawing.Size(70, 40); + this.labelTentColor.TabIndex = 4; + this.labelTentColor.Text = "Цвет тента"; + this.labelTentColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelTentColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelTentColor_DragDrop); + this.labelTentColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // labelDumpBoxColor + // + this.labelDumpBoxColor.AllowDrop = true; + this.labelDumpBoxColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelDumpBoxColor.Location = new System.Drawing.Point(124, 13); + this.labelDumpBoxColor.Name = "labelDumpBoxColor"; + this.labelDumpBoxColor.Size = new System.Drawing.Size(70, 40); + this.labelDumpBoxColor.TabIndex = 3; + this.labelDumpBoxColor.Text = "Цвет кузова"; + this.labelDumpBoxColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelDumpBoxColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDumpBoxColor_DragDrop); + this.labelDumpBoxColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(46, 13); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(70, 40); + this.labelBaseColor.TabIndex = 2; + this.labelBaseColor.Text = "Основной цвет"; + this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(527, 221); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(100, 30); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(653, 221); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(100, 30); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormTruckConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 271); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.PanelObject); + this.Controls.Add(this.groupBoxParameters); + this.Name = "FormTruckConfig"; + this.Text = "Создание объекта"; + this.groupBoxParameters.ResumeLayout(false); + this.groupBoxParameters.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.PanelObject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxParameters; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + 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 checkBoxDumpBox; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private PictureBox pictureBoxObject; + private Panel PanelObject; + private Label labelDumpBoxColor; + private Label labelBaseColor; + private Button buttonAdd; + private Button buttonCancel; + private Label labelTentColor; + } +} \ No newline at end of file diff --git a/DumpTruck/FormTruckConfig.cs b/DumpTruck/FormTruckConfig.cs new file mode 100644 index 0000000..6498da9 --- /dev/null +++ b/DumpTruck/FormTruckConfig.cs @@ -0,0 +1,177 @@ +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 DumpTruck.DrawingObjects; +using DumpTruck.Entities; + +namespace DumpTruck +{ + public partial class FormTruckConfig : Form + { + /// + /// Переменная-выбранный грузовик + /// + DrawingTruck? _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 += (object sender, EventArgs 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 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": + _truck = new DrawingTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _truck = new DrawingDumpTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, checkBoxTent.Checked, + checkBoxDumpBox.Checked, Color.Black, Color.Gray, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawTruck(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + 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 labelBaseColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck != null) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + _truck.EntityTruck.BodyColor = (Color)e.Data.GetData(typeof(Color)); + } + DrawTruck(); + } + } + private void labelDumpBoxColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck != null && _truck.EntityTruck is EntityDumpTruck entityDumpTruck) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + entityDumpTruck.DumpBoxColor = (Color)e.Data.GetData(typeof(Color)); + } + DrawTruck(); + } + } + private void labelTentColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck != null && _truck.EntityTruck is EntityDumpTruck entityDumpTruck) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + entityDumpTruck.TentColor = (Color)e.Data.GetData(typeof(Color)); + } + DrawTruck(); + } + } + + /// + /// Добавление грузовика + /// + /// + /// + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddTruck?.Invoke(_truck); + Close(); + } + } +} diff --git a/DumpTruck/FormTruckConfig.resx b/DumpTruck/FormTruckConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/DumpTruck/FormTruckConfig.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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