diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs index 9a9e03d..5c29324 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs @@ -12,9 +12,25 @@ public class MassiveGenericObjects : ICollectionGenericObjects { private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } + - public MassiveGenericObjects() { _collection = Array.Empty(); diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAU.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAU.cs index 3ccbbbc..daf417b 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAU.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAU.cs @@ -12,9 +12,9 @@ public class DrawingSAU : DrawingBase { - public DrawingSAU(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool guns) : base(150, 100) + public DrawingSAU(int speed, double weight, Color bodyColor, Color additionalColor, bool tracks, bool guns) : base(150, 100) { - BaseSAU = new EntitySAU( speed, weight, bodyColor, additionalColor, wheels, guns); + BaseSAU = new EntitySAU( speed, weight, bodyColor, additionalColor, tracks, guns); } @@ -29,12 +29,9 @@ public class DrawingSAU : DrawingBase Brush additionalBrush = new SolidBrush(SAU.AdditionalColor); - //гусеницы - g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 55, 130, 40); //пулеметы - if (SAU.Guns) { @@ -46,7 +43,12 @@ public class DrawingSAU : DrawingBase base.DrawSAU(g); //гусеницы - g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 55, 130, 40); + if (SAU.Tracks) + { + g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 55, 130, 40); + } + + } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/BaseSAU.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/BaseSAU.cs index 851ea2e..317c7e6 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/BaseSAU.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/BaseSAU.cs @@ -22,5 +22,9 @@ namespace Project_SelfPropelledArtilleryUnit.Entity BodyColor = bodyColor; } + public void SetBodyColor(Color bodyColor) + { + BodyColor = bodyColor; + } } } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/EntitySAU.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/EntitySAU.cs index 335665e..919bfcc 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/EntitySAU.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Entity/EntitySAU.cs @@ -11,15 +11,19 @@ public class EntitySAU: BaseSAU public Color AdditionalColor { get; private set; } - public bool Wheels { get; private set; } - //длина ствола + public bool Tracks { get; private set; } + public bool Guns { get; private set; } - public EntitySAU(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool guns) : base(speed, weight, bodyColor) + public EntitySAU(int speed, double weight, Color bodyColor, Color additionalColor, bool tracks, bool guns) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; - Wheels = wheels; + Tracks = tracks; Guns = guns; } + public void SetAdditionalColor(Color additionalColor) + { + AdditionalColor = additionalColor; + } } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs index 21baaf5..d751890 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs @@ -32,7 +32,6 @@ panelCompanyTools = new Panel(); buttonAddBaseSAU = new Button(); buttonUpdate = new Button(); - buttonAddSAU = new Button(); buttonGoToCheck = new Button(); maskedTextBox = new MaskedTextBox(); buttonRemoveSAU = new Button(); @@ -69,7 +68,6 @@ // panelCompanyTools.Controls.Add(buttonAddBaseSAU); panelCompanyTools.Controls.Add(buttonUpdate); - panelCompanyTools.Controls.Add(buttonAddSAU); panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Controls.Add(buttonRemoveSAU); @@ -86,9 +84,9 @@ buttonAddBaseSAU.Name = "buttonAddBaseSAU"; buttonAddBaseSAU.Size = new Size(203, 41); buttonAddBaseSAU.TabIndex = 2; - buttonAddBaseSAU.Text = "Добавление базовой САУ"; + buttonAddBaseSAU.Text = "Добавление САУ"; buttonAddBaseSAU.UseVisualStyleBackColor = true; - buttonAddBaseSAU.Click += buttonAddBaseSAU_Click; + buttonAddBaseSAU.Click += buttonAddSAU_Click; // // buttonUpdate // @@ -100,16 +98,6 @@ buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.Click += buttonUpdate_Click; // - // buttonAddSAU - // - buttonAddSAU.Location = new Point(3, 50); - buttonAddSAU.Name = "buttonAddSAU"; - buttonAddSAU.Size = new Size(203, 41); - buttonAddSAU.TabIndex = 3; - buttonAddSAU.Text = "Добавление САУ"; - buttonAddSAU.UseVisualStyleBackColor = true; - buttonAddSAU.Click += buttonAddSAU_Click; - // // buttonGoToCheck // buttonGoToCheck.Location = new Point(3, 177); @@ -274,7 +262,6 @@ private GroupBox groupBoxTools; private ComboBox comboBoxSelectorCompany; - private Button buttonAddSAU; private Button buttonAddBaseSAU; private PictureBox pictureBox; private Button buttonGoToCheck; diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs index e22da97..e34a90f 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs @@ -30,27 +30,24 @@ public partial class FormSAUCollection : Form panelCompanyTools.Enabled = false; } - private void CreateObject(string type) - { - if (_company == null) { return; } - DrawingBase drawingbase; - Random random = new(); - switch (type) - { - case nameof(DrawingBase): - drawingbase = new DrawingBase(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawingSAU): - drawingbase = new DrawingSAU(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; + + + private void buttonAddSAU_Click(object sender, EventArgs e) + { + FormSAUConfig form = new(); + form.Show(); + form.AddEvent(SetSAU); + } + + private void SetSAU(DrawingBase sau) + { + if (_company == null || sau == null) + { + return; } - if (_company + drawingbase != -1) + if (_company + sau != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -61,22 +58,6 @@ public partial class FormSAUCollection : Form } } - private static Color GetColor(Random random) - { - Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - color = dialog.Color; - } - return color; - } - - - private void buttonAddBaseSAU_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBase)); - - private void buttonAddSAU_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingSAU)); - private void buttonRemoveSAU_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs new file mode 100644 index 0000000..3617c6b --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs @@ -0,0 +1,373 @@ +namespace Project_SelfPropelledArtilleryUnit +{ + partial class FormSAUConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxConfig = new GroupBox(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelGreen = new Panel(); + panelBlue = new Panel(); + panelRed = new Panel(); + labelSimpleObject = new Label(); + checkBoxGuns = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + labelWeight = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + pictureBoxObject = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelBodyColor = new Label(); + checkBoxTracks = new CheckBox(); + 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(checkBoxTracks); + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Controls.Add(checkBoxGuns); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Dock = DockStyle.Left; + groupBoxConfig.Location = new Point(0, 0); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(569, 223); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(317, 23); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(230, 127); + groupBoxColors.TabIndex = 8; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.AllowDrop = true; + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(180, 82); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(42, 39); + panelPurple.TabIndex = 7; + panelPurple.MouseDown += labelObject_MouseDown; + // + // panelBlack + // + panelBlack.AllowDrop = true; + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(122, 82); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(42, 39); + panelBlack.TabIndex = 6; + panelBlack.MouseDown += labelObject_MouseDown; + // + // panelGray + // + panelGray.AllowDrop = true; + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(65, 82); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(42, 39); + panelGray.TabIndex = 5; + panelGray.MouseDown += labelObject_MouseDown; + // + // panelWhite + // + panelWhite.AllowDrop = true; + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(6, 82); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(42, 39); + panelWhite.TabIndex = 4; + panelWhite.MouseDown += labelObject_MouseDown; + // + // panelYellow + // + panelYellow.AllowDrop = true; + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(180, 26); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(42, 39); + panelYellow.TabIndex = 3; + panelYellow.MouseDown += labelObject_MouseDown; + // + // panelGreen + // + panelGreen.AllowDrop = true; + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(122, 26); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(42, 39); + panelGreen.TabIndex = 2; + panelGreen.MouseDown += labelObject_MouseDown; + // + // panelBlue + // + panelBlue.AllowDrop = true; + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(65, 26); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(42, 39); + panelBlue.TabIndex = 1; + panelBlue.MouseDown += labelObject_MouseDown; + // + // panelRed + // + panelRed.AllowDrop = true; + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(6, 26); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(42, 39); + panelRed.TabIndex = 0; + panelRed.MouseDown += labelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(317, 172); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(120, 42); + labelSimpleObject.TabIndex = 0; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelObject_MouseDown; + // + // checkBoxGuns + // + checkBoxGuns.AutoSize = true; + checkBoxGuns.Location = new Point(12, 105); + checkBoxGuns.Name = "checkBoxGuns"; + checkBoxGuns.Size = new Size(232, 24); + checkBoxGuns.TabIndex = 7; + checkBoxGuns.Text = "Признак наличия пулеметов"; + checkBoxGuns.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(85, 63); + 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(110, 27); + numericUpDownWeight.TabIndex = 5; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(6, 65); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(36, 20); + labelWeight.TabIndex = 4; + labelWeight.Text = "Вес:"; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(85, 26); + 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(110, 27); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(3, 28); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(76, 20); + labelSpeed.TabIndex = 2; + labelSpeed.Text = "Скорость:"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(443, 172); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(120, 42); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += labelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(3, 48); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(209, 112); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(575, 183); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(90, 31); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(700, 183); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(90, 31); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(575, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(215, 165); + panelObject.TabIndex = 4; + panelObject.DragDrop += panelObject_DragDrop; + panelObject.DragEnter += panelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(110, 9); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(102, 27); + labelAdditionalColor.TabIndex = 3; + labelAdditionalColor.Text = " Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(3, 9); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(101, 27); + labelBodyColor.TabIndex = 2; + labelBodyColor.Text = " Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += labelBodyColor_DragDrop; + labelBodyColor.DragEnter += labelBodyColor_DragEnter; + // + // checkBoxTracks + // + checkBoxTracks.AutoSize = true; + checkBoxTracks.Location = new Point(12, 135); + checkBoxTracks.Name = "checkBoxTracks"; + checkBoxTracks.Size = new Size(213, 24); + checkBoxTracks.TabIndex = 9; + checkBoxTracks.Text = "Признак наличия гусениц"; + checkBoxTracks.UseVisualStyleBackColor = true; + // + // FormSAUConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(793, 223); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Name = "FormSAUConfig"; + Text = "FormSAUConfig"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelSimpleObject; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private Label labelModifiedObject; + private CheckBox checkBoxGuns; + private GroupBox groupBoxColors; + private Panel panelYellow; + private Panel panelGreen; + private Panel panelBlue; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + private Label labelBodyColor; + private Label labelAdditionalColor; + private CheckBox checkBoxTracks; + } +} \ No newline at end of file diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.cs new file mode 100644 index 0000000..1baade2 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.cs @@ -0,0 +1,138 @@ +using Project_SelfPropelledArtilleryUnit.Drawings; +using Project_SelfPropelledArtilleryUnit.Entity; +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; + +namespace Project_SelfPropelledArtilleryUnit; + +public partial class FormSAUConfig : Form +{ + private DrawingBase? _drawingBase; + + private event Action? SauDelegate; + public FormSAUConfig() + { + InitializeComponent(); + + panelRed.MouseDown += panel_MouseDown; + panelGreen.MouseDown += panel_MouseDown; + panelBlue.MouseDown += panel_MouseDown; + panelYellow.MouseDown += panel_MouseDown; + panelWhite.MouseDown += panel_MouseDown; + panelGray.MouseDown += panel_MouseDown; + panelBlack.MouseDown += panel_MouseDown; + panelPurple.MouseDown += panel_MouseDown; + + buttonCancel.Click += (sender, e) => Close(); + + } + + public void AddEvent(Action sauDelegate) + { + SauDelegate += sauDelegate; + } + + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingBase?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _drawingBase?.SetPosition(5, 5); + _drawingBase?.DrawSAU(gr); + pictureBoxObject.Image = bmp; + } + + 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": + _drawingBase = new DrawingBase((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _drawingBase = new DrawingSAU((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, + Color.Black, checkBoxTracks.Checked, checkBoxGuns.Checked); + break; + } + + DrawObject(); + } + + private void panel_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control)?.DoDragDrop((sender as Control)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void labelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_drawingBase != null) + { + _drawingBase.BaseSAU.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + } + + 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 labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_drawingBase?.BaseSAU is EntitySAU _accordionBus) + { + _accordionBus.SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + } + + private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (_drawingBase is DrawingBase) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + if (_drawingBase != null) + { + SauDelegate?.Invoke(_drawingBase); + Close(); + } + } + + + +} diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.resx b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/SAUDelegate.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/SAUDelegate.cs new file mode 100644 index 0000000..593d560 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/SAUDelegate.cs @@ -0,0 +1,10 @@ +using Project_SelfPropelledArtilleryUnit.Drawings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project_SelfPropelledArtilleryUnit; + +public delegate void SAUDelegate(DrawingBase sau);