доделаю

This commit is contained in:
sqdselo 2024-04-14 20:01:01 +04:00
parent d4ccb9c74a
commit a50b38a592
6 changed files with 120 additions and 75 deletions

View File

@ -7,6 +7,6 @@ using System.Threading.Tasks;
namespace HoistingCrane namespace HoistingCrane
{ {
public delegate void CarDelegate(DrawningTrackedVehicle car); public delegate void CarDelegate(DrawningTrackedVehicle car);
} }

View File

@ -25,8 +25,6 @@ namespace HoistingCrane.CollectionGenericObjects
/// <param name="collectionType">тип коллекции</param> /// <param name="collectionType">тип коллекции</param>
public void AddCollection(string name, CollectionType collectionType) public void AddCollection(string name, CollectionType collectionType)
{ {
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
if (!string.IsNullOrEmpty(name) && !Keys.Contains(name)) if (!string.IsNullOrEmpty(name) && !Keys.Contains(name))
{ {
if(collectionType == CollectionType.Massive) if(collectionType == CollectionType.Massive)
@ -45,12 +43,8 @@ namespace HoistingCrane.CollectionGenericObjects
/// <param name="name">Название коллекции</param> /// <param name="name">Название коллекции</param>
public void DelCollection(string name) public void DelCollection(string name)
{ {
// TODO Прописать логику для удаления коллекции if (dict.ContainsKey(name))
if(Keys.Contains(name))
{
dict.Remove(name); dict.Remove(name);
}
} }
/// <summary> /// <summary>
/// Доступ к коллекции /// Доступ к коллекции
@ -61,12 +55,8 @@ namespace HoistingCrane.CollectionGenericObjects
{ {
get get
{ {
// TODO Продумать логику получения объекта if (name == null || !dict.ContainsKey(name)) { return null; }
if (dict.TryGetValue(name, out ICollectionGenericObjects<T>? result)) return dict[name];
{
return result;
}
return null;
} }
} }
} }

View File

@ -221,9 +221,9 @@
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
buttonCreateHoistingCrane.Size = new Size(192, 22); buttonCreateHoistingCrane.Size = new Size(192, 22);
buttonCreateHoistingCrane.TabIndex = 0; buttonCreateHoistingCrane.TabIndex = 0;
buttonCreateHoistingCrane.Text = "Добавить подъемный кран"; buttonCreateHoistingCrane.Text = "Добавить транспорт";
buttonCreateHoistingCrane.UseVisualStyleBackColor = true; buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click;
// //
// pictureBox // pictureBox
// //

View File

@ -74,20 +74,13 @@ namespace HoistingCrane
return color; return color;
} }
private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e)
{
FormCarConfig form = new();
form.Show();
form.AddEvent(SetCar);
}
private void SetCar(DrawningTrackedVehicle car) private void SetCar(DrawningTrackedVehicle car)
{ {
if(_company == null || car == null) if (_company == null || car == null)
{ {
return; return;
} }
if((_company + car) != -1) if ((_company + car) != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
@ -225,6 +218,13 @@ namespace HoistingCrane
panelStorage.Enabled = true; panelStorage.Enabled = true;
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
private void buttonCreateHoistingCrane_Click(object sender, EventArgs e)
{
FormCarConfig form = new();
form.AddEvent(SetCar);
form.Show();
}
} }
} }

View File

@ -263,7 +263,8 @@
labelAdditionalColor.TabIndex = 10; labelAdditionalColor.TabIndex = 10;
labelAdditionalColor.Text = "Доп. цвет"; labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragEnter += labelColors_DragEnter; labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter;
// //
// labelBodyColor // labelBodyColor
// //
@ -274,7 +275,8 @@
labelBodyColor.TabIndex = 9; labelBodyColor.TabIndex = 9;
labelBodyColor.Text = "Цвет"; labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragEnter += labelColors_DragEnter; labelBodyColor.DragDrop += labelBodyColor_DragDrop;
labelBodyColor.DragEnter += labelBodyColor_DragEnter;
// //
// pictureBoxObject // pictureBoxObject
// //
@ -302,7 +304,6 @@
buttonCancel.TabIndex = 2; buttonCancel.TabIndex = 2;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
// //
// FormCarConfig // FormCarConfig
// //

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
namespace HoistingCrane namespace HoistingCrane
{ {
@ -19,6 +20,7 @@ namespace HoistingCrane
private event CarDelegate? _carDelegate; private event CarDelegate? _carDelegate;
public FormCarConfig() public FormCarConfig()
{ {
InitializeComponent();
panelColorRed.MouseDown += panel_MouseDown; panelColorRed.MouseDown += panel_MouseDown;
panelColorBlue.MouseDown += panel_MouseDown; panelColorBlue.MouseDown += panel_MouseDown;
panelColorGreen.MouseDown += panel_MouseDown; panelColorGreen.MouseDown += panel_MouseDown;
@ -28,45 +30,53 @@ namespace HoistingCrane
panelColorGray.MouseDown += panel_MouseDown; panelColorGray.MouseDown += panel_MouseDown;
panelColorPurple.MouseDown += panel_MouseDown; panelColorPurple.MouseDown += panel_MouseDown;
buttonCancel.Click += (sender, e) => Close(); buttonCancel.Click += (sender, e) => Close();
InitializeComponent();
} }
/// <summary>
/// Привязка метода к событию
/// </summary>
/// <param name="carDelegate"></param>
public void AddEvent(CarDelegate carDelegate) public void AddEvent(CarDelegate carDelegate)
{ {
_carDelegate += carDelegate; _carDelegate += carDelegate;
} }
/// <summary>
/// Отрисовка объекта
/// </summary>
private void DrawObject() private void DrawObject()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
car?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); car?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
car?.SetPosition(5, 5); car?.SetPosition(25, 25);
car?.DrawTransport(gr); car?.DrawTransport(gr);
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelObject_MouseDown(object sender, MouseEventArgs e) private void labelObject_MouseDown(object sender, MouseEventArgs e)
{ {
var label = sender as Label; (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
label?.DoDragDrop(label.Name, DragDropEffects.Move);
label?.DoDragDrop(label.Name, DragDropEffects.Copy);
} }
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel_DragEnter(object sender, DragEventArgs e) private void panel_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
} }
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel_DragDrop(object sender, DragEventArgs e) private void panel_DragDrop(object sender, DragEventArgs e)
{ {
switch (e.Data?.GetData(DataFormats.Text)?.ToString()) switch (e.Data?.GetData(DataFormats.Text).ToString())
{ {
case "labelSimpleObject": case "labelSimpleObject":
car = new DrawningTrackedVehicle((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); car = new DrawningTrackedVehicle((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
@ -78,35 +88,20 @@ namespace HoistingCrane
} }
DrawObject(); DrawObject();
} }
/// <summary>
/// Передаем информацию при нажатии на Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel_MouseDown(object? sender, MouseEventArgs e) private void panel_MouseDown(object? sender, MouseEventArgs e)
{ {
var color = sender as Label; (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.White, DragDropEffects.Move | DragDropEffects.Copy);
color?.DoDragDrop(color.BackColor, DragDropEffects.Move);
color?.DoDragDrop(color.BackColor, DragDropEffects.Copy);
} }
/// <summary>
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) /// Передача объекта
private void labelColors_DragEnter(object sender, DragEventArgs e) /// </summary>
{ /// <param name="sender"></param>
var label = (String)sender; /// <param name="e"></param>
Color newColor = (Color)e.Data.GetData(typeof(Color).ToString());
switch (label)
{
case "labelBodyColor":
car?.EntityTrackedVehicle?.SetBodyColor(newColor);
DrawObject();
break;
case "labelAdditionalColor":
if (car is DrawningHoistingCrane)
{
(car.EntityTrackedVehicle as EntityHoistingCrane).SetAdditionalColor(newColor);
DrawObject();
}
break;
}
}
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
if (car != null) if (car != null)
@ -115,8 +110,67 @@ namespace HoistingCrane
Close(); Close();
} }
} }
/// <summary>
/// Прорисовка основным цветом
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (car != null)
{
car.EntityTrackedVehicle?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
/// <summary>
/// Передача основного цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Прорисовка основным цветом
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (car?.EntityTrackedVehicle is EntityHoistingCrane entityHoistingCrane)
{
entityHoistingCrane.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
}
DrawObject();
}
/// <summary>
/// Передача дополнительного цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (car is DrawningHoistingCrane)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
} }
} }