diff --git a/RoadTrain/DrawningRoadTrain.cs b/RoadTrain/DrawningRoadTrain.cs index a09dd18..7dbd051 100644 --- a/RoadTrain/DrawningRoadTrain.cs +++ b/RoadTrain/DrawningRoadTrain.cs @@ -17,11 +17,11 @@ namespace RoadTrain.DrawningObjects /// /// Ширина окна /// - protected int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - protected int _pictureHeight; + public int _pictureHeight; /// /// Левая координата прорисовки автомобиля /// @@ -178,5 +178,9 @@ DrawningObjectTrain(this); g.FillEllipse(br, _startPosX + 60, _startPosY + 20, 10, 10); g.FillRectangle(br, _startPosX + 60, _startPosY, 10, 20); } + public void SetBodyColor(Color color) + { + EntityRoadTrain.SetBodyColor(color); + } } } \ No newline at end of file diff --git a/RoadTrain/DrawningTrain.cs b/RoadTrain/DrawningTrain.cs index 22b3046..a46281a 100644 --- a/RoadTrain/DrawningTrain.cs +++ b/RoadTrain/DrawningTrain.cs @@ -50,7 +50,10 @@ namespace RoadTrain.DrawningObjects g.DrawLine(pen, _startPosX + 20, _startPosY + 10, _startPosX + 10, _startPosY + 30); g.DrawLine(pen, _startPosX + 17, _startPosY + 30, _startPosX + 3, _startPosY + 30); } - } - } + public void SetAdditionalColor(Color color) + { + (EntityRoadTrain as EntityTrain).SetAdditionalColor(color); + } + } } \ No newline at end of file diff --git a/RoadTrain/EntityRoadTrain.cs b/RoadTrain/EntityRoadTrain.cs index 3bde5cd..9ccd4f6 100644 --- a/RoadTrain/EntityRoadTrain.cs +++ b/RoadTrain/EntityRoadTrain.cs @@ -20,9 +20,10 @@ namespace RoadTrain.Entities /// Основной цвет /// public Color BodyColor { get; protected set; } - /// - /// Дополнительный цвет (для опциональных элементов) - /// + public void SetBodyColor(Color color) + { + BodyColor = color; + } public double Step => (double)Speed * 100 / Weight; /// /// Инициализация полей объекта-класса поезда diff --git a/RoadTrain/EntityTrain.cs b/RoadTrain/EntityTrain.cs index 629bdb5..5a07a67 100644 --- a/RoadTrain/EntityTrain.cs +++ b/RoadTrain/EntityTrain.cs @@ -15,6 +15,10 @@ namespace RoadTrain.Entities /// Дополнительный цвет (для опциональных элементов) /// public Color AdditionalColor { get; private set; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } /// /// Признак (опция) наличия обвеса /// diff --git a/RoadTrain/FormTrainCollection.cs b/RoadTrain/FormTrainCollection.cs index e6ac440..e647cf0 100644 --- a/RoadTrain/FormTrainCollection.cs +++ b/RoadTrain/FormTrainCollection.cs @@ -44,33 +44,34 @@ pictureBoxCollection.Height); listBoxStorages.SelectedIndex = index; } } - - private void ButtonAddTrain_Click(object sender, EventArgs e) + private void AddTrain(DrawningRoadTrain train) { + train._pictureWidth = pictureBoxCollection.Width; + train._pictureHeight = pictureBoxCollection.Height; if (listBoxStorages.SelectedIndex == -1) { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - FormRoadTrain form = new(); - if (form.ShowDialog() == DialogResult.OK) + if (obj + train != -1) { - if (obj + form.SelectedTrain != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTrains(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTrains(); } - + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + private void ButtonAddTrain_Click(object sender, EventArgs e) + { + var formTrainConfig = new FormTrainConfig(); + formTrainConfig.AddEvent(AddTrain); + formTrainConfig.Show(); } private void ButtonRemoveTrain_Click(object sender, EventArgs e) diff --git a/RoadTrain/FormTrainConfig.cs b/RoadTrain/FormTrainConfig.cs index 38c1388..b5d890d 100644 --- a/RoadTrain/FormTrainConfig.cs +++ b/RoadTrain/FormTrainConfig.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using RoadTrain.MovementStrategy; using RoadTrain.DrawningObjects; +using RoadTrain.Entities; namespace RoadTrain { @@ -110,6 +111,7 @@ namespace RoadTrain pictureBoxObject.Height); break; } + DrawTrain(); } private void ButtonOk_Click(object sender, EventArgs e)