Коммит

This commit is contained in:
Stranni15k 2022-11-19 23:06:12 +04:00
parent 73c5fa9476
commit 6d3d2b2283
9 changed files with 641 additions and 32 deletions

View File

@ -8,10 +8,10 @@ namespace ElectricLocomotive
{ {
internal class DrawningElectricLocomotive : DrawningLocomotive internal class DrawningElectricLocomotive : DrawningLocomotive
{ {
public DrawningElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : public DrawningElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool sportLine) :
base(speed, weight, bodyColor, 110, 60) base(speed, weight, bodyColor, 110, 60)
{ {
Locomotive = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); Locomotive = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, bodyKit, sportLine);
} }
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
@ -24,7 +24,6 @@ namespace ElectricLocomotive
Pen window = new(Color.Blue); Pen window = new(Color.Blue);
Brush dopBrush = new SolidBrush(sportCar.DopColor); Brush dopBrush = new SolidBrush(sportCar.DopColor);
if (sportCar.BodyKit) if (sportCar.BodyKit)
{ {
Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 15, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY)), new Point(Convert.ToInt32(_startPosX) + 75, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY) + 40) }; Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 15, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY)), new Point(Convert.ToInt32(_startPosX) + 75, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY) + 40) };
@ -39,5 +38,9 @@ namespace ElectricLocomotive
base.DrawTransport(g); base.DrawTransport(g);
} }
public void SetExtraColor(Color color)
{
(Locomotive as EntityElectricLocomotive).DopColor = color;
}
} }
} }

View File

@ -147,6 +147,10 @@ namespace ElectricLocomotive
_startPosY = _pictureHeight.Value - _locomotiveHeight; _startPosY = _pictureHeight.Value - _locomotiveHeight;
} }
} }
public void SetBodyColor(Color color)
{
(Locomotive as EntityLocomotive).setColor(color);
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight); return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight);

View File

@ -8,16 +8,14 @@ namespace ElectricLocomotive
{ {
internal class EntityElectricLocomotive : EntityLocomotive internal class EntityElectricLocomotive : EntityLocomotive
{ {
public Color DopColor { get; private set; } public Color DopColor { get; set; }
public bool BodyKit { get; private set; } public bool BodyKit { get; private set; }
public bool Wing { get; private set; }
public bool SportLine { get; private set; } public bool SportLine { get; private set; }
public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool sportLine) :
base(speed, weight, bodyColor) base(speed, weight, bodyColor)
{ {
DopColor = dopColor; DopColor = dopColor;
BodyKit = bodyKit; BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine; SportLine = sportLine;
} }
} }

View File

@ -11,7 +11,7 @@ namespace ElectricLocomotive
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public float Weight { get; private set; } public float Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
public float Step => Speed * 100 / Weight; public float Step => Speed * 100 / Weight;
public EntityLocomotive(int speed, float weight, Color bodyColor) public EntityLocomotive(int speed, float weight, Color bodyColor)
{ {
@ -20,5 +20,10 @@ namespace ElectricLocomotive
Weight = weight <= 0 ? rnd.Next(150, 200) : weight; Weight = weight <= 0 ? rnd.Next(150, 200) : weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
public void setColor(Color color)
{
BodyColor = color;
}
} }
} }

View File

@ -98,7 +98,7 @@ namespace ElectricLocomotive
_locomotive = new DrawningElectricLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), _locomotive = new DrawningElectricLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
color, dopColor, color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
2)), Convert.ToBoolean(rnd.Next(0, 2))); 2)));
SetData(); SetData();
Draw(); Draw();
} }

View File

@ -0,0 +1,398 @@
namespace ElectricLocomotive
{
partial class FormLocomotiveConfig
{
/// <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()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.labelHardObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.checkBoxProvod = new System.Windows.Forms.CheckBox();
this.checkBoxObv = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelobject = new System.Windows.Forms.Panel();
this.LabelDopColor = new System.Windows.Forms.Label();
this.LabelBaseColor = new System.Windows.Forms.Label();
this.buttonOk = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelobject.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.labelHardObject);
this.groupBox1.Controls.Add(this.labelSimpleObject);
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.checkBoxProvod);
this.groupBox1.Controls.Add(this.checkBoxObv);
this.groupBox1.Controls.Add(this.numericUpDownWeight);
this.groupBox1.Controls.Add(this.numericUpDownSpeed);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(470, 201);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Параметры";
//
// labelHardObject
//
this.labelHardObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelHardObject.Location = new System.Drawing.Point(334, 166);
this.labelHardObject.Name = "labelHardObject";
this.labelHardObject.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.labelHardObject.Size = new System.Drawing.Size(100, 23);
this.labelHardObject.TabIndex = 9;
this.labelHardObject.Text = "Продвинутый";
this.labelHardObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelHardObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelSimpleObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(228, 166);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(100, 23);
this.labelSimpleObject.TabIndex = 8;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelSimpleObject_MouseDown);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.panelWhite);
this.groupBox2.Controls.Add(this.panelYellow);
this.groupBox2.Controls.Add(this.panelGray);
this.groupBox2.Controls.Add(this.panelBlue);
this.groupBox2.Controls.Add(this.panelGreen);
this.groupBox2.Controls.Add(this.panelPurple);
this.groupBox2.Controls.Add(this.panelRed);
this.groupBox2.Controls.Add(this.panelBlack);
this.groupBox2.Location = new System.Drawing.Point(216, 22);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(228, 130);
this.groupBox2.TabIndex = 7;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Цвета";
//
// panelWhite
//
this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(167, 78);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(43, 44);
this.panelWhite.TabIndex = 3;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelYellow
//
this.panelYellow.AllowDrop = true;
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(167, 28);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(43, 44);
this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGray
//
this.panelGray.AllowDrop = true;
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(118, 78);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(43, 44);
this.panelGray.TabIndex = 4;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.AllowDrop = true;
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(69, 78);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(43, 44);
this.panelBlue.TabIndex = 5;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.AllowDrop = true;
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(118, 28);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(43, 44);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelPurple
//
this.panelPurple.AllowDrop = true;
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(20, 78);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(43, 44);
this.panelPurple.TabIndex = 2;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
this.panelRed.AllowDrop = true;
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(69, 28);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(43, 44);
this.panelRed.TabIndex = 1;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlack
//
this.panelBlack.AllowDrop = true;
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(20, 28);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(43, 44);
this.panelBlack.TabIndex = 0;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBoxProvod
//
this.checkBoxProvod.AutoSize = true;
this.checkBoxProvod.Location = new System.Drawing.Point(6, 145);
this.checkBoxProvod.Name = "checkBoxProvod";
this.checkBoxProvod.Size = new System.Drawing.Size(163, 19);
this.checkBoxProvod.TabIndex = 5;
this.checkBoxProvod.Text = "Признак наличия отвала";
this.checkBoxProvod.UseVisualStyleBackColor = true;
//
// checkBoxObv
//
this.checkBoxObv.AutoSize = true;
this.checkBoxObv.Location = new System.Drawing.Point(6, 120);
this.checkBoxObv.Name = "checkBoxObv";
this.checkBoxObv.Size = new System.Drawing.Size(179, 19);
this.checkBoxObv.TabIndex = 4;
this.checkBoxObv.Text = "Признак наличия проводов";
this.checkBoxObv.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(74, 71);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 42);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 73);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 15);
this.label2.TabIndex = 1;
this.label2.Text = "Вес:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 44);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Скорость:";
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(12, 42);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(212, 122);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
// panelobject
//
this.panelobject.AllowDrop = true;
this.panelobject.Controls.Add(this.LabelDopColor);
this.panelobject.Controls.Add(this.LabelBaseColor);
this.panelobject.Controls.Add(this.pictureBoxObject);
this.panelobject.Location = new System.Drawing.Point(525, 12);
this.panelobject.Name = "panelobject";
this.panelobject.Size = new System.Drawing.Size(238, 172);
this.panelobject.TabIndex = 10;
this.panelobject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelobject_DragDrop);
this.panelobject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelobject_DragEnter);
//
// LabelDopColor
//
this.LabelDopColor.AllowDrop = true;
this.LabelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.LabelDopColor.Location = new System.Drawing.Point(124, 9);
this.LabelDopColor.Name = "LabelDopColor";
this.LabelDopColor.Size = new System.Drawing.Size(100, 23);
this.LabelDopColor.TabIndex = 3;
this.LabelDopColor.Text = "Доп.цвет";
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
//
this.LabelBaseColor.AllowDrop = true;
this.LabelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.LabelBaseColor.Location = new System.Drawing.Point(12, 9);
this.LabelBaseColor.Name = "LabelBaseColor";
this.LabelBaseColor.Size = new System.Drawing.Size(100, 23);
this.LabelBaseColor.TabIndex = 2;
this.LabelBaseColor.Text = "Цвет";
this.LabelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.LabelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.LabelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(537, 190);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(75, 23);
this.buttonOk.TabIndex = 11;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(674, 190);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 12;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
//
// FormLocomotiveConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(783, 221);
this.Controls.Add(this.button2);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panelobject);
this.Controls.Add(this.groupBox1);
this.Name = "FormLocomotiveConfig";
this.Text = "FormLocomotiveConfig";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelobject.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Label labelHardObject;
private Label labelSimpleObject;
private GroupBox groupBox2;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelGray;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelPurple;
private Panel panelRed;
private Panel panelBlack;
private CheckBox checkBoxProvod;
private CheckBox checkBoxObv;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label label2;
private Label label1;
private PictureBox pictureBoxObject;
private Panel panelobject;
private Label LabelDopColor;
private Label LabelBaseColor;
private Button buttonOk;
private Button button2;
}
}

View File

@ -0,0 +1,139 @@
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 ElectricLocomotive
{
public partial class FormLocomotiveConfig : Form
{
private event Action<DrawningLocomotive> EventAddLocomotive;
DrawningLocomotive _locomotive = null;
public FormLocomotiveConfig()
{
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;
}
public void AddEvent(Action<DrawningLocomotive> ev)
{
if (EventAddLocomotive == null)
{
EventAddLocomotive = new Action<DrawningLocomotive>(ev);
}
else
{
EventAddLocomotive += ev;
}
}
private void DrawLocomotive()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_locomotive?.SetPosition(5, 5, pictureBoxObject.Width,
pictureBoxObject.Height);
_locomotive?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void labelSimpleObject_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))
{
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":
{
_locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
}
break;
case "labelHardObject":
{
_locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxObv.Checked, checkBoxProvod.Checked);
}
break;
}
DrawLocomotive();
}
private void buttonOk_Click(object sender, EventArgs e)
{
EventAddLocomotive?.Invoke(_locomotive);
Close();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
_locomotive.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawLocomotive();
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_locomotive is not DrawningElectricLocomotive HardLocomotive)
{
return;
}
HardLocomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color)));
DrawLocomotive();
}
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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

@ -12,7 +12,7 @@ namespace ElectricLocomotive
{ {
public partial class FormMapWithSetLocomotive : Form public partial class FormMapWithSetLocomotive : Form
{ {
private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotiveCollectionGeneric; private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapShipCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapDict = new() private readonly Dictionary<string, AbstractMap> _mapDict = new()
{ {
{"Простая карта", new SimpleMap() }, {"Простая карта", new SimpleMap() },
@ -67,34 +67,37 @@ namespace ElectricLocomotive
} }
if (map != null) if (map != null)
{ {
_mapLocomotiveCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>( _mapShipCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(
pictureBox1.Width, pictureBox1.Height, map); pictureBox1.Width, pictureBox1.Height, map);
} }
else else
{ {
_mapLocomotiveCollectionGeneric = null; _mapShipCollectionGeneric = null;
} }
} }
private void ButtonAddLocomotive_Click(object sender, EventArgs e) private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
var FormLocmotiveConfig = new FormLocomotiveConfig();
FormLocmotiveConfig.AddEvent(new(AddLocomotive));
FormLocmotiveConfig.Show();
}
public void AddLocomotive(DrawningLocomotive aircraft)
{ {
if (ListBoxMaps.SelectedIndex == -1) if (ListBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
FormLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK) if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(aircraft) != -1)
{ {
DrawningObjectLocomotive Locomotive = new(form.SelectedLocomotive); MessageBox.Show("Object is added");
if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + Locomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Unable to add object");
}
} }
} }
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e) private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
{ {
@ -182,7 +185,6 @@ namespace ElectricLocomotive
{ {
pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
private void ButtonDeleteMap_Click(object sender, EventArgs e) private void ButtonDeleteMap_Click(object sender, EventArgs e)
{ {
if (ListBoxMaps.SelectedIndex == -1) if (ListBoxMaps.SelectedIndex == -1)