From 5920c92ecaf91913cb0d26fc8b625960ecee7ba0 Mon Sep 17 00:00:00 2001 From: DeerElk Date: Tue, 13 Feb 2024 23:27:44 +0400 Subject: [PATCH] lab5 --- .../AircraftCarrier/EntityAircraftCarrier.cs | 1 + .../AircraftCarrier/EntityWarship.cs | 1 + .../AircraftCarrier/FormWarshipCollection.cs | 11 +- .../FormWarshipConfig.Designer.cs | 370 ++++++++++++++++++ .../AircraftCarrier/FormWarshipConfig.cs | 153 ++++++++ .../AircraftCarrier/FormWarshipConfig.resx | 120 ++++++ 6 files changed, 651 insertions(+), 5 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/FormWarshipConfig.Designer.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormWarshipConfig.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormWarshipConfig.resx diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs index 9a86008..f12c402 100644 --- a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -40,5 +40,6 @@ namespace ProjectAircraftCarrier.Entities Runway = runway; Cabin = cabin; } + public void ChangeAddColor(Color color) { AdditionalColor = color; } } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/EntityWarship.cs b/AircraftCarrier/AircraftCarrier/EntityWarship.cs index f946d08..f6b2d7a 100644 --- a/AircraftCarrier/AircraftCarrier/EntityWarship.cs +++ b/AircraftCarrier/AircraftCarrier/EntityWarship.cs @@ -39,5 +39,6 @@ namespace ProjectAircraftCarrier.Entities Weight = weight; BodyColor = bodyColor; } + public void ChangeColor(Color color) { BodyColor = color; } } } diff --git a/AircraftCarrier/AircraftCarrier/FormWarshipCollection.cs b/AircraftCarrier/AircraftCarrier/FormWarshipCollection.cs index 7b4201e..db5f70d 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarshipCollection.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarshipCollection.cs @@ -109,10 +109,10 @@ namespace ProjectAircraftCarrier { return; } - FormAircraftCarrier form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedWarship) + FormWarshipConfig form = new(); + form.Show(); + Action? warshipDelegate = new((warship) => { + if (obj + warship) { MessageBox.Show("Object added"); pictureBoxCollection.Image = obj.ShowWarships(); @@ -121,7 +121,8 @@ namespace ProjectAircraftCarrier { MessageBox.Show("Failed to add an object"); } - } + }); + form.AddEvent(warshipDelegate); } /// /// Удаление объекта из набора diff --git a/AircraftCarrier/AircraftCarrier/FormWarshipConfig.Designer.cs b/AircraftCarrier/AircraftCarrier/FormWarshipConfig.Designer.cs new file mode 100644 index 0000000..728fcdb --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormWarshipConfig.Designer.cs @@ -0,0 +1,370 @@ +namespace ProjectAircraftCarrier +{ + partial class FormWarshipConfig + { + /// + /// 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() + { + groupBoxCreationParameters = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + groupBoxCreationColors = new GroupBox(); + panelBlack = new Panel(); + panelWhite = new Panel(); + panelPurple = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + panelGray = new Panel(); + panelYellow = new Panel(); + checkBoxCabin = new CheckBox(); + checkBoxRunway = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + labelSpeed = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + pictureBoxObject = new PictureBox(); + panelObject = new Panel(); + labelAddColor = new Label(); + labelColor = new Label(); + buttonAddWarship = new Button(); + buttonCancel = new Button(); + groupBoxCreationParameters.SuspendLayout(); + groupBoxCreationColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxCreationParameters + // + groupBoxCreationParameters.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; + groupBoxCreationParameters.Controls.Add(labelModifiedObject); + groupBoxCreationParameters.Controls.Add(labelSimpleObject); + groupBoxCreationParameters.Controls.Add(groupBoxCreationColors); + groupBoxCreationParameters.Controls.Add(checkBoxCabin); + groupBoxCreationParameters.Controls.Add(checkBoxRunway); + groupBoxCreationParameters.Controls.Add(numericUpDownWeight); + groupBoxCreationParameters.Controls.Add(labelSpeed); + groupBoxCreationParameters.Controls.Add(numericUpDownSpeed); + groupBoxCreationParameters.Controls.Add(labelWeight); + groupBoxCreationParameters.Location = new Point(12, 12); + groupBoxCreationParameters.Name = "groupBoxCreationParameters"; + groupBoxCreationParameters.Size = new Size(684, 306); + groupBoxCreationParameters.TabIndex = 0; + groupBoxCreationParameters.TabStop = false; + groupBoxCreationParameters.Text = "Parameters"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(518, 229); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(140, 50); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Modified"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(358, 229); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(140, 50); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Simple"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBoxCreationColors + // + groupBoxCreationColors.Controls.Add(panelBlack); + groupBoxCreationColors.Controls.Add(panelWhite); + groupBoxCreationColors.Controls.Add(panelPurple); + groupBoxCreationColors.Controls.Add(panelBlue); + groupBoxCreationColors.Controls.Add(panelGreen); + groupBoxCreationColors.Controls.Add(panelRed); + groupBoxCreationColors.Controls.Add(panelGray); + groupBoxCreationColors.Controls.Add(panelYellow); + groupBoxCreationColors.Location = new Point(346, 24); + groupBoxCreationColors.Name = "groupBoxCreationColors"; + groupBoxCreationColors.Size = new Size(327, 190); + groupBoxCreationColors.TabIndex = 1; + groupBoxCreationColors.TabStop = false; + groupBoxCreationColors.Text = "Colors"; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(172, 110); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(60, 60); + panelBlack.TabIndex = 7; + panelBlack.MouseDown += PanelColor_MouseDown; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(12, 110); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(60, 60); + panelWhite.TabIndex = 6; + panelWhite.MouseDown += PanelColor_MouseDown; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(252, 110); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(60, 60); + panelPurple.TabIndex = 5; + panelPurple.MouseDown += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(172, 30); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(60, 60); + panelBlue.TabIndex = 4; + panelBlue.MouseDown += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(92, 30); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(60, 60); + panelGreen.TabIndex = 3; + panelGreen.MouseDown += PanelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(12, 30); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(60, 60); + panelRed.TabIndex = 2; + panelRed.MouseDown += PanelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(92, 110); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(60, 60); + panelGray.TabIndex = 1; + panelGray.MouseDown += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(252, 30); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(60, 60); + panelYellow.TabIndex = 0; + panelYellow.MouseDown += PanelColor_MouseDown; + // + // checkBoxCabin + // + checkBoxCabin.AutoSize = true; + checkBoxCabin.Location = new Point(25, 198); + checkBoxCabin.Name = "checkBoxCabin"; + checkBoxCabin.Size = new Size(272, 29); + checkBoxCabin.TabIndex = 6; + checkBoxCabin.Text = "Indication of cabin availability"; + checkBoxCabin.UseVisualStyleBackColor = true; + // + // checkBoxRunway + // + checkBoxRunway.AutoSize = true; + checkBoxRunway.Location = new Point(25, 145); + checkBoxRunway.Name = "checkBoxRunway"; + checkBoxRunway.Size = new Size(287, 29); + checkBoxRunway.TabIndex = 5; + checkBoxRunway.Text = "Indication of runway availability"; + checkBoxRunway.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(116, 85); + 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(180, 31); + numericUpDownWeight.TabIndex = 4; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(16, 43); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(66, 25); + labelSpeed.TabIndex = 1; + labelSpeed.Text = "Speed:"; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(116, 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(180, 31); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(17, 87); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(72, 25); + labelWeight.TabIndex = 2; + labelWeight.Text = "Weight:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(16, 70); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(331, 157); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right; + panelObject.Controls.Add(labelAddColor); + panelObject.Controls.Add(labelColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(708, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(366, 242); + panelObject.TabIndex = 2; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAddColor + // + labelAddColor.AllowDrop = true; + labelAddColor.Anchor = AnchorStyles.Top | AnchorStyles.Right; + labelAddColor.BorderStyle = BorderStyle.FixedSingle; + labelAddColor.Location = new Point(195, 13); + labelAddColor.Name = "labelAddColor"; + labelAddColor.Size = new Size(152, 50); + labelAddColor.TabIndex = 3; + labelAddColor.Text = "Add. color"; + labelAddColor.TextAlign = ContentAlignment.MiddleCenter; + labelAddColor.DragDrop += LabelAddColor_DragDrop; + labelAddColor.DragEnter += LabelColor_DragEnter; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.Anchor = AnchorStyles.Top | AnchorStyles.Right; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(16, 13); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(156, 50); + labelColor.TabIndex = 2; + labelColor.Text = "Color"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += LabelColor_DragDrop; + labelColor.DragEnter += LabelColor_DragEnter; + // + // buttonAddWarship + // + buttonAddWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonAddWarship.Location = new Point(724, 260); + buttonAddWarship.Name = "buttonAddWarship"; + buttonAddWarship.Size = new Size(156, 50); + buttonAddWarship.TabIndex = 4; + buttonAddWarship.Text = "Add"; + buttonAddWarship.UseVisualStyleBackColor = true; + buttonAddWarship.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(903, 260); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(152, 50); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormWarshipConfig + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1084, 322); + Controls.Add(buttonCancel); + Controls.Add(panelObject); + Controls.Add(buttonAddWarship); + Controls.Add(groupBoxCreationParameters); + Name = "FormWarshipConfig"; + Text = "Object creation"; + groupBoxCreationParameters.ResumeLayout(false); + groupBoxCreationParameters.PerformLayout(); + groupBoxCreationColors.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 groupBoxCreationParameters; + private Label labelSpeed; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private NumericUpDown numericUpDownWeight; + private GroupBox groupBoxCreationColors; + private CheckBox checkBoxCabin; + private CheckBox checkBoxRunway; + private Panel panelBlack; + private Panel panelWhite; + private Panel panelPurple; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private Panel panelGray; + private Panel panelYellow; + private Label labelModifiedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Button buttonAddWarship; + private Label labelAddColor; + private Label labelColor; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormWarshipConfig.cs b/AircraftCarrier/AircraftCarrier/FormWarshipConfig.cs new file mode 100644 index 0000000..285af62 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormWarshipConfig.cs @@ -0,0 +1,153 @@ +using ProjectAircraftCarrier.DrawingObjects; +using ProjectAircraftCarrier.Entities; + +namespace ProjectAircraftCarrier +{ + public partial class FormWarshipConfig : Form + { + /// + /// Переменная-выбранный военный корабль + /// + DrawingWarship? _warship = null; + private event Action? EventAddWarship; + /// + /// Конструктор + /// + public FormWarshipConfig() + { + 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(); + } + /// + /// Отрисовать военний корабль + /// + private void DrawWarship() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _warship?.SetPosition(5, 5); + _warship?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action? ev) + { + if (EventAddWarship == null) + { + EventAddWarship = ev; + } + else + { + EventAddWarship += ev; + } + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + 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 "labelSimpleObject": + _warship = new DrawingWarship( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + case "labelModifiedObject": + _warship = new DrawingAircraftCarrier( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, + Color.Black, checkBoxCabin.Checked, + checkBoxRunway.Checked, + pictureBoxObject.Width,pictureBoxObject.Height); + break; + } + DrawWarship(); + } + private void PanelColor_MouseDown(object? sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + /// + /// Добавление военного корабля + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_warship == null) + return; + EventAddWarship?.Invoke(_warship); + Close(); + } + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + if (_warship?.EntityWarship == null) + return; + Color bodyColor = (Color)e.Data.GetData(typeof(Color)); + _warship.EntityWarship.ChangeColor(bodyColor); + DrawWarship(); + } + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + if ((_warship?.EntityWarship == null) || (_warship is + DrawingAircraftCarrier == false)) + return; + Color additionalColor = (Color)e.Data.GetData(typeof(Color)); + ((EntityAircraftCarrier)_warship.EntityWarship).ChangeAddColor(additionalColor); + DrawWarship(); + } + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormWarshipConfig.resx b/AircraftCarrier/AircraftCarrier/FormWarshipConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormWarshipConfig.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