Сделанная 5 лаба (не проверена)

This commit is contained in:
Danil Malin 2022-10-19 23:23:31 +04:00
parent 38ae601acc
commit 498ce0d89b
6 changed files with 67 additions and 20 deletions

View File

@ -19,7 +19,7 @@ namespace WarmlyLocomotive
/// <summary> /// <summary>
/// Цвет кузова /// Цвет кузова
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
/// <summary> /// <summary>
/// Шаг перемещения локомотива /// Шаг перемещения локомотива
/// </summary> /// </summary>

View File

@ -12,7 +12,7 @@ namespace WarmlyLocomotive
/// <summary> /// <summary>
/// Дополнительный цвет /// Дополнительный цвет
/// </summary> /// </summary>
public Color DopColor { get; private set; } public Color DopColor { get; set; }
/// <summary> /// <summary>
/// Признак наличия трубы /// Признак наличия трубы
/// </summary> /// </summary>

View File

@ -121,6 +121,7 @@
// //
// panelPurple // panelPurple
// //
this.panelPurple.AllowDrop = true;
this.panelPurple.BackColor = System.Drawing.Color.Purple; this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(157, 68); this.panelPurple.Location = new System.Drawing.Point(157, 68);
this.panelPurple.MaximumSize = new System.Drawing.Size(30, 30); this.panelPurple.MaximumSize = new System.Drawing.Size(30, 30);
@ -130,6 +131,7 @@
// //
// panelBlack // panelBlack
// //
this.panelBlack.AllowDrop = true;
this.panelBlack.BackColor = System.Drawing.Color.Black; this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(111, 68); this.panelBlack.Location = new System.Drawing.Point(111, 68);
this.panelBlack.MaximumSize = new System.Drawing.Size(30, 30); this.panelBlack.MaximumSize = new System.Drawing.Size(30, 30);
@ -139,6 +141,7 @@
// //
// panelGray // panelGray
// //
this.panelGray.AllowDrop = true;
this.panelGray.BackColor = System.Drawing.Color.Gray; this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(65, 68); this.panelGray.Location = new System.Drawing.Point(65, 68);
this.panelGray.MaximumSize = new System.Drawing.Size(30, 30); this.panelGray.MaximumSize = new System.Drawing.Size(30, 30);
@ -148,6 +151,7 @@
// //
// panelWhite // panelWhite
// //
this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White; this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(19, 68); this.panelWhite.Location = new System.Drawing.Point(19, 68);
this.panelWhite.MaximumSize = new System.Drawing.Size(30, 30); this.panelWhite.MaximumSize = new System.Drawing.Size(30, 30);
@ -157,6 +161,7 @@
// //
// panelYellow // panelYellow
// //
this.panelYellow.AllowDrop = true;
this.panelYellow.BackColor = System.Drawing.Color.Yellow; this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(157, 22); this.panelYellow.Location = new System.Drawing.Point(157, 22);
this.panelYellow.MaximumSize = new System.Drawing.Size(30, 30); this.panelYellow.MaximumSize = new System.Drawing.Size(30, 30);
@ -166,6 +171,7 @@
// //
// panelBlue // panelBlue
// //
this.panelBlue.AllowDrop = true;
this.panelBlue.BackColor = System.Drawing.Color.Blue; this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(111, 22); this.panelBlue.Location = new System.Drawing.Point(111, 22);
this.panelBlue.MaximumSize = new System.Drawing.Size(30, 30); this.panelBlue.MaximumSize = new System.Drawing.Size(30, 30);
@ -175,6 +181,7 @@
// //
// panelGreen // panelGreen
// //
this.panelGreen.AllowDrop = true;
this.panelGreen.BackColor = System.Drawing.Color.Green; this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(65, 22); this.panelGreen.Location = new System.Drawing.Point(65, 22);
this.panelGreen.MaximumSize = new System.Drawing.Size(30, 30); this.panelGreen.MaximumSize = new System.Drawing.Size(30, 30);
@ -184,6 +191,7 @@
// //
// panelRed // panelRed
// //
this.panelRed.AllowDrop = true;
this.panelRed.BackColor = System.Drawing.Color.Red; this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(19, 22); this.panelRed.Location = new System.Drawing.Point(19, 22);
this.panelRed.MaximumSize = new System.Drawing.Size(30, 30); this.panelRed.MaximumSize = new System.Drawing.Size(30, 30);
@ -295,6 +303,7 @@
this.labelDopColor.Text = "Доп. цвет"; this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
// //
// labelBaseColor // labelBaseColor
// //

View File

@ -16,7 +16,7 @@ namespace WarmlyLocomotive
/// <summary> /// <summary>
/// Событие /// Событие
/// </summary> /// </summary>
private event LocomotiveDelegate EventAddLocomotive; private event Action<DrawningLocomotive> EventAddLocomotive;
public FormLocomotiveConfig() public FormLocomotiveConfig()
{ {
InitializeComponent(); InitializeComponent();
@ -28,7 +28,7 @@ namespace WarmlyLocomotive
panelWhite.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (object sender, EventArgs e) => Close();
// TODO buttonCancel.Click with lambda // TODO buttonCancel.Click with lambda
} }
/// <summary> /// <summary>
@ -46,11 +46,11 @@ namespace WarmlyLocomotive
/// Добавление события /// Добавление события
/// </summary> /// </summary>
/// <param name="ev"></param> /// <param name="ev"></param>
public void AddEvent(LocomotiveDelegate ev) public void AddEvent(Action<DrawningLocomotive> ev)
{ {
if (EventAddLocomotive == null) if (EventAddLocomotive == null)
{ {
EventAddLocomotive = new LocomotiveDelegate(ev); EventAddLocomotive = new Action<DrawningLocomotive>(ev);
} }
else else
{ {
@ -134,6 +134,29 @@ namespace WarmlyLocomotive
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{ {
// TODO Call method from object _car and set color // TODO Call method from object _car and set color
if(_locomotive != null)
{
if (e.Data.GetDataPresent(typeof(Color))) {
_locomotive.Locomotive.BodyColor = (Color)e.Data.GetData(typeof(Color));
}
DrawLocomotive();
}
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
} }
/// <summary> /// <summary>
/// Принимаем дополнительный цвет /// Принимаем дополнительный цвет
@ -143,6 +166,17 @@ namespace WarmlyLocomotive
private void LabelDopColor_DragDrop(object sender, DragEventArgs e) private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{ {
// TODO Call method from object _car if _car is DrawningSportCar and set dop color // TODO Call method from object _car if _car is DrawningSportCar and set dop color
if (_locomotive != null && _locomotive is DrawningWarmlyLocomotive warmlyLocomotive)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
if(warmlyLocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
{
entityWarmlyLocomotive.DopColor = (Color)e.Data.GetData(typeof(Color));
}
}
DrawLocomotive();
}
} }
/// <summary> /// <summary>
/// Добавление локомотива /// Добавление локомотива

View File

@ -68,8 +68,26 @@ namespace WarmlyLocomotive
{ {
var formLocomotiveConfig = new FormLocomotiveConfig(); var formLocomotiveConfig = new FormLocomotiveConfig();
// TODO Call method AddEvent from formCarConfig // TODO Call method AddEvent from formCarConfig
formLocomotiveConfig.AddEvent(AddLocomotive);
formLocomotiveConfig.Show(); formLocomotiveConfig.Show();
} }
private void AddLocomotive(DrawningLocomotive drawningLocomotive)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(drawningLocomotive);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary> /// <summary>
/// Удаление объекта /// Удаление объекта
/// </summary> /// </summary>

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive
{
/// <summary>
/// Делегат для передачи объекта-локомотива
/// </summary>
/// <param name="locomotive"></param>
public delegate void LocomotiveDelegate(DrawningLocomotive locomotive);
}