diff --git a/ContainerShip/DrawningShip.cs b/ContainerShip/DrawningShip.cs index 28bacd0..bd0a68e 100644 --- a/ContainerShip/DrawningShip.cs +++ b/ContainerShip/DrawningShip.cs @@ -119,5 +119,11 @@ namespace ContainerShip.DrawningObjects } public IMoveableObject GetMoveableObject => new DrawingObjectShip(this); + public void ChangeBordersPicture(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + } + } } diff --git a/ContainerShip/EntityContainerShip.cs b/ContainerShip/EntityContainerShip.cs index b0b4daf..396a496 100644 --- a/ContainerShip/EntityContainerShip.cs +++ b/ContainerShip/EntityContainerShip.cs @@ -20,6 +20,10 @@ namespace ContainerShip.Entities Load = load; Crane = crane; } + public void ChangeAdditionalColor(Color additionalColor) + { + AdditionalColor = additionalColor; + } } } diff --git a/ContainerShip/EntityShip.cs b/ContainerShip/EntityShip.cs index 1bbc698..4b51f50 100644 --- a/ContainerShip/EntityShip.cs +++ b/ContainerShip/EntityShip.cs @@ -18,5 +18,10 @@ namespace ContainerShip.Entities Weight = weight; BodyColor = bodyColor; } + + public void ChangeBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/ContainerShip/FormShipCollection.Designer.cs b/ContainerShip/FormShipCollection.Designer.cs index f3532aa..eb6698f 100644 --- a/ContainerShip/FormShipCollection.Designer.cs +++ b/ContainerShip/FormShipCollection.Designer.cs @@ -44,9 +44,10 @@ // // buttonAdd // - buttonAdd.Location = new Point(647, 305); + buttonAdd.Location = new Point(739, 407); + buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(144, 24); + buttonAdd.Size = new Size(165, 32); buttonAdd.TabIndex = 0; buttonAdd.Text = "Добавить корабль"; buttonAdd.UseVisualStyleBackColor = true; @@ -54,9 +55,10 @@ // // buttonDelete // - buttonDelete.Location = new Point(645, 362); + buttonDelete.Location = new Point(737, 482); + buttonDelete.Margin = new Padding(3, 4, 3, 4); buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(143, 24); + buttonDelete.Size = new Size(163, 32); buttonDelete.TabIndex = 1; buttonDelete.Text = "Удалить корабль"; buttonDelete.UseVisualStyleBackColor = true; @@ -65,59 +67,62 @@ // labelTools // labelTools.AutoSize = true; - labelTools.Location = new Point(677, 9); + labelTools.Location = new Point(774, 12); labelTools.Name = "labelTools"; - labelTools.Size = new Size(83, 15); + labelTools.Size = new Size(103, 20); labelTools.TabIndex = 3; labelTools.Text = "Инструменты"; // // maskedTextBoxNumber // - maskedTextBoxNumber.Location = new Point(645, 335); + maskedTextBoxNumber.Location = new Point(737, 447); + maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4); maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(142, 23); + maskedTextBoxNumber.Size = new Size(162, 27); maskedTextBoxNumber.TabIndex = 4; // // pictureBoxCollection // pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Margin = new Padding(3, 4, 3, 4); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(640, 386); + pictureBoxCollection.Size = new Size(731, 609); pictureBoxCollection.TabIndex = 5; pictureBoxCollection.TabStop = false; // // labelSet // labelSet.AutoSize = true; - labelSet.Location = new Point(654, 31); + labelSet.Location = new Point(748, 41); labelSet.Name = "labelSet"; - labelSet.Size = new Size(43, 15); + labelSet.Size = new Size(55, 20); labelSet.TabIndex = 6; labelSet.Text = "Набор"; // // textBoxStorageName // - textBoxStorageName.Location = new Point(647, 49); + textBoxStorageName.Location = new Point(739, 65); + textBoxStorageName.Margin = new Padding(3, 4, 3, 4); textBoxStorageName.Name = "textBoxStorageName"; - textBoxStorageName.Size = new Size(142, 23); + textBoxStorageName.Size = new Size(162, 27); textBoxStorageName.TabIndex = 7; // // listBoxStorages // listBoxStorages.FormattingEnabled = true; - listBoxStorages.ItemHeight = 15; - listBoxStorages.Location = new Point(647, 134); - listBoxStorages.Margin = new Padding(3, 2, 3, 2); + listBoxStorages.ItemHeight = 20; + listBoxStorages.Location = new Point(739, 179); listBoxStorages.Name = "listBoxStorages"; - listBoxStorages.Size = new Size(145, 94); + listBoxStorages.Size = new Size(165, 124); listBoxStorages.TabIndex = 8; listBoxStorages.SelectedIndexChanged += buttonUpdate_Click; // // buttonAddStorage // - buttonAddStorage.Location = new Point(647, 75); + buttonAddStorage.Location = new Point(739, 100); + buttonAddStorage.Margin = new Padding(3, 4, 3, 4); buttonAddStorage.Name = "buttonAddStorage"; - buttonAddStorage.Size = new Size(144, 24); + buttonAddStorage.Size = new Size(165, 32); buttonAddStorage.TabIndex = 9; buttonAddStorage.Text = "Добавить набор"; buttonAddStorage.UseVisualStyleBackColor = true; @@ -125,9 +130,10 @@ // // buttonDeleteStorage // - buttonDeleteStorage.Location = new Point(647, 242); + buttonDeleteStorage.Location = new Point(739, 322); + buttonDeleteStorage.Margin = new Padding(3, 4, 3, 4); buttonDeleteStorage.Name = "buttonDeleteStorage"; - buttonDeleteStorage.Size = new Size(144, 24); + buttonDeleteStorage.Size = new Size(165, 32); buttonDeleteStorage.TabIndex = 11; buttonDeleteStorage.Text = "Удалить набор"; buttonDeleteStorage.UseVisualStyleBackColor = true; @@ -135,9 +141,10 @@ // // buttonUpdate // - buttonUpdate.Location = new Point(647, 105); + buttonUpdate.Location = new Point(739, 140); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(143, 24); + buttonUpdate.Size = new Size(163, 32); buttonUpdate.TabIndex = 2; buttonUpdate.Text = "Обновить набор"; buttonUpdate.UseVisualStyleBackColor = true; @@ -145,9 +152,9 @@ // // FormShipCollection // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 393); + ClientSize = new Size(914, 600); Controls.Add(buttonDeleteStorage); Controls.Add(buttonAddStorage); Controls.Add(listBoxStorages); @@ -159,6 +166,7 @@ Controls.Add(buttonUpdate); Controls.Add(buttonDelete); Controls.Add(buttonAdd); + Margin = new Padding(3, 4, 3, 4); Name = "FormShipCollection"; Text = "Набор кораблей"; ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); diff --git a/ContainerShip/FormShipCollection.cs b/ContainerShip/FormShipCollection.cs index 5e49624..b8b3af1 100644 --- a/ContainerShip/FormShipCollection.cs +++ b/ContainerShip/FormShipCollection.cs @@ -67,9 +67,18 @@ namespace ContainerShip } } private void buttonAdd_Click(object sender, EventArgs e) + { + var formShipConfig = new FormShipConfig(); + formShipConfig.AddEvent(AddShip); + formShipConfig.Show(); + + } + + private void AddShip(DrawningShip selectedShip) { if (listBoxStorages.SelectedIndex == -1) { + MessageBox.Show("Не выбран набор"); return; } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; @@ -77,20 +86,16 @@ namespace ContainerShip { return; } - FormShips form = new(); - if (form.ShowDialog() == DialogResult.OK) + selectedShip.ChangeBordersPicture(pictureBoxCollection.Width, pictureBoxCollection.Height); + if (obj + selectedShip != -1) { - if (obj + form.SelectedShip != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowShips(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowShips(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } - } private void buttonDelete_Click(object sender, EventArgs e) { @@ -135,6 +140,5 @@ namespace ContainerShip } pictureBoxCollection.Image = obj.ShowShips(); } - } } diff --git a/ContainerShip/FormShipCollection.resx b/ContainerShip/FormShipCollection.resx index af32865..a395bff 100644 --- a/ContainerShip/FormShipCollection.resx +++ b/ContainerShip/FormShipCollection.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/ContainerShip/FormShipConfig.Designer.cs b/ContainerShip/FormShipConfig.Designer.cs new file mode 100644 index 0000000..6111594 --- /dev/null +++ b/ContainerShip/FormShipConfig.Designer.cs @@ -0,0 +1,357 @@ +namespace ContainerShip +{ + 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() + { + groupBoxConfig = new GroupBox(); + labelAdvancedObject = new Label(); + labelSimpleObject = new Label(); + groupBoxColor = new GroupBox(); + panelBlue = new Panel(); + panelBlack = new Panel(); + panelPink = new Panel(); + panelGray = new Panel(); + panelGreen = new Panel(); + panelYellow = new Panel(); + panelRoyalBlue = new Panel(); + panelFirebrick = new Panel(); + checkBoxCrane = new CheckBox(); + checkBoxLoad = new CheckBox(); + numericUpDownSpeed = new NumericUpDown(); + numericUpDownWeight = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelMainColor = new Label(); + pictureBoxObject = new PictureBox(); + buttonCancel = new Button(); + buttonAdd = new Button(); + groupBoxConfig.SuspendLayout(); + groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(labelAdvancedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Controls.Add(groupBoxColor); + groupBoxConfig.Controls.Add(checkBoxCrane); + groupBoxConfig.Controls.Add(checkBoxLoad); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Location = new Point(47, 93); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(570, 251); + groupBoxConfig.TabIndex = 3; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // labelAdvancedObject + // + labelAdvancedObject.BorderStyle = BorderStyle.FixedSingle; + labelAdvancedObject.Location = new Point(440, 188); + labelAdvancedObject.Name = "labelAdvancedObject"; + labelAdvancedObject.Size = new Size(120, 30); + labelAdvancedObject.TabIndex = 8; + labelAdvancedObject.Text = "Продвинутый"; + labelAdvancedObject.TextAlign = ContentAlignment.MiddleCenter; + labelAdvancedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(283, 188); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(120, 30); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBoxColor + // + groupBoxColor.Controls.Add(panelBlue); + groupBoxColor.Controls.Add(panelBlack); + groupBoxColor.Controls.Add(panelPink); + groupBoxColor.Controls.Add(panelGray); + groupBoxColor.Controls.Add(panelGreen); + groupBoxColor.Controls.Add(panelYellow); + groupBoxColor.Controls.Add(panelRoyalBlue); + groupBoxColor.Controls.Add(panelFirebrick); + groupBoxColor.Location = new Point(283, 32); + groupBoxColor.Name = "groupBoxColor"; + groupBoxColor.Size = new Size(277, 145); + groupBoxColor.TabIndex = 6; + groupBoxColor.TabStop = false; + groupBoxColor.Text = "Цвета"; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(5, 85); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(50, 40); + panelBlue.TabIndex = 0; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(75, 85); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(50, 40); + panelBlack.TabIndex = 0; + // + // panelPink + // + panelPink.BackColor = Color.DeepPink; + panelPink.Location = new Point(145, 85); + panelPink.Name = "panelPink"; + panelPink.Size = new Size(50, 40); + panelPink.TabIndex = 0; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(215, 85); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(50, 40); + panelGray.TabIndex = 0; + // + // panelGreen + // + panelGreen.BackColor = Color.FromArgb(0, 192, 0); + panelGreen.Location = new Point(215, 25); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(50, 40); + panelGreen.TabIndex = 0; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(145, 25); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(50, 40); + panelYellow.TabIndex = 0; + // + // panelRoyalBlue + // + panelRoyalBlue.BackColor = Color.RoyalBlue; + panelRoyalBlue.Location = new Point(75, 25); + panelRoyalBlue.Name = "panelRoyalBlue"; + panelRoyalBlue.Size = new Size(50, 40); + panelRoyalBlue.TabIndex = 0; + // + // panelFirebrick + // + panelFirebrick.BackColor = Color.Firebrick; + panelFirebrick.Location = new Point(5, 25); + panelFirebrick.Name = "panelFirebrick"; + panelFirebrick.Size = new Size(50, 40); + panelFirebrick.TabIndex = 0; + // + // checkBoxCrane + // + checkBoxCrane.AutoSize = true; + checkBoxCrane.Location = new Point(13, 149); + checkBoxCrane.Name = "checkBoxCrane"; + checkBoxCrane.Size = new Size(137, 24); + checkBoxCrane.TabIndex = 5; + checkBoxCrane.Text = "Наличие крана"; + checkBoxCrane.UseVisualStyleBackColor = true; + // + // checkBoxLoad + // + checkBoxLoad.AutoSize = true; + checkBoxLoad.Location = new Point(13, 119); + checkBoxLoad.Name = "checkBoxLoad"; + checkBoxLoad.Size = new Size(133, 24); + checkBoxLoad.TabIndex = 4; + checkBoxLoad.Text = "Наличие груза"; + checkBoxLoad.UseVisualStyleBackColor = true; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(94, 32); + 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(150, 27); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(94, 83); + 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(150, 27); + numericUpDownWeight.TabIndex = 2; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(6, 85); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(36, 20); + labelWeight.TabIndex = 1; + labelWeight.Text = "Вес:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(6, 32); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(76, 20); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость:"; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelMainColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(646, 74); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(401, 301); + panelObject.TabIndex = 4; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(233, 19); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(90, 50); + labelAdditionalColor.TabIndex = 3; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += LabelColor_DragEnter; + // + // labelMainColor + // + labelMainColor.AllowDrop = true; + labelMainColor.BorderStyle = BorderStyle.FixedSingle; + labelMainColor.Location = new Point(77, 19); + labelMainColor.Name = "labelMainColor"; + labelMainColor.Size = new Size(90, 50); + labelMainColor.TabIndex = 2; + labelMainColor.Text = "Цвет"; + labelMainColor.TextAlign = ContentAlignment.MiddleCenter; + labelMainColor.DragDrop += LabelMainColor_DragDrop; + labelMainColor.DragEnter += LabelMainColor_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.BorderStyle = BorderStyle.FixedSingle; + pictureBoxObject.Location = new Point(35, 84); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(327, 205); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonCancel + // + buttonCancel.Location = new Point(879, 394); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonAdd + // + buttonAdd.Location = new Point(722, 392); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormShipConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1095, 449); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Controls.Add(panelObject); + Name = "FormShipConfig"; + Text = "FormShipConfig"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelAdvancedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColor; + private Panel panelBlue; + private Panel panelBlack; + private Panel panelPink; + private Panel panelGray; + private Panel panelGreen; + private Panel panelYellow; + private Panel panelRoyalBlue; + private Panel panelFirebrick; + private CheckBox checkBoxCrane; + private CheckBox checkBoxLoad; + private NumericUpDown numericUpDownSpeed; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private Label labelSpeed; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelMainColor; + private PictureBox pictureBoxObject; + private Button buttonCancel; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ContainerShip/FormShipConfig.cs b/ContainerShip/FormShipConfig.cs new file mode 100644 index 0000000..254c9a3 --- /dev/null +++ b/ContainerShip/FormShipConfig.cs @@ -0,0 +1,139 @@ +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 ContainerShip.DrawningObjects; +using ContainerShip.Entities; + +namespace ContainerShip +{ + public partial class FormShipConfig : Form + { + DrawningShip? _ship = null; + private event Action? EventAddShip; + public FormShipConfig() + { + InitializeComponent(); + panelFirebrick.MouseDown += PanelColor_MouseDown; + panelRoyalBlue.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelBlack.MouseDown += PanelColor_MouseDown; + panelPink.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_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; + } + } + 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 "labelAdvancedObject": + _ship = new DrawingContainerShip( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, + Color.White, Color.Black, + checkBoxLoad.Checked, checkBoxCrane.Checked, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawShip(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + private void LabelMainColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _ship != null) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelMainColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e.Data.GetData(typeof(Color)); + _ship.EntityShip.ChangeBodyColor(color); + DrawShip(); + } + 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 LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + Color addColor = (Color)e.Data?.GetData(typeof(Color)); + if (_ship is DrawingContainerShip) + { + EntityContainerShip _containerShip = _ship.EntityShip as EntityContainerShip; + _containerShip.ChangeAdditionalColor(addColor); + } + DrawShip(); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } + } +} diff --git a/ContainerShip/FormShipConfig.resx b/ContainerShip/FormShipConfig.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/ContainerShip/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 diff --git a/ContainerShip/SetGeneric.cs b/ContainerShip/SetGeneric.cs index 3414007..31d7cd3 100644 --- a/ContainerShip/SetGeneric.cs +++ b/ContainerShip/SetGeneric.cs @@ -24,13 +24,10 @@ namespace ContainerShip.Generic } public bool Insert(T ship, int position) { - // TODO проверка позиции if (position < 0 || position >= Count || Count >= _maxCount) { return false; } - - // TODO вставка по позиции _places.Insert(position, ship); return true; } diff --git a/ContainerShip/ShipsGenericCollection.cs b/ContainerShip/ShipsGenericCollection.cs index ee4650e..910696e 100644 --- a/ContainerShip/ShipsGenericCollection.cs +++ b/ContainerShip/ShipsGenericCollection.cs @@ -78,6 +78,7 @@ namespace ContainerShip.Generic for (int i = 0; i < _collection.Count; i++) { DrawningShip _ship = _collection[i]; + if (_ship != null) { if (x < 0) { x = _pictureWidth / _placeSizeWidth - 1; @@ -86,6 +87,7 @@ namespace ContainerShip.Generic _ship.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y); _ship.DrawTransport(g); x--; + } } } }