diff --git a/Hydroplane/EntityHydroplane.cs b/Hydroplane/EntityHydroplane.cs index f3eaf65..c385df0 100644 --- a/Hydroplane/EntityHydroplane.cs +++ b/Hydroplane/EntityHydroplane.cs @@ -8,7 +8,7 @@ namespace Hydroplane.Entities { public class EntityHydroplane : EntityPlane { - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } public bool Boat { get; private set; } public bool Bobber { get; private set; } public EntityHydroplane(int speed, double weight, Color bodyColor, Color @@ -18,5 +18,9 @@ namespace Hydroplane.Entities Boat = boat; Bobber = bobber; } + public void setAdditionalColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/Hydroplane/EntityPlane.cs b/Hydroplane/EntityPlane.cs index d030edc..bd47765 100644 --- a/Hydroplane/EntityPlane.cs +++ b/Hydroplane/EntityPlane.cs @@ -10,7 +10,7 @@ namespace Hydroplane.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 EntityPlane(int speed, double weight, Color bodyColor) { @@ -18,5 +18,9 @@ namespace Hydroplane.Entities Weight = weight; BodyColor = bodyColor; } + public void setBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/Hydroplane/FormHydroplaneCollection.cs b/Hydroplane/FormHydroplaneCollection.cs index 5c51f8e..18a0400 100644 --- a/Hydroplane/FormHydroplaneCollection.cs +++ b/Hydroplane/FormHydroplaneCollection.cs @@ -93,36 +93,39 @@ namespace Hydroplane ReloadObjects(); } } - /// - /// Добавление объекта в набор - /// - /// - /// + private void ButtonAddPlane_Click(object sender, EventArgs e) { if (CollectionListBox.SelectedIndex == -1) { return; } - var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty]; - if (obj == null) + + var formPlaneConfig = new FormPlaneConfig(); + + formPlaneConfig.AddEvent(plane => { - return; - } - FormHydroplane form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedPlane) + if (CollectionListBox.SelectedIndex != -1) { - MessageBox.Show("Объект добавлен"); - DrawPlane.Image = obj.ShowPlanes(); + var obj = _storage[CollectionListBox.SelectedItem?.ToString() ?? string.Empty]; + if (obj != null) + { + if (obj + plane) + { + MessageBox.Show("Объект добавлен"); + DrawPlane.Image = obj.ShowPlanes(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + }); + + formPlaneConfig.Show(); } + /// /// Удаление объекта из набора /// diff --git a/Hydroplane/FormPlaneConfig.Designer.cs b/Hydroplane/FormPlaneConfig.Designer.cs new file mode 100644 index 0000000..0da7c6d --- /dev/null +++ b/Hydroplane/FormPlaneConfig.Designer.cs @@ -0,0 +1,399 @@ +namespace Hydroplane +{ + partial class FormPlaneConfig + { + /// + /// 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() + { + groupBox_param = new GroupBox(); + checkBox_boat = new CheckBox(); + checkBox_bobber = new CheckBox(); + label_weight = new Label(); + groupBox_colors = new GroupBox(); + panelGray = new Panel(); + panelCian = new Panel(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelYellow = new Panel(); + panelRed = new Panel(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label_speed = new Label(); + labelOriginalObject = new Label(); + labelModifiedObject = new Label(); + pictureBox = new PictureBox(); + Panel = new Panel(); + button_close = new Button(); + button_add = new Button(); + label_color = new Label(); + panel_color = new Panel(); + panel_addit_color = new Panel(); + label1 = new Label(); + groupBox_param.SuspendLayout(); + groupBox_colors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + Panel.SuspendLayout(); + panel_color.SuspendLayout(); + panel_addit_color.SuspendLayout(); + SuspendLayout(); + // + // groupBox_param + // + groupBox_param.Controls.Add(checkBox_boat); + groupBox_param.Controls.Add(checkBox_bobber); + groupBox_param.Controls.Add(label_weight); + groupBox_param.Controls.Add(groupBox_colors); + groupBox_param.Controls.Add(numericUpDownWeight); + groupBox_param.Controls.Add(numericUpDownSpeed); + groupBox_param.Controls.Add(label_speed); + groupBox_param.Location = new Point(525, 9); + groupBox_param.Margin = new Padding(3, 2, 3, 2); + groupBox_param.Name = "groupBox_param"; + groupBox_param.Padding = new Padding(3, 2, 3, 2); + groupBox_param.Size = new Size(164, 301); + groupBox_param.TabIndex = 0; + groupBox_param.TabStop = false; + groupBox_param.Text = "Параметры"; + // + // checkBox_boat + // + checkBox_boat.AutoSize = true; + checkBox_boat.Location = new Point(89, 116); + checkBox_boat.Margin = new Padding(3, 2, 3, 2); + checkBox_boat.Name = "checkBox_boat"; + checkBox_boat.Size = new Size(59, 19); + checkBox_boat.TabIndex = 5; + checkBox_boat.Text = "Лодка"; + checkBox_boat.UseVisualStyleBackColor = true; + // + // checkBox_bobber + // + checkBox_bobber.AutoSize = true; + checkBox_bobber.Location = new Point(5, 116); + checkBox_bobber.Margin = new Padding(3, 2, 3, 2); + checkBox_bobber.Name = "checkBox_bobber"; + checkBox_bobber.Size = new Size(59, 19); + checkBox_bobber.TabIndex = 6; + checkBox_bobber.Text = "Лыжи"; + // + // label_weight + // + label_weight.AutoSize = true; + label_weight.Location = new Point(5, 64); + label_weight.Name = "label_weight"; + label_weight.Size = new Size(26, 15); + label_weight.TabIndex = 3; + label_weight.Text = "Вес"; + // + // groupBox_colors + // + groupBox_colors.Controls.Add(panelGray); + groupBox_colors.Controls.Add(panelCian); + groupBox_colors.Controls.Add(panelPurple); + groupBox_colors.Controls.Add(panelBlack); + groupBox_colors.Controls.Add(panelBlue); + groupBox_colors.Controls.Add(panelGreen); + groupBox_colors.Controls.Add(panelYellow); + groupBox_colors.Controls.Add(panelRed); + groupBox_colors.Location = new Point(9, 138); + groupBox_colors.Margin = new Padding(3, 2, 3, 2); + groupBox_colors.Name = "groupBox_colors"; + groupBox_colors.Padding = new Padding(3, 2, 3, 2); + groupBox_colors.Size = new Size(145, 152); + groupBox_colors.TabIndex = 1; + groupBox_colors.TabStop = false; + groupBox_colors.Text = "Цвета"; + // + // panelGray + // + panelGray.BackColor = Color.Silver; + panelGray.Location = new Point(80, 122); + panelGray.Margin = new Padding(3, 2, 3, 2); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(52, 19); + panelGray.TabIndex = 7; + // + // panelCian + // + panelCian.BackColor = Color.Cyan; + panelCian.Location = new Point(8, 122); + panelCian.Margin = new Padding(3, 2, 3, 2); + panelCian.Name = "panelCian"; + panelCian.Size = new Size(52, 19); + panelCian.TabIndex = 6; + // + // panelPurple + // + panelPurple.BackColor = Color.FromArgb(192, 0, 192); + panelPurple.Location = new Point(80, 92); + panelPurple.Margin = new Padding(3, 2, 3, 2); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(52, 19); + panelPurple.TabIndex = 5; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(8, 92); + panelBlack.Margin = new Padding(3, 2, 3, 2); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(52, 19); + panelBlack.TabIndex = 4; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(80, 59); + panelBlue.Margin = new Padding(3, 2, 3, 2); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(52, 19); + panelBlue.TabIndex = 3; + // + // panelGreen + // + panelGreen.BackColor = Color.Lime; + panelGreen.Location = new Point(8, 59); + panelGreen.Margin = new Padding(3, 2, 3, 2); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(52, 19); + panelGreen.TabIndex = 2; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(80, 27); + panelYellow.Margin = new Padding(3, 2, 3, 2); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(52, 19); + panelYellow.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(7, 28); + panelRed.Margin = new Padding(3, 2, 3, 2); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(52, 19); + panelRed.TabIndex = 0; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(5, 82); + numericUpDownWeight.Margin = new Padding(3, 2, 3, 2); + 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(46, 23); + numericUpDownWeight.TabIndex = 2; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(5, 42); + numericUpDownSpeed.Margin = new Padding(3, 2, 3, 2); + 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(49, 23); + numericUpDownSpeed.TabIndex = 1; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label_speed + // + label_speed.AutoSize = true; + label_speed.Location = new Point(5, 25); + label_speed.Name = "label_speed"; + label_speed.Size = new Size(59, 15); + label_speed.TabIndex = 0; + label_speed.Text = "Скорость"; + // + // labelOriginalObject + // + labelOriginalObject.BorderStyle = BorderStyle.FixedSingle; + labelOriginalObject.Location = new Point(530, 312); + labelOriginalObject.Name = "labelOriginalObject"; + labelOriginalObject.Size = new Size(71, 22); + labelOriginalObject.TabIndex = 2; + labelOriginalObject.Text = "Простой"; + labelOriginalObject.MouseDown += Label_MouseDown; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(622, 312); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(68, 22); + labelModifiedObject.TabIndex = 3; + labelModifiedObject.Text = "Потомок"; + labelModifiedObject.MouseDown += Label_MouseDown; + // + // pictureBox + // + pictureBox.Location = new Point(3, 16); + pictureBox.Margin = new Padding(3, 2, 3, 2); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(514, 274); + pictureBox.TabIndex = 4; + pictureBox.TabStop = false; + // + // Panel + // + Panel.AllowDrop = true; + Panel.Controls.Add(pictureBox); + Panel.Location = new Point(0, 44); + Panel.Margin = new Padding(3, 2, 3, 2); + Panel.Name = "Panel"; + Panel.Size = new Size(525, 294); + Panel.TabIndex = 5; + Panel.DragDrop += panel_dragDrop; + Panel.DragEnter += panel_dragEnter; + // + // button_close + // + button_close.Location = new Point(447, 9); + button_close.Margin = new Padding(3, 2, 3, 2); + button_close.Name = "button_close"; + button_close.Size = new Size(70, 22); + button_close.TabIndex = 8; + button_close.Text = "Отмена"; + button_close.UseVisualStyleBackColor = true; + // + // button_add + // + button_add.Location = new Point(359, 9); + button_add.Margin = new Padding(3, 2, 3, 2); + button_add.Name = "button_add"; + button_add.Size = new Size(83, 22); + button_add.TabIndex = 7; + button_add.Text = "Добавить"; + button_add.UseVisualStyleBackColor = true; + button_add.Click += button_add_Click; + // + // label_color + // + label_color.BorderStyle = BorderStyle.FixedSingle; + label_color.Location = new Point(4, 5); + label_color.Name = "label_color"; + label_color.Size = new Size(150, 35); + label_color.TabIndex = 5; + label_color.Text = "Основной цвет"; + // + // panel_color + // + panel_color.AllowDrop = true; + panel_color.Controls.Add(label_color); + panel_color.Location = new Point(0, 2); + panel_color.Margin = new Padding(3, 2, 3, 2); + panel_color.Name = "panel_color"; + panel_color.Size = new Size(157, 40); + panel_color.TabIndex = 6; + panel_color.DragDrop += labelColor_dragDrop; + panel_color.DragEnter += labelColor_dragEnter; + // + // panel_addit_color + // + panel_addit_color.AllowDrop = true; + panel_addit_color.Controls.Add(label1); + panel_addit_color.Location = new Point(164, 2); + panel_addit_color.Margin = new Padding(3, 2, 3, 2); + panel_addit_color.Name = "panel_addit_color"; + panel_addit_color.Size = new Size(157, 40); + panel_addit_color.TabIndex = 7; + panel_addit_color.DragDrop += labelColor_dragDrop; + panel_addit_color.DragEnter += labelColor_dragEnter; + // + // label1 + // + label1.BorderStyle = BorderStyle.FixedSingle; + label1.Location = new Point(3, 5); + label1.Name = "label1"; + label1.Size = new Size(152, 35); + label1.TabIndex = 6; + label1.Text = "Дополнительный цвет"; + // + // FormPlaneConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 338); + Controls.Add(panel_addit_color); + Controls.Add(panel_color); + Controls.Add(button_close); + Controls.Add(Panel); + Controls.Add(button_add); + Controls.Add(labelModifiedObject); + Controls.Add(labelOriginalObject); + Controls.Add(groupBox_param); + Margin = new Padding(3, 2, 3, 2); + Name = "FormPlaneConfig"; + Text = "FormSPAUConfig"; + groupBox_param.ResumeLayout(false); + groupBox_param.PerformLayout(); + groupBox_colors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + Panel.ResumeLayout(false); + panel_color.ResumeLayout(false); + panel_addit_color.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox_param; + private Label label_weight; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label_speed; + private CheckBox checkBox_boat; + private CheckBox checkBox_bobber; + private GroupBox groupBox_colors; + private Panel panelGreen; + private Panel panelYellow; + private Panel panelRed; + private Panel panelGray; + private Panel panelCian; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelBlue; + private Label labelOriginalObject; + private Label labelModifiedObject; + private PictureBox pictureBox; + private Panel Panel; + private Button button_close; + private Button button_add; + private Label label_color; + private Label label_addit_color; + private Panel panel_color; + private Panel panel_addit_color; + private Label label1; + } +} \ No newline at end of file diff --git a/Hydroplane/FormPlaneConfig.cs b/Hydroplane/FormPlaneConfig.cs new file mode 100644 index 0000000..2cbfc37 --- /dev/null +++ b/Hydroplane/FormPlaneConfig.cs @@ -0,0 +1,166 @@ +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 Hydroplane.DrawningObjects; +using Hydroplane.Entities; + +namespace Hydroplane +{ + public partial class FormPlaneConfig : Form + { + /// + /// Переменная-выбранная машина + /// + DrawningPlane? _plane = null; + /// + /// Событие + /// + public event Action? EventAddPlane; + /// + /// Конструктор + /// + public FormPlaneConfig() + { + + InitializeComponent(); + panelBlack.MouseDown += panelColor_MouseDown; + panelPurple.MouseDown += panelColor_MouseDown; + panelGray.MouseDown += panelColor_MouseDown; + panelGreen.MouseDown += panelColor_MouseDown; + panelRed.MouseDown += panelColor_MouseDown; + panelCian.MouseDown += panelColor_MouseDown; + panelYellow.MouseDown += panelColor_MouseDown; + panelBlue.MouseDown += panelColor_MouseDown; + + button_close.Click += (s, e) => Close(); + } + + + + /// + /// Отрисовать машину + /// + private void DrawPlane() + { + Bitmap bmp = new(pictureBox.Width, pictureBox.Height); + Graphics gr = Graphics.FromImage(bmp); + _plane?.SetPosition(5, 5); + _plane?.DrawTransport(gr); + pictureBox.Image = bmp; + } + + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddPlane == null) + { + EventAddPlane = ev; + } + else + { + EventAddPlane += ev; + } + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void Label_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// + private void panel_dragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + /// + /// Действия при приеме перетаскиваемой информации + /// + /// + /// + private void panel_dragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelOriginalObject": + _plane = new DrawningPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, pictureBox.Width, pictureBox.Height); + break; + case "labelModifiedObject": + _plane = new DrawningHydroplane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBox_boat.Checked, checkBox_bobber.Checked, pictureBox.Width, pictureBox.Height); + break; + } + DrawPlane(); + } + + public 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; + switch (((Panel)sender).Name) + { + case "panel_color": + _plane?.EntityPlane?.setBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "panel_addit_color": + if (!(_plane is DrawningHydroplane)) + return; + (_plane.EntityPlane as EntityHydroplane)?.setAdditionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawPlane(); + } + + /// + /// Добавление машины + /// + /// + /// + + private void button_add_Click(object sender, EventArgs e) + { + EventAddPlane?.Invoke(_plane); + Close(); + } + } +} diff --git a/Hydroplane/FormPlaneConfig.resx b/Hydroplane/FormPlaneConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Hydroplane/FormPlaneConfig.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