2024-06-15 09:53:32 +04:00
|
|
|
|
using ProjectCruiser.DrawningSamples;
|
|
|
|
|
using ProjectCruiser.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace ProjectCruiser;
|
|
|
|
|
public partial class EditorForm3 : Form
|
|
|
|
|
{
|
|
|
|
|
private DrawningBase _cruiser;
|
|
|
|
|
|
|
|
|
|
// private event Action<DrawingBase>? 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<DrawingBase> delegator)
|
|
|
|
|
{
|
|
|
|
|
if (shipDelegate == null) shipDelegate = del;
|
|
|
|
|
else 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":
|
2024-06-15 13:28:42 +04:00
|
|
|
|
EntityBase ship = new EntityBase((int)SpeedN.Value, (double)WeightN.Value, Color.White);
|
|
|
|
|
_cruiser = new DrawningBase(ship);
|
2024-06-15 09:53:32 +04:00
|
|
|
|
break;
|
|
|
|
|
case "AdvLabel":
|
|
|
|
|
Random rn = new Random();
|
2024-06-15 13:28:42 +04:00
|
|
|
|
EntityCruiser cruiser = new EntityCruiser((int)SpeedN.Value, (double)WeightN.Value,
|
2024-06-15 10:03:23 +04:00
|
|
|
|
Color.White, Color.Black, checkBoxPads.Checked, checkBoxHangars.Checked);
|
2024-06-15 13:28:42 +04:00
|
|
|
|
_cruiser = new DrawningCruiser(cruiser);
|
2024-06-15 09:53:32 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
labelMcolor.BackColor = Color.Empty;
|
|
|
|
|
labelAcolor.BackColor = Color.Empty;
|
|
|
|
|
DrawObject();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 10:03:23 +04:00
|
|
|
|
// Логика смены цветов: основного и дополнительного (для продвинутого объекта)
|
2024-06-15 09:53:32 +04:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|