From 471df50dbc03d2eed00a1da0bc629c62e9aa11d0 Mon Sep 17 00:00:00 2001 From: Anatoliy Date: Fri, 29 Dec 2023 23:06:40 +0400 Subject: [PATCH] PIbd22_Kuznetsov.A.V_lab5 --- Excavator/Drawing/DrawingExcavator.cs | 8 +- Excavator/Drawing/DrawingMash.cs | 11 +- Excavator/Entities/EntityExcavator.cs | 5 + Excavator/Entities/EntityMash.cs | 4 + Excavator/FormExcavatorCollection.Designer.cs | 85 ++-- Excavator/FormExcavatorCollection.cs | 41 +- Excavator/FormMashConfig.Designer.cs | 375 ++++++++++++++++++ Excavator/FormMashConfig.cs | 137 +++++++ Excavator/FormMashConfig.resx | 60 +++ Excavator/Generic/MashGenericCollection.cs | 16 +- Excavator/Generic/MashsGenericStorage.cs | 6 +- Excavator/Generic/SetGeneric.cs | 7 +- Excavator/Move_Strategy/DrawingObjectMash.cs | 35 ++ Excavator/Move_Strategy/MoveToBorder.cs | 1 + Excavator/Move_Strategy/Status.cs | 2 +- Excavator/Program.cs | 5 + 16 files changed, 715 insertions(+), 83 deletions(-) create mode 100644 Excavator/FormMashConfig.Designer.cs create mode 100644 Excavator/FormMashConfig.cs create mode 100644 Excavator/FormMashConfig.resx create mode 100644 Excavator/Move_Strategy/DrawingObjectMash.cs diff --git a/Excavator/Drawing/DrawingExcavator.cs b/Excavator/Drawing/DrawingExcavator.cs index a20ef6f..433e91e 100644 --- a/Excavator/Drawing/DrawingExcavator.cs +++ b/Excavator/Drawing/DrawingExcavator.cs @@ -23,9 +23,9 @@ namespace Excavator.Drawing { return; } - Pen pen = new(Color.Black); - Pen additionalPen = new(Excavator.AddColor); - Brush additionalBrush = new SolidBrush(Excavator.AddColor); + Pen pen = new(Color.Black); + Pen additionalPen = new(Excavator.Body); + Brush additionalBrush = new SolidBrush(Excavator.Body); base.DrawTransport(g); if (Excavator.Bucket) @@ -34,7 +34,7 @@ namespace Excavator.Drawing SolidBrush(EntityMash.BodyColor); g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 42, 20, 5); - g.FillRectangle(additionalBrush, _startPosX+ 5, _startPosY + 37, 10, 50); + g.FillRectangle(additionalBrush, _startPosX + 5, _startPosY + 37, 10, 50); } if (Excavator.Supports) diff --git a/Excavator/Drawing/DrawingMash.cs b/Excavator/Drawing/DrawingMash.cs index ab9b7bc..459d44b 100644 --- a/Excavator/Drawing/DrawingMash.cs +++ b/Excavator/Drawing/DrawingMash.cs @@ -11,14 +11,14 @@ namespace Excavator.Drawing { public class DrawingMash { - public IMoveableObject GetMoveableObject => new DrawingObjectmash(this); + public IMoveableObject GetMoveableObject => new DrawingObjectmash(this); public EntityMash? EntityMash { get; protected set; } public int _pictureWidth; public int _pictureHeight; protected int _startPosX; protected int _startPosY; - protected readonly int _mashWidth = 175; - protected readonly int _mashHeight = 115; + protected readonly int _mashWidth = 175; + protected readonly int _mashHeight = 115; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _mashWidth; @@ -136,5 +136,10 @@ namespace Excavator.Drawing _ => false, }; } + public void ChangeBordersPicture(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + } } } \ No newline at end of file diff --git a/Excavator/Entities/EntityExcavator.cs b/Excavator/Entities/EntityExcavator.cs index ec2f63e..955ff61 100644 --- a/Excavator/Entities/EntityExcavator.cs +++ b/Excavator/Entities/EntityExcavator.cs @@ -9,6 +9,7 @@ namespace Excavator.Entities { public class EntityExcavator : EntityMash { + public Color Body { get; private set; } public Color AddColor { get; private set; } public bool Bucket { get; private set; } public bool Supports { get; private set; } @@ -18,5 +19,9 @@ namespace Excavator.Entities Bucket = bucket; Supports = supports; } + public void ChangeAdditionalColor(Color additionalColor) + { + Body = additionalColor; + } } } \ No newline at end of file diff --git a/Excavator/Entities/EntityMash.cs b/Excavator/Entities/EntityMash.cs index ff750f1..c3b0de6 100644 --- a/Excavator/Entities/EntityMash.cs +++ b/Excavator/Entities/EntityMash.cs @@ -18,5 +18,9 @@ namespace Excavator.Entities Weight = weight; BodyColor = bodyColor; } + public void ChangeBodyColor(Color color) + { + BodyColor = color; + } } } \ No newline at end of file diff --git a/Excavator/FormExcavatorCollection.Designer.cs b/Excavator/FormExcavatorCollection.Designer.cs index 73627b9..d018c15 100644 --- a/Excavator/FormExcavatorCollection.Designer.cs +++ b/Excavator/FormExcavatorCollection.Designer.cs @@ -2,7 +2,15 @@ { partial class FormExcavatorCollection { + /// + /// 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)) @@ -20,11 +28,11 @@ /// private void InitializeComponent() { - this.buttonAddmash = new System.Windows.Forms.Button(); + this.buttonAddMash = new System.Windows.Forms.Button(); this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); this.labelInstruments = new System.Windows.Forms.Label(); this.buttonUpdate = new System.Windows.Forms.Button(); - this.buttonDeletemash = new System.Windows.Forms.Button(); + this.buttonDeleteMash = new System.Windows.Forms.Button(); this.colorDialog = new System.Windows.Forms.ColorDialog(); this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); this.label1 = new System.Windows.Forms.Label(); @@ -35,33 +43,32 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); this.SuspendLayout(); // - // buttonAddmash + // buttonAddMash // - this.buttonAddmash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAddmash.Location = new System.Drawing.Point(761, 441); - this.buttonAddmash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.buttonAddmash.Name = "buttonAddmash"; - this.buttonAddmash.Size = new System.Drawing.Size(135, 37); - this.buttonAddmash.TabIndex = 0; - this.buttonAddmash.Text = "Добавить автобус"; - this.buttonAddmash.UseVisualStyleBackColor = true; - this.buttonAddmash.Click += new System.EventHandler(this.buttonAddmash_Click); + this.buttonAddMash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAddMash.Location = new System.Drawing.Point(982, 441); + this.buttonAddMash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddMash.Name = "buttonAddMash"; + this.buttonAddMash.Size = new System.Drawing.Size(135, 37); + this.buttonAddMash.TabIndex = 0; + this.buttonAddMash.Text = "Добавить автобус"; + this.buttonAddMash.UseVisualStyleBackColor = true; + this.buttonAddMash.Click += new System.EventHandler(this.buttonAddMash_Click); // // pictureBoxCollection // this.pictureBoxCollection.Location = new System.Drawing.Point(3, 0); this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(730, 581); + this.pictureBoxCollection.Size = new System.Drawing.Size(949, 633); this.pictureBoxCollection.TabIndex = 1; - this.pictureBoxCollection.TabStop = false; - // + this.pictureBoxCollection.TabStop = false; // // labelInstruments // this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.labelInstruments.AutoSize = true; this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelInstruments.Location = new System.Drawing.Point(761, 0); + this.labelInstruments.Location = new System.Drawing.Point(982, 0); this.labelInstruments.Name = "labelInstruments"; this.labelInstruments.Size = new System.Drawing.Size(136, 28); this.labelInstruments.TabIndex = 2; @@ -70,31 +77,29 @@ // buttonUpdate // this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUpdate.Location = new System.Drawing.Point(752, 173); + this.buttonUpdate.Location = new System.Drawing.Point(973, 173); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(150, 33); this.buttonUpdate.TabIndex = 3; this.buttonUpdate.Text = "Обновить набор"; this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // - // buttonDeletemash + // buttonDeleteMash // - this.buttonDeletemash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDeletemash.Location = new System.Drawing.Point(761, 525); - this.buttonDeletemash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.buttonDeletemash.Name = "buttonDeletemash"; - this.buttonDeletemash.Size = new System.Drawing.Size(135, 37); - this.buttonDeletemash.TabIndex = 4; - this.buttonDeletemash.Text = "Удалить объект"; - this.buttonDeletemash.UseVisualStyleBackColor = true; - this.buttonDeletemash.Click += new System.EventHandler(this.buttonDeletemash_Click); + this.buttonDeleteMash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDeleteMash.Location = new System.Drawing.Point(982, 525); + this.buttonDeleteMash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDeleteMash.Name = "buttonDeleteMash"; + this.buttonDeleteMash.Size = new System.Drawing.Size(135, 37); + this.buttonDeleteMash.TabIndex = 4; + this.buttonDeleteMash.Text = "Удалить "; + this.buttonDeleteMash.UseVisualStyleBackColor = true; // // maskedTextBoxNumber // this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.maskedTextBoxNumber.Location = new System.Drawing.Point(752, 487); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(973, 487); this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxNumber.Mask = "00"; this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; @@ -106,7 +111,7 @@ // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(752, 51); + this.label1.Location = new System.Drawing.Point(973, 51); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(66, 20); this.label1.TabIndex = 7; @@ -116,15 +121,14 @@ // this.listBoxStorages.FormattingEnabled = true; this.listBoxStorages.ItemHeight = 20; - this.listBoxStorages.Location = new System.Drawing.Point(751, 212); + this.listBoxStorages.Location = new System.Drawing.Point(971, 213); this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Size = new System.Drawing.Size(150, 144); this.listBoxStorages.TabIndex = 8; - this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged); // // buttonAddStorage // - this.buttonAddStorage.Location = new System.Drawing.Point(751, 135); + this.buttonAddStorage.Location = new System.Drawing.Point(971, 136); this.buttonAddStorage.Name = "buttonAddStorage"; this.buttonAddStorage.Size = new System.Drawing.Size(150, 33); this.buttonAddStorage.TabIndex = 9; @@ -134,17 +138,16 @@ // // buttonDeleteStorage // - this.buttonDeleteStorage.Location = new System.Drawing.Point(751, 363); + this.buttonDeleteStorage.Location = new System.Drawing.Point(971, 364); this.buttonDeleteStorage.Name = "buttonDeleteStorage"; this.buttonDeleteStorage.Size = new System.Drawing.Size(150, 33); this.buttonDeleteStorage.TabIndex = 10; this.buttonDeleteStorage.Text = "Удалить набор"; this.buttonDeleteStorage.UseVisualStyleBackColor = true; - this.buttonDeleteStorage.Click += new System.EventHandler(this.buttonDeleteStorage_Click); // // textBoxStorageName // - this.textBoxStorageName.Location = new System.Drawing.Point(751, 101); + this.textBoxStorageName.Location = new System.Drawing.Point(971, 103); this.textBoxStorageName.Name = "textBoxStorageName"; this.textBoxStorageName.Size = new System.Drawing.Size(150, 27); this.textBoxStorageName.TabIndex = 11; @@ -153,15 +156,15 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(926, 591); + this.ClientSize = new System.Drawing.Size(1146, 640); this.Controls.Add(this.textBoxStorageName); this.Controls.Add(this.buttonDeleteStorage); this.Controls.Add(this.buttonAddStorage); this.Controls.Add(this.listBoxStorages); this.Controls.Add(this.label1); - this.Controls.Add(this.buttonAddmash); + this.Controls.Add(this.buttonAddMash); this.Controls.Add(this.maskedTextBoxNumber); - this.Controls.Add(this.buttonDeletemash); + this.Controls.Add(this.buttonDeleteMash); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.labelInstruments); this.Controls.Add(this.pictureBoxCollection); @@ -176,11 +179,11 @@ #endregion - private Button buttonAddmash; + private Button buttonAddMash; private PictureBox pictureBoxCollection; private Label labelInstruments; private Button buttonUpdate; - private Button buttonDeletemash; + private Button buttonDeleteMash; private ColorDialog colorDialog; private MaskedTextBox maskedTextBoxNumber; private Label label1; diff --git a/Excavator/FormExcavatorCollection.cs b/Excavator/FormExcavatorCollection.cs index f053d88..63769c4 100644 --- a/Excavator/FormExcavatorCollection.cs +++ b/Excavator/FormExcavatorCollection.cs @@ -15,11 +15,11 @@ namespace Excavator { public partial class FormExcavatorCollection : Form { - private readonly MashsGenericStorage _storage; + private readonly mashesGenericStorage _storage; public FormExcavatorCollection() { InitializeComponent(); - _storage = new MashsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); + _storage = new mashesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); } private void ReloadObjects() { @@ -50,7 +50,7 @@ namespace Excavator } private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e) { - pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.Showmash(); + pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMash(); } private void buttonDeleteStorage_Click(object sender, EventArgs e) { @@ -64,7 +64,13 @@ namespace Excavator ReloadObjects(); } } - private void buttonAddmash_Click(object sender, EventArgs e) + private void buttonAddMash_Click(object sender, EventArgs e) + { + var formmashConfig = new FormmashConfig(); + formmashConfig.AddEvent(AddMash); + formmashConfig.Show(); + } + private void AddMash(DrawingMash SelectedMash) { if (listBoxStorages.SelectedIndex == -1) { @@ -76,21 +82,18 @@ namespace Excavator { return; } - FormExcavator form = new(); - if (form.ShowDialog() == DialogResult.OK) + SelectedMash.ChangeBordersPicture(pictureBoxCollection.Width, pictureBoxCollection.Height); + if (obj + SelectedMash != -1) { - if (obj + form.Selectedmash != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.Showmash(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowMash(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } - private void buttonDeletemash_Click(object sender, EventArgs e) + private void buttonDeleteMash_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) { @@ -115,10 +118,10 @@ namespace Excavator MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (obj - pos) + if (obj - pos) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = obj.Showmash(); + pictureBoxCollection.Image = obj.ShowMash(); } else { @@ -137,7 +140,7 @@ namespace Excavator { return; } - pictureBoxCollection.Image = obj.Showmash(); + pictureBoxCollection.Image = obj.ShowMash(); } } } diff --git a/Excavator/FormMashConfig.Designer.cs b/Excavator/FormMashConfig.Designer.cs new file mode 100644 index 0000000..cfb98da --- /dev/null +++ b/Excavator/FormMashConfig.Designer.cs @@ -0,0 +1,375 @@ +namespace Excavator +{ + partial class FormmashConfig + { + private System.ComponentModel.IContainer components = null; + 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.groupBoxConfig = new System.Windows.Forms.GroupBox(); + this.labelAdvancedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColor = new System.Windows.Forms.GroupBox(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelPink = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelRoyalBlue = new System.Windows.Forms.Panel(); + this.panelFirebrick = new System.Windows.Forms.Panel(); + this.checkBoxLadder = new System.Windows.Forms.CheckBox(); + this.checkBoxbucket = new System.Windows.Forms.CheckBox(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWeight = 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.labelAdditionalColor = new System.Windows.Forms.Label(); + this.labelMainColor = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxConfig.SuspendLayout(); + this.groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelObject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelAdvancedObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColor); + this.groupBoxConfig.Controls.Add(this.checkBoxLadder); + this.groupBoxConfig.Controls.Add(this.checkBoxbucket); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(14, 48); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Size = new System.Drawing.Size(570, 251); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Параметры"; + // + // labelAdvancedObject + // + this.labelAdvancedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdvancedObject.Location = new System.Drawing.Point(440, 188); + this.labelAdvancedObject.Name = "labelAdvancedObject"; + this.labelAdvancedObject.Size = new System.Drawing.Size(120, 30); + this.labelAdvancedObject.TabIndex = 8; + this.labelAdvancedObject.Text = "Продвинутый"; + this.labelAdvancedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdvancedObject.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(283, 188); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(120, 30); + 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); + // + // groupBoxColor + // + this.groupBoxColor.Controls.Add(this.panelBlue); + this.groupBoxColor.Controls.Add(this.panelBlack); + this.groupBoxColor.Controls.Add(this.panelPink); + this.groupBoxColor.Controls.Add(this.panelGray); + this.groupBoxColor.Controls.Add(this.panelGreen); + this.groupBoxColor.Controls.Add(this.panelYellow); + this.groupBoxColor.Controls.Add(this.panelRoyalBlue); + this.groupBoxColor.Controls.Add(this.panelFirebrick); + this.groupBoxColor.Location = new System.Drawing.Point(283, 32); + this.groupBoxColor.Name = "groupBoxColor"; + this.groupBoxColor.Size = new System.Drawing.Size(277, 145); + this.groupBoxColor.TabIndex = 6; + this.groupBoxColor.TabStop = false; + this.groupBoxColor.Text = "Цвета"; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(5, 85); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(50, 40); + this.panelBlue.TabIndex = 0; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(75, 85); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(50, 40); + this.panelBlack.TabIndex = 0; + // + // panelPink + // + this.panelPink.BackColor = System.Drawing.Color.DeepPink; + this.panelPink.Location = new System.Drawing.Point(145, 85); + this.panelPink.Name = "panelPink"; + this.panelPink.Size = new System.Drawing.Size(50, 40); + this.panelPink.TabIndex = 0; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(215, 85); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(50, 40); + this.panelGray.TabIndex = 0; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.Location = new System.Drawing.Point(215, 25); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(50, 40); + this.panelGreen.TabIndex = 0; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(145, 25); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(50, 40); + this.panelYellow.TabIndex = 0; + // + // panelRoyalBlue + // + this.panelRoyalBlue.BackColor = System.Drawing.Color.RoyalBlue; + this.panelRoyalBlue.Location = new System.Drawing.Point(75, 25); + this.panelRoyalBlue.Name = "panelRoyalBlue"; + this.panelRoyalBlue.Size = new System.Drawing.Size(50, 40); + this.panelRoyalBlue.TabIndex = 0; + // + // panelFirebrick + // + this.panelFirebrick.BackColor = System.Drawing.Color.Firebrick; + this.panelFirebrick.Location = new System.Drawing.Point(5, 25); + this.panelFirebrick.Name = "panelFirebrick"; + this.panelFirebrick.Size = new System.Drawing.Size(50, 40); + this.panelFirebrick.TabIndex = 0; + // + // checkBoxLadder + // + this.checkBoxLadder.AutoSize = true; + this.checkBoxLadder.Location = new System.Drawing.Point(13, 149); + this.checkBoxLadder.Name = "checkBoxLadder"; + this.checkBoxLadder.Size = new System.Drawing.Size(132, 24); + this.checkBoxLadder.TabIndex = 5; + this.checkBoxLadder.Text = "Наличие опор"; + this.checkBoxLadder.UseVisualStyleBackColor = true; + + // + // checkBoxbucket + // + this.checkBoxbucket.AutoSize = true; + this.checkBoxbucket.Location = new System.Drawing.Point(13, 119); + this.checkBoxbucket.Name = "checkBoxbucket"; + this.checkBoxbucket.Size = new System.Drawing.Size(149, 24); + this.checkBoxbucket.TabIndex = 4; + this.checkBoxbucket.Text = "Наличие Отвала "; + this.checkBoxbucket.UseVisualStyleBackColor = true; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(94, 32); + 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(150, 27); + this.numericUpDownSpeed.TabIndex = 3; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(94, 83); + 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(150, 27); + this.numericUpDownWeight.TabIndex = 2; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(6, 85); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(36, 20); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес:"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(6, 32); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(76, 20); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость:"; + // + // pictureBoxObject + // + this.pictureBoxObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pictureBoxObject.Location = new System.Drawing.Point(35, 84); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(327, 205); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelAdditionalColor); + this.panelObject.Controls.Add(this.labelMainColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(613, 29); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(401, 301); + 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); + // + // labelAdditionalColor + // + this.labelAdditionalColor.AllowDrop = true; + this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdditionalColor.Location = new System.Drawing.Point(233, 19); + this.labelAdditionalColor.Name = "labelAdditionalColor"; + this.labelAdditionalColor.Size = new System.Drawing.Size(90, 50); + this.labelAdditionalColor.TabIndex = 3; + this.labelAdditionalColor.Text = "Доп. цвет"; + this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragDrop); + this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragEnter); + // + // labelMainColor + // + this.labelMainColor.AllowDrop = true; + this.labelMainColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelMainColor.Location = new System.Drawing.Point(77, 19); + this.labelMainColor.Name = "labelMainColor"; + this.labelMainColor.Size = new System.Drawing.Size(90, 50); + this.labelMainColor.TabIndex = 2; + this.labelMainColor.Text = "Цвет"; + this.labelMainColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelMainColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelMainColor_DragDrop); + this.labelMainColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelMainColor_DragEnter); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(689, 337); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(846, 339); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormmashConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1032, 383); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormmashConfig"; + this.Text = "FormmashConfig"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelObject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxConfig; + private NumericUpDown numericUpDownSpeed; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private Label labelSpeed; + private CheckBox checkBoxLadder; + private CheckBox checkBoxbucket; + private GroupBox groupBoxColor; + private Panel panelBlue; + private Panel panelBlack; + private Panel panelPink; + private Panel panelGray; + private Panel panelGreen; + private Panel panelYellow; + private Panel panelRoyalBlue; + private Panel panelFirebrick; + private Label labelAdvancedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelMainColor; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Excavator/FormMashConfig.cs b/Excavator/FormMashConfig.cs new file mode 100644 index 0000000..7312a56 --- /dev/null +++ b/Excavator/FormMashConfig.cs @@ -0,0 +1,137 @@ +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 Excavator.Drawing; +using Excavator.Entities; + +namespace Excavator +{ + public partial class FormmashConfig : Form + { + DrawingMash? _mash = null; + private event Action? EventAddMash; + public FormmashConfig() + { + InitializeComponent(); + panelFirebrick.MouseDown += PanelColor_MouseDown; + panelRoyalBlue.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelBlack.MouseDown += PanelColor_MouseDown; + panelPink.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + private void DrawMash() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _mash?.SetPosition(5, 5); + _mash?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + public void AddEvent(Action ev) + { + if (EventAddMash == null) + { + EventAddMash = ev; + } + else + { + EventAddMash += ev; + } + } + 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": + _mash = new DrawingMash( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, + Color.White, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + + case "labelAdvancedObject": + _mash = new DrawingExcavator( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, + Color.White, Color.Black, + checkBoxbucket.Checked, checkBoxLadder.Checked, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawMash(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + private void LabelMainColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _mash != null) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelMainColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e.Data.GetData(typeof(Color)); + _mash.EntityMash.ChangeBodyColor(color); + DrawMash(); + } + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _mash != null && _mash is DrawingExcavator) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e.Data.GetData(typeof(Color)); + + EntityExcavator? _Excavator = _mash.EntityMash as EntityExcavator; + _Excavator.ChangeAdditionalColor(color); + DrawMash(); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + EventAddMash?.Invoke(_mash); + Close(); + } + } +} diff --git a/Excavator/FormMashConfig.resx b/Excavator/FormMashConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Excavator/FormMashConfig.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 diff --git a/Excavator/Generic/MashGenericCollection.cs b/Excavator/Generic/MashGenericCollection.cs index bd5dc3c..4e8a377 100644 --- a/Excavator/Generic/MashGenericCollection.cs +++ b/Excavator/Generic/MashGenericCollection.cs @@ -17,6 +17,7 @@ namespace Excavator.Generic private readonly int _placeSizeWidth = 200; private readonly int _placeSizeHeight = 120; private readonly SetGeneric _collection; + public MashGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; @@ -36,7 +37,7 @@ namespace Excavator.Generic } public static bool operator -(MashGenericCollection collect, int pos) { - if (collect._collection.Getmash(pos) == null) + if (collect._collection.GetMash(pos) == null) { return false; } @@ -46,11 +47,7 @@ namespace Excavator.Generic { return (U?)_collection[pos]?.GetMoveableObject; } - public int ReturnLength() - { - return _collection.Count; - } - public Bitmap Showmash() + public Bitmap ShowMash() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); @@ -72,9 +69,11 @@ namespace Excavator.Generic } private void DrawObjects(Graphics g) { + int x = _pictureWidth / _placeSizeWidth - 1; int y = 0; - foreach (var mash in _collection.Getmash()) + + foreach (var mash in _collection.GetMash()) { if (mash != null) { @@ -90,4 +89,5 @@ namespace Excavator.Generic } } } -} \ No newline at end of file + } + diff --git a/Excavator/Generic/MashsGenericStorage.cs b/Excavator/Generic/MashsGenericStorage.cs index 51d4ac4..0201584 100644 --- a/Excavator/Generic/MashsGenericStorage.cs +++ b/Excavator/Generic/MashsGenericStorage.cs @@ -8,14 +8,13 @@ using Excavator.Move_Strategy; namespace Excavator.Generic { - internal class MashsGenericStorage + internal class mashesGenericStorage { readonly Dictionary> _mashStorages; public List Keys => _mashStorages.Keys.ToList(); private readonly int _pictureWidth; private readonly int _pictureHeight; - - public MashsGenericStorage(int pictureWidth, int pictureHeight) + public mashesGenericStorage(int pictureWidth, int pictureHeight) { _mashStorages = new Dictionary>(); _pictureWidth = pictureWidth; @@ -39,7 +38,6 @@ namespace Excavator.Generic { _mashStorages.Remove(name); } - } public MashGenericCollection? this[string ind] { diff --git a/Excavator/Generic/SetGeneric.cs b/Excavator/Generic/SetGeneric.cs index 8d59117..2cf6d43 100644 --- a/Excavator/Generic/SetGeneric.cs +++ b/Excavator/Generic/SetGeneric.cs @@ -19,7 +19,7 @@ namespace Excavator.Generic } public int Insert(T mash) { - _places.Insert(0, mash); + _places.Insert(0, mash); return 0; } public bool Insert(T mash, int position) @@ -38,6 +38,7 @@ namespace Excavator.Generic return false; } _places.RemoveAt(position); + return true; } public T? this[int position] @@ -59,7 +60,7 @@ namespace Excavator.Generic _places.Insert(position, value); } } - public IEnumerable Getmash(int? maxmash = null) + public IEnumerable GetMash(int? maxmash = null) { for (int i = 0; i < _places.Count; ++i) { @@ -71,4 +72,4 @@ namespace Excavator.Generic } } } -} +} \ No newline at end of file diff --git a/Excavator/Move_Strategy/DrawingObjectMash.cs b/Excavator/Move_Strategy/DrawingObjectMash.cs new file mode 100644 index 0000000..06feec6 --- /dev/null +++ b/Excavator/Move_Strategy/DrawingObjectMash.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +using Excavator.Entities; +using Excavator.Drawing; + +namespace Excavator.Move_Strategy +{ + public class DrawingObjectmash : IMoveableObject + { + private readonly DrawingMash? _DrawingMash = null; + public DrawingObjectmash(DrawingMash DrawingMash) + { + _DrawingMash = DrawingMash; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_DrawingMash == null || _DrawingMash.EntityMash == null) + { + return null; + } + return new ObjectParameters(_DrawingMash.GetPosX, _DrawingMash.GetPosY, _DrawingMash.GetWidth, _DrawingMash.GetHeight); + } + } + public int GetStep => (int)(_DrawingMash?.EntityMash?.Step ?? 0); + public bool CheckCanMove(DirectionType direction) => _DrawingMash?.CanMove(direction) ?? false; + public void MoveObject(DirectionType direction) => _DrawingMash?.MoveTransport(direction); + } +} \ No newline at end of file diff --git a/Excavator/Move_Strategy/MoveToBorder.cs b/Excavator/Move_Strategy/MoveToBorder.cs index 54e9fd4..e70fd9e 100644 --- a/Excavator/Move_Strategy/MoveToBorder.cs +++ b/Excavator/Move_Strategy/MoveToBorder.cs @@ -38,6 +38,7 @@ namespace Excavator.Move_Strategy { MoveRight(); } + } var diffY = objParams.ObjectMiddleVertical - FieldHeight; if (Math.Abs(diffY) > GetStep()) diff --git a/Excavator/Move_Strategy/Status.cs b/Excavator/Move_Strategy/Status.cs index c7af06c..0050ceb 100644 --- a/Excavator/Move_Strategy/Status.cs +++ b/Excavator/Move_Strategy/Status.cs @@ -12,4 +12,4 @@ namespace Excavator.Move_Strategy InProgress, Finish } -} \ No newline at end of file +} diff --git a/Excavator/Program.cs b/Excavator/Program.cs index cc3f9ab..032fe7f 100644 --- a/Excavator/Program.cs +++ b/Excavator/Program.cs @@ -2,9 +2,14 @@ namespace Excavator { internal static class Program { + /// + /// The main entry point for the application. + /// [STAThread] static void Main() { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); Application.Run(new FormExcavatorCollection()); } -- 2.25.1