From 8463082f803e47ca132a474386d1844e66e82453 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Tue, 1 Nov 2022 12:58:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=8F=D1=82=D0=B0=D1=8F=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=A0=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=20=D1=81=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormAirBomberConfig.Designer.cs | 1 + AirBomber/AirBomber/FormAirBomberConfig.cs | 25 ++++++++++++++++++- .../AirBomber/FormMapWithSetAirBombers.cs | 23 +++++++---------- .../AirBomber/MapWithSetAirBombersGeneric.cs | 5 ++++ 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs b/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs index a4f6683..4e8ddea 100644 --- a/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs @@ -80,6 +80,7 @@ this.buttonOk.TabIndex = 8; this.buttonOk.Text = "Добавить"; this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); // // panelObject // diff --git a/AirBomber/AirBomber/FormAirBomberConfig.cs b/AirBomber/AirBomber/FormAirBomberConfig.cs index e03fea3..a3b47cd 100644 --- a/AirBomber/AirBomber/FormAirBomberConfig.cs +++ b/AirBomber/AirBomber/FormAirBomberConfig.cs @@ -14,6 +14,8 @@ namespace AirBomber { DrawingAirBomber _airBomber = null; + private event Action EventAddAirBomber; + public FormAirBomberConfig() { InitializeComponent(); @@ -25,6 +27,7 @@ namespace AirBomber panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (object sender, EventArgs e) => Close(); } private void DrawAirBomber() @@ -53,6 +56,18 @@ namespace AirBomber } } + public void AddEvent(Action ev) + { + if (EventAddAirBomber == null) + { + EventAddAirBomber = ev; + } + else + { + EventAddAirBomber += ev; + } + } + private void panelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data.GetData(DataFormats.Text).ToString()) @@ -75,7 +90,7 @@ namespace AirBomber private void labelColor_DragEnter(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(typeof(Color))) + if (e.Data.GetDataPresent(typeof(String))) { e.Effect = DragDropEffects.Copy; } @@ -88,6 +103,7 @@ namespace AirBomber private void labelBaseColor_DragDrop(object sender, DragEventArgs e) { _airBomber?.AirBomber?.setColor(Color.FromName(e.Data.GetData(DataFormats.Text).ToString())); + DrawAirBomber(); } private void labelDopColor_DragDrop(object sender, DragEventArgs e) @@ -95,7 +111,14 @@ namespace AirBomber if (_airBomber.AirBomber is EntityHeavyAirBomber heavyAirBomber) { heavyAirBomber.setDopColor(Color.FromName(e.Data.GetData(DataFormats.Text).ToString())); + DrawAirBomber(); } } + + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddAirBomber?.Invoke(_airBomber); + Close(); + } } } diff --git a/AirBomber/AirBomber/FormMapWithSetAirBombers.cs b/AirBomber/AirBomber/FormMapWithSetAirBombers.cs index f568850..f690fc1 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBombers.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBombers.cs @@ -27,6 +27,10 @@ namespace AirBomber /// private readonly MapsCollection _mapsCollection; + private Action AddAction; + + private DrawingObjectAirBomber returnedAirBomber; + public FormMapWithSetAirBombers() { InitializeComponent(); @@ -36,6 +40,8 @@ namespace AirBomber { comboBoxSelectorMap.Items.Add(elem.Key); } + AddAction = airBomber => { _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].add(new DrawingObjectAirBomber(airBomber)); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();}; } private void buttonAddAirBomber_Click(object sender, EventArgs e) @@ -44,20 +50,9 @@ namespace AirBomber { return; } - FormAirBomber form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - DrawingObjectAirBomber airBomber = new(form.SelectedAirBomber); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airBomber != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + var formAirBomberConfig = new FormAirBomberConfig(); + formAirBomberConfig.AddEvent(AddAction); + formAirBomberConfig.Show(); } private void buttonRemoveAirBomber_Click(object sender, EventArgs e) diff --git a/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs b/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs index 194a3b5..a9704db 100644 --- a/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs @@ -69,6 +69,11 @@ namespace AirBomber { return map._setAirBombers.Remove(position); } + + public void add(T airBomber) + { + _setAirBombers.Insert(airBomber); + } /// /// Вывод всего набора объектов ///