This commit is contained in:
Кашин Максим 2022-10-16 21:36:34 +04:00
parent 5f2bc387d9
commit 8bd7a3ee39
3 changed files with 188 additions and 83 deletions

View File

@ -29,6 +29,12 @@
private void InitializeComponent()
{
this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.keyRight = new System.Windows.Forms.Button();
this.keyLeft = new System.Windows.Forms.Button();
@ -38,14 +44,15 @@
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveGasolineTanker = new System.Windows.Forms.Button();
this.buttonAddGasolineTanker = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.keyRight);
this.groupBoxTools.Controls.Add(this.keyLeft);
@ -55,24 +62,84 @@
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker);
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(685, 0);
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Location = new System.Drawing.Point(694, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Size = new System.Drawing.Size(229, 664);
this.groupBoxTools.Size = new System.Drawing.Size(200, 629);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools";
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(190, 305);
this.groupBoxMaps.TabIndex = 13;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 241);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(175, 49);
this.buttonDeleteMap.TabIndex = 16;
this.buttonDeleteMap.Text = "Delete Map";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15;
this.listBoxMaps.Location = new System.Drawing.Point(6, 141);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(176, 94);
this.listBoxMaps.TabIndex = 15;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 84);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(176, 51);
this.buttonAddMap.TabIndex = 14;
this.buttonAddMap.Text = "Add Map";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 24);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(178, 23);
this.textBoxNewMapName.TabIndex = 13;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple map",
"Long map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 53);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(178, 23);
this.comboBoxSelectorMap.TabIndex = 12;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(11, 151);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 391);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23);
this.maskedTextBoxPosition.TabIndex = 11;
//
// keyRight
@ -80,10 +147,9 @@
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyRight.Location = new System.Drawing.Point(139, 608);
this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyRight.Location = new System.Drawing.Point(122, 587);
this.keyRight.Name = "keyRight";
this.keyRight.Size = new System.Drawing.Size(34, 40);
this.keyRight.Size = new System.Drawing.Size(30, 30);
this.keyRight.TabIndex = 10;
this.keyRight.UseVisualStyleBackColor = true;
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
@ -93,10 +159,9 @@
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyLeft.Location = new System.Drawing.Point(57, 608);
this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyLeft.Location = new System.Drawing.Point(50, 587);
this.keyLeft.Name = "keyLeft";
this.keyLeft.Size = new System.Drawing.Size(34, 40);
this.keyLeft.Size = new System.Drawing.Size(30, 30);
this.keyLeft.TabIndex = 9;
this.keyLeft.UseVisualStyleBackColor = true;
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@ -106,10 +171,9 @@
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyUp.Location = new System.Drawing.Point(98, 560);
this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyUp.Location = new System.Drawing.Point(86, 551);
this.keyUp.Name = "keyUp";
this.keyUp.Size = new System.Drawing.Size(34, 40);
this.keyUp.Size = new System.Drawing.Size(30, 30);
this.keyUp.TabIndex = 8;
this.keyUp.UseVisualStyleBackColor = true;
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
@ -119,20 +183,18 @@
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyDown.Location = new System.Drawing.Point(98, 608);
this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyDown.Location = new System.Drawing.Point(86, 587);
this.keyDown.Name = "keyDown";
this.keyDown.Size = new System.Drawing.Size(34, 40);
this.keyDown.Size = new System.Drawing.Size(30, 30);
this.keyDown.TabIndex = 7;
this.keyDown.UseVisualStyleBackColor = true;
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(9, 435);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Location = new System.Drawing.Point(8, 500);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45);
this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34);
this.buttonShowOnMap.TabIndex = 4;
this.buttonShowOnMap.Text = "Show on map";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -140,10 +202,9 @@
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(9, 321);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Location = new System.Drawing.Point(8, 460);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(213, 45);
this.buttonShowStorage.Size = new System.Drawing.Size(186, 34);
this.buttonShowStorage.TabIndex = 3;
this.buttonShowStorage.Text = "Show storage";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -151,60 +212,45 @@
//
// buttonRemoveGasolineTanker
//
this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(11, 189);
this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(8, 420);
this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker";
this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45);
this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34);
this.buttonRemoveGasolineTanker.TabIndex = 2;
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
this.buttonRemoveGasolineTanker.Click += new System.EventHandler(this.ButtonRemoveGasolineTanker_Click);
//
// buttonAddGasolineTanker
//
this.buttonAddGasolineTanker.Location = new System.Drawing.Point(9, 97);
this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddGasolineTanker.Location = new System.Drawing.Point(10, 351);
this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45);
this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34);
this.buttonAddGasolineTanker.TabIndex = 1;
this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
this.buttonAddGasolineTanker.Click += new System.EventHandler(this.ButtonAddGasolineTanker_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple map",
"Long map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 29);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28);
this.comboBoxSelectorMap.TabIndex = 12;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(685, 664);
this.pictureBox.Size = new System.Drawing.Size(694, 629);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetGasolineTanker
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(914, 664);
this.ClientSize = new System.Drawing.Size(894, 629);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetGasolineTanker";
this.Text = "FormMapWithSetGasolineTanker";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@ -224,5 +270,10 @@
private Button keyUp;
private Button keyDown;
private MaskedTextBox maskedTextBoxPosition;
private GroupBox groupBoxMaps;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
}
}

View File

@ -12,25 +12,67 @@ namespace GasolineTanker
{
public partial class FormMapWithSetGasolineTanker : Form
{
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Simple map", new SimpleMap() },
{ "Long map", new LongMap() }
};
private MapWithSetGasolienTankerGeneric<DrawingObjectGasolineTanker, AbstractMap> _mapGasolineTankerCollectionGeneric;
private readonly MapsCollection _mapsCollection;
public FormMapWithSetGasolineTanker()
{
InitializeComponent();
}
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ReloadMaps()
{
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 ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private void ButtonAddGasolineTanker_Click(object sender, EventArgs e)
{
if (_mapGasolineTankerCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
FormGasolineTanker form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectGasolineTanker GasolineTanker = new(form.SelectedGasolineTanker);
if (_mapGasolineTankerCollectionGeneric + GasolineTanker >= 0)
DrawingObjectGasolineTanker antiAircraftGun = new(form.SelectedGasolineTanker);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun >= 0)
{
MessageBox.Show("Object added");
pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@ -39,31 +81,9 @@ namespace GasolineTanker
}
}
private void ButtonRemoveGasolineTanker_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Delete object?", "Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapGasolineTankerCollectionGeneric - pos != null)
{
MessageBox.Show("Object deleted");
pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Failed to delete object");
}
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapGasolineTankerCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@ -72,7 +92,7 @@ namespace GasolineTanker
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapGasolineTankerCollectionGeneric == null)
if(listBoxMaps.SelectedIndex == -1)
{
return;
}
@ -80,7 +100,7 @@ namespace GasolineTanker
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapGasolineTankerCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@ -127,5 +147,39 @@ namespace GasolineTanker
_mapGasolineTankerCollectionGeneric = null;
}
}
private void buttonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Not all data saved", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("No such card", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
}
}

View File

@ -117,8 +117,8 @@ namespace GasolineTanker
width += _placeSizeWidth;
if (width > _pictureWidth - _placeSizeWidth)
{
width = _placeSizeWidth / 10;
height += _placeSizeHeight;
width = _pictureWidth / _placeSizeWidth;
height -= _placeSizeHeight;
}
}
}