готовая лаба 5

This commit is contained in:
spacyboy 2023-12-12 15:46:08 +04:00
parent 93f32ceef3
commit cb5e989a82
12 changed files with 749 additions and 22 deletions

View File

@ -11,17 +11,12 @@ namespace RoadTrain.DrawingObjects
public class DrawingRoadTrain
{
public EntityRoadTrain? EntityRoadTrain { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
public int _pictureWidth;
public int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _roadTrainWidth = 200;
protected readonly int _roadTrainHeight = 100;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _roadTrainWidth;
public int GetHeight => _roadTrainHeight;
public IMoveableObject GetMoveableObject => new DrawingObjectTrain(this);
public DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _roadTrainWidth || height < _roadTrainHeight)
@ -57,6 +52,51 @@ namespace RoadTrain.DrawingObjects
_startPosX = x;
_startPosY = y;
}
public virtual void DrawTransport(Graphics g)
{
if (EntityRoadTrain == null)
{
return;
}
Pen pen = new(Color.Black, 2);
Pen anchor = new(Color.Black, 4);
Brush bodyBrush = new SolidBrush(EntityRoadTrain.BodyColor);
Brush whiteBrush = new SolidBrush(Color.White);
//машина
g.DrawRectangle(pen, _startPosX, _startPosY + 50, 160, 20);
g.FillRectangle(bodyBrush, _startPosX, _startPosY + 50, 160, 20);
g.DrawEllipse(pen, _startPosX + 5, _startPosY + 70, 30, 30); //колесо
g.FillEllipse(bodyBrush, _startPosX + 5, _startPosY + 70, 30, 30);
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 70, 30, 30); //колесо
g.FillEllipse(bodyBrush, _startPosX + 40, _startPosY + 70, 30, 30);
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 30, 30); //колесо
g.FillEllipse(bodyBrush, _startPosX + 120, _startPosY + 70, 30, 30);
g.DrawRectangle(pen, _startPosX + 120, _startPosY + 10, 40, 40); //кабина
g.FillRectangle(bodyBrush, _startPosX + 120, _startPosY + 10, 40, 40);
g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно
g.FillRectangle(whiteBrush, _startPosX + 130, _startPosY + 20, 30, 20);
}
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _roadTrainWidth;
public int GetHeight => _roadTrainHeight;
public bool CanMove(DirectionType direction)
{
if (EntityRoadTrain == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityRoadTrain.Step > 0,
DirectionType.Up => _startPosY - EntityRoadTrain.Step > 0,
DirectionType.Right => _startPosX + EntityRoadTrain.Step + _roadTrainWidth < _pictureWidth,
DirectionType.Down => _startPosY + EntityRoadTrain.Step + _roadTrainHeight < _pictureHeight,
_ => false,
};
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityRoadTrain == null)
@ -79,6 +119,7 @@ namespace RoadTrain.DrawingObjects
break;
}
}
<<<<<<< HEAD
public bool CanMove(DirectionType direction)
{
if (EntityRoadTrain == null)
@ -118,7 +159,15 @@ namespace RoadTrain.DrawingObjects
g.FillRectangle(bodyBrush, _startPosX + 120, _startPosY + 10, 40, 40);
g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно
g.FillRectangle(whiteBrush, _startPosX + 130, _startPosY + 20, 30, 20);
=======
public IMoveableObject GetMoveableObject => new DrawingObjectTrain(this);
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
>>>>>>> a4a5763 (готовая лаба 5)
{
_pictureWidth = pictureBoxWidth;
_pictureHeight = pictureBoxHeight;
}
}
}

View File

@ -43,5 +43,9 @@ namespace RoadTrain.DrawingObjects
g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY, 90, 50);
}
}
public void SetAddColor(Color color)
{
(EntityRoadTrain as EntityRoadTrainWithTank).AdditionalColor = color;
}
}
}

View File

@ -10,7 +10,7 @@ namespace RoadTrain.Entities
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
public double Step => (double)Speed * 100 / Weight;
public EntityRoadTrain(int speed, double weight, Color bodyColor)
{
@ -18,5 +18,9 @@ namespace RoadTrain.Entities
Weight = weight;
BodyColor = bodyColor;
}
public void SetBodyColor(Color color)
{
BodyColor = color;
}
}
}

View File

@ -8,7 +8,7 @@ namespace RoadTrain.Entities
{
public class EntityRoadTrainWithTank : EntityRoadTrain
{
public Color AdditionalColor { get; private set; }
public Color AdditionalColor { get; set; }
public bool Tank { get; private set; }
public bool Brush { get; private set; }
public EntityRoadTrainWithTank(int speed, double weight, Color bodyColor, Color
@ -19,5 +19,9 @@ namespace RoadTrain.Entities
Tank = tank;
Brush = brush;
}
public void SetAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@ -11,7 +11,7 @@ namespace RoadTrain.Generics
{
private readonly List<T?> _places;
public int Count => _places.Count;
public readonly int _maxCount;
private readonly int _maxCount;
public SetGeneric(int count)
{
@ -53,13 +53,16 @@ namespace RoadTrain.Generics
}
set
{
if (position < 0 || position > Count || Count >= _maxCount)
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
{
return;
}
_places.Insert(position, value);
return;
}
}
public IEnumerable<T?> GetTrains(int? maxTrains = null)
public IEnumerable<T> GetTrains(int? maxTrains = null)
{
for (int i = 0; i < _places.Count; ++i)
{

View File

@ -83,19 +83,23 @@ namespace RoadTrain
{
return;
}
RoadTrain form = new();
if (form.ShowDialog() == DialogResult.OK)
var formTrainConfig = new TrainConfig();
formTrainConfig.Show();
Action<DrawingRoadTrain>? trainDelegate = new((m) =>
{
if (obj + form.SelectedTrain)
bool isAddSuccessful = (obj + m);
if (isAddSuccessful)
{
MessageBox.Show("Объект добавлен");
m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
pictureBoxCollection.Image = obj.ShowTrains();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
formTrainConfig.AddEvent(trainDelegate);
}
private void ButtonRemoveTrain_Click(object sender, EventArgs e)
{

View File

@ -0,0 +1,390 @@
namespace RoadTrain
{
partial class TrainConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
pictureBoxObject = new PictureBox();
labelSimpleObject = new Label();
panelRed = new Panel();
panelBlue = new Panel();
panelYellow = new Panel();
panelWhite = new Panel();
panelGray = new Panel();
panelBlack = new Panel();
panelPurple = new Panel();
panelGreen = new Panel();
labelModifiedObject = new Label();
groupBoxColor = new GroupBox();
checkBoxBrush = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
labelWeight = new Label();
labelSpeed = new Label();
panel1 = new Panel();
buttonCancel = new Button();
buttonOk = new Button();
labelAddColor = new Label();
labelBodyColor = new Label();
checkBoxTank = new CheckBox();
groupBoxParameters = new GroupBox();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
panel1.SuspendLayout();
groupBoxParameters.SuspendLayout();
SuspendLayout();
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(15, 58);
pictureBoxObject.Margin = new Padding(3, 2, 3, 2);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(282, 160);
pictureBoxObject.TabIndex = 0;
pictureBoxObject.TabStop = false;
//
// labelSimpleObject
//
labelSimpleObject.AllowDrop = true;
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point);
labelSimpleObject.Location = new Point(274, 205);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(109, 28);
labelSimpleObject.TabIndex = 7;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.Tomato;
panelRed.Location = new Point(6, 29);
panelRed.Margin = new Padding(3, 2, 3, 2);
panelRed.Name = "panelRed";
panelRed.Size = new Size(40, 40);
panelRed.TabIndex = 1;
panelRed.MouseDown += PanelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.CornflowerBlue;
panelBlue.Location = new Point(125, 29);
panelBlue.Margin = new Padding(3, 2, 3, 2);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(40, 40);
panelBlue.TabIndex = 1;
panelBlue.MouseDown += PanelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.FromArgb(255, 255, 128);
panelYellow.Location = new Point(187, 29);
panelYellow.Margin = new Padding(3, 2, 3, 2);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(40, 40);
panelYellow.TabIndex = 1;
panelYellow.MouseDown += PanelColor_MouseDown;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(5, 86);
panelWhite.Margin = new Padding(3, 2, 3, 2);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(40, 40);
panelWhite.TabIndex = 1;
panelWhite.MouseDown += PanelColor_MouseDown;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(65, 86);
panelGray.Margin = new Padding(3, 2, 3, 2);
panelGray.Name = "panelGray";
panelGray.Size = new Size(40, 40);
panelGray.TabIndex = 1;
panelGray.MouseDown += PanelColor_MouseDown;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(125, 86);
panelBlack.Margin = new Padding(3, 2, 3, 2);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(40, 40);
panelBlack.TabIndex = 1;
panelBlack.MouseDown += PanelColor_MouseDown;
//
// panelPurple
//
panelPurple.BackColor = Color.Violet;
panelPurple.Location = new Point(187, 86);
panelPurple.Margin = new Padding(3, 2, 3, 2);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(40, 40);
panelPurple.TabIndex = 1;
panelPurple.MouseDown += PanelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.LightGreen;
panelGreen.Location = new Point(65, 29);
panelGreen.Margin = new Padding(3, 2, 3, 2);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(40, 40);
panelGreen.TabIndex = 0;
panelGreen.MouseDown += PanelColor_MouseDown;
//
// labelModifiedObject
//
labelModifiedObject.AllowDrop = true;
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point);
labelModifiedObject.Location = new Point(399, 205);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(106, 28);
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// groupBoxColor
//
groupBoxColor.Controls.Add(panelRed);
groupBoxColor.Controls.Add(panelBlue);
groupBoxColor.Controls.Add(panelYellow);
groupBoxColor.Controls.Add(panelWhite);
groupBoxColor.Controls.Add(panelGray);
groupBoxColor.Controls.Add(panelBlack);
groupBoxColor.Controls.Add(panelPurple);
groupBoxColor.Controls.Add(panelGreen);
groupBoxColor.Location = new Point(274, 28);
groupBoxColor.Margin = new Padding(3, 2, 3, 2);
groupBoxColor.Name = "groupBoxColor";
groupBoxColor.Padding = new Padding(3, 2, 3, 2);
groupBoxColor.Size = new Size(231, 162);
groupBoxColor.TabIndex = 6;
groupBoxColor.TabStop = false;
groupBoxColor.Text = "Цвета";
//
// checkBoxBrush
//
checkBoxBrush.AutoSize = true;
checkBoxBrush.Location = new Point(13, 147);
checkBoxBrush.Margin = new Padding(3, 2, 3, 2);
checkBoxBrush.Name = "checkBoxBrush";
checkBoxBrush.Size = new Size(161, 19);
checkBoxBrush.TabIndex = 5;
checkBoxBrush.Text = "Признак наличия щетки";
checkBoxBrush.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(94, 60);
numericUpDownWeight.Margin = new Padding(3, 2, 3, 2);
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(51, 23);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(94, 28);
numericUpDownSpeed.Margin = new Padding(3, 2, 3, 2);
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(59, 23);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(13, 67);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(26, 15);
labelWeight.TabIndex = 1;
labelWeight.Text = "Вес";
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(13, 35);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(59, 15);
labelSpeed.TabIndex = 0;
labelSpeed.Text = "Скорость";
//
// panel1
//
panel1.AllowDrop = true;
panel1.Controls.Add(buttonCancel);
panel1.Controls.Add(buttonOk);
panel1.Controls.Add(labelAddColor);
panel1.Controls.Add(labelBodyColor);
panel1.Controls.Add(pictureBoxObject);
panel1.Location = new Point(557, 7);
panel1.Margin = new Padding(3, 2, 3, 2);
panel1.Name = "panel1";
panel1.Size = new Size(312, 263);
panel1.TabIndex = 1;
panel1.DragDrop += PanelObject_DragDrop;
panel1.DragEnter += PanelObject_DragEnter;
//
// buttonCancel
//
buttonCancel.Location = new Point(175, 223);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(108, 24);
buttonCancel.TabIndex = 12;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOk
//
buttonOk.Location = new Point(38, 223);
buttonOk.Margin = new Padding(3, 2, 3, 2);
buttonOk.Name = "buttonOk";
buttonOk.Size = new Size(108, 24);
buttonOk.TabIndex = 11;
buttonOk.Text = "Добавить";
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += ButtonOk_Click;
//
// labelAddColor
//
labelAddColor.AllowDrop = true;
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
labelAddColor.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point);
labelAddColor.Location = new Point(175, 22);
labelAddColor.Name = "labelAddColor";
labelAddColor.Size = new Size(109, 28);
labelAddColor.TabIndex = 10;
labelAddColor.Text = "Доп. цвет";
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
labelAddColor.DragDrop += LabelColor_DragDrop;
labelAddColor.DragEnter += LabelColor_DragEnter;
//
// labelBodyColor
//
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Font = new Font("Segoe UI", 10.2F, FontStyle.Regular, GraphicsUnit.Point);
labelBodyColor.Location = new Point(38, 22);
labelBodyColor.Name = "labelBodyColor";
labelBodyColor.Size = new Size(109, 28);
labelBodyColor.TabIndex = 9;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += LabelColor_DragDrop;
labelBodyColor.DragEnter += LabelColor_DragEnter;
//
// checkBoxTank
//
checkBoxTank.AutoSize = true;
checkBoxTank.Location = new Point(13, 113);
checkBoxTank.Margin = new Padding(3, 2, 3, 2);
checkBoxTank.Name = "checkBoxTank";
checkBoxTank.Size = new Size(196, 19);
checkBoxTank.TabIndex = 4;
checkBoxTank.Text = "Признак наличия бака с водой";
checkBoxTank.UseVisualStyleBackColor = true;
//
// groupBoxParameters
//
groupBoxParameters.Controls.Add(labelModifiedObject);
groupBoxParameters.Controls.Add(labelSimpleObject);
groupBoxParameters.Controls.Add(groupBoxColor);
groupBoxParameters.Controls.Add(checkBoxBrush);
groupBoxParameters.Controls.Add(checkBoxTank);
groupBoxParameters.Controls.Add(numericUpDownWeight);
groupBoxParameters.Controls.Add(numericUpDownSpeed);
groupBoxParameters.Controls.Add(labelWeight);
groupBoxParameters.Controls.Add(labelSpeed);
groupBoxParameters.Location = new Point(15, 7);
groupBoxParameters.Margin = new Padding(3, 2, 3, 2);
groupBoxParameters.Name = "groupBoxParameters";
groupBoxParameters.Padding = new Padding(3, 2, 3, 2);
groupBoxParameters.Size = new Size(524, 260);
groupBoxParameters.TabIndex = 2;
groupBoxParameters.TabStop = false;
groupBoxParameters.Text = "Параметры";
//
// TrainConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 277);
Controls.Add(panel1);
Controls.Add(groupBoxParameters);
Name = "TrainConfig";
Text = "TrainConfig";
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
groupBoxColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
panel1.ResumeLayout(false);
groupBoxParameters.ResumeLayout(false);
groupBoxParameters.PerformLayout();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxObject;
private Label labelSimpleObject;
private Panel panelRed;
private Panel panelBlue;
private Panel panelYellow;
private Panel panelWhite;
private Panel panelGray;
private Panel panelBlack;
private Panel panelPurple;
private Panel panelGreen;
private Label labelModifiedObject;
private GroupBox groupBoxColor;
private CheckBox checkBoxBrush;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private Panel panel1;
private Button buttonCancel;
private Button buttonOk;
private Label labelAddColor;
private Label labelBodyColor;
private CheckBox checkBoxTank;
private GroupBox groupBoxParameters;
}
}

View File

@ -0,0 +1,127 @@
using RoadTrain.DrawingObjects;
using RoadTrain.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RoadTrain
{
public partial class TrainConfig : Form
{
DrawingRoadTrain? _train = null;
private event Action<DrawingRoadTrain>? EventAddTrain;
public TrainConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
private void DrawTrain()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_train?.SetPosition(5, 5);
_train?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
internal void AddEvent(Action<DrawingRoadTrain> ev)
{
if (EventAddTrain == null)
{
EventAddTrain = ev;
}
else
{
EventAddTrain += ev;
}
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_train = new DrawingRoadTrain((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_train = new DrawingRoadTrainWithTank((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTank.Checked,
checkBoxBrush.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawTrain();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_train == null)
return;
switch (((Label)sender).Name)
{
case "labelBodyColor":
_train.EntityRoadTrain.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAddColor":
if (!(_train is DrawingRoadTrainWithTank))
return;
(_train.EntityRoadTrain as EntityRoadTrainWithTank).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawTrain();
}
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddTrain?.Invoke(_train);
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.DrawingObjects;
namespace RoadTrain
{
internal class TrainDelegate
{
public delegate void Action(DrawingRoadTrain train);
}
}

View File

@ -16,7 +16,7 @@ namespace RoadTrain.Generics
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 220;
private readonly int _placeSizeWidth = 200;
private readonly int _placeSizeHeight = 100;
private readonly SetGeneric<T> _collection;
public TrainsGenericCollection(int picWidth, int picHeight)

View File

@ -23,13 +23,19 @@ namespace RoadTrain.Generics
}
public void AddSet(string name)
{
if (!_trainStorages.ContainsKey(name))
_trainStorages.Add(name, new TrainsGenericCollection<DrawingRoadTrain, DrawingObjectTrain>(_pictureWidth, _pictureHeight));
if (_trainStorages.ContainsKey(name))
{
return;
}
_trainStorages[name] = new TrainsGenericCollection<DrawingRoadTrain, DrawingObjectTrain>(_pictureWidth, _pictureHeight);
}
public void DelSet(string name)
{
if (_trainStorages.ContainsKey(name))
_trainStorages.Remove(name);
if (!_trainStorages.ContainsKey(name))
{
return;
}
_trainStorages.Remove(name);
}
public TrainsGenericCollection<DrawingRoadTrain, DrawingObjectTrain>?
this[string ind]