diff --git a/WarmlyShip/DrawningObjects/DrawningShip.cs b/WarmlyShip/DrawningObjects/DrawningShip.cs index bd54335..6ecbaae 100644 --- a/WarmlyShip/DrawningObjects/DrawningShip.cs +++ b/WarmlyShip/DrawningObjects/DrawningShip.cs @@ -224,5 +224,20 @@ namespace WarmlyShip.DrawningObjects Point point_8 = new Point(_startPosX + 131, _startPosY + 35); g.DrawLine(pen, point_7, point_8); } + + public void SetColor(Color color) + { + if (EntityShip == null) + { + return; + } + EntityShip.BodyColor = color; + } + + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + _pictureWidth = pictureBoxWidth; + _pictureHeight = pictureBoxHeight; + } } } \ No newline at end of file diff --git a/WarmlyShip/DrawningObjects/DrawningWarmlyShip.cs b/WarmlyShip/DrawningObjects/DrawningWarmlyShip.cs index b449df7..723ce5b 100644 --- a/WarmlyShip/DrawningObjects/DrawningWarmlyShip.cs +++ b/WarmlyShip/DrawningObjects/DrawningWarmlyShip.cs @@ -80,5 +80,10 @@ additionalColor, bool pipe, bool fuelCompartment, int width, int height) : g.DrawRectangle(pen, _startPosX + 70, _startPosY + 45, 20, 15); } } + + public void SetAddColor(Color color) + { + ((EntityWarmlyShip)EntityShip).AdditionalColor = color; + } } -} +} \ No newline at end of file diff --git a/WarmlyShip/Entities/EntityShip.cs b/WarmlyShip/Entities/EntityShip.cs index 26231f3..7d5f9d9 100644 --- a/WarmlyShip/Entities/EntityShip.cs +++ b/WarmlyShip/Entities/EntityShip.cs @@ -22,7 +22,7 @@ namespace WarmlyShip.Entities /// /// Основной цвет /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг перемещения корабля diff --git a/WarmlyShip/Entities/EntityWarmlyShip.cs b/WarmlyShip/Entities/EntityWarmlyShip.cs index e3994ab..b4127cc 100644 --- a/WarmlyShip/Entities/EntityWarmlyShip.cs +++ b/WarmlyShip/Entities/EntityWarmlyShip.cs @@ -14,7 +14,7 @@ namespace WarmlyShip.Entities /// /// Дополнительный цвет (для опциональных элементов) /// - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } /// /// Признак (опция) наличия труб /// diff --git a/WarmlyShip/FormShipCollection.cs b/WarmlyShip/FormShipCollection.cs index fb03af0..ecb63d3 100644 --- a/WarmlyShip/FormShipCollection.cs +++ b/WarmlyShip/FormShipCollection.cs @@ -118,19 +118,24 @@ namespace WarmlyShip { return; } - FormWarmlyShip form = new(); - if (form.ShowDialog() == DialogResult.OK) + + FormShipConfig form = new(); + form.Show(); + Action? shipDelegate = new((m) => { - if (obj + form.SelectedShip) + bool isAdditionSuccessful = (obj + m); + if (isAdditionSuccessful) { MessageBox.Show("Объект добавлен"); + m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); pictureBoxCollection.Image = obj.ShowShips(); } else { MessageBox.Show("Не удалось добавить объект"); } - } + }); + form.AddEvent(shipDelegate); } /// diff --git a/WarmlyShip/FormShipConfig.Designer.cs b/WarmlyShip/FormShipConfig.Designer.cs new file mode 100644 index 0000000..fafb78b --- /dev/null +++ b/WarmlyShip/FormShipConfig.Designer.cs @@ -0,0 +1,355 @@ +namespace WarmlyShip +{ + partial class FormShipConfig + { + /// + /// 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(); + groupBoxColor = new GroupBox(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlack = new Panel(); + panelBlue = new Panel(); + panelGray = new Panel(); + panelGreen = new Panel(); + panelWhite = new Panel(); + panelRed = new Panel(); + checkBoxFuelCompartment = new CheckBox(); + checkBoxPipe = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + panelObject = new Panel(); + pictureBoxObject = new PictureBox(); + labelExtraColor = new Label(); + labelColor = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + groupBoxParameters.SuspendLayout(); + groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxParameters + // + groupBoxParameters.Controls.Add(labelModifiedObject); + groupBoxParameters.Controls.Add(labelSimpleObject); + groupBoxParameters.Controls.Add(groupBoxColor); + groupBoxParameters.Controls.Add(checkBoxFuelCompartment); + groupBoxParameters.Controls.Add(checkBoxPipe); + groupBoxParameters.Controls.Add(numericUpDownWeight); + groupBoxParameters.Controls.Add(numericUpDownSpeed); + groupBoxParameters.Controls.Add(labelWeight); + groupBoxParameters.Controls.Add(labelSpeed); + groupBoxParameters.Location = new Point(12, 12); + groupBoxParameters.Name = "groupBoxParameters"; + groupBoxParameters.Size = new Size(407, 207); + groupBoxParameters.TabIndex = 0; + groupBoxParameters.TabStop = false; + groupBoxParameters.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(309, 150); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(88, 30); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(215, 150); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(88, 30); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + // + // groupBoxColor + // + groupBoxColor.Controls.Add(panelPurple); + groupBoxColor.Controls.Add(panelYellow); + groupBoxColor.Controls.Add(panelBlack); + groupBoxColor.Controls.Add(panelBlue); + groupBoxColor.Controls.Add(panelGray); + groupBoxColor.Controls.Add(panelGreen); + groupBoxColor.Controls.Add(panelWhite); + groupBoxColor.Controls.Add(panelRed); + groupBoxColor.Location = new Point(215, 22); + groupBoxColor.Name = "groupBoxColor"; + groupBoxColor.Size = new Size(183, 115); + groupBoxColor.TabIndex = 6; + groupBoxColor.TabStop = false; + groupBoxColor.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(138, 66); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(38, 38); + panelPurple.TabIndex = 5; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(138, 22); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(38, 38); + panelYellow.TabIndex = 4; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(94, 66); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(38, 38); + panelBlack.TabIndex = 3; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(94, 22); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(38, 38); + panelBlue.TabIndex = 2; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(50, 66); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(38, 38); + panelGray.TabIndex = 1; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(50, 22); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(38, 38); + panelGreen.TabIndex = 0; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(6, 66); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(38, 38); + panelWhite.TabIndex = 0; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(6, 22); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(38, 38); + panelRed.TabIndex = 0; + // + // checkBoxFuelCompartment + // + checkBoxFuelCompartment.AutoSize = true; + checkBoxFuelCompartment.Location = new Point(6, 138); + checkBoxFuelCompartment.Name = "checkBoxFuelCompartment"; + checkBoxFuelCompartment.Size = new Size(186, 19); + checkBoxFuelCompartment.TabIndex = 5; + checkBoxFuelCompartment.Text = "Наличие отсека под топливо"; + checkBoxFuelCompartment.UseVisualStyleBackColor = true; + // + // checkBoxPipe + // + checkBoxPipe.AutoSize = true; + checkBoxPipe.Location = new Point(6, 102); + checkBoxPipe.Name = "checkBoxPipe"; + checkBoxPipe.Size = new Size(103, 19); + checkBoxPipe.TabIndex = 4; + checkBoxPipe.Text = "Наличие труб"; + checkBoxPipe.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(76, 61); + 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(74, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(76, 27); + 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(74, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(6, 63); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(29, 15); + labelWeight.TabIndex = 1; + labelWeight.Text = "Вес:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(6, 29); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(62, 15); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость:"; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelExtraColor); + panelObject.Controls.Add(labelColor); + panelObject.Location = new Point(434, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(345, 217); + panelObject.TabIndex = 2; + panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(7, 40); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(331, 167); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // labelExtraColor + // + labelExtraColor.AllowDrop = true; + labelExtraColor.BorderStyle = BorderStyle.FixedSingle; + labelExtraColor.Location = new Point(215, 7); + labelExtraColor.Name = "labelExtraColor"; + labelExtraColor.Size = new Size(89, 30); + labelExtraColor.TabIndex = 2; + labelExtraColor.Text = "Доп. цвет"; + labelExtraColor.TextAlign = ContentAlignment.MiddleCenter; + labelExtraColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); + labelExtraColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(44, 7); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(89, 30); + labelColor.TabIndex = 1; + labelColor.Text = "Цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // buttonAdd + // + buttonAdd.Location = new Point(478, 235); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(89, 32); + buttonAdd.TabIndex = 3; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonCancel + // + buttonCancel.Location = new Point(649, 235); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(89, 32); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormShipConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(791, 279); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(panelObject); + Controls.Add(groupBoxParameters); + Name = "FormShipConfig"; + Text = "Создание объекта"; + groupBoxParameters.ResumeLayout(false); + groupBoxParameters.PerformLayout(); + groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxParameters; + private Label labelWeight; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private CheckBox checkBoxFuelCompartment; + private CheckBox checkBoxPipe; + private GroupBox groupBoxColor; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlack; + private Panel panelBlue; + private Panel panelGray; + private Panel panelGreen; + private Panel panelWhite; + private Panel panelRed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private Panel panelObject; + private Button buttonAdd; + private Button buttonCancel; + private PictureBox pictureBoxObject; + private Label labelExtraColor; + private Label labelColor; + } +} \ No newline at end of file diff --git a/WarmlyShip/FormShipConfig.cs b/WarmlyShip/FormShipConfig.cs new file mode 100644 index 0000000..f8b2f22 --- /dev/null +++ b/WarmlyShip/FormShipConfig.cs @@ -0,0 +1,198 @@ +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 System.Windows.Forms.VisualStyles; +using WarmlyShip.DrawningObjects; + +namespace WarmlyShip +{ + /// + /// Форма создания объекта + /// + public partial class FormShipConfig : Form + { + /// + /// Переменная-выбранный корабль + /// + DrawningShip? _ship = null; + + /// + /// Событие + /// + private event Action? EventAddShip; + + /// + /// Конструктор + /// + public FormShipConfig() + { + 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; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + + /// + /// Отрисовать корабль + /// + private void DrawShip() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.SetPosition(5, 5); + _ship?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddShip == null) + { + EventAddShip = ev; + } + else + { + EventAddShip += 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": + _ship = new DrawningShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + Color.White, pictureBoxObject.Width, pictureBoxObject.Height); + break; + case "labelModifiedObject": + _ship = new DrawningWarmlyShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + Color.White, Color.Black, checkBoxPipe.Checked, checkBoxFuelCompartment.Checked, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + labelColor.BackColor = Color.Empty; + labelExtraColor.BackColor = Color.Empty; + DrawShip(); + } + + /// + /// Отправляем цвет с панели + /// + /// + /// + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Принимаем основной цвет + /// + /// + /// + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + if (_ship == null) + { + return; + } + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _ship.SetColor(labelColor.BackColor); + DrawShip(); + } + + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + 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 LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if ((_ship == null) || (_ship is DrawningWarmlyShip == false)) + { + return; + } + labelExtraColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + ((DrawningWarmlyShip)_ship).SetAddColor(labelExtraColor.BackColor); + DrawShip(); + } + + /// + /// Добавление корабля + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } + } +} \ No newline at end of file diff --git a/WarmlyShip/FormShipConfig.resx b/WarmlyShip/FormShipConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WarmlyShip/FormShipConfig.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