From cd5b790f24bbbf270e4fb544481853c0869ba387 Mon Sep 17 00:00:00 2001 From: Marselchi Date: Fri, 24 Nov 2023 15:14:59 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A4=D1=83=D0=BB=D0=BB=205=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Entities/EntityLiner.cs | 4 +- Liner/FormLinerCollection.cs | 47 ++- Liner/FormLinerConfig.Designer.cs | 356 +++++++++++++++++++ Liner/FormLinerConfig.cs | 170 +++++++++ Liner/FormLinerConfig.resx | 120 +++++++ Liner/Generics/SetGeneric.cs | 2 +- Liner/MainScreen.cs | 9 - Liner/MovingStrategies/DrawingObjectLiner.cs | 1 - 8 files changed, 671 insertions(+), 38 deletions(-) create mode 100644 Liner/FormLinerConfig.Designer.cs create mode 100644 Liner/FormLinerConfig.cs create mode 100644 Liner/FormLinerConfig.resx diff --git a/Liner/Entities/EntityLiner.cs b/Liner/Entities/EntityLiner.cs index 7bb84ee..bbc5598 100644 --- a/Liner/Entities/EntityLiner.cs +++ b/Liner/Entities/EntityLiner.cs @@ -20,11 +20,11 @@ namespace Liner.Entities /// /// Основной цвет /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Доп цвет /// - public Color BottomColor { get; private set; } + public Color BottomColor { get; set; } /// /// Шаг /// diff --git a/Liner/FormLinerCollection.cs b/Liner/FormLinerCollection.cs index 5683fcb..a3fdc6e 100644 --- a/Liner/FormLinerCollection.cs +++ b/Liner/FormLinerCollection.cs @@ -41,24 +41,30 @@ namespace Liner { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var formLinerConfig = new FormLinerConfig(); + formLinerConfig.AddEvent(AddLiner); + formLinerConfig.Show(); + } + + private void AddLiner(DrawingLiner liner) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - MainScreen form = new(); - if (form.ShowDialog() == DialogResult.OK) + if ((obj + liner) != -1) { - if (obj + form.SelectedLiner != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowLiners(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowLiners(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } /// @@ -68,7 +74,6 @@ namespace Liner /// private void ButtonRemoveLiner_Click(object sender, EventArgs e) { - int pos; if (listBoxStorages.SelectedIndex == -1) { return; @@ -83,16 +88,7 @@ namespace Liner { return; } - if (textBoxNumber.Text != "") - { - pos = Convert.ToInt32(textBoxNumber.Text); - } - else - { - MessageBox.Show("Не удалось удалить объект"); - return; - } - pos = 0; + int pos = Convert.ToInt32(textBoxNumber.Text); if (obj - pos) { MessageBox.Show("Объект удален"); @@ -152,7 +148,8 @@ namespace Liner /// /// /// - private void ButtonRefreshCollection_Click(object sender, EventArgs e) + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) { if (listBoxStorages.SelectedIndex == -1) { diff --git a/Liner/FormLinerConfig.Designer.cs b/Liner/FormLinerConfig.Designer.cs new file mode 100644 index 0000000..9b91ab5 --- /dev/null +++ b/Liner/FormLinerConfig.Designer.cs @@ -0,0 +1,356 @@ +namespace Liner +{ + partial class FormLinerConfig + { + /// + /// 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() + { + groupBoxParametrs = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxDeck = new CheckBox(); + checkBoxPool = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + TextWeight = new Label(); + TextSpeed = new Label(); + panelObject = new Panel(); + pictureBoxObject = new PictureBox(); + labelAddColor = new Label(); + labelMainColor = new Label(); + buttonOk = new Button(); + buttonCancel = new Button(); + groupBoxParametrs.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxParametrs + // + groupBoxParametrs.Controls.Add(labelModifiedObject); + groupBoxParametrs.Controls.Add(labelSimpleObject); + groupBoxParametrs.Controls.Add(groupBoxColors); + groupBoxParametrs.Controls.Add(checkBoxDeck); + groupBoxParametrs.Controls.Add(checkBoxPool); + groupBoxParametrs.Controls.Add(numericUpDownWeight); + groupBoxParametrs.Controls.Add(numericUpDownSpeed); + groupBoxParametrs.Controls.Add(TextWeight); + groupBoxParametrs.Controls.Add(TextSpeed); + groupBoxParametrs.Location = new Point(12, 12); + groupBoxParametrs.Name = "groupBoxParametrs"; + groupBoxParametrs.Size = new Size(588, 307); + groupBoxParametrs.TabIndex = 0; + groupBoxParametrs.TabStop = false; + groupBoxParametrs.Text = "Parametrs"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(419, 241); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(120, 50); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Big"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(278, 241); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(120, 50); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Small"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(244, 22); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(338, 200); + groupBoxColors.TabIndex = 6; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Colors"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(248, 110); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(57, 49); + panelPurple.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(175, 110); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(57, 49); + panelBlack.TabIndex = 1; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(97, 110); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(57, 49); + panelGray.TabIndex = 5; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(18, 110); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(57, 49); + panelWhite.TabIndex = 4; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(248, 22); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(57, 49); + panelYellow.TabIndex = 3; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(175, 22); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(57, 49); + panelBlue.TabIndex = 2; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(97, 22); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(57, 49); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(18, 22); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(57, 49); + panelRed.TabIndex = 0; + // + // checkBoxDeck + // + checkBoxDeck.AutoSize = true; + checkBoxDeck.Location = new Point(17, 162); + checkBoxDeck.Name = "checkBoxDeck"; + checkBoxDeck.Size = new Size(110, 19); + checkBoxDeck.TabIndex = 5; + checkBoxDeck.Text = "Additional Deck"; + checkBoxDeck.UseVisualStyleBackColor = true; + // + // checkBoxPool + // + checkBoxPool.AutoSize = true; + checkBoxPool.Location = new Point(17, 137); + checkBoxPool.Name = "checkBoxPool"; + checkBoxPool.Size = new Size(110, 19); + checkBoxPool.TabIndex = 4; + checkBoxPool.Text = "Swimming pool"; + checkBoxPool.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(81, 70); + 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(70, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(81, 41); + 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(70, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // TextWeight + // + TextWeight.AutoSize = true; + TextWeight.Location = new Point(17, 73); + TextWeight.Name = "TextWeight"; + TextWeight.Size = new Size(48, 15); + TextWeight.TabIndex = 1; + TextWeight.Text = "Weight:"; + // + // TextSpeed + // + TextSpeed.AutoSize = true; + TextSpeed.Location = new Point(17, 43); + TextSpeed.Name = "TextSpeed"; + TextSpeed.Size = new Size(42, 15); + TextSpeed.TabIndex = 0; + TextSpeed.Text = "Speed:"; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(626, 56); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(325, 224); + panelObject.TabIndex = 1; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(20, 6); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(292, 218); + pictureBoxObject.TabIndex = 11; + pictureBoxObject.TabStop = false; + // + // labelAddColor + // + labelAddColor.AllowDrop = true; + labelAddColor.BorderStyle = BorderStyle.FixedSingle; + labelAddColor.Location = new Point(801, 7); + labelAddColor.Name = "labelAddColor"; + labelAddColor.Size = new Size(150, 46); + labelAddColor.TabIndex = 10; + labelAddColor.Text = "Additional Color"; + labelAddColor.TextAlign = ContentAlignment.MiddleCenter; + labelAddColor.DragDrop += LabelColor_DragDrop; + labelAddColor.DragEnter += LabelColor_DragEnter; + // + // labelMainColor + // + labelMainColor.AllowDrop = true; + labelMainColor.BorderStyle = BorderStyle.FixedSingle; + labelMainColor.Location = new Point(626, 7); + labelMainColor.Name = "labelMainColor"; + labelMainColor.Size = new Size(150, 46); + labelMainColor.TabIndex = 9; + labelMainColor.Text = "Main Color"; + labelMainColor.TextAlign = ContentAlignment.MiddleCenter; + labelMainColor.DragDrop += LabelColor_DragDrop; + labelMainColor.DragEnter += LabelColor_DragEnter; + // + // buttonOk + // + buttonOk.Location = new Point(626, 290); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(135, 29); + buttonOk.TabIndex = 2; + buttonOk.Text = "Add"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += ButtonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(816, 290); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(135, 29); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormLinerConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(985, 331); + Controls.Add(buttonCancel); + Controls.Add(labelAddColor); + Controls.Add(buttonOk); + Controls.Add(panelObject); + Controls.Add(labelMainColor); + Controls.Add(groupBoxParametrs); + Name = "FormLinerConfig"; + Text = "FormLinerConfig"; + groupBoxParametrs.ResumeLayout(false); + groupBoxParametrs.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxParametrs; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label TextWeight; + private Label TextSpeed; + private GroupBox groupBoxColors; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private CheckBox checkBoxDeck; + private CheckBox checkBoxPool; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Label labelSimpleObject; + private Label labelModifiedObject; + private Panel panelObject; + private PictureBox pictureBoxObject; + private Label labelAddColor; + private Label labelMainColor; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Liner/FormLinerConfig.cs b/Liner/FormLinerConfig.cs new file mode 100644 index 0000000..cdb98b2 --- /dev/null +++ b/Liner/FormLinerConfig.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.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Liner.Drawing; +using Liner.Entities; + +namespace Liner +{ + /// + /// Форма создания объекта + /// + public partial class FormLinerConfig : Form + { + /// + /// Переменная-выбранная машина + /// + DrawingLiner? _liner = null; + /// + /// Событие + /// + private event Action? EventAddLiner; + /// + /// Конструктор + /// + public FormLinerConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (s, a) => Close(); + } + /// + /// Отрисовать лайнер + /// + private void DrawLiner() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _liner?.SetPosition(15, 15); + _liner?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddLiner == null) + { + EventAddLiner = ev; + } + else + { + EventAddLiner += 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; + } + } + /// + /// Передаем информацию при нажатии на Panel с цветом + /// + /// + /// + 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 "labelSimpleObject": + _liner = new DrawingLiner((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _liner = new DrawingBigLiner((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPool.Checked, + checkBoxDeck.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + + DrawLiner(); + } + 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 (_liner == null) + { + return; + } + switch (((Label)sender).Name) + { + case "labelMainColor": + _liner.EntityLiner.BottomColor = (Color)e.Data.GetData(typeof(Color)); + break; + case "labelAddColor": + if (!(_liner is DrawingBigLiner)) + return; + (_liner as DrawingBigLiner).EntityLiner.BodyColor = (Color)e.Data.GetData(typeof(Color)); + break; + } + DrawLiner(); + } + /// + /// Добавление лайнера + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddLiner?.Invoke(_liner); + Close(); + } + + } +} diff --git a/Liner/FormLinerConfig.resx b/Liner/FormLinerConfig.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/Liner/FormLinerConfig.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/Liner/Generics/SetGeneric.cs b/Liner/Generics/SetGeneric.cs index 0e78153..fa66542 100644 --- a/Liner/Generics/SetGeneric.cs +++ b/Liner/Generics/SetGeneric.cs @@ -86,7 +86,7 @@ namespace Liner.Generics { get { - if (_places.Count >= position && position >= 0) + if (_places.Count > position && position >= 0) { return _places[position]; } diff --git a/Liner/MainScreen.cs b/Liner/MainScreen.cs index 0c71647..3cf00ec 100644 --- a/Liner/MainScreen.cs +++ b/Liner/MainScreen.cs @@ -49,11 +49,6 @@ namespace Liner Random random = new(); Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - addColor = dialog.Color; - } _drawingLiner = new DrawingLiner(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor, pictureBoxLiner.Width, pictureBoxLiner.Height); @@ -96,10 +91,6 @@ namespace Liner { addColor = dialog.Color; } - if (dialog.ShowDialog() == DialogResult.OK) - { - mainColor = dialog.Color; - } _drawingLiner = new DrawingBigLiner(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor, Convert.ToBoolean(random.Next(0, 2)), diff --git a/Liner/MovingStrategies/DrawingObjectLiner.cs b/Liner/MovingStrategies/DrawingObjectLiner.cs index aa00f5c..0afe82d 100644 --- a/Liner/MovingStrategies/DrawingObjectLiner.cs +++ b/Liner/MovingStrategies/DrawingObjectLiner.cs @@ -35,5 +35,4 @@ namespace Liner.MovingStrategies public void MoveObject(DirectionType direction) => _drawingLiner?.MoveTransport(direction); } - } -- 2.25.1 From c05b306cb15aeee6f66a6d033839ac6d90bcce81 Mon Sep 17 00:00:00 2001 From: Marselchi Date: Fri, 24 Nov 2023 15:22:12 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/FormLinerCollection.cs | 3 +-- Liner/MovingStrategies/DrawingObjectLiner.cs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Liner/FormLinerCollection.cs b/Liner/FormLinerCollection.cs index a3fdc6e..2464a4b 100644 --- a/Liner/FormLinerCollection.cs +++ b/Liner/FormLinerCollection.cs @@ -148,8 +148,7 @@ namespace Liner /// /// /// - private void ButtonRefreshCollection_Click(object sender, EventArgs - e) + private void ButtonRefreshCollection_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) { diff --git a/Liner/MovingStrategies/DrawingObjectLiner.cs b/Liner/MovingStrategies/DrawingObjectLiner.cs index 0afe82d..aa00f5c 100644 --- a/Liner/MovingStrategies/DrawingObjectLiner.cs +++ b/Liner/MovingStrategies/DrawingObjectLiner.cs @@ -35,4 +35,5 @@ namespace Liner.MovingStrategies public void MoveObject(DirectionType direction) => _drawingLiner?.MoveTransport(direction); } + } -- 2.25.1 From 7dbd8ad01f471249ae615ed86abcb0abf6da5bcc Mon Sep 17 00:00:00 2001 From: Marselchi Date: Fri, 24 Nov 2023 15:24:14 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/MainScreen.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Liner/MainScreen.cs b/Liner/MainScreen.cs index 3cf00ec..0c71647 100644 --- a/Liner/MainScreen.cs +++ b/Liner/MainScreen.cs @@ -49,6 +49,11 @@ namespace Liner Random random = new(); Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + addColor = dialog.Color; + } _drawingLiner = new DrawingLiner(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor, pictureBoxLiner.Width, pictureBoxLiner.Height); @@ -91,6 +96,10 @@ namespace Liner { addColor = dialog.Color; } + if (dialog.ShowDialog() == DialogResult.OK) + { + mainColor = dialog.Color; + } _drawingLiner = new DrawingBigLiner(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor, Convert.ToBoolean(random.Next(0, 2)), -- 2.25.1 From 964619d691665e91a37bb9bc539edde654b75b55 Mon Sep 17 00:00:00 2001 From: Marselchi Date: Fri, 24 Nov 2023 15:27:59 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A1=D0=BD=D0=BE=D0=B2=D0=B0=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=20=D0=BA=D0=BE=D1=81=D1=8F=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/FormLinerCollection.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Liner/FormLinerCollection.cs b/Liner/FormLinerCollection.cs index 2464a4b..5ea71d7 100644 --- a/Liner/FormLinerCollection.cs +++ b/Liner/FormLinerCollection.cs @@ -74,6 +74,7 @@ namespace Liner /// private void ButtonRemoveLiner_Click(object sender, EventArgs e) { + int pos; if (listBoxStorages.SelectedIndex == -1) { return; @@ -88,7 +89,16 @@ namespace Liner { return; } - int pos = Convert.ToInt32(textBoxNumber.Text); + if (textBoxNumber.Text != "") + { + pos = Convert.ToInt32(textBoxNumber.Text); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + return; + } + pos = 0; if (obj - pos) { MessageBox.Show("Объект удален"); -- 2.25.1 From 3983ae497ff5c9605f969a9d1f9db943be1afaa4 Mon Sep 17 00:00:00 2001 From: Marselchi Date: Sun, 3 Dec 2023 14:42:46 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8=20=D1=81=20=D1=86=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Drawing/DrawingBigLiner.cs | 17 ++++++++++++----- Liner/Drawing/DrawingLiner.cs | 16 ++++++++-------- Liner/Entities/EntityBigLiner.cs | 7 ++++++- Liner/Entities/EntityLiner.cs | 10 ++-------- Liner/FormLinerConfig.cs | 4 ++-- Liner/MainScreen.cs | 2 +- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Liner/Drawing/DrawingBigLiner.cs b/Liner/Drawing/DrawingBigLiner.cs index bef1bed..e7888f5 100644 --- a/Liner/Drawing/DrawingBigLiner.cs +++ b/Liner/Drawing/DrawingBigLiner.cs @@ -19,12 +19,12 @@ namespace Liner.Drawing /// Признак наличия доп палубы /// Ширина картинки /// Высота картинки - public DrawingBigLiner(int speed, double weight, Color bodyColor, Color bottomColor, bool swimmingPool, bool deck, int width, int height) - : base(speed,weight,bodyColor,bottomColor,width,height,100,80) + public DrawingBigLiner(int speed, double weight, Color bottomColor, Color bodyColor, bool swimmingPool, bool deck, int width, int height) + : base(speed,weight,bodyColor,width,height,100,80) { if(EntityLiner!= null) { - EntityLiner = new EntityBigLiner(speed, weight, bodyColor, bottomColor, deck, swimmingPool); + EntityLiner = new EntityBigLiner(speed, weight,bottomColor, bodyColor, deck, swimmingPool); } } @@ -41,8 +41,8 @@ namespace Liner.Drawing } Pen pen = new(Color.Black); Brush poolBrush = new SolidBrush(Color.Blue); - Brush bottomBrush = new SolidBrush(EntityLiner.BottomColor); - Brush deckBrush = new SolidBrush(EntityLiner.BodyColor); + Brush bottomBrush = new SolidBrush(liner.BottomColor); + Brush deckBrush = new SolidBrush(liner.BodyColor); // палуба Point[] firstDeck = {new Point(_startPosX + 30, _startPosY), new Point(_startPosX + 30 + 60, _startPosY), new Point(_startPosX + 30 + 60, _startPosY + 20), new Point(_startPosX + 30, _startPosY + 20)}; @@ -76,5 +76,12 @@ namespace Liner.Drawing g.DrawPolygon(pen, bottom);//рисуем нижний корпус if (liner.SwimmingPool) { g.FillPolygon(poolBrush, pool); }//рисуем бассейн } + /// + /// установка цвета большого лайнера + /// + public void SetAddColor(Color color) + { + (EntityLiner as EntityBigLiner).BodyColor = color; + } } } diff --git a/Liner/Drawing/DrawingLiner.cs b/Liner/Drawing/DrawingLiner.cs index eddd0a6..0bbb2e1 100644 --- a/Liner/Drawing/DrawingLiner.cs +++ b/Liner/Drawing/DrawingLiner.cs @@ -63,32 +63,32 @@ namespace Liner.Drawing /// /// Скорость /// Вес лайнера - /// Основной цвет + /// Основной цвет /// Ширина картинки /// Высота картинки - public DrawingLiner(int speed, double weight, Color bodyColor, Color bottomColor, int width, int height) + public DrawingLiner(int speed, double weight, Color bottomColor, int width, int height) { _pictureWidth = width; _pictureHeight = height; - EntityLiner = new EntityLiner(speed, weight, bodyColor, bottomColor); + EntityLiner = new EntityLiner(speed, weight, bottomColor); } /// /// Конструктор /// /// Скорость /// Вес лайнера - /// Основной цвет + /// Основной цвет /// Ширина картинки /// Высота картинки /// Ширина прорисовки лайнера /// Высота прорисовки лайнера - protected DrawingLiner(int speed, double weight, Color bodyColor, Color bottomColor, int width, int height,int linerWidth,int linerHeight) + protected DrawingLiner(int speed, double weight, Color bottomColor, int width, int height,int linerWidth,int linerHeight) { _linerHeight = linerHeight; _linerWidth = linerWidth; _pictureWidth = width; _pictureHeight = height; - EntityLiner = new EntityLiner(speed, weight, bodyColor, bottomColor); + EntityLiner = new EntityLiner(speed, weight, bottomColor); } /// /// Установка позиции @@ -113,8 +113,8 @@ namespace Liner.Drawing return; } Pen pen = new(Color.Black); - Brush bottomBrush = new SolidBrush(EntityLiner.BottomColor); - Brush deckBrush = new SolidBrush(EntityLiner.BodyColor); + Brush bottomBrush = new SolidBrush(EntityLiner.BottomColor); + Brush deckBrush = new SolidBrush(Color.Black);//черная палуба по умолчанию // палуба Point[] firstDeck = {new Point(_startPosX + 30, _startPosY), new Point(_startPosX + 30 + 60, _startPosY), new Point(_startPosX + 30 + 60, _startPosY + 20), new Point(_startPosX + 30, _startPosY + 20)}; diff --git a/Liner/Entities/EntityBigLiner.cs b/Liner/Entities/EntityBigLiner.cs index 387e10e..bffdb30 100644 --- a/Liner/Entities/EntityBigLiner.cs +++ b/Liner/Entities/EntityBigLiner.cs @@ -17,6 +17,10 @@ namespace Liner.Entities /// public bool Deck { get; private set; } /// + /// Доп цвет + /// + public Color BodyColor { get; set; } + /// /// Конструктор с параметрами /// /// Скорость @@ -25,10 +29,11 @@ namespace Liner.Entities /// Дополнительный цвет /// Признак наличия доп палубы /// Признак наличия бассейна - public EntityBigLiner(int speed, double weight, Color bodyColor, Color bottomColor,bool deck, bool swimmingPool) : base(speed, weight, bodyColor,bottomColor) + public EntityBigLiner(int speed, double weight, Color bottomColor,Color bodyColor,bool deck, bool swimmingPool) : base(speed, weight, bottomColor) { Deck = deck; SwimmingPool = swimmingPool; + BodyColor = bodyColor; } } } diff --git a/Liner/Entities/EntityLiner.cs b/Liner/Entities/EntityLiner.cs index bbc5598..e40f871 100644 --- a/Liner/Entities/EntityLiner.cs +++ b/Liner/Entities/EntityLiner.cs @@ -20,10 +20,6 @@ namespace Liner.Entities /// /// Основной цвет /// - public Color BodyColor { get; set; } - /// - /// Доп цвет - /// public Color BottomColor { get; set; } /// /// Шаг @@ -34,13 +30,11 @@ namespace Liner.Entities /// /// Скорость /// Вес лайнера - /// Основной цвет - /// Доп цвет - public EntityLiner(int speed, double weight, Color bodyColor, Color bottomColor) + /// Основной цвет + public EntityLiner(int speed, double weight, Color bottomColor) { Speed = speed; Weight = weight; - BodyColor = bodyColor; BottomColor = bottomColor; } } diff --git a/Liner/FormLinerConfig.cs b/Liner/FormLinerConfig.cs index cdb98b2..4a7e6d6 100644 --- a/Liner/FormLinerConfig.cs +++ b/Liner/FormLinerConfig.cs @@ -113,7 +113,7 @@ namespace Liner { case "labelSimpleObject": _liner = new DrawingLiner((int)numericUpDownSpeed.Value, - (int)numericUpDownWeight.Value, Color.White, Color.Black, pictureBoxObject.Width, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height); break; case "labelModifiedObject": @@ -150,7 +150,7 @@ namespace Liner case "labelAddColor": if (!(_liner is DrawingBigLiner)) return; - (_liner as DrawingBigLiner).EntityLiner.BodyColor = (Color)e.Data.GetData(typeof(Color)); + (_liner as DrawingBigLiner).SetAddColor((Color)e.Data.GetData(typeof(Color))); break; } DrawLiner(); diff --git a/Liner/MainScreen.cs b/Liner/MainScreen.cs index 0c71647..bb6b621 100644 --- a/Liner/MainScreen.cs +++ b/Liner/MainScreen.cs @@ -55,7 +55,7 @@ namespace Liner addColor = dialog.Color; } _drawingLiner = new DrawingLiner(random.Next(100, 300), - random.Next(1000, 3000), mainColor, addColor, + random.Next(1000, 3000), mainColor, pictureBoxLiner.Width, pictureBoxLiner.Height); _drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); -- 2.25.1