This commit is contained in:
Максим Егоров 2024-05-05 22:45:24 +03:00
parent e0a52ea60c
commit 1d71499845
4 changed files with 205 additions and 168 deletions

View File

@ -28,142 +28,138 @@
/// </summary>
private void InitializeComponent()
{
pictureBoxCollection = new PictureBox();
panelTools = new Panel();
panelCollection = new Panel();
buttonDelObject = new Button();
listBoxStorages = new ListBox();
buttonAddObject = new Button();
textBoxStorageName = new TextBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonRefreshCollection = new Button();
buttonRemoveBoat = new Button();
buttonAddBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
panelTools.SuspendLayout();
panelCollection.SuspendLayout();
SuspendLayout();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.panelTools = new System.Windows.Forms.Panel();
this.panelCollection = new System.Windows.Forms.Panel();
this.buttonDelObject = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.buttonAddObject = new System.Windows.Forms.Button();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.buttonRefreshCollection = new System.Windows.Forms.Button();
this.buttonRemoveBoat = new System.Windows.Forms.Button();
this.buttonAddBoat = new System.Windows.Forms.Button();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.panelTools.SuspendLayout();
this.panelCollection.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(750, 600);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
pictureBoxCollection.Click += pictureBoxCollection_Click;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(750, 600);
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.TabStop = false;
//
// panelTools
//
panelTools.BackColor = SystemColors.ScrollBar;
panelTools.Controls.Add(panelCollection);
panelTools.Controls.Add(maskedTextBoxNumber);
panelTools.Controls.Add(buttonRefreshCollection);
panelTools.Controls.Add(buttonRemoveBoat);
panelTools.Controls.Add(buttonAddBoat);
panelTools.Location = new Point(639, 20);
panelTools.Margin = new Padding(3, 2, 3, 2);
panelTools.Name = "panelTools";
panelTools.Size = new Size(183, 441);
panelTools.TabIndex = 1;
panelTools.Paint += panelTools_Paint;
this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar;
this.panelTools.Controls.Add(this.panelCollection);
this.panelTools.Controls.Add(this.maskedTextBoxNumber);
this.panelTools.Controls.Add(this.buttonRefreshCollection);
this.panelTools.Controls.Add(this.buttonRemoveBoat);
this.panelTools.Controls.Add(this.buttonAddBoat);
this.panelTools.Controls.Add(this.menuStrip);
this.panelTools.Location = new System.Drawing.Point(756, 0);
this.panelTools.Name = "panelTools";
this.panelTools.Size = new System.Drawing.Size(209, 722);
this.panelTools.TabIndex = 1;
//
// panelCollection
//
panelCollection.BackColor = SystemColors.AppWorkspace;
panelCollection.Controls.Add(buttonDelObject);
panelCollection.Controls.Add(listBoxStorages);
panelCollection.Controls.Add(buttonAddObject);
panelCollection.Controls.Add(textBoxStorageName);
panelCollection.Location = new Point(14, 11);
panelCollection.Margin = new Padding(3, 2, 3, 2);
panelCollection.Name = "panelCollection";
panelCollection.Size = new Size(158, 215);
panelCollection.TabIndex = 4;
this.panelCollection.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panelCollection.Controls.Add(this.buttonDelObject);
this.panelCollection.Controls.Add(this.listBoxStorages);
this.panelCollection.Controls.Add(this.buttonAddObject);
this.panelCollection.Controls.Add(this.textBoxStorageName);
this.panelCollection.Location = new System.Drawing.Point(20, 166);
this.panelCollection.Name = "panelCollection";
this.panelCollection.Size = new System.Drawing.Size(181, 287);
this.panelCollection.TabIndex = 4;
//
// buttonDelObject
//
buttonDelObject.Location = new Point(10, 172);
buttonDelObject.Margin = new Padding(3, 2, 3, 2);
buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(135, 26);
buttonDelObject.TabIndex = 5;
buttonDelObject.Text = "Удалить набор";
buttonDelObject.UseVisualStyleBackColor = true;
buttonDelObject.Click += buttonDelObject_Click;
this.buttonDelObject.Location = new System.Drawing.Point(12, 230);
this.buttonDelObject.Name = "buttonDelObject";
this.buttonDelObject.Size = new System.Drawing.Size(154, 34);
this.buttonDelObject.TabIndex = 5;
this.buttonDelObject.Text = "Удалить набор";
this.buttonDelObject.UseVisualStyleBackColor = true;
this.buttonDelObject.Click += new System.EventHandler(this.buttonDelObject_Click);
//
// listBoxStorages
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 15;
listBoxStorages.Location = new Point(10, 76);
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(135, 79);
listBoxStorages.TabIndex = 6;
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 20;
this.listBoxStorages.Location = new System.Drawing.Point(12, 102);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(154, 104);
this.listBoxStorages.TabIndex = 6;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
//
// buttonAddObject
//
buttonAddObject.Location = new Point(10, 46);
buttonAddObject.Margin = new Padding(3, 2, 3, 2);
buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(135, 26);
buttonAddObject.TabIndex = 5;
buttonAddObject.Text = "Добавить набор";
buttonAddObject.UseVisualStyleBackColor = true;
buttonAddObject.Click += buttonAddObject_Click;
this.buttonAddObject.Location = new System.Drawing.Point(12, 62);
this.buttonAddObject.Name = "buttonAddObject";
this.buttonAddObject.Size = new System.Drawing.Size(154, 34);
this.buttonAddObject.TabIndex = 5;
this.buttonAddObject.Text = "Добавить набор";
this.buttonAddObject.UseVisualStyleBackColor = true;
this.buttonAddObject.Click += new System.EventHandler(this.buttonAddObject_Click);
//
// textBoxStorageName
//
textBoxStorageName.Location = new Point(25, 22);
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(110, 23);
textBoxStorageName.TabIndex = 0;
this.textBoxStorageName.Location = new System.Drawing.Point(29, 29);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(125, 27);
this.textBoxStorageName.TabIndex = 0;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(39, 312);
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(110, 23);
maskedTextBoxNumber.TabIndex = 3;
this.maskedTextBoxNumber.Location = new System.Drawing.Point(49, 567);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
this.maskedTextBoxNumber.TabIndex = 3;
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(14, 398);
buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(158, 26);
buttonRefreshCollection.TabIndex = 2;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
this.buttonRefreshCollection.Location = new System.Drawing.Point(20, 682);
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34);
this.buttonRefreshCollection.TabIndex = 2;
this.buttonRefreshCollection.Text = "Обновить коллекцию";
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click);
//
// buttonRemoveBoat
//
buttonRemoveBoat.Location = new Point(15, 352);
buttonRemoveBoat.Margin = new Padding(3, 2, 3, 2);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(158, 26);
buttonRemoveBoat.TabIndex = 1;
buttonRemoveBoat.Text = "Удалить лодку";
buttonRemoveBoat.UseVisualStyleBackColor = true;
buttonRemoveBoat.Click += buttonRemoveBoat_Click;
this.buttonRemoveBoat.Location = new System.Drawing.Point(21, 620);
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34);
this.buttonRemoveBoat.TabIndex = 1;
this.buttonRemoveBoat.Text = "Удалить лодку";
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
//
// buttonAddBoat
//
buttonAddBoat.Location = new Point(14, 254);
buttonAddBoat.Margin = new Padding(3, 2, 3, 2);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(158, 26);
buttonAddBoat.TabIndex = 0;
buttonAddBoat.Text = "Добавить лодку";
buttonAddBoat.UseVisualStyleBackColor = true;
buttonAddBoat.Click += buttonAddBoat_Click;
this.buttonAddBoat.Location = new System.Drawing.Point(20, 490);
this.buttonAddBoat.Name = "buttonAddBoat";
this.buttonAddBoat.Size = new System.Drawing.Size(180, 34);
this.buttonAddBoat.TabIndex = 0;
this.buttonAddBoat.Text = "Добавить лодку";
this.buttonAddBoat.UseVisualStyleBackColor = true;
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click);
//
// menuStrip
//
@ -215,21 +211,24 @@
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(834, 546);
Controls.Add(panelTools);
Controls.Add(pictureBoxCollection);
Margin = new Padding(3, 2, 3, 2);
Name = "FormBoatCollection";
Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
panelTools.ResumeLayout(false);
panelTools.PerformLayout();
panelCollection.ResumeLayout(false);
panelCollection.PerformLayout();
ResumeLayout(false);
PerformLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(969, 728);
this.Controls.Add(this.panelTools);
this.Controls.Add(this.pictureBoxCollection);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormBoatCollection";
this.Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.panelTools.ResumeLayout(false);
this.panelTools.PerformLayout();
this.panelCollection.ResumeLayout(false);
this.panelCollection.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
@ -252,7 +251,5 @@
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private EventHandler SaveToolStripMenuItem_Click;
private EventHandler LoadToolStripMenuItem_Click;
}
}

View File

@ -48,6 +48,23 @@ namespace Sailboat
}
private void buttonAddBoat_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(AddBoat);
formBoatConfig.Show();
}
private void AddBoat(DrawingBoat drawingBoat)
{
if (listBoxStorages.SelectedIndex == -1)
{
@ -59,21 +76,16 @@ namespace Sailboat
{
return;
}
FormBoatConfig form = new FormBoatConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
form.Show();
Action<DrawingBoat>? boatDelegate = new((plane) =>
if (obj + drawingBoat)
{
if (obj + plane)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
});
form.AddEvent(boatDelegate);
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)
@ -146,7 +158,7 @@ namespace Sailboat
{
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);
@ -154,14 +166,40 @@ namespace Sailboat
}
}
private void panelTools_Paint(object sender, PaintEventArgs e)
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void pictureBoxCollection_Click(object sender, EventArgs e)
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
ReloadObjects();
}
}
}

View File

@ -176,7 +176,7 @@
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
@ -187,7 +187,7 @@
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// checkBoxSail
//
@ -326,7 +326,7 @@
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//

View File

@ -1,6 +1,4 @@
using Sailboat.DrawingObjects;
using Sailboat.Entities;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -10,18 +8,19 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sailboat.DrawingObjects;
using Sailboat.Generics;
using Sailboat.MovementStrategy;
using Sailboat.Entities;
namespace Sailboat
{
public partial class FormBoatConfig : Form
{
DrawingBoat? _boat = null;
private event Action<DrawingBoat>? EventAddBoat;
public int _pictureWidth { get; private set; }
public int _pictureHeight { get; private set; }
public FormBoatConfig(int pictureWidth, int pictureHeight)
private event Action <DrawingBoat>? EventAddBoat;
public FormBoatConfig()
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
@ -54,21 +53,18 @@ namespace Sailboat
EventAddBoat += ev;
}
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LableObject_MouseDown(object sender, MouseEventArgs e)
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;
@ -85,29 +81,34 @@ namespace Sailboat
{
case "labelSimpleObject":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
checkBoxSail.Checked, _pictureWidth, _pictureHeight);
checkBoxSail.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawBoat();
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat?.EntityBoat == null)
if (_boat == null)
return;
Color bodyColor = (Color)e.Data.GetData(typeof(Color));
_boat.EntityBoat.ChangeColor(bodyColor);
DrawBoat();
}
private void addColorLabel_DragDrop(object sender, DragEventArgs e)
{
if ((_boat?.EntityBoat == null) || (_boat is DrawingSailboat == false))
return;
((EntitySailboat)_boat.EntityBoat).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
switch (((Label)sender).Name)
{
case "labelColor":
_boat.EntityBoat.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAddColor":
if (!(_boat is DrawingSailboat))
return;
(_boat.EntityBoat as EntitySailboat).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawBoat();
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
@ -121,7 +122,8 @@ namespace Sailboat
e.Effect = DragDropEffects.None;
}
}
private void buttonOk_Click(object sender, EventArgs e)
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
Close();