From 4acd470e61e241c3a72a625e71dd411d22347dcf Mon Sep 17 00:00:00 2001 From: dex_moth Date: Sat, 2 Dec 2023 09:05:27 +0400 Subject: [PATCH] =?UTF-8?q?5=D0=B0=D1=8F=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Drawnings/DrawningAirbus.cs | 7 + Airbus/Entities/EntityAirbus.cs | 5 + Airbus/Entities/EntityPlane.cs | 5 + Airbus/FormAirbusCollection.cs | 27 ++- Airbus/FormAirbusConfig.Designer.cs | 357 ++++++++++++++++++++++++++++ Airbus/FormAirbusConfig.cs | 157 ++++++++++++ Airbus/FormAirbusConfig.resx | 120 ++++++++++ 7 files changed, 667 insertions(+), 11 deletions(-) create mode 100644 Airbus/FormAirbusConfig.Designer.cs create mode 100644 Airbus/FormAirbusConfig.cs create mode 100644 Airbus/FormAirbusConfig.resx diff --git a/Airbus/Drawnings/DrawningAirbus.cs b/Airbus/Drawnings/DrawningAirbus.cs index 1076fd9..8a2320d 100644 --- a/Airbus/Drawnings/DrawningAirbus.cs +++ b/Airbus/Drawnings/DrawningAirbus.cs @@ -70,6 +70,13 @@ namespace ProjectAirbus.Drawnings }; } + // изменение границы поля, когда закрываем конфиг + public void ChangeBordersPicture(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + } + public void SetPosition(int x, int y) { if (x >= _pictureWidth || y >= _pictureHeight) diff --git a/Airbus/Entities/EntityAirbus.cs b/Airbus/Entities/EntityAirbus.cs index 16bf834..aa64c9b 100644 --- a/Airbus/Entities/EntityAirbus.cs +++ b/Airbus/Entities/EntityAirbus.cs @@ -20,5 +20,10 @@ namespace ProjectAirbus.Entities Weight = weight; BodyColor = bodyColor; } + + public void ChangeBodyColor(Color bodyColor) + { + BodyColor = bodyColor; + } } } diff --git a/Airbus/Entities/EntityPlane.cs b/Airbus/Entities/EntityPlane.cs index 3273514..b50c6ab 100644 --- a/Airbus/Entities/EntityPlane.cs +++ b/Airbus/Entities/EntityPlane.cs @@ -19,5 +19,10 @@ namespace ProjectAirbus.Entities IsCompartment = isCompartment; IsAdditionalEngine = isAdditionalEngine; } + + public void ChangeColorAdditional(Color additionalColor) + { + AdditionalColor = additionalColor; + } } } diff --git a/Airbus/FormAirbusCollection.cs b/Airbus/FormAirbusCollection.cs index 9df28bd..e039902 100644 --- a/Airbus/FormAirbusCollection.cs +++ b/Airbus/FormAirbusCollection.cs @@ -78,6 +78,13 @@ namespace ProjectAirbus // добавить самолёт в набор private void buttonAddAirbus_Click(object sender, EventArgs e) + { + var formAirbusConfig = new FormAirbusConfig(); + formAirbusConfig.AddEvent(AddAirbusInSet); + formAirbusConfig.Show(); + } + + private void AddAirbusInSet(DrawningAirbus _airbus) { if (listBoxStorages.SelectedIndex == -1) { @@ -89,18 +96,16 @@ namespace ProjectAirbus { return; } - FormPlane form = new(); - if (form.ShowDialog() == DialogResult.OK) + // меняем границы после закрытия конфига + _airbus.ChangeBordersPicture(Width, Height); + if (obj + _airbus != -1) { - if (obj + form.SelectedAirbus != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowAirbus(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowAirbus(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } diff --git a/Airbus/FormAirbusConfig.Designer.cs b/Airbus/FormAirbusConfig.Designer.cs new file mode 100644 index 0000000..33aa4d3 --- /dev/null +++ b/Airbus/FormAirbusConfig.Designer.cs @@ -0,0 +1,357 @@ +namespace ProjectAirbus +{ + partial class FormAirbusConfig + { + /// + /// 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(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + checkBoxAdditionalEngine = new CheckBox(); + checkBoxCompartment = new CheckBox(); + labelWeight = new Label(); + labelSpeed = new Label(); + groupBoxColors = new GroupBox(); + panelSilver = new Panel(); + panelOrange = new Panel(); + panelWhite = new Panel(); + panelGreen = new Panel(); + panelViolet = new Panel(); + panelBlue = new Panel(); + panelYellow = new Panel(); + labelComplexObject = new Label(); + labelSimpleObject = new Label(); + panelRed = new Panel(); + buttonOk = new Button(); + buttonCancel = new Button(); + pictureBoxObject = new PictureBox(); + labelBodyColor = new Label(); + labelAdditionalColor = new Label(); + panelObject = new Panel(); + groupBoxConfig.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(checkBoxAdditionalEngine); + groupBoxConfig.Controls.Add(checkBoxCompartment); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Location = new Point(24, 16); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(620, 243); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(106, 88); + 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(79, 27); + numericUpDownWeight.TabIndex = 7; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(106, 41); + 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(79, 27); + numericUpDownSpeed.TabIndex = 6; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // checkBoxAdditionalEngine + // + checkBoxAdditionalEngine.AutoSize = true; + checkBoxAdditionalEngine.Location = new Point(22, 151); + checkBoxAdditionalEngine.Name = "checkBoxAdditionalEngine"; + checkBoxAdditionalEngine.Size = new Size(204, 24); + checkBoxAdditionalEngine.TabIndex = 4; + checkBoxAdditionalEngine.Text = "Добавить доп. двигатель"; + checkBoxAdditionalEngine.UseVisualStyleBackColor = true; + // + // checkBoxCompartment + // + checkBoxCompartment.AutoSize = true; + checkBoxCompartment.Location = new Point(22, 186); + checkBoxCompartment.Name = "checkBoxCompartment"; + checkBoxCompartment.Size = new Size(243, 24); + checkBoxCompartment.TabIndex = 3; + checkBoxCompartment.Text = "Добавить пассажирский отсек"; + checkBoxCompartment.UseVisualStyleBackColor = true; + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(22, 95); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(36, 20); + labelWeight.TabIndex = 2; + labelWeight.Text = "Вес:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(22, 43); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(80, 20); + labelSpeed.TabIndex = 1; + labelSpeed.Text = "Скорость: "; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelSilver); + groupBoxColors.Controls.Add(panelOrange); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelViolet); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(labelComplexObject); + groupBoxColors.Controls.Add(labelSimpleObject); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(310, 21); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(279, 212); + groupBoxColors.TabIndex = 0; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelSilver + // + panelSilver.BackColor = Color.Silver; + panelSilver.Location = new Point(148, 96); + panelSilver.Name = "panelSilver"; + panelSilver.Size = new Size(40, 40); + panelSilver.TabIndex = 3; + // + // panelOrange + // + panelOrange.BackColor = Color.DarkOrange; + panelOrange.Location = new Point(204, 96); + panelOrange.Name = "panelOrange"; + panelOrange.Size = new Size(40, 40); + panelOrange.TabIndex = 3; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(93, 96); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(40, 40); + panelWhite.TabIndex = 3; + // + // panelGreen + // + panelGreen.BackColor = Color.LimeGreen; + panelGreen.Location = new Point(38, 96); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(40, 40); + panelGreen.TabIndex = 3; + // + // panelViolet + // + panelViolet.BackColor = Color.MediumVioletRed; + panelViolet.Location = new Point(204, 43); + panelViolet.Name = "panelViolet"; + panelViolet.Size = new Size(40, 40); + panelViolet.TabIndex = 3; + // + // panelBlue + // + panelBlue.BackColor = Color.MediumBlue; + panelBlue.Location = new Point(148, 43); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(40, 40); + panelBlue.TabIndex = 3; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(93, 43); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(40, 40); + panelYellow.TabIndex = 3; + // + // labelComplexObject + // + labelComplexObject.BorderStyle = BorderStyle.FixedSingle; + labelComplexObject.Location = new Point(148, 157); + labelComplexObject.Name = "labelComplexObject"; + labelComplexObject.RightToLeft = RightToLeft.No; + labelComplexObject.Size = new Size(120, 38); + labelComplexObject.TabIndex = 4; + labelComplexObject.Text = "Продвинутый"; + labelComplexObject.TextAlign = ContentAlignment.MiddleCenter; + labelComplexObject.MouseDown += labelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(14, 157); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(120, 38); + labelSimpleObject.TabIndex = 3; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelObject_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(38, 43); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(40, 40); + panelRed.TabIndex = 2; + // + // buttonOk + // + buttonOk.Location = new Point(666, 212); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(107, 43); + buttonOk.TabIndex = 0; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += buttonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(796, 212); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(107, 43); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(18, 55); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(227, 109); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(18, 9); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(107, 38); + labelBodyColor.TabIndex = 2; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += labelBodyColor_DragDrop; + labelBodyColor.DragEnter += labelColor_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(138, 9); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(107, 38); + labelAdditionalColor.TabIndex = 3; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Location = new Point(650, 27); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(264, 171); + panelObject.TabIndex = 2; + panelObject.DragDrop += panelObject_DragDrop; + panelObject.DragEnter += panelObject_DragEnter; + // + // FormAirbusConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(952, 283); + Controls.Add(panelObject); + Controls.Add(groupBoxConfig); + Controls.Add(buttonOk); + Controls.Add(buttonCancel); + Name = "FormAirbusConfig"; + Text = "Конструирование самолёта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private CheckBox checkBoxAdditionalEngine; + private CheckBox checkBoxCompartment; + private Label labelWeight; + private Label labelSpeed; + private GroupBox groupBoxColors; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Panel panelRed; + private Button buttonCancel; + private Button buttonOk; + private Label labelComplexObject; + private Label labelSimpleObject; + private Label labelAdditionalColor; + private Label labelBodyColor; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Panel panelSilver; + private Panel panelOrange; + private Panel panelWhite; + private Panel panelGreen; + private Panel panelViolet; + private Panel panelBlue; + private Panel panelYellow; + } +} \ No newline at end of file diff --git a/Airbus/FormAirbusConfig.cs b/Airbus/FormAirbusConfig.cs new file mode 100644 index 0000000..eb1d7fb --- /dev/null +++ b/Airbus/FormAirbusConfig.cs @@ -0,0 +1,157 @@ +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 ProjectAirbus.Drawnings; +using ProjectAirbus.Entities; + +namespace ProjectAirbus +{ + public partial class FormAirbusConfig : Form + { + // выбранный самолёт + DrawningAirbus? _airbus = null; + + // событие + private event Action EventAddAirbus; + // конструктор + public FormAirbusConfig() + { + InitializeComponent(); + panelRed.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelOrange.MouseDown += PanelColor_MouseDown; + panelViolet.MouseDown += PanelColor_MouseDown; + panelSilver.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + + buttonCancel.Click += (sender, e) => Close(); + } + + // добавить событие + public void AddEvent(Action ev) + { + if (EventAddAirbus == null) + { + EventAddAirbus = ev; + } + else + { + EventAddAirbus += ev; + } + } + + // цвета + private void labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + // перекрашиваем базовый + private void labelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_airbus == null) + return; + + Color bodyColor = (Color)e.Data?.GetData(typeof(Color)); + _airbus.EntityAirbus.ChangeBodyColor(bodyColor); + DrawAirbus(); + } + + // перекрашиваем доп + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_airbus == null) + return; + + Color addColor = (Color)e.Data?.GetData(typeof(Color)); + if (_airbus is DrawningPlane) + { + EntityPlane _plane = _airbus.EntityAirbus as EntityPlane; + _plane.ChangeColorAdditional(addColor); + } + else + { + MessageBox.Show("Нельзя задать доп. цвет обычному самолёту"); + } + DrawAirbus(); + } + + // объект + private void panelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + // передаём информацию при нажатии на label + private void labelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + // что делаем при приеме информации + private void panelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _airbus = new DrawningAirbus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + Color.White, pictureBoxObject.Width, pictureBoxObject.Height); + break; + case "labelComplexObject": + _airbus = new DrawningPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + Color.White, Color.Black, checkBoxCompartment.Checked, checkBoxAdditionalEngine.Checked, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawAirbus(); + } + + // добавить самолёт + private void buttonOk_Click(object sender, EventArgs e) + { + if (_airbus == null) + return; + + EventAddAirbus?.Invoke(_airbus); + Close(); + } + + // отрисовать самолёт + private void DrawAirbus() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _airbus?.SetPosition(5, 5); + _airbus?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + } +} \ No newline at end of file diff --git a/Airbus/FormAirbusConfig.resx b/Airbus/FormAirbusConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Airbus/FormAirbusConfig.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