From ef62f8b0164b6962894e48afad241f61f6e97455 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 14 Dec 2023 21:48:23 +0400 Subject: [PATCH] lab 5 is done --- ...ArmoredTransportCollectionForm.Designer.cs | 2 +- .../ArmoredTransportCollectionForm.cs | 27 +- .../ArmoredTransportConfigForm.Designer.cs | 399 ++++++++++++++++++ .../ProjectTank/ArmoredTransportConfigForm.cs | 183 ++++++++ .../ArmoredTransportConfigForm.resx | 60 +++ .../ArmoredTransportsGenericCollection.cs | 1 + .../ArmoredTransportsGenericStorage.cs | 10 +- .../ProjectTank/DrawningArmoredTransport.cs | 8 + ProjectTank/ProjectTank/DrawningTank.cs | 4 + .../ProjectTank/EntityArmoredTransport.cs | 2 +- ProjectTank/ProjectTank/EntityTank.cs | 2 +- 11 files changed, 676 insertions(+), 22 deletions(-) create mode 100644 ProjectTank/ProjectTank/ArmoredTransportConfigForm.Designer.cs create mode 100644 ProjectTank/ProjectTank/ArmoredTransportConfigForm.cs create mode 100644 ProjectTank/ProjectTank/ArmoredTransportConfigForm.resx diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs index 70b6c68..66dae54 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs @@ -184,7 +184,7 @@ this.Controls.Add(this.ArmoredTransportCollectionFormToolsGroup); this.Controls.Add(this.pictureBoxCollection); this.Name = "ArmoredTransportCollectionForm"; - this.Text = "ArmoredTransportCollectionForm"; + this.Text = "Коллекция бронированного транспорта"; this.ArmoredTransportCollectionFormToolsGroup.ResumeLayout(false); this.ArmoredTransportCollectionFormToolsGroup.PerformLayout(); this.groupBox1.ResumeLayout(false); diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs index 9b54726..8014e8f 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs @@ -65,10 +65,9 @@ namespace ProjectTank /// /// /// - private void ListBoxObjects_SelectedIndexChanged(object sender,EventArgs e) + private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) { - pictureBoxCollection.Image = - _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowArmoredTransports(); + pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowArmoredTransports(); } /// /// Удаление набора @@ -81,7 +80,8 @@ namespace ProjectTank { return; } - if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes){ + if (MessageBox.Show($"Удалить объект: {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { _storage.DelSet(listBoxStorages.SelectedItem.ToString()??string.Empty); ReloadObjects(); if (listBoxStorages.SelectedIndex == -1) @@ -112,10 +112,12 @@ namespace ProjectTank { return; } - TankForm form = new(); - if (form.ShowDialog() == DialogResult.OK) + ArmoredTransportConfigForm form = new(pictureBoxCollection.Width, pictureBoxCollection.Height); + form.Show(); + Action? armoredTransportDelegate = new((m) => { - if (obj + form.SelectedArmoredTransport) + bool q = (obj + m); + if (q) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowArmoredTransports(); @@ -124,7 +126,8 @@ namespace ProjectTank { MessageBox.Show("Не удалось добавить объект"); } - } + }); + form.AddEvent(armoredTransportDelegate); } /// /// Удаление объекта из набора @@ -137,13 +140,12 @@ namespace ProjectTank { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString()??string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, - MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } @@ -163,7 +165,8 @@ namespace ProjectTank /// /// /// - private void ButtonRefreshCollection_Click(object sender, EventArgs e) + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) { if (listBoxStorages.SelectedIndex == -1) { diff --git a/ProjectTank/ProjectTank/ArmoredTransportConfigForm.Designer.cs b/ProjectTank/ProjectTank/ArmoredTransportConfigForm.Designer.cs new file mode 100644 index 0000000..dd57482 --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportConfigForm.Designer.cs @@ -0,0 +1,399 @@ +namespace ProjectTank +{ + partial class ArmoredTransportConfigForm + { + /// + /// 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() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxMachineGun = new System.Windows.Forms.CheckBox(); + this.checkBoxGun = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.panel9 = new System.Windows.Forms.Panel(); + this.addColorLabel = new System.Windows.Forms.Label(); + this.colorLabel = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.panel9.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.labelModifiedObject); + this.groupBox1.Controls.Add(this.labelSimpleObject); + this.groupBox1.Controls.Add(this.groupBox2); + this.groupBox1.Controls.Add(this.checkBoxMachineGun); + this.groupBox1.Controls.Add(this.checkBoxGun); + this.groupBox1.Controls.Add(this.numericUpDownWeight); + this.groupBox1.Controls.Add(this.numericUpDownSpeed); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(23, 23); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(888, 523); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(634, 428); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(230, 70); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(348, 428); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(230, 70); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragDrop); + this.labelSimpleObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragEnter); + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.panelYellow); + this.groupBox2.Controls.Add(this.panelPurple); + this.groupBox2.Controls.Add(this.panelBlue); + this.groupBox2.Controls.Add(this.panelBlack); + this.groupBox2.Controls.Add(this.panelGreen); + this.groupBox2.Controls.Add(this.panelGray); + this.groupBox2.Controls.Add(this.panelWhite); + this.groupBox2.Controls.Add(this.panelRed); + this.groupBox2.Location = new System.Drawing.Point(348, 72); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(516, 298); + this.groupBox2.TabIndex = 6; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Цвета"; + // + // panelYellow + // + this.panelYellow.AllowDrop = true; + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(381, 38); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(100, 100); + this.panelYellow.TabIndex = 4; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelPurple + // + this.panelPurple.AllowDrop = true; + this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64))))); + this.panelPurple.Location = new System.Drawing.Point(381, 170); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(100, 100); + this.panelPurple.TabIndex = 4; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.AllowDrop = true; + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(259, 38); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(100, 100); + this.panelBlue.TabIndex = 4; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.AllowDrop = true; + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(259, 170); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(100, 100); + this.panelBlack.TabIndex = 4; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.AllowDrop = true; + this.panelGreen.BackColor = System.Drawing.Color.Lime; + this.panelGreen.Location = new System.Drawing.Point(138, 38); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(100, 100); + this.panelGreen.TabIndex = 2; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.AllowDrop = true; + this.panelGray.BackColor = System.Drawing.Color.Silver; + this.panelGray.Location = new System.Drawing.Point(138, 170); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(100, 100); + this.panelGray.TabIndex = 3; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.AllowDrop = true; + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(20, 170); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(100, 100); + this.panelWhite.TabIndex = 1; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.AllowDrop = true; + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(20, 38); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(100, 100); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxMachineGun + // + this.checkBoxMachineGun.AutoSize = true; + this.checkBoxMachineGun.Location = new System.Drawing.Point(20, 247); + this.checkBoxMachineGun.Name = "checkBoxMachineGun"; + this.checkBoxMachineGun.Size = new System.Drawing.Size(141, 36); + this.checkBoxMachineGun.TabIndex = 5; + this.checkBoxMachineGun.Text = "Пулемет"; + this.checkBoxMachineGun.UseVisualStyleBackColor = true; + // + // checkBoxGun + // + this.checkBoxGun.AutoSize = true; + this.checkBoxGun.Location = new System.Drawing.Point(20, 197); + this.checkBoxGun.Name = "checkBoxGun"; + this.checkBoxGun.Size = new System.Drawing.Size(118, 36); + this.checkBoxGun.TabIndex = 4; + this.checkBoxGun.Text = "Пушка"; + this.checkBoxGun.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(172, 118); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(143, 39); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(172, 65); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(143, 39); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(20, 125); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(57, 32); + this.label2.TabIndex = 1; + this.label2.Text = "Вес:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(17, 72); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(121, 32); + this.label1.TabIndex = 0; + this.label1.Text = "Скорость:"; + // + // pictureBox + // + this.pictureBox.Location = new System.Drawing.Point(16, 98); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(517, 289); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // panel9 + // + this.panel9.AllowDrop = true; + this.panel9.Controls.Add(this.addColorLabel); + this.panel9.Controls.Add(this.colorLabel); + this.panel9.Controls.Add(this.pictureBox); + this.panel9.Location = new System.Drawing.Point(929, 42); + this.panel9.Name = "panel9"; + this.panel9.Size = new System.Drawing.Size(549, 409); + this.panel9.TabIndex = 2; + this.panel9.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panel9.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // addColorLabel + // + this.addColorLabel.AllowDrop = true; + this.addColorLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.addColorLabel.Location = new System.Drawing.Point(303, 13); + this.addColorLabel.Name = "addColorLabel"; + this.addColorLabel.Size = new System.Drawing.Size(230, 70); + this.addColorLabel.TabIndex = 10; + this.addColorLabel.Text = "Доп. цвет"; + this.addColorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.addColorLabel.DragDrop += new System.Windows.Forms.DragEventHandler(this.addColorLabel_DragDrop); + this.addColorLabel.DragEnter += new System.Windows.Forms.DragEventHandler(this.addColorLabel_DragEnter); + // + // colorLabel + // + this.colorLabel.AllowDrop = true; + this.colorLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.colorLabel.Location = new System.Drawing.Point(16, 13); + this.colorLabel.Name = "colorLabel"; + this.colorLabel.Size = new System.Drawing.Size(230, 70); + this.colorLabel.TabIndex = 9; + this.colorLabel.Text = "Цвет"; + this.colorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.colorLabel.DragDrop += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragDrop); + this.colorLabel.DragEnter += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragEnter); + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(945, 474); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(200, 60); + this.buttonOk.TabIndex = 3; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(1262, 474); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(200, 60); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // ArmoredTransportConfigForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1497, 577); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panel9); + this.Controls.Add(this.groupBox1); + this.Name = "ArmoredTransportConfigForm"; + this.Text = "Создание объекта"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.panel9.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private CheckBox checkBoxMachineGun; + private CheckBox checkBoxGun; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + private Label label1; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBox2; + private Panel panelYellow; + private Panel panelPurple; + private Panel panelBlue; + private Panel panelBlack; + private Panel panelGreen; + private Panel panelGray; + private Panel panelWhite; + private Panel panelRed; + private PictureBox pictureBox; + private Panel panel9; + private Label addColorLabel; + private Label colorLabel; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ArmoredTransportConfigForm.cs b/ProjectTank/ProjectTank/ArmoredTransportConfigForm.cs new file mode 100644 index 0000000..ee5717e --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportConfigForm.cs @@ -0,0 +1,183 @@ +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; +using System; +using System.Collections.Generic; +using ProjectTank.DrawningObjects; +using ProjectTank.Entities; + +namespace ProjectTank +{ + /// + /// Форма создания объекта + /// + public partial class ArmoredTransportConfigForm : Form + { + private readonly int PictureWidth; + private readonly int PictureHeight; + /// + /// Переменная-выбранная машина + /// + DrawningArmoredTransport? _armoredTransport = null; + /// + /// Событие + /// + Action? EventAddArmoredTransport; + /// + /// Конструктор + /// + public ArmoredTransportConfigForm(int width, int height) + { + 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; + buttonCancel.Click += (s, e) => Close(); + PictureWidth = width; + PictureHeight = height; + } + /// + /// Отрисовать машину + /// + private void DrawArmoredTransport() + { + Bitmap bmp = new(pictureBox.Width, pictureBox.Height); + Graphics gr = Graphics.FromImage(bmp); + _armoredTransport?.SetPosition(5, 5); + _armoredTransport?.DrawTransport(gr); + pictureBox.Image = bmp; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action? ev) + { + if (EventAddArmoredTransport == null) + { + EventAddArmoredTransport = ev; + } + else + { + EventAddArmoredTransport += ev; + } + } + /// + /// Передаем информацию при нажатии на 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": + _armoredTransport = new DrawningArmoredTransport((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, PictureWidth, PictureHeight); + break; + case "labelModifiedObject": + _armoredTransport = new DrawningTank((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxGun.Checked, checkBoxMachineGun.Checked, PictureWidth, PictureHeight); + break; + } + DrawArmoredTransport(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + private void allowPanel_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + + } + /// + /// Добавление машины + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddArmoredTransport?.Invoke(_armoredTransport); + Close(); + } + private void colorLabel_DragDrop(object sender, DragEventArgs e) + { + if (_armoredTransport == null) + return; + _armoredTransport.ChangeColor((Color)e.Data.GetData(typeof(Color))); + DrawArmoredTransport(); + } + private void colorLabel_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void addColorLabel_DragDrop(object sender, DragEventArgs e) + { + if ((_armoredTransport == null) || (_armoredTransport is DrawningTank == false)) + return; + ((DrawningTank)_armoredTransport).ChangeAddColor((Color)e.Data.GetData(typeof(Color))); + DrawArmoredTransport(); + } + private void addColorLabel_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ArmoredTransportConfigForm.resx b/ProjectTank/ProjectTank/ArmoredTransportConfigForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportConfigForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs index dbf2709..a43677d 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs @@ -119,6 +119,7 @@ namespace ProjectTank.Generics } g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } } /// diff --git a/ProjectTank/ProjectTank/ArmoredTransportsGenericStorage.cs b/ProjectTank/ProjectTank/ArmoredTransportsGenericStorage.cs index 4f15a1d..cd6ee0b 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportsGenericStorage.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportsGenericStorage.cs @@ -12,8 +12,7 @@ namespace ProjectTank.Generics /// /// Словарь (хранилище) /// - readonly Dictionary> _armoredTransportStorages; + readonly Dictionary> _armoredTransportStorages; /// /// Возвращение списка названий наборов /// @@ -33,8 +32,7 @@ namespace ProjectTank.Generics /// public ArmoredTransportsGenericStorage(int pictureWidth, int pictureHeight) { - _armoredTransportStorages = new Dictionary>(); + _armoredTransportStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -44,9 +42,7 @@ namespace ProjectTank.Generics /// Название набора public void AddSet(string name) { - _armoredTransportStorages.Add(name, new ArmoredTransportsGenericCollection(_pictureWidth, - _pictureHeight)); + _armoredTransportStorages.Add(name, new ArmoredTransportsGenericCollection(_pictureWidth, _pictureHeight)); } /// /// Удаление набора diff --git a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs index 39fd477..7dfa615 100644 --- a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs +++ b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs @@ -119,6 +119,14 @@ namespace ProjectTank.DrawningObjects _startPosY = y; } } + public void ChangeColor(Color color) + { + if (EntityArmoredTransport == null) + { + return; + } + EntityArmoredTransport.BodyColor = color; + } /// /// Прорисовка объекта /// diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index 2b85acc..a63d444 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -34,6 +34,10 @@ namespace ProjectTank.DrawningObjects additionalColor, gun, machineGun); } } + public void ChangeAddColor(Color color) + { + ((EntityTank)EntityArmoredTransport).AdditionalColor = color; + } public override void DrawTransport(Graphics g) { if (EntityArmoredTransport is not EntityTank tank) diff --git a/ProjectTank/ProjectTank/EntityArmoredTransport.cs b/ProjectTank/ProjectTank/EntityArmoredTransport.cs index bf3b54a..ee1c908 100644 --- a/ProjectTank/ProjectTank/EntityArmoredTransport.cs +++ b/ProjectTank/ProjectTank/EntityArmoredTransport.cs @@ -22,7 +22,7 @@ namespace ProjectTank.Entities /// /// Основной цвет /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг перемещения автомобиля /// diff --git a/ProjectTank/ProjectTank/EntityTank.cs b/ProjectTank/ProjectTank/EntityTank.cs index 136aca2..efc886b 100644 --- a/ProjectTank/ProjectTank/EntityTank.cs +++ b/ProjectTank/ProjectTank/EntityTank.cs @@ -15,7 +15,7 @@ namespace ProjectTank.Entities /// /// Дополнительный цвет (для опциональных элементов) /// - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } /// /// Пушка ///