From f52c0fc2ca3493b7d5281cb3d216f1b4b5ce6385 Mon Sep 17 00:00:00 2001 From: DelphyAlmond Date: Sat, 15 Jun 2024 09:53:32 +0400 Subject: [PATCH 1/2] In process : make helicopter non-default --- .../CollectionGenericObj/StorageCollection.cs | 6 - ProjectCruiser/EditorForm3.Designer.cs | 344 ++++++++++++++++++ ProjectCruiser/EditorForm3.cs | 124 +++++++ ProjectCruiser/EditorForm3.resx | 120 ++++++ ProjectCruiser/Entities/EntityBase.cs | 5 + ProjectCruiser/Entities/EntityCruiser.cs | 5 + ProjectCruiser/ServiceForm2.Designer.cs | 232 ++++++------ ProjectCruiser/ServiceForm2.cs | 55 +-- ProjectCruiser/ShipDelegate.cs | 6 + 9 files changed, 725 insertions(+), 172 deletions(-) create mode 100644 ProjectCruiser/EditorForm3.Designer.cs create mode 100644 ProjectCruiser/EditorForm3.cs create mode 100644 ProjectCruiser/EditorForm3.resx create mode 100644 ProjectCruiser/ShipDelegate.cs diff --git a/ProjectCruiser/CollectionGenericObj/StorageCollection.cs b/ProjectCruiser/CollectionGenericObj/StorageCollection.cs index f835efa..cd62ac5 100644 --- a/ProjectCruiser/CollectionGenericObj/StorageCollection.cs +++ b/ProjectCruiser/CollectionGenericObj/StorageCollection.cs @@ -46,12 +46,6 @@ where T : class public ICollectionGenObj? this[string name] { get => _storages.ContainsKey(name) ? _storages[name] : null; - /* ^^^ - { - if (_storages.ContainsKey(name)) return _storages[name]; - return null; - } - */ } } diff --git a/ProjectCruiser/EditorForm3.Designer.cs b/ProjectCruiser/EditorForm3.Designer.cs new file mode 100644 index 0000000..ae42415 --- /dev/null +++ b/ProjectCruiser/EditorForm3.Designer.cs @@ -0,0 +1,344 @@ +namespace ProjectCruiser +{ + partial class EditorForm3 + { + /// + /// 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() + { + ParametersBox = new GroupBox(); + AdvLabel = new Label(); + BaseLabel = new Label(); + groupBox2 = new GroupBox(); + PurpleP = new Panel(); + GreenP = new Panel(); + PinkP = new Panel(); + OrangeP = new Panel(); + CyanP = new Panel(); + YellowP = new Panel(); + RedP = new Panel(); + BlueP = new Panel(); + checkBoxPads = new CheckBox(); + checkBoxHangars = new CheckBox(); + WeightN = new NumericUpDown(); + SpeedN = new NumericUpDown(); + Label = new Label(); + Showcase = new PictureBox(); + btnAdd = new Button(); + btnCancel = new Button(); + panelObject = new Panel(); + labelAcolor = new Label(); + labelMcolor = new Label(); + ParametersBox.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)WeightN).BeginInit(); + ((System.ComponentModel.ISupportInitialize)SpeedN).BeginInit(); + ((System.ComponentModel.ISupportInitialize)Showcase).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // ParametersBox + // + ParametersBox.Controls.Add(AdvLabel); + ParametersBox.Controls.Add(BaseLabel); + ParametersBox.Controls.Add(groupBox2); + ParametersBox.Controls.Add(checkBoxPads); + ParametersBox.Controls.Add(checkBoxHangars); + ParametersBox.Controls.Add(WeightN); + ParametersBox.Controls.Add(SpeedN); + ParametersBox.Controls.Add(Label); + ParametersBox.Location = new Point(12, 0); + ParametersBox.Name = "ParametersBox"; + ParametersBox.Size = new Size(388, 495); + ParametersBox.TabIndex = 0; + ParametersBox.TabStop = false; + ParametersBox.Text = "Parameters"; + // + // AdvLabel + // + AdvLabel.BorderStyle = BorderStyle.FixedSingle; + AdvLabel.Location = new Point(175, 428); + AdvLabel.Name = "AdvLabel"; + AdvLabel.Size = new Size(184, 46); + AdvLabel.TabIndex = 5; + AdvLabel.Text = "Advanced"; + AdvLabel.TextAlign = ContentAlignment.MiddleCenter; + AdvLabel.MouseDown += BaseAdvLabel_MouseDown; + // + // BaseLabel + // + BaseLabel.BorderStyle = BorderStyle.FixedSingle; + BaseLabel.Location = new Point(17, 428); + BaseLabel.Name = "BaseLabel"; + BaseLabel.Size = new Size(132, 46); + BaseLabel.TabIndex = 4; + BaseLabel.Text = "Base"; + BaseLabel.TextAlign = ContentAlignment.MiddleCenter; + BaseLabel.MouseDown += BaseAdvLabel_MouseDown; + // + // groupBox2 + // + groupBox2.Controls.Add(PurpleP); + groupBox2.Controls.Add(GreenP); + groupBox2.Controls.Add(PinkP); + groupBox2.Controls.Add(OrangeP); + groupBox2.Controls.Add(CyanP); + groupBox2.Controls.Add(YellowP); + groupBox2.Controls.Add(RedP); + groupBox2.Controls.Add(BlueP); + groupBox2.Location = new Point(17, 197); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(342, 213); + groupBox2.TabIndex = 1; + groupBox2.TabStop = false; + groupBox2.Text = "Color picker"; + // + // PurpleP + // + PurpleP.BackColor = Color.DarkViolet; + PurpleP.Location = new Point(260, 126); + PurpleP.Name = "PurpleP"; + PurpleP.Size = new Size(63, 59); + PurpleP.TabIndex = 12; + // + // GreenP + // + GreenP.BackColor = Color.SpringGreen; + GreenP.Location = new Point(259, 49); + GreenP.Name = "GreenP"; + GreenP.Size = new Size(63, 59); + GreenP.TabIndex = 9; + // + // PinkP + // + PinkP.BackColor = Color.DeepPink; + PinkP.Location = new Point(180, 126); + PinkP.Name = "PinkP"; + PinkP.Size = new Size(63, 59); + PinkP.TabIndex = 11; + // + // OrangeP + // + OrangeP.BackColor = Color.DarkOrange; + OrangeP.Location = new Point(180, 49); + OrangeP.Name = "OrangeP"; + OrangeP.Size = new Size(63, 59); + OrangeP.TabIndex = 8; + // + // CyanP + // + CyanP.BackColor = Color.Cyan; + CyanP.Location = new Point(100, 126); + CyanP.Name = "CyanP"; + CyanP.Size = new Size(63, 59); + CyanP.TabIndex = 10; + // + // YellowP + // + YellowP.BackColor = Color.Gold; + YellowP.Location = new Point(19, 126); + YellowP.Name = "YellowP"; + YellowP.Size = new Size(63, 59); + YellowP.TabIndex = 9; + // + // RedP + // + RedP.BackColor = Color.Firebrick; + RedP.Location = new Point(100, 49); + RedP.Name = "RedP"; + RedP.Size = new Size(63, 59); + RedP.TabIndex = 7; + // + // BlueP + // + BlueP.BackColor = SystemColors.Highlight; + BlueP.Location = new Point(19, 49); + BlueP.Name = "BlueP"; + BlueP.Size = new Size(63, 59); + BlueP.TabIndex = 6; + // + // checkBoxPads + // + checkBoxPads.AutoSize = true; + checkBoxPads.Location = new Point(24, 142); + checkBoxPads.Name = "checkBoxPads"; + checkBoxPads.Size = new Size(203, 36); + checkBoxPads.TabIndex = 3; + checkBoxPads.Text = "Helicopter pad"; + checkBoxPads.UseVisualStyleBackColor = true; + // + // checkBoxHangars + // + checkBoxHangars.AutoSize = true; + checkBoxHangars.Location = new Point(234, 142); + checkBoxHangars.Name = "checkBoxHangars"; + checkBoxHangars.Size = new Size(133, 36); + checkBoxHangars.TabIndex = 1; + checkBoxHangars.Text = "Hangars"; + checkBoxHangars.UseVisualStyleBackColor = true; + // + // WeightN + // + WeightN.Location = new Point(198, 88); + WeightN.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + WeightN.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + WeightN.Name = "WeightN"; + WeightN.Size = new Size(142, 39); + WeightN.TabIndex = 2; + WeightN.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // SpeedN + // + SpeedN.Location = new Point(36, 88); + SpeedN.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + SpeedN.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + SpeedN.Name = "SpeedN"; + SpeedN.Size = new Size(142, 39); + SpeedN.TabIndex = 1; + SpeedN.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // Label + // + Label.AutoSize = true; + Label.Location = new Point(36, 53); + Label.Name = "Label"; + Label.Size = new Size(304, 32); + Label.TabIndex = 1; + Label.Text = "Speed Weight"; + // + // Showcase + // + Showcase.Location = new Point(58, 98); + Showcase.Name = "Showcase"; + Showcase.Size = new Size(458, 272); + Showcase.TabIndex = 1; + Showcase.TabStop = false; + // + // btnAdd + // + btnAdd.Location = new Point(419, 447); + btnAdd.Name = "btnAdd"; + btnAdd.Size = new Size(268, 46); + btnAdd.TabIndex = 2; + btnAdd.Text = "Add"; + btnAdd.UseVisualStyleBackColor = true; + btnAdd.Click += AddButton_Click; + // + // btnCancel + // + btnCancel.Location = new Point(694, 447); + btnCancel.Name = "btnCancel"; + btnCancel.Size = new Size(286, 46); + btnCancel.TabIndex = 3; + btnCancel.Text = "Cancel"; + btnCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAcolor); + panelObject.Controls.Add(labelMcolor); + panelObject.Controls.Add(Showcase); + panelObject.Location = new Point(419, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(561, 410); + panelObject.TabIndex = 4; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAcolor + // + labelAcolor.AllowDrop = true; + labelAcolor.BorderStyle = BorderStyle.FixedSingle; + labelAcolor.Location = new Point(253, 39); + labelAcolor.Name = "labelAcolor"; + labelAcolor.Size = new Size(263, 42); + labelAcolor.TabIndex = 7; + labelAcolor.Text = "Additional color"; + labelAcolor.TextAlign = ContentAlignment.MiddleCenter; + labelAcolor.DragDrop += AdditionalColor_DragDrop; + labelAcolor.DragEnter += AdditionalColor_DragEnter; + // + // labelMcolor + // + labelMcolor.AllowDrop = true; + labelMcolor.BorderStyle = BorderStyle.FixedSingle; + labelMcolor.Location = new Point(58, 39); + labelMcolor.Name = "labelMcolor"; + labelMcolor.Size = new Size(180, 42); + labelMcolor.TabIndex = 6; + labelMcolor.Text = "Main color"; + labelMcolor.TextAlign = ContentAlignment.MiddleCenter; + labelMcolor.DragDrop += BodyColor_DragDrop; + labelMcolor.DragEnter += BodyColor_DragEnter; + // + // EditorForm3 + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(992, 516); + Controls.Add(panelObject); + Controls.Add(btnCancel); + Controls.Add(btnAdd); + Controls.Add(ParametersBox); + Name = "EditorForm3"; + Text = "FormTransportConfig"; + ParametersBox.ResumeLayout(false); + ParametersBox.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)WeightN).EndInit(); + ((System.ComponentModel.ISupportInitialize)SpeedN).EndInit(); + ((System.ComponentModel.ISupportInitialize)Showcase).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox ParametersBox; + private Label Label; + private CheckBox checkBoxPads; + private CheckBox checkBoxHangars; + private NumericUpDown WeightN; + private NumericUpDown SpeedN; + private GroupBox groupBox2; + private Label BaseLabel; + private Label AdvLabel; + private Panel PurpleP; + private Panel GreenP; + private Panel PinkP; + private Panel OrangeP; + private Panel CyanP; + private Panel YellowP; + private Panel RedP; + private Panel BlueP; + private PictureBox Showcase; + private Button btnAdd; + private Button btnCancel; + private Panel panelObject; + private Label labelMcolor; + private Label labelAcolor; + } +} \ No newline at end of file diff --git a/ProjectCruiser/EditorForm3.cs b/ProjectCruiser/EditorForm3.cs new file mode 100644 index 0000000..949cbf5 --- /dev/null +++ b/ProjectCruiser/EditorForm3.cs @@ -0,0 +1,124 @@ +using ProjectCruiser.DrawningSamples; +using ProjectCruiser.Entities; +using System; + +namespace ProjectCruiser; +public partial class EditorForm3 : Form +{ + private DrawningBase _cruiser; + + // private event Action? shipDelegate; + private event ShipDelegate? shipDelegate; + + public EditorForm3() + { + InitializeComponent(); + BlueP.MouseDown += Panel_MouseDown; + RedP.MouseDown += Panel_MouseDown; + PinkP.MouseDown += Panel_MouseDown; + YellowP.MouseDown += Panel_MouseDown; + CyanP.MouseDown += Panel_MouseDown; + PurpleP.MouseDown += Panel_MouseDown; + GreenP.MouseDown += Panel_MouseDown; + OrangeP.MouseDown += Panel_MouseDown; + btnCancel.Click += (sender, e) => Close(); + } + + public void AddEvent(ShipDelegate del)// Action delegator) + { + if (shipDelegate == null) shipDelegate = del; + else shipDelegate += del; + //shipDelegate += del; + } + + private void DrawObject() + { + Bitmap bmp = new(Showcase.Width, Showcase.Height); + Graphics gr = Graphics.FromImage(bmp); + + _cruiser?.SetPictureSize(Showcase.Width, Showcase.Height); + _cruiser?.SetPosition(Showcase.Width - 400, Showcase.Height - 120); + _cruiser?.DrawTransport(gr); + Showcase.Image = bmp; + } + + private void Panel_MouseDown(object? sender, MouseEventArgs e) + { + // TODO отправка цвета в Drag&Drop + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void BaseAdvLabel_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, 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 "BaseLabel": + _cruiser = new DrawningBase((int)SpeedN.Value, (double)WeightN.Value, Color.White); + break; + case "AdvLabel": + Random rn = new Random(); + _cruiser = new DrawningCruiser((int)SpeedN.Value, (double)WeightN.Value, + Color.White, Color.Black,checkBoxHangars.Checked); + // ADD helicopter PAD as NOT DEFAULT - checkBoxPads.Checked [!] + // Convert.ToBoolean(rn.Next(0, 2))); + break; + } + labelMcolor.BackColor = Color.Empty; + labelAcolor.BackColor = Color.Empty; + DrawObject(); + } + + // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + private void BodyColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy; + else e.Effect = DragDropEffects.None; + } + + private void BodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_cruiser != null) + { + _cruiser.EntityTransport.setMainColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + } + + private void AdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (_cruiser is DrawningCruiser) + { + if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy; + else e.Effect = DragDropEffects.None; + } + } + + private void AdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_cruiser.EntityTransport is EntityCruiser _ship) + { + _ship.setAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + } + + private void AddButton_Click(object sender, EventArgs e) + { + if (_cruiser != null) + { + shipDelegate?.Invoke(_cruiser); + Close(); + } + } +} diff --git a/ProjectCruiser/EditorForm3.resx b/ProjectCruiser/EditorForm3.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCruiser/EditorForm3.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/ProjectCruiser/Entities/EntityBase.cs b/ProjectCruiser/Entities/EntityBase.cs index f9aac46..ba5b0cf 100644 --- a/ProjectCruiser/Entities/EntityBase.cs +++ b/ProjectCruiser/Entities/EntityBase.cs @@ -7,6 +7,11 @@ public class EntityBase public double Weight { get; private set; } // вес public Color MainColor { get; private set; } // основной цвет + public void setMainColor(Color clr) + { + MainColor = clr; + } + // public bool Deckhouse { get; private set; } // салон на верхней палубе public double Step => Speed * 100 / Weight; diff --git a/ProjectCruiser/Entities/EntityCruiser.cs b/ProjectCruiser/Entities/EntityCruiser.cs index 514f8e8..af25267 100644 --- a/ProjectCruiser/Entities/EntityCruiser.cs +++ b/ProjectCruiser/Entities/EntityCruiser.cs @@ -4,6 +4,11 @@ public class EntityCruiser : EntityBase { public Color AdditionalColor { get; private set; } // доп. цвет + public void setAdditionalColor(Color clr) + { + AdditionalColor = clr; + } + // признаки (наличия) public bool HelicopterPads { get; private set; } // вертолетная площадка public bool Hangars { get; private set; } // ангар diff --git a/ProjectCruiser/ServiceForm2.Designer.cs b/ProjectCruiser/ServiceForm2.Designer.cs index ed3cc6a..3a92906 100644 --- a/ProjectCruiser/ServiceForm2.Designer.cs +++ b/ProjectCruiser/ServiceForm2.Designer.cs @@ -29,16 +29,7 @@ private void InitializeComponent() { comboBoxArrList = new ComboBox(); - btnAddBase = new Button(); groupBox = new GroupBox(); - toolPanel = new Panel(); - btnUpdate = new Button(); - btnTest = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - btnDelete = new Button(); - btnAddCruiser = new Button(); - btnCreateCompany = new Button(); - pictureBox = new PictureBox(); companyPanel = new Panel(); btnDeleteCollection = new Button(); listBox = new ListBox(); @@ -47,10 +38,18 @@ rBtnArray = new RadioButton(); maskedTxtBoxCName = new MaskedTextBox(); label = new Label(); + toolPanel = new Panel(); + btnUpdate = new Button(); + btnTest = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + btnDelete = new Button(); + btnAddCruiser = new Button(); + btnCreateCompany = new Button(); + pictureBox = new PictureBox(); groupBox.SuspendLayout(); + companyPanel.SuspendLayout(); toolPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - companyPanel.SuspendLayout(); SuspendLayout(); // // comboBoxArrList @@ -64,17 +63,6 @@ comboBoxArrList.TabIndex = 0; comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged; // - // btnAddBase - // - btnAddBase.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnAddBase.Location = new Point(17, 13); - btnAddBase.Name = "btnAddBase"; - btnAddBase.Size = new Size(192, 43); - btnAddBase.TabIndex = 1; - btnAddBase.Text = "Add ship"; - btnAddBase.UseVisualStyleBackColor = true; - btnAddBase.Click += btnAddBase_Click; - // // groupBox // groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; @@ -89,6 +77,89 @@ groupBox.TabStop = false; groupBox.Text = "Tool panel"; // + // companyPanel + // + companyPanel.Controls.Add(btnDeleteCollection); + companyPanel.Controls.Add(listBox); + companyPanel.Controls.Add(btnAddCollection); + companyPanel.Controls.Add(rBtnList); + companyPanel.Controls.Add(rBtnArray); + companyPanel.Controls.Add(maskedTxtBoxCName); + companyPanel.Controls.Add(label); + companyPanel.Location = new Point(17, 91); + companyPanel.Name = "companyPanel"; + companyPanel.Size = new Size(243, 391); + companyPanel.TabIndex = 7; + // + // btnDeleteCollection + // + btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + btnDeleteCollection.Location = new Point(15, 312); + btnDeleteCollection.Name = "btnDeleteCollection"; + btnDeleteCollection.Size = new Size(214, 73); + btnDeleteCollection.TabIndex = 11; + btnDeleteCollection.Text = "Remove Collection"; + btnDeleteCollection.UseVisualStyleBackColor = true; + btnDeleteCollection.Click += btnCollectionDel_Click; + // + // listBox + // + listBox.FormattingEnabled = true; + listBox.Location = new Point(16, 174); + listBox.Name = "listBox"; + listBox.Size = new Size(214, 132); + listBox.TabIndex = 10; + // + // btnAddCollection + // + btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + btnAddCollection.Location = new Point(15, 119); + btnAddCollection.Name = "btnAddCollection"; + btnAddCollection.Size = new Size(214, 50); + btnAddCollection.TabIndex = 7; + btnAddCollection.Text = "Add Collection"; + btnAddCollection.UseVisualStyleBackColor = true; + btnAddCollection.Click += btnCollectionAdd_Click; + // + // rBtnList + // + rBtnList.AutoSize = true; + rBtnList.Location = new Point(150, 80); + rBtnList.Name = "rBtnList"; + rBtnList.Size = new Size(80, 36); + rBtnList.TabIndex = 9; + rBtnList.TabStop = true; + rBtnList.Text = "List"; + rBtnList.UseVisualStyleBackColor = true; + // + // rBtnArray + // + rBtnArray.AutoSize = true; + rBtnArray.Location = new Point(16, 80); + rBtnArray.Name = "rBtnArray"; + rBtnArray.Size = new Size(100, 36); + rBtnArray.TabIndex = 8; + rBtnArray.TabStop = true; + rBtnArray.Text = "Array"; + rBtnArray.UseVisualStyleBackColor = true; + // + // maskedTxtBoxCName + // + maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + maskedTxtBoxCName.Location = new Point(16, 40); + maskedTxtBoxCName.Name = "maskedTxtBoxCName"; + maskedTxtBoxCName.Size = new Size(214, 39); + maskedTxtBoxCName.TabIndex = 7; + // + // label + // + label.AutoSize = true; + label.Location = new Point(29, 5); + label.Name = "label"; + label.Size = new Size(188, 32); + label.TabIndex = 0; + label.Text = "Collection name"; + // // toolPanel // toolPanel.Controls.Add(btnUpdate); @@ -96,19 +167,18 @@ toolPanel.Controls.Add(maskedTextBoxPosition); toolPanel.Controls.Add(btnDelete); toolPanel.Controls.Add(btnAddCruiser); - toolPanel.Controls.Add(btnAddBase); toolPanel.Enabled = false; - toolPanel.Location = new Point(26, 593); + toolPanel.Location = new Point(26, 567); toolPanel.Name = "toolPanel"; - toolPanel.Size = new Size(226, 377); + toolPanel.Size = new Size(226, 317); toolPanel.TabIndex = 13; // // btnUpdate // btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnUpdate.Location = new Point(17, 315); + btnUpdate.Location = new Point(16, 257); btnUpdate.Name = "btnUpdate"; - btnUpdate.Size = new Size(192, 49); + btnUpdate.Size = new Size(192, 41); btnUpdate.TabIndex = 6; btnUpdate.Text = "Update"; btnUpdate.UseVisualStyleBackColor = true; @@ -117,9 +187,9 @@ // btnTest // btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnTest.Location = new Point(17, 224); + btnTest.Location = new Point(17, 162); btnTest.Name = "btnTest"; - btnTest.Size = new Size(192, 85); + btnTest.Size = new Size(192, 89); btnTest.TabIndex = 5; btnTest.Text = "Choose\r\nfor testing"; btnTest.UseVisualStyleBackColor = true; @@ -128,7 +198,7 @@ // maskedTextBoxPosition // maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBoxPosition.Location = new Point(17, 119); + maskedTextBoxPosition.Location = new Point(17, 68); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(192, 39); @@ -138,9 +208,9 @@ // btnDelete // btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnDelete.Location = new Point(17, 170); + btnDelete.Location = new Point(16, 113); btnDelete.Name = "btnDelete"; - btnDelete.Size = new Size(192, 48); + btnDelete.Size = new Size(192, 43); btnDelete.TabIndex = 4; btnDelete.Text = "Delete"; btnDelete.UseVisualStyleBackColor = true; @@ -149,22 +219,22 @@ // btnAddCruiser // btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnAddCruiser.Location = new Point(17, 62); + btnAddCruiser.Location = new Point(17, 13); btnAddCruiser.Name = "btnAddCruiser"; - btnAddCruiser.Size = new Size(192, 51); + btnAddCruiser.Size = new Size(192, 49); btnAddCruiser.TabIndex = 2; btnAddCruiser.Text = "Add cruiser"; btnAddCruiser.UseVisualStyleBackColor = true; - btnAddCruiser.Click += btnAddAdvanced_Click; + btnAddCruiser.Click += btnAddTransport_Click; // // btnCreateCompany // btnCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnCreateCompany.Location = new Point(17, 526); + btnCreateCompany.Location = new Point(16, 488); btnCreateCompany.Name = "btnCreateCompany"; - btnCreateCompany.Size = new Size(243, 61); + btnCreateCompany.Size = new Size(245, 73); btnCreateCompany.TabIndex = 12; - btnCreateCompany.Text = "Create Company"; + btnCreateCompany.Text = "Create or switch to Company"; btnCreateCompany.UseVisualStyleBackColor = true; btnCreateCompany.Click += btnCreateCompany_Click; // @@ -177,89 +247,6 @@ pictureBox.TabIndex = 3; pictureBox.TabStop = false; // - // companyPanel - // - companyPanel.Controls.Add(btnDeleteCollection); - companyPanel.Controls.Add(listBox); - companyPanel.Controls.Add(btnAddCollection); - companyPanel.Controls.Add(rBtnList); - companyPanel.Controls.Add(rBtnArray); - companyPanel.Controls.Add(maskedTxtBoxCName); - companyPanel.Controls.Add(label); - companyPanel.Location = new Point(17, 91); - companyPanel.Name = "companyPanel"; - companyPanel.Size = new Size(243, 429); - companyPanel.TabIndex = 7; - // - // btnDeleteCollection - // - btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnDeleteCollection.Location = new Point(15, 371); - btnDeleteCollection.Name = "btnDeleteCollection"; - btnDeleteCollection.Size = new Size(214, 43); - btnDeleteCollection.TabIndex = 11; - btnDeleteCollection.Text = "Remove Collection"; - btnDeleteCollection.UseVisualStyleBackColor = true; - btnDeleteCollection.Click += btnCollectionDel_Click; - // - // listBox - // - listBox.FormattingEnabled = true; - listBox.Location = new Point(16, 199); - listBox.Name = "listBox"; - listBox.Size = new Size(214, 164); - listBox.TabIndex = 10; - // - // btnAddCollection - // - btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - btnAddCollection.Location = new Point(15, 130); - btnAddCollection.Name = "btnAddCollection"; - btnAddCollection.Size = new Size(214, 61); - btnAddCollection.TabIndex = 7; - btnAddCollection.Text = "Add Collection"; - btnAddCollection.UseVisualStyleBackColor = true; - btnAddCollection.Click += btnCollectionAdd_Click; - // - // rBtnList - // - rBtnList.AutoSize = true; - rBtnList.Location = new Point(150, 88); - rBtnList.Name = "rBtnList"; - rBtnList.Size = new Size(80, 36); - rBtnList.TabIndex = 9; - rBtnList.TabStop = true; - rBtnList.Text = "List"; - rBtnList.UseVisualStyleBackColor = true; - // - // rBtnArray - // - rBtnArray.AutoSize = true; - rBtnArray.Location = new Point(16, 88); - rBtnArray.Name = "rBtnArray"; - rBtnArray.Size = new Size(100, 36); - rBtnArray.TabIndex = 8; - rBtnArray.TabStop = true; - rBtnArray.Text = "Array"; - rBtnArray.UseVisualStyleBackColor = true; - // - // maskedTxtBoxCName - // - maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - maskedTxtBoxCName.Location = new Point(16, 43); - maskedTxtBoxCName.Name = "maskedTxtBoxCName"; - maskedTxtBoxCName.Size = new Size(214, 39); - maskedTxtBoxCName.TabIndex = 7; - // - // label - // - label.AutoSize = true; - label.Location = new Point(29, 6); - label.Name = "label"; - label.Size = new Size(188, 32); - label.TabIndex = 0; - label.Text = "Collection name"; - // // ServiceForm2 // AutoScaleDimensions = new SizeF(13F, 32F); @@ -270,18 +257,17 @@ Name = "ServiceForm2"; Text = "ServiceForm2"; groupBox.ResumeLayout(false); + companyPanel.ResumeLayout(false); + companyPanel.PerformLayout(); toolPanel.ResumeLayout(false); toolPanel.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - companyPanel.ResumeLayout(false); - companyPanel.PerformLayout(); ResumeLayout(false); } #endregion private ComboBox comboBoxArrList; - private Button btnAddBase; private GroupBox groupBox; private Button btnAddCruiser; private Button btnUpdate; diff --git a/ProjectCruiser/ServiceForm2.cs b/ProjectCruiser/ServiceForm2.cs index 02bbd58..fb6f4d7 100644 --- a/ProjectCruiser/ServiceForm2.cs +++ b/ProjectCruiser/ServiceForm2.cs @@ -1,9 +1,5 @@ -using System.Collections.Generic; -using System.Windows.Forms; -using System.Xml.Linq; -using ProjectCruiser.CollectionGenericObj; +using ProjectCruiser.CollectionGenericObj; using ProjectCruiser.DrawningSamples; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace ProjectCruiser; public partial class ServiceForm2 : Form @@ -22,16 +18,6 @@ public partial class ServiceForm2 : Form // Выбор компании private void SelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - /* - switch (comboBoxArrList.Text) - { - case "Storage": - _company = new ShipSharingService(pictureBox.Width, pictureBox.Height, - new ArrayGenObj()); - break; - } - */ - toolPanel.Enabled = false; } @@ -47,40 +33,23 @@ public partial class ServiceForm2 : Form return cl; } - // Добавление обычного корабля - private void btnAddBase_Click(object sender, EventArgs e) => - CreateObject(nameof(DrawningBase)); - - // Добавление продвинутого - private void btnAddAdvanced_Click(object sender, EventArgs e) => - CreateObject(nameof(DrawningCruiser)); + // Добавление корабля + private void btnAddTransport_Click(object sender, EventArgs e) + { + EditorForm3 form3 = new(); + // TODO передать метод : + form3.AddEvent(CreateObject); + form3.Show(); + } // Создание объекта класса-перемещения - private void CreateObject(string type) + private void CreateObject(DrawningBase? ship) { - if (_company == null) + if (_company == null || ship == null) { return; } - Random random = new(); - DrawningBase drawningCar; - - switch (type) - { - case nameof(DrawningBase): - drawningCar = new DrawningBase(random.Next(100, 300), - random.Next(1000, 3000), pickColor(random)); - break; - - case nameof(DrawningCruiser): - drawningCar = new DrawningCruiser(random.Next(100, 300), - random.Next(1000, 3000), pickColor(random), pickColor(random), - Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - if (_company + drawningCar != -1) + if (_company + ship != -1) { MessageBox.Show("> Object was added"); pictureBox.Image = _company.Show(); diff --git a/ProjectCruiser/ShipDelegate.cs b/ProjectCruiser/ShipDelegate.cs new file mode 100644 index 0000000..5f320a0 --- /dev/null +++ b/ProjectCruiser/ShipDelegate.cs @@ -0,0 +1,6 @@ +using ProjectCruiser.DrawningSamples; + +namespace ProjectCruiser +{ + public delegate void ShipDelegate(DrawningBase transport); +} -- 2.25.1 From f3a64bc61701e498ae839c43f7004aa201337a05 Mon Sep 17 00:00:00 2001 From: DelphyAlmond Date: Sat, 15 Jun 2024 10:03:23 +0400 Subject: [PATCH 2/2] delegates --- .../DrawningSamples/DrawningCruiser.cs | 20 ++++++++++--------- ProjectCruiser/EditorForm3.cs | 9 ++------- ProjectCruiser/Entities/EntityCruiser.cs | 4 ++-- ProjectCruiser/OceanForm1.cs | 2 +- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ProjectCruiser/DrawningSamples/DrawningCruiser.cs b/ProjectCruiser/DrawningSamples/DrawningCruiser.cs index 4f3f56e..8b1c8c7 100644 --- a/ProjectCruiser/DrawningSamples/DrawningCruiser.cs +++ b/ProjectCruiser/DrawningSamples/DrawningCruiser.cs @@ -6,17 +6,17 @@ public class DrawningCruiser : DrawningBase { // Инициализация свойств (все параметры класса (сущности)) public DrawningCruiser(int speed, double weight, Color bodyColor, - Color additionalColor, bool hangars) : base(302, 42) - // all additional featchures 'inside' object, so size remains + Color additionalColor, bool pad, bool hangars) : base(302, 42) { EntityTransport = new EntityCruiser(speed, weight, - bodyColor, additionalColor, hangars); + bodyColor, additionalColor, pad, hangars); } public override void DrawTransport(Graphics g) { - if (EntityTransport == null || EntityTransport is not EntityCruiser ship || - !_startPosX.HasValue || !_startPosY.HasValue) // [ !!! ] :O + if (EntityTransport == null || + EntityTransport is not EntityCruiser ship || + !_startPosX.HasValue || !_startPosY.HasValue) { return; } @@ -31,10 +31,12 @@ public class DrawningCruiser : DrawningBase base.DrawTransport(g); - // вертолетная площадка - default TRUE now - g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); - g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); - + // вертолетная площадка - non-default + if (ship.HelicopterPads) + { + g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); + g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); + } // ангар(ы) if (ship.Hangars) { diff --git a/ProjectCruiser/EditorForm3.cs b/ProjectCruiser/EditorForm3.cs index 949cbf5..269f27b 100644 --- a/ProjectCruiser/EditorForm3.cs +++ b/ProjectCruiser/EditorForm3.cs @@ -28,7 +28,6 @@ public partial class EditorForm3 : Form { if (shipDelegate == null) shipDelegate = del; else shipDelegate += del; - //shipDelegate += del; } private void DrawObject() @@ -69,9 +68,7 @@ public partial class EditorForm3 : Form case "AdvLabel": Random rn = new Random(); _cruiser = new DrawningCruiser((int)SpeedN.Value, (double)WeightN.Value, - Color.White, Color.Black,checkBoxHangars.Checked); - // ADD helicopter PAD as NOT DEFAULT - checkBoxPads.Checked [!] - // Convert.ToBoolean(rn.Next(0, 2))); + Color.White, Color.Black, checkBoxPads.Checked, checkBoxHangars.Checked); break; } labelMcolor.BackColor = Color.Empty; @@ -79,13 +76,12 @@ public partial class EditorForm3 : Form DrawObject(); } - // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + // Логика смены цветов: основного и дополнительного (для продвинутого объекта) private void BodyColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } - private void BodyColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser != null) @@ -103,7 +99,6 @@ public partial class EditorForm3 : Form else e.Effect = DragDropEffects.None; } } - private void AdditionalColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser.EntityTransport is EntityCruiser _ship) diff --git a/ProjectCruiser/Entities/EntityCruiser.cs b/ProjectCruiser/Entities/EntityCruiser.cs index af25267..e04588a 100644 --- a/ProjectCruiser/Entities/EntityCruiser.cs +++ b/ProjectCruiser/Entities/EntityCruiser.cs @@ -14,11 +14,11 @@ public class EntityCruiser : EntityBase public bool Hangars { get; private set; } // ангар public EntityCruiser(int speed, double weight, Color mainc, - Color additionalColor, bool hangars) + Color additionalColor, bool pad, bool hangars) : base(speed, weight, mainc) { AdditionalColor = additionalColor; - // HelicopterPads = pads; - default TRUE now for Advanced obj + HelicopterPads = pad; // non-default now for editor Form3 Hangars = hangars; } } diff --git a/ProjectCruiser/OceanForm1.cs b/ProjectCruiser/OceanForm1.cs index e8b217f..3c9e341 100644 --- a/ProjectCruiser/OceanForm1.cs +++ b/ProjectCruiser/OceanForm1.cs @@ -68,7 +68,7 @@ namespace ProjectCruiser random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2))); + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: -- 2.25.1