140 lines
4.7 KiB
C#
140 lines
4.7 KiB
C#
|
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 ContainerShip.DrawningObjects;
|
|||
|
using ContainerShip.Entities;
|
|||
|
|
|||
|
namespace ContainerShip
|
|||
|
{
|
|||
|
public partial class FormShipConfig : Form
|
|||
|
{
|
|||
|
DrawningShip? _ship = null;
|
|||
|
private event Action<DrawningShip>? EventAddShip;
|
|||
|
public FormShipConfig()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
panelFirebrick.MouseDown += PanelColor_MouseDown;
|
|||
|
panelRoyalBlue.MouseDown += PanelColor_MouseDown;
|
|||
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
|||
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
|||
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
|||
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
|||
|
panelPink.MouseDown += PanelColor_MouseDown;
|
|||
|
panelGray.MouseDown += PanelColor_MouseDown;
|
|||
|
buttonCancel.Click += (s, e) => Close();
|
|||
|
}
|
|||
|
private void DrawShip()
|
|||
|
{
|
|||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_ship?.SetPosition(5, 5);
|
|||
|
_ship?.DrawTransport(gr);
|
|||
|
pictureBoxObject.Image = bmp;
|
|||
|
}
|
|||
|
public void AddEvent(Action<DrawningShip> ev)
|
|||
|
{
|
|||
|
if (EventAddShip == null)
|
|||
|
{
|
|||
|
EventAddShip = ev;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
EventAddShip += ev;
|
|||
|
}
|
|||
|
}
|
|||
|
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 "labelSimpleObject":
|
|||
|
_ship = new DrawningShip(
|
|||
|
(int)numericUpDownSpeed.Value,
|
|||
|
(int)numericUpDownWeight.Value,
|
|||
|
Color.White,
|
|||
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
break;
|
|||
|
|
|||
|
case "labelAdvancedObject":
|
|||
|
_ship = new DrawingContainerShip(
|
|||
|
(int)numericUpDownSpeed.Value,
|
|||
|
(int)numericUpDownWeight.Value,
|
|||
|
Color.White, Color.Black,
|
|||
|
checkBoxLoad.Checked, checkBoxCrane.Checked,
|
|||
|
pictureBoxObject.Width, pictureBoxObject.Height);
|
|||
|
break;
|
|||
|
}
|
|||
|
DrawShip();
|
|||
|
}
|
|||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
|||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|||
|
}
|
|||
|
private void LabelMainColor_DragEnter(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
if (e.Data.GetDataPresent(typeof(Color)) && _ship != null)
|
|||
|
{
|
|||
|
e.Effect = DragDropEffects.Copy;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
e.Effect = DragDropEffects.None;
|
|||
|
}
|
|||
|
}
|
|||
|
private void LabelMainColor_DragDrop(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
var color = (Color)e.Data.GetData(typeof(Color));
|
|||
|
_ship.EntityShip.ChangeBodyColor(color);
|
|||
|
DrawShip();
|
|||
|
}
|
|||
|
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 LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
|||
|
{
|
|||
|
Color addColor = (Color)e.Data?.GetData(typeof(Color));
|
|||
|
if (_ship is DrawingContainerShip)
|
|||
|
{
|
|||
|
EntityContainerShip _containerShip = _ship.EntityShip as EntityContainerShip;
|
|||
|
_containerShip.ChangeAdditionalColor(addColor);
|
|||
|
}
|
|||
|
DrawShip();
|
|||
|
}
|
|||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
EventAddShip?.Invoke(_ship);
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|