100%
This commit is contained in:
parent
cb80d0bdd5
commit
0ec10cf560
@ -20,8 +20,8 @@ namespace DumpTruck.DrawningObjects
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена,
|
||||
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool trailer, int width, int height) :
|
||||
base (speed, weight, bodyColor, additionalColor, width, height,110, 85)
|
||||
additionalColor, bool trailer, int width, int height)
|
||||
: base (speed, weight, bodyColor, width, height,110, 85)
|
||||
{
|
||||
if (EntityTruck != null)
|
||||
{
|
||||
@ -40,11 +40,15 @@ namespace DumpTruck.DrawningObjects
|
||||
if (dumpTruck.Trailer)
|
||||
{
|
||||
//прицеп
|
||||
Brush trailer = new SolidBrush(EntityTruck.AdditionalColor);
|
||||
Brush trailer = new SolidBrush(dumpTruck.AdditionalColor);
|
||||
g.FillRectangle(trailer, _startPosX, _startPosY, 5, 38);
|
||||
g.FillRectangle(trailer, _startPosX + 5, _startPosY + 33, 70, 5);
|
||||
g.FillRectangle(trailer, _startPosX + 70, _startPosY, 5, 38);
|
||||
}
|
||||
}
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
(EntityTruck as EntityDumpTruck).SetAdditionalColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ namespace DumpTruck.DrawningObjects
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningTruck(int speed, double weight, Color bodyColor,Color additionalColor, int width, int height)
|
||||
public DrawningTruck(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width < _truckWidth || height < _truckHeight)
|
||||
@ -80,7 +80,7 @@ namespace DumpTruck.DrawningObjects
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor);
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -92,7 +92,7 @@ namespace DumpTruck.DrawningObjects
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="truckWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="truckHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningTruck(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int truckWidth, int truckHeight)
|
||||
protected DrawningTruck(int speed, double weight, Color bodyColor, int width, int height, int truckWidth, int truckHeight)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width < _truckWidth || height < _truckHeight)
|
||||
@ -103,7 +103,7 @@ namespace DumpTruck.DrawningObjects
|
||||
_pictureHeight = height;
|
||||
_truckWidth = truckWidth;
|
||||
_truckHeight = truckHeight;
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor);
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -211,5 +211,10 @@ namespace DumpTruck.DrawningObjects
|
||||
g.FillEllipse(wheels, _startPosX + 25, _startPosY + 63, 25, 25);
|
||||
g.FillEllipse(wheels, _startPosX + 85, _startPosY + 63, 25, 25);
|
||||
}
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
EntityTruck.SetBodyColor(color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ namespace DumpTruck.Entities
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Trailer { get; private set; }
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
|
||||
/// Инициализация полей объекта-класса
|
||||
/// </summary>
|
||||
@ -20,9 +22,14 @@ namespace DumpTruck.Entities
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool trailer) : base (speed,weight, bodyColor,additionalColor)
|
||||
additionalColor, bool trailer) : base (speed,weight, bodyColor)
|
||||
{
|
||||
Trailer = trailer;
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,6 @@ namespace DumpTruck.Entities
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
@ -36,13 +33,17 @@ namespace DumpTruck.Entities
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityTruck(int speed, double weight, Color bodyColor,Color additionalColor)
|
||||
public EntityTruck(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace DumpTruck
|
||||
}
|
||||
|
||||
_drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000),
|
||||
color, color,
|
||||
color,
|
||||
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
||||
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
|
@ -47,32 +47,7 @@ namespace DumpTruck
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormDumpTruck form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (obj + form.selectedTruck != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -133,7 +108,39 @@ namespace DumpTruck
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
private void AddTruck(DrawningTruck truck)
|
||||
{
|
||||
truck._pictureWidth = pictureBoxCollection.Width;
|
||||
truck._pictureHeight = pictureBoxCollection.Height;
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (obj + truck != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var formTruckConfig = new FormTruckConfig();
|
||||
formTruckConfig.AddEvent(AddTruck);
|
||||
formTruckConfig.Show();
|
||||
}
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
|
352
DumpTruck/DumpTruck/FormTruckConfig.Designer.cs
generated
Normal file
352
DumpTruck/DumpTruck/FormTruckConfig.Designer.cs
generated
Normal file
@ -0,0 +1,352 @@
|
||||
namespace DumpTruck
|
||||
{
|
||||
partial class FormTruckConfig
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxConfig = new GroupBox();
|
||||
labelModifiedObject = new Label();
|
||||
labelSimpleObject = new Label();
|
||||
groupBoxColor = new GroupBox();
|
||||
panelBlue = new Panel();
|
||||
panelLime = new Panel();
|
||||
panelRed = new Panel();
|
||||
panelOrange = new Panel();
|
||||
panelBrown = new Panel();
|
||||
panelYellow = new Panel();
|
||||
panelBlack = new Panel();
|
||||
panelWrite = new Panel();
|
||||
checkBoxTrailer = new CheckBox();
|
||||
numericUpDownWeight = new NumericUpDown();
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
pictureBoxObject = new PictureBox();
|
||||
panelObject = new Panel();
|
||||
labelAdditionalColor = new Label();
|
||||
labelBodyColor = new Label();
|
||||
buttonOk = new Button();
|
||||
buttonCancel = new Button();
|
||||
groupBoxConfig.SuspendLayout();
|
||||
groupBoxColor.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||
panelObject.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
groupBoxConfig.Controls.Add(labelModifiedObject);
|
||||
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||
groupBoxConfig.Controls.Add(groupBoxColor);
|
||||
groupBoxConfig.Controls.Add(checkBoxTrailer);
|
||||
groupBoxConfig.Controls.Add(numericUpDownWeight);
|
||||
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
||||
groupBoxConfig.Controls.Add(label2);
|
||||
groupBoxConfig.Controls.Add(label1);
|
||||
groupBoxConfig.Location = new Point(12, 24);
|
||||
groupBoxConfig.Name = "groupBoxConfig";
|
||||
groupBoxConfig.Size = new Size(724, 393);
|
||||
groupBoxConfig.TabIndex = 0;
|
||||
groupBoxConfig.TabStop = false;
|
||||
groupBoxConfig.Text = "groupBox1";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelModifiedObject.Location = new Point(550, 264);
|
||||
labelModifiedObject.Name = "labelModifiedObject";
|
||||
labelModifiedObject.Size = new Size(140, 40);
|
||||
labelModifiedObject.TabIndex = 7;
|
||||
labelModifiedObject.Text = "Продвинутый";
|
||||
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelModifiedObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleObject.Location = new Point(317, 264);
|
||||
labelSimpleObject.Name = "labelSimpleObject";
|
||||
labelSimpleObject.Size = new Size(140, 40);
|
||||
labelSimpleObject.TabIndex = 6;
|
||||
labelSimpleObject.Text = "Простой";
|
||||
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// groupBoxColor
|
||||
//
|
||||
groupBoxColor.Controls.Add(panelBlue);
|
||||
groupBoxColor.Controls.Add(panelLime);
|
||||
groupBoxColor.Controls.Add(panelRed);
|
||||
groupBoxColor.Controls.Add(panelOrange);
|
||||
groupBoxColor.Controls.Add(panelBrown);
|
||||
groupBoxColor.Controls.Add(panelYellow);
|
||||
groupBoxColor.Controls.Add(panelBlack);
|
||||
groupBoxColor.Controls.Add(panelWrite);
|
||||
groupBoxColor.Location = new Point(287, 26);
|
||||
groupBoxColor.Name = "groupBoxColor";
|
||||
groupBoxColor.Size = new Size(418, 213);
|
||||
groupBoxColor.TabIndex = 5;
|
||||
groupBoxColor.TabStop = false;
|
||||
groupBoxColor.Text = "groupBox2";
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Blue;
|
||||
panelBlue.Location = new Point(317, 123);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(62, 58);
|
||||
panelBlue.TabIndex = 1;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelLime
|
||||
//
|
||||
panelLime.BackColor = Color.Lime;
|
||||
panelLime.Location = new Point(225, 123);
|
||||
panelLime.Name = "panelLime";
|
||||
panelLime.Size = new Size(62, 58);
|
||||
panelLime.TabIndex = 1;
|
||||
panelLime.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.Red;
|
||||
panelRed.Location = new Point(317, 40);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(62, 58);
|
||||
panelRed.TabIndex = 1;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelOrange
|
||||
//
|
||||
panelOrange.BackColor = Color.OrangeRed;
|
||||
panelOrange.Location = new Point(225, 40);
|
||||
panelOrange.Name = "panelOrange";
|
||||
panelOrange.Size = new Size(62, 58);
|
||||
panelOrange.TabIndex = 1;
|
||||
panelOrange.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBrown
|
||||
//
|
||||
panelBrown.BackColor = Color.Brown;
|
||||
panelBrown.Location = new Point(131, 123);
|
||||
panelBrown.Name = "panelBrown";
|
||||
panelBrown.Size = new Size(62, 58);
|
||||
panelBrown.TabIndex = 1;
|
||||
panelBrown.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(131, 40);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(62, 58);
|
||||
panelYellow.TabIndex = 2;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = SystemColors.ActiveCaptionText;
|
||||
panelBlack.Location = new Point(30, 123);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(62, 58);
|
||||
panelBlack.TabIndex = 1;
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelWrite
|
||||
//
|
||||
panelWrite.BackColor = SystemColors.ButtonHighlight;
|
||||
panelWrite.Location = new Point(30, 40);
|
||||
panelWrite.Name = "panelWrite";
|
||||
panelWrite.Size = new Size(62, 58);
|
||||
panelWrite.TabIndex = 0;
|
||||
panelWrite.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// checkBoxTrailer
|
||||
//
|
||||
checkBoxTrailer.AutoSize = true;
|
||||
checkBoxTrailer.Location = new Point(48, 160);
|
||||
checkBoxTrailer.Name = "checkBoxTrailer";
|
||||
checkBoxTrailer.Size = new Size(72, 24);
|
||||
checkBoxTrailer.TabIndex = 4;
|
||||
checkBoxTrailer.Text = "Trailer";
|
||||
checkBoxTrailer.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(133, 111);
|
||||
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(77, 27);
|
||||
numericUpDownWeight.TabIndex = 3;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(133, 42);
|
||||
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(77, 27);
|
||||
numericUpDownSpeed.TabIndex = 2;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(48, 113);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(36, 20);
|
||||
label2.TabIndex = 1;
|
||||
label2.Text = "Вес:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(48, 49);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(76, 20);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Скорость:";
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(12, 38);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(333, 253);
|
||||
pictureBoxObject.TabIndex = 1;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
panelObject.AllowDrop = true;
|
||||
panelObject.Controls.Add(labelAdditionalColor);
|
||||
panelObject.Controls.Add(labelBodyColor);
|
||||
panelObject.Controls.Add(pictureBoxObject);
|
||||
panelObject.Location = new Point(742, 37);
|
||||
panelObject.Name = "panelObject";
|
||||
panelObject.Size = new Size(363, 326);
|
||||
panelObject.TabIndex = 3;
|
||||
panelObject.DragDrop += PanelObject_DragDrop;
|
||||
panelObject.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// labelAdditionalColor
|
||||
//
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new Point(211, 8);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
labelAdditionalColor.Size = new Size(111, 25);
|
||||
labelAdditionalColor.TabIndex = 3;
|
||||
labelAdditionalColor.Text = "Доп Цвет";
|
||||
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAdditionalColor.UseMnemonic = false;
|
||||
labelAdditionalColor.DragDrop += labelColor_DragDrop;
|
||||
labelAdditionalColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// labelBodyColor
|
||||
//
|
||||
labelBodyColor.AllowDrop = true;
|
||||
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelBodyColor.Location = new Point(42, 8);
|
||||
labelBodyColor.Name = "labelBodyColor";
|
||||
labelBodyColor.Size = new Size(100, 25);
|
||||
labelBodyColor.TabIndex = 2;
|
||||
labelBodyColor.Text = "Цвет";
|
||||
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelBodyColor.DragDrop += labelColor_DragDrop;
|
||||
labelBodyColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
buttonOk.Location = new Point(764, 379);
|
||||
buttonOk.Name = "buttonOk";
|
||||
buttonOk.Size = new Size(94, 29);
|
||||
buttonOk.TabIndex = 4;
|
||||
buttonOk.Text = "Добавить";
|
||||
buttonOk.UseVisualStyleBackColor = true;
|
||||
buttonOk.Click += buttonOk_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(993, 379);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Удалить";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormTruckConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1132, 455);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonOk);
|
||||
Controls.Add(panelObject);
|
||||
Controls.Add(groupBoxConfig);
|
||||
Name = "FormTruckConfig";
|
||||
Text = "Создание объекта";
|
||||
groupBoxConfig.ResumeLayout(false);
|
||||
groupBoxConfig.PerformLayout();
|
||||
groupBoxColor.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||
panelObject.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private CheckBox checkBoxTrailer;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private GroupBox groupBoxColor;
|
||||
private Panel panelWrite;
|
||||
private Panel panelBlue;
|
||||
private Panel panelLime;
|
||||
private Panel panelRed;
|
||||
private Panel panelOrange;
|
||||
private Panel panelBrown;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlack;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panelObject;
|
||||
private Label labelAdditionalColor;
|
||||
private Label labelBodyColor;
|
||||
private Button buttonOk;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
175
DumpTruck/DumpTruck/FormTruckConfig.cs
Normal file
175
DumpTruck/DumpTruck/FormTruckConfig.cs
Normal file
@ -0,0 +1,175 @@
|
||||
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;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Generics;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using DumpTruck.Entities;
|
||||
|
||||
namespace DumpTruck
|
||||
{
|
||||
public partial class FormTruckConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранная машина
|
||||
/// </summary>
|
||||
DrawningTruck? _truck = null;
|
||||
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawningTruck> EventAddTruck;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTruckConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
panelWrite.MouseDown += panelColor_MouseDown;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
panelLime.MouseDown += panelColor_MouseDown;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
panelOrange.MouseDown += panelColor_MouseDown;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
panelBrown.MouseDown += panelColor_MouseDown;
|
||||
|
||||
buttonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовать машину
|
||||
/// </summary>
|
||||
private void DrawTruck()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_truck?.SetPosition(5, 5);
|
||||
_truck?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
public void AddEvent(Action<DrawningTruck> ev)
|
||||
{
|
||||
if (EventAddTruck == null)
|
||||
{
|
||||
EventAddTruck = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddTruck += ev;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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 labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_truck = new DrawningTruck((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||
checkBoxTrailer.Checked, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawTruck();
|
||||
}
|
||||
|
||||
public void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_truck == null)
|
||||
return;
|
||||
|
||||
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelBodyColor":
|
||||
_truck.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAdditionalColor":
|
||||
if (!(_truck is DrawningDumpTruck))
|
||||
{
|
||||
return;
|
||||
}
|
||||
(_truck as DrawningDumpTruck).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawTruck();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление машины
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddTruck?.Invoke(_truck);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
120
DumpTruck/DumpTruck/FormTruckConfig.resx
Normal file
120
DumpTruck/DumpTruck/FormTruckConfig.resx
Normal 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>
|
Loading…
Reference in New Issue
Block a user