Добавлена форма FormPlaneConfig и реализована его логика

This commit is contained in:
Никита Потапов 2023-11-06 13:31:26 +04:00
parent 51a27f8e12
commit 0b208db4dd
6 changed files with 619 additions and 2 deletions

View File

@ -24,7 +24,7 @@ namespace ProjectStormtrooper
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
/// <summary>
/// Шаг перемещения
/// </summary>

View File

@ -12,7 +12,7 @@ namespace ProjectStormtrooper
/// </summary>
public class EntityStormtrooper : EntityPlane
{
public Color AdditionalColor { get; private set; }
public Color AdditionalColor { get; set; }
/// <summary>
/// Признак (опция) наличия ракет
/// </summary>

View File

@ -0,0 +1,356 @@
namespace ProjectStormtrooper
{
partial class FormPlaneConfig
{
/// <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()
{
groupBoxParams = new GroupBox();
groupBoxColors = new GroupBox();
panelColorPink = new Panel();
panelColorPurple = new Panel();
panelColorBlue = new Panel();
panelColorBrown = new Panel();
panelColorGreen = new Panel();
panelColorLightBlue = new Panel();
panelColorYellow = new Panel();
panelColorRed = new Panel();
labelStormtrooper = new Label();
labelPlane = new Label();
checkBoxRockets = new CheckBox();
checkBoxBombs = new CheckBox();
numericUpDownWeight = new NumericUpDown();
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();
groupBoxParams.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
groupBoxControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
SuspendLayout();
//
// groupBoxParams
//
groupBoxParams.Controls.Add(groupBoxColors);
groupBoxParams.Controls.Add(labelStormtrooper);
groupBoxParams.Controls.Add(labelPlane);
groupBoxParams.Controls.Add(checkBoxRockets);
groupBoxParams.Controls.Add(checkBoxBombs);
groupBoxParams.Controls.Add(numericUpDownWeight);
groupBoxParams.Controls.Add(numericUpDownSpeed);
groupBoxParams.Controls.Add(labelWeight);
groupBoxParams.Controls.Add(labelSpeed);
groupBoxParams.Location = new Point(2, 7);
groupBoxParams.Name = "groupBoxParams";
groupBoxParams.Size = new Size(497, 261);
groupBoxParams.TabIndex = 0;
groupBoxParams.TabStop = false;
groupBoxParams.Text = "Параметры";
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelColorPink);
groupBoxColors.Controls.Add(panelColorPurple);
groupBoxColors.Controls.Add(panelColorBlue);
groupBoxColors.Controls.Add(panelColorBrown);
groupBoxColors.Controls.Add(panelColorGreen);
groupBoxColors.Controls.Add(panelColorLightBlue);
groupBoxColors.Controls.Add(panelColorYellow);
groupBoxColors.Controls.Add(panelColorRed);
groupBoxColors.Location = new Point(176, 26);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(308, 156);
groupBoxColors.TabIndex = 8;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Цвета";
//
// panelColorPink
//
panelColorPink.BackColor = Color.FromArgb(255, 192, 192);
panelColorPink.Location = new Point(241, 89);
panelColorPink.Name = "panelColorPink";
panelColorPink.Size = new Size(50, 50);
panelColorPink.TabIndex = 1;
//
// panelColorPurple
//
panelColorPurple.BackColor = Color.Fuchsia;
panelColorPurple.Location = new Point(164, 89);
panelColorPurple.Name = "panelColorPurple";
panelColorPurple.Size = new Size(50, 50);
panelColorPurple.TabIndex = 1;
//
// panelColorBlue
//
panelColorBlue.BackColor = Color.Blue;
panelColorBlue.Location = new Point(87, 89);
panelColorBlue.Name = "panelColorBlue";
panelColorBlue.Size = new Size(50, 50);
panelColorBlue.TabIndex = 1;
//
// panelColorBrown
//
panelColorBrown.BackColor = Color.FromArgb(192, 64, 0);
panelColorBrown.Location = new Point(17, 89);
panelColorBrown.Name = "panelColorBrown";
panelColorBrown.Size = new Size(50, 50);
panelColorBrown.TabIndex = 3;
//
// panelColorGreen
//
panelColorGreen.BackColor = Color.Lime;
panelColorGreen.Location = new Point(241, 26);
panelColorGreen.Name = "panelColorGreen";
panelColorGreen.Size = new Size(50, 50);
panelColorGreen.TabIndex = 1;
//
// panelColorLightBlue
//
panelColorLightBlue.BackColor = Color.Cyan;
panelColorLightBlue.Location = new Point(164, 26);
panelColorLightBlue.Name = "panelColorLightBlue";
panelColorLightBlue.Size = new Size(50, 50);
panelColorLightBlue.TabIndex = 2;
//
// panelColorYellow
//
panelColorYellow.BackColor = Color.Yellow;
panelColorYellow.Location = new Point(87, 26);
panelColorYellow.Name = "panelColorYellow";
panelColorYellow.Size = new Size(50, 50);
panelColorYellow.TabIndex = 1;
//
// panelColorRed
//
panelColorRed.BackColor = Color.Red;
panelColorRed.Location = new Point(17, 26);
panelColorRed.Name = "panelColorRed";
panelColorRed.Size = new Size(50, 50);
panelColorRed.TabIndex = 0;
//
// labelStormtrooper
//
labelStormtrooper.BorderStyle = BorderStyle.FixedSingle;
labelStormtrooper.Location = new Point(340, 203);
labelStormtrooper.Name = "labelStormtrooper";
labelStormtrooper.Padding = new Padding(10);
labelStormtrooper.Size = new Size(127, 42);
labelStormtrooper.TabIndex = 7;
labelStormtrooper.Text = "Продвинутый";
labelStormtrooper.TextAlign = ContentAlignment.MiddleCenter;
labelStormtrooper.MouseDown += labelObject_MouseDown;
//
// labelPlane
//
labelPlane.BorderStyle = BorderStyle.FixedSingle;
labelPlane.Location = new Point(193, 203);
labelPlane.Name = "labelPlane";
labelPlane.Padding = new Padding(10);
labelPlane.Size = new Size(120, 42);
labelPlane.TabIndex = 6;
labelPlane.Text = "Простой";
labelPlane.TextAlign = ContentAlignment.MiddleCenter;
labelPlane.MouseDown += labelObject_MouseDown;
//
// checkBoxRockets
//
checkBoxRockets.AutoSize = true;
checkBoxRockets.Location = new Point(6, 145);
checkBoxRockets.Name = "checkBoxRockets";
checkBoxRockets.Size = new Size(79, 24);
checkBoxRockets.TabIndex = 5;
checkBoxRockets.Text = "Ракеты";
checkBoxRockets.UseVisualStyleBackColor = true;
//
// checkBoxBombs
//
checkBoxBombs.AutoSize = true;
checkBoxBombs.Location = new Point(6, 115);
checkBoxBombs.Name = "checkBoxBombs";
checkBoxBombs.Size = new Size(80, 24);
checkBoxBombs.TabIndex = 4;
checkBoxBombs.Text = "Бомбы";
checkBoxBombs.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(88, 73);
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(82, 27);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(88, 29);
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(82, 27);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(6, 75);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(36, 20);
labelWeight.TabIndex = 1;
labelWeight.Text = "Вес:";
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(6, 31);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(76, 20);
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.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// buttonApply
//
buttonApply.Location = new Point(12, 226);
buttonApply.Name = "buttonApply";
buttonApply.Size = new Size(94, 29);
buttonApply.TabIndex = 3;
buttonApply.Text = "Добавить";
buttonApply.UseVisualStyleBackColor = true;
buttonApply.Click += buttonApply_Click;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(6, 59);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(251, 161);
pictureBoxObject.TabIndex = 2;
pictureBoxObject.TabStop = false;
pictureBoxObject.DragDrop += pictureBoxObject_DragDrop;
pictureBoxObject.DragEnter += pictureBoxObject_DragEnter;
//
// labelAddColor
//
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
labelAddColor.Location = new Point(157, 16);
labelAddColor.Name = "labelAddColor";
labelAddColor.Size = new Size(100, 40);
labelAddColor.TabIndex = 1;
labelAddColor.Text = "Доп. цвет";
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
labelAddColor.DragDrop += labelAddColor_DragDrop;
labelAddColor.DragEnter += labelColor_DragEnter;
//
// labelColor
//
labelColor.BorderStyle = BorderStyle.FixedSingle;
labelColor.Location = new Point(6, 16);
labelColor.Name = "labelColor";
labelColor.Size = new Size(100, 40);
labelColor.TabIndex = 0;
labelColor.Text = "Цвет";
labelColor.TextAlign = ContentAlignment.MiddleCenter;
labelColor.DragDrop += labelColor_DragDrop;
labelColor.DragEnter += labelColor_DragEnter;
//
// FormPlaneConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(781, 275);
Controls.Add(groupBoxControl);
Controls.Add(groupBoxParams);
Name = "FormPlaneConfig";
Text = "Создание объекта";
groupBoxParams.ResumeLayout(false);
groupBoxParams.PerformLayout();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
groupBoxControl.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParams;
private GroupBox groupBoxColors;
private Label labelStormtrooper;
private Label labelPlane;
private CheckBox checkBoxRockets;
private CheckBox checkBoxBombs;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private Panel panelColorRed;
private Panel panelColorPink;
private Panel panelColorPurple;
private Panel panelColorBlue;
private Panel panelColorBrown;
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;
}
}

View File

@ -0,0 +1,127 @@
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 ProjectStormtrooper
{
public partial class FormPlaneConfig : Form
{
/// <summary>
/// Переменная-выбранный самолет
/// </summary>
DrawingPlane? _plane = null;
/// <summary>
/// Событие
/// </summary>
private event PlaneDelegate? EventAddPlane;
public FormPlaneConfig()
{
InitializeComponent();
panelColorRed.MouseDown += panelColor_MouseDown;
panelColorYellow.MouseDown += panelColor_MouseDown;
panelColorLightBlue.MouseDown += panelColor_MouseDown;
panelColorGreen.MouseDown += panelColor_MouseDown;
panelColorBrown.MouseDown += panelColor_MouseDown;
panelColorBlue.MouseDown += panelColor_MouseDown;
panelColorPurple.MouseDown += panelColor_MouseDown;
panelColorPink.MouseDown += panelColor_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(PlaneDelegate ev)
{
if (EventAddPlane == null)
{
EventAddPlane = ev;
}
else
{
EventAddPlane += ev;
}
}
/// <summary>
/// Отрисовать машину
/// </summary>
private void DrawPlane()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_plane?.SetPosition(5, 5);
_plane?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void buttonApply_Click(object sender, EventArgs e)
{
EventAddPlane?.Invoke(_plane);
Close();
}
private void pictureBoxObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void pictureBoxObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelPlane":
_plane = new DrawingPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height);
break;
case "labelStormtrooper":
_plane = new DrawingStormtrooper((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRockets.Checked, checkBoxBombs.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawPlane();
}
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);
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_plane == null)
return;
_plane.EntityPlane.BodyColor = (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());
DrawPlane();
}
}
}

View 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>

View File

@ -0,0 +1,14 @@
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);
}