From bab2bdbead44061dc70f652cfcfac77ada22a6b4 Mon Sep 17 00:00:00 2001 From: MariaBelkina <89656988623@mail.ru> Date: Tue, 21 May 2024 09:57:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=205=20=D0=B2=D1=81?= =?UTF-8?q?=D1=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListGenericObjects.cs | 2 +- .../StorageCollection.cs | 2 +- .../ProjectBulldozer/DozerDelegate.cs | 10 + .../Entities/EntityBulldozer.cs | 5 + .../ProjectBulldozer/Entities/EntityDozer.cs | 5 + .../FormBulldozer.Designer.cs | 4 +- .../FormBulldozerCollection.Designer.cs | 43 +- .../FormBulldozerCollection.cs | 57 ++- .../FormBulldozerConfig.Designer.cs | 367 ++++++++++++++++++ .../ProjectBulldozer/FormBulldozerConfig.cs | 207 ++++++++++ .../ProjectBulldozer/FormBulldozerConfig.resx | 120 ++++++ 11 files changed, 777 insertions(+), 45 deletions(-) create mode 100644 ProjectBulldozer/ProjectBulldozer/DozerDelegate.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.Designer.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.resx diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs index 3b24d65..09229fa 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs @@ -66,7 +66,7 @@ public class ListGenericObjects : ICollectoinGenericObjects } // Проверка позиции. - if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) //TODO проверить, что если заменить _Collection.Count на Count + if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) { return -1; } diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs index 6537f15..8e54847 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs @@ -19,7 +19,7 @@ public class StorageCollection readonly Dictionary> _storages; /// - /// Вщзвращение списка названий коллекций + /// Возвращение списка названий коллекций /// public List Keys => _storages.Keys.ToList(); diff --git a/ProjectBulldozer/ProjectBulldozer/DozerDelegate.cs b/ProjectBulldozer/ProjectBulldozer/DozerDelegate.cs new file mode 100644 index 0000000..9855853 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/DozerDelegate.cs @@ -0,0 +1,10 @@ +using ProjectBulldozer.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer; + +public delegate void DozerDelegate(DrawningDozer dozer); diff --git a/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs index cfce915..0145502 100644 --- a/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs +++ b/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs @@ -29,6 +29,11 @@ public class EntityBulldozer : EntityDozer /// public Color AdditionalColor { get; private set; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } + /// ///Инициализация полей объекта-класса бульдозера /// diff --git a/ProjectBulldozer/ProjectBulldozer/Entities/EntityDozer.cs b/ProjectBulldozer/ProjectBulldozer/Entities/EntityDozer.cs index d78fe16..c58f859 100644 --- a/ProjectBulldozer/ProjectBulldozer/Entities/EntityDozer.cs +++ b/ProjectBulldozer/ProjectBulldozer/Entities/EntityDozer.cs @@ -26,6 +26,11 @@ public class EntityDozer /// public Color BodyColor { get; private set; } + public void SetBodyColor(Color color) + { + BodyColor = color; + } + /// /// Шаг перемещения бульдозера /// diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs index 3ababcc..48b2b63 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs @@ -99,11 +99,13 @@ // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FlatStyle = FlatStyle.System; + comboBoxStrategy.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К левому нижнему краю", "К правому нижнему краю" }); comboBoxStrategy.Location = new Point(620, 12); comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(242, 40); + comboBoxStrategy.Size = new Size(242, 41); comboBoxStrategy.TabIndex = 7; // // buttonStrategyStep diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs index a3d7ad0..feb3d4a 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs @@ -31,7 +31,6 @@ groupBoxTools = new GroupBox(); panelCompanyTools = new Panel(); buttonAddDozer = new Button(); - buttonAddBulldozer = new Button(); buttonDelBulldozer = new Button(); maskedTextBox = new MaskedTextBox(); buttonGoToCheck = new Button(); @@ -63,7 +62,7 @@ groupBoxTools.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); groupBoxTools.Location = new Point(1290, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(358, 1051); + groupBoxTools.Size = new Size(358, 968); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -71,7 +70,6 @@ // panelCompanyTools // panelCompanyTools.Controls.Add(buttonAddDozer); - panelCompanyTools.Controls.Add(buttonAddBulldozer); panelCompanyTools.Controls.Add(buttonDelBulldozer); panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Controls.Add(buttonGoToCheck); @@ -79,12 +77,12 @@ panelCompanyTools.Enabled = false; panelCompanyTools.Location = new Point(3, 624); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(400, 449); + panelCompanyTools.Size = new Size(400, 345); panelCompanyTools.TabIndex = 7; // // buttonAddDozer // - buttonAddDozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonAddDozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); buttonAddDozer.Location = new Point(11, 14); buttonAddDozer.Name = "buttonAddDozer"; @@ -94,23 +92,11 @@ buttonAddDozer.UseVisualStyleBackColor = true; buttonAddDozer.Click += ButtonAddDozer_Click; // - // buttonAddBulldozer - // - buttonAddBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonAddBulldozer.Location = new Point(11, 84); - buttonAddBulldozer.Name = "buttonAddBulldozer"; - buttonAddBulldozer.Size = new Size(332, 79); - buttonAddBulldozer.TabIndex = 3; - buttonAddBulldozer.Text = "Добавление крутого бульдозера"; - buttonAddBulldozer.UseVisualStyleBackColor = true; - buttonAddBulldozer.Click += ButtonAddBulldozer_Click; - // // buttonDelBulldozer // - buttonDelBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonDelBulldozer.Location = new Point(11, 216); + buttonDelBulldozer.Location = new Point(11, 131); buttonDelBulldozer.Name = "buttonDelBulldozer"; buttonDelBulldozer.Size = new Size(332, 63); buttonDelBulldozer.TabIndex = 3; @@ -120,8 +106,8 @@ // // maskedTextBox // - maskedTextBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBox.Location = new Point(11, 169); + maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(11, 84); maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(332, 41); maskedTextBox.TabIndex = 5; @@ -129,9 +115,9 @@ // // buttonGoToCheck // - buttonGoToCheck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonGoToCheck.Location = new Point(11, 285); + buttonGoToCheck.Location = new Point(11, 200); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(332, 63); buttonGoToCheck.TabIndex = 3; @@ -141,9 +127,9 @@ // // buttonRefresh // - buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonRefresh.Location = new Point(11, 354); + buttonRefresh.Location = new Point(11, 269); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(332, 63); buttonRefresh.TabIndex = 3; @@ -245,7 +231,7 @@ // // comboBoxSelectorCompany // - comboBoxSelectorCompany.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); comboBoxSelectorCompany.FormattingEnabled = true; @@ -261,7 +247,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1290, 1051); + pictureBox.Size = new Size(1290, 968); pictureBox.TabIndex = 4; pictureBox.TabStop = false; // @@ -269,7 +255,7 @@ // AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1648, 1051); + ClientSize = new Size(1648, 968); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormBulldozerCollection"; @@ -288,7 +274,6 @@ private GroupBox groupBoxTools; private ComboBox comboBoxSelectorCompany; private Button buttonAddDozer; - private Button buttonAddBulldozer; private PictureBox pictureBox; private MaskedTextBox maskedTextBox; private Button buttonDelBulldozer; diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs index 0f24c1a..a747f11 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs @@ -47,22 +47,57 @@ public partial class FormBulldozerCollection : Form panelCompanyTools.Enabled = false; } + /* + /// + /// Добавление обычного бульдозера + /// + /// + /// + private void ButtonAddDozer_Click(object sender, EventArgs e) => + CreateObject(nameof(DrawningDozer)); + + /// + /// Добавление крутого бульдозера + /// + /// + /// + private void ButtonAddBulldozer_Click(object sender, EventArgs e) => + CreateObject(nameof(DrawningBulldozer));*/ /// - /// Добавление обычного бульдозера + /// Добавление бульдозера /// /// /// - private void ButtonAddDozer_Click(object sender, EventArgs e) => - CreateObject(nameof(DrawningDozer)); + private void ButtonAddDozer_Click(object sender, EventArgs e) + { + FormBulldozerConfig form = new(); + // Передача метода. + form.Show(); + form.AddEvent(SetDozer); + } /// - /// Добавление крутого бульдозера + /// Добавление бульдозера в коллекцию /// - /// - /// - private void ButtonAddBulldozer_Click(object sender, EventArgs e) => - CreateObject(nameof(DrawningBulldozer)); + /// + private void SetDozer(DrawningDozer? dozer) + { + if (_company == null || dozer == null) + { + return; + } + + if (_company + dozer != -1) + { + MessageBox.Show("Объект добавлен."); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект!"); + } + } /// /// Создание объекта класса-перемещения @@ -243,10 +278,6 @@ public partial class FormBulldozerCollection : Form RefreshListBoxItems(); } - /*private ListBox GetListBoxCollection() - { - return listBoxCollection; - }*/ /// /// Удаление коллекции @@ -255,7 +286,7 @@ public partial class FormBulldozerCollection : Form /// private void ButtonCollectionDel_Click(object sender, EventArgs e) { - // Прописать логику удаления элемента из коллекции. + // Логика удаления элемента из коллекции. // Нужно убедиться, что есть выбранная коллекция if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0) { diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.Designer.cs new file mode 100644 index 0000000..54a73ca --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.Designer.cs @@ -0,0 +1,367 @@ +namespace ProjectBulldozer +{ + partial class FormBulldozerConfig + { + /// + /// 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(); + panelBlack = new Panel(); + panelOrange = new Panel(); + panelSilver = new Panel(); + panelRed = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelCadetBlue = new Panel(); + panelGold = new Panel(); + checkBoxCaterpillar = new CheckBox(); + checkBoxBlade = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + labelWeight = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + pictureBoxObject = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + panelObject = new Panel(); + labelBodyColor = new Label(); + labelAdditionalColor = 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(checkBoxCaterpillar); + groupBoxConfig.Controls.Add(checkBoxBlade); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Dock = DockStyle.Left; + groupBoxConfig.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); + groupBoxConfig.Location = new Point(0, 0); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(851, 261); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelOrange); + groupBoxColors.Controls.Add(panelSilver); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelCadetBlue); + groupBoxColors.Controls.Add(panelGold); + groupBoxColors.Location = new Point(400, 26); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(429, 145); + groupBoxColors.TabIndex = 5; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelBlack + // + panelBlack.AllowDrop = true; + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(324, 89); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(100, 43); + panelBlack.TabIndex = 0; + // + // panelOrange + // + panelOrange.AllowDrop = true; + panelOrange.BackColor = Color.Orange; + panelOrange.Location = new Point(324, 40); + panelOrange.Name = "panelOrange"; + panelOrange.Size = new Size(100, 43); + panelOrange.TabIndex = 0; + // + // panelSilver + // + panelSilver.AllowDrop = true; + panelSilver.BackColor = Color.Silver; + panelSilver.Location = new Point(218, 89); + panelSilver.Name = "panelSilver"; + panelSilver.Size = new Size(100, 43); + panelSilver.TabIndex = 0; + // + // panelRed + // + panelRed.AllowDrop = true; + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(218, 40); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(100, 43); + panelRed.TabIndex = 0; + // + // panelWhite + // + panelWhite.AllowDrop = true; + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(112, 89); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(100, 43); + panelWhite.TabIndex = 0; + // + // panelYellow + // + panelYellow.AllowDrop = true; + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(112, 40); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(100, 43); + panelYellow.TabIndex = 0; + // + // panelCadetBlue + // + panelCadetBlue.AllowDrop = true; + panelCadetBlue.BackColor = Color.CadetBlue; + panelCadetBlue.Location = new Point(6, 89); + panelCadetBlue.Name = "panelCadetBlue"; + panelCadetBlue.Size = new Size(100, 43); + panelCadetBlue.TabIndex = 0; + // + // panelGold + // + panelGold.AllowDrop = true; + panelGold.BackColor = Color.Gold; + panelGold.Location = new Point(6, 40); + panelGold.Name = "panelGold"; + panelGold.Size = new Size(100, 43); + panelGold.TabIndex = 0; + panelGold.MouseDown += LabelObject_MouseDown; + // + // checkBoxCaterpillar + // + checkBoxCaterpillar.AutoSize = true; + checkBoxCaterpillar.Location = new Point(12, 192); + checkBoxCaterpillar.Name = "checkBoxCaterpillar"; + checkBoxCaterpillar.Size = new Size(366, 37); + checkBoxCaterpillar.TabIndex = 4; + checkBoxCaterpillar.Text = "Признак наличия гусеницы"; + checkBoxCaterpillar.UseVisualStyleBackColor = true; + // + // checkBoxBlade + // + checkBoxBlade.AutoSize = true; + checkBoxBlade.Location = new Point(12, 147); + checkBoxBlade.Name = "checkBoxBlade"; + checkBoxBlade.Size = new Size(332, 37); + checkBoxBlade.TabIndex = 4; + checkBoxBlade.Text = "Признак наличия отвала"; + checkBoxBlade.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(142, 87); + 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(178, 41); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(12, 89); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(62, 33); + labelWeight.TabIndex = 2; + labelWeight.Text = "Вес:"; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(142, 35); + 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(178, 41); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(12, 37); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(124, 33); + labelSpeed.TabIndex = 2; + labelSpeed.Text = "Скорость:"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(629, 180); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(200, 70); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(400, 180); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(200, 70); + labelSimpleObject.TabIndex = 0; + labelSimpleObject.Text = "Поростой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(12, 16); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(200, 150); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(869, 207); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(135, 46); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(1028, 207); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(135, 46); + buttonCancel.TabIndex = 2; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(859, 19); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(317, 181); + panelObject.TabIndex = 3; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(218, 16); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(93, 70); + labelBodyColor.TabIndex = 6; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += LabelBodyColor_DragDrop; + labelBodyColor.DragEnter += LabelBodyColor_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(218, 96); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(93, 70); + labelAdditionalColor.TabIndex = 6; + labelAdditionalColor.Text = "Цвет колёс"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += LabelAdditionalColor_DragEnter; + // + // FormBulldozerConfig + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1182, 261); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Name = "FormBulldozerConfig"; + Text = "Создание объекта"; + 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 labelModifiedObject; + private Label labelSimpleObject; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private CheckBox checkBoxBlade; + private CheckBox checkBoxCaterpillar; + private GroupBox groupBoxColors; + private Panel panelGold; + private Panel panelOrange; + private Panel panelRed; + private Panel panelYellow; + private Panel panelBlack; + private Panel panelSilver; + private Panel panelWhite; + private Panel panelCadetBlue; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + private Label labelBodyColor; + private Label labelAdditionalColor; + } +} \ No newline at end of file diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.cs new file mode 100644 index 0000000..ebb59c8 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.cs @@ -0,0 +1,207 @@ +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 ProjectBulldozer.Drawnings; +using ProjectBulldozer.Entities; + +namespace ProjectBulldozer; + +/// +/// Форма конигурации объекта +/// +public partial class FormBulldozerConfig : Form +{ + /// + /// Объект прорисовка бульдозера + /// + private DrawningDozer? _dozer /*= null*/; + + /// + /// Событие для передачи объекта + /// + public event Action? _dozerDelegate; + + //private event Action<> = + + /// + /// Конструктор + /// + public FormBulldozerConfig() + { + InitializeComponent(); + panelGold.MouseDown += Panel_MouseDown; + panelYellow.MouseDown += Panel_MouseDown; + panelRed.MouseDown += Panel_MouseDown; + panelOrange.MouseDown += Panel_MouseDown; + panelCadetBlue.MouseDown += Panel_MouseDown; + panelWhite.MouseDown += Panel_MouseDown; + panelSilver.MouseDown += Panel_MouseDown; + panelBlack.MouseDown += Panel_MouseDown; + + // buttonCancel.Click привязка анонимного метода через lambda с закрытием формы. + buttonCancel.Click += (sender, e) => Close(); + + + } + + /// + /// Привязка внешнего метода к событию + /// + /// + public void AddEvent(Action? dozerDelegate) + { + _dozerDelegate += dozerDelegate; + } + + /// + /// Прорисовка объекта + /// + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _dozer?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _dozer?.SetPosition(25, 30); + _dozer?.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": + _dozer = new DrawningDozer((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _dozer = new DrawningBulldozer((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, + Color.White, Color.Black, checkBoxBlade.Checked, checkBoxCaterpillar.Checked); + break; + } + DrawObject(); + } + + /// + /// Передаём информацию при нажатии на Panel + /// + /// + /// + private void Panel_MouseDown(object? sender, MouseEventArgs e) + { + // Отправка цвета в Drag&Drop + (sender as Control)?.DoDragDrop((sender as Control)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + + // Реализация логики смены цветов: основного и дополнительного (для смены объекта) + + /// + /// Передача основного цвет + /// + /// + /// + private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + /// + /// Закраска основным цветом + /// + /// + /// + private void LabelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_dozer == null) return; + _dozer.EntityDozer?.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + + /// + /// Передача дополнительного цвета + /// + /// + /// + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (_dozer is DrawningBulldozer) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } + + /// + /// Расскраска дополнительным цветом + /// + /// + /// + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_dozer == null) return; + if (_dozer?.EntityDozer is EntityBulldozer entityBulldozer) + { + entityBulldozer.SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + } + + /// + /// Передача объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_dozer != null) + { + _dozerDelegate?.Invoke(_dozer); + Close(); + } + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.resx b/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerConfig.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 -- 2.25.1