From 16f6e435d56638024a1ed33978c9210888d7370c Mon Sep 17 00:00:00 2001 From: the Date: Mon, 7 Nov 2022 10:00:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ship/Ship/DrawingMotorShip.cs | 10 ++++++++++ Ship/Ship/DrawingShip.cs | 5 +++++ Ship/Ship/FormMapWithSetShips.cs | 20 +++++++++++--------- Ship/Ship/FormShipConfig.Designer.cs | 2 ++ Ship/Ship/FormShipConfig.cs | 16 +++++++++++----- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Ship/Ship/DrawingMotorShip.cs b/Ship/Ship/DrawingMotorShip.cs index 5d2f155..909cd0d 100644 --- a/Ship/Ship/DrawingMotorShip.cs +++ b/Ship/Ship/DrawingMotorShip.cs @@ -44,5 +44,15 @@ namespace Ship g.FillEllipse(dopBrush, _startPosX + 40, _startPosY + 55, 20, 10); } } + + public override void SetColor(Color color) + { + Ship = new EntityMotorShip(Ship.Speed, Ship.Weight, color, (Ship as EntityMotorShip).DopColor, (Ship as EntityMotorShip).Pipes, (Ship as EntityMotorShip).Fueltank); + } + + public void SetDopColor(Color color) + { + Ship = new EntityMotorShip(Ship.Speed, Ship.Weight, (Ship as EntityMotorShip).BodyColor, color, (Ship as EntityMotorShip).Pipes, (Ship as EntityMotorShip).Fueltank); + } } } diff --git a/Ship/Ship/DrawingShip.cs b/Ship/Ship/DrawingShip.cs index 07e9db2..0eedaff 100644 --- a/Ship/Ship/DrawingShip.cs +++ b/Ship/Ship/DrawingShip.cs @@ -178,6 +178,11 @@ namespace Ship } } + virtual public void SetColor(Color color) + { + Ship = new EntityShip(Ship.Speed, Ship.Weight, color); + } + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return (_startPosX, _startPosX + _shipWidth, _startPosY, _startPosY + _shipHeight); diff --git a/Ship/Ship/FormMapWithSetShips.cs b/Ship/Ship/FormMapWithSetShips.cs index fdbd326..84adf12 100644 --- a/Ship/Ship/FormMapWithSetShips.cs +++ b/Ship/Ship/FormMapWithSetShips.cs @@ -124,15 +124,14 @@ namespace Ship /// private void ButtonAddShip_Click(object sender, EventArgs e) { - if (listBoxMaps.SelectedIndex == -1) + FormShipConfig form = new FormShipConfig(); + form.AddEvent((ship) => { - return; - } - FormShip form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - DrawingObject car = new(form.SelectedShip); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car != -1) + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObject(ship) != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); @@ -141,7 +140,10 @@ namespace Ship { MessageBox.Show("Не удалось добавить объект"); } - } + + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); + }); + form.Show(); } /// /// Удаление объекта diff --git a/Ship/Ship/FormShipConfig.Designer.cs b/Ship/Ship/FormShipConfig.Designer.cs index 51dc113..f9484c6 100644 --- a/Ship/Ship/FormShipConfig.Designer.cs +++ b/Ship/Ship/FormShipConfig.Designer.cs @@ -298,6 +298,7 @@ this.buttonOk.TabIndex = 5; this.buttonOk.Text = "Добавить"; this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); // // buttonCancel // @@ -328,6 +329,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); this.panelObject.ResumeLayout(false); this.ResumeLayout(false); + } #endregion diff --git a/Ship/Ship/FormShipConfig.cs b/Ship/Ship/FormShipConfig.cs index 9f8dcad..cdc36da 100644 --- a/Ship/Ship/FormShipConfig.cs +++ b/Ship/Ship/FormShipConfig.cs @@ -19,7 +19,7 @@ namespace Ship /// /// Событие /// - private event ShipDelegate EventAddShip; + private event Action EventAddShip; /// /// Конструктор /// @@ -35,7 +35,7 @@ namespace Ship panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - // TODO buttonCancel.Click with lambda + buttonCancel.Click += (sender, e) => Close(); } /// /// Отрисовать машину @@ -52,11 +52,11 @@ namespace Ship /// Добавление события /// /// - public void AddEvent(ShipDelegate ev) + public void AddEvent(Action ev) { if (EventAddShip == null) { - EventAddShip = new ShipDelegate(ev); + EventAddShip = new Action(ev); } else { @@ -139,6 +139,8 @@ namespace Ship /// private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { + _ship.SetColor((Color)e.Data.GetData(typeof(Color))); + DrawShip(); } /// /// Принимаем дополнительный цвет @@ -147,7 +149,11 @@ namespace Ship /// private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - // TODO Call method from object _car if _car is DrawningSportCar and set dop color + if(_ship is DrawingMotorShip ship) + { + ship.SetDopColor((Color)e.Data.GetData(typeof(Color))); + } + DrawShip(); } /// /// Добавление машины