Stage 2 + 3: MapsCollection and additions in form
This commit is contained in:
parent
e769920644
commit
7a6735b1a2
208
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
208
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
@ -29,23 +29,30 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.PanelGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.MapsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.DeleteMapButton = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.AddMapButton = new System.Windows.Forms.Button();
|
||||
this.newMapTextBox = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
|
||||
this.AddAircraftButton = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPostion = new System.Windows.Forms.MaskedTextBox();
|
||||
this.DeleteAircraftButton = new System.Windows.Forms.Button();
|
||||
this.ShowHangarButton = new System.Windows.Forms.Button();
|
||||
this.ShowMapButton = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.ShowMapButton = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.ShowHangarButton = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.DeleteAircraftButton = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPostion = new System.Windows.Forms.MaskedTextBox();
|
||||
this.AddAircraftButton = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.PanelGroupBox.SuspendLayout();
|
||||
this.MapsGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// PanelGroupBox
|
||||
//
|
||||
this.PanelGroupBox.Controls.Add(this.MapsGroupBox);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonDown);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonRight);
|
||||
this.PanelGroupBox.Controls.Add(this.ShowMapButton);
|
||||
@ -55,23 +62,64 @@
|
||||
this.PanelGroupBox.Controls.Add(this.DeleteAircraftButton);
|
||||
this.PanelGroupBox.Controls.Add(this.maskedTextBoxPostion);
|
||||
this.PanelGroupBox.Controls.Add(this.AddAircraftButton);
|
||||
this.PanelGroupBox.Controls.Add(this.comboBoxMapSelection);
|
||||
this.PanelGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.PanelGroupBox.Location = new System.Drawing.Point(600, 0);
|
||||
this.PanelGroupBox.Location = new System.Drawing.Point(690, 0);
|
||||
this.PanelGroupBox.Name = "PanelGroupBox";
|
||||
this.PanelGroupBox.Size = new System.Drawing.Size(200, 450);
|
||||
this.PanelGroupBox.Size = new System.Drawing.Size(200, 623);
|
||||
this.PanelGroupBox.TabIndex = 0;
|
||||
this.PanelGroupBox.TabStop = false;
|
||||
this.PanelGroupBox.Text = "Function panel";
|
||||
//
|
||||
// pictureBox
|
||||
// MapsGroupBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(600, 450);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
this.MapsGroupBox.Controls.Add(this.DeleteMapButton);
|
||||
this.MapsGroupBox.Controls.Add(this.listBoxMaps);
|
||||
this.MapsGroupBox.Controls.Add(this.AddMapButton);
|
||||
this.MapsGroupBox.Controls.Add(this.newMapTextBox);
|
||||
this.MapsGroupBox.Controls.Add(this.comboBoxMapSelection);
|
||||
this.MapsGroupBox.Location = new System.Drawing.Point(6, 22);
|
||||
this.MapsGroupBox.Name = "MapsGroupBox";
|
||||
this.MapsGroupBox.Size = new System.Drawing.Size(188, 260);
|
||||
this.MapsGroupBox.TabIndex = 15;
|
||||
this.MapsGroupBox.TabStop = false;
|
||||
this.MapsGroupBox.Text = "Maps";
|
||||
//
|
||||
// DeleteMapButton
|
||||
//
|
||||
this.DeleteMapButton.Location = new System.Drawing.Point(6, 222);
|
||||
this.DeleteMapButton.Name = "DeleteMapButton";
|
||||
this.DeleteMapButton.Size = new System.Drawing.Size(176, 32);
|
||||
this.DeleteMapButton.TabIndex = 13;
|
||||
this.DeleteMapButton.Text = "Delete map";
|
||||
this.DeleteMapButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteMapButton.Click += new System.EventHandler(this.DeleteMapButton_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(8, 122);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(174, 94);
|
||||
this.listBoxMaps.TabIndex = 12;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// AddMapButton
|
||||
//
|
||||
this.AddMapButton.Location = new System.Drawing.Point(6, 81);
|
||||
this.AddMapButton.Name = "AddMapButton";
|
||||
this.AddMapButton.Size = new System.Drawing.Size(176, 35);
|
||||
this.AddMapButton.TabIndex = 11;
|
||||
this.AddMapButton.Text = "Add map";
|
||||
this.AddMapButton.UseVisualStyleBackColor = true;
|
||||
this.AddMapButton.Click += new System.EventHandler(this.AddMapButton_Click);
|
||||
//
|
||||
// newMapTextBox
|
||||
//
|
||||
this.newMapTextBox.Location = new System.Drawing.Point(6, 22);
|
||||
this.newMapTextBox.Name = "newMapTextBox";
|
||||
this.newMapTextBox.Size = new System.Drawing.Size(176, 23);
|
||||
this.newMapTextBox.TabIndex = 10;
|
||||
//
|
||||
// comboBoxMapSelection
|
||||
//
|
||||
@ -80,66 +128,18 @@
|
||||
this.comboBoxMapSelection.Items.AddRange(new object[] {
|
||||
"1. Simple map",
|
||||
"2. NightSky map"});
|
||||
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 22);
|
||||
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 51);
|
||||
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
|
||||
this.comboBoxMapSelection.Size = new System.Drawing.Size(182, 23);
|
||||
this.comboBoxMapSelection.Size = new System.Drawing.Size(176, 23);
|
||||
this.comboBoxMapSelection.TabIndex = 9;
|
||||
this.comboBoxMapSelection.SelectedIndexChanged += new System.EventHandler(this.comboBoxMapSelection_SelectedIndexChanged);
|
||||
//
|
||||
// AddAircraftButton
|
||||
//
|
||||
this.AddAircraftButton.Location = new System.Drawing.Point(6, 80);
|
||||
this.AddAircraftButton.Name = "AddAircraftButton";
|
||||
this.AddAircraftButton.Size = new System.Drawing.Size(182, 35);
|
||||
this.AddAircraftButton.TabIndex = 10;
|
||||
this.AddAircraftButton.Text = "Add aircraft";
|
||||
this.AddAircraftButton.UseVisualStyleBackColor = true;
|
||||
this.AddAircraftButton.Click += new System.EventHandler(this.AddAircraftButton_Click);
|
||||
//
|
||||
// maskedTextBoxPostion
|
||||
//
|
||||
this.maskedTextBoxPostion.Location = new System.Drawing.Point(6, 139);
|
||||
this.maskedTextBoxPostion.Mask = "00";
|
||||
this.maskedTextBoxPostion.Name = "maskedTextBoxPostion";
|
||||
this.maskedTextBoxPostion.Size = new System.Drawing.Size(182, 23);
|
||||
this.maskedTextBoxPostion.TabIndex = 11;
|
||||
//
|
||||
// DeleteAircraftButton
|
||||
//
|
||||
this.DeleteAircraftButton.Location = new System.Drawing.Point(6, 177);
|
||||
this.DeleteAircraftButton.Name = "DeleteAircraftButton";
|
||||
this.DeleteAircraftButton.Size = new System.Drawing.Size(182, 36);
|
||||
this.DeleteAircraftButton.TabIndex = 12;
|
||||
this.DeleteAircraftButton.Text = "Delete aircraft";
|
||||
this.DeleteAircraftButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteAircraftButton.Click += new System.EventHandler(this.DeleteAircraftButton_Click);
|
||||
//
|
||||
// ShowHangarButton
|
||||
//
|
||||
this.ShowHangarButton.Location = new System.Drawing.Point(6, 258);
|
||||
this.ShowHangarButton.Name = "ShowHangarButton";
|
||||
this.ShowHangarButton.Size = new System.Drawing.Size(182, 30);
|
||||
this.ShowHangarButton.TabIndex = 13;
|
||||
this.ShowHangarButton.Text = "Show hangar";
|
||||
this.ShowHangarButton.UseVisualStyleBackColor = true;
|
||||
this.ShowHangarButton.Click += new System.EventHandler(this.ShowHangarButton_Click);
|
||||
//
|
||||
// ShowMapButton
|
||||
//
|
||||
this.ShowMapButton.Location = new System.Drawing.Point(6, 308);
|
||||
this.ShowMapButton.Name = "ShowMapButton";
|
||||
this.ShowMapButton.Size = new System.Drawing.Size(182, 36);
|
||||
this.ShowMapButton.TabIndex = 14;
|
||||
this.ShowMapButton.Text = "Show map";
|
||||
this.ShowMapButton.UseVisualStyleBackColor = true;
|
||||
this.ShowMapButton.Click += new System.EventHandler(this.ShowMapButton_Click);
|
||||
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(81, 408);
|
||||
this.buttonDown.Location = new System.Drawing.Point(81, 581);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 11;
|
||||
@ -151,48 +151,107 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(117, 408);
|
||||
this.buttonRight.Location = new System.Drawing.Point(117, 581);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 10;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ShowMapButton
|
||||
//
|
||||
this.ShowMapButton.Location = new System.Drawing.Point(6, 483);
|
||||
this.ShowMapButton.Name = "ShowMapButton";
|
||||
this.ShowMapButton.Size = new System.Drawing.Size(182, 36);
|
||||
this.ShowMapButton.TabIndex = 14;
|
||||
this.ShowMapButton.Text = "Show map";
|
||||
this.ShowMapButton.UseVisualStyleBackColor = true;
|
||||
this.ShowMapButton.Click += new System.EventHandler(this.ShowMapButton_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(45, 408);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(45, 581);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ShowHangarButton
|
||||
//
|
||||
this.ShowHangarButton.Location = new System.Drawing.Point(6, 447);
|
||||
this.ShowHangarButton.Name = "ShowHangarButton";
|
||||
this.ShowHangarButton.Size = new System.Drawing.Size(182, 30);
|
||||
this.ShowHangarButton.TabIndex = 13;
|
||||
this.ShowHangarButton.Text = "Show hangar";
|
||||
this.ShowHangarButton.UseVisualStyleBackColor = true;
|
||||
this.ShowHangarButton.Click += new System.EventHandler(this.ShowHangarButton_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(81, 372);
|
||||
this.buttonUp.Location = new System.Drawing.Point(81, 545);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 8;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// DeleteAircraftButton
|
||||
//
|
||||
this.DeleteAircraftButton.Location = new System.Drawing.Point(6, 405);
|
||||
this.DeleteAircraftButton.Name = "DeleteAircraftButton";
|
||||
this.DeleteAircraftButton.Size = new System.Drawing.Size(182, 36);
|
||||
this.DeleteAircraftButton.TabIndex = 12;
|
||||
this.DeleteAircraftButton.Text = "Delete aircraft";
|
||||
this.DeleteAircraftButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteAircraftButton.Click += new System.EventHandler(this.DeleteAircraftButton_Click);
|
||||
//
|
||||
// maskedTextBoxPostion
|
||||
//
|
||||
this.maskedTextBoxPostion.Location = new System.Drawing.Point(6, 358);
|
||||
this.maskedTextBoxPostion.Mask = "00";
|
||||
this.maskedTextBoxPostion.Name = "maskedTextBoxPostion";
|
||||
this.maskedTextBoxPostion.Size = new System.Drawing.Size(182, 23);
|
||||
this.maskedTextBoxPostion.TabIndex = 11;
|
||||
//
|
||||
// AddAircraftButton
|
||||
//
|
||||
this.AddAircraftButton.Location = new System.Drawing.Point(6, 317);
|
||||
this.AddAircraftButton.Name = "AddAircraftButton";
|
||||
this.AddAircraftButton.Size = new System.Drawing.Size(182, 35);
|
||||
this.AddAircraftButton.TabIndex = 10;
|
||||
this.AddAircraftButton.Text = "Add aircraft";
|
||||
this.AddAircraftButton.UseVisualStyleBackColor = true;
|
||||
this.AddAircraftButton.Click += new System.EventHandler(this.AddAircraftButton_Click);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(690, 623);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetAircrafts
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(890, 623);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.PanelGroupBox);
|
||||
this.Name = "FormMapWithSetAircrafts";
|
||||
this.Text = "MapWithSelectedAircrafts";
|
||||
this.PanelGroupBox.ResumeLayout(false);
|
||||
this.PanelGroupBox.PerformLayout();
|
||||
this.MapsGroupBox.ResumeLayout(false);
|
||||
this.MapsGroupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@ -212,5 +271,10 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private GroupBox MapsGroupBox;
|
||||
private Button DeleteMapButton;
|
||||
private ListBox listBoxMaps;
|
||||
private Button AddMapButton;
|
||||
private TextBox newMapTextBox;
|
||||
}
|
||||
}
|
@ -12,52 +12,63 @@ namespace AirFighter
|
||||
{
|
||||
public partial class FormMapWithSetAircrafts : Form
|
||||
{
|
||||
private MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> _mapAircraftsCollectionGeneric;
|
||||
|
||||
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Simple map", new SimpleMap() },
|
||||
|
||||
{"Nightsky map", new NightSkyMap()}
|
||||
};
|
||||
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
public FormMapWithSetAircrafts()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxMapSelection.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxMapSelection.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshMaps()
|
||||
{
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
|
||||
listBoxMaps.Items.Clear();
|
||||
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
|
||||
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAircraftsCollectionGeneric == null)
|
||||
|
||||
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
|
||||
private void comboBoxMapSelection_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxMapSelection.Text)
|
||||
{
|
||||
case "1. Simple map":
|
||||
{
|
||||
map = new SimpleMap();
|
||||
}
|
||||
break;
|
||||
case "2. NightSky map":
|
||||
{
|
||||
map = new NightSkyMap();
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapAircraftsCollectionGeneric = new MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapAircraftsCollectionGeneric = null;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
|
||||
private void AddAircraftButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAircraftsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -65,10 +76,10 @@ namespace AirFighter
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectAircraft aircraft = new(form.SelectedAircraft);
|
||||
if (_mapAircraftsCollectionGeneric + aircraft != -1)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + aircraft != -1)
|
||||
{
|
||||
MessageBox.Show("Object is added");
|
||||
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -79,6 +90,11 @@ namespace AirFighter
|
||||
|
||||
private void DeleteAircraftButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPostion.Text))
|
||||
{
|
||||
return;
|
||||
@ -88,10 +104,10 @@ namespace AirFighter
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPostion.Text);
|
||||
if (_mapAircraftsCollectionGeneric - pos != null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object is deleted");
|
||||
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -101,16 +117,16 @@ namespace AirFighter
|
||||
|
||||
private void ShowHangarButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAircraftsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAircraftsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAircraftsCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -140,7 +156,42 @@ namespace AirFighter
|
||||
}
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapAircraftsCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void AddMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxMapSelection.SelectedIndex == -1 || string.IsNullOrEmpty(newMapTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Not all data is filled", " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxMapSelection.Text))
|
||||
{
|
||||
MessageBox.Show("There is no such map","Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(newMapTextBox.Text, _mapsDict[comboBoxMapSelection.Text]);
|
||||
RefreshMaps();
|
||||
}
|
||||
|
||||
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void DeleteMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DeleteMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
RefreshMaps();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
61
AirFighter/MapsCollection.cs
Normal file
61
AirFighter/MapsCollection.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>> _mapsVault;
|
||||
|
||||
public List<string> Keys => _mapsVault.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_mapsVault = new Dictionary<string, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>>();
|
||||
}
|
||||
|
||||
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
int flag = 0;
|
||||
//TODO addition logic
|
||||
foreach (var mapExp in Keys)
|
||||
{
|
||||
if (mapExp.Contains(name))
|
||||
{
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
if(flag != 1)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteMap(string name)
|
||||
{
|
||||
//TODO deletion logic
|
||||
}
|
||||
|
||||
public MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
//TODO check if map exist logic
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user