Смена делегатов на встроенные, кнопка отмены, работа с цветами и привязка к форме

This commit is contained in:
ityurner02@mail.ru 2022-10-29 20:36:09 +04:00
parent e853de9b51
commit a099ea6fd6
6 changed files with 45 additions and 27 deletions

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
/// <summary>
/// Делегат для передачи объекта-орудия
/// </summary>
/// <param name="antiAircraftGun"></param>
public delegate void AntiAircraftGunDelegate(DrawingAntiAircraftGun antiAircraftGun);
}

View File

@ -19,7 +19,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Цвет зенитнго орудия /// Цвет зенитнго орудия
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
/// <summary> /// <summary>
/// Шаг перемещения зенитного орудия /// Шаг перемещения зенитного орудия
/// </summary> /// </summary>

View File

@ -11,7 +11,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Дополнительный цвет /// Дополнительный цвет
/// </summary> /// </summary>
public Color DopColor { get; private set; } public Color DopColor { get; set; }
/// <summary> /// <summary>
/// Признак наличия башни с орудием /// Признак наличия башни с орудием
/// </summary> /// </summary>

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
namespace AntiAircraftGun namespace AntiAircraftGun
{ {
@ -19,7 +20,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Событие /// Событие
/// </summary> /// </summary>
private event AntiAircraftGunDelegate EventAddAntiAircraftGun; private event Action<DrawingAntiAircraftGun> EventAddAntiAircraftGun;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -34,12 +35,12 @@ namespace AntiAircraftGun
panelWhite.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda buttonCancel.Click += (sender, e) => { Close(); };
} }
/// <summary> /// <summary>
/// Отрисовать орудие /// Отрисовать орудие
/// </summary> /// </summary>
private void DrawCar() private void DrawAntiAircraftGun()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
@ -51,11 +52,11 @@ namespace AntiAircraftGun
/// Добавление события /// Добавление события
/// </summary> /// </summary>
/// <param name="ev"></param> /// <param name="ev"></param>
public void AddEvent(AntiAircraftGunDelegate ev) public void AddEvent(Action<DrawingAntiAircraftGun> ev)
{ {
if (EventAddAntiAircraftGun == null) if (EventAddAntiAircraftGun == null)
{ {
EventAddAntiAircraftGun = new AntiAircraftGunDelegate(ev); EventAddAntiAircraftGun = ev;
} }
else else
{ {
@ -105,7 +106,7 @@ namespace AntiAircraftGun
checkBoxGun.Checked, checkBoxRadar.Checked); checkBoxGun.Checked, checkBoxRadar.Checked);
break; break;
} }
DrawCar(); DrawAntiAircraftGun();
} }
/// <summary> /// <summary>
/// Отправляем цвет с панели /// Отправляем цвет с панели
@ -132,14 +133,19 @@ namespace AntiAircraftGun
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
/// <summary> /// <summary>labelModifiedObject
/// Принимаем основной цвет /// Принимаем основной цвет
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void LableBaseColor_DragDrop(object sender, DragEventArgs e) private void LableBaseColor_DragDrop(object sender, DragEventArgs e)
{ {
// TODO Call method from object _antiAircraftGun and set color if (_antiAircraftGun == null || !e.Data.GetDataPresent(typeof(Color)))
{
return;
}
_antiAircraftGun.AntiAircraftGun.BodyColor = (Color)e.Data.GetData(typeof(Color));
DrawAntiAircraftGun();
} }
/// <summary> /// <summary>
/// Принимаем дополнительный цвет /// Принимаем дополнительный цвет
@ -148,7 +154,15 @@ namespace AntiAircraftGun
/// <param name="e"></param> /// <param name="e"></param>
private void LableDopColor_DragDrop(object sender, DragEventArgs e) private void LableDopColor_DragDrop(object sender, DragEventArgs e)
{ {
// TODO Call method from object _car if _antiAircraftGun is DrawningSportCar and set dop color if (_antiAircraftGun == null || _antiAircraftGun.GetType() != typeof(DrawingUpdateAntiAircraftGun) || !e.Data.GetDataPresent(typeof(Color)))
{
return;
}
if (_antiAircraftGun.AntiAircraftGun is EntityUpdateAntiAircraftGun upGun)
{
upGun.DopColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAntiAircraftGun();
} }
/// <summary> /// <summary>
/// Добавление орудия /// Добавление орудия

View File

@ -188,6 +188,7 @@
// //
// groupBoxMaps // groupBoxMaps
// //
this.groupBoxMaps.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxMaps.Controls.Add(this.listBoxMaps); this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap);
@ -195,7 +196,7 @@
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(580, 26); this.groupBoxMaps.Location = new System.Drawing.Point(580, 26);
this.groupBoxMaps.Name = "groupBoxMaps"; this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(226, 277); this.groupBoxMaps.Size = new System.Drawing.Size(220, 277);
this.groupBoxMaps.TabIndex = 17; this.groupBoxMaps.TabIndex = 17;
this.groupBoxMaps.TabStop = false; this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты"; this.groupBoxMaps.Text = "Карты";

View File

@ -110,9 +110,26 @@ namespace AntiAircraftGun
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
{ {
var formAntiAircraftGunConfig = new FormAntiAircraftGunConfig(); var formAntiAircraftGunConfig = new FormAntiAircraftGunConfig();
// TODO Call method AddEvent from formAntiAircraftGunConfig formAntiAircraftGunConfig.AddEvent(AddAntiAircraftGun);
formAntiAircraftGunConfig.Show(); formAntiAircraftGunConfig.Show();
} }
private void AddAntiAircraftGun(DrawingAntiAircraftGun drawingAntiAircraftGuns)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawingObjectAntiAircraftGun antiAircraftGun = new DrawingObjectAntiAircraftGun(drawingAntiAircraftGuns);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun != -1)
{
MessageBox.Show("Object added");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Cant add object");
}
}
/// <summary> /// <summary>
/// Удаление объекта /// Удаление объекта
/// </summary> /// </summary>