From dcaf12050343b3e840038a3d09331ca4e41067eb Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 12 Dec 2022 23:38:47 +0400 Subject: [PATCH] =?UTF-8?q?5=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp1/Direction.cs | 4 - WinFormsApp1/EntityTractor.cs | 2 +- WinFormsApp1/FormMapWithSetTraktor.cs | 37 +-- WinFormsApp1/FormTractor.cs | 6 +- WinFormsApp1/FormTraktorConfig.Designer.cs | 358 +++++++++++++++++++++ WinFormsApp1/FormTraktorConfig.cs | 148 +++++++++ WinFormsApp1/FormTraktorConfig.resx | 120 +++++++ WinFormsApp1/MapWithSetTraktorGeneric.cs | 29 +- WinFormsApp1/MultiTraktor.cs | 13 +- WinFormsApp1/MultiTraktorDraw.cs | 68 ++-- WinFormsApp1/TractorDraw.cs | 37 +-- WinFormsApp1/TraktorDelgete.cs | 10 + 12 files changed, 722 insertions(+), 110 deletions(-) create mode 100644 WinFormsApp1/FormTraktorConfig.Designer.cs create mode 100644 WinFormsApp1/FormTraktorConfig.cs create mode 100644 WinFormsApp1/FormTraktorConfig.resx create mode 100644 WinFormsApp1/TraktorDelgete.cs diff --git a/WinFormsApp1/Direction.cs b/WinFormsApp1/Direction.cs index 7a1c31b..990a12a 100644 --- a/WinFormsApp1/Direction.cs +++ b/WinFormsApp1/Direction.cs @@ -11,9 +11,5 @@ namespace WinFormsApp1 Down = 2, Left = 3, Right = 4, - DRDiagonal = 5, - DLDiagonal = 6, - ULDiagonal = 7, - URDiagonal = 8 } } diff --git a/WinFormsApp1/EntityTractor.cs b/WinFormsApp1/EntityTractor.cs index d7fe3c3..c055e9b 100644 --- a/WinFormsApp1/EntityTractor.cs +++ b/WinFormsApp1/EntityTractor.cs @@ -20,7 +20,7 @@ namespace WinFormsApp1 /// /// Цвет кузова /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг перемещения автомобиля /// diff --git a/WinFormsApp1/FormMapWithSetTraktor.cs b/WinFormsApp1/FormMapWithSetTraktor.cs index 66abe83..dbf51b8 100644 --- a/WinFormsApp1/FormMapWithSetTraktor.cs +++ b/WinFormsApp1/FormMapWithSetTraktor.cs @@ -79,35 +79,32 @@ namespace WinFormsApp1 } } + + private void ButtonAddTraktor_Click(object sender, EventArgs e) + { + var formBusConfig = new FormTraktorConfig(); + formBusConfig.AddEvent(AddTraktor); + formBusConfig.Show(); + } + + private void AddTraktor(TractorDraw traktor) { if (listBoxMaps.SelectedIndex == -1) { return; } - FormTractor form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawningObjectTractor boat = new(traktor); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0) { - if (form.SelectedTractor == null) - { - MessageBox.Show("Сначала создайте объект"); - return; - } - - DrawningObjectTractor bus = new(form.SelectedTractor); - - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } - private void ButtonRemoveTraktor_Click(object sender, EventArgs e) { if (listBoxMaps.SelectedIndex == -1) diff --git a/WinFormsApp1/FormTractor.cs b/WinFormsApp1/FormTractor.cs index 65dae70..d6eb2ed 100644 --- a/WinFormsApp1/FormTractor.cs +++ b/WinFormsApp1/FormTractor.cs @@ -82,10 +82,6 @@ namespace WinFormsApp1 Draw(); } - - - - private void buttonCreateModif_Click(object sender, EventArgs e) { Random random = new Random(); @@ -103,7 +99,7 @@ namespace WinFormsApp1 dopColor = dialogDop.Color; } - _Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor); + _Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor, true, true); SetData(); Draw(); diff --git a/WinFormsApp1/FormTraktorConfig.Designer.cs b/WinFormsApp1/FormTraktorConfig.Designer.cs new file mode 100644 index 0000000..678f10e --- /dev/null +++ b/WinFormsApp1/FormTraktorConfig.Designer.cs @@ -0,0 +1,358 @@ +using System.Windows.Forms; + +namespace WinFormsApp1 +{ + partial class FormTraktorConfig + { + /// + /// 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.labelHardObject = 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.panelYellow = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxBehind = new System.Windows.Forms.CheckBox(); + this.checkBoxAhead = new System.Windows.Forms.CheckBox(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.panel1 = new System.Windows.Forms.Panel(); + this.labelDopColor = new System.Windows.Forms.Label(); + this.labelColor = 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.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelHardObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColors); + this.groupBoxConfig.Controls.Add(this.checkBoxBehind); + this.groupBoxConfig.Controls.Add(this.checkBoxAhead); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(12, 12); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Size = new System.Drawing.Size(423, 197); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Параметры"; + // + // labelHardObject + // + this.labelHardObject.AllowDrop = true; + this.labelHardObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelHardObject.Location = new System.Drawing.Point(314, 127); + this.labelHardObject.Name = "labelHardObject"; + this.labelHardObject.Size = new System.Drawing.Size(94, 40); + this.labelHardObject.TabIndex = 8; + this.labelHardObject.Text = "Продвинутый"; + this.labelHardObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelHardObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.AllowDrop = true; + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(238, 127); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(70, 40); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + 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.panelYellow); + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(238, 22); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(170, 102); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(123, 58); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(30, 30); + this.panelPurple.TabIndex = 2; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(87, 58); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(30, 30); + this.panelBlack.TabIndex = 1; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(123, 22); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(30, 30); + this.panelYellow.TabIndex = 1; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(51, 58); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(30, 30); + this.panelGray.TabIndex = 1; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.SystemColors.HotTrack; + this.panelBlue.Location = new System.Drawing.Point(87, 22); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(30, 30); + this.panelBlue.TabIndex = 1; + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(15, 58); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(30, 30); + this.panelWhite.TabIndex = 1; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.SeaGreen; + this.panelGreen.Location = new System.Drawing.Point(51, 22); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(30, 30); + this.panelGreen.TabIndex = 1; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(15, 22); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(30, 30); + this.panelRed.TabIndex = 0; + // + // checkBoxBehind + // + this.checkBoxBehind.AutoSize = true; + this.checkBoxBehind.Location = new System.Drawing.Point(17, 116); + this.checkBoxBehind.Name = "checkBoxBehind"; + this.checkBoxBehind.Size = new System.Drawing.Size(219, 19); + this.checkBoxBehind.TabIndex = 5; + this.checkBoxBehind.Text = "Признак наличия рыхлителя сзади"; + this.checkBoxBehind.UseVisualStyleBackColor = true; + // + // checkBoxAhead + // + this.checkBoxAhead.AutoSize = true; + this.checkBoxAhead.Location = new System.Drawing.Point(17, 91); + this.checkBoxAhead.Name = "checkBoxAhead"; + this.checkBoxAhead.Size = new System.Drawing.Size(216, 19); + this.checkBoxAhead.TabIndex = 4; + this.checkBoxAhead.Text = "Прищнак наличия ковша спереди"; + this.checkBoxAhead.UseVisualStyleBackColor = true; + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(17, 70); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(26, 15); + this.labelWeight.TabIndex = 3; + this.labelWeight.Text = "Вес"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(17, 41); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(59, 15); + this.labelSpeed.TabIndex = 2; + this.labelSpeed.Text = "Скорость"; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(82, 62); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23); + this.numericUpDownWeight.TabIndex = 1; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(82, 33); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23); + this.numericUpDownSpeed.TabIndex = 0; + // + // panel1 + // + this.panel1.AllowDrop = true; + this.panel1.Controls.Add(this.labelDopColor); + this.panel1.Controls.Add(this.labelColor); + this.panel1.Controls.Add(this.pictureBoxObject); + this.panel1.Location = new System.Drawing.Point(454, 31); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(246, 197); + this.panel1.TabIndex = 1; + this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.Panel1_DragDrop); + this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.Panel1_DragEnter); + // + // labelDopColor + // + this.labelDopColor.AllowDrop = true; + this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelDopColor.Location = new System.Drawing.Point(88, 8); + this.labelDopColor.Name = "labelDopColor"; + this.labelDopColor.Size = new System.Drawing.Size(78, 29); + this.labelDopColor.TabIndex = 10; + this.labelDopColor.Text = "Доп. цвет"; + 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); + // + // labelColor + // + this.labelColor.AllowDrop = true; + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(12, 8); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(70, 29); + this.labelColor.TabIndex = 9; + this.labelColor.Text = "Цвет"; + this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(12, 43); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(231, 151); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(480, 234); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(561, 234); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormTraktorConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(770, 317); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panel1); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormTraktorConfig"; + this.Text = "FormTraktorConfig"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxConfig; + private CheckBox checkBoxBehind; + private CheckBox checkBoxAhead; + private Label labelWeight; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelHardObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelYellow; + private Panel panelGray; + private Panel panelBlue; + private Panel panelWhite; + private Panel panelGreen; + private Panel panelRed; + private Panel panel1; + private Label labelDopColor; + private Label labelColor; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + + } + + +} \ No newline at end of file diff --git a/WinFormsApp1/FormTraktorConfig.cs b/WinFormsApp1/FormTraktorConfig.cs new file mode 100644 index 0000000..c19132b --- /dev/null +++ b/WinFormsApp1/FormTraktorConfig.cs @@ -0,0 +1,148 @@ +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 WinFormsApp1 +{ + public partial class FormTraktorConfig : Form + { + TractorDraw _traktor = null; + private event TraktorDelegate EventAddTraktor; + + public FormTraktorConfig() + { + 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 += (object sender, EventArgs a) => Close(); + } + + private void labelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void DrawTraktor() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _traktor?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); + _traktor?.DrawEntity(gr); + pictureBoxObject.Image = bmp; + } + + public void AddEvent(TraktorDelegate ev) + { + if (EventAddTraktor == null) + { + EventAddTraktor = new TraktorDelegate(ev); + } + else + { + EventAddTraktor += ev; + } + } + + private void Panel1_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.Text)) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void Panel1_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _traktor = new TractorDraw((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, labelColor.BackColor); + break; + case "labelHardObject": + _traktor = new MultiTraktorDraw((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, labelColor.BackColor, labelDopColor.BackColor, + checkBoxAhead.Checked, checkBoxBehind.Checked); + break; + } + DrawTraktor(); + } + + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + var color = e.Data.GetData(typeof(Color)); + if (color != null) + { + (sender as Label).BackColor = (Color)color; + } + if (_traktor != null) + { + _traktor.Tractor.BodyColor = (Color)color; + DrawTraktor(); + } + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_traktor != null && _traktor.Tractor is MultiTraktor entityBulldozer) + { + entityBulldozer.DopColor = (Color)e.Data.GetData(typeof(Color)); + + DrawTraktor(); + } + } + + private void LabelDopColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddTraktor?.Invoke(_traktor); + Close(); + } + } + + +} + diff --git a/WinFormsApp1/FormTraktorConfig.resx b/WinFormsApp1/FormTraktorConfig.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormsApp1/FormTraktorConfig.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/WinFormsApp1/MapWithSetTraktorGeneric.cs b/WinFormsApp1/MapWithSetTraktorGeneric.cs index 750ed9c..a1658f0 100644 --- a/WinFormsApp1/MapWithSetTraktorGeneric.cs +++ b/WinFormsApp1/MapWithSetTraktorGeneric.cs @@ -109,30 +109,29 @@ namespace WinFormsApp1 private void DrawTraktors(Graphics g) { - - int currentWidth = _pictureWidth / _placeSizeWidth - 1; - int currentHeight = _pictureHeight / _placeSizeHeight - 1; + int widthEl = _pictureWidth / _placeSizeWidth; + int heightEl = _pictureHeight / _placeSizeHeight; + int curWidth = 1; + int curHeight = 0; foreach (var traktor in _setTraktors.GetTraktor()) { - traktor?.SetObject( - currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + traktor?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 130, + curHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); traktor?.DrawningObject(g); - if (currentWidth > 0) - { - currentWidth -= 1; - } + if (curWidth < widthEl) + curWidth++; else { - if (currentHeight > 0) - { - currentHeight -= 1; - currentWidth = _pictureWidth / _placeSizeWidth - 1; - } - else return; + curWidth = 1; + curHeight++; + } + if (curHeight > heightEl) + { + return; } } } diff --git a/WinFormsApp1/MultiTraktor.cs b/WinFormsApp1/MultiTraktor.cs index 12f1caa..e0fa979 100644 --- a/WinFormsApp1/MultiTraktor.cs +++ b/WinFormsApp1/MultiTraktor.cs @@ -7,15 +7,14 @@ namespace WinFormsApp1 { internal class MultiTraktor : EntityTractor { - public Color DopColor { get; private set; } - /// Инициализация свойств - /// Скорость - /// Вес трактора - /// Цвет кузова - /// Дополнительный цвет - public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor) + public Color DopColor { get; set; } + public bool dopAhead { get; private set; } + public bool dopBehind { get; private set; } + public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor, bool dopahead, bool dopbehind) : base(speed, weight, bodyColor) { DopColor = dopColor; + dopAhead = dopahead; + dopBehind = dopbehind; } } } diff --git a/WinFormsApp1/MultiTraktorDraw.cs b/WinFormsApp1/MultiTraktorDraw.cs index 7e7c06d..24d5556 100644 --- a/WinFormsApp1/MultiTraktorDraw.cs +++ b/WinFormsApp1/MultiTraktorDraw.cs @@ -7,16 +7,14 @@ namespace WinFormsApp1 { class MultiTraktorDraw : TractorDraw { - /// Инициализация свойств - /// Скорость - /// Вес трактора - /// Цвет кузова - /// Дополнительный цвет - /// Ширина отрисовки автомобиля - /// Высота отрисовки автомобиля - public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor, 188, 100) + public void SetDopColor(Color color) { - Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor); + ((MultiTraktor)Tractor).DopColor = color; + } + + public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor, bool dopahead, bool dopbehind) : base(speed, weight, bodyColor, 188, 100) + { + Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor, dopahead, dopbehind); } public override void DrawEntity(Graphics g) @@ -25,6 +23,10 @@ namespace WinFormsApp1 { return; } + if (!DrawCheck()) + { + return; + } Pen pen_Black_1pxl = new Pen(Color.Black, 1); Pen pen_Black_2pxl = new Pen(Color.Black, 2); Brush brBlack = new SolidBrush(Color.Black); @@ -38,48 +40,54 @@ namespace WinFormsApp1 g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 8, 4, 35); g.DrawRectangle(pen_Black_1pxl, startPosX + 33, startPosY + 34, 10, 15); - point1 = new PointF(startPosX, startPosY + 8); - point2 = new PointF(startPosX + 33, startPosY + 41); - point3 = new PointF(startPosX + 33, startPosY + 34); - point4 = new PointF(startPosX + 7, startPosY + 8); - PointF[] curvePoints = + if (multiTraktor.dopBehind) { + point1 = new PointF(startPosX, startPosY + 8); + point2 = new PointF(startPosX + 33, startPosY + 41); + point3 = new PointF(startPosX + 33, startPosY + 34); + point4 = new PointF(startPosX + 7, startPosY + 8); + PointF[] curvePoints = + { point1, point2, point3, point4 }; - g.FillPolygon(dopBrush, curvePoints); - g.DrawPolygon(pen_Black_1pxl, curvePoints); + g.FillPolygon(dopBrush, curvePoints); + g.DrawPolygon(pen_Black_1pxl, curvePoints); - point1 = new PointF(startPosX + 6, startPosY + 8 + 15); - point2 = new PointF(startPosX + 6, startPosY + 8 + 35); - point3 = new PointF(startPosX + 26, startPosY + 8 + 35); - PointF[] curvePoints2 = -{ + point1 = new PointF(startPosX + 6, startPosY + 8 + 15); + point2 = new PointF(startPosX + 6, startPosY + 8 + 35); + point3 = new PointF(startPosX + 26, startPosY + 8 + 35); + PointF[] curvePoints2 = + { point1, point2, point3 }; - g.FillPolygon(dopBrush, curvePoints2); - g.DrawPolygon(pen_Black_1pxl, curvePoints2); + g.FillPolygon(dopBrush, curvePoints2); + g.DrawPolygon(pen_Black_1pxl, curvePoints2); + } startPosX += 43; base.DrawEntity(g); startPosX -= 43; - point1 = new PointF(startPosX + 43 + 102, startPosY + 30); - point2 = new PointF(startPosX + 43 + 102, startPosY + 65); - point3 = new PointF(startPosX + 43 + 137, startPosY + 65); - - PointF[] curvePoints3 = + if (multiTraktor.dopAhead) { + point1 = new PointF(startPosX + 43 + 102, startPosY + 30); + point2 = new PointF(startPosX + 43 + 102, startPosY + 65); + point3 = new PointF(startPosX + 43 + 137, startPosY + 65); + + PointF[] curvePoints3 = + { point1, point2, point3 }; - g.FillPolygon(dopBrush, curvePoints3); - g.DrawPolygon(pen_Black_1pxl, curvePoints3); + g.FillPolygon(dopBrush, curvePoints3); + g.DrawPolygon(pen_Black_1pxl, curvePoints3); + } } } } diff --git a/WinFormsApp1/TractorDraw.cs b/WinFormsApp1/TractorDraw.cs index d97024e..321deb2 100644 --- a/WinFormsApp1/TractorDraw.cs +++ b/WinFormsApp1/TractorDraw.cs @@ -90,38 +90,19 @@ namespace WinFormsApp1 startPosY -= Tractor.Step; } break; - case Direction.DRDiagonal: - if (startPosX + entWidth + Tractor.Step < pictureWidth && startPosY + entHeight + Tractor.Step < pictureHeight) - { - startPosX += Tractor.Step; - startPosY += Tractor.Step; - } - break; - case Direction.DLDiagonal: - if (startPosY + entHeight + Tractor.Step < pictureHeight && startPosX - 10 - Tractor.Step > 0) - { - startPosY += Tractor.Step; - startPosX -= Tractor.Step; - } - break; - case Direction.URDiagonal: - if (startPosY - Tractor.Step > 0 && startPosX + entWidth + Tractor.Step < pictureWidth) - { - startPosY -= Tractor.Step; - startPosX += Tractor.Step; - } - break; - case Direction.ULDiagonal: - if (startPosY - Tractor.Step > 0 && startPosX - 10 - Tractor.Step > 0) - { - startPosY -= Tractor.Step; - startPosX -= Tractor.Step; - } - break; + } } + public bool DrawCheck() + { + if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue) + { + return false; + } + return true; + } //Отрисовка сущности public virtual void DrawEntity(Graphics g) { diff --git a/WinFormsApp1/TraktorDelgete.cs b/WinFormsApp1/TraktorDelgete.cs new file mode 100644 index 0000000..a097810 --- /dev/null +++ b/WinFormsApp1/TraktorDelgete.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsApp1 +{ + public delegate void TraktorDelegate(TractorDraw traktor); +}