From f9a3d57a1771af1c27db0c225732e9b62185250b Mon Sep 17 00:00:00 2001 From: Extrimal Date: Tue, 14 Nov 2023 22:55:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D1=83=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=20=D0=BF=D1=83=D0=BF=D0=B5=D1=80=20=D0=B7=D0=B0=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=88=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20laba5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/DrawningAircraft.cs | 4 +- .../AircraftCarrier/EntityAircraft.cs | 2 +- .../AircraftCarrier/EntityAircraftCarrier.cs | 2 +- .../AircraftCarrier/FormAircraftCollection.cs | 30 +- .../FormAircraftConfig.Designer.cs | 353 ++++++++++++++++++ .../AircraftCarrier/FormAircraftConfig.cs | 130 +++++++ .../AircraftCarrier/FormAircraftConfig.resx | 120 ++++++ 7 files changed, 626 insertions(+), 15 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/FormAircraftConfig.Designer.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormAircraftConfig.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormAircraftConfig.resx diff --git a/AircraftCarrier/AircraftCarrier/DrawningAircraft.cs b/AircraftCarrier/AircraftCarrier/DrawningAircraft.cs index 4e9190b..eff265b 100644 --- a/AircraftCarrier/AircraftCarrier/DrawningAircraft.cs +++ b/AircraftCarrier/AircraftCarrier/DrawningAircraft.cs @@ -13,9 +13,9 @@ namespace AircraftCarrier.DrawningObjects /// Класс-сущность public EntityAircraft? EntityAircraft { get; protected set; } /// Ширина окна - private int _pictureWidth; + public int _pictureWidth; /// Высота окна - private int _pictureHeight; + public int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _AircraftWidth = 164; diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraft.cs b/AircraftCarrier/AircraftCarrier/EntityAircraft.cs index c6223e7..4b16863 100644 --- a/AircraftCarrier/AircraftCarrier/EntityAircraft.cs +++ b/AircraftCarrier/AircraftCarrier/EntityAircraft.cs @@ -13,7 +13,7 @@ namespace AircraftCarrier.Entities /// Вес public double Weight { get; private set; } /// Основной цвет - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public double Step => (double)Speed * 100 / Weight; /// Конструктор с параметрами /// Скорость diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs index 51ef381..5021b66 100644 --- a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -9,7 +9,7 @@ namespace AircraftCarrier.Entities public class EntityAircraftCarrier : EntityAircraft { /// Дополнительный цвет (для опциональных элементов) - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } /// Признак (опция) наличия кабины public bool Cabin { get; private set; } /// Признак (опция) наличия взлетной полосы diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs index 61817b1..90b6a67 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs @@ -68,6 +68,18 @@ namespace AircraftCarrier } private void ButtonAddAircraft_Click(object sender, EventArgs e) { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var formMonorailConfig = new FormAircraftConfig(); + formMonorailConfig.AddEvent(AddAircraft); + formMonorailConfig.Show(); + } + private void AddAircraft(DrawningAircraft aircraft) + { + aircraft._pictureHeight = pictureBoxCollection.Height; + aircraft._pictureWidth = pictureBoxCollection.Width; if (listBoxStorage.SelectedIndex == -1) { return; @@ -77,18 +89,14 @@ namespace AircraftCarrier { return; } - FormAircraftCarrier form = new(); - if (form.ShowDialog() == DialogResult.OK) + if (obj + aircraft != -1) { - if (obj + form.SelectedAircraft != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowAircrafts(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowAircrafts(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } private void ButtonRemoveAircraft_Click(object sender, EventArgs e) diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftConfig.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftConfig.Designer.cs new file mode 100644 index 0000000..58a911c --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftConfig.Designer.cs @@ -0,0 +1,353 @@ +namespace AircraftCarrier +{ + partial class FormAircraftConfig + { + /// + /// 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() + { + groupBoxParameters = new GroupBox(); + panelColor = new Panel(); + panelRed = new Panel(); + panelPurple = new Panel(); + panelGreen = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelBlue = new Panel(); + panelYellow = new Panel(); + panelWhite = new Panel(); + labelHardObject = new Label(); + labelSimpleObject = new Label(); + checkBoxCabin = new CheckBox(); + checkBoxRunWay = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label_Weight = new Label(); + label_Speed = new Label(); + pictureBoxObject = new PictureBox(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelMainColor = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + groupBoxParameters.SuspendLayout(); + panelColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxParameters + // + groupBoxParameters.Controls.Add(panelColor); + groupBoxParameters.Controls.Add(labelHardObject); + groupBoxParameters.Controls.Add(labelSimpleObject); + groupBoxParameters.Controls.Add(checkBoxCabin); + groupBoxParameters.Controls.Add(checkBoxRunWay); + groupBoxParameters.Controls.Add(numericUpDownWeight); + groupBoxParameters.Controls.Add(numericUpDownSpeed); + groupBoxParameters.Controls.Add(label_Weight); + groupBoxParameters.Controls.Add(label_Speed); + groupBoxParameters.Location = new Point(12, 7); + groupBoxParameters.Name = "groupBoxParameters"; + groupBoxParameters.Size = new Size(549, 304); + groupBoxParameters.TabIndex = 0; + groupBoxParameters.TabStop = false; + groupBoxParameters.Text = "Параметры"; + // + // panelColor + // + panelColor.Controls.Add(panelRed); + panelColor.Controls.Add(panelPurple); + panelColor.Controls.Add(panelGreen); + panelColor.Controls.Add(panelBlack); + panelColor.Controls.Add(panelGray); + panelColor.Controls.Add(panelBlue); + panelColor.Controls.Add(panelYellow); + panelColor.Controls.Add(panelWhite); + panelColor.Location = new Point(282, 55); + panelColor.Name = "panelColor"; + panelColor.Size = new Size(250, 140); + panelColor.TabIndex = 10; + panelColor.MouseDown += panelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(15, 14); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(38, 44); + panelRed.TabIndex = 0; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(195, 83); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(38, 44); + panelPurple.TabIndex = 6; + // + // panelGreen + // + panelGreen.BackColor = Color.Lime; + panelGreen.Location = new Point(73, 14); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(38, 44); + panelGreen.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(137, 83); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(38, 44); + panelBlack.TabIndex = 5; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(73, 83); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(38, 44); + panelGray.TabIndex = 4; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(137, 14); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(38, 44); + panelBlue.TabIndex = 2; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(195, 14); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(38, 44); + panelYellow.TabIndex = 0; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(15, 83); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(38, 44); + panelWhite.TabIndex = 3; + // + // labelHardObject + // + labelHardObject.BorderStyle = BorderStyle.FixedSingle; + labelHardObject.Location = new Point(419, 228); + labelHardObject.Name = "labelHardObject"; + labelHardObject.Size = new Size(113, 41); + labelHardObject.TabIndex = 9; + labelHardObject.Text = "Продвинутый"; + labelHardObject.TextAlign = ContentAlignment.MiddleCenter; + labelHardObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(297, 228); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(113, 41); + labelSimpleObject.TabIndex = 8; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // checkBoxCabin + // + checkBoxCabin.AutoSize = true; + checkBoxCabin.Location = new Point(18, 245); + checkBoxCabin.Name = "checkBoxCabin"; + checkBoxCabin.Size = new Size(258, 24); + checkBoxCabin.TabIndex = 5; + checkBoxCabin.Text = "Обозначение рубки управления"; + checkBoxCabin.UseVisualStyleBackColor = true; + // + // checkBoxRunWay + // + checkBoxRunWay.AutoSize = true; + checkBoxRunWay.Location = new Point(18, 189); + checkBoxRunWay.Name = "checkBoxRunWay"; + checkBoxRunWay.Size = new Size(251, 24); + checkBoxRunWay.TabIndex = 4; + checkBoxRunWay.Text = "Обозначение взлетной полосы"; + checkBoxRunWay.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(117, 109); + 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(87, 27); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(117, 53); + 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(87, 27); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label_Weight + // + label_Weight.AutoSize = true; + label_Weight.Location = new Point(18, 111); + label_Weight.Name = "label_Weight"; + label_Weight.Size = new Size(36, 20); + label_Weight.TabIndex = 1; + label_Weight.Text = "Вес:"; + // + // label_Speed + // + label_Speed.AutoSize = true; + label_Speed.Location = new Point(18, 55); + label_Speed.Name = "label_Speed"; + label_Speed.Size = new Size(76, 20); + label_Speed.TabIndex = 0; + label_Speed.Text = "Скорость:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(30, 55); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(249, 169); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelMainColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(567, 21); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(303, 242); + panelObject.TabIndex = 2; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(167, 13); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(112, 39); + labelAdditionalColor.TabIndex = 3; + labelAdditionalColor.Text = "Доп. Цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // labelMainColor + // + labelMainColor.BorderStyle = BorderStyle.FixedSingle; + labelMainColor.Location = new Point(30, 12); + labelMainColor.Name = "labelMainColor"; + labelMainColor.Size = new Size(113, 39); + labelMainColor.TabIndex = 2; + labelMainColor.Text = "Цвет"; + labelMainColor.TextAlign = ContentAlignment.MiddleCenter; + labelMainColor.DragDrop += labelMainColor_DragDrop; + labelMainColor.DragEnter += labelColor_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(597, 282); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 29); + buttonAdd.TabIndex = 3; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(734, 282); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 29); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormAircraftConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(882, 323); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(panelObject); + Controls.Add(groupBoxParameters); + Name = "FormAircraftConfig"; + Text = "FormAircraftConfig"; + groupBoxParameters.ResumeLayout(false); + groupBoxParameters.PerformLayout(); + panelColor.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 groupBoxParameters; + private Label label_Weight; + private Label label_Speed; + private CheckBox checkBoxCabin; + private CheckBox checkBoxRunWay; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Label labelHardObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelMainColor; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelColor; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftConfig.cs b/AircraftCarrier/AircraftCarrier/FormAircraftConfig.cs new file mode 100644 index 0000000..513b194 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftConfig.cs @@ -0,0 +1,130 @@ +using AircraftCarrier.DrawningObjects; +using AircraftCarrier.Entities; +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 AircraftCarrier +{ + public partial class FormAircraftConfig : Form + { + /// Переменная-выбранная машина + DrawningAircraft? _Aircraft = null; + /// Событие + private event Action? EventAddAircraft; + /// Конструктор + public FormAircraftConfig() + { + InitializeComponent(); + panelBlack.MouseDown += panelColor_MouseDown; + panelPurple.MouseDown += panelColor_MouseDown; + panelGray.MouseDown += panelColor_MouseDown; + panelGreen.MouseDown += panelColor_MouseDown; + panelRed.MouseDown += panelColor_MouseDown; + panelWhite.MouseDown += panelColor_MouseDown; + panelYellow.MouseDown += panelColor_MouseDown; + panelBlue.MouseDown += panelColor_MouseDown; + + buttonCancel.Click += (s, e) => Close(); + } + public void AddEvent(Action ev) + { + if (EventAddAircraft == null) + { + EventAddAircraft = ev; + } + else + { + EventAddAircraft += ev; + } + } + + private void DrawAircraft() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _Aircraft?.SetPosition(5, 5); + _Aircraft?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// Передаем информацию при нажатии на Label + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, + DragDropEffects.Move | DragDropEffects.Copy); + } + private void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + 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 labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _Aircraft = new DrawningAircraft((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelHardObject": + _Aircraft = new DrawningAircraftCarrier((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRunWay.Checked, + checkBoxCabin.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawAircraft(); + } + private void labelMainColor_DragDrop(object sender, DragEventArgs e) + { + if (_Aircraft == null) + return; + _Aircraft.EntityAircraft.BodyColor = (Color)e.Data?.GetData(typeof(Color)); + DrawAircraft(); + } + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_Aircraft == null || _Aircraft is not DrawningAircraftCarrier) + return; + ((EntityAircraftCarrier)_Aircraft.EntityAircraft).AdditionalColor = (Color)e.Data?.GetData(typeof(Color)); + DrawAircraft(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddAircraft?.Invoke(_Aircraft); + Close(); + } + + + } +} diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftConfig.resx b/AircraftCarrier/AircraftCarrier/FormAircraftConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftConfig.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