Изменения в форме

This commit is contained in:
Данила 2022-12-04 16:21:41 +04:00
parent 50da9d8226
commit cea4b0acb6
3 changed files with 147 additions and 52 deletions

View File

@ -29,6 +29,10 @@
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.MapsTextBox = new System.Windows.Forms.MaskedTextBox();
this.buttonMapsAdd = new System.Windows.Forms.Button();
this.ButtonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.ButtonShowOnMap = new System.Windows.Forms.Button();
@ -46,6 +50,10 @@
//
// groupBox1
//
this.groupBox1.Controls.Add(this.MapsTextBox);
this.groupBox1.Controls.Add(this.buttonMapsAdd);
this.groupBox1.Controls.Add(this.ButtonDeleteMap);
this.groupBox1.Controls.Add(this.listBoxMaps);
this.groupBox1.Controls.Add(this.maskedTextBox1);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Controls.Add(this.ButtonShowOnMap);
@ -57,19 +65,57 @@
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(600, 0);
this.groupBox1.Location = new System.Drawing.Point(607, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 450);
this.groupBox1.Size = new System.Drawing.Size(200, 539);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// MapsTextBox
//
this.MapsTextBox.Location = new System.Drawing.Point(7, 22);
this.MapsTextBox.Mask = "00";
this.MapsTextBox.Name = "MapsTextBox";
this.MapsTextBox.Size = new System.Drawing.Size(187, 23);
this.MapsTextBox.TabIndex = 19;
//
// buttonMapsAdd
//
this.buttonMapsAdd.Location = new System.Drawing.Point(7, 80);
this.buttonMapsAdd.Name = "buttonMapsAdd";
this.buttonMapsAdd.Size = new System.Drawing.Size(187, 27);
this.buttonMapsAdd.TabIndex = 18;
this.buttonMapsAdd.Text = "Добавить карту";
this.buttonMapsAdd.UseVisualStyleBackColor = true;
this.buttonMapsAdd.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// ButtonDeleteMap
//
this.ButtonDeleteMap.Location = new System.Drawing.Point(7, 213);
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
this.ButtonDeleteMap.Size = new System.Drawing.Size(187, 27);
this.ButtonDeleteMap.TabIndex = 17;
this.ButtonDeleteMap.Text = "Удалить карту";
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(7, 113);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(187, 94);
this.listBoxMaps.TabIndex = 16;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// maskedTextBox1
//
this.maskedTextBox1.Location = new System.Drawing.Point(7, 159);
this.maskedTextBox1.Location = new System.Drawing.Point(7, 311);
this.maskedTextBox1.Mask = "00";
this.maskedTextBox1.Name = "maskedTextBox1";
this.maskedTextBox1.Size = new System.Drawing.Size(181, 23);
this.maskedTextBox1.Size = new System.Drawing.Size(187, 23);
this.maskedTextBox1.TabIndex = 15;
//
// comboBoxSelectorMap
@ -80,18 +126,17 @@
"Простая карта",
"Пользовательская карта #1",
"Пользовательская карта #2"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 22);
this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 51);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(187, 23);
this.comboBoxSelectorMap.TabIndex = 14;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// ButtonShowOnMap
//
this.ButtonShowOnMap.Location = new System.Drawing.Point(6, 279);
this.ButtonShowOnMap.Location = new System.Drawing.Point(7, 406);
this.ButtonShowOnMap.Name = "ButtonShowOnMap";
this.ButtonShowOnMap.Size = new System.Drawing.Size(188, 27);
this.ButtonShowOnMap.Size = new System.Drawing.Size(187, 27);
this.ButtonShowOnMap.TabIndex = 13;
this.ButtonShowOnMap.Text = "Посмотреть карту";
this.ButtonShowOnMap.UseVisualStyleBackColor = true;
@ -99,9 +144,9 @@
//
// ButtonShowStorage
//
this.ButtonShowStorage.Location = new System.Drawing.Point(6, 246);
this.ButtonShowStorage.Location = new System.Drawing.Point(7, 373);
this.ButtonShowStorage.Name = "ButtonShowStorage";
this.ButtonShowStorage.Size = new System.Drawing.Size(188, 27);
this.ButtonShowStorage.Size = new System.Drawing.Size(187, 27);
this.ButtonShowStorage.TabIndex = 12;
this.ButtonShowStorage.Text = "Посмотреть хранилище";
this.ButtonShowStorage.UseVisualStyleBackColor = true;
@ -109,9 +154,9 @@
//
// ButtonRemoveCar
//
this.ButtonRemoveCar.Location = new System.Drawing.Point(6, 213);
this.ButtonRemoveCar.Location = new System.Drawing.Point(7, 340);
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
this.ButtonRemoveCar.Size = new System.Drawing.Size(188, 27);
this.ButtonRemoveCar.Size = new System.Drawing.Size(187, 27);
this.ButtonRemoveCar.TabIndex = 11;
this.ButtonRemoveCar.Text = "Удалить поезд";
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
@ -119,9 +164,9 @@
//
// ButtonAddLoco
//
this.ButtonAddLoco.Location = new System.Drawing.Point(6, 101);
this.ButtonAddLoco.Location = new System.Drawing.Point(7, 278);
this.ButtonAddLoco.Name = "ButtonAddLoco";
this.ButtonAddLoco.Size = new System.Drawing.Size(188, 27);
this.ButtonAddLoco.Size = new System.Drawing.Size(187, 27);
this.ButtonAddLoco.TabIndex = 9;
this.ButtonAddLoco.Text = "Добавить поезд";
this.ButtonAddLoco.UseVisualStyleBackColor = true;
@ -132,7 +177,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Locomative.Properties.Resources.arrow_up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(80, 350);
this.buttonUp.Location = new System.Drawing.Point(80, 439);
this.buttonUp.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(41, 40);
@ -145,7 +190,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Locomative.Properties.Resources.arrow_down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(80, 398);
this.buttonDown.Location = new System.Drawing.Point(80, 487);
this.buttonDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(41, 40);
@ -158,7 +203,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Locomative.Properties.Resources.arrow_right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(127, 398);
this.buttonRight.Location = new System.Drawing.Point(127, 487);
this.buttonRight.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(41, 40);
@ -171,7 +216,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Locomative.Properties.Resources.arrow_left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(32, 398);
this.buttonLeft.Location = new System.Drawing.Point(32, 487);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(41, 40);
@ -184,7 +229,7 @@
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.Size = new System.Drawing.Size(607, 539);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
@ -192,7 +237,7 @@
//
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(807, 539);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Name = "FormMapWithSetLocomatives";
@ -218,5 +263,9 @@
private Button ButtonAddLoco;
private MaskedTextBox maskedTextBox1;
private ComboBox comboBoxSelectorMap;
private MaskedTextBox MapsTextBox;
private Button buttonMapsAdd;
private Button ButtonDeleteMap;
private ListBox listBoxMaps;
}
}

View File

@ -14,37 +14,82 @@ namespace Locomative
public partial class FormMapWithSetLocomatives : Form
{
private MapWithSetLocoGeneric<DrawningObjectLoco, AbstractMap> _mapLocoCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Пользовательская карта #1", new UserMap_BigBox() },
{ "Пользовательская карта #2", new UserMap_Rally() }
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetLocomatives()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
private void ReloadMaps()
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Пользовательская карта #1":
map = new UserMap_BigBox();
break;
case "Пользовательская карта #2":
map = new UserMap_Rally();
break;
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (map != null)
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >=
listBoxMaps.Items.Count))
{
_mapLocoCollectionGeneric = new MapWithSetLocoGeneric<DrawningObjectLoco, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
listBoxMaps.SelectedIndex = 0;
}
else
else if (listBoxMaps.Items.Count > 0 && index > -1 && index <
listBoxMaps.Items.Count)
{
_mapLocoCollectionGeneric = null;
listBoxMaps.SelectedIndex = index;
}
}
private void ButtonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(MapsTextBox.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(MapsTextBox.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?",
"Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ??
string.Empty);
ReloadMaps();
}
}
private void ButtonAddLoco_Click(object sender, EventArgs e)
{
if (_mapLocoCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@ -52,10 +97,10 @@ namespace Locomative
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectLoco loco = new(form.SelectedLoco);
if ((_mapLocoCollectionGeneric + loco)>=0)
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + loco) >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapLocoCollectionGeneric.ShowSet();
pictureBox.Image =_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@ -65,20 +110,21 @@ namespace Locomative
}
private void ButtonRemoveLoco_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox1.Text))
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
if (maskedTextBox1.Text == null)
return;
int pos = Convert.ToInt32(maskedTextBox1.Text);
if (( _mapLocoCollectionGeneric - (pos - 1)) != null)
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapLocoCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@ -87,23 +133,23 @@ namespace Locomative
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapLocoCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapLocoCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapLocoCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapLocoCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapLocoCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@ -124,7 +170,7 @@ namespace Locomative
dir = Direction.Right;
break;
}
pictureBox.Image = _mapLocoCollectionGeneric.MoveObject(dir);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
}

View File

@ -33,7 +33,7 @@ namespace Locomative
{
color = dialog.Color;
}
_loco = new DrawningLocomative(rnd.Next(1, 200), rnd.Next(10, 300), color);
_loco = new DrawningLocomative(rnd.Next(20, 70), rnd.Next(10, 300), color);
SetData();
Draw();
}
@ -85,7 +85,7 @@ namespace Locomative
{
dopColor = dialogDop.Color;
}
_loco = new DrawningFastLoco(rnd.Next(1, 200), rnd.Next(100, 300), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
_loco = new DrawningFastLoco(rnd.Next(20, 70), rnd.Next(100, 300), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}