diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs index 70a8013..6e51100 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs @@ -9,11 +9,19 @@ public class EntityDumpTruck : EntityTruck /// Дополнительный цвет (для опциональных элементов) /// public Color AdditionalColor { get; private set; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } /// /// Дополнительный цвет (для опциональных элементов) /// public Color Additional2Color { get; private set; } + public void SetAdditional2Color(Color color) + { + Additional2Color = color; + } /// /// Признак (опция) наличия кузова @@ -36,7 +44,7 @@ public class EntityDumpTruck : EntityTruck /// Признак наличия кузова /// Признак наличия тента - public EntityDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(speed, weight, bodyColor) + public EntityDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(5, 45, bodyColor) { AdditionalColor = additionalColor; Additional2Color = additional2Color; diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs index f385560..8244313 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs @@ -19,6 +19,10 @@ public class EntityTruck /// Основной цвет /// public Color BodyColor { get; private set; } + public void SetBodyColor(Color color) + { + BodyColor = color; + } /// /// Шаг перемещения самосвала diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs index 4f7e18e..e7cdee3 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelCompanyTools = new Panel(); + buttonAddTruck = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonRemoveTruck = new Button(); + buttonGoToCheck = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -38,19 +44,12 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveTruck = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddDumpTruck = new Button(); - buttonAddTruck = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -67,6 +66,74 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Интсрументы"; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddTruck); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveTruck); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 381); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(173, 276); + panelCompanyTools.TabIndex = 8; + // + // buttonAddTruck + // + buttonAddTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTruck.Location = new Point(3, 3); + buttonAddTruck.Name = "buttonAddTruck"; + buttonAddTruck.Size = new Size(167, 42); + buttonAddTruck.TabIndex = 1; + buttonAddTruck.Text = "Добавить грузовик"; + buttonAddTruck.UseVisualStyleBackColor = true; + buttonAddTruck.Click += ButtonAddTruck_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBoxPosition.Location = new Point(3, 99); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(167, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(3, 224); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(167, 42); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonRemoveTruck + // + buttonRemoveTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTruck.Location = new Point(3, 128); + buttonRemoveTruck.Name = "buttonRemoveTruck"; + buttonRemoveTruck.Size = new Size(167, 42); + buttonRemoveTruck.TabIndex = 4; + buttonRemoveTruck.Text = "Удалить грузовик"; + buttonRemoveTruck.UseVisualStyleBackColor = true; + buttonRemoveTruck.Click += ButtonRemoveTruck_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(3, 176); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(167, 42); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Отправить на проверку"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // // buttonCreateCompany // buttonCreateCompany.Location = new Point(6, 307); @@ -159,71 +226,6 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции: "; // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(3, 224); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(167, 42); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(3, 176); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(167, 42); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Отправить на проверку"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveTruck - // - buttonRemoveTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveTruck.Location = new Point(3, 128); - buttonRemoveTruck.Name = "buttonRemoveTruck"; - buttonRemoveTruck.Size = new Size(167, 42); - buttonRemoveTruck.TabIndex = 4; - buttonRemoveTruck.Text = "Удалить грузовик"; - buttonRemoveTruck.UseVisualStyleBackColor = true; - buttonRemoveTruck.Click += ButtonRemoveTruck_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBoxPosition.Location = new Point(3, 99); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(167, 23); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddDumpTruck - // - buttonAddDumpTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddDumpTruck.Location = new Point(3, 51); - buttonAddDumpTruck.Name = "buttonAddDumpTruck"; - buttonAddDumpTruck.Size = new Size(167, 42); - buttonAddDumpTruck.TabIndex = 2; - buttonAddDumpTruck.Text = "Добавить самосвал"; - buttonAddDumpTruck.UseVisualStyleBackColor = true; - buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click; - // - // buttonAddTruck - // - buttonAddTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddTruck.Location = new Point(3, 3); - buttonAddTruck.Name = "buttonAddTruck"; - buttonAddTruck.Size = new Size(167, 42); - buttonAddTruck.TabIndex = 1; - buttonAddTruck.Text = "Добавить грузовик"; - buttonAddTruck.UseVisualStyleBackColor = true; - buttonAddTruck.Click += ButtonAddTruck_Click; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -245,21 +247,6 @@ pictureBox.TabIndex = 1; pictureBox.TabStop = false; // - // panelCompanyTools - // - panelCompanyTools.Controls.Add(buttonAddTruck); - panelCompanyTools.Controls.Add(buttonAddDumpTruck); - panelCompanyTools.Controls.Add(maskedTextBoxPosition); - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(buttonRemoveTruck); - panelCompanyTools.Controls.Add(buttonGoToCheck); - panelCompanyTools.Dock = DockStyle.Bottom; - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 381); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(173, 276); - panelCompanyTools.TabIndex = 8; - // // FormTruckCollection // AutoScaleDimensions = new SizeF(7F, 15F); @@ -270,11 +257,11 @@ Name = "FormTruckCollection"; Text = "FormTruckCollection"; groupBoxTools.ResumeLayout(false); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTools.ResumeLayout(false); - panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -284,7 +271,6 @@ private Button buttonAddTruck; private ComboBox comboBoxSelectorCompany; private MaskedTextBox maskedTextBoxPosition; - private Button buttonAddDumpTruck; private PictureBox pictureBox; private Button buttonRefresh; private Button buttonGoToCheck; diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs index e7b228b..6c225ec 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs @@ -38,33 +38,35 @@ public partial class FormTruckCollection : Form panelCompanyTools.Enabled = false; } + /// - /// Создание объекта класса-перемещения + /// Добавление грузовика /// - /// Тип создаваемого объекта - private void CreateObject(string type) + /// + /// + private void ButtonAddTruck_Click(object sender, EventArgs e) { if (_company == null) { return; } + FormTruckConfig form = new(); + form.TruckDelegate += SetTruck; + form.Show(); + } - Random random = new(); - DrawningTruck drawningTruck; - switch (type) + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void SetTruck(DrawningTruck truck) + { + + if (_company == null || truck == null) { - case nameof(DrawningTruck): - drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningDumpTruck): - // TODO Выбор цвета - drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), GetColor(random), - Convert.ToBoolean(random.Next(2, 2)), Convert.ToBoolean(random.Next(1, 2))); - break; - default: - return; + return; } - if (_company + drawningTruck != -1) + if (_company + truck != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -75,36 +77,7 @@ public partial class FormTruckCollection : Form } } - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - 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 new file mode 100644 index 0000000..5278ae7 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.Designer.cs @@ -0,0 +1,358 @@ +namespace ProjectDumpTruck +{ + 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() + { + groupBoxConfig = new GroupBox(); + groupBoxColors = 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(); + checkBoxAwning = new CheckBox(); + checkBoxBodywork = new CheckBox(); + labelModifiedObject = new Label(); + numericUpDownWeight = new NumericUpDown(); + labelSimpleObject = new Label(); + labelWeight = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + pictureBoxObject = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelBodyColor = new Label(); + groupBoxConfig.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(checkBoxAwning); + groupBoxConfig.Controls.Add(checkBoxBodywork); + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Dock = DockStyle.Left; + groupBoxConfig.Location = new Point(0, 0); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(552, 344); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(238, 53); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(284, 146); + groupBoxColors.TabIndex = 6; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(214, 95); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(45, 45); + panelPurple.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(142, 95); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(45, 45); + panelBlack.TabIndex = 1; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(87, 95); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(45, 45); + panelGray.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(16, 95); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(45, 45); + panelWhite.TabIndex = 1; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(214, 34); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(45, 45); + panelYellow.TabIndex = 1; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(142, 34); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(45, 45); + panelBlue.TabIndex = 1; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(87, 34); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(45, 45); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(16, 34); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(45, 45); + panelRed.TabIndex = 0; + panelRed.MouseDown += Panel_MouseDown; + // + // checkBoxAwning + // + checkBoxAwning.AutoSize = true; + checkBoxAwning.Location = new Point(21, 180); + checkBoxAwning.Name = "checkBoxAwning"; + checkBoxAwning.Size = new Size(155, 19); + checkBoxAwning.TabIndex = 5; + checkBoxAwning.Text = "Признак наличия тента"; + checkBoxAwning.UseVisualStyleBackColor = true; + // + // checkBoxBodywork + // + checkBoxBodywork.AutoSize = true; + checkBoxBodywork.Location = new Point(20, 146); + checkBoxBodywork.Name = "checkBoxBodywork"; + checkBoxBodywork.Size = new Size(162, 19); + checkBoxBodywork.TabIndex = 4; + checkBoxBodywork.Text = "Признак наличия кузова"; + checkBoxBodywork.UseVisualStyleBackColor = true; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(325, 286); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(100, 23); + labelModifiedObject.TabIndex = 2; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(94, 109); + 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 }); + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(219, 286); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(100, 23); + labelSimpleObject.TabIndex = 1; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(20, 111); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(35, 15); + labelWeight.TabIndex = 2; + labelWeight.Text = "Вес : "; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(94, 74); + 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 = 1; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(20, 76); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(68, 15); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость : "; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(15, 46); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(195, 175); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(573, 256); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(693, 261); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(558, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(230, 238); + panelObject.TabIndex = 4; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(121, 10); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(100, 23); + labelAdditionalColor.TabIndex = 7; + labelAdditionalColor.Text = "Доп цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += LabelAdditionalColor_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(15, 10); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(100, 23); + labelBodyColor.TabIndex = 7; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += LabelBodyColor_DragDrop; + labelBodyColor.DragEnter += LabelBodyColor_DragEnter; + // + // FormTruckConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 344); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Name = "FormTruckConfig"; + Text = "FormTruckConfig"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelSimpleObject; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private Label labelModifiedObject; + private CheckBox checkBoxBodywork; + private NumericUpDown numericUpDownWeight; + private CheckBox checkBoxAwning; + 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 PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelBodyColor; + } +} \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs new file mode 100644 index 0000000..37df59d --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.cs @@ -0,0 +1,169 @@ +using ProjectDumpTruck.Drawnings; +using ProjectDumpTruck.Entities; + + +namespace ProjectDumpTruck; +/// +/// Форма конфигурации объекта +/// +public partial class FormTruckConfig : Form +{ + + + /// + /// Объект - прорисовка + /// + private DrawningTruck? _truck; + + /// + /// Констурктор + /// + public FormTruckConfig() + { + InitializeComponent(); + panelRed.MouseDown += Panel_MouseDown; + panelGreen.MouseDown += Panel_MouseDown; + panelBlue.MouseDown += Panel_MouseDown; + panelYellow.MouseDown += Panel_MouseDown; + panelWhite.MouseDown += Panel_MouseDown; + panelGray.MouseDown += Panel_MouseDown; + panelBlack.MouseDown += Panel_MouseDown; + panelPurple.MouseDown += Panel_MouseDown; + + buttonCancel.Click += (sender, e) => Close(); + } + + /// + /// Событие для передачи объекта + /// + public event Action? TruckDelegate; + + // + /// Привязка внешнего метода к событию + /// + /// + public void AddEvent(Action truckDelegate) + { + TruckDelegate += truckDelegate; + } + + /// + /// Прорисовка объекта + /// + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _truck?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _truck?.SetPosition(15, 15); + _truck?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : 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, (double)numericUpDownWeight.Value, Color.Aqua); + break; + case "labelModifiedObject": + _truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, + Color.Black, Color.Red, checkBoxBodywork.Checked, checkBoxAwning.Checked); + break; + } + + DrawObject(); + } + + /// + /// Передаем информацию при нажатии на Panel + /// + /// + /// + private void Panel_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Передача объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_truck != null) + { + TruckDelegate?.Invoke(_truck); + Close(); + } + } + + private void LabelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck == null) + { + return; + } + Color color = (Color)e.Data.GetData(typeof(Color)); + + if (_truck is DrawningTruck) + { + _truck?.EntityTruck?.SetBodyColor(color); + } + DrawObject(); + } + + private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; + } + + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck == null) + { + return; + } + Color color = (Color)e.Data.GetData(typeof(Color)); + + if (_truck is DrawningDumpTruck) + { + var dumpTruck = _truck.EntityTruck as EntityDumpTruck; + dumpTruck.SetAdditionalColor(color); + } + DrawObject(); + } + + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; + } +} + diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTruckConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/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 diff --git a/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs b/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs new file mode 100644 index 0000000..3205bdb --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/TruckDelegate.cs @@ -0,0 +1,9 @@ +using ProjectDumpTruck.Drawnings; + + +namespace ProjectDumpTruck; +/// +/// Делегат передачи объекта класса-прорисовки +/// +/// +public delegate void TruckDelegate(DrawningTruck truck); \ No newline at end of file