Этап 3 Форма
This commit is contained in:
parent
ce71636c0d
commit
79b94442ae
@ -40,12 +40,19 @@
|
||||
this.buttonAddTrolleybus = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||
this.groupBox1.Controls.Add(this.buttonRight);
|
||||
this.groupBox1.Controls.Add(this.buttonDown);
|
||||
@ -55,11 +62,10 @@
|
||||
this.groupBox1.Controls.Add(this.buttonRemoveTrolleybus);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox1.Controls.Add(this.buttonAddTrolleybus);
|
||||
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox1.Location = new System.Drawing.Point(600, 0);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(200, 450);
|
||||
this.groupBox1.Size = new System.Drawing.Size(200, 648);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
@ -68,7 +74,7 @@
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(59, 402);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(80, 605);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
@ -79,7 +85,7 @@
|
||||
//
|
||||
this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(135, 402);
|
||||
this.buttonRight.Location = new System.Drawing.Point(156, 605);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonRight.TabIndex = 8;
|
||||
@ -90,7 +96,7 @@
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(97, 402);
|
||||
this.buttonDown.Location = new System.Drawing.Point(118, 605);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonDown.TabIndex = 7;
|
||||
@ -101,7 +107,7 @@
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(97, 365);
|
||||
this.buttonUp.Location = new System.Drawing.Point(118, 568);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
@ -110,7 +116,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 256);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 511);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -120,7 +126,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(7, 216);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(7, 471);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -130,7 +136,7 @@
|
||||
//
|
||||
// buttonRemoveTrolleybus
|
||||
//
|
||||
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(6, 170);
|
||||
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(6, 425);
|
||||
this.buttonRemoveTrolleybus.Name = "buttonRemoveTrolleybus";
|
||||
this.buttonRemoveTrolleybus.Size = new System.Drawing.Size(182, 23);
|
||||
this.buttonRemoveTrolleybus.TabIndex = 3;
|
||||
@ -140,14 +146,14 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 128);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 383);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(181, 20);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
//
|
||||
// buttonAddTrolleybus
|
||||
//
|
||||
this.buttonAddTrolleybus.Location = new System.Drawing.Point(7, 85);
|
||||
this.buttonAddTrolleybus.Location = new System.Drawing.Point(7, 340);
|
||||
this.buttonAddTrolleybus.Name = "buttonAddTrolleybus";
|
||||
this.buttonAddTrolleybus.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonAddTrolleybus.TabIndex = 1;
|
||||
@ -161,9 +167,9 @@
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Сложная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 42);
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 44);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 21);
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 21);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
@ -172,15 +178,62 @@
|
||||
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(600, 648);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBox2.Controls.Add(this.listBoxMaps);
|
||||
this.groupBox2.Controls.Add(this.buttonAddMap);
|
||||
this.groupBox2.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBox2.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox2.Location = new System.Drawing.Point(6, 19);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(181, 287);
|
||||
this.groupBox2.TabIndex = 2;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Карты";
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(7, 18);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(168, 20);
|
||||
this.textBoxNewMapName.TabIndex = 1;
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(7, 72);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonAddMap.TabIndex = 2;
|
||||
this.buttonAddMap.Text = "Добавить Карту";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(7, 102);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(168, 95);
|
||||
this.listBoxMaps.TabIndex = 3;
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(7, 204);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonDeleteMap.TabIndex = 4;
|
||||
this.buttonDeleteMap.Text = "Удалить Карту";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormMapWithSetTrolleybus
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(800, 648);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormMapWithSetTrolleybus";
|
||||
@ -188,6 +241,8 @@
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@ -206,5 +261,10 @@
|
||||
private System.Windows.Forms.Button buttonShowStorage;
|
||||
private System.Windows.Forms.Button buttonRemoveTrolleybus;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBoxPosition;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Button buttonDeleteMap;
|
||||
private System.Windows.Forms.ListBox listBoxMaps;
|
||||
private System.Windows.Forms.Button buttonAddMap;
|
||||
private System.Windows.Forms.TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -12,9 +12,72 @@ namespace Trolleybus
|
||||
{
|
||||
public partial class FormMapWithSetTrolleybus : Form
|
||||
{
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Сложная карта", new AutoStopMap() },
|
||||
};
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
public FormMapWithSetTrolleybus()
|
||||
{
|
||||
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 ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.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 MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> _mapTrolleybusCollectionGeneric;
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
@ -41,18 +104,18 @@ namespace Trolleybus
|
||||
}
|
||||
private void ButtonAddTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Form1 form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectTrolleybus trolleybus = new(form.SelectedTrolleybus);
|
||||
if (_mapTrolleybusCollectionGeneric + trolleybus !=-1)
|
||||
DrawningObjectTrolleybus tractor = new(form.SelectedTrolleybus);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tractor != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -67,19 +130,16 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text) ||
|
||||
MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapTrolleybusCollectionGeneric - pos !=null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -93,11 +153,11 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
@ -106,11 +166,11 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@ -119,29 +179,29 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
Direction enums = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
case "buttonsUp":
|
||||
enums = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
case "buttonsDown":
|
||||
enums = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
case "buttonsLeft":
|
||||
enums = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
case "buttonsRight":
|
||||
enums = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(enums);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user