diff --git a/DumpTruck/DumpTruck/DrawingDumpCar.cs b/DumpTruck/DumpTruck/DrawingDumpCar.cs index afc7b18..1fd5ba5 100644 --- a/DumpTruck/DumpTruck/DrawingDumpCar.cs +++ b/DumpTruck/DumpTruck/DrawingDumpCar.cs @@ -69,6 +69,15 @@ namespace DumpTruck.DrawningObjects } } } + + public void setAddColor(Color color) + { + if (EntityCar is EntityDumpTruck dumpTruck) + { + dumpTruck.setAddColor(color); + } + + } } } diff --git a/DumpTruck/DumpTruck/DrawningCar.cs b/DumpTruck/DumpTruck/DrawningCar.cs index d7490a1..4e83a63 100644 --- a/DumpTruck/DumpTruck/DrawningCar.cs +++ b/DumpTruck/DumpTruck/DrawningCar.cs @@ -49,7 +49,7 @@ namespace DumpTruck.DrawningObjects public DrawningCar(int speed, double weight, Color bodyColor, int width, int height) { - if(width < _carWidth || height < _carHeight) + if (width < _carWidth || height < _carHeight) { return; } @@ -58,7 +58,7 @@ namespace DumpTruck.DrawningObjects EntityCar = new EntityCar(speed, weight, bodyColor); - + } @@ -113,7 +113,7 @@ width, int height, int carWidth, int carHeight) break; } } - + public bool CanMove(DirectionType direction) { if (EntityCar == null) @@ -144,7 +144,7 @@ width, int height, int carWidth, int carHeight) Pen pen = new Pen(Color.Black); Brush brush = new SolidBrush(EntityCar.BodyColor); - + //границы автомобиля g.FillRectangle(brush, _startPosX, _startPosY + 35, 110, 10); g.FillRectangle(brush, _startPosX + 85, _startPosY, 25, 35); @@ -154,5 +154,11 @@ width, int height, int carWidth, int carHeight) } + + + public void setColor(Color color) + { + EntityCar.setColor(color); + } } } diff --git a/DumpTruck/DumpTruck/EntityCar.cs b/DumpTruck/DumpTruck/EntityCar.cs index 2694658..710fece 100644 --- a/DumpTruck/DumpTruck/EntityCar.cs +++ b/DumpTruck/DumpTruck/EntityCar.cs @@ -37,5 +37,10 @@ namespace DumpTruck.Entities BodyColor = bodyColor; } + public void setColor(Color color) + { + BodyColor = color; + } + } } diff --git a/DumpTruck/DumpTruck/EntityDumpTruck.cs b/DumpTruck/DumpTruck/EntityDumpTruck.cs index d6024c4..24db731 100644 --- a/DumpTruck/DumpTruck/EntityDumpTruck.cs +++ b/DumpTruck/DumpTruck/EntityDumpTruck.cs @@ -36,6 +36,11 @@ namespace DumpTruck.Entities BodyKit = bodyKit; Tent = tent; } + + public void setAddColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/DumpTruck/DumpTruck/FormCarConfig.Designer.cs b/DumpTruck/DumpTruck/FormCarConfig.Designer.cs index 77e258a..929d048 100644 --- a/DumpTruck/DumpTruck/FormCarConfig.Designer.cs +++ b/DumpTruck/DumpTruck/FormCarConfig.Designer.cs @@ -29,7 +29,8 @@ private void InitializeComponent() { this.groupBoxParameters = new System.Windows.Forms.GroupBox(); - this.labelBase = new System.Windows.Forms.Label(); + this.labelAdvancedObject = new System.Windows.Forms.Label(); + this.labelBaseObject = new System.Windows.Forms.Label(); this.groupBoxColors = new System.Windows.Forms.GroupBox(); this.panelWhite = new System.Windows.Forms.Panel(); this.panelPurple = new System.Windows.Forms.Panel(); @@ -39,34 +40,31 @@ this.panelBlack = new System.Windows.Forms.Panel(); this.panelOrange = new System.Windows.Forms.Panel(); this.panelRed = new System.Windows.Forms.Panel(); - this.checkBoxTentAndKit = new System.Windows.Forms.CheckBox(); this.checkBoxTent = new System.Windows.Forms.CheckBox(); this.checkBoxKit = new System.Windows.Forms.CheckBox(); this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); this.labelWeight = new System.Windows.Forms.Label(); this.labelSpeed = new System.Windows.Forms.Label(); - this.pictureBoxCar = new System.Windows.Forms.PictureBox(); - this.panel9 = new System.Windows.Forms.Panel(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelColor = new System.Windows.Forms.Label(); + this.labelAddColor = new System.Windows.Forms.Label(); this.buttonAdd = new System.Windows.Forms.Button(); this.buttonCanel = new System.Windows.Forms.Button(); - this.labelAdvanced = new System.Windows.Forms.Label(); - this.labelAddColor = new System.Windows.Forms.Label(); - this.labelColor = new System.Windows.Forms.Label(); this.groupBoxParameters.SuspendLayout(); this.groupBoxColors.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); - this.panel9.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelObject.SuspendLayout(); this.SuspendLayout(); // // groupBoxParameters // - this.groupBoxParameters.Controls.Add(this.labelAdvanced); - this.groupBoxParameters.Controls.Add(this.labelBase); + this.groupBoxParameters.Controls.Add(this.labelAdvancedObject); + this.groupBoxParameters.Controls.Add(this.labelBaseObject); this.groupBoxParameters.Controls.Add(this.groupBoxColors); - this.groupBoxParameters.Controls.Add(this.checkBoxTentAndKit); this.groupBoxParameters.Controls.Add(this.checkBoxTent); this.groupBoxParameters.Controls.Add(this.checkBoxKit); this.groupBoxParameters.Controls.Add(this.numericUpDownWeight); @@ -80,16 +78,28 @@ this.groupBoxParameters.TabStop = false; this.groupBoxParameters.Text = "Параметры"; // - // labelBase + // labelAdvancedObject // - this.labelBase.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelBase.Location = new System.Drawing.Point(295, 271); - this.labelBase.Name = "labelBase"; - this.labelBase.Size = new System.Drawing.Size(98, 35); - this.labelBase.TabIndex = 2; - this.labelBase.Text = "Простой"; - this.labelBase.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelBase.Click += new System.EventHandler(this.labelBase_Click); + this.labelAdvancedObject.AllowDrop = true; + this.labelAdvancedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdvancedObject.Location = new System.Drawing.Point(406, 271); + this.labelAdvancedObject.Name = "labelAdvancedObject"; + this.labelAdvancedObject.Size = new System.Drawing.Size(98, 35); + this.labelAdvancedObject.TabIndex = 6; + this.labelAdvancedObject.Text = "Продвинутый"; + this.labelAdvancedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdvancedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelBaseObject + // + this.labelBaseObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseObject.Location = new System.Drawing.Point(295, 271); + this.labelBaseObject.Name = "labelBaseObject"; + this.labelBaseObject.Size = new System.Drawing.Size(98, 35); + this.labelBaseObject.TabIndex = 2; + this.labelBaseObject.Text = "Простой"; + this.labelBaseObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // // groupBoxColors // @@ -110,6 +120,7 @@ // // panelWhite // + this.panelWhite.AllowDrop = true; this.panelWhite.BackColor = System.Drawing.Color.White; this.panelWhite.Location = new System.Drawing.Point(230, 106); this.panelWhite.Name = "panelWhite"; @@ -118,6 +129,7 @@ // // panelPurple // + this.panelPurple.AllowDrop = true; this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255))))); this.panelPurple.Location = new System.Drawing.Point(156, 106); this.panelPurple.Name = "panelPurple"; @@ -126,6 +138,7 @@ // // panelLightBlue // + this.panelLightBlue.AllowDrop = true; this.panelLightBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); this.panelLightBlue.Location = new System.Drawing.Point(13, 106); this.panelLightBlue.Name = "panelLightBlue"; @@ -134,6 +147,7 @@ // // panelYellow // + this.panelYellow.AllowDrop = true; this.panelYellow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); this.panelYellow.Location = new System.Drawing.Point(156, 35); this.panelYellow.Name = "panelYellow"; @@ -142,6 +156,7 @@ // // panelBlue // + this.panelBlue.AllowDrop = true; this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255))))); this.panelBlue.Location = new System.Drawing.Point(86, 106); this.panelBlue.Name = "panelBlue"; @@ -150,6 +165,7 @@ // // panelBlack // + this.panelBlack.AllowDrop = true; this.panelBlack.BackColor = System.Drawing.Color.Black; this.panelBlack.Location = new System.Drawing.Point(230, 35); this.panelBlack.Name = "panelBlack"; @@ -158,6 +174,7 @@ // // panelOrange // + this.panelOrange.AllowDrop = true; this.panelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128))))); this.panelOrange.Location = new System.Drawing.Point(86, 35); this.panelOrange.Name = "panelOrange"; @@ -166,22 +183,13 @@ // // panelRed // + this.panelRed.AllowDrop = true; this.panelRed.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128))))); this.panelRed.Location = new System.Drawing.Point(13, 35); this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(57, 53); this.panelRed.TabIndex = 0; // - // checkBoxTentAndKit - // - this.checkBoxTentAndKit.AutoSize = true; - this.checkBoxTentAndKit.Location = new System.Drawing.Point(18, 189); - this.checkBoxTentAndKit.Name = "checkBoxTentAndKit"; - this.checkBoxTentAndKit.Size = new System.Drawing.Size(204, 19); - this.checkBoxTentAndKit.TabIndex = 5; - this.checkBoxTentAndKit.Text = "Признак наличия кузова и тента"; - this.checkBoxTentAndKit.UseVisualStyleBackColor = true; - // // checkBoxTent // this.checkBoxTent.AutoSize = true; @@ -264,23 +272,52 @@ this.labelSpeed.TabIndex = 1; this.labelSpeed.Text = "Скорость:"; // - // pictureBoxCar + // pictureBoxObject // - this.pictureBoxCar.Location = new System.Drawing.Point(16, 64); - this.pictureBoxCar.Name = "pictureBoxCar"; - this.pictureBoxCar.Size = new System.Drawing.Size(260, 183); - this.pictureBoxCar.TabIndex = 7; - this.pictureBoxCar.TabStop = false; + this.pictureBoxObject.Location = new System.Drawing.Point(16, 64); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(260, 183); + this.pictureBoxObject.TabIndex = 7; + this.pictureBoxObject.TabStop = false; // - // panel9 + // panelObject // - this.panel9.Controls.Add(this.labelColor); - this.panel9.Controls.Add(this.labelAddColor); - this.panel9.Controls.Add(this.pictureBoxCar); - this.panel9.Location = new System.Drawing.Point(618, 21); - this.panel9.Name = "panel9"; - this.panel9.Size = new System.Drawing.Size(294, 270); - this.panel9.TabIndex = 2; + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelColor); + this.panelObject.Controls.Add(this.labelAddColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(618, 21); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(294, 270); + 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); + // + // labelColor + // + this.labelColor.AllowDrop = true; + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(16, 23); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(124, 35); + this.labelColor.TabIndex = 10; + this.labelColor.Text = "Цвет"; + this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // labelAddColor + // + this.labelAddColor.AllowDrop = true; + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Location = new System.Drawing.Point(150, 23); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(126, 35); + this.labelAddColor.TabIndex = 9; + this.labelAddColor.Text = "Доп. цвет"; + this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // buttonAdd // @@ -300,36 +337,6 @@ this.buttonCanel.Text = "Отмена"; this.buttonCanel.UseVisualStyleBackColor = true; // - // labelAdvanced - // - this.labelAdvanced.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelAdvanced.Location = new System.Drawing.Point(406, 271); - this.labelAdvanced.Name = "labelAdvanced"; - this.labelAdvanced.Size = new System.Drawing.Size(98, 35); - this.labelAdvanced.TabIndex = 6; - this.labelAdvanced.Text = "Продвинутый"; - this.labelAdvanced.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // labelAddColor - // - this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelAddColor.Location = new System.Drawing.Point(150, 23); - this.labelAddColor.Name = "labelAddColor"; - this.labelAddColor.Size = new System.Drawing.Size(126, 35); - this.labelAddColor.TabIndex = 9; - this.labelAddColor.Text = "Доп. цвет"; - this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // labelColor - // - this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelColor.Location = new System.Drawing.Point(16, 23); - this.labelColor.Name = "labelColor"; - this.labelColor.Size = new System.Drawing.Size(124, 35); - this.labelColor.TabIndex = 10; - this.labelColor.Text = "Цвет"; - this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // FormCarConfig // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -337,7 +344,7 @@ this.ClientSize = new System.Drawing.Size(924, 348); this.Controls.Add(this.buttonCanel); this.Controls.Add(this.buttonAdd); - this.Controls.Add(this.panel9); + this.Controls.Add(this.panelObject); this.Controls.Add(this.groupBoxParameters); this.Name = "FormCarConfig"; this.Text = "FormCarConfig"; @@ -346,8 +353,8 @@ this.groupBoxColors.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit(); - this.panel9.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelObject.ResumeLayout(false); this.ResumeLayout(false); } @@ -355,8 +362,7 @@ #endregion private GroupBox groupBoxParameters; - private Label labelBase; - private CheckBox checkBoxTentAndKit; + private Label labelBaseObject; private CheckBox checkBoxTent; private CheckBox checkBoxKit; private NumericUpDown numericUpDownWeight; @@ -372,11 +378,11 @@ private Panel panelBlack; private Panel panelOrange; private Panel panelRed; - private PictureBox pictureBoxCar; - private Panel panel9; + private PictureBox pictureBoxObject; + private Panel panelObject; private Button buttonAdd; private Button buttonCanel; - private Label labelAdvanced; + private Label labelAdvancedObject; private Label labelColor; private Label labelAddColor; } diff --git a/DumpTruck/DumpTruck/FormCarConfig.cs b/DumpTruck/DumpTruck/FormCarConfig.cs index 6a3ecbc..c608e90 100644 --- a/DumpTruck/DumpTruck/FormCarConfig.cs +++ b/DumpTruck/DumpTruck/FormCarConfig.cs @@ -14,24 +14,112 @@ namespace DumpTruck public partial class FormCarConfig : Form { DrawningCar? _car = null; - private event CarDelegate? EventAddCar; + //private event CarDelegate? EventAddCar; public FormCarConfig() { InitializeComponent(); - } - - private void labelBase_Click(object sender, EventArgs e) - { panelBlack.MouseDown += PanelColor_MouseDown; panelPurple.MouseDown += PanelColor_MouseDown; panelOrange.MouseDown += PanelColor_MouseDown; panelLightBlue.MouseDown += PanelColor_MouseDown; - panelRed.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + + } + private void DrawCar() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _car?.SetPosition(5, 5); + _car?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, +DragDropEffects.Move | DragDropEffects.Copy); + + } + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + e.Effect = DragDropEffects.Copy; + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + + if (_car is DrawningCar car) + { + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _car.setColor((Color)e.Data.GetData(typeof(Color))); + } + DrawCar(); + } + + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + + if (_car is DrawningDumpTruck car) + { + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + car.setAddColor((Color)e.Data.GetData(typeof(Color))); + } + DrawCar(); + } + + + 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 "labelBaseObject": + _car = new DrawningCar((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + labelColor.BackColor = Color.White; + labelAddColor.BackColor = Color.Transparent; + break; + case "labelAdvancedObject": + _car = new DrawningDumpTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxKit.Checked, + checkBoxTent.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + labelColor.BackColor = Color.White; + labelAddColor.BackColor = Color.Black; + break; + } + + DrawCar(); } } } diff --git a/DumpTruck/DumpTruck/Program.cs b/DumpTruck/DumpTruck/Program.cs index dece68e..2995af7 100644 --- a/DumpTruck/DumpTruck/Program.cs +++ b/DumpTruck/DumpTruck/Program.cs @@ -11,7 +11,7 @@ namespace DumpTruck // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCarCollection()); + Application.Run(new FormCarConfig()); } } } \ No newline at end of file