From f711ae5b81a937d8b4084f96ba97645501e8676b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=9F=D1=83=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Thu, 9 Nov 2023 17:11:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=205?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RoadTrain/DrawningRoadTrain.cs | 8 ++++++-- RoadTrain/DrawningTrain.cs | 7 +++++-- RoadTrain/EntityRoadTrain.cs | 7 ++++--- RoadTrain/EntityTrain.cs | 4 ++++ RoadTrain/FormTrainCollection.cs | 33 ++++++++++++++++---------------- RoadTrain/FormTrainConfig.cs | 2 ++ 6 files changed, 38 insertions(+), 23 deletions(-) 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)