From 58fce949481e97fb7aa58cfc03fccb67b63e96c2 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 23 Oct 2022 15:36:01 +0400 Subject: [PATCH 1/3] Add config form --- ...ocomotive.cs => EntityWarmlyLocomotive.cs} | 0 .../FormLocomotiveConfig.Designer.cs | 359 ++++++++++++++++++ Locomotive/Locomotive/FormLocomotiveConfig.cs | 99 +++++ .../Locomotive/FormLocomotiveConfig.resx | 60 +++ 4 files changed, 518 insertions(+) rename Locomotive/Locomotive/{EntityElectroLocomotive.cs => EntityWarmlyLocomotive.cs} (100%) create mode 100644 Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs create mode 100644 Locomotive/Locomotive/FormLocomotiveConfig.cs create mode 100644 Locomotive/Locomotive/FormLocomotiveConfig.resx diff --git a/Locomotive/Locomotive/EntityElectroLocomotive.cs b/Locomotive/Locomotive/EntityWarmlyLocomotive.cs similarity index 100% rename from Locomotive/Locomotive/EntityElectroLocomotive.cs rename to Locomotive/Locomotive/EntityWarmlyLocomotive.cs diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs new file mode 100644 index 0000000..5072c7a --- /dev/null +++ b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs @@ -0,0 +1,359 @@ +namespace Locomotive +{ + partial class FormLocomotiveConfig + { + /// + /// 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() + { + this.groupBoxConfig = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxFuelStorage = new System.Windows.Forms.CheckBox(); + this.checkBoxPipe = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelDopColor = new System.Windows.Forms.Label(); + this.labelBaseColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxConfig.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelModifiedObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColors); + this.groupBoxConfig.Controls.Add(this.checkBoxFuelStorage); + this.groupBoxConfig.Controls.Add(this.checkBoxPipe); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(12, 12); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Size = new System.Drawing.Size(453, 260); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Configuration"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(312, 200); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(115, 45); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Modified"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(179, 200); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(115, 45); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Simple"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); + // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(179, 26); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(248, 156); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Colors"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Fuchsia; + this.panelPurple.Location = new System.Drawing.Point(193, 102); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(43, 40); + this.panelPurple.TabIndex = 3; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(132, 102); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(43, 40); + this.panelBlack.TabIndex = 2; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(72, 102); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(43, 40); + this.panelGray.TabIndex = 3; + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(11, 102); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(43, 40); + this.panelWhite.TabIndex = 2; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(193, 31); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(43, 40); + this.panelYellow.TabIndex = 1; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.Location = new System.Drawing.Point(72, 31); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(43, 40); + this.panelGreen.TabIndex = 1; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(133, 31); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(43, 40); + this.panelBlue.TabIndex = 1; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(11, 31); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(43, 40); + this.panelRed.TabIndex = 0; + // + // checkBoxFuelStorage + // + this.checkBoxFuelStorage.AutoSize = true; + this.checkBoxFuelStorage.Location = new System.Drawing.Point(7, 158); + this.checkBoxFuelStorage.Name = "checkBoxFuelStorage"; + this.checkBoxFuelStorage.Size = new System.Drawing.Size(146, 24); + this.checkBoxFuelStorage.TabIndex = 5; + this.checkBoxFuelStorage.Text = "Add Fuel Storage"; + this.checkBoxFuelStorage.UseVisualStyleBackColor = true; + // + // checkBoxPipe + // + this.checkBoxPipe.AutoSize = true; + this.checkBoxPipe.Location = new System.Drawing.Point(7, 128); + this.checkBoxPipe.Name = "checkBoxPipe"; + this.checkBoxPipe.Size = new System.Drawing.Size(92, 24); + this.checkBoxPipe.TabIndex = 4; + this.checkBoxPipe.Text = "Add Pipe"; + this.checkBoxPipe.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(75, 75); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(68, 27); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(7, 77); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(63, 20); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Weight: "; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 31); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(69, 27); + this.numericUpDownSpeed.TabIndex = 1; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(6, 33); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(62, 20); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = " Speed: "; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelDopColor); + this.panelObject.Controls.Add(this.labelBaseColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(471, 22); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(419, 250); + this.panelObject.TabIndex = 1; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter); + // + // labelDopColor + // + this.labelDopColor.AllowDrop = true; + this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelDopColor.Location = new System.Drawing.Point(232, 16); + this.labelDopColor.Name = "labelDopColor"; + this.labelDopColor.Size = new System.Drawing.Size(115, 45); + this.labelDopColor.TabIndex = 9; + this.labelDopColor.Text = "Extra Color"; + this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop); + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(69, 16); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(115, 45); + this.labelBaseColor.TabIndex = 8; + this.labelBaseColor.Text = "Base Color"; + this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelBaseColor_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(16, 67); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(386, 168); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(487, 278); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(168, 29); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Add"; + this.buttonAdd.UseVisualStyleBackColor = true; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(703, 278); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(170, 29); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormLocomotiveConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(902, 315); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormLocomotiveConfig"; + this.Text = "Object Creation"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxConfig; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private CheckBox checkBoxFuelStorage; + private CheckBox checkBoxPipe; + private GroupBox groupBoxColors; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelGreen; + private Panel panelBlue; + private Label labelSimpleObject; + private Label labelModifiedObject; + private Panel panelObject; + private PictureBox pictureBoxObject; + private Label labelDopColor; + private Label labelBaseColor; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.cs b/Locomotive/Locomotive/FormLocomotiveConfig.cs new file mode 100644 index 0000000..b5f52ec --- /dev/null +++ b/Locomotive/Locomotive/FormLocomotiveConfig.cs @@ -0,0 +1,99 @@ +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 Locomotive +{ + public partial class FormLocomotiveConfig : Form + { + DrawningLocomotive _locomotive = null; + + public FormLocomotiveConfig() + { + 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; + } + + 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)) + { + 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": + _locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _locomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + Color.White, Color.Black, + checkBoxPipe.Checked, checkBoxFuelStorage.Checked); + break; + } + DrawLocomotive(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void DrawLocomotive() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _locomotive?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); + _locomotive?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + private void labelBaseColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void labelBaseColor_DragDrop(object sender, DragEventArgs e) + { + // ! - TODO + } + + private void labelDopColor_DragDrop(object sender, DragEventArgs e) + { + // ! - TODO + } + } +} diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.resx b/Locomotive/Locomotive/FormLocomotiveConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Locomotive/Locomotive/FormLocomotiveConfig.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 -- 2.25.1 From 6b7a6625db9ea0fe0c85365a85f3bcf8eacff1e7 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 23 Oct 2022 17:02:32 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0.=20=D0=9D=D0=B5=D0=BE=D0=B1=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D0=BE=20=D0=BF=D0=BE=D1=87=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BA=D0=BE=D0=B4=20=D0=B8=20=D1=81=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B8=D1=82=D1=8C=D1=81=D1=8F=20=D1=81=20=D1=82?= =?UTF-8?q?=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=D0=BC?= =?UTF-8?q?=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 15 ++++++ .../Locomotive/DrawningWarmlyLocomotive.cs | 10 ++++ .../FormLocomotiveConfig.Designer.cs | 2 + Locomotive/Locomotive/FormLocomotiveConfig.cs | 47 +++++++++++++++++++ .../Locomotive/FormMapWithSetLocomotives.cs | 30 +++++++++++- Locomotive/Locomotive/LocomotiveDelegate.cs | 10 ++++ 6 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 Locomotive/Locomotive/LocomotiveDelegate.cs diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 827d7d2..9df50a5 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -38,6 +38,21 @@ namespace Locomotive _locomotiveHeight = locomotiveHeight; } + public void SetBaseColor(Color color) + { + if (Locomotive is EntityWarmlyLocomotive) + { + var locomotive = Locomotive as EntityWarmlyLocomotive; + if (locomotive is not null) + { + locomotive = new EntityWarmlyLocomotive(locomotive.Speed, locomotive.Weight, color, locomotive.ExtraColor, locomotive.Pipe, locomotive.FuelStorage); + Locomotive = locomotive; + return; + } + } + Locomotive = new EntityLocomotive(Locomotive.Speed, Locomotive.Weight, color); + } + /// Установка позиции локомотива public void SetPosition(int x, int y, int width, int height) { diff --git a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs index dbb2b78..ca5c0d5 100644 --- a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs +++ b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs @@ -14,6 +14,16 @@ namespace Locomotive Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage); } + public void SetExtraColor(Color color) + { + var LocomotiveWarmly = Locomotive as EntityWarmlyLocomotive; + if (LocomotiveWarmly is not null) + { + LocomotiveWarmly = new EntityWarmlyLocomotive(LocomotiveWarmly.Speed, LocomotiveWarmly.Weight, LocomotiveWarmly.BodyColor, color, LocomotiveWarmly.Pipe, LocomotiveWarmly.FuelStorage); + Locomotive = LocomotiveWarmly; + } + } + public override void DrawTransport(Graphics g) { if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive) diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs index 5072c7a..b17967a 100644 --- a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs +++ b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs @@ -267,6 +267,7 @@ this.labelDopColor.Text = "Extra Color"; this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop); + this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragEnter); // // labelBaseColor // @@ -297,6 +298,7 @@ this.buttonAdd.TabIndex = 2; this.buttonAdd.Text = "Add"; this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); // // buttonCancel // diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.cs b/Locomotive/Locomotive/FormLocomotiveConfig.cs index b5f52ec..98cebd5 100644 --- a/Locomotive/Locomotive/FormLocomotiveConfig.cs +++ b/Locomotive/Locomotive/FormLocomotiveConfig.cs @@ -14,6 +14,25 @@ namespace Locomotive { DrawningLocomotive _locomotive = null; + private event LocomotiveDelegate eventAddLocomotive; + + public void AddEvent(LocomotiveDelegate ev) + { + if (eventAddLocomotive == null) + { + eventAddLocomotive = new LocomotiveDelegate(ev); + } + else + { + eventAddLocomotive += ev; + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + eventAddLocomotive?.Invoke(_locomotive); + Close(); + } + public FormLocomotiveConfig() { InitializeComponent(); @@ -25,6 +44,9 @@ namespace Locomotive panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; + + // ! - TODO buttonCancel.Click with lambda + buttonCancel.Click += (object sender, EventArgs e) => Close(); } private void labelObject_MouseDown(object sender, MouseEventArgs e) @@ -87,13 +109,38 @@ namespace Locomotive } private void labelBaseColor_DragDrop(object sender, DragEventArgs e) + { + // ! - TODO Call method from object _car and set color + + _locomotive.SetBaseColor((Color)e.Data.GetData(typeof(Color))); + DrawLocomotive(); + + } + private void labelDopColor_DragEnter(object sender, DragEventArgs e) { // ! - TODO + + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } } private void labelDopColor_DragDrop(object sender, DragEventArgs e) { // ! - TODO + if (_locomotive is DrawningWarmlyLocomotive) + { + var locomotive = _locomotive as DrawningWarmlyLocomotive; + locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color))); + } + DrawLocomotive(); + } + } } diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index a4dcc05..b8b342b 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -87,7 +87,7 @@ namespace Locomotive /// Добавление объекта private void buttonAddLocomotive_Click(object sender, EventArgs e) { - if (listBoxMaps.SelectedIndex == -1) + /*if (listBoxMaps.SelectedIndex == -1) { return; } @@ -104,8 +104,34 @@ namespace Locomotive { MessageBox.Show("Failed to add object"); } - } + }*/ + + var formCarConfig = new FormLocomotiveConfig(); + // TODO Call method AddEvent from formCarConfig + formCarConfig.AddEvent(new (AddLocomotive)); + formCarConfig.Show(); } + + private void AddLocomotive(DrawningLocomotive locomotive) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1) + { + MessageBox.Show("Object added"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + + else + { + MessageBox.Show("Failed to add object"); + } + + } + /// Удаление объекта private void buttonRemoveLocomotive_Click(object sender, EventArgs e) { diff --git a/Locomotive/Locomotive/LocomotiveDelegate.cs b/Locomotive/Locomotive/LocomotiveDelegate.cs new file mode 100644 index 0000000..813f2bc --- /dev/null +++ b/Locomotive/Locomotive/LocomotiveDelegate.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + public delegate void LocomotiveDelegate(DrawningLocomotive locomotive); +} -- 2.25.1 From 75190e85943b79e59b655ca7b4df4fe5d6d4db4a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 25 Oct 2022 15:44:49 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.=20?= =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=9B=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=E2=84=965?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 7 +++---- .../Locomotive/DrawningWarmlyLocomotive.cs | 7 +++---- .../FormLocomotiveConfig.Designer.cs | 10 ++++++++++ Locomotive/Locomotive/FormLocomotiveConfig.cs | 11 +++------- .../Locomotive/FormMapWithSetLocomotives.cs | 20 ------------------- Locomotive/Locomotive/LocomotiveDelegate.cs | 10 ---------- 6 files changed, 19 insertions(+), 46 deletions(-) delete mode 100644 Locomotive/Locomotive/LocomotiveDelegate.cs diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 9df50a5..9615e6e 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -42,11 +42,10 @@ namespace Locomotive { if (Locomotive is EntityWarmlyLocomotive) { - var locomotive = Locomotive as EntityWarmlyLocomotive; - if (locomotive is not null) + Locomotive = (EntityWarmlyLocomotive)Locomotive; + if (Locomotive is not null) { - locomotive = new EntityWarmlyLocomotive(locomotive.Speed, locomotive.Weight, color, locomotive.ExtraColor, locomotive.Pipe, locomotive.FuelStorage); - Locomotive = locomotive; + Locomotive = new EntityWarmlyLocomotive(Locomotive.Speed, Locomotive.Weight, color, (Locomotive as EntityWarmlyLocomotive).ExtraColor, (Locomotive as EntityWarmlyLocomotive).Pipe, (Locomotive as EntityWarmlyLocomotive).FuelStorage); return; } } diff --git a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs index ca5c0d5..0f3af01 100644 --- a/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs +++ b/Locomotive/Locomotive/DrawningWarmlyLocomotive.cs @@ -16,11 +16,10 @@ namespace Locomotive public void SetExtraColor(Color color) { - var LocomotiveWarmly = Locomotive as EntityWarmlyLocomotive; - if (LocomotiveWarmly is not null) + Locomotive = Locomotive as EntityWarmlyLocomotive; + if (Locomotive is not null) { - LocomotiveWarmly = new EntityWarmlyLocomotive(LocomotiveWarmly.Speed, LocomotiveWarmly.Weight, LocomotiveWarmly.BodyColor, color, LocomotiveWarmly.Pipe, LocomotiveWarmly.FuelStorage); - Locomotive = LocomotiveWarmly; + Locomotive = new EntityWarmlyLocomotive(Locomotive.Speed, Locomotive.Weight, Locomotive.BodyColor, color, (Locomotive as EntityWarmlyLocomotive).Pipe, (Locomotive as EntityWarmlyLocomotive).FuelStorage); } } diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs index b17967a..77cf4bf 100644 --- a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs +++ b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs @@ -204,6 +204,11 @@ // numericUpDownWeight // this.numericUpDownWeight.Location = new System.Drawing.Point(75, 75); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 500, + 0, + 0, + 0}); this.numericUpDownWeight.Name = "numericUpDownWeight"; this.numericUpDownWeight.Size = new System.Drawing.Size(68, 27); this.numericUpDownWeight.TabIndex = 3; @@ -225,6 +230,11 @@ // numericUpDownSpeed // this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 31); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 500, + 0, + 0, + 0}); this.numericUpDownSpeed.Name = "numericUpDownSpeed"; this.numericUpDownSpeed.Size = new System.Drawing.Size(69, 27); this.numericUpDownSpeed.TabIndex = 1; diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.cs b/Locomotive/Locomotive/FormLocomotiveConfig.cs index 98cebd5..f016a97 100644 --- a/Locomotive/Locomotive/FormLocomotiveConfig.cs +++ b/Locomotive/Locomotive/FormLocomotiveConfig.cs @@ -14,13 +14,13 @@ namespace Locomotive { DrawningLocomotive _locomotive = null; - private event LocomotiveDelegate eventAddLocomotive; + private event Action eventAddLocomotive; - public void AddEvent(LocomotiveDelegate ev) + public void AddEvent(Action ev) { if (eventAddLocomotive == null) { - eventAddLocomotive = new LocomotiveDelegate(ev); + eventAddLocomotive = new Action(ev); } else { @@ -45,7 +45,6 @@ namespace Locomotive panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - // ! - TODO buttonCancel.Click with lambda buttonCancel.Click += (object sender, EventArgs e) => Close(); } @@ -110,15 +109,12 @@ namespace Locomotive private void labelBaseColor_DragDrop(object sender, DragEventArgs e) { - // ! - TODO Call method from object _car and set color - _locomotive.SetBaseColor((Color)e.Data.GetData(typeof(Color))); DrawLocomotive(); } private void labelDopColor_DragEnter(object sender, DragEventArgs e) { - // ! - TODO if (e.Data.GetDataPresent(typeof(Color))) { @@ -132,7 +128,6 @@ namespace Locomotive private void labelDopColor_DragDrop(object sender, DragEventArgs e) { - // ! - TODO if (_locomotive is DrawningWarmlyLocomotive) { var locomotive = _locomotive as DrawningWarmlyLocomotive; diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index b8b342b..4c9a0ad 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -87,27 +87,7 @@ namespace Locomotive /// Добавление объекта private void buttonAddLocomotive_Click(object sender, EventArgs e) { - /*if (listBoxMaps.SelectedIndex == -1) - { - return; - } - FormLocomotive form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1) - { - MessageBox.Show("Object added"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Failed to add object"); - } - }*/ - var formCarConfig = new FormLocomotiveConfig(); - // TODO Call method AddEvent from formCarConfig formCarConfig.AddEvent(new (AddLocomotive)); formCarConfig.Show(); } diff --git a/Locomotive/Locomotive/LocomotiveDelegate.cs b/Locomotive/Locomotive/LocomotiveDelegate.cs deleted file mode 100644 index 813f2bc..0000000 --- a/Locomotive/Locomotive/LocomotiveDelegate.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Locomotive -{ - public delegate void LocomotiveDelegate(DrawningLocomotive locomotive); -} -- 2.25.1