diff --git a/Tank/Tank.sln b/Tank/Tank.sln index 736023a..9f7a1ff 100644 --- a/Tank/Tank.sln +++ b/Tank/Tank.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{5C602C58-ECEC-4FAB-BA10-FB671582D227}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +11,15 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.Build.0 = Release|Any CPU + {4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C238BAE-E8EA-4DEF-ABB8-DA9CC49797C0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {73BF3262-E499-401F-BDBD-BD2BC7D3C324} + SolutionGuid = {73628EAF-BF42-4CF6-87BF-26523028F0DD} EndGlobalSection EndGlobal diff --git a/Tank/Tank/DrawArmoVehicle.cs b/Tank/Tank/DrawArmoVehicle.cs index cfdf93e..8c7a09f 100644 --- a/Tank/Tank/DrawArmoVehicle.cs +++ b/Tank/Tank/DrawArmoVehicle.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Security.Cryptography.Pkcs; using System.Text; using System.Threading.Tasks; +using System.Drawing; using Tank.Entities; using Tank.MovementStrategy; @@ -12,8 +13,8 @@ namespace Tank public class DrawArmoVehicle { public EntityArmoVehicle? Tank { get; protected set; } - protected int _pictureWidth; - protected int _pictureHeight; + public int _pictureWidth; + public int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _Width = 160; diff --git a/Tank/Tank/DrawTank.cs b/Tank/Tank/DrawTank.cs index e270a72..d8b5247 100644 --- a/Tank/Tank/DrawTank.cs +++ b/Tank/Tank/DrawTank.cs @@ -38,7 +38,7 @@ namespace Tank.DrawningObjects if (ArmoVehicle.Caterpillar) { // Гусеница. Отрисовка танковых катков - Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black); + Brush BrushRandom = new SolidBrush(ArmoVehicle?.AdditionalColor ?? Color.Black); g.FillRectangle(BrushRandom, 28 + _startPosX, 50 + _startPosY, 10, 3); g.FillRectangle(BrushRandom, 53 + _startPosX, 50 + _startPosY, 10, 3); g.FillRectangle(BrushRandom, 78 + _startPosX, 50 + _startPosY, 10, 3); diff --git a/Tank/Tank/EntityArmoVehicle.cs b/Tank/Tank/EntityArmoVehicle.cs index 8263ed4..f8c2a31 100644 --- a/Tank/Tank/EntityArmoVehicle.cs +++ b/Tank/Tank/EntityArmoVehicle.cs @@ -4,13 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Tank.Entities +namespace Tank { public class EntityArmoVehicle { public int Speed { get; private set; } public double Weight { get; private set; } public Color BodyColor { get; private set; } + public void setBodyColor(Color color) { BodyColor = color; } public double Step => (double)Speed * 100 / Weight; public EntityArmoVehicle(int speed, double weight, Color bodyColor) { diff --git a/Tank/Tank/EntityTank.cs b/Tank/Tank/EntityTank.cs index 04d5f7f..39491e1 100644 --- a/Tank/Tank/EntityTank.cs +++ b/Tank/Tank/EntityTank.cs @@ -9,6 +9,7 @@ namespace Tank.Entities public class EntityTank : EntityArmoVehicle { public Color AdditionalColor { get; private set; } + public void setAdditionalColor(Color color) { AdditionalColor = color; } public bool BodyKit { get; private set; } public bool Caterpillar { get; private set; } public bool Tower { get; private set; } diff --git a/Tank/Tank/FormTankConfig.Designer.cs b/Tank/Tank/FormTankConfig.Designer.cs new file mode 100644 index 0000000..e6a334b --- /dev/null +++ b/Tank/Tank/FormTankConfig.Designer.cs @@ -0,0 +1,405 @@ +namespace Tank +{ + 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() + { + ParamsGroup = new GroupBox(); + labelTank = new Label(); + labelArmoVehicle = new Label(); + groupBoxColors = new GroupBox(); + panelPink = new Panel(); + panelYellow = new Panel(); + panelCyan = new Panel(); + panelRed = new Panel(); + panelBlue = new Panel(); + panelOrange = new Panel(); + panelGreen = new Panel(); + panelSilver = new Panel(); + checkBoxCaterpillar = new CheckBox(); + checkBoxBodyKit = new CheckBox(); + checkBoxTower = new CheckBox(); + numericWeight = new NumericUpDown(); + numericSpeed = new NumericUpDown(); + weightLabel = new Label(); + speedLabel = new Label(); + panelPictureTank = new Panel(); + pictureBox = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + labelColor = new Label(); + labelAdditionalColor = new Label(); + ParamsGroup.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericSpeed).BeginInit(); + panelPictureTank.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // ParamsGroup + // + ParamsGroup.Controls.Add(labelTank); + ParamsGroup.Controls.Add(labelArmoVehicle); + ParamsGroup.Controls.Add(groupBoxColors); + ParamsGroup.Controls.Add(checkBoxCaterpillar); + ParamsGroup.Controls.Add(checkBoxBodyKit); + ParamsGroup.Controls.Add(checkBoxTower); + ParamsGroup.Controls.Add(numericWeight); + ParamsGroup.Controls.Add(numericSpeed); + ParamsGroup.Controls.Add(weightLabel); + ParamsGroup.Controls.Add(speedLabel); + ParamsGroup.Location = new Point(5, 3); + ParamsGroup.Margin = new Padding(5, 4, 5, 4); + ParamsGroup.Name = "ParamsGroup"; + ParamsGroup.Padding = new Padding(5, 4, 5, 4); + ParamsGroup.Size = new Size(240, 740); + ParamsGroup.TabIndex = 0; + ParamsGroup.TabStop = false; + ParamsGroup.Text = "Params Group Box"; + // + // labelTank + // + labelTank.BorderStyle = BorderStyle.FixedSingle; + labelTank.Location = new Point(120, 644); + labelTank.Margin = new Padding(5, 0, 5, 0); + labelTank.Name = "labelTank"; + labelTank.Size = new Size(87, 55); + labelTank.TabIndex = 10; + labelTank.Text = "Tank"; + labelTank.TextAlign = ContentAlignment.MiddleCenter; + labelTank.MouseDown += LabelObject_MouseDown; + // + // labelArmoVehicle + // + labelArmoVehicle.BorderStyle = BorderStyle.FixedSingle; + labelArmoVehicle.Location = new Point(9, 644); + labelArmoVehicle.Margin = new Padding(5, 0, 5, 0); + labelArmoVehicle.Name = "labelArmoVehicle"; + labelArmoVehicle.Size = new Size(96, 55); + labelArmoVehicle.TabIndex = 9; + labelArmoVehicle.Text = "ArmoVehicle"; + labelArmoVehicle.TextAlign = ContentAlignment.MiddleCenter; + labelArmoVehicle.MouseDown += LabelObject_MouseDown; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPink); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelCyan); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelOrange); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelSilver); + groupBoxColors.Location = new Point(16, 268); + groupBoxColors.Margin = new Padding(5, 4, 5, 4); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Padding = new Padding(5, 4, 5, 4); + groupBoxColors.Size = new Size(210, 348); + groupBoxColors.TabIndex = 8; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Colors"; + // + // panelPink + // + panelPink.BackColor = Color.Fuchsia; + panelPink.Location = new Point(107, 276); + panelPink.Margin = new Padding(5, 4, 5, 4); + panelPink.Name = "panelPink"; + panelPink.Size = new Size(56, 61); + panelPink.TabIndex = 3; + panelPink.MouseDown += panelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(107, 108); + panelYellow.Margin = new Padding(5, 4, 5, 4); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(56, 61); + panelYellow.TabIndex = 1; + panelYellow.MouseDown += panelColor_MouseDown; + // + // panelCyan + // + panelCyan.BackColor = Color.Cyan; + panelCyan.Location = new Point(107, 192); + panelCyan.Margin = new Padding(5, 4, 5, 4); + panelCyan.Name = "panelCyan"; + panelCyan.Size = new Size(56, 61); + panelCyan.TabIndex = 4; + panelCyan.MouseDown += panelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(107, 24); + panelRed.Margin = new Padding(5, 4, 5, 4); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(56, 61); + panelRed.TabIndex = 1; + panelRed.MouseDown += panelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(33, 276); + panelBlue.Margin = new Padding(5, 4, 5, 4); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(56, 61); + panelBlue.TabIndex = 5; + panelBlue.MouseDown += panelColor_MouseDown; + // + // panelOrange + // + panelOrange.BackColor = Color.FromArgb(255, 128, 0); + panelOrange.Location = new Point(33, 108); + panelOrange.Margin = new Padding(5, 4, 5, 4); + panelOrange.Name = "panelOrange"; + panelOrange.Size = new Size(56, 61); + panelOrange.TabIndex = 1; + panelOrange.MouseDown += panelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Lime; + panelGreen.Location = new Point(33, 192); + panelGreen.Margin = new Padding(5, 4, 5, 4); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(56, 61); + panelGreen.TabIndex = 2; + panelGreen.MouseDown += panelColor_MouseDown; + // + // panelSilver + // + panelSilver.BackColor = Color.Silver; + panelSilver.Location = new Point(33, 24); + panelSilver.Margin = new Padding(5, 4, 5, 4); + panelSilver.Name = "panelSilver"; + panelSilver.Size = new Size(56, 61); + panelSilver.TabIndex = 0; + panelSilver.MouseDown += panelColor_MouseDown; + // + // checkBoxCaterpillarTank + // + checkBoxCaterpillar.AutoSize = true; + checkBoxCaterpillar.Location = new Point(18, 180); + checkBoxCaterpillar.Margin = new Padding(5, 4, 5, 4); + checkBoxCaterpillar.Name = "checkBoxCaterpillarTank"; + checkBoxCaterpillar.Size = new Size(100, 24); + checkBoxCaterpillar.TabIndex = 7; + checkBoxCaterpillar.Text = "Caterpillar"; + checkBoxCaterpillar.UseVisualStyleBackColor = true; + // + // checkBoxBodyKit + // + checkBoxBodyKit.AutoSize = true; + checkBoxBodyKit.Location = new Point(18, 149); + checkBoxBodyKit.Margin = new Padding(5, 4, 5, 4); + checkBoxBodyKit.Name = "checkBoxBodyKit"; + checkBoxBodyKit.Size = new Size(83, 24); + checkBoxBodyKit.TabIndex = 6; + checkBoxBodyKit.Text = "BodyKit"; + checkBoxBodyKit.UseVisualStyleBackColor = true; + // + // checkBoxTower + // + checkBoxTower.AutoSize = true; + checkBoxTower.Location = new Point(18, 216); + checkBoxTower.Margin = new Padding(5, 4, 5, 4); + checkBoxTower.Name = "checkBoxTower"; + checkBoxTower.Size = new Size(71, 24); + checkBoxTower.TabIndex = 5; + checkBoxTower.Text = "Tower"; + checkBoxTower.UseVisualStyleBackColor = true; + // + // numericWeight + // + numericWeight.Location = new Point(66, 79); + numericWeight.Margin = new Padding(5, 4, 5, 4); + numericWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericWeight.Name = "numericWeight"; + numericWeight.Size = new Size(160, 27); + numericWeight.TabIndex = 4; + numericWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericSpeed + // + numericSpeed.Location = new Point(66, 36); + numericSpeed.Margin = new Padding(5, 4, 5, 4); + numericSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericSpeed.Name = "numericSpeed"; + numericSpeed.Size = new Size(160, 27); + numericSpeed.TabIndex = 3; + numericSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // weightLabel + // + weightLabel.AutoSize = true; + weightLabel.Location = new Point(11, 79); + weightLabel.Margin = new Padding(5, 0, 5, 0); + weightLabel.Name = "weightLabel"; + weightLabel.Size = new Size(49, 20); + weightLabel.TabIndex = 2; + weightLabel.Text = "weigh"; + // + // speedLabel + // + speedLabel.AutoSize = true; + speedLabel.Location = new Point(11, 39); + speedLabel.Margin = new Padding(5, 0, 5, 0); + speedLabel.Name = "speedLabel"; + speedLabel.Size = new Size(49, 20); + speedLabel.TabIndex = 1; + speedLabel.Text = "speed"; + // + // panel9 + // + panelPictureTank.AllowDrop = true; + panelPictureTank.Controls.Add(pictureBox); + panelPictureTank.Location = new Point(266, 116); + panelPictureTank.Margin = new Padding(5, 4, 5, 4); + panelPictureTank.Name = "panel9"; + panelPictureTank.Size = new Size(784, 520); + panelPictureTank.TabIndex = 11; + panelPictureTank.DragDrop += PanelObject_DragDrop; + panelPictureTank.DragEnter += PanelObject_DragEnter; + // + // pictureBox + // + pictureBox.Location = new Point(18, 8); + pictureBox.Margin = new Padding(5, 4, 5, 4); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(741, 508); + pictureBox.TabIndex = 0; + pictureBox.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(306, 660); + buttonAdd.Margin = new Padding(5, 4, 5, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(200, 62); + buttonAdd.TabIndex = 12; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(793, 662); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(210, 60); + buttonCancel.TabIndex = 13; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(349, 37); + labelColor.Margin = new Padding(5, 0, 5, 0); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(139, 42); + labelColor.TabIndex = 14; + labelColor.Text = "Color"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += labelColor_DragDrop; + labelColor.DragEnter += labelColor_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(815, 32); + labelAdditionalColor.Margin = new Padding(5, 0, 5, 0); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(136, 39); + labelAdditionalColor.TabIndex = 15; + labelAdditionalColor.Text = "Additional color"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // FormTankConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1066, 744); + Controls.Add(labelAdditionalColor); + Controls.Add(labelColor); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(panelPictureTank); + Controls.Add(ParamsGroup); + Margin = new Padding(5, 4, 5, 4); + Name = "FormTankConfig"; + Text = "FormTankConfig"; + ParamsGroup.ResumeLayout(false); + ParamsGroup.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericSpeed).EndInit(); + panelPictureTank.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox ParamsGroup; + private CheckBox checkBoxCaterpillar; + private CheckBox checkBoxBodyKit; + private CheckBox checkBoxTower; + private NumericUpDown numericWeight; + private NumericUpDown numericSpeed; + private Label weightLabel; + private Label speedLabel; + private GroupBox groupBoxColors; + private Panel panelPink; + private Panel panelYellow; + private Panel panelCyan; + private Panel panelRed; + private Panel panelBlue; + private Panel panelOrange; + private Panel panelGreen; + private Panel panelSilver; + private Label labelTank; + private Label labelArmoVehicle; + private Panel panelPictureTank; + private PictureBox pictureBox; + private Button buttonAdd; + private Button buttonCancel; + private Label labelColor; + private Label labelAdditionalColor; + } +} \ No newline at end of file diff --git a/Tank/Tank/FormTankConfig.cs b/Tank/Tank/FormTankConfig.cs new file mode 100644 index 0000000..b3d82e3 --- /dev/null +++ b/Tank/Tank/FormTankConfig.cs @@ -0,0 +1,148 @@ +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 Tank.DrawningObjects; +using Tank.Entities; + +namespace Tank +{ + public partial class FormTankConfig : Form + { + Color defaultColor; + + // Переменная-выбранный танк + DrawArmoVehicle _tank = null; + + // Событие + private event Action EventAddTank; + + // Конструктор + public FormTankConfig() + { + InitializeComponent(); + + panelSilver.MouseDown += panelColor_MouseDown; + panelRed.MouseDown += panelColor_MouseDown; + panelOrange.MouseDown += panelColor_MouseDown; + panelYellow.MouseDown += panelColor_MouseDown; + panelGreen.MouseDown += panelColor_MouseDown; + panelCyan.MouseDown += panelColor_MouseDown; + panelBlue.MouseDown += panelColor_MouseDown; + panelPink.MouseDown += panelColor_MouseDown; + + defaultColor = labelColor.BackColor; + buttonCancel.Click += (s, e) => Close(); + } + + // Отрисовать танк + private void DrawingTank() + { + Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height); + Graphics gr = Graphics.FromImage(bmp); + _tank?.SetPosition(5, 5); + if (_tank is DrawTank) + (_tank as DrawTank).DrawTransport(gr); + else + _tank?.DrawTransport(gr); + pictureBox.Image = bmp; + } + + // Добавление события + internal void AddEvent(Action ev) + { + if (EventAddTank == null) + { + EventAddTank = ev; + } + else + { + EventAddTank += 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 "labelArmoVehicle": + _tank = new DrawArmoVehicle((int)numericSpeed.Value, (int)numericWeight.Value, Color.White, pictureBox.Width, pictureBox.Height); + break; + case "labelTank": + _tank = new DrawTank((int)numericSpeed.Value, (int)numericWeight.Value, Color.White, Color.Black, checkBoxBodyKit.Checked, checkBoxCaterpillar.Checked, checkBoxTower.Checked, pictureBox.Width, pictureBox.Height); + break; + } + labelColor.BackColor = defaultColor; + labelAdditionalColor.BackColor = defaultColor; + DrawingTank(); + } + + // Добавление танка + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddTank?.Invoke(_tank); + Close(); + } + + 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 (_tank == null) + return; + ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); + switch (((Label)sender).Name) + { + case "labelColor": + _tank.Tank.setBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAdditionalColor": + if (!(_tank is DrawTank)) + return; + (_tank.Tank as EntityTank).setAdditionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawingTank(); + } + } +} \ No newline at end of file diff --git a/Tank/Tank/FormTankConfig.resx b/Tank/Tank/FormTankConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Tank/Tank/FormTankConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Tank/Tank/FormTanksCollections.cs b/Tank/Tank/FormTanksCollections.cs index e310e23..f35d91d 100644 --- a/Tank/Tank/FormTanksCollections.cs +++ b/Tank/Tank/FormTanksCollections.cs @@ -77,7 +77,7 @@ namespace Tank } } - private void ButtonAddTank_Click(object sender, EventArgs e) + private void AddTank(DrawArmoVehicle tank) { if (CollectionListBox.SelectedIndex == -1) { @@ -88,20 +88,34 @@ namespace Tank { return; } - FormTank form = new(); - if (form.ShowDialog() == DialogResult.OK) + if ((obj + tank) != false) { - if (obj + form.SelectedTank) - { - MessageBox.Show("Объект добавлен"); - DrawTank.Image = obj.ShowTanks(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + DrawTank.Image = obj.ShowTanks(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } + + private void ButtonAddTank_Click(object sender, EventArgs e) + { + // Проверка на вызов формочки + if (CollectionListBox.SelectedIndex == -1) + { + return; + } + var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + FormTankConfig form = new FormTankConfig(); + form.Show(); + form.AddEvent(AddTank); + } + private void ButtonRemoveTank_Click(object sender, EventArgs e) { if (CollectionListBox.SelectedIndex == -1) diff --git a/Tank/Tank/TanksGenericCollection.cs b/Tank/Tank/TanksGenericCollection.cs index 5251443..70c5411 100644 --- a/Tank/Tank/TanksGenericCollection.cs +++ b/Tank/Tank/TanksGenericCollection.cs @@ -99,6 +99,8 @@ namespace Tank.Generics { if (tank != null) { + tank._pictureWidth = _pictureWidth; + tank._pictureHeight = _pictureHeight; tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); tank.DrawTransport(g); }