From 9120b1881491e718723d92ecc884d048e6a9b4ee Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Tue, 1 Nov 2022 11:36:52 +0400 Subject: [PATCH 1/6] Add config form --- Liner/Liner/DrawingLiner.cs | 8 + Liner/Liner/DrawingShip.cs | 4 + Liner/Liner/EntityLiner.cs | 2 +- Liner/Liner/EntityShip.cs | 2 +- Liner/Liner/FormShipConfig.Designer.cs | 361 +++++++++++++++++++++++++ Liner/Liner/FormShipConfig.cs | 102 +++++++ Liner/Liner/FormShipConfig.resx | 60 ++++ 7 files changed, 537 insertions(+), 2 deletions(-) create mode 100644 Liner/Liner/FormShipConfig.Designer.cs create mode 100644 Liner/Liner/FormShipConfig.cs create mode 100644 Liner/Liner/FormShipConfig.resx diff --git a/Liner/Liner/DrawingLiner.cs b/Liner/Liner/DrawingLiner.cs index 0d99201..28d4270 100644 --- a/Liner/Liner/DrawingLiner.cs +++ b/Liner/Liner/DrawingLiner.cs @@ -13,6 +13,14 @@ namespace Liner { Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool); } + public void SetDopColor(Color color) + { + if (Ship is not EntityLiner liner) + { + return; + } + liner.DopColor = color; + } public override void DrawTransport(Graphics g) { if (Ship is not EntityLiner liner) diff --git a/Liner/Liner/DrawingShip.cs b/Liner/Liner/DrawingShip.cs index 6a68c2a..156fc36 100644 --- a/Liner/Liner/DrawingShip.cs +++ b/Liner/Liner/DrawingShip.cs @@ -25,6 +25,10 @@ namespace Liner _ShipWidth = shipWidth; _ShipHeight = shipHeight; } + public void SetColor(Color color) + { + Ship.BodyColor = color; + } public void SetPosition(int x, int y, int width, int height) { if (width <= _ShipWidth + x || height <= _ShipHeight + y || x<0 || y<0) diff --git a/Liner/Liner/EntityLiner.cs b/Liner/Liner/EntityLiner.cs index 66b1827..2c552fd 100644 --- a/Liner/Liner/EntityLiner.cs +++ b/Liner/Liner/EntityLiner.cs @@ -8,7 +8,7 @@ namespace Liner { internal class EntityLiner : EntityShip { - public Color DopColor { get; private set; } + public Color DopColor { get; set; } public bool DopDeck { get; private set; } diff --git a/Liner/Liner/EntityShip.cs b/Liner/Liner/EntityShip.cs index 08b2b0b..45807d5 100644 --- a/Liner/Liner/EntityShip.cs +++ b/Liner/Liner/EntityShip.cs @@ -12,7 +12,7 @@ namespace Liner public float Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public float Step => Speed * 100 / Weight; diff --git a/Liner/Liner/FormShipConfig.Designer.cs b/Liner/Liner/FormShipConfig.Designer.cs new file mode 100644 index 0000000..9bd35f7 --- /dev/null +++ b/Liner/Liner/FormShipConfig.Designer.cs @@ -0,0 +1,361 @@ +namespace Liner +{ + partial class FormShipConfig + { + /// + /// 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.labelModifObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelCyan = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxDopDeck = new System.Windows.Forms.CheckBox(); + this.checkBoxPool = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + 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.labelModifObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColors); + this.groupBoxConfig.Controls.Add(this.checkBoxDopDeck); + this.groupBoxConfig.Controls.Add(this.checkBoxPool); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.labelWeight); + 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(492, 243); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Параметры"; + // + // labelModifObject + // + this.labelModifObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifObject.Location = new System.Drawing.Point(366, 159); + this.labelModifObject.Name = "labelModifObject"; + this.labelModifObject.Size = new System.Drawing.Size(115, 46); + this.labelModifObject.TabIndex = 8; + this.labelModifObject.Text = "Продвинутый"; + this.labelModifObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifObject.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(258, 159); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(102, 46); + 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.panelBlack); + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelCyan); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(258, 23); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(223, 134); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(172, 75); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(45, 45); + this.panelBlack.TabIndex = 1; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(121, 77); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(45, 45); + this.panelPurple.TabIndex = 1; + // + // panelCyan + // + this.panelCyan.BackColor = System.Drawing.Color.Cyan; + this.panelCyan.Location = new System.Drawing.Point(57, 77); + this.panelCyan.Name = "panelCyan"; + this.panelCyan.Size = new System.Drawing.Size(45, 45); + this.panelCyan.TabIndex = 1; + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(6, 76); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(45, 45); + this.panelWhite.TabIndex = 1; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(172, 25); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(45, 45); + this.panelBlue.TabIndex = 2; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(121, 25); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(45, 45); + this.panelGreen.TabIndex = 1; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(57, 26); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(45, 45); + this.panelYellow.TabIndex = 1; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(6, 25); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(45, 45); + this.panelRed.TabIndex = 0; + // + // checkBoxDopDeck + // + this.checkBoxDopDeck.AutoSize = true; + this.checkBoxDopDeck.Location = new System.Drawing.Point(6, 159); + this.checkBoxDopDeck.Name = "checkBoxDopDeck"; + this.checkBoxDopDeck.Size = new System.Drawing.Size(243, 24); + this.checkBoxDopDeck.TabIndex = 5; + this.checkBoxDopDeck.Text = "Признак наличия доп. палубы"; + this.checkBoxDopDeck.UseVisualStyleBackColor = true; + // + // checkBoxPool + // + this.checkBoxPool.AutoSize = true; + this.checkBoxPool.Location = new System.Drawing.Point(6, 119); + this.checkBoxPool.Name = "checkBoxPool"; + this.checkBoxPool.Size = new System.Drawing.Size(223, 24); + this.checkBoxPool.TabIndex = 4; + this.checkBoxPool.Text = "Признак наличия бассейна"; + this.checkBoxPool.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(88, 66); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 33); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 60, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(6, 73); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(36, 20); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес:"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(0, 40); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(76, 20); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость:"; + // + // 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(510, 21); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(250, 204); + 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(130, 8); + this.LabelDopColor.Name = "LabelDopColor"; + this.LabelDopColor.Size = new System.Drawing.Size(117, 46); + this.LabelDopColor.TabIndex = 8; + 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.LabelBaseColor_DragEnter); + // + // LabelBaseColor + // + this.LabelBaseColor.AllowDrop = true; + this.LabelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelBaseColor.Location = new System.Drawing.Point(3, 8); + this.LabelBaseColor.Name = "LabelBaseColor"; + this.LabelBaseColor.Size = new System.Drawing.Size(117, 46); + this.LabelBaseColor.TabIndex = 8; + this.LabelBaseColor.Text = "Цвет"; + 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(3, 57); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(244, 144); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(513, 231); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + 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(663, 231); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormShipConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(770, 267); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormShipConfig"; + this.Text = "Создание объекта"; + 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 Label labelModifObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + private Panel panelBlack; + private Panel panelPurple; + private Panel panelCyan; + private Panel panelWhite; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelYellow; + private Panel panelRed; + private CheckBox checkBoxDopDeck; + private CheckBox checkBoxPool; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private Panel panelObject; + private Label LabelDopColor; + private Label LabelBaseColor; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Liner/Liner/FormShipConfig.cs b/Liner/Liner/FormShipConfig.cs new file mode 100644 index 0000000..7a60a3e --- /dev/null +++ b/Liner/Liner/FormShipConfig.cs @@ -0,0 +1,102 @@ +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 Liner +{ + public partial class FormShipConfig : Form + { + DrawingShip _ship=null; + public FormShipConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelCyan.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(); + } + public void DrawShip() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); + _ship?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, 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 "labelSimple": + _ship = new DrawingShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); + break; + case "labelModif": + _ship = new DrawningLiner((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, + checkBoxDopDeck.Checked, checkBoxPool.Checked); + break; + } + DrawShip(); + } + 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) + { + _ship.SetColor((Color)e.Data.GetData(typeof(Color))); + DrawShip(); + } + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_ship is not DrawningLiner liner) + { + return; + } + liner.SetDopColor((Color)e.Data.GetData(typeof(Color))); + DrawShip(); + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } + } +} diff --git a/Liner/Liner/FormShipConfig.resx b/Liner/Liner/FormShipConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Liner/Liner/FormShipConfig.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 From 6999084ee6f026b8da30a1b2b3f57b4574e41691 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Tue, 1 Nov 2022 11:58:16 +0400 Subject: [PATCH 2/6] Event work --- Liner/Liner/FormMapWithSetShips.cs | 26 ++++++++++++++------------ Liner/Liner/FormShipConfig.Designer.cs | 22 +++++++++++++++++++++- Liner/Liner/FormShipConfig.cs | 16 ++++++++++++++-- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Liner/Liner/FormMapWithSetShips.cs b/Liner/Liner/FormMapWithSetShips.cs index 340096c..bce36f8 100644 --- a/Liner/Liner/FormMapWithSetShips.cs +++ b/Liner/Liner/FormMapWithSetShips.cs @@ -50,25 +50,27 @@ namespace Liner } } private void ButtonAddShip_Click(object sender, EventArgs e) + { + var formShipConfig = new FormShipConfig(); + formShipConfig.AddEvent(AddShip); + formShipConfig.Show(); + } + private void AddShip(DrawingShip ship) { if (ListBoxMaps.SelectedIndex == -1) { return; } - FormShip form = new(); - if (form.ShowDialog() == DialogResult.OK) + if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectShip(ship) != -1) { - DrawingObjectShip ship = new(form.SelectedShip); - if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + ship != -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 ButtonRemoveShip_Click(object sender, EventArgs e) { diff --git a/Liner/Liner/FormShipConfig.Designer.cs b/Liner/Liner/FormShipConfig.Designer.cs index 9bd35f7..44ad4be 100644 --- a/Liner/Liner/FormShipConfig.Designer.cs +++ b/Liner/Liner/FormShipConfig.Designer.cs @@ -204,6 +204,16 @@ // numericUpDownWeight // this.numericUpDownWeight.Location = new System.Drawing.Point(88, 66); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); this.numericUpDownWeight.Name = "numericUpDownWeight"; this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27); this.numericUpDownWeight.TabIndex = 3; @@ -216,11 +226,21 @@ // numericUpDownSpeed // this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 33); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); this.numericUpDownSpeed.Name = "numericUpDownSpeed"; this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27); this.numericUpDownSpeed.TabIndex = 2; this.numericUpDownSpeed.Value = new decimal(new int[] { - 60, + 100, 0, 0, 0}); diff --git a/Liner/Liner/FormShipConfig.cs b/Liner/Liner/FormShipConfig.cs index 7a60a3e..e39ac7e 100644 --- a/Liner/Liner/FormShipConfig.cs +++ b/Liner/Liner/FormShipConfig.cs @@ -13,6 +13,7 @@ namespace Liner public partial class FormShipConfig : Form { DrawingShip _ship=null; + private event Action EventAddShip; public FormShipConfig() { InitializeComponent(); @@ -34,6 +35,17 @@ namespace Liner _ship?.DrawTransport(gr); pictureBoxObject.Image = bmp; } + public void AddEvent(Action ev) + { + if (EventAddShip == null) + { + EventAddShip = new Action(ev); + } + else + { + EventAddShip += ev; + } + } private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); @@ -58,10 +70,10 @@ namespace Liner { switch (e.Data.GetData(DataFormats.Text).ToString()) { - case "labelSimple": + case "labelSimpleObject": _ship = new DrawingShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); break; - case "labelModif": + case "labelModifObject": _ship = new DrawningLiner((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxDopDeck.Checked, checkBoxPool.Checked); break; From a576085d7a95c4d37f6dd525529b4eaf2605e99a Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Wed, 2 Nov 2022 10:33:43 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/FormShipConfig.Designer.cs | 2 +- Liner/Liner/FormShipConfig.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Liner/Liner/FormShipConfig.Designer.cs b/Liner/Liner/FormShipConfig.Designer.cs index 44ad4be..5c597eb 100644 --- a/Liner/Liner/FormShipConfig.Designer.cs +++ b/Liner/Liner/FormShipConfig.Designer.cs @@ -287,7 +287,7 @@ 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.LabelBaseColor_DragEnter); + this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter); // // LabelBaseColor // diff --git a/Liner/Liner/FormShipConfig.cs b/Liner/Liner/FormShipConfig.cs index e39ac7e..5814faa 100644 --- a/Liner/Liner/FormShipConfig.cs +++ b/Liner/Liner/FormShipConfig.cs @@ -80,9 +80,9 @@ namespace Liner } DrawShip(); } - private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + private void setDragEffect(DragEventArgs e, Type needTypeData, bool condition) { - if (e.Data.GetDataPresent(typeof(Color))) + if (e.Data.GetDataPresent(needTypeData) && condition) { e.Effect = DragDropEffects.Copy; } @@ -91,11 +91,13 @@ namespace Liner e.Effect = DragDropEffects.None; } } + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _ship != null); + private void LabelDopColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _ship != null && _ship is DrawningLiner); private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { _ship.SetColor((Color)e.Data.GetData(typeof(Color))); DrawShip(); - } + } private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { if (_ship is not DrawningLiner liner) From 7132f8f3225e3a8cd4c187bfebf87e7e1148fa10 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Thu, 3 Nov 2022 14:01:55 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8(Drag?= =?UTF-8?q?=20drop)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/FormShipConfig.Designer.cs | 4 ++-- Liner/Liner/FormShipConfig.cs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Liner/Liner/FormShipConfig.Designer.cs b/Liner/Liner/FormShipConfig.Designer.cs index 5c597eb..fff8435 100644 --- a/Liner/Liner/FormShipConfig.Designer.cs +++ b/Liner/Liner/FormShipConfig.Designer.cs @@ -287,7 +287,7 @@ 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); + this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // LabelBaseColor // @@ -300,7 +300,7 @@ this.LabelBaseColor.Text = "Цвет"; 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); + this.LabelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // pictureBoxObject // diff --git a/Liner/Liner/FormShipConfig.cs b/Liner/Liner/FormShipConfig.cs index 5814faa..169e877 100644 --- a/Liner/Liner/FormShipConfig.cs +++ b/Liner/Liner/FormShipConfig.cs @@ -80,9 +80,9 @@ namespace Liner } DrawShip(); } - private void setDragEffect(DragEventArgs e, Type needTypeData, bool condition) + private void LabelColor_DragEnter(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(needTypeData) && condition) + if (e.Data.GetDataPresent(typeof(Color))) { e.Effect = DragDropEffects.Copy; } @@ -91,16 +91,18 @@ namespace Liner e.Effect = DragDropEffects.None; } } - private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _ship != null); - private void LabelDopColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _ship != null && _ship is DrawningLiner); private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { + if (_ship == null) + { + return; + } _ship.SetColor((Color)e.Data.GetData(typeof(Color))); DrawShip(); } private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - if (_ship is not DrawningLiner liner) + if (_ship == null || _ship is not DrawningLiner liner) { return; } From cc7aadb10dbb56622d7976ede17be62ce079d502 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Thu, 3 Nov 2022 14:31:20 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=95=D1=89=D0=B5=20=D0=BD=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/DrawingLiner.cs | 9 +-------- Liner/Liner/DrawingShip.cs | 5 +---- Liner/Liner/FormShipConfig.cs | 6 +++--- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Liner/Liner/DrawingLiner.cs b/Liner/Liner/DrawingLiner.cs index 28d4270..9ae0a3f 100644 --- a/Liner/Liner/DrawingLiner.cs +++ b/Liner/Liner/DrawingLiner.cs @@ -13,14 +13,7 @@ namespace Liner { Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool); } - public void SetDopColor(Color color) - { - if (Ship is not EntityLiner liner) - { - return; - } - liner.DopColor = color; - } + public override void DrawTransport(Graphics g) { if (Ship is not EntityLiner liner) diff --git a/Liner/Liner/DrawingShip.cs b/Liner/Liner/DrawingShip.cs index 156fc36..427c1ac 100644 --- a/Liner/Liner/DrawingShip.cs +++ b/Liner/Liner/DrawingShip.cs @@ -25,10 +25,7 @@ namespace Liner _ShipWidth = shipWidth; _ShipHeight = shipHeight; } - public void SetColor(Color color) - { - Ship.BodyColor = color; - } + public void SetPosition(int x, int y, int width, int height) { if (width <= _ShipWidth + x || height <= _ShipHeight + y || x<0 || y<0) diff --git a/Liner/Liner/FormShipConfig.cs b/Liner/Liner/FormShipConfig.cs index 169e877..64b7914 100644 --- a/Liner/Liner/FormShipConfig.cs +++ b/Liner/Liner/FormShipConfig.cs @@ -97,16 +97,16 @@ namespace Liner { return; } - _ship.SetColor((Color)e.Data.GetData(typeof(Color))); + _ship.Ship.BodyColor=(Color)e.Data.GetData(typeof(Color)); DrawShip(); } private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - if (_ship == null || _ship is not DrawningLiner liner) + if (_ship == null || _ship.Ship is not EntityLiner liner) { return; } - liner.SetDopColor((Color)e.Data.GetData(typeof(Color))); + liner.DopColor=(Color)e.Data.GetData(typeof(Color)); DrawShip(); } private void ButtonAdd_Click(object sender, EventArgs e) From f4343ce1258f9b35e5c7d83c30d82f1672c08533 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Thu, 3 Nov 2022 14:32:17 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9B=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=B5=D0=BB=D1=8B=20=D1=83=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/DrawingLiner.cs | 1 - Liner/Liner/DrawingShip.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Liner/Liner/DrawingLiner.cs b/Liner/Liner/DrawingLiner.cs index 9ae0a3f..0d99201 100644 --- a/Liner/Liner/DrawingLiner.cs +++ b/Liner/Liner/DrawingLiner.cs @@ -13,7 +13,6 @@ namespace Liner { Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool); } - public override void DrawTransport(Graphics g) { if (Ship is not EntityLiner liner) diff --git a/Liner/Liner/DrawingShip.cs b/Liner/Liner/DrawingShip.cs index 427c1ac..6a68c2a 100644 --- a/Liner/Liner/DrawingShip.cs +++ b/Liner/Liner/DrawingShip.cs @@ -25,7 +25,6 @@ namespace Liner _ShipWidth = shipWidth; _ShipHeight = shipHeight; } - public void SetPosition(int x, int y, int width, int height) { if (width <= _ShipWidth + x || height <= _ShipHeight + y || x<0 || y<0)