From cb5e989a82af5bb0cca1fb6464cd65479b6853f6 Mon Sep 17 00:00:00 2001 From: spacyboy Date: Tue, 12 Dec 2023 15:46:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RoadTrain/RoadTrain/DrawingRoadTrain.cs | 63 ++- .../RoadTrain/DrawingRoadTrainWithTank.cs | 6 +- RoadTrain/RoadTrain/EntityRoadTrain.cs | 6 +- .../RoadTrain/EntityRoadTrainWithTank.cs | 6 +- RoadTrain/RoadTrain/SetGeneric.cs | 9 +- RoadTrain/RoadTrain/TrainCollection.cs | 12 +- RoadTrain/RoadTrain/TrainConfig.Designer.cs | 390 ++++++++++++++++++ RoadTrain/RoadTrain/TrainConfig.cs | 127 ++++++ RoadTrain/RoadTrain/TrainConfig.resx | 120 ++++++ RoadTrain/RoadTrain/TrainDelegate.cs | 16 + .../RoadTrain/TrainsGenericCollection.cs | 2 +- RoadTrain/RoadTrain/TrainsGenericStorage.cs | 14 +- 12 files changed, 749 insertions(+), 22 deletions(-) create mode 100644 RoadTrain/RoadTrain/TrainConfig.Designer.cs create mode 100644 RoadTrain/RoadTrain/TrainConfig.cs create mode 100644 RoadTrain/RoadTrain/TrainConfig.resx create mode 100644 RoadTrain/RoadTrain/TrainDelegate.cs diff --git a/RoadTrain/RoadTrain/DrawingRoadTrain.cs b/RoadTrain/RoadTrain/DrawingRoadTrain.cs index 1507701..3e5c7af 100644 --- a/RoadTrain/RoadTrain/DrawingRoadTrain.cs +++ b/RoadTrain/RoadTrain/DrawingRoadTrain.cs @@ -11,17 +11,12 @@ namespace RoadTrain.DrawingObjects public class DrawingRoadTrain { public EntityRoadTrain? EntityRoadTrain { get; protected set; } - private int _pictureWidth; - private int _pictureHeight; + public int _pictureWidth; + public int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _roadTrainWidth = 200; protected readonly int _roadTrainHeight = 100; - public int GetPosX => _startPosX; - public int GetPosY => _startPosY; - public int GetWidth => _roadTrainWidth; - public int GetHeight => _roadTrainHeight; - public IMoveableObject GetMoveableObject => new DrawingObjectTrain(this); public DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height) { if (width < _roadTrainWidth || height < _roadTrainHeight) @@ -57,6 +52,51 @@ namespace RoadTrain.DrawingObjects _startPosX = x; _startPosY = y; } + public virtual void DrawTransport(Graphics g) + { + if (EntityRoadTrain == null) + { + return; + } + Pen pen = new(Color.Black, 2); + Pen anchor = new(Color.Black, 4); + Brush bodyBrush = new SolidBrush(EntityRoadTrain.BodyColor); + Brush whiteBrush = new SolidBrush(Color.White); + + //машина + g.DrawRectangle(pen, _startPosX, _startPosY + 50, 160, 20); + g.FillRectangle(bodyBrush, _startPosX, _startPosY + 50, 160, 20); + g.DrawEllipse(pen, _startPosX + 5, _startPosY + 70, 30, 30); //колесо + g.FillEllipse(bodyBrush, _startPosX + 5, _startPosY + 70, 30, 30); + g.DrawEllipse(pen, _startPosX + 40, _startPosY + 70, 30, 30); //колесо + g.FillEllipse(bodyBrush, _startPosX + 40, _startPosY + 70, 30, 30); + g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 30, 30); //колесо + g.FillEllipse(bodyBrush, _startPosX + 120, _startPosY + 70, 30, 30); + g.DrawRectangle(pen, _startPosX + 120, _startPosY + 10, 40, 40); //кабина + g.FillRectangle(bodyBrush, _startPosX + 120, _startPosY + 10, 40, 40); + g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно + g.FillRectangle(whiteBrush, _startPosX + 130, _startPosY + 20, 30, 20); + + } + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _roadTrainWidth; + public int GetHeight => _roadTrainHeight; + public bool CanMove(DirectionType direction) + { + if (EntityRoadTrain == null) + { + return false; + } + return direction switch + { + DirectionType.Left => _startPosX - EntityRoadTrain.Step > 0, + DirectionType.Up => _startPosY - EntityRoadTrain.Step > 0, + DirectionType.Right => _startPosX + EntityRoadTrain.Step + _roadTrainWidth < _pictureWidth, + DirectionType.Down => _startPosY + EntityRoadTrain.Step + _roadTrainHeight < _pictureHeight, + _ => false, + }; + } public void MoveTransport(DirectionType direction) { if (!CanMove(direction) || EntityRoadTrain == null) @@ -79,6 +119,7 @@ namespace RoadTrain.DrawingObjects break; } } +<<<<<<< HEAD public bool CanMove(DirectionType direction) { if (EntityRoadTrain == null) @@ -118,7 +159,15 @@ namespace RoadTrain.DrawingObjects g.FillRectangle(bodyBrush, _startPosX + 120, _startPosY + 10, 40, 40); g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно g.FillRectangle(whiteBrush, _startPosX + 130, _startPosY + 20, 30, 20); +======= + public IMoveableObject GetMoveableObject => new DrawingObjectTrain(this); + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) +>>>>>>> a4a5763 (готовая лаба 5) + { + _pictureWidth = pictureBoxWidth; + _pictureHeight = pictureBoxHeight; } + } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs b/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs index 9ad989e..bf72a78 100644 --- a/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs +++ b/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs @@ -43,5 +43,9 @@ namespace RoadTrain.DrawingObjects g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY, 90, 50); } } + public void SetAddColor(Color color) + { + (EntityRoadTrain as EntityRoadTrainWithTank).AdditionalColor = color; + } } -} \ No newline at end of file +} diff --git a/RoadTrain/RoadTrain/EntityRoadTrain.cs b/RoadTrain/RoadTrain/EntityRoadTrain.cs index 00affdb..d5ee30a 100644 --- a/RoadTrain/RoadTrain/EntityRoadTrain.cs +++ b/RoadTrain/RoadTrain/EntityRoadTrain.cs @@ -10,7 +10,7 @@ namespace RoadTrain.Entities { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public double Step => (double)Speed * 100 / Weight; public EntityRoadTrain(int speed, double weight, Color bodyColor) { @@ -18,5 +18,9 @@ namespace RoadTrain.Entities Weight = weight; BodyColor = bodyColor; } + public void SetBodyColor(Color color) + { + BodyColor = color; + } } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs b/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs index 448eb41..1508de2 100644 --- a/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs +++ b/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs @@ -8,7 +8,7 @@ namespace RoadTrain.Entities { public class EntityRoadTrainWithTank : EntityRoadTrain { - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } public bool Tank { get; private set; } public bool Brush { get; private set; } public EntityRoadTrainWithTank(int speed, double weight, Color bodyColor, Color @@ -19,5 +19,9 @@ namespace RoadTrain.Entities Tank = tank; Brush = brush; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/SetGeneric.cs b/RoadTrain/RoadTrain/SetGeneric.cs index 0361a54..17a5900 100644 --- a/RoadTrain/RoadTrain/SetGeneric.cs +++ b/RoadTrain/RoadTrain/SetGeneric.cs @@ -11,7 +11,7 @@ namespace RoadTrain.Generics { private readonly List _places; public int Count => _places.Count; - public readonly int _maxCount; + private readonly int _maxCount; public SetGeneric(int count) { @@ -53,13 +53,16 @@ namespace RoadTrain.Generics } set { - if (position < 0 || position > Count || Count >= _maxCount) + if (!(position >= 0 && position < Count && _places.Count < _maxCount)) + { return; + } _places.Insert(position, value); + return; } } - public IEnumerable GetTrains(int? maxTrains = null) + public IEnumerable GetTrains(int? maxTrains = null) { for (int i = 0; i < _places.Count; ++i) { diff --git a/RoadTrain/RoadTrain/TrainCollection.cs b/RoadTrain/RoadTrain/TrainCollection.cs index 2be5c9d..b3b76d3 100644 --- a/RoadTrain/RoadTrain/TrainCollection.cs +++ b/RoadTrain/RoadTrain/TrainCollection.cs @@ -83,19 +83,23 @@ namespace RoadTrain { return; } - RoadTrain form = new(); - if (form.ShowDialog() == DialogResult.OK) + var formTrainConfig = new TrainConfig(); + formTrainConfig.Show(); + Action? trainDelegate = new((m) => { - if (obj + form.SelectedTrain) + bool isAddSuccessful = (obj + m); + if (isAddSuccessful) { MessageBox.Show("Объект добавлен"); + m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); pictureBoxCollection.Image = obj.ShowTrains(); } else { MessageBox.Show("Не удалось добавить объект"); } - } + }); + formTrainConfig.AddEvent(trainDelegate); } private void ButtonRemoveTrain_Click(object sender, EventArgs e) { diff --git a/RoadTrain/RoadTrain/TrainConfig.Designer.cs b/RoadTrain/RoadTrain/TrainConfig.Designer.cs new file mode 100644 index 0000000..7c64f20 --- /dev/null +++ b/RoadTrain/RoadTrain/TrainConfig.Designer.cs @@ -0,0 +1,390 @@ +namespace RoadTrain +{ + partial class TrainConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureBoxObject = new PictureBox(); + labelSimpleObject = new Label(); + panelRed = new Panel(); + panelBlue = new Panel(); + panelYellow = new Panel(); + panelWhite = new Panel(); + panelGray = new Panel(); + panelBlack = new Panel(); + panelPurple = new Panel(); + panelGreen = new Panel(); + labelModifiedObject = new Label(); + groupBoxColor = new GroupBox(); + checkBoxBrush = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + panel1 = new Panel(); + buttonCancel = new Button(); + buttonOk = new Button(); + labelAddColor = new Label(); + labelBodyColor = new Label(); + checkBoxTank = new CheckBox(); + groupBoxParameters = new GroupBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panel1.SuspendLayout(); + groupBoxParameters.SuspendLayout(); + SuspendLayout(); + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(15, 58); + pictureBoxObject.Margin = new Padding(3, 2, 3, 2); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(282, 160); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // labelSimpleObject + // + labelSimpleObject.AllowDrop = true; + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point); + labelSimpleObject.Location = new Point(274, 205); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(109, 28); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Tomato; + panelRed.Location = new Point(6, 29); + panelRed.Margin = new Padding(3, 2, 3, 2); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(40, 40); + panelRed.TabIndex = 1; + panelRed.MouseDown += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.CornflowerBlue; + panelBlue.Location = new Point(125, 29); + panelBlue.Margin = new Padding(3, 2, 3, 2); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(40, 40); + panelBlue.TabIndex = 1; + panelBlue.MouseDown += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.FromArgb(255, 255, 128); + panelYellow.Location = new Point(187, 29); + panelYellow.Margin = new Padding(3, 2, 3, 2); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(40, 40); + panelYellow.TabIndex = 1; + panelYellow.MouseDown += PanelColor_MouseDown; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(5, 86); + panelWhite.Margin = new Padding(3, 2, 3, 2); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(40, 40); + panelWhite.TabIndex = 1; + panelWhite.MouseDown += PanelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(65, 86); + panelGray.Margin = new Padding(3, 2, 3, 2); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(40, 40); + panelGray.TabIndex = 1; + panelGray.MouseDown += PanelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(125, 86); + panelBlack.Margin = new Padding(3, 2, 3, 2); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(40, 40); + panelBlack.TabIndex = 1; + panelBlack.MouseDown += PanelColor_MouseDown; + // + // panelPurple + // + panelPurple.BackColor = Color.Violet; + panelPurple.Location = new Point(187, 86); + panelPurple.Margin = new Padding(3, 2, 3, 2); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(40, 40); + panelPurple.TabIndex = 1; + panelPurple.MouseDown += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.LightGreen; + panelGreen.Location = new Point(65, 29); + panelGreen.Margin = new Padding(3, 2, 3, 2); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(40, 40); + panelGreen.TabIndex = 0; + panelGreen.MouseDown += PanelColor_MouseDown; + // + // labelModifiedObject + // + labelModifiedObject.AllowDrop = true; + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point); + labelModifiedObject.Location = new Point(399, 205); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(106, 28); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // groupBoxColor + // + groupBoxColor.Controls.Add(panelRed); + groupBoxColor.Controls.Add(panelBlue); + groupBoxColor.Controls.Add(panelYellow); + groupBoxColor.Controls.Add(panelWhite); + groupBoxColor.Controls.Add(panelGray); + groupBoxColor.Controls.Add(panelBlack); + groupBoxColor.Controls.Add(panelPurple); + groupBoxColor.Controls.Add(panelGreen); + groupBoxColor.Location = new Point(274, 28); + groupBoxColor.Margin = new Padding(3, 2, 3, 2); + groupBoxColor.Name = "groupBoxColor"; + groupBoxColor.Padding = new Padding(3, 2, 3, 2); + groupBoxColor.Size = new Size(231, 162); + groupBoxColor.TabIndex = 6; + groupBoxColor.TabStop = false; + groupBoxColor.Text = "Цвета"; + // + // checkBoxBrush + // + checkBoxBrush.AutoSize = true; + checkBoxBrush.Location = new Point(13, 147); + checkBoxBrush.Margin = new Padding(3, 2, 3, 2); + checkBoxBrush.Name = "checkBoxBrush"; + checkBoxBrush.Size = new Size(161, 19); + checkBoxBrush.TabIndex = 5; + checkBoxBrush.Text = "Признак наличия щетки"; + checkBoxBrush.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(94, 60); + numericUpDownWeight.Margin = new Padding(3, 2, 3, 2); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(51, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(94, 28); + numericUpDownSpeed.Margin = new Padding(3, 2, 3, 2); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(59, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(13, 67); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(26, 15); + labelWeight.TabIndex = 1; + labelWeight.Text = "Вес"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(13, 35); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(59, 15); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость"; + // + // panel1 + // + panel1.AllowDrop = true; + panel1.Controls.Add(buttonCancel); + panel1.Controls.Add(buttonOk); + panel1.Controls.Add(labelAddColor); + panel1.Controls.Add(labelBodyColor); + panel1.Controls.Add(pictureBoxObject); + panel1.Location = new Point(557, 7); + panel1.Margin = new Padding(3, 2, 3, 2); + panel1.Name = "panel1"; + panel1.Size = new Size(312, 263); + panel1.TabIndex = 1; + panel1.DragDrop += PanelObject_DragDrop; + panel1.DragEnter += PanelObject_DragEnter; + // + // buttonCancel + // + buttonCancel.Location = new Point(175, 223); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(108, 24); + buttonCancel.TabIndex = 12; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonOk + // + buttonOk.Location = new Point(38, 223); + buttonOk.Margin = new Padding(3, 2, 3, 2); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(108, 24); + buttonOk.TabIndex = 11; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += ButtonOk_Click; + // + // labelAddColor + // + labelAddColor.AllowDrop = true; + labelAddColor.BorderStyle = BorderStyle.FixedSingle; + labelAddColor.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point); + labelAddColor.Location = new Point(175, 22); + labelAddColor.Name = "labelAddColor"; + labelAddColor.Size = new Size(109, 28); + labelAddColor.TabIndex = 10; + labelAddColor.Text = "Доп. цвет"; + labelAddColor.TextAlign = ContentAlignment.MiddleCenter; + labelAddColor.DragDrop += LabelColor_DragDrop; + labelAddColor.DragEnter += LabelColor_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point); + labelBodyColor.Location = new Point(38, 22); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(109, 28); + labelBodyColor.TabIndex = 9; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += LabelColor_DragDrop; + labelBodyColor.DragEnter += LabelColor_DragEnter; + // + // checkBoxTank + // + checkBoxTank.AutoSize = true; + checkBoxTank.Location = new Point(13, 113); + checkBoxTank.Margin = new Padding(3, 2, 3, 2); + checkBoxTank.Name = "checkBoxTank"; + checkBoxTank.Size = new Size(196, 19); + checkBoxTank.TabIndex = 4; + checkBoxTank.Text = "Признак наличия бака с водой"; + checkBoxTank.UseVisualStyleBackColor = true; + // + // groupBoxParameters + // + groupBoxParameters.Controls.Add(labelModifiedObject); + groupBoxParameters.Controls.Add(labelSimpleObject); + groupBoxParameters.Controls.Add(groupBoxColor); + groupBoxParameters.Controls.Add(checkBoxBrush); + groupBoxParameters.Controls.Add(checkBoxTank); + groupBoxParameters.Controls.Add(numericUpDownWeight); + groupBoxParameters.Controls.Add(numericUpDownSpeed); + groupBoxParameters.Controls.Add(labelWeight); + groupBoxParameters.Controls.Add(labelSpeed); + groupBoxParameters.Location = new Point(15, 7); + groupBoxParameters.Margin = new Padding(3, 2, 3, 2); + groupBoxParameters.Name = "groupBoxParameters"; + groupBoxParameters.Padding = new Padding(3, 2, 3, 2); + groupBoxParameters.Size = new Size(524, 260); + groupBoxParameters.TabIndex = 2; + groupBoxParameters.TabStop = false; + groupBoxParameters.Text = "Параметры"; + // + // TrainConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(884, 277); + Controls.Add(panel1); + Controls.Add(groupBoxParameters); + Name = "TrainConfig"; + Text = "TrainConfig"; + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panel1.ResumeLayout(false); + groupBoxParameters.ResumeLayout(false); + groupBoxParameters.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxObject; + private Label labelSimpleObject; + private Panel panelRed; + private Panel panelBlue; + private Panel panelYellow; + private Panel panelWhite; + private Panel panelGray; + private Panel panelBlack; + private Panel panelPurple; + private Panel panelGreen; + private Label labelModifiedObject; + private GroupBox groupBoxColor; + private CheckBox checkBoxBrush; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private Panel panel1; + private Button buttonCancel; + private Button buttonOk; + private Label labelAddColor; + private Label labelBodyColor; + private CheckBox checkBoxTank; + private GroupBox groupBoxParameters; + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/TrainConfig.cs b/RoadTrain/RoadTrain/TrainConfig.cs new file mode 100644 index 0000000..ed24d3b --- /dev/null +++ b/RoadTrain/RoadTrain/TrainConfig.cs @@ -0,0 +1,127 @@ +using RoadTrain.DrawingObjects; +using RoadTrain.Entities; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RoadTrain +{ + public partial class TrainConfig : Form + { + + DrawingRoadTrain? _train = null; + private event Action? EventAddTrain; + + public TrainConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + + buttonCancel.Click += (s, e) => Close(); + + } + private void DrawTrain() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _train?.SetPosition(5, 5); + _train?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + internal void AddEvent(Action ev) + { + if (EventAddTrain == null) + { + EventAddTrain = ev; + } + else + { + EventAddTrain += ev; + } + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _train = new DrawingRoadTrain((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _train = new DrawingRoadTrainWithTank((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTank.Checked, + checkBoxBrush.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawTrain(); + } + 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 (_train == null) + return; + switch (((Label)sender).Name) + { + case "labelBodyColor": + _train.EntityRoadTrain.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAddColor": + if (!(_train is DrawingRoadTrainWithTank)) + return; + (_train.EntityRoadTrain as EntityRoadTrainWithTank).SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawTrain(); + } + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddTrain?.Invoke(_train); + Close(); + } + } +} diff --git a/RoadTrain/RoadTrain/TrainConfig.resx b/RoadTrain/RoadTrain/TrainConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RoadTrain/RoadTrain/TrainConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RoadTrain/RoadTrain/TrainDelegate.cs b/RoadTrain/RoadTrain/TrainDelegate.cs new file mode 100644 index 0000000..ee5d1d1 --- /dev/null +++ b/RoadTrain/RoadTrain/TrainDelegate.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RoadTrain.DrawingObjects; + + +namespace RoadTrain +{ + internal class TrainDelegate + { + public delegate void Action(DrawingRoadTrain train); + + } +} diff --git a/RoadTrain/RoadTrain/TrainsGenericCollection.cs b/RoadTrain/RoadTrain/TrainsGenericCollection.cs index f5aa496..87884fb 100644 --- a/RoadTrain/RoadTrain/TrainsGenericCollection.cs +++ b/RoadTrain/RoadTrain/TrainsGenericCollection.cs @@ -16,7 +16,7 @@ namespace RoadTrain.Generics { private readonly int _pictureWidth; private readonly int _pictureHeight; - private readonly int _placeSizeWidth = 220; + private readonly int _placeSizeWidth = 200; private readonly int _placeSizeHeight = 100; private readonly SetGeneric _collection; public TrainsGenericCollection(int picWidth, int picHeight) diff --git a/RoadTrain/RoadTrain/TrainsGenericStorage.cs b/RoadTrain/RoadTrain/TrainsGenericStorage.cs index f8ba5fd..227fbbc 100644 --- a/RoadTrain/RoadTrain/TrainsGenericStorage.cs +++ b/RoadTrain/RoadTrain/TrainsGenericStorage.cs @@ -23,13 +23,19 @@ namespace RoadTrain.Generics } public void AddSet(string name) { - if (!_trainStorages.ContainsKey(name)) - _trainStorages.Add(name, new TrainsGenericCollection(_pictureWidth, _pictureHeight)); + if (_trainStorages.ContainsKey(name)) + { + return; + } + _trainStorages[name] = new TrainsGenericCollection(_pictureWidth, _pictureHeight); } public void DelSet(string name) { - if (_trainStorages.ContainsKey(name)) - _trainStorages.Remove(name); + if (!_trainStorages.ContainsKey(name)) + { + return; + } + _trainStorages.Remove(name); } public TrainsGenericCollection? this[string ind]