From cbeceed949d6fc93571f1fd22034e23378483060 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Sat, 9 Dec 2023 11:48:28 +0400 Subject: [PATCH 1/3] done --- DumpTruck/DumpTruck/CarsGenericStorage.cs | 4 + DumpTruck/DumpTruck/ClassDelegate.cs | 11 + DumpTruck/DumpTruck/DrawingDumpCar.cs | 9 + DumpTruck/DumpTruck/DrawningCar.cs | 14 +- DumpTruck/DumpTruck/EntityCar.cs | 5 + DumpTruck/DumpTruck/EntityDumpTruck.cs | 5 + DumpTruck/DumpTruck/FormCarCollection.cs | 39 +- DumpTruck/DumpTruck/FormCarConfig.Designer.cs | 390 ++++++++++++++++++ DumpTruck/DumpTruck/FormCarConfig.cs | 162 ++++++++ DumpTruck/DumpTruck/FormCarConfig.resx | 60 +++ 10 files changed, 674 insertions(+), 25 deletions(-) create mode 100644 DumpTruck/DumpTruck/ClassDelegate.cs create mode 100644 DumpTruck/DumpTruck/FormCarConfig.Designer.cs create mode 100644 DumpTruck/DumpTruck/FormCarConfig.cs create mode 100644 DumpTruck/DumpTruck/FormCarConfig.resx diff --git a/DumpTruck/DumpTruck/CarsGenericStorage.cs b/DumpTruck/DumpTruck/CarsGenericStorage.cs index 4409f1d..b2cbd98 100644 --- a/DumpTruck/DumpTruck/CarsGenericStorage.cs +++ b/DumpTruck/DumpTruck/CarsGenericStorage.cs @@ -77,6 +77,10 @@ namespace DumpTruck.Generics return null; } } + + + + } } diff --git a/DumpTruck/DumpTruck/ClassDelegate.cs b/DumpTruck/DumpTruck/ClassDelegate.cs new file mode 100644 index 0000000..6b1fcc1 --- /dev/null +++ b/DumpTruck/DumpTruck/ClassDelegate.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DumpTruck.DrawningObjects; + +namespace DumpTruck +{ + public delegate void CarDelegate(DrawningCar car); +} 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/FormCarCollection.cs b/DumpTruck/DumpTruck/FormCarCollection.cs index 455780c..345f7b2 100644 --- a/DumpTruck/DumpTruck/FormCarCollection.cs +++ b/DumpTruck/DumpTruck/FormCarCollection.cs @@ -19,7 +19,7 @@ namespace DumpTruck { public partial class FormCarCollection : Form { - //private readonly CarsGenericCollection _cars; + private readonly CarsGenericStorage _storage; public FormCarCollection() { @@ -28,16 +28,6 @@ namespace DumpTruck pictureBoxCollection.Height); } - private void Form2_Load(object sender, EventArgs e) - { - - } - - private void pictureBoxCollection_Click(object sender, EventArgs e) - { - - } - private void ReloadObjects() { int index = listBoxStorages.SelectedIndex; @@ -63,26 +53,27 @@ pictureBoxCollection.Height); private void ButtonAddCar_Click(object sender, EventArgs e) { - if (listBoxStorages.SelectedIndex == -1) { return; } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - + if (obj == null) { - + return; } - - FormDumpTruck form = new(); - if (form.ShowDialog() == DialogResult.OK) + + + FormCarConfig form = new FormCarConfig(); + form.Show(); + Action? carDelegate = new((m) => { - - if (obj + form.SelectedCar != -1) + int q = obj + m; + + if (q != -1) { - MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowCars(); } @@ -90,7 +81,13 @@ pictureBoxCollection.Height); { MessageBox.Show("Не удалось добавить объект"); } - } + }); + + Action? ColorDelegate = new((m) => + { + MessageBox.Show(m.ToString()); + }); + form.AddEvent(carDelegate); } diff --git a/DumpTruck/DumpTruck/FormCarConfig.Designer.cs b/DumpTruck/DumpTruck/FormCarConfig.Designer.cs new file mode 100644 index 0000000..97e2163 --- /dev/null +++ b/DumpTruck/DumpTruck/FormCarConfig.Designer.cs @@ -0,0 +1,390 @@ +namespace DumpTruck +{ + partial class FormCarConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBoxParameters = new System.Windows.Forms.GroupBox(); + this.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(); + this.panelLightBlue = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelOrange = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + 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.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.groupBoxParameters.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelObject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxParameters + // + this.groupBoxParameters.Controls.Add(this.labelAdvancedObject); + this.groupBoxParameters.Controls.Add(this.labelBaseObject); + this.groupBoxParameters.Controls.Add(this.groupBoxColors); + this.groupBoxParameters.Controls.Add(this.checkBoxTent); + this.groupBoxParameters.Controls.Add(this.checkBoxKit); + this.groupBoxParameters.Controls.Add(this.numericUpDownWeight); + this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed); + this.groupBoxParameters.Controls.Add(this.labelWeight); + this.groupBoxParameters.Controls.Add(this.labelSpeed); + this.groupBoxParameters.Location = new System.Drawing.Point(12, 12); + this.groupBoxParameters.Name = "groupBoxParameters"; + this.groupBoxParameters.Size = new System.Drawing.Size(589, 328); + this.groupBoxParameters.TabIndex = 0; + this.groupBoxParameters.TabStop = false; + this.groupBoxParameters.Text = "Параметры"; + // + // labelAdvancedObject + // + 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 + // + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelLightBlue); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelOrange); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(250, 22); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(303, 246); + this.groupBoxColors.TabIndex = 1; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // 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"; + this.panelWhite.Size = new System.Drawing.Size(57, 53); + this.panelWhite.TabIndex = 1; + // + // 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"; + this.panelPurple.Size = new System.Drawing.Size(57, 53); + this.panelPurple.TabIndex = 1; + // + // 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"; + this.panelLightBlue.Size = new System.Drawing.Size(57, 53); + this.panelLightBlue.TabIndex = 1; + // + // 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"; + this.panelYellow.Size = new System.Drawing.Size(57, 53); + this.panelYellow.TabIndex = 1; + // + // 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"; + this.panelBlue.Size = new System.Drawing.Size(57, 53); + this.panelBlue.TabIndex = 1; + // + // 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"; + this.panelBlack.Size = new System.Drawing.Size(57, 53); + this.panelBlack.TabIndex = 1; + // + // 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"; + this.panelOrange.Size = new System.Drawing.Size(57, 53); + this.panelOrange.TabIndex = 1; + // + // 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; + // + // checkBoxTent + // + this.checkBoxTent.AutoSize = true; + this.checkBoxTent.Location = new System.Drawing.Point(18, 164); + this.checkBoxTent.Name = "checkBoxTent"; + this.checkBoxTent.Size = new System.Drawing.Size(155, 19); + this.checkBoxTent.TabIndex = 1; + this.checkBoxTent.Text = "Признак наличия тента"; + this.checkBoxTent.UseVisualStyleBackColor = true; + // + // checkBoxKit + // + this.checkBoxKit.AutoSize = true; + this.checkBoxKit.Location = new System.Drawing.Point(18, 139); + this.checkBoxKit.Name = "checkBoxKit"; + this.checkBoxKit.Size = new System.Drawing.Size(162, 19); + this.checkBoxKit.TabIndex = 4; + this.checkBoxKit.Text = "Признак наличия кузова"; + this.checkBoxKit.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(88, 87); + 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(120, 23); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 44); + 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(120, 23); + this.numericUpDownSpeed.TabIndex = 1; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(18, 87); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(29, 15); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Вес:"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(18, 44); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(62, 15); + this.labelSpeed.TabIndex = 1; + this.labelSpeed.Text = "Скорость:"; + // + // pictureBoxObject + // + 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; + // + // panelObject + // + 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.LabelColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(672, 302); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(86, 38); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonCanel + // + this.buttonCanel.Location = new System.Drawing.Point(768, 302); + this.buttonCanel.Name = "buttonCanel"; + this.buttonCanel.Size = new System.Drawing.Size(86, 38); + this.buttonCanel.TabIndex = 4; + this.buttonCanel.Text = "Отмена"; + this.buttonCanel.UseVisualStyleBackColor = true; + // + // FormCarConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(924, 348); + this.Controls.Add(this.buttonCanel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxParameters); + this.Name = "FormCarConfig"; + this.Text = "FormCarConfig"; + this.groupBoxParameters.ResumeLayout(false); + this.groupBoxParameters.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelObject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxParameters; + private Label labelBaseObject; + private CheckBox checkBoxTent; + private CheckBox checkBoxKit; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private GroupBox groupBoxColors; + private Panel panelWhite; + private Panel panelPurple; + private Panel panelLightBlue; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelBlack; + private Panel panelOrange; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Button buttonAdd; + private Button buttonCanel; + private Label labelAdvancedObject; + private Label labelColor; + private Label labelAddColor; + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/FormCarConfig.cs b/DumpTruck/DumpTruck/FormCarConfig.cs new file mode 100644 index 0000000..4a1f95e --- /dev/null +++ b/DumpTruck/DumpTruck/FormCarConfig.cs @@ -0,0 +1,162 @@ +using DumpTruck.DrawningObjects; +using System; +using System.Collections; +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; + +namespace DumpTruck +{ + public partial class FormCarConfig : Form + { + + DrawningCar? _car = null; + public event Action? EventAddCar; + + public FormCarConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelOrange.MouseDown += PanelColor_MouseDown; + panelLightBlue.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + buttonCanel.Click += (s, e) => Close(); + } + + 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) + { + { + string senderName = ((Label)sender).Name; + if (_car == null || e.Data.GetDataPresent(typeof(Color)) == false) + return; + + Color droppedColor = (Color)e.Data.GetData(typeof(Color)); + + if (senderName == "labelColor") + { + labelColor.BackColor = droppedColor; + ((DrawningCar)_car).setColor(labelColor.BackColor); + } + else if (senderName == "labelAddColor" && _car is DrawningDumpTruck) + { + labelAddColor.BackColor = droppedColor; + ((DrawningDumpTruck)_car).setAddColor(labelAddColor.BackColor); + } + + DrawCar(); + } + } + + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + + if (_car is DrawningDumpTruck car) + { + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + ((DrawningDumpTruck)_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(); + } + + public void AddEvent(Action ev) + { + if (EventAddCar == null) + { + EventAddCar = ev; + } + else + { + EventAddCar += ev; + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + if (_car == null) + { + return; + } + EventAddCar?.Invoke(_car); + Close(); + } + } +} diff --git a/DumpTruck/DumpTruck/FormCarConfig.resx b/DumpTruck/DumpTruck/FormCarConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/DumpTruck/DumpTruck/FormCarConfig.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 -- 2.25.1 From a250cf671dc34d174d9eb0c105e2c93b0107f702 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Sat, 9 Dec 2023 11:51:08 +0400 Subject: [PATCH 2/3] done done --- DumpTruck/DumpTruck/CarsGenericStorage.cs | 4 ---- DumpTruck/DumpTruck/DrawningCar.cs | 2 -- DumpTruck/DumpTruck/FormCarConfig.cs | 12 ------------ 3 files changed, 18 deletions(-) diff --git a/DumpTruck/DumpTruck/CarsGenericStorage.cs b/DumpTruck/DumpTruck/CarsGenericStorage.cs index b2cbd98..4409f1d 100644 --- a/DumpTruck/DumpTruck/CarsGenericStorage.cs +++ b/DumpTruck/DumpTruck/CarsGenericStorage.cs @@ -77,10 +77,6 @@ namespace DumpTruck.Generics return null; } } - - - - } } diff --git a/DumpTruck/DumpTruck/DrawningCar.cs b/DumpTruck/DumpTruck/DrawningCar.cs index 4e83a63..55f28dc 100644 --- a/DumpTruck/DumpTruck/DrawningCar.cs +++ b/DumpTruck/DumpTruck/DrawningCar.cs @@ -154,8 +154,6 @@ width, int height, int carWidth, int carHeight) } - - public void setColor(Color color) { EntityCar.setColor(color); diff --git a/DumpTruck/DumpTruck/FormCarConfig.cs b/DumpTruck/DumpTruck/FormCarConfig.cs index 4a1f95e..29fcaf7 100644 --- a/DumpTruck/DumpTruck/FormCarConfig.cs +++ b/DumpTruck/DumpTruck/FormCarConfig.cs @@ -81,18 +81,6 @@ DragDropEffects.Move | DragDropEffects.Copy); } } - private void LabelAddColor_DragDrop(object sender, DragEventArgs e) - { - - if (_car is DrawningDumpTruck car) - { - labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); - ((DrawningDumpTruck)_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, -- 2.25.1 From bb349d756c4af1257eadaa76a40af3045584b9d2 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Sat, 9 Dec 2023 12:28:46 +0400 Subject: [PATCH 3/3] done done done --- DumpTruck/DumpTruck/FormCarConfig.Designer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DumpTruck/DumpTruck/FormCarConfig.Designer.cs b/DumpTruck/DumpTruck/FormCarConfig.Designer.cs index 97e2163..f949a84 100644 --- a/DumpTruck/DumpTruck/FormCarConfig.Designer.cs +++ b/DumpTruck/DumpTruck/FormCarConfig.Designer.cs @@ -130,7 +130,7 @@ // panelPurple // this.panelPurple.AllowDrop = true; - this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255))))); + this.panelPurple.BackColor = System.Drawing.Color.Fuchsia; this.panelPurple.Location = new System.Drawing.Point(156, 106); this.panelPurple.Name = "panelPurple"; this.panelPurple.Size = new System.Drawing.Size(57, 53); @@ -139,7 +139,7 @@ // panelLightBlue // this.panelLightBlue.AllowDrop = true; - this.panelLightBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.panelLightBlue.BackColor = System.Drawing.Color.Cyan; this.panelLightBlue.Location = new System.Drawing.Point(13, 106); this.panelLightBlue.Name = "panelLightBlue"; this.panelLightBlue.Size = new System.Drawing.Size(57, 53); @@ -148,7 +148,7 @@ // panelYellow // this.panelYellow.AllowDrop = true; - this.panelYellow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.panelYellow.BackColor = System.Drawing.Color.Yellow; this.panelYellow.Location = new System.Drawing.Point(156, 35); this.panelYellow.Name = "panelYellow"; this.panelYellow.Size = new System.Drawing.Size(57, 53); @@ -157,7 +157,7 @@ // panelBlue // this.panelBlue.AllowDrop = true; - this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255))))); + this.panelBlue.BackColor = System.Drawing.Color.Blue; this.panelBlue.Location = new System.Drawing.Point(86, 106); this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(57, 53); @@ -175,7 +175,7 @@ // panelOrange // this.panelOrange.AllowDrop = true; - this.panelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128))))); + this.panelOrange.BackColor = System.Drawing.Color.Orange; this.panelOrange.Location = new System.Drawing.Point(86, 35); this.panelOrange.Name = "panelOrange"; this.panelOrange.Size = new System.Drawing.Size(57, 53); @@ -184,7 +184,7 @@ // panelRed // this.panelRed.AllowDrop = true; - this.panelRed.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128))))); + this.panelRed.BackColor = System.Drawing.Color.Red; this.panelRed.Location = new System.Drawing.Point(13, 35); this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(57, 53); -- 2.25.1