Базовая логика готова. Необходимо почистить код и свериться с требованиями.
This commit is contained in:
parent
58fce94948
commit
6b7a6625db
@ -38,6 +38,21 @@ namespace Locomotive
|
|||||||
_locomotiveHeight = locomotiveHeight;
|
_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)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,16 @@ namespace Locomotive
|
|||||||
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
|
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)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||||
|
@ -267,6 +267,7 @@
|
|||||||
this.labelDopColor.Text = "Extra Color";
|
this.labelDopColor.Text = "Extra Color";
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -297,6 +298,7 @@
|
|||||||
this.buttonAdd.TabIndex = 2;
|
this.buttonAdd.TabIndex = 2;
|
||||||
this.buttonAdd.Text = "Add";
|
this.buttonAdd.Text = "Add";
|
||||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
|
@ -14,6 +14,25 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
DrawningLocomotive _locomotive = null;
|
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()
|
public FormLocomotiveConfig()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -25,6 +44,9 @@ namespace Locomotive
|
|||||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||||
panelBlue.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)
|
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
@ -87,13 +109,38 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
_locomotive.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
DrawLocomotive();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void labelDopColor_DragEnter(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
// ! - TODO
|
// ! - TODO
|
||||||
|
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
|
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
// ! - TODO
|
// ! - TODO
|
||||||
}
|
if (_locomotive is DrawningWarmlyLocomotive)
|
||||||
|
{
|
||||||
|
var locomotive = _locomotive as DrawningWarmlyLocomotive;
|
||||||
|
locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace Locomotive
|
|||||||
/// Добавление объекта
|
/// Добавление объекта
|
||||||
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
/*if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,8 +104,34 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
MessageBox.Show("Failed to add object");
|
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)
|
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
10
Locomotive/Locomotive/LocomotiveDelegate.cs
Normal file
10
Locomotive/Locomotive/LocomotiveDelegate.cs
Normal 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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user