Изменения

This commit is contained in:
crum61kg 2023-01-23 03:05:28 +04:00
parent a51a6a2102
commit d9f1f47750
5 changed files with 90 additions and 34 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
@ -52,5 +53,15 @@ namespace WarmlyShip
}
}
public void SetDopColor(Color color)
{
Ship = Ship as EntityLiner;
if (Ship is not null)
{
Ship = new EntityLiner(Ship.Speed, Ship.Weight, Ship.BodyColor,
color, (Ship as EntityLiner).SwimmingPool, (Ship as EntityLiner).DopDeck);
}
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
@ -199,5 +200,20 @@ namespace WarmlyShip
{
return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
}
public virtual void SetBaseColor(Color color)
{
if (Ship is EntityLiner)
{
Ship = (EntityLiner)Ship;
if (Ship is not null)
{
Ship = new EntityLiner(Ship.Speed, Ship.Weight, color, (Ship as EntityLiner).DopColor, (Ship as EntityLiner).SwimmingPool, (Ship as EntityLiner).DopDeck);
return;
}
}
Ship = new EntityShip(Ship.Speed, Ship.Weight, color);
}
}
}

View File

@ -48,8 +48,8 @@
this.labelSpeed = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelObject = new System.Windows.Forms.Panel();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelBaseColor = new System.Windows.Forms.Label();
this.groupBoxConfig.SuspendLayout();
@ -252,8 +252,8 @@
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.button2);
this.panelObject.Controls.Add(this.button1);
this.panelObject.Controls.Add(this.buttonCancel);
this.panelObject.Controls.Add(this.buttonAdd);
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
@ -265,23 +265,24 @@
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
this.panelObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// button2
// buttonCancel
//
this.button2.Location = new System.Drawing.Point(112, 159);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 5;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
this.buttonCancel.Location = new System.Drawing.Point(112, 159);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// button1
// buttonAdd
//
this.button1.Location = new System.Drawing.Point(31, 159);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Добавить";
this.button1.UseVisualStyleBackColor = true;
this.buttonAdd.Location = new System.Drawing.Point(31, 159);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 4;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonOk_Click);
//
// labelDopColor
//
@ -293,6 +294,8 @@
this.labelDopColor.TabIndex = 3;
this.labelDopColor.Text = "Доп.цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// labelBaseColor
//
@ -304,6 +307,7 @@
this.labelBaseColor.TabIndex = 2;
this.labelBaseColor.Text = "Цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// FormLinerConfig
@ -350,7 +354,7 @@
private Panel panelObject;
private Label labelDopColor;
private Label labelBaseColor;
private Button button2;
private Button button1;
private Button buttonCancel;
private Button buttonAdd;
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -18,7 +19,7 @@ namespace WarmlyShip
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawningShip _ship = null;
DrawningShip _liner = null;
/// <summary>
/// Событие
/// </summary>
@ -38,8 +39,7 @@ namespace WarmlyShip
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Отрисовать машину
@ -48,8 +48,8 @@ namespace WarmlyShip
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_ship?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_ship?.DrawTransport(gr);
_liner?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_liner?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
@ -103,11 +103,11 @@ namespace WarmlyShip
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_ship = new DrawningShip((int)numericUpDownSpeed.Value,
_liner = new DrawningShip((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_ship = new DrawningLiner((int)numericUpDownSpeed.Value,
_liner = new DrawningLiner((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxSwimmingPool.Checked, checkBoxDopDeck.Checked);
break;
@ -147,7 +147,11 @@ namespace WarmlyShip
/// <param name="e"></param>
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
// TODO Call method from object _car and set color
if (_liner != null)
{
_liner.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
DrawLiner();
}
}
/// <summary>
/// Принимаем дополнительный цвет
@ -156,7 +160,13 @@ namespace WarmlyShip
/// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
// TODO Call method from object _car if _car is DrawningSportCar and set dop color
if (_liner is DrawningLiner)
{
var liner = _liner as DrawningLiner;
liner.SetDopColor((Color)e.Data.GetData(typeof(Color)));
}
DrawLiner();
}
/// <summary>
@ -166,7 +176,7 @@ namespace WarmlyShip
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddShip?.Invoke(_ship);
EventAddShip?.Invoke(_liner);
Close();
}

View File

@ -113,12 +113,27 @@ namespace WarmlyShip
/// <param name="e"></param>
private void ButtonAddShip_Click(object sender, EventArgs e)
{
var formCarConfig = new FormLinerConfig();
// TODO Call method AddEvent from formCarConfig
formCarConfig.Show();
var formLinerConfig = new FormLinerConfig();
formLinerConfig.AddEvent(new(AddShip));
formLinerConfig.Show();
}
private void AddShip(DrawningShip liner)
{
if (listBoxMaps.SelectedIndex == -1)
{
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
}
else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectShip(liner) != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Удаление объекта
/// </summary>