Базовая логика готова. Необходимо почистить код и свериться с требованиями.

This commit is contained in:
Данила Мочалов 2022-10-23 17:02:32 +04:00
parent 58fce94948
commit 6b7a6625db
6 changed files with 112 additions and 2 deletions

View File

@ -38,6 +38,21 @@ namespace Locomotive
_locomotiveHeight = locomotiveHeight;
}
public void SetBaseColor(Color color)
{
if (Locomotive is EntityWarmlyLocomotive)
{
var locomotive = Locomotive as EntityWarmlyLocomotive;
if (locomotive is not null)
{
locomotive = new EntityWarmlyLocomotive(locomotive.Speed, locomotive.Weight, color, locomotive.ExtraColor, locomotive.Pipe, locomotive.FuelStorage);
Locomotive = locomotive;
return;
}
}
Locomotive = new EntityLocomotive(Locomotive.Speed, Locomotive.Weight, color);
}
/// Установка позиции локомотива
public void SetPosition(int x, int y, int width, int height)
{

View File

@ -14,6 +14,16 @@ namespace Locomotive
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
}
public void SetExtraColor(Color color)
{
var LocomotiveWarmly = Locomotive as EntityWarmlyLocomotive;
if (LocomotiveWarmly is not null)
{
LocomotiveWarmly = new EntityWarmlyLocomotive(LocomotiveWarmly.Speed, LocomotiveWarmly.Weight, LocomotiveWarmly.BodyColor, color, LocomotiveWarmly.Pipe, LocomotiveWarmly.FuelStorage);
Locomotive = LocomotiveWarmly;
}
}
public override void DrawTransport(Graphics g)
{
if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)

View File

@ -267,6 +267,7 @@
this.labelDopColor.Text = "Extra Color";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragEnter);
//
// labelBaseColor
//
@ -297,6 +298,7 @@
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Add";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonCancel
//

View File

@ -14,6 +14,25 @@ namespace Locomotive
{
DrawningLocomotive _locomotive = null;
private event LocomotiveDelegate eventAddLocomotive;
public void AddEvent(LocomotiveDelegate ev)
{
if (eventAddLocomotive == null)
{
eventAddLocomotive = new LocomotiveDelegate(ev);
}
else
{
eventAddLocomotive += ev;
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
eventAddLocomotive?.Invoke(_locomotive);
Close();
}
public FormLocomotiveConfig()
{
InitializeComponent();
@ -25,6 +44,9 @@ namespace Locomotive
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
// ! - TODO buttonCancel.Click with lambda
buttonCancel.Click += (object sender, EventArgs e) => Close();
}
private void labelObject_MouseDown(object sender, MouseEventArgs e)
@ -87,13 +109,38 @@ namespace Locomotive
}
private void labelBaseColor_DragDrop(object sender, DragEventArgs e)
{
// ! - TODO Call method from object _car and set color
_locomotive.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
DrawLocomotive();
}
private void labelDopColor_DragEnter(object sender, DragEventArgs e)
{
// ! - TODO
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
{
// ! - TODO
}
if (_locomotive is DrawningWarmlyLocomotive)
{
var locomotive = _locomotive as DrawningWarmlyLocomotive;
locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color)));
}
DrawLocomotive();
}
}
}

View File

@ -87,7 +87,7 @@ namespace Locomotive
/// Добавление объекта
private void buttonAddLocomotive_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
/*if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@ -104,8 +104,34 @@ namespace Locomotive
{
MessageBox.Show("Failed to add object");
}
}*/
var formCarConfig = new FormLocomotiveConfig();
// TODO Call method AddEvent from formCarConfig
formCarConfig.AddEvent(new (AddLocomotive));
formCarConfig.Show();
}
private void AddLocomotive(DrawningLocomotive locomotive)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1)
{
MessageBox.Show("Object added");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Failed to add object");
}
}
/// Удаление объекта
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
{

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Locomotive
{
public delegate void LocomotiveDelegate(DrawningLocomotive locomotive);
}