From 82904c3f20650dfe0580b1c25333215f078e1c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 24 Oct 2022 21:49:26 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArtilleryDelegate.cs | 10 + .../DrawingAdvancedArtillery.cs | 10 + .../DrawingArtillery.cs | 5 + .../FormArtilleryConfig.Designer.cs | 381 ++++++++++++++++++ .../FormArtilleryConfig.cs | 123 ++++++ .../FormArtilleryConfig.resx | 60 +++ .../FormMapWithSetArtilleries.cs | 20 +- 7 files changed, 596 insertions(+), 13 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/ArtilleryDelegate.cs create mode 100644 SelfPropelledArtilleryUnit/FormArtilleryConfig.Designer.cs create mode 100644 SelfPropelledArtilleryUnit/FormArtilleryConfig.cs create mode 100644 SelfPropelledArtilleryUnit/FormArtilleryConfig.resx diff --git a/SelfPropelledArtilleryUnit/ArtilleryDelegate.cs b/SelfPropelledArtilleryUnit/ArtilleryDelegate.cs new file mode 100644 index 0000000..745f1fd --- /dev/null +++ b/SelfPropelledArtilleryUnit/ArtilleryDelegate.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + public delegate void ArtilleryDelegate(DrawingArtillery artillery); +} diff --git a/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs index ae60223..3a43065 100644 --- a/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs @@ -38,5 +38,15 @@ namespace Artilleries base.DrawTransport(g); } + + public override void SetBodyColor(Color color) + { + Artillery = new EntityAdvancedArtillery(Artillery.Speed, Artillery.Weight, color, (Artillery as EntityAdvancedArtillery).DopColor, (Artillery as EntityAdvancedArtillery).Weapon, (Artillery as EntityAdvancedArtillery).SalvoBattery); + } + + public void SetDopColor(Color color) + { + Artillery = new EntityAdvancedArtillery(Artillery.Speed, Artillery.Weight, Artillery.BodyColor, color, (Artillery as EntityAdvancedArtillery).Weapon, (Artillery as EntityAdvancedArtillery).SalvoBattery); + } } } diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs index 52f941c..5ea083d 100644 --- a/SelfPropelledArtilleryUnit/DrawingArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingArtillery.cs @@ -124,6 +124,11 @@ namespace Artilleries } } + public virtual void SetBodyColor(Color color) + { + Artillery = new EntityArtillery(Artillery.Speed, Artillery.Weight, color); + } + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return (_startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight - 1); diff --git a/SelfPropelledArtilleryUnit/FormArtilleryConfig.Designer.cs b/SelfPropelledArtilleryUnit/FormArtilleryConfig.Designer.cs new file mode 100644 index 0000000..dc85963 --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormArtilleryConfig.Designer.cs @@ -0,0 +1,381 @@ +namespace Artilleries +{ + partial class FormArtilleryConfig + { + /// + /// 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.groupBoxSettings = new System.Windows.Forms.GroupBox(); + this.labelAdvancedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxSalvoBattery = new System.Windows.Forms.CheckBox(); + this.checkBoxWeapon = 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.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.labelDopColor = new System.Windows.Forms.Label(); + this.labelBaseColor = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxSettings.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(); + // + // groupBoxSettings + // + this.groupBoxSettings.Controls.Add(this.labelAdvancedObject); + this.groupBoxSettings.Controls.Add(this.labelSimpleObject); + this.groupBoxSettings.Controls.Add(this.groupBoxColors); + this.groupBoxSettings.Controls.Add(this.checkBoxSalvoBattery); + this.groupBoxSettings.Controls.Add(this.checkBoxWeapon); + this.groupBoxSettings.Controls.Add(this.numericUpDownWeight); + this.groupBoxSettings.Controls.Add(this.numericUpDownSpeed); + this.groupBoxSettings.Controls.Add(this.labelWeight); + this.groupBoxSettings.Controls.Add(this.labelSpeed); + this.groupBoxSettings.Location = new System.Drawing.Point(12, 12); + this.groupBoxSettings.Name = "groupBoxSettings"; + this.groupBoxSettings.Size = new System.Drawing.Size(538, 244); + this.groupBoxSettings.TabIndex = 0; + this.groupBoxSettings.TabStop = false; + this.groupBoxSettings.Text = "Параметры"; + // + // labelAdvancedObject + // + this.labelAdvancedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdvancedObject.Location = new System.Drawing.Point(414, 187); + this.labelAdvancedObject.Name = "labelAdvancedObject"; + this.labelAdvancedObject.Size = new System.Drawing.Size(100, 38); + this.labelAdvancedObject.TabIndex = 8; + this.labelAdvancedObject.Text = "Продвинутый"; + this.labelAdvancedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdvancedObject.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(305, 187); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(100, 38); + 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.panelGray); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(289, 39); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(243, 126); + 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(181, 74); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(39, 39); + this.panelPurple.TabIndex = 1; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(125, 74); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(39, 39); + this.panelBlack.TabIndex = 1; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(70, 74); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(39, 39); + this.panelGray.TabIndex = 1; + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(16, 74); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(39, 39); + this.panelWhite.TabIndex = 1; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(181, 22); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(39, 39); + this.panelYellow.TabIndex = 1; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(125, 22); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(39, 39); + this.panelBlue.TabIndex = 1; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(70, 22); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(39, 39); + this.panelGreen.TabIndex = 1; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(16, 22); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(39, 39); + this.panelRed.TabIndex = 0; + // + // checkBoxSalvoBattery + // + this.checkBoxSalvoBattery.AutoSize = true; + this.checkBoxSalvoBattery.Location = new System.Drawing.Point(22, 169); + this.checkBoxSalvoBattery.Name = "checkBoxSalvoBattery"; + this.checkBoxSalvoBattery.Size = new System.Drawing.Size(225, 19); + this.checkBoxSalvoBattery.TabIndex = 5; + this.checkBoxSalvoBattery.Text = "Признак наличия залповой батареи"; + this.checkBoxSalvoBattery.UseVisualStyleBackColor = true; + // + // checkBoxWeapon + // + this.checkBoxWeapon.AutoSize = true; + this.checkBoxWeapon.Location = new System.Drawing.Point(22, 133); + this.checkBoxWeapon.Name = "checkBoxWeapon"; + this.checkBoxWeapon.Size = new System.Drawing.Size(165, 19); + this.checkBoxWeapon.TabIndex = 4; + this.checkBoxWeapon.Text = "Признак наличия орудия"; + this.checkBoxWeapon.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(88, 83); + 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(120, 23); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 39); + 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(120, 23); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(20, 85); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(29, 15); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес:"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(20, 41); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(62, 15); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость:"; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Controls.Add(this.labelDopColor); + this.panelObject.Controls.Add(this.labelBaseColor); + this.panelObject.Location = new System.Drawing.Point(556, 12); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(293, 205); + 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); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(29, 61); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(236, 127); + this.pictureBoxObject.TabIndex = 11; + this.pictureBoxObject.TabStop = false; + // + // labelDopColor + // + this.labelDopColor.AllowDrop = true; + this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelDopColor.Location = new System.Drawing.Point(165, 18); + this.labelDopColor.Name = "labelDopColor"; + this.labelDopColor.Size = new System.Drawing.Size(100, 38); + 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.labelColor_DragEnter); + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(29, 18); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(100, 38); + this.labelBaseColor.TabIndex = 9; + 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.labelColor_DragEnter); + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(585, 223); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(100, 33); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(721, 223); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(100, 33); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormArtilleryConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(861, 268); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxSettings); + this.Name = "FormArtilleryConfig"; + this.Text = "FormArtilleryConfig"; + this.groupBoxSettings.ResumeLayout(false); + this.groupBoxSettings.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 groupBoxSettings; + private CheckBox checkBoxWeapon; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private CheckBox checkBoxSalvoBattery; + private Label labelAdvancedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private Panel panelObject; + private PictureBox pictureBoxObject; + private Label labelDopColor; + private Label labelBaseColor; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs b/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs new file mode 100644 index 0000000..50d7e15 --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs @@ -0,0 +1,123 @@ +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 Artilleries +{ + public partial class FormArtilleryConfig : Form + { + DrawingArtillery _artillery = null; + private event ArtilleryDelegate EventAddArtillery; + + public FormArtilleryConfig() + { + 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 += (sender, e) => Close(); + } + + private void DrawArtillery() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _artillery?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height); + _artillery?.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 panelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.Text)) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _artillery = new DrawingArtillery((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); + break; + case "labelAdvancedObject": + _artillery = new DrawingAdvancedArtillery((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWeapon.Checked, checkBoxSalvoBattery.Checked); + break; + } + DrawArtillery(); + } + + private void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + 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 labelBaseColor_DragDrop(object sender, DragEventArgs e) + { + _artillery.SetBodyColor((Color) e.Data.GetData(typeof(Color))); + DrawArtillery(); + } + + private void labelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_artillery is DrawingAdvancedArtillery artillery) + { + artillery.SetDopColor((Color)e.Data.GetData(typeof(Color))); + } + DrawArtillery(); + } + + public void AddEvent(ArtilleryDelegate ev) + { + if (EventAddArtillery == null) + { + EventAddArtillery = new ArtilleryDelegate(ev); + } + else + { + EventAddArtillery += ev; + } + } + + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddArtillery?.Invoke(_artillery); + Close(); + } + + } +} diff --git a/SelfPropelledArtilleryUnit/FormArtilleryConfig.resx b/SelfPropelledArtilleryUnit/FormArtilleryConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormArtilleryConfig.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 diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index a2696c8..46ee05e 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -88,24 +88,18 @@ namespace Artilleries private void buttonAddArtillery_Click(object sender, EventArgs e) { - if (listBoxMaps.SelectedIndex == -1) - { - return; - } - FormArtillery form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - DrawingObjectArtillery artillery = new(form.SelectedArtillery); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + artillery != -1) + var formArtilleryConfig = new FormArtilleryConfig(); + formArtilleryConfig.AddEvent((artillery) => { + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + new DrawingObjectArtillery(artillery) != -1) { MessageBox.Show("Объект добавлен"); - pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else + } else { MessageBox.Show("Не удалось добавить объект"); } - } + pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); + }); + formArtilleryConfig.Show(); } private void buttonRemoveArtillery_Click(object sender, EventArgs e) -- 2.25.1 From 3cee8a2eab971a17292385371aa6308fbc06b361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Tue, 25 Oct 2022 01:57:21 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/FormArtilleryConfig.cs | 1 - SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs b/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs index 50d7e15..51cfc96 100644 --- a/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs +++ b/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs @@ -118,6 +118,5 @@ namespace Artilleries EventAddArtillery?.Invoke(_artillery); Close(); } - } } diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index 46ee05e..f5bdf3a 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -89,7 +89,12 @@ namespace Artilleries private void buttonAddArtillery_Click(object sender, EventArgs e) { var formArtilleryConfig = new FormArtilleryConfig(); - formArtilleryConfig.AddEvent((artillery) => { + formArtilleryConfig.AddEvent((artillery) => { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + new DrawingObjectArtillery(artillery) != -1) { MessageBox.Show("Объект добавлен"); -- 2.25.1 From 5df31a49858538c62bf45686daace72342001ca4 Mon Sep 17 00:00:00 2001 From: ChipsEater Date: Tue, 25 Oct 2022 15:51:51 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/FormArtilleryConfig.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs b/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs index 51cfc96..071033a 100644 --- a/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs +++ b/SelfPropelledArtilleryUnit/FormArtilleryConfig.cs @@ -13,7 +13,7 @@ namespace Artilleries public partial class FormArtilleryConfig : Form { DrawingArtillery _artillery = null; - private event ArtilleryDelegate EventAddArtillery; + private event Action EventAddArtillery; public FormArtilleryConfig() { @@ -101,11 +101,11 @@ namespace Artilleries DrawArtillery(); } - public void AddEvent(ArtilleryDelegate ev) + public void AddEvent(Action ev) { if (EventAddArtillery == null) { - EventAddArtillery = new ArtilleryDelegate(ev); + EventAddArtillery = new Action(ev); } else { -- 2.25.1 From c141d70193d09ef8972bff418cd0786a1d69b576 Mon Sep 17 00:00:00 2001 From: ChipsEater Date: Tue, 25 Oct 2022 16:41:59 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D1=91=D0=BD=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B9=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=B3=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/ArtilleryDelegate.cs | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 SelfPropelledArtilleryUnit/ArtilleryDelegate.cs diff --git a/SelfPropelledArtilleryUnit/ArtilleryDelegate.cs b/SelfPropelledArtilleryUnit/ArtilleryDelegate.cs deleted file mode 100644 index 745f1fd..0000000 --- a/SelfPropelledArtilleryUnit/ArtilleryDelegate.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Artilleries -{ - public delegate void ArtilleryDelegate(DrawingArtillery artillery); -} -- 2.25.1