Функционал

This commit is contained in:
the 2022-11-07 10:00:07 +04:00
parent 6b25163fc1
commit 16f6e435d5
5 changed files with 39 additions and 14 deletions

View File

@ -44,5 +44,15 @@ namespace Ship
g.FillEllipse(dopBrush, _startPosX + 40, _startPosY + 55, 20, 10); 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);
}
} }
} }

View File

@ -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() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return (_startPosX, _startPosX + _shipWidth, _startPosY, _startPosY + _shipHeight); return (_startPosX, _startPosX + _shipWidth, _startPosY, _startPosY + _shipHeight);

View File

@ -124,15 +124,14 @@ namespace Ship
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddShip_Click(object sender, EventArgs e) private void ButtonAddShip_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1) FormShipConfig form = new FormShipConfig();
form.AddEvent((ship) =>
{ {
return; if (listBoxMaps.SelectedIndex == -1)
} {
FormShip form = new(); return;
if (form.ShowDialog() == DialogResult.OK) }
{ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObject(ship) != -1)
DrawingObject car = new(form.SelectedShip);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
@ -141,7 +140,10 @@ namespace Ship
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
});
form.Show();
} }
/// <summary> /// <summary>
/// Удаление объекта /// Удаление объекта

View File

@ -298,6 +298,7 @@
this.buttonOk.TabIndex = 5; this.buttonOk.TabIndex = 5;
this.buttonOk.Text = "Добавить"; this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true; this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
// //
// buttonCancel // buttonCancel
// //
@ -328,6 +329,7 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelObject.ResumeLayout(false); this.panelObject.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion

View File

@ -19,7 +19,7 @@ namespace Ship
/// <summary> /// <summary>
/// Событие /// Событие
/// </summary> /// </summary>
private event ShipDelegate EventAddShip; private event Action<DrawingShip> EventAddShip;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -35,7 +35,7 @@ namespace Ship
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda buttonCancel.Click += (sender, e) => Close();
} }
/// <summary> /// <summary>
/// Отрисовать машину /// Отрисовать машину
@ -52,11 +52,11 @@ namespace Ship
/// Добавление события /// Добавление события
/// </summary> /// </summary>
/// <param name="ev"></param> /// <param name="ev"></param>
public void AddEvent(ShipDelegate ev) public void AddEvent(Action<DrawingShip> ev)
{ {
if (EventAddShip == null) if (EventAddShip == null)
{ {
EventAddShip = new ShipDelegate(ev); EventAddShip = new Action<DrawingShip>(ev);
} }
else else
{ {
@ -139,6 +139,8 @@ namespace Ship
/// <param name="e"></param> /// <param name="e"></param>
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{ {
_ship.SetColor((Color)e.Data.GetData(typeof(Color)));
DrawShip();
} }
/// <summary> /// <summary>
/// Принимаем дополнительный цвет /// Принимаем дополнительный цвет
@ -147,7 +149,11 @@ namespace Ship
/// <param name="e"></param> /// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e) 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();
} }
/// <summary> /// <summary>
/// Добавление машины /// Добавление машины