Yahontov O.U. LabWork5 #6

Closed
Arklightning wants to merge 5 commits from LabWork5 into LabWork4
5 changed files with 147 additions and 60 deletions
Showing only changes of commit 92b5d17585 - Show all commits

View File

@ -12,16 +12,16 @@ namespace Trolleybus
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
public Color DopColor { get; set; }
/// <summary>
/// Признак наличия обвеса
/// </summary>
public bool BodyKit { get; private set; }
public bool BodyKit { get; set; }
/// <summary>
/// Признак наличия гоночной полосы
/// </summary>
public bool Horns { get; private set; }
public bool Battary { get; private set; }
public bool Horns { get; set; }
public bool Battary { get; set; }
/// <summary>
/// Инициализация свойств
/// </summary>

View File

@ -23,7 +23,7 @@ namespace Trolleybus
/// <summary>
/// Цвет кузова
/// </summary>
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
/// <summary>
/// Шаг перемещения троллейбуса
/// </summary>

View File

@ -107,12 +107,34 @@ namespace Trolleybus
_mapTrolleybusCollectionGeneric = null;
}
}
private void ButtonAddTrolleybus_Click(object sender, EventArgs e)
private void AddTrolleybus(DrawingTrolleybus trolleybus)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectTrolleybus(trolleybus) != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void ButtonAddTrolleybus_Click(object sender, EventArgs e)
{
var formTrolleybusConfig = new FormTrolleybusConfig();
formTrolleybusConfig.AddEvent(AddTrolleybus);
formTrolleybusConfig.Show();
/*if (listBoxMaps.SelectedIndex == -1)
{
return;
}
Form1 form = new();
if (form.ShowDialog() == DialogResult.OK)
{
@ -126,7 +148,7 @@ namespace Trolleybus
{
MessageBox.Show("Не удалось добавить объект");
}
}
}*/
}
/// <summary>
/// Удаление объекта

View File

@ -29,8 +29,9 @@
private void InitializeComponent()
{
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.checkBoxBodyKit = new System.Windows.Forms.CheckBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.lebelSimpleObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
@ -50,9 +51,8 @@
this.panelObject = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.checkBoxBodyKit = new System.Windows.Forms.CheckBox();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
@ -65,7 +65,7 @@
//
this.groupBoxConfig.Controls.Add(this.checkBoxBodyKit);
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
this.groupBoxConfig.Controls.Add(this.lebelSimpleObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxBattary);
this.groupBoxConfig.Controls.Add(this.checkBoxHorns);
@ -80,6 +80,16 @@
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// checkBoxBodyKit
//
this.checkBoxBodyKit.AutoSize = true;
this.checkBoxBodyKit.Location = new System.Drawing.Point(11, 224);
this.checkBoxBodyKit.Name = "checkBoxBodyKit";
this.checkBoxBodyKit.Size = new System.Drawing.Size(89, 24);
this.checkBoxBodyKit.TabIndex = 10;
this.checkBoxBodyKit.Text = "BodyKit";
this.checkBoxBodyKit.UseVisualStyleBackColor = true;
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
@ -88,16 +98,19 @@
this.labelModifiedObject.Size = new System.Drawing.Size(130, 34);
this.labelModifiedObject.TabIndex = 9;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_Mouse_Down);
//
// lebelSimpleObject
// labelSimpleObject
//
this.lebelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lebelSimpleObject.Location = new System.Drawing.Point(336, 214);
this.lebelSimpleObject.Name = "lebelSimpleObject";
this.lebelSimpleObject.Size = new System.Drawing.Size(100, 34);
this.lebelSimpleObject.TabIndex = 8;
this.lebelSimpleObject.Text = "Простой";
this.lebelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelSimpleObject_Mouse_Down);
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(336, 214);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(100, 34);
this.labelSimpleObject.TabIndex = 8;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_Mouse_Down);
//
// groupBoxColors
//
@ -115,7 +128,6 @@
this.groupBoxColors.TabIndex = 7;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
this.groupBoxColors.Enter += new System.EventHandler(this.groupBox2_Enter);
//
// panelPurple
//
@ -124,6 +136,7 @@
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(62, 49);
this.panelPurple.TabIndex = 2;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlack
//
@ -132,6 +145,7 @@
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(62, 49);
this.panelBlack.TabIndex = 2;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGrey
//
@ -140,6 +154,7 @@
this.panelGrey.Name = "panelGrey";
this.panelGrey.Size = new System.Drawing.Size(62, 49);
this.panelGrey.TabIndex = 2;
this.panelGrey.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelWhite
//
@ -148,6 +163,7 @@
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(62, 49);
this.panelWhite.TabIndex = 2;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelYellow
//
@ -156,6 +172,7 @@
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(62, 49);
this.panelYellow.TabIndex = 2;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlue
//
@ -164,6 +181,7 @@
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(62, 49);
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
@ -172,6 +190,7 @@
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(62, 50);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
@ -180,6 +199,7 @@
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(62, 49);
this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBoxBattary
//
@ -245,77 +265,78 @@
//
// pictureBoxObject
//
this.pictureBoxObject.Anchor = System.Windows.Forms.AnchorStyles.None;
this.pictureBoxObject.Location = new System.Drawing.Point(27, 81);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(218, 141);
this.pictureBoxObject.Size = new System.Drawing.Size(346, 208);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(698, 39);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(288, 245);
this.panelObject.Size = new System.Drawing.Size(412, 316);
this.panelObject.TabIndex = 2;
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(139, 26);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(106, 52);
this.labelDopColor.TabIndex = 3;
this.labelDopColor.Text = "Доп цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// labelColor
//
this.labelColor.AllowDrop = true;
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(27, 26);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(106, 52);
this.labelColor.TabIndex = 2;
this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// button1
// buttonOk
//
this.button1.Location = new System.Drawing.Point(725, 290);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(106, 50);
this.button1.TabIndex = 3;
this.button1.Text = "Добваить";
this.button1.UseVisualStyleBackColor = true;
this.buttonOk.Location = new System.Drawing.Point(725, 361);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(106, 50);
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добваить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// button2
// buttonCancel
//
this.button2.Location = new System.Drawing.Point(837, 290);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(106, 50);
this.button2.TabIndex = 4;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
//
// checkBoxBodyKit
//
this.checkBoxBodyKit.AutoSize = true;
this.checkBoxBodyKit.Location = new System.Drawing.Point(11, 224);
this.checkBoxBodyKit.Name = "checkBoxBodyKit";
this.checkBoxBodyKit.Size = new System.Drawing.Size(89, 24);
this.checkBoxBodyKit.TabIndex = 10;
this.checkBoxBodyKit.Text = "BodyKit";
this.checkBoxBodyKit.UseVisualStyleBackColor = true;
this.buttonCancel.Location = new System.Drawing.Point(837, 361);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(106, 50);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormTrolleybusConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1180, 482);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormTrolleybusConfig";
@ -345,7 +366,7 @@
private System.Windows.Forms.Label labelWeight;
private System.Windows.Forms.Label labelSpeed;
private System.Windows.Forms.Label labelModifiedObject;
private System.Windows.Forms.Label lebelSimpleObject;
private System.Windows.Forms.Label labelSimpleObject;
private System.Windows.Forms.Panel panelPurple;
private System.Windows.Forms.Panel panelBlack;
private System.Windows.Forms.Panel panelGrey;
@ -355,8 +376,8 @@
private System.Windows.Forms.Panel panelObject;
private System.Windows.Forms.Label labelDopColor;
private System.Windows.Forms.Label labelColor;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button buttonOk;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.CheckBox checkBoxBodyKit;
}
}

View File

@ -17,13 +17,23 @@ namespace Trolleybus
public FormTrolleybusConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGrey.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 += (object sender, EventArgs e) => Close();
}
private void DrawTrolleybus()
{
Bitmap btm = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(btm);
_trolleybus?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_trolleybus?.SetPosition(25, 25, pictureBoxObject.Width, pictureBoxObject.Height);
_trolleybus?.DrawTransport(gr);
pictureBoxObject.Image = btm;
}
@ -40,12 +50,7 @@ namespace Trolleybus
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void labelSimpleObject_Mouse_Down(object sender, MouseEventArgs e)
private void labelObject_Mouse_Down(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
@ -64,6 +69,7 @@ namespace Trolleybus
private void panelObject_DragDrop(object sender, DragEventArgs e)
{
//labelColor.BackColor = Color.Red;
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
@ -71,11 +77,49 @@ namespace Trolleybus
break;
case "labelModifiedObject":
_trolleybus = new DrawningSmallTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxHorns.Checked, checkBoxBattary.Checked, checkBoxBodyKit.Checked);
checkBoxBodyKit.Checked, checkBoxHorns.Checked, checkBoxBattary.Checked);
break;
}
DrawTrolleybus();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
//проверка на пустоту объекта
if (_trolleybus != null)
{
_trolleybus.Trolleybus.BodyColor = (Color)e.Data.GetData(typeof(Color));
DrawTrolleybus();
}
}
private void LabelAddColor_DragDrop(object sender, DragEventArgs e)
{
//проверка на пустоту объекта и правильную сущноть
if (_trolleybus != null && _trolleybus.Trolleybus is EntitySmallTrolleybus smallTrolleybus)
{
smallTrolleybus.DopColor = (Color)e.Data.GetData(typeof(Color));
DrawTrolleybus();
}
}
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddTrolleybus?.Invoke(_trolleybus);