diff --git a/Bulldoser/Bulldoser/Drawings/DrawingBulldoser.cs b/Bulldoser/Bulldoser/Drawings/DrawingBulldoser.cs index 8080eec..f87193a 100644 --- a/Bulldoser/Bulldoser/Drawings/DrawingBulldoser.cs +++ b/Bulldoser/Bulldoser/Drawings/DrawingBulldoser.cs @@ -33,15 +33,15 @@ namespace Bulldoser.Drawings Brush grayBrush = new SolidBrush(Color.Gray); if (Bulldoser.Otval) { - g.FillRectangle(blackBrush, _startPosX + 20, _startPosY + 55, 15, 5); - g.FillRectangle(blackBrush, _startPosX + 10, _startPosY + 35, 10, 70); - g.FillRectangle(blackBrush, _startPosX + 0, _startPosY + 100, 10, 5); + g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 55, 15, 5); + g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 35, 10, 70); + g.FillRectangle(additionalBrush, _startPosX + 0, _startPosY + 100, 10, 5); } if (Bulldoser.SeifBatteries) { - g.FillRectangle(blackBrush, _startPosX + 155, _startPosY + 65, 40, 10); - g.FillRectangle(blackBrush, _startPosX + 185, _startPosY + 75, 5, 30); - g.FillRectangle(blackBrush, _startPosX + 175, _startPosY + 75, 5, 30); + g.FillRectangle(additionalBrush, _startPosX + 155, _startPosY + 65, 40, 10); + g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 75, 5, 30); + g.FillRectangle(additionalBrush, _startPosX + 175, _startPosY + 75, 5, 30); } base.DrawTransport(g); diff --git a/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs b/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs index c306959..ed9f1ce 100644 --- a/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs +++ b/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs @@ -10,7 +10,7 @@ namespace Bulldoser.Drawings { public class DrawingTractor { - public EntityTractor? EntityTractor { get; protected set; } + public EntityTractor? EntityTractor { get; set; } protected int _pictureWidth; diff --git a/Bulldoser/Bulldoser/Entities/EntityBulldoser.cs b/Bulldoser/Bulldoser/Entities/EntityBulldoser.cs index 422aaf5..574436a 100644 --- a/Bulldoser/Bulldoser/Entities/EntityBulldoser.cs +++ b/Bulldoser/Bulldoser/Entities/EntityBulldoser.cs @@ -9,7 +9,7 @@ namespace Bulldoser.Entities { public class EntityBulldoser : EntityTractor { - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } public bool Otval { get; private set; } public bool SeifBatteries { get; private set; } public EntityBulldoser(int speed, double weight, Color bodyColor, Color additionalColor, bool otval, diff --git a/Bulldoser/Bulldoser/Entities/EntityTractor.cs b/Bulldoser/Bulldoser/Entities/EntityTractor.cs index b09aab6..67ddf6b 100644 --- a/Bulldoser/Bulldoser/Entities/EntityTractor.cs +++ b/Bulldoser/Bulldoser/Entities/EntityTractor.cs @@ -10,7 +10,7 @@ namespace Bulldoser.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 EntityTractor(int speed, double weight, Color bodyColor) { diff --git a/Bulldoser/Bulldoser/Form2.cs b/Bulldoser/Bulldoser/Form2.cs index d4f932f..09dbd80 100644 --- a/Bulldoser/Bulldoser/Form2.cs +++ b/Bulldoser/Bulldoser/Form2.cs @@ -70,27 +70,31 @@ namespace Bulldoser private void ButtonAddTractor_Click(object sender, EventArgs e) { - if (listBoxStorage.SelectedIndex == -1) return; - - var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty]; - if (obj == null) + if (listBoxStorage.SelectedIndex == -1) { return; } - FormBulldoser form = new(); - if (form.ShowDialog() == DialogResult.OK) + var formBulldozerConfig = new FormBulldoserConfig(); + formBulldozerConfig.AddEvent(usta => { - //проверяем, удалось ли нам загрузить объект - if (obj + form.SelectedTractor > -1) + if (listBoxStorage.SelectedIndex != -1) { - MessageBox.Show("Объект добавлен"); - pictureBoxCollections.Image = obj.ShowTractors(); + var obj = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]; + if (obj != null) + { + if (obj + usta != 1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollections.Image = obj.ShowTractors(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + }); + formBulldozerConfig.Show(); } private void ButtonRemoveTractor_Click(object sender, EventArgs e) diff --git a/Bulldoser/Bulldoser/FormBulldoserConfig.Designer.cs b/Bulldoser/Bulldoser/FormBulldoserConfig.Designer.cs new file mode 100644 index 0000000..438ca14 --- /dev/null +++ b/Bulldoser/Bulldoser/FormBulldoserConfig.Designer.cs @@ -0,0 +1,362 @@ +namespace Bulldoser +{ + partial class FormBulldoserConfig + { + /// + /// 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(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlack = new Panel(); + panelBlue = new Panel(); + panelGray = new Panel(); + panelGreen = new Panel(); + panelWhite = new Panel(); + panelRed = new Panel(); + checkBoxSeifBatteries = new CheckBox(); + checkBoxOtval = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + panelColor = new Panel(); + labelDopColor = new Label(); + labelBaseColor = new Label(); + pictureBoxObject = new PictureBox(); + ButtonOk = new Button(); + buttonCancel = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(labelModifiedObject); + groupBox1.Controls.Add(labelSimpleObject); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(checkBoxSeifBatteries); + groupBox1.Controls.Add(checkBoxOtval); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(label1); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(454, 228); + groupBox1.TabIndex = 1; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(345, 146); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(87, 27); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(247, 146); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(87, 27); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBox2 + // + groupBox2.Controls.Add(panelPurple); + groupBox2.Controls.Add(panelYellow); + groupBox2.Controls.Add(panelBlack); + groupBox2.Controls.Add(panelBlue); + groupBox2.Controls.Add(panelGray); + groupBox2.Controls.Add(panelGreen); + groupBox2.Controls.Add(panelWhite); + groupBox2.Controls.Add(panelRed); + groupBox2.Location = new Point(247, 31); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(185, 106); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(139, 63); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(35, 30); + panelPurple.TabIndex = 7; + panelPurple.MouseDown += panelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(139, 22); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(35, 30); + panelYellow.TabIndex = 3; + panelYellow.MouseDown += panelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(98, 63); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(35, 30); + panelBlack.TabIndex = 6; + panelBlack.MouseDown += panelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(98, 22); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(35, 30); + panelBlue.TabIndex = 2; + panelBlue.MouseDown += panelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(57, 63); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(35, 30); + panelGray.TabIndex = 5; + panelGray.MouseDown += panelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(57, 22); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(35, 30); + panelGreen.TabIndex = 1; + panelGreen.MouseDown += panelColor_MouseDown; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(16, 63); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(35, 30); + panelWhite.TabIndex = 4; + panelWhite.MouseDown += panelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(16, 22); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(35, 30); + panelRed.TabIndex = 0; + panelRed.MouseDown += panelColor_MouseDown; + // + // checkBoxSeifBatteries + // + checkBoxSeifBatteries.AutoSize = true; + checkBoxSeifBatteries.Location = new Point(10, 154); + checkBoxSeifBatteries.Name = "checkBoxSeifBatteries"; + checkBoxSeifBatteries.Size = new Size(208, 19); + checkBoxSeifBatteries.TabIndex = 5; + checkBoxSeifBatteries.Text = "Признак наличия заднего отвала"; + checkBoxSeifBatteries.UseVisualStyleBackColor = true; + // + // checkBoxOtval + // + checkBoxOtval.AutoSize = true; + checkBoxOtval.Location = new Point(10, 119); + checkBoxOtval.Name = "checkBoxOtval"; + checkBoxOtval.Size = new Size(163, 19); + checkBoxOtval.TabIndex = 4; + checkBoxOtval.Text = "Признак наличия отвала"; + checkBoxOtval.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(76, 60); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(73, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(76, 31); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(73, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(10, 62); + label2.Name = "label2"; + label2.Size = new Size(29, 15); + label2.TabIndex = 1; + label2.Text = "Вес:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(10, 33); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 0; + label1.Text = "Скорость:"; + // + // panelColor + // + panelColor.AllowDrop = true; + panelColor.Controls.Add(labelDopColor); + panelColor.Controls.Add(labelBaseColor); + panelColor.Controls.Add(pictureBoxObject); + panelColor.Location = new Point(492, 12); + panelColor.Name = "panelColor"; + panelColor.Size = new Size(276, 184); + panelColor.TabIndex = 2; + panelColor.DragDrop += PanelObject_DragDrop; + panelColor.DragEnter += PanelObject_DragEnter; + // + // labelDopColor + // + labelDopColor.AllowDrop = true; + labelDopColor.BorderStyle = BorderStyle.FixedSingle; + labelDopColor.Location = new Point(164, 10); + labelDopColor.Name = "labelDopColor"; + labelDopColor.Size = new Size(100, 29); + labelDopColor.TabIndex = 2; + labelDopColor.Text = "Доп. цвет"; + labelDopColor.TextAlign = ContentAlignment.MiddleCenter; + labelDopColor.DragDrop += LabelDopColor_DragDrop; + labelDopColor.DragEnter += LabelColor_DragEnter; + labelDopColor.MouseDown += LabelObject_MouseDown; + // + // labelBaseColor + // + labelBaseColor.AllowDrop = true; + labelBaseColor.BorderStyle = BorderStyle.FixedSingle; + labelBaseColor.Location = new Point(12, 10); + labelBaseColor.Name = "labelBaseColor"; + labelBaseColor.Size = new Size(100, 29); + labelBaseColor.TabIndex = 2; + labelBaseColor.Text = "Цвет"; + labelBaseColor.TextAlign = ContentAlignment.MiddleCenter; + labelBaseColor.DragDrop += LabelBaseColor_DragDrop; + labelBaseColor.DragEnter += LabelColor_DragEnter; + labelBaseColor.MouseDown += LabelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(12, 46); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(252, 127); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // ButtonOk + // + ButtonOk.Location = new Point(492, 202); + ButtonOk.Name = "ButtonOk"; + ButtonOk.Size = new Size(100, 32); + ButtonOk.TabIndex = 3; + ButtonOk.Text = "Добавить"; + ButtonOk.UseVisualStyleBackColor = true; + ButtonOk.Click += ButtonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(668, 202); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(100, 32); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormBulldoserConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 247); + Controls.Add(buttonCancel); + Controls.Add(ButtonOk); + Controls.Add(panelColor); + Controls.Add(groupBox1); + Name = "FormBulldoserConfig"; + Text = "FormBulldoserConfig"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBox2; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlack; + private Panel panelBlue; + private Panel panelGray; + private Panel panelGreen; + private Panel panelWhite; + private Panel panelRed; + private CheckBox checkBoxSeifBatteries; + private CheckBox checkBoxOtval; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + private Label label1; + private Panel panelColor; + private Label labelDopColor; + private Label labelBaseColor; + private PictureBox pictureBoxObject; + private Button ButtonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Bulldoser/Bulldoser/FormBulldoserConfig.cs b/Bulldoser/Bulldoser/FormBulldoserConfig.cs new file mode 100644 index 0000000..12d0401 --- /dev/null +++ b/Bulldoser/Bulldoser/FormBulldoserConfig.cs @@ -0,0 +1,144 @@ +using Bulldoser.Drawings; +using Bulldoser.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 Bulldoser +{ + public partial class FormBulldoserConfig : Form + { + /// + /// Переменная-выбранная установка + /// + DrawingTractor? _bulldozer = null; + /// + /// Событие + /// + private event Action EventAddBulldozer; + /// + /// Конструктор + /// + public FormBulldoserConfig() + { + 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; + // TODO buttonCancel.Click with lambda + buttonCancel.Click += (sender, e) => Close(); + } + private void DrawBulldozer() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _bulldozer?.SetPosition(5, 5); + _bulldozer?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + public void AddEvent(Action ev) + { + if (EventAddBulldozer == null) + { + EventAddBulldozer = new Action(ev); + } + else + { + EventAddBulldozer += 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 panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelModifiedObject": + _bulldozer = new DrawingBulldoser((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxSeifBatteries.Checked, + checkBoxOtval.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + case "labelSimpleObject": + _bulldozer = new DrawingTractor((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawBulldozer(); + } + private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) + { + if (_bulldozer != null) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + _bulldozer.EntityTractor.BodyColor = (Color)e.Data.GetData(typeof(Color)); + + } + DrawBulldozer(); + } + } + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (_bulldozer != null && _bulldozer.EntityTractor is EntityBulldoser entitybulldoser) + { + labelDopColor.AllowDrop = true; + } + else + labelDopColor.AllowDrop = false; + + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_bulldozer != null && _bulldozer.EntityTractor is EntityBulldoser entitybulldoser) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + entitybulldoser.AdditionalColor = (Color)e.Data.GetData(typeof(Color)); + + } + DrawBulldozer(); + } + } + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddBulldozer?.Invoke(_bulldozer); + Close(); + } + } +} diff --git a/Bulldoser/Bulldoser/FormBulldoserConfig.resx b/Bulldoser/Bulldoser/FormBulldoserConfig.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/Bulldoser/Bulldoser/FormBulldoserConfig.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