всё готово

This commit is contained in:
foxkerik6 2022-11-29 01:56:58 +04:00
parent b82e72038d
commit f3d2973c84
5 changed files with 45 additions and 21 deletions

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
public delegate void AirDelegate(DrawningMilitaryAirplane airplane);
}

View File

@ -334,6 +334,7 @@
this.buttonAdd.TabIndex = 3; this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить"; this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
// //
// buttonCancel // buttonCancel
// //

View File

@ -13,6 +13,7 @@ namespace Stormtrooper
public partial class FormAirConfig : Form public partial class FormAirConfig : Form
{ {
DrawningMilitaryAirplane _airplane = null; DrawningMilitaryAirplane _airplane = null;
private event AirDelegate EventAddAirplane;
public FormAirConfig() public FormAirConfig()
{ {
InitializeComponent(); InitializeComponent();
@ -24,6 +25,7 @@ namespace Stormtrooper
panelCyan.MouseDown += PanelColor_MouseDown; panelCyan.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (object sender, EventArgs e) => Close();
} }
private void DrawAirplane() private void DrawAirplane()
@ -34,6 +36,17 @@ namespace Stormtrooper
_airplane?.DrawAirplane(gr); _airplane?.DrawAirplane(gr);
pictureBoxShow.Image = bmp; pictureBoxShow.Image = bmp;
} }
public void AddEvent(AirDelegate ev)
{
if (EventAddAirplane == null)
{
EventAddAirplane = new AirDelegate(ev);
}
else
{
EventAddAirplane += ev;
}
}
private void label_MouseDown(object sender, MouseEventArgs e) private void label_MouseDown(object sender, MouseEventArgs e)
{ {
@ -118,5 +131,11 @@ namespace Stormtrooper
} }
} }
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddAirplane?.Invoke(_airplane);
Close();
}
} }
} }

View File

@ -78,17 +78,18 @@ namespace Stormtrooper
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{
var formLocomotiveConfig = new FormAirConfig();
formLocomotiveConfig.AddEvent(AddLocomotive);
formLocomotiveConfig.Show();
}
private void AddLocomotive(DrawningMilitaryAirplane drawningMilitaryAirplane)
{ {
if (listBoxMap.SelectedIndex == -1) if (listBoxMap.SelectedIndex == -1)
{ {
return; return;
} }
MainForm form = new(); DrawningObject airplane = new(drawningMilitaryAirplane);
if (form.ShowDialog() == DialogResult.OK)
{
if(form.SelectedAirplane != null)
{
DrawningObject airplane = new (form.SelectedAirplane);
if (_mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty] + airplane != -1) if (_mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
@ -99,13 +100,6 @@ namespace Stormtrooper
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
else
{
MessageBox.Show("Объект не создан");
}
}
}
/// <summary> /// <summary>
/// Удаление объекта /// Удаление объекта
/// </summary> /// </summary>

View File

@ -16,7 +16,7 @@ namespace Stormtrooper
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormAirConfig()); Application.Run(new FormMapWithSetAirplane());
} }
} }
} }