Refactor the code that open edit forms, to make it easier to add different forms in the future

This commit is contained in:
MascaraSnake 2022-12-28 13:10:04 +01:00
parent 5ed59088fc
commit 51d56016f3
12 changed files with 169 additions and 136 deletions

View file

@ -274,6 +274,9 @@
<Compile Include="Rendering\VertexBuffer.cs" />
<Compile Include="Rendering\VisualSlopeHandle.cs" />
<Compile Include="VisualModes\VisualSlope.cs" />
<Compile Include="Windows\ILinedefEditForm.cs" />
<Compile Include="Windows\ISectorEditForm.cs" />
<Compile Include="Windows\IThingEditForm.cs" />
<Compile Include="Windows\PreAndPostCommandsForm.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -266,6 +266,9 @@
<Compile Include="Rendering\VertexBuffer.cs" />
<Compile Include="Rendering\VisualSlopeHandle.cs" />
<Compile Include="VisualModes\VisualSlope.cs" />
<Compile Include="Windows\ILinedefEditForm.cs" />
<Compile Include="Windows\ISectorEditForm.cs" />
<Compile Include="Windows\IThingEditForm.cs" />
<Compile Include="Windows\PreAndPostCommandsForm.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -0,0 +1,23 @@
#region ================== Namespaces
using CodeImp.DoomBuilder.Map;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
#endregion
namespace CodeImp.DoomBuilder.Windows
{
public interface ILinedefEditForm
{
//Events
event EventHandler OnValuesChanged;
event EventHandler Closed;
// Methods
void Setup(ICollection<Linedef> lines, bool selectfront, bool selectback);
DialogResult ShowDialog(IWin32Window owner);
void Dispose();
}
}

View file

@ -0,0 +1,23 @@
#region ================== Namespaces
using CodeImp.DoomBuilder.Map;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
#endregion
namespace CodeImp.DoomBuilder.Windows
{
public interface ISectorEditForm
{
//Events
event EventHandler OnValuesChanged;
event EventHandler Closed;
// Methods
void Setup(ICollection<Sector> sectors);
DialogResult ShowDialog(IWin32Window owner);
void Dispose();
}
}

View file

@ -0,0 +1,23 @@
#region ================== Namespaces
using CodeImp.DoomBuilder.Map;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
#endregion
namespace CodeImp.DoomBuilder.Windows
{
public interface IThingEditForm
{
//Events
event EventHandler OnValuesChanged;
event EventHandler Closed;
// Methods
void Setup(ICollection<Thing> things);
DialogResult ShowDialog(IWin32Window owner);
void Dispose();
}
}

View file

@ -28,7 +28,7 @@ using CodeImp.DoomBuilder.Types;
namespace CodeImp.DoomBuilder.Windows
{
internal partial class LinedefEditForm : DelayedForm
internal partial class LinedefEditForm : DelayedForm, ILinedefEditForm
{
#region ================== Events
@ -149,7 +149,7 @@ namespace CodeImp.DoomBuilder.Windows
#region ================== Methods
// This sets up the form to edit the given lines
public void Setup(ICollection<Linedef> lines)
public void Setup(ICollection<Linedef> lines, bool selectfront, bool selectback)
{
preventchanges = true;
oldmapischanged = General.Map.IsChanged;

View file

@ -29,7 +29,7 @@ using CodeImp.DoomBuilder.Types;
namespace CodeImp.DoomBuilder.Windows
{
internal partial class LinedefEditFormUDMF : DelayedForm
internal partial class LinedefEditFormUDMF : DelayedForm, ILinedefEditForm
{
#region ================== Events

View file

@ -4144,12 +4144,8 @@ namespace CodeImp.DoomBuilder.Windows
// This shows the dialog to edit lines
public DialogResult ShowEditLinedefs(ICollection<Linedef> lines, bool selectfront, bool selectback)
{
DialogResult result;
// Show line edit dialog
if(General.Map.UDMF) //mxd
{
LinedefEditFormUDMF f = new LinedefEditFormUDMF(selectfront, selectback);
ILinedefEditForm f = GetLinedefEditForm(selectfront, selectback);
DisableProcessing(); //mxd
#if NO_WIN32
BreakExclusiveMouseInput();
@ -4164,44 +4160,30 @@ namespace CodeImp.DoomBuilder.Windows
#endif
f.OnValuesChanged += EditForm_OnValuesChanged;
editformopen = true; //mxd
result = f.ShowDialog(this);
DialogResult result = f.ShowDialog(this);
editformopen = false; //mxd
f.Dispose();
return result;
}
private ILinedefEditForm GetLinedefEditForm(bool selectfront, bool selectback)
{
if (General.Map.UDMF)
{
return new LinedefEditFormUDMF(selectfront, selectback);
}
else
{
LinedefEditForm f = new LinedefEditForm();
DisableProcessing(); //mxd
#if NO_WIN32
BreakExclusiveMouseInput();
f.Closed += (object sender, EventArgs e) => {
ResumeExclusiveMouseInput();
EnableProcessing(); //mxd
};
#endif
f.Setup(lines);
#if !NO_WIN32
EnableProcessing();
#endif
f.OnValuesChanged += EditForm_OnValuesChanged;
editformopen = true; //mxd
result = f.ShowDialog(this);
editformopen = false; //mxd
f.Dispose();
return new LinedefEditForm();
}
return result;
}
// This shows the dialog to edit sectors
public DialogResult ShowEditSectors(ICollection<Sector> sectors)
{
DialogResult result;
// Show sector edit dialog
if(General.Map.UDMF) //mxd
{
SectorEditFormUDMF f = new SectorEditFormUDMF();
ISectorEditForm f = GetSectorEditForm();
DisableProcessing(); //mxd
#if NO_WIN32
BreakExclusiveMouseInput();
@ -4216,44 +4198,30 @@ namespace CodeImp.DoomBuilder.Windows
#endif
f.OnValuesChanged += EditForm_OnValuesChanged;
editformopen = true; //mxd
result = f.ShowDialog(this);
DialogResult result = f.ShowDialog(this);
editformopen = false; //mxd
f.Dispose();
return result;
}
private ISectorEditForm GetSectorEditForm()
{
if (General.Map.UDMF)
{
return new SectorEditFormUDMF();
}
else
{
SectorEditForm f = new SectorEditForm();
DisableProcessing(); //mxd
#if NO_WIN32
BreakExclusiveMouseInput();
f.Closed += (object sender, EventArgs e) => {
ResumeExclusiveMouseInput();
EnableProcessing(); //mxd
};
#endif
f.Setup(sectors);
#if !NO_WIN32
EnableProcessing(); //mxd
#endif
f.OnValuesChanged += EditForm_OnValuesChanged;
editformopen = true; //mxd
result = f.ShowDialog(this);
editformopen = false; //mxd
f.Dispose();
return new SectorEditForm();
}
return result;
}
// This shows the dialog to edit things
public DialogResult ShowEditThings(ICollection<Thing> things)
{
DialogResult result;
// Show thing edit dialog
if(General.Map.UDMF)
{
ThingEditFormUDMF f = new ThingEditFormUDMF();
IThingEditForm f = GetThingEditForm();
DisableProcessing(); //mxd
#if NO_WIN32
BreakExclusiveMouseInput();
@ -4268,33 +4236,23 @@ namespace CodeImp.DoomBuilder.Windows
#endif
f.OnValuesChanged += EditForm_OnValuesChanged;
editformopen = true; //mxd
result = f.ShowDialog(this);
DialogResult result = f.ShowDialog(this);
editformopen = false; //mxd
f.Dispose();
return result;
}
private IThingEditForm GetThingEditForm()
{
if (General.Map.UDMF)
{
return new ThingEditFormUDMF();
}
else
{
ThingEditForm f = new ThingEditForm();
DisableProcessing(); //mxd
#if NO_WIN32
BreakExclusiveMouseInput();
f.Closed += (object sender, EventArgs e) => {
ResumeExclusiveMouseInput();
EnableProcessing(); //mxd
};
#endif
f.Setup(things);
#if !NO_WIN32
EnableProcessing(); //mxd
#endif
f.OnValuesChanged += EditForm_OnValuesChanged;
editformopen = true; //mxd
result = f.ShowDialog(this);
editformopen = false; //mxd
f.Dispose();
return new ThingEditForm();
}
return result;
}
//mxd

View file

@ -27,7 +27,7 @@ using CodeImp.DoomBuilder.Types;
namespace CodeImp.DoomBuilder.Windows
{
internal partial class SectorEditForm : DelayedForm
internal partial class SectorEditForm : DelayedForm, ISectorEditForm
{
#region ================== Events

View file

@ -13,7 +13,7 @@ using CodeImp.DoomBuilder.Types;
namespace CodeImp.DoomBuilder.Windows
{
internal partial class SectorEditFormUDMF : DelayedForm
internal partial class SectorEditFormUDMF : DelayedForm, ISectorEditForm
{
#region ================== Events

View file

@ -33,7 +33,7 @@ namespace CodeImp.DoomBuilder.Windows
/// <summary>
/// Dialog window that allows viewing and editing of Thing properties.
/// </summary>
internal partial class ThingEditForm : DelayedForm
internal partial class ThingEditForm : DelayedForm, IThingEditForm
{
#region ================== Events

View file

@ -33,7 +33,7 @@ namespace CodeImp.DoomBuilder.Windows
/// <summary>
/// Dialog window that allows viewing and editing of Thing properties.
/// </summary>
internal partial class ThingEditFormUDMF : DelayedForm
internal partial class ThingEditFormUDMF : DelayedForm, IThingEditForm
{
#region ================== Events