5 лаба, работает, но надо доделать малясь

This commit is contained in:
a.puchkina 2023-11-18 23:36:59 +04:00
parent 07cc928cb7
commit 329ffa2e48
6 changed files with 238 additions and 74 deletions

View File

@ -229,5 +229,10 @@ namespace AirplaneWithRadar.DrawningObjects
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 72), new Point(_startPosX + 150, _startPosY + 55));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 72), new Point(_startPosX + 190, _startPosY + 55));
}
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
{
_pictureWidth = pictureBoxWidth;
_pictureHeight = pictureBoxHeight;
}
}
}

View File

@ -39,6 +39,10 @@ namespace AirplaneWithRadar.Entities
Weight = weight;
BodyColor = bodyColor;
}
internal void SetBodyColor(Color color)
{
BodyColor = color;
}
}
}

View File

@ -45,5 +45,9 @@ namespace AirplaneWithRadar.Entities
Tank = tank;
Pin = pin;
}
internal void SetAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@ -103,6 +103,25 @@ namespace AirplaneWithRadar
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/**private void buttonAdd_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
var formAirplaneConfig = new FormAirplaneConfig();
formAirplaneConfig.AddEvent(AddAirplane);
formAirplaneConfig.Show();
}
**/
private void buttonAdd_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
@ -115,20 +134,51 @@ namespace AirplaneWithRadar
{
return;
}
AirplaneWithRadarForm form = new();
if (form.ShowDialog() == DialogResult.OK)
var formAirplaneConfig = new FormAirplaneConfig();
formAirplaneConfig.Show();
Action<DrawningAirplane>? airplaneDelegate = new((m) =>
{
if (obj + form.SelectedAirplane)
bool isAddSuccessful = (obj + m);
if (isAddSuccessful)
{
MessageBox.Show("Объект добавлен");
m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
pictureBoxCollection.Image = obj.ShowAirplanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
formAirplaneConfig.AddEvent(airplaneDelegate);
}
/**private void AddAirplane(DrawningAirplane drawningAirplane)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (obj + drawningAirplane)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowAirplanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}**/
/// <summary>
/// Удаление объекта из набора
/// </summary>

View File

@ -36,7 +36,7 @@
panelYellow = new Panel();
panelBlack = new Panel();
panelBlue = new Panel();
panelGrey = new Panel();
panelGray = new Panel();
panelGreen = new Panel();
panelWhite = new Panel();
panelRed = new Panel();
@ -52,7 +52,7 @@
labelBodyColor = new Label();
pictureBoxObject = new PictureBox();
buttonOk = new Button();
button2 = new Button();
buttonCancel = new Button();
groupBoxParameters.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
@ -73,9 +73,11 @@
groupBoxParameters.Controls.Add(numericUpDownSpeed);
groupBoxParameters.Controls.Add(labelWeight);
groupBoxParameters.Controls.Add(labelSpeed);
groupBoxParameters.Location = new Point(12, 12);
groupBoxParameters.Location = new Point(10, 9);
groupBoxParameters.Margin = new Padding(3, 2, 3, 2);
groupBoxParameters.Name = "groupBoxParameters";
groupBoxParameters.Size = new Size(499, 254);
groupBoxParameters.Padding = new Padding(3, 2, 3, 2);
groupBoxParameters.Size = new Size(437, 190);
groupBoxParameters.TabIndex = 0;
groupBoxParameters.TabStop = false;
groupBoxParameters.Text = "Параметры";
@ -83,19 +85,20 @@
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(363, 192);
labelModifiedObject.Location = new Point(318, 144);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(111, 36);
labelModifiedObject.Size = new Size(97, 28);
labelModifiedObject.TabIndex = 10;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(264, 192);
labelSimpleObject.Location = new Point(231, 144);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(97, 36);
labelSimpleObject.Size = new Size(85, 28);
labelSimpleObject.TabIndex = 9;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
@ -107,13 +110,15 @@
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelGrey);
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Location = new Point(248, 42);
groupBoxColors.Location = new Point(217, 32);
groupBoxColors.Margin = new Padding(3, 2, 3, 2);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(232, 125);
groupBoxColors.Padding = new Padding(3, 2, 3, 2);
groupBoxColors.Size = new Size(203, 94);
groupBoxColors.TabIndex = 8;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Цвета";
@ -121,73 +126,90 @@
// panelPurple
//
panelPurple.BackColor = Color.Orchid;
panelPurple.Location = new Point(186, 79);
panelPurple.Location = new Point(163, 59);
panelPurple.Margin = new Padding(3, 2, 3, 2);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(40, 40);
panelPurple.Size = new Size(35, 30);
panelPurple.TabIndex = 7;
panelPurple.MouseDown += PanelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(186, 26);
panelYellow.Location = new Point(163, 20);
panelYellow.Margin = new Padding(3, 2, 3, 2);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(40, 40);
panelYellow.Size = new Size(35, 30);
panelYellow.TabIndex = 3;
panelYellow.MouseDown += PanelColor_MouseDown;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(129, 79);
panelBlack.Location = new Point(113, 59);
panelBlack.Margin = new Padding(3, 2, 3, 2);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(40, 40);
panelBlack.Size = new Size(35, 30);
panelBlack.TabIndex = 6;
panelBlack.MouseDown += PanelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.CornflowerBlue;
panelBlue.Location = new Point(129, 26);
panelBlue.Location = new Point(113, 20);
panelBlue.Margin = new Padding(3, 2, 3, 2);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(40, 40);
panelBlue.Size = new Size(35, 30);
panelBlue.TabIndex = 2;
panelBlue.MouseDown += PanelColor_MouseDown;
//
// panelGrey
// panelGray
//
panelGrey.BackColor = Color.DarkGray;
panelGrey.Location = new Point(73, 79);
panelGrey.Name = "panelGrey";
panelGrey.Size = new Size(40, 40);
panelGrey.TabIndex = 5;
panelGray.BackColor = Color.DarkGray;
panelGray.Location = new Point(64, 59);
panelGray.Margin = new Padding(3, 2, 3, 2);
panelGray.Name = "panelGray";
panelGray.Size = new Size(35, 30);
panelGray.TabIndex = 5;
panelGray.MouseDown += PanelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.YellowGreen;
panelGreen.Location = new Point(73, 26);
panelGreen.Location = new Point(64, 20);
panelGreen.Margin = new Padding(3, 2, 3, 2);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(40, 40);
panelGreen.Size = new Size(35, 30);
panelGreen.TabIndex = 1;
panelGreen.MouseDown += PanelColor_MouseDown;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(16, 79);
panelWhite.Location = new Point(14, 59);
panelWhite.Margin = new Padding(3, 2, 3, 2);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(40, 40);
panelWhite.Size = new Size(35, 30);
panelWhite.TabIndex = 4;
panelWhite.MouseDown += PanelColor_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.IndianRed;
panelRed.Location = new Point(16, 26);
panelRed.Location = new Point(14, 20);
panelRed.Margin = new Padding(3, 2, 3, 2);
panelRed.Name = "panelRed";
panelRed.Size = new Size(40, 40);
panelRed.Size = new Size(35, 30);
panelRed.TabIndex = 0;
panelRed.MouseDown += PanelColor_MouseDown;
//
// checkBoxPin
//
checkBoxPin.AutoSize = true;
checkBoxPin.Location = new Point(6, 192);
checkBoxPin.Location = new Point(5, 144);
checkBoxPin.Margin = new Padding(3, 2, 3, 2);
checkBoxPin.Name = "checkBoxPin";
checkBoxPin.Size = new Size(204, 24);
checkBoxPin.Size = new Size(164, 19);
checkBoxPin.TabIndex = 6;
checkBoxPin.Text = "Признак наличия штыря";
checkBoxPin.UseVisualStyleBackColor = true;
@ -195,9 +217,10 @@
// checkBoxTank
//
checkBoxTank.AutoSize = true;
checkBoxTank.Location = new Point(6, 162);
checkBoxTank.Location = new Point(5, 122);
checkBoxTank.Margin = new Padding(3, 2, 3, 2);
checkBoxTank.Name = "checkBoxTank";
checkBoxTank.Size = new Size(190, 24);
checkBoxTank.Size = new Size(151, 19);
checkBoxTank.TabIndex = 5;
checkBoxTank.Text = "Признак наличия бака";
checkBoxTank.UseVisualStyleBackColor = true;
@ -205,48 +228,51 @@
// checkBoxRadar
//
checkBoxRadar.AutoSize = true;
checkBoxRadar.Location = new Point(6, 132);
checkBoxRadar.Location = new Point(5, 99);
checkBoxRadar.Margin = new Padding(3, 2, 3, 2);
checkBoxRadar.Name = "checkBoxRadar";
checkBoxRadar.Size = new Size(208, 24);
checkBoxRadar.Size = new Size(164, 19);
checkBoxRadar.TabIndex = 4;
checkBoxRadar.Text = "Признак наличия радара";
checkBoxRadar.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(88, 85);
numericUpDownWeight.Location = new Point(77, 64);
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(102, 27);
numericUpDownWeight.Size = new Size(89, 23);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 1000, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(88, 42);
numericUpDownSpeed.Location = new Point(77, 32);
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(102, 27);
numericUpDownSpeed.Size = new Size(89, 23);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 1000, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(6, 87);
labelWeight.Location = new Point(5, 65);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(36, 20);
labelWeight.Size = new Size(29, 15);
labelWeight.TabIndex = 1;
labelWeight.Text = "Вес:";
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(6, 42);
labelSpeed.Location = new Point(5, 32);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(76, 20);
labelSpeed.Size = new Size(62, 15);
labelSpeed.TabIndex = 0;
labelSpeed.Text = "Скорость:";
//
@ -256,69 +282,80 @@
panelObject.Controls.Add(labelAdditionalColor);
panelObject.Controls.Add(labelBodyColor);
panelObject.Controls.Add(pictureBoxObject);
panelObject.Location = new Point(517, 12);
panelObject.Location = new Point(452, 9);
panelObject.Margin = new Padding(3, 2, 3, 2);
panelObject.Name = "panelObject";
panelObject.Size = new Size(260, 193);
panelObject.Size = new Size(228, 145);
panelObject.TabIndex = 12;
panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(134, 6);
labelAdditionalColor.Location = new Point(117, 4);
labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(107, 36);
labelAdditionalColor.Size = new Size(94, 28);
labelAdditionalColor.TabIndex = 13;
labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += labelColor_DragDrop;
labelAdditionalColor.DragEnter += labelColor_DragEnter;
//
// labelBodyColor
//
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Location = new Point(31, 6);
labelBodyColor.Location = new Point(27, 4);
labelBodyColor.Name = "labelBodyColor";
labelBodyColor.Size = new Size(97, 36);
labelBodyColor.Size = new Size(85, 28);
labelBodyColor.TabIndex = 12;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += labelColor_DragDrop;
labelBodyColor.DragEnter += labelColor_DragEnter;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(3, 45);
pictureBoxObject.Location = new Point(3, 34);
pictureBoxObject.Margin = new Padding(3, 2, 3, 2);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(254, 148);
pictureBoxObject.Size = new Size(222, 111);
pictureBoxObject.TabIndex = 7;
pictureBoxObject.TabStop = false;
//
// buttonOk
//
buttonOk.Location = new Point(551, 226);
buttonOk.Location = new Point(482, 170);
buttonOk.Margin = new Padding(3, 2, 3, 2);
buttonOk.Name = "buttonOk";
buttonOk.Size = new Size(94, 29);
buttonOk.Size = new Size(82, 22);
buttonOk.TabIndex = 13;
buttonOk.Text = "Добавить";
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += buttonOk_Click;
//
// button2
// buttonCancel
//
button2.Location = new Point(651, 226);
button2.Name = "button2";
button2.Size = new Size(94, 29);
button2.TabIndex = 14;
button2.Text = "Отмена";
button2.UseVisualStyleBackColor = true;
buttonCancel.Location = new Point(570, 170);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 14;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// FormAirplaneConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 278);
Controls.Add(button2);
ClientSize = new Size(700, 208);
Controls.Add(buttonCancel);
Controls.Add(buttonOk);
Controls.Add(panelObject);
Controls.Add(groupBoxParameters);
Margin = new Padding(3, 2, 3, 2);
Name = "FormAirplaneConfig";
Text = "FormAirplaneConfig";
groupBoxParameters.ResumeLayout(false);
@ -347,7 +384,7 @@
private Panel panelYellow;
private Panel panelBlack;
private Panel panelBlue;
private Panel panelGrey;
private Panel panelGray;
private Panel panelGreen;
private Panel panelWhite;
private Label labelModifiedObject;
@ -357,6 +394,6 @@
private Label labelBodyColor;
private PictureBox pictureBoxObject;
private Button buttonOk;
private Button button2;
private Button buttonCancel;
}
}

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AirplaneWithRadar.DrawningObjects;
using AirplaneWithRadar.Entities;
namespace AirplaneWithRadar
{
@ -20,13 +21,24 @@ namespace AirplaneWithRadar
/// <summary>
/// Событие
/// </summary>
private event AirplaneDelegate? EventAddAirplane;
private event Action<DrawningAirplane>? EventAddAirplane;
/// <summary>
/// Конструктор
/// </summary
public FormAirplaneConfig()
{
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;
// TODO buttonCancel.Click with lambda +
buttonCancel.Click += (s, e) => Close();
}
/// <summary>
/// Отрисовать самолет
@ -39,6 +51,22 @@ namespace AirplaneWithRadar
_airplane?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawningAirplane>? ev)
{
if (EventAddAirplane == null)
{
EventAddAirplane = ev;
}
else
{
EventAddAirplane += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
@ -88,16 +116,52 @@ namespace AirplaneWithRadar
}
DrawAirplane();
}
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
/// <summary>
/// Добавление машины
/// Добавление самолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonOk_Click(object sender, EventArgs e)
{
EventAddCar?.Invoke(_airplane);
EventAddAirplane?.Invoke(_airplane);
Close();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_airplane == null)
return;
switch (((Label)sender).Name)
{
case "labelBodyColor":
_airplane?.EntityAirplane?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAdditionalColor":
if (!(_airplane is DrawningAirplaneWithRadar))
return;
(_airplane.EntityAirplane as EntityAirplaneWithRadar)?.SetAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
break;
}
DrawAirplane();
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}