From b2e5c3e9b5098d740751f319a62eb66c82d9a04d Mon Sep 17 00:00:00 2001 From: dyakonovr Date: Sat, 18 Nov 2023 16:18:44 +0400 Subject: [PATCH] All done --- ProjectTank/DrawningObjects/DrawningTank.cs | 5 +- .../DrawningObjects/DrawningTankBase.cs | 11 + ProjectTank/Entities/EntityTank.cs | 2 +- ProjectTank/Entities/EntityTankBase.cs | 2 +- ProjectTank/FormTankCollection.Designer.cs | 110 +++--- ProjectTank/FormTankCollection.cs | 32 +- ProjectTank/FormTankConfig.Designer.cs | 365 ++++++++++++++++++ ProjectTank/FormTankConfig.cs | 154 ++++++++ ProjectTank/FormTankConfig.resx | 123 ++++++ 9 files changed, 733 insertions(+), 71 deletions(-) create mode 100644 ProjectTank/FormTankConfig.Designer.cs create mode 100644 ProjectTank/FormTankConfig.cs create mode 100644 ProjectTank/FormTankConfig.resx diff --git a/ProjectTank/DrawningObjects/DrawningTank.cs b/ProjectTank/DrawningObjects/DrawningTank.cs index 63b8814..5ef4d5c 100644 --- a/ProjectTank/DrawningObjects/DrawningTank.cs +++ b/ProjectTank/DrawningObjects/DrawningTank.cs @@ -17,7 +17,6 @@ namespace ProjectTank.DrawningObjects EntityTankBase = new EntityTank(speed, weight, bodyColor, additionalColor, isTankTower, isAntiAirforceGun); } - public override void DrawTransport(Graphics g) { if (EntityTankBase is not EntityTank tank) return; @@ -59,5 +58,9 @@ namespace ProjectTank.DrawningObjects g.DrawPolygon(pen, rightRectanglePoints); } } + public void ChangeAdditionalColor(Color color) + { + ((EntityTank)EntityTankBase).AdditionalColor = color; + } } } \ No newline at end of file diff --git a/ProjectTank/DrawningObjects/DrawningTankBase.cs b/ProjectTank/DrawningObjects/DrawningTankBase.cs index e7408df..defe520 100644 --- a/ProjectTank/DrawningObjects/DrawningTankBase.cs +++ b/ProjectTank/DrawningObjects/DrawningTankBase.cs @@ -58,6 +58,11 @@ namespace ProjectTank.DrawningObjects startPosY = 1; } } + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + pictureHeight = pictureBoxHeight; + pictureWidth = pictureBoxWidth; + } public void MoveTransport(DirectionType direction) { if (!CanMove(direction) || EntityTankBase == null) return; @@ -115,5 +120,11 @@ namespace ProjectTank.DrawningObjects g.FillRectangle(brush, startPosX + 5, startPosY + 55 + 1, tankWidth - 10, 9); } + + public void ChangeColor(Color col) + { + if (EntityTankBase == null) return; + EntityTankBase.BodyColor = col; + } } } \ No newline at end of file diff --git a/ProjectTank/Entities/EntityTank.cs b/ProjectTank/Entities/EntityTank.cs index 642ee52..54d6fac 100644 --- a/ProjectTank/Entities/EntityTank.cs +++ b/ProjectTank/Entities/EntityTank.cs @@ -9,7 +9,7 @@ namespace ProjectTank.Entities { public class EntityTank : EntityTankBase { - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } public bool TankTower { get; private set; } public bool AntiAirforceGun { get; private set; } public EntityTank(int speed, double weight, Color bodyColor, Color diff --git a/ProjectTank/Entities/EntityTankBase.cs b/ProjectTank/Entities/EntityTankBase.cs index bee2392..a03954e 100644 --- a/ProjectTank/Entities/EntityTankBase.cs +++ b/ProjectTank/Entities/EntityTankBase.cs @@ -10,7 +10,7 @@ namespace ProjectTank.Entities { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public double Step => (double)Speed * 100 / Weight; public EntityTankBase(int speed, double weight, Color bodyColor) { diff --git a/ProjectTank/FormTankCollection.Designer.cs b/ProjectTank/FormTankCollection.Designer.cs index a34b5a1..59cec92 100644 --- a/ProjectTank/FormTankCollection.Designer.cs +++ b/ProjectTank/FormTankCollection.Designer.cs @@ -30,15 +30,15 @@ { pictureBoxCollection = new PictureBox(); label1 = new Label(); - button3 = new Button(); - button2 = new Button(); - button4 = new Button(); + refreshObjectsButton = new Button(); + deleteTankButton = new Button(); + addTankButton = new Button(); maskedTextBoxNumber = new TextBox(); label2 = new Label(); textBoxStorageName = new TextBox(); - button1 = new Button(); + addObjectButton = new Button(); listBoxStorages = new ListBox(); - button5 = new Button(); + deleteObjectButton = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); SuspendLayout(); // @@ -59,35 +59,35 @@ label1.TabIndex = 1; label1.Text = "Инструменты"; // - // button3 + // refreshObjectsButton // - button3.Location = new Point(775, 448); - button3.Name = "button3"; - button3.Size = new Size(139, 29); - button3.TabIndex = 4; - button3.Text = "Обн. коллекцию"; - button3.UseVisualStyleBackColor = true; - button3.Click += ButtonRefreshCollection_Click; + refreshObjectsButton.Location = new Point(775, 448); + refreshObjectsButton.Name = "refreshObjectsButton"; + refreshObjectsButton.Size = new Size(139, 29); + refreshObjectsButton.TabIndex = 4; + refreshObjectsButton.Text = "Обн. коллекцию"; + refreshObjectsButton.UseVisualStyleBackColor = true; + refreshObjectsButton.Click += ButtonRefreshCollection_Click; // - // button2 + // deleteTankButton // - button2.Location = new Point(775, 393); - button2.Name = "button2"; - button2.Size = new Size(139, 29); - button2.TabIndex = 5; - button2.Text = "Удалить танк"; - button2.UseVisualStyleBackColor = true; - button2.Click += ButtonRemoveTank_Click; + deleteTankButton.Location = new Point(775, 393); + deleteTankButton.Name = "deleteTankButton"; + deleteTankButton.Size = new Size(139, 29); + deleteTankButton.TabIndex = 5; + deleteTankButton.Text = "Удалить танк"; + deleteTankButton.UseVisualStyleBackColor = true; + deleteTankButton.Click += ButtonRemoveTank_Click; // - // button4 + // addTankButton // - button4.Location = new Point(775, 306); - button4.Name = "button4"; - button4.Size = new Size(139, 29); - button4.TabIndex = 6; - button4.Text = "Добавить танк"; - button4.UseVisualStyleBackColor = true; - button4.Click += ButtonAddTank_Click; + addTankButton.Location = new Point(775, 306); + addTankButton.Name = "addTankButton"; + addTankButton.Size = new Size(139, 29); + addTankButton.TabIndex = 6; + addTankButton.Text = "Добавить танк"; + addTankButton.UseVisualStyleBackColor = true; + addTankButton.Click += ButtonAddTank_Click; // // maskedTextBoxNumber // @@ -112,15 +112,15 @@ textBoxStorageName.Size = new Size(139, 27); textBoxStorageName.TabIndex = 9; // - // button1 + // addObjectButton // - button1.Location = new Point(775, 107); - button1.Name = "button1"; - button1.Size = new Size(139, 29); - button1.TabIndex = 10; - button1.Text = "Добавить набор"; - button1.UseVisualStyleBackColor = true; - button1.Click += ButtonAddObject_Click; + addObjectButton.Location = new Point(775, 107); + addObjectButton.Name = "addObjectButton"; + addObjectButton.Size = new Size(139, 29); + addObjectButton.TabIndex = 10; + addObjectButton.Text = "Добавить набор"; + addObjectButton.UseVisualStyleBackColor = true; + addObjectButton.Click += ButtonAddObject_Click; // // listBoxStorages // @@ -132,30 +132,30 @@ listBoxStorages.TabIndex = 11; listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged; // - // button5 + // deleteObjectButton // - button5.Location = new Point(775, 232); - button5.Name = "button5"; - button5.Size = new Size(139, 29); - button5.TabIndex = 12; - button5.Text = "Удалить набор"; - button5.UseVisualStyleBackColor = true; - button5.Click += ButtonDelObject_Click; + deleteObjectButton.Location = new Point(775, 232); + deleteObjectButton.Name = "deleteObjectButton"; + deleteObjectButton.Size = new Size(139, 29); + deleteObjectButton.TabIndex = 12; + deleteObjectButton.Text = "Удалить набор"; + deleteObjectButton.UseVisualStyleBackColor = true; + deleteObjectButton.Click += ButtonDelObject_Click; // // FormTankCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(926, 486); - Controls.Add(button5); + Controls.Add(deleteObjectButton); Controls.Add(listBoxStorages); - Controls.Add(button1); + Controls.Add(addObjectButton); Controls.Add(textBoxStorageName); Controls.Add(label2); Controls.Add(maskedTextBoxNumber); - Controls.Add(button4); - Controls.Add(button2); - Controls.Add(button3); + Controls.Add(addTankButton); + Controls.Add(deleteTankButton); + Controls.Add(refreshObjectsButton); Controls.Add(label1); Controls.Add(pictureBoxCollection); Name = "FormTankCollection"; @@ -169,14 +169,14 @@ private PictureBox pictureBoxCollection; private Label label1; - private Button button3; - private Button button2; - private Button button4; + private Button refreshObjectsButton; + private Button deleteTankButton; + private Button addTankButton; private TextBox maskedTextBoxNumber; private Label label2; private TextBox textBoxStorageName; - private Button button1; + private Button addObjectButton; private ListBox listBoxStorages; - private Button button5; + private Button deleteObjectButton; } } \ No newline at end of file diff --git a/ProjectTank/FormTankCollection.cs b/ProjectTank/FormTankCollection.cs index 68f2196..3295ad3 100644 --- a/ProjectTank/FormTankCollection.cs +++ b/ProjectTank/FormTankCollection.cs @@ -21,12 +21,10 @@ namespace ProjectTank { int index = listBoxStorages.SelectedIndex; listBoxStorages.Items.Clear(); - for (int i = 0; i < _storage.Keys.Count; i++) { listBoxStorages.Items.Add(_storage.Keys[i]); } - if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count)) { @@ -41,10 +39,10 @@ namespace ProjectTank private void ButtonAddObject_Click(object sender, EventArgs e) { - string objName = textBoxStorageName.Text; - if (string.IsNullOrEmpty(objName)) + if (string.IsNullOrEmpty(textBoxStorageName.Text)) { - MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Не все данные заполнены", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _storage.AddSet(textBoxStorageName.Text); @@ -81,20 +79,26 @@ namespace ProjectTank private void ButtonAddTank_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) return; - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) return; - FormTank form = new(); - if (form.ShowDialog() == DialogResult.OK) + FormTankConfig form = new(); + form.Show(); + Action? tankDelegate = new((t) => { - if (obj + form.SelectedTank) + if (obj + t) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowTanks(); + t.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); } - else MessageBox.Show("Не удалось добавить объект"); - } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + }); + + form.AddEvent(tankDelegate); } /// /// Удаление объекта из набора @@ -103,8 +107,10 @@ namespace ProjectTank /// private void ButtonRemoveTank_Click(object sender, EventArgs e) { - if (listBoxStorages.SelectedIndex == -1) return; - + if (listBoxStorages.SelectedIndex == -1) + { + return; + } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) return; diff --git a/ProjectTank/FormTankConfig.Designer.cs b/ProjectTank/FormTankConfig.Designer.cs new file mode 100644 index 0000000..3265673 --- /dev/null +++ b/ProjectTank/FormTankConfig.Designer.cs @@ -0,0 +1,365 @@ +namespace ProjectTank +{ + partial class FormTankConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + contextMenuStrip1 = new ContextMenuStrip(components); + mainGroupBox = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + colorsGroupBox = new GroupBox(); + bluePanel = new Panel(); + blackPanel = new Panel(); + orangePanel = new Panel(); + greenPanel = new Panel(); + redPanel = new Panel(); + purplePanel = new Panel(); + cyanPanel = new Panel(); + yellowPanel = new Panel(); + checkBoxAntiAirforceGun = new CheckBox(); + checkBoxTankTower = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + weightLabel = new Label(); + speedLabel = new Label(); + mainColorLabel = new Label(); + additionalColorLabel = new Label(); + addButton = new Button(); + cancelButton = new Button(); + pictureBoxPanel = new Panel(); + pictureBoxObject = new PictureBox(); + mainGroupBox.SuspendLayout(); + colorsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + pictureBoxPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // contextMenuStrip1 + // + contextMenuStrip1.ImageScalingSize = new Size(20, 20); + contextMenuStrip1.Name = "contextMenuStrip1"; + contextMenuStrip1.Size = new Size(61, 4); + // + // mainGroupBox + // + mainGroupBox.Controls.Add(labelModifiedObject); + mainGroupBox.Controls.Add(labelSimpleObject); + mainGroupBox.Controls.Add(colorsGroupBox); + mainGroupBox.Controls.Add(checkBoxAntiAirforceGun); + mainGroupBox.Controls.Add(checkBoxTankTower); + mainGroupBox.Controls.Add(numericUpDownWeight); + mainGroupBox.Controls.Add(numericUpDownSpeed); + mainGroupBox.Controls.Add(weightLabel); + mainGroupBox.Controls.Add(speedLabel); + mainGroupBox.Location = new Point(12, 12); + mainGroupBox.Name = "mainGroupBox"; + mainGroupBox.Size = new Size(610, 239); + mainGroupBox.TabIndex = 1; + mainGroupBox.TabStop = false; + mainGroupBox.Text = "Параметры"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(465, 179); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(127, 47); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(322, 179); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(127, 47); + labelSimpleObject.TabIndex = 5; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // colorsGroupBox + // + colorsGroupBox.Controls.Add(bluePanel); + colorsGroupBox.Controls.Add(blackPanel); + colorsGroupBox.Controls.Add(orangePanel); + colorsGroupBox.Controls.Add(greenPanel); + colorsGroupBox.Controls.Add(redPanel); + colorsGroupBox.Controls.Add(purplePanel); + colorsGroupBox.Controls.Add(cyanPanel); + colorsGroupBox.Controls.Add(yellowPanel); + colorsGroupBox.Location = new Point(322, 26); + colorsGroupBox.Name = "colorsGroupBox"; + colorsGroupBox.Size = new Size(270, 145); + colorsGroupBox.TabIndex = 2; + colorsGroupBox.TabStop = false; + colorsGroupBox.Text = "Цвета"; + // + // bluePanel + // + bluePanel.BackColor = Color.Blue; + bluePanel.Location = new Point(211, 84); + bluePanel.Name = "bluePanel"; + bluePanel.Size = new Size(49, 48); + bluePanel.TabIndex = 4; + // + // blackPanel + // + blackPanel.BackColor = Color.Black; + blackPanel.Location = new Point(143, 84); + blackPanel.Name = "blackPanel"; + blackPanel.Size = new Size(49, 48); + blackPanel.TabIndex = 3; + // + // orangePanel + // + orangePanel.BackColor = Color.FromArgb(255, 128, 0); + orangePanel.Location = new Point(78, 84); + orangePanel.Name = "orangePanel"; + orangePanel.Size = new Size(49, 48); + orangePanel.TabIndex = 2; + // + // greenPanel + // + greenPanel.BackColor = Color.Lime; + greenPanel.Location = new Point(12, 84); + greenPanel.Name = "greenPanel"; + greenPanel.Size = new Size(49, 48); + greenPanel.TabIndex = 1; + // + // redPanel + // + redPanel.BackColor = Color.Red; + redPanel.Location = new Point(211, 26); + redPanel.Name = "redPanel"; + redPanel.Size = new Size(49, 48); + redPanel.TabIndex = 3; + // + // purplePanel + // + purplePanel.BackColor = Color.Fuchsia; + purplePanel.Location = new Point(143, 26); + purplePanel.Name = "purplePanel"; + purplePanel.Size = new Size(49, 48); + purplePanel.TabIndex = 2; + // + // cyanPanel + // + cyanPanel.BackColor = Color.Cyan; + cyanPanel.Location = new Point(78, 26); + cyanPanel.Name = "cyanPanel"; + cyanPanel.Size = new Size(49, 48); + cyanPanel.TabIndex = 1; + // + // yellowPanel + // + yellowPanel.BackColor = Color.FromArgb(255, 255, 128); + yellowPanel.Location = new Point(12, 26); + yellowPanel.Name = "yellowPanel"; + yellowPanel.Size = new Size(49, 48); + yellowPanel.TabIndex = 0; + // + // checkBoxAntiAirforceGun + // + checkBoxAntiAirforceGun.AutoSize = true; + checkBoxAntiAirforceGun.Location = new Point(17, 175); + checkBoxAntiAirforceGun.Name = "checkBoxAntiAirforceGun"; + checkBoxAntiAirforceGun.Size = new Size(287, 24); + checkBoxAntiAirforceGun.TabIndex = 7; + checkBoxAntiAirforceGun.Text = "Признак наличия зенитного оружия"; + checkBoxAntiAirforceGun.UseVisualStyleBackColor = true; + // + // checkBoxTankTower + // + checkBoxTankTower.AutoSize = true; + checkBoxTankTower.Location = new Point(17, 134); + checkBoxTankTower.Name = "checkBoxTankTower"; + checkBoxTankTower.Size = new Size(253, 24); + checkBoxTankTower.TabIndex = 6; + checkBoxTankTower.Text = "Признак наличия дула и башни"; + checkBoxTankTower.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(99, 80); + numericUpDownWeight.Maximum = new decimal(new int[] { 3000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(150, 27); + numericUpDownWeight.TabIndex = 5; + numericUpDownWeight.Value = new decimal(new int[] { 1000, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(99, 40); + numericUpDownSpeed.Maximum = new decimal(new int[] { 300, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(150, 27); + numericUpDownSpeed.TabIndex = 4; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // weightLabel + // + weightLabel.AutoSize = true; + weightLabel.Location = new Point(17, 82); + weightLabel.Name = "weightLabel"; + weightLabel.Size = new Size(36, 20); + weightLabel.TabIndex = 3; + weightLabel.Text = "Вес:"; + // + // speedLabel + // + speedLabel.AutoSize = true; + speedLabel.Location = new Point(17, 42); + speedLabel.Name = "speedLabel"; + speedLabel.Size = new Size(76, 20); + speedLabel.TabIndex = 2; + speedLabel.Text = "Скорость:"; + // + // mainColorLabel + // + mainColorLabel.AllowDrop = true; + mainColorLabel.BorderStyle = BorderStyle.FixedSingle; + mainColorLabel.Location = new Point(13, 9); + mainColorLabel.Name = "mainColorLabel"; + mainColorLabel.Size = new Size(92, 38); + mainColorLabel.TabIndex = 9; + mainColorLabel.Text = "Цвет"; + mainColorLabel.TextAlign = ContentAlignment.MiddleCenter; + mainColorLabel.DragDrop += ColorLabel_DragDrop; + mainColorLabel.DragEnter += ColorLabel_DragEnter; + // + // additionalColorLabel + // + additionalColorLabel.AllowDrop = true; + additionalColorLabel.BorderStyle = BorderStyle.FixedSingle; + additionalColorLabel.Location = new Point(126, 9); + additionalColorLabel.Name = "additionalColorLabel"; + additionalColorLabel.Size = new Size(92, 38); + additionalColorLabel.TabIndex = 10; + additionalColorLabel.Text = "Доп. Цвет"; + additionalColorLabel.TextAlign = ContentAlignment.MiddleCenter; + additionalColorLabel.DragDrop += ColorLabel_DragDrop; + additionalColorLabel.DragEnter += ColorLabel_DragEnter; + // + // addButton + // + addButton.Location = new Point(632, 222); + addButton.Name = "addButton"; + addButton.Size = new Size(94, 29); + addButton.TabIndex = 11; + addButton.Text = "Добавить"; + addButton.UseVisualStyleBackColor = true; + addButton.Click += ButtonOk_Click; + // + // cancelButton + // + cancelButton.Location = new Point(769, 222); + cancelButton.Name = "cancelButton"; + cancelButton.Size = new Size(94, 29); + cancelButton.TabIndex = 12; + cancelButton.Text = "Отмена"; + cancelButton.UseVisualStyleBackColor = true; + // + // pictureBoxPanel + // + pictureBoxPanel.AllowDrop = true; + pictureBoxPanel.Controls.Add(pictureBoxObject); + pictureBoxPanel.Controls.Add(mainColorLabel); + pictureBoxPanel.Controls.Add(additionalColorLabel); + pictureBoxPanel.Location = new Point(628, 22); + pictureBoxPanel.Name = "pictureBoxPanel"; + pictureBoxPanel.Size = new Size(235, 189); + pictureBoxPanel.TabIndex = 9; + pictureBoxPanel.DragDrop += PanelObject_DragDrop; + pictureBoxPanel.DragEnter += PanelObject_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(13, 60); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(205, 117); + pictureBoxObject.TabIndex = 13; + pictureBoxObject.TabStop = false; + // + // FormTankConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(875, 267); + Controls.Add(pictureBoxPanel); + Controls.Add(cancelButton); + Controls.Add(addButton); + Controls.Add(mainGroupBox); + Name = "FormTankConfig"; + Text = "Настройка конфигурации танка"; + mainGroupBox.ResumeLayout(false); + mainGroupBox.PerformLayout(); + colorsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + pictureBoxPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private ContextMenuStrip contextMenuStrip1; + private GroupBox mainGroupBox; + private CheckBox checkBoxAntiAirforceGun; + private CheckBox checkBoxTankTower; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label weightLabel; + private Label speedLabel; + private GroupBox colorsGroupBox; + private Panel redPanel; + private Panel purplePanel; + private Panel cyanPanel; + private Panel yellowPanel; + private Panel greenPanel; + private Panel bluePanel; + private Panel blackPanel; + private Panel orangePanel; + private Label labelSimpleObject; + private Label labelModifiedObject; + private Label mainColorLabel; + private Label additionalColorLabel; + private Button addButton; + private Button cancelButton; + private Panel pictureBoxPanel; + private PictureBox pictureBoxObject; + } +} \ No newline at end of file diff --git a/ProjectTank/FormTankConfig.cs b/ProjectTank/FormTankConfig.cs new file mode 100644 index 0000000..d7daf80 --- /dev/null +++ b/ProjectTank/FormTankConfig.cs @@ -0,0 +1,154 @@ +using ProjectTank.DrawningObjects; +using System.Windows.Forms; + +namespace ProjectTank +{ + /// + /// Форма создания объекта + /// + public partial class FormTankConfig : Form + { + /// + /// Переменная-выбранный танк + /// + DrawningTankBase? _tank = null; + /// + /// Событие + /// + private event Action? EventAddTank; + /// + /// Конструктор + /// + public FormTankConfig() + { + InitializeComponent(); + yellowPanel.MouseDown += PanelColor_MouseDown; + cyanPanel.MouseDown += PanelColor_MouseDown; + purplePanel.MouseDown += PanelColor_MouseDown; + redPanel.MouseDown += PanelColor_MouseDown; + greenPanel.MouseDown += PanelColor_MouseDown; + orangePanel.MouseDown += PanelColor_MouseDown; + blackPanel.MouseDown += PanelColor_MouseDown; + bluePanel.MouseDown += PanelColor_MouseDown; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + cancelButton.Click += (s, e) => Close(); + } + /// + /// Отрисовать танк + /// + private void DrawTank() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _tank?.SetPosition(5, 5); + _tank?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddTank == null) EventAddTank = ev; + else EventAddTank += ev; + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_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) ?? false) + { + 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": + _tank = new DrawningTankBase((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _tank = new DrawningTank((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTankTower.Checked, + checkBoxAntiAirforceGun.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + + mainColorLabel.BackColor = Color.Empty; + additionalColorLabel.BackColor = Color.Empty; + DrawTank(); + } + /// + /// Добавление танка + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddTank?.Invoke(_tank); + Close(); + } + private void ColorLabel_DragDrop(object sender, DragEventArgs e) + { + string senderName = ((Label)sender).Name; + if (_tank == null || e.Data.GetDataPresent(typeof(Color)) == false) + return; + + Color droppedColor = (Color)e.Data.GetData(typeof(Color)); + + if (senderName == "mainColorLabel") + { + mainColorLabel.BackColor = droppedColor; + ((DrawningTankBase)_tank).ChangeColor(mainColorLabel.BackColor); + } + else if (senderName == "additionalColorLabel" && _tank is DrawningTank) + { + additionalColorLabel.BackColor = droppedColor; + ((DrawningTank)_tank).ChangeAdditionalColor(additionalColorLabel.BackColor); + } + + DrawTank(); + } + private void ColorLabel_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } +} diff --git a/ProjectTank/FormTankConfig.resx b/ProjectTank/FormTankConfig.resx new file mode 100644 index 0000000..82079dd --- /dev/null +++ b/ProjectTank/FormTankConfig.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file