diff --git a/RoadTrain/FormTrainConfig.Designer.cs b/RoadTrain/FormTrainConfig.Designer.cs new file mode 100644 index 0000000..3864589 --- /dev/null +++ b/RoadTrain/FormTrainConfig.Designer.cs @@ -0,0 +1,382 @@ +namespace RoadTrain +{ + partial class FormTrainConfig + { + /// + /// 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() + { + groupBox1 = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + groupBox2 = new GroupBox(); + panelWhite = new Panel(); + panelGray = new Panel(); + panelBlack = new Panel(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxSweepingBrush = new CheckBox(); + checkBoxWaterContainer = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + pictureBoxObject = new PictureBox(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelColor = new Label(); + ButtonOk = new Button(); + ButtonCancel = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(labelModifiedObject); + groupBox1.Controls.Add(labelSimpleObject); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(checkBoxSweepingBrush); + groupBox1.Controls.Add(checkBoxWaterContainer); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(labelWeight); + groupBox1.Controls.Add(labelSpeed); + groupBox1.Location = new Point(14, 16); + groupBox1.Margin = new Padding(3, 4, 3, 4); + groupBox1.Name = "groupBox1"; + groupBox1.Padding = new Padding(3, 4, 3, 4); + groupBox1.Size = new Size(677, 309); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(525, 221); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(107, 46); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(403, 221); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(100, 46); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.UseCompatibleTextRendering = true; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBox2 + // + groupBox2.Controls.Add(panelWhite); + groupBox2.Controls.Add(panelGray); + groupBox2.Controls.Add(panelBlack); + groupBox2.Controls.Add(panelPurple); + groupBox2.Controls.Add(panelYellow); + groupBox2.Controls.Add(panelBlue); + groupBox2.Controls.Add(panelGreen); + groupBox2.Controls.Add(panelRed); + groupBox2.Location = new Point(379, 36); + groupBox2.Margin = new Padding(3, 4, 3, 4); + groupBox2.Name = "groupBox2"; + groupBox2.Padding = new Padding(3, 4, 3, 4); + groupBox2.Size = new Size(270, 163); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Цвета"; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(24, 100); + panelWhite.Margin = new Padding(3, 4, 3, 4); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(41, 47); + panelWhite.TabIndex = 0; + panelWhite.MouseDown += PanelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Silver; + panelGray.Location = new Point(83, 100); + panelGray.Margin = new Padding(3, 4, 3, 4); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(41, 47); + panelGray.TabIndex = 0; + panelGray.MouseDown += PanelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(146, 100); + panelBlack.Margin = new Padding(3, 4, 3, 4); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(41, 47); + panelBlack.TabIndex = 0; + panelBlack.MouseDown += PanelColor_MouseDown; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(206, 100); + panelPurple.Margin = new Padding(3, 4, 3, 4); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(41, 47); + panelPurple.TabIndex = 0; + panelPurple.MouseDown += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(206, 32); + panelYellow.Margin = new Padding(3, 4, 3, 4); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(41, 47); + panelYellow.TabIndex = 0; + panelYellow.MouseDown += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.FromArgb(0, 0, 192); + panelBlue.Location = new Point(146, 32); + panelBlue.Margin = new Padding(3, 4, 3, 4); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(41, 47); + panelBlue.TabIndex = 0; + panelBlue.MouseDown += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.FromArgb(0, 192, 0); + panelGreen.Location = new Point(83, 32); + panelGreen.Margin = new Padding(3, 4, 3, 4); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(41, 47); + panelGreen.TabIndex = 0; + panelGreen.MouseDown += PanelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(24, 32); + panelRed.Margin = new Padding(3, 4, 3, 4); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(41, 47); + panelRed.TabIndex = 0; + panelRed.MouseDown += PanelColor_MouseDown; + // + // checkBoxSweepingBrush + // + checkBoxSweepingBrush.AutoSize = true; + checkBoxSweepingBrush.Location = new Point(41, 204); + checkBoxSweepingBrush.Margin = new Padding(3, 4, 3, 4); + checkBoxSweepingBrush.Name = "checkBoxSweepingBrush"; + checkBoxSweepingBrush.Size = new Size(200, 24); + checkBoxSweepingBrush.TabIndex = 5; + checkBoxSweepingBrush.Text = "Признак наличия щетки"; + checkBoxSweepingBrush.UseVisualStyleBackColor = true; + // + // checkBoxWaterContainer + // + checkBoxWaterContainer.AutoSize = true; + checkBoxWaterContainer.Location = new Point(41, 153); + checkBoxWaterContainer.Margin = new Padding(3, 4, 3, 4); + checkBoxWaterContainer.Name = "checkBoxWaterContainer"; + checkBoxWaterContainer.Size = new Size(298, 24); + checkBoxWaterContainer.TabIndex = 4; + checkBoxWaterContainer.Text = "Признак наличия контейнера с водой"; + checkBoxWaterContainer.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(151, 81); + numericUpDownWeight.Margin = new Padding(3, 4, 3, 4); + 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(126, 27); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(151, 33); + numericUpDownSpeed.Margin = new Padding(3, 4, 3, 4); + 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(126, 27); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(41, 84); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(36, 20); + labelWeight.TabIndex = 1; + labelWeight.Text = "Вес:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(21, 36); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(76, 20); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(54, 61); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(190, 144); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(697, 20); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(288, 233); + panelObject.TabIndex = 2; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(160, 11); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(84, 41); + labelAdditionalColor.TabIndex = 3; + labelAdditionalColor.Text = "Доп.цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(54, 11); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(79, 41); + labelColor.TabIndex = 2; + labelColor.Text = "Цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += labelColor_DragDrop; + labelColor.DragEnter += labelColor_DragEnter; + // + // ButtonOk + // + ButtonOk.Location = new Point(712, 276); + ButtonOk.Name = "ButtonOk"; + ButtonOk.Size = new Size(101, 36); + ButtonOk.TabIndex = 3; + ButtonOk.Text = "Добавить"; + ButtonOk.UseVisualStyleBackColor = true; + ButtonOk.Click += ButtonOk_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(871, 276); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(102, 36); + ButtonCancel.TabIndex = 4; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + // + // FormTrainConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1015, 341); + Controls.Add(ButtonCancel); + Controls.Add(ButtonOk); + Controls.Add(panelObject); + Controls.Add(groupBox1); + Margin = new Padding(3, 4, 3, 4); + Name = "FormTrainConfig"; + Text = "FormTrainConfig"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private CheckBox checkBoxWaterContainer; + private CheckBox checkBoxSweepingBrush; + private GroupBox groupBox2; + private Panel panelWhite; + private Panel panelGray; + private Panel panelBlack; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelColor; + private Button ButtonOk; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/RoadTrain/FormTrainConfig.cs b/RoadTrain/FormTrainConfig.cs new file mode 100644 index 0000000..38c1388 --- /dev/null +++ b/RoadTrain/FormTrainConfig.cs @@ -0,0 +1,170 @@ +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; +using RoadTrain.MovementStrategy; +using RoadTrain.DrawningObjects; + +namespace RoadTrain +{ + public partial class FormTrainConfig : Form + { + /// + /// Переменная-выбранный пеозд + /// + DrawningRoadTrain? _train = null; + /// + /// Событие + /// + private event Action EventAddTrain; + public FormTrainConfig() + { + InitializeComponent(); + ButtonCancel.Click += (s, e) => Close(); + 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; + + } + /// + /// Отрисовать машину + /// + 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; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddTrain == null) + { + EventAddTrain = ev; + } + else + { + EventAddTrain += ev; + } + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + 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 DrawningRoadTrain((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _train = new DrawningTrain((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWaterContainer.Checked, + checkBoxSweepingBrush.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + } + + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddTrain?.Invoke(_train); + Close(); + } + + 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; + ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); + switch (((Label)sender).Name) + { + case "labelColor": + _train.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAdditionalColor": + if (!(_train is DrawningTrain)) + { + return; + } + (_train as DrawningTrain).SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawTrain(); + } + } +} +//case "labelSimpleObject": +// obj = new DrawningRoadTrain((int)numericUpDownSpeed.Value, +// (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, +// pictureBoxObject.Height); +// break; +//case "labelModifiedObject": +// obj = new DrawningTrain((int)numericUpDownSpeed.Value, +// (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWaterContainer.Checked, +// checkBoxSweepingBrush.Checked, pictureBoxObject.Width, +// pictureBoxObject.Height); +// break; diff --git a/RoadTrain/FormTrainConfig.resx b/RoadTrain/FormTrainConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RoadTrain/FormTrainConfig.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