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); + } /// /// Вывод всего набора объектов ///