Фиксы по лабе и требованиям

This commit is contained in:
Никита Потапов 2023-11-06 14:44:39 +04:00
parent 5a616231fd
commit cd74aa1932
7 changed files with 59 additions and 65 deletions

View File

@ -18,11 +18,11 @@ namespace ProjectStormtrooper
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth;
public int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight;
public int _pictureHeight;
/// <summary>
/// Левая координата начала прорисовки
/// </summary>

View File

@ -24,7 +24,7 @@ namespace ProjectStormtrooper
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; set; }
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения
/// </summary>
@ -41,5 +41,9 @@ namespace ProjectStormtrooper
Weight = weight;
BodyColor = bodyColor;
}
public void SetColor(Color color)
{
BodyColor = color;
}
}
}

View File

@ -12,7 +12,7 @@ namespace ProjectStormtrooper
/// </summary>
public class EntityStormtrooper : EntityPlane
{
public Color AdditionalColor { get; set; }
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия ракет
/// </summary>
@ -28,5 +28,9 @@ namespace ProjectStormtrooper
Rockets = rockets;
Bombs = bombs;
}
public void SetAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@ -96,11 +96,13 @@ namespace ProjectStormtrooper
private void buttonAddPlane_Click(object sender, EventArgs e)
{
var formPlaneConfig = new FormPlaneConfig();
formPlaneConfig.AddEvent(new PlaneDelegate(AddPlaneListener));
formPlaneConfig.AddEvent(AddPlaneListener);
formPlaneConfig.Show();
}
public void AddPlaneListener(DrawingPlane plane)
{
plane._pictureWidth = pictureBoxCollection.Width;
plane._pictureHeight = pictureBoxCollection.Height;
if (listBoxStorages.SelectedIndex == -1)
{
return;
@ -110,18 +112,14 @@ namespace ProjectStormtrooper
{
return;
}
FormStormtrooper form = new();
if (form.ShowDialog() == DialogResult.OK)
if (obj + plane > -1)
{
if (obj + plane > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>

View File

@ -46,18 +46,18 @@
numericUpDownSpeed = new NumericUpDown();
labelWeight = new Label();
labelSpeed = new Label();
groupBoxControl = new GroupBox();
buttonCancel = new Button();
buttonApply = new Button();
pictureBoxObject = new PictureBox();
labelAddColor = new Label();
labelColor = new Label();
panelControl = new Panel();
groupBoxParams.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
groupBoxControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
panelControl.SuspendLayout();
SuspendLayout();
//
// groupBoxParams
@ -241,22 +241,9 @@
labelSpeed.TabIndex = 0;
labelSpeed.Text = "Скорость:";
//
// groupBoxControl
//
groupBoxControl.Controls.Add(buttonCancel);
groupBoxControl.Controls.Add(buttonApply);
groupBoxControl.Controls.Add(pictureBoxObject);
groupBoxControl.Controls.Add(labelAddColor);
groupBoxControl.Controls.Add(labelColor);
groupBoxControl.Location = new Point(505, 7);
groupBoxControl.Name = "groupBoxControl";
groupBoxControl.Size = new Size(268, 261);
groupBoxControl.TabIndex = 1;
groupBoxControl.TabStop = false;
//
// buttonCancel
//
buttonCancel.Location = new Point(157, 226);
buttonCancel.Location = new Point(178, 220);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 4;
@ -265,7 +252,7 @@
//
// buttonApply
//
buttonApply.Location = new Point(12, 226);
buttonApply.Location = new Point(21, 220);
buttonApply.Name = "buttonApply";
buttonApply.Size = new Size(94, 29);
buttonApply.TabIndex = 3;
@ -275,18 +262,17 @@
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(6, 59);
pictureBoxObject.Location = new Point(21, 68);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(251, 161);
pictureBoxObject.Size = new Size(251, 146);
pictureBoxObject.TabIndex = 2;
pictureBoxObject.TabStop = false;
pictureBoxObject.DragDrop += pictureBoxObject_DragDrop;
pictureBoxObject.DragEnter += pictureBoxObject_DragEnter;
//
// labelAddColor
//
labelAddColor.AllowDrop = true;
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
labelAddColor.Location = new Point(157, 16);
labelAddColor.Location = new Point(172, 16);
labelAddColor.Name = "labelAddColor";
labelAddColor.Size = new Size(100, 40);
labelAddColor.TabIndex = 1;
@ -297,8 +283,9 @@
//
// labelColor
//
labelColor.AllowDrop = true;
labelColor.BorderStyle = BorderStyle.FixedSingle;
labelColor.Location = new Point(6, 16);
labelColor.Location = new Point(21, 16);
labelColor.Name = "labelColor";
labelColor.Size = new Size(100, 40);
labelColor.TabIndex = 0;
@ -307,12 +294,27 @@
labelColor.DragDrop += labelColor_DragDrop;
labelColor.DragEnter += labelColor_DragEnter;
//
// panelControl
//
panelControl.AllowDrop = true;
panelControl.Controls.Add(labelColor);
panelControl.Controls.Add(buttonCancel);
panelControl.Controls.Add(buttonApply);
panelControl.Controls.Add(pictureBoxObject);
panelControl.Controls.Add(labelAddColor);
panelControl.Location = new Point(505, 12);
panelControl.Name = "panelControl";
panelControl.Size = new Size(298, 256);
panelControl.TabIndex = 5;
panelControl.DragDrop += panelControlObject_DragDrop;
panelControl.DragEnter += panelControlObject_DragEnter;
//
// FormPlaneConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(781, 275);
Controls.Add(groupBoxControl);
ClientSize = new Size(809, 275);
Controls.Add(panelControl);
Controls.Add(groupBoxParams);
Name = "FormPlaneConfig";
Text = "Создание объекта";
@ -321,8 +323,8 @@
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
groupBoxControl.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
panelControl.ResumeLayout(false);
ResumeLayout(false);
}
@ -346,11 +348,11 @@
private Panel panelColorGreen;
private Panel panelColorLightBlue;
private Panel panelColorYellow;
private GroupBox groupBoxControl;
private Button buttonCancel;
private Button buttonApply;
private PictureBox pictureBoxObject;
private Label labelAddColor;
private Label labelColor;
private Panel panelControl;
}
}

View File

@ -19,11 +19,11 @@ namespace ProjectStormtrooper
/// <summary>
/// Событие
/// </summary>
private event PlaneDelegate? EventAddPlane;
private event Action<DrawingPlane>? EventAddPlane;
public FormPlaneConfig()
{
InitializeComponent();
panelColorRed.MouseDown += panelColor_MouseDown;
panelColorYellow.MouseDown += panelColor_MouseDown;
panelColorLightBlue.MouseDown += panelColor_MouseDown;
@ -39,7 +39,7 @@ namespace ProjectStormtrooper
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(PlaneDelegate ev)
public void AddEvent(Action<DrawingPlane> ev)
{
if (EventAddPlane == null)
{
@ -57,7 +57,7 @@ namespace ProjectStormtrooper
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_plane?.SetPosition(5, 5);
_plane?.SetPosition((int)((pictureBoxObject.Width - _plane?.GetWidth) / 2), (int)((pictureBoxObject.Height - _plane?.GetHeight) / 2));
_plane?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
@ -66,7 +66,7 @@ namespace ProjectStormtrooper
EventAddPlane?.Invoke(_plane);
Close();
}
private void pictureBoxObject_DragEnter(object sender, DragEventArgs e)
private void panelControlObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
@ -77,7 +77,7 @@ namespace ProjectStormtrooper
e.Effect = DragDropEffects.None;
}
}
private void pictureBoxObject_DragDrop(object sender, DragEventArgs e)
private void panelControlObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
@ -113,14 +113,14 @@ namespace ProjectStormtrooper
{
if (_plane == null)
return;
_plane.EntityPlane.BodyColor = (Color)e.Data.GetData(typeof(Color).ToString());
_plane.EntityPlane.SetColor((Color)e.Data.GetData(typeof(Color).ToString()));
DrawPlane();
}
private void labelAddColor_DragDrop(object sender, DragEventArgs e)
{
if (_plane == null || _plane is not DrawingStormtrooper)
return;
(_plane.EntityPlane as EntityStormtrooper).AdditionalColor = (Color)e.Data.GetData(typeof(Color).ToString());
(_plane.EntityPlane as EntityStormtrooper).SetAdditionalColor((Color)e.Data.GetData(typeof(Color).ToString()));
DrawPlane();
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper
{
/// <summary>
/// Делегат для передачи объекта-самолета
/// </summary>
/// <param name="plane"></param>
public delegate void PlaneDelegate(DrawingPlane plane);
}