diff --git a/Battleship/Battleship/EntityBattleship.cs b/Battleship/Battleship/EntityBattleship.cs index 999b563..f3cd02c 100644 --- a/Battleship/Battleship/EntityBattleship.cs +++ b/Battleship/Battleship/EntityBattleship.cs @@ -39,5 +39,10 @@ namespace Battleship.Entities Tower = tower; Section = section; } + + internal void setAdditionalColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/Battleship/Battleship/EntityShip.cs b/Battleship/Battleship/EntityShip.cs index ec575b5..db19207 100644 --- a/Battleship/Battleship/EntityShip.cs +++ b/Battleship/Battleship/EntityShip.cs @@ -37,5 +37,10 @@ namespace Battleship.Entities Weight = weight; BodyColor = bodyColor; } + + internal void setBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index 962a37b..cfd8f05 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -106,6 +106,24 @@ namespace Battleship { return; } + + var FormShipConfig = new FormShipConfig(); + FormShipConfig.AddEvent(AddShip); + FormShipConfig.Show(); + + } + + private void AddShip(DrawningShip drawningShip) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } FormBattleship form = new(); if (form.ShowDialog() == DialogResult.OK) { @@ -136,7 +154,18 @@ namespace Battleship { return; } - int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + + int pos; + try + { + + pos = Convert.ToInt32(maskedTextBoxNumber.Text); + } + catch + { + MessageBox.Show("Не удалось удалить объект"); + return; + } if (obj - pos != null) { MessageBox.Show("Объект удален"); @@ -162,18 +191,6 @@ namespace Battleship } pictureBoxCollection.Image = obj.ShowShips(); } - - /// - /// Добавление объекта - /// - /// - /// - private void ButtonAddCar_Click(object sender, EventArgs e) - { - var formCarConfig = new FormShipConfig(); - // TODO Call method AddEvent from formCarConfig - formCarConfig.Show(); - } } } diff --git a/Battleship/Battleship/FormShipConfig.Designer.cs b/Battleship/Battleship/FormShipConfig.Designer.cs index 5abbb75..43b84ed 100644 --- a/Battleship/Battleship/FormShipConfig.Designer.cs +++ b/Battleship/Battleship/FormShipConfig.Designer.cs @@ -281,9 +281,12 @@ this.panelPicture.Name = "panelPicture"; this.panelPicture.Size = new System.Drawing.Size(256, 216); this.panelPicture.TabIndex = 9; + this.panelPicture.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelPicture.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // // labelAddColor // + this.labelAddColor.AllowDrop = true; this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelAddColor.Location = new System.Drawing.Point(145, 17); this.labelAddColor.Name = "labelAddColor"; @@ -291,9 +294,12 @@ this.labelAddColor.TabIndex = 12; this.labelAddColor.Text = "Доп. цвет"; this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_dragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter); // // labelBodyColor // + this.labelBodyColor.AllowDrop = true; this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelBodyColor.Location = new System.Drawing.Point(15, 17); this.labelBodyColor.Name = "labelBodyColor"; @@ -301,6 +307,8 @@ this.labelBodyColor.TabIndex = 11; this.labelBodyColor.Text = "Цвет"; this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_dragDrop); + this.labelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter); // // pictureBoxObject // diff --git a/Battleship/Battleship/FormShipConfig.cs b/Battleship/Battleship/FormShipConfig.cs index dc1a6a9..15b27ec 100644 --- a/Battleship/Battleship/FormShipConfig.cs +++ b/Battleship/Battleship/FormShipConfig.cs @@ -38,11 +38,13 @@ namespace Battleship panelBlue.MouseDown += PanelColor_MouseDown; // TODO buttonCancel.Click with lambda + buttonCancel.Click += (s, e) => Close(); + } /// /// Отрисовать машину /// - private void DrawCar() + private void DrawShip() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); @@ -72,8 +74,7 @@ namespace Battleship /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { - (sender as Label)?.DoDragDrop((sender as Label)?.Name, - DragDropEffects.Move | DragDropEffects.Copy); + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } /// /// Проверка получаемой информации (ее типа на соответствие требуемому) @@ -110,7 +111,7 @@ namespace Battleship checkBoxRocket.Checked, pictureBoxObject.Width, pictureBoxObject.Height); break; } - DrawCar(); + DrawShip(); } // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) /// @@ -118,7 +119,7 @@ namespace Battleship /// /// /// - private void ButtonOk_Click(object sender, EventArgs e) + private void buttonAdd_Click(object sender, EventArgs e) { EventAddShip?.Invoke(_ship); Close(); @@ -126,7 +127,35 @@ namespace Battleship 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)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void labelColor_dragDrop(object sender, DragEventArgs e) + { + if (_ship == null) + return; + switch (((Label)sender).Name) + { + case "labelBodyColor": + _ship?.EntityShip?.setBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAddColor": + if (!(_ship is DrawningBattleship)) + return; + (_ship.EntityShip as EntityBattleship)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color))); + break; + } + DrawShip(); } } }