diff --git a/AirBomber/AirBomber/DrawingAirBomber.cs b/AirBomber/AirBomber/DrawingAirBomber.cs index aec5907..e4fe080 100644 --- a/AirBomber/AirBomber/DrawingAirBomber.cs +++ b/AirBomber/AirBomber/DrawingAirBomber.cs @@ -122,6 +122,14 @@ namespace AirBomber.DrawingObjects } + public void setAddColor(Color color) + { + if (EntityWarAirplane is EntityAirBomber airBomber) + { + airBomber.setAddColor(color); + } + + } } } diff --git a/AirBomber/AirBomber/DrawingWarAirplane.cs b/AirBomber/AirBomber/DrawingWarAirplane.cs index 95e67e0..2e850e2 100644 --- a/AirBomber/AirBomber/DrawingWarAirplane.cs +++ b/AirBomber/AirBomber/DrawingWarAirplane.cs @@ -233,5 +233,9 @@ namespace AirBomber.DrawingObjects } + public void setColor(Color color) + { + EntityWarAirplane.setColor(color); + } } } diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index 8ff5cab..f2b404f 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -15,5 +15,9 @@ namespace AirBomber.Entities FuelTank = fuelTank; Bombs = bombs; } + public void setAddColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/AirBomber/AirBomber/EntityWarAirplane.cs b/AirBomber/AirBomber/EntityWarAirplane.cs index 0f1fe50..d30e5cf 100644 --- a/AirBomber/AirBomber/EntityWarAirplane.cs +++ b/AirBomber/AirBomber/EntityWarAirplane.cs @@ -18,5 +18,10 @@ namespace AirBomber.Entities Weight = weight; BodyColor = bodyColor; } + + public void setColor(Color color) + { + BodyColor = color; + } } } diff --git a/AirBomber/AirBomber/FormWarAirplaneCollection.cs b/AirBomber/AirBomber/FormWarAirplaneCollection.cs index c13e9f4..9cf3757 100644 --- a/AirBomber/AirBomber/FormWarAirplaneCollection.cs +++ b/AirBomber/AirBomber/FormWarAirplaneCollection.cs @@ -84,14 +84,21 @@ namespace AirBomber return; } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) { + return; } - FormAirBomber form = new(); - if (form.ShowDialog() == DialogResult.OK) + + + FormWarAirplaneConfig form = new FormWarAirplaneConfig(); + form.Show(); + Action? warAirplaneDelegate = new((m) => { - if (obj + form.SelectedWarAirplane) + bool q = obj + m; + + if (q == true) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowWarAirplane(); @@ -100,7 +107,13 @@ namespace AirBomber { MessageBox.Show("Не удалось добавить объект"); } - } + }); + + Action? ColorDelegate = new((m) => + { + MessageBox.Show(m.ToString()); + }); + form.AddEvent(warAirplaneDelegate); } private void ButtonRemoveWarAirplane_Click(object sender, EventArgs e) { diff --git a/AirBomber/AirBomber/FormWarAirplaneConfig.Designer.cs b/AirBomber/AirBomber/FormWarAirplaneConfig.Designer.cs new file mode 100644 index 0000000..44f7fe5 --- /dev/null +++ b/AirBomber/AirBomber/FormWarAirplaneConfig.Designer.cs @@ -0,0 +1,370 @@ +namespace AirBomber +{ + partial class FormWarAirplaneConfig + { + /// + /// 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(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + checkBoxBombs = new CheckBox(); + checkBoxFuelTank = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + groupBoxObject = new GroupBox(); + panelObject = new Panel(); + pictureBoxObject = new PictureBox(); + labelAddColor = new Label(); + labelColor = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + groupBoxParameters.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + groupBoxColors.SuspendLayout(); + groupBoxObject.SuspendLayout(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxParameters + // + groupBoxParameters.Controls.Add(labelModifiedObject); + groupBoxParameters.Controls.Add(labelSimpleObject); + groupBoxParameters.Controls.Add(checkBoxBombs); + groupBoxParameters.Controls.Add(checkBoxFuelTank); + groupBoxParameters.Controls.Add(numericUpDownWeight); + groupBoxParameters.Controls.Add(numericUpDownSpeed); + groupBoxParameters.Controls.Add(labelWeight); + groupBoxParameters.Controls.Add(labelSpeed); + groupBoxParameters.Controls.Add(groupBoxColors); + groupBoxParameters.Location = new Point(11, 12); + groupBoxParameters.Name = "groupBoxParameters"; + groupBoxParameters.Size = new Size(515, 300); + groupBoxParameters.TabIndex = 0; + groupBoxParameters.TabStop = false; + groupBoxParameters.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(385, 192); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(90, 50); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(251, 192); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(90, 50); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // checkBoxBombs + // + checkBoxBombs.AutoSize = true; + checkBoxBombs.Location = new Point(23, 155); + checkBoxBombs.Name = "checkBoxBombs"; + checkBoxBombs.Size = new Size(65, 19); + checkBoxBombs.TabIndex = 6; + checkBoxBombs.Text = "Бомбы"; + checkBoxBombs.UseVisualStyleBackColor = true; + // + // checkBoxFuelTank + // + checkBoxFuelTank.AutoSize = true; + checkBoxFuelTank.Location = new Point(23, 120); + checkBoxFuelTank.Name = "checkBoxFuelTank"; + checkBoxFuelTank.Size = new Size(210, 19); + checkBoxFuelTank.TabIndex = 5; + checkBoxFuelTank.Text = "Дополнительный топливный бак"; + checkBoxFuelTank.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(105, 70); + 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(120, 23); + numericUpDownWeight.TabIndex = 4; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(105, 37); + 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(120, 23); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(25, 72); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(29, 15); + labelWeight.TabIndex = 2; + labelWeight.Text = "Вес:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(25, 39); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(62, 15); + labelSpeed.TabIndex = 1; + labelSpeed.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(panelBlue); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(240, 24); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(248, 150); + groupBoxColors.TabIndex = 0; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(190, 85); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(45, 45); + panelPurple.TabIndex = 7; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(132, 85); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(45, 45); + panelBlack.TabIndex = 6; + // + // panelGray + // + panelGray.BackColor = Color.FromArgb(64, 64, 64); + panelGray.Location = new Point(72, 85); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(45, 45); + panelGray.TabIndex = 5; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(11, 85); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(45, 45); + panelWhite.TabIndex = 4; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(190, 24); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(45, 45); + panelYellow.TabIndex = 3; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(132, 24); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(45, 45); + panelBlue.TabIndex = 2; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(72, 24); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(45, 45); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(11, 24); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(45, 45); + panelRed.TabIndex = 0; + // + // groupBoxObject + // + groupBoxObject.Controls.Add(panelObject); + groupBoxObject.Location = new Point(532, 11); + groupBoxObject.Name = "groupBoxObject"; + groupBoxObject.Size = new Size(256, 268); + groupBoxObject.TabIndex = 1; + groupBoxObject.TabStop = false; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelAddColor); + panelObject.Controls.Add(labelColor); + panelObject.Location = new Point(6, 22); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(244, 240); + panelObject.TabIndex = 3; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(8, 65); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(224, 172); + pictureBoxObject.TabIndex = 2; + pictureBoxObject.TabStop = false; + // + // labelAddColor + // + labelAddColor.AllowDrop = true; + labelAddColor.BorderStyle = BorderStyle.FixedSingle; + labelAddColor.Location = new Point(123, 16); + labelAddColor.Name = "labelAddColor"; + labelAddColor.Size = new Size(109, 40); + labelAddColor.TabIndex = 1; + labelAddColor.Text = "Дополнительный цвет"; + labelAddColor.TextAlign = ContentAlignment.MiddleCenter; + labelAddColor.DragDrop += LabelAddColor_DragDrop; + labelAddColor.DragEnter += LabelColor_DragEnter; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(8, 16); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(109, 40); + labelColor.TabIndex = 0; + labelColor.Text = "Основной цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += LabelColor_DragDrop; + labelColor.DragEnter += LabelColor_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(538, 285); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(105, 29); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(687, 285); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(97, 27); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormWarAirplaneConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 336); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxObject); + Controls.Add(groupBoxParameters); + Name = "FormWarAirplaneConfig"; + Text = "FormWarAirplaneConfig"; + groupBoxParameters.ResumeLayout(false); + groupBoxParameters.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + groupBoxColors.ResumeLayout(false); + groupBoxObject.ResumeLayout(false); + panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxParameters; + private Label labelSpeed; + private GroupBox groupBoxColors; + private GroupBox groupBoxObject; + private Label labelModifiedObject; + private Label labelSimpleObject; + private CheckBox checkBoxBombs; + private CheckBox checkBoxFuelTank; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Label labelAddColor; + private Label labelColor; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormWarAirplaneConfig.cs b/AirBomber/AirBomber/FormWarAirplaneConfig.cs new file mode 100644 index 0000000..92aa3e4 --- /dev/null +++ b/AirBomber/AirBomber/FormWarAirplaneConfig.cs @@ -0,0 +1,149 @@ +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 AirBomber.DrawingObjects; + +namespace AirBomber +{ + public partial class FormWarAirplaneConfig : Form + { + DrawingWarAirplane? _WarAirplane = null; + public event Action? EventAddWarAirplane; + + public FormWarAirplaneConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + + private void DrawWarAirplane() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _WarAirplane?.SetPosition(5, 5); + _WarAirplane?.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) + { + + if (_WarAirplane is DrawingWarAirplane WarAirplane) + { + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _WarAirplane.setColor((Color)e.Data.GetData(typeof(Color))); + } + DrawWarAirplane(); + } + + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + + if (_WarAirplane is DrawingAirBomber WarAirplane) + { + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + ((DrawingAirBomber)_WarAirplane).setAddColor((Color)e.Data.GetData(typeof(Color))); + } + DrawWarAirplane(); + } + + + 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": + _WarAirplane = new DrawingWarAirplane((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + labelColor.BackColor = Color.White; + labelAddColor.BackColor = Color.Transparent; + break; + case "labelModifiedObject": + _WarAirplane = new DrawingAirBomber((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxFuelTank.Checked, + checkBoxBombs.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + labelColor.BackColor = Color.White; + labelAddColor.BackColor = Color.Black; + break; + } + + DrawWarAirplane(); + } + + public void AddEvent(Action ev) + { + if (EventAddWarAirplane == null) + { + EventAddWarAirplane = ev; + } + else + { + EventAddWarAirplane += ev; + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddWarAirplane?.Invoke(_WarAirplane); + Close(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + } +} diff --git a/AirBomber/AirBomber/FormWarAirplaneConfig.resx b/AirBomber/AirBomber/FormWarAirplaneConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AirBomber/AirBomber/FormWarAirplaneConfig.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