Add quick sector/linedef tag increment/decrement actions

This commit is contained in:
spherallic 2022-12-21 02:21:30 +01:00
parent b45861bb39
commit dbdb8bc931
4 changed files with 179 additions and 8 deletions

View file

@ -82,6 +82,27 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Methods #region ================== Methods
public int CreateSelectionCRC()
{
CRC crc = new CRC();
ICollection<Linedef> orderedselection = General.Map.Map.GetSelectedLinedefs(true);
crc.Add(orderedselection.Count);
foreach (Linedef l in orderedselection)
{
crc.Add(l.Index);
}
return (int)(crc.Value & 0xFFFFFFFF);
}
//mxd. This makes a CRC for given selection
private static int CreateSelectionCRC(ICollection<Linedef> selection)
{
CRC crc = new CRC();
crc.Add(selection.Count);
foreach (Linedef l in selection) crc.Add(l.Index);
return (int)(crc.Value & 0xFFFFFFFF);
}
// This highlights a new item // This highlights a new item
private void Highlight(Linedef l) private void Highlight(Linedef l)
{ {
@ -1932,6 +1953,68 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!"); General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!");
} }
[BeginAction("incrementtag")]
public void IncrementTag()
{
// Get selection
ICollection<Linedef> selected = General.Map.Map.GetSelectedLinedefs(true);
if (selected.Count == 0 && highlighted != null && !highlighted.IsDisposed)
selected.Add(highlighted);
if (selected.Count == 0)
{
General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!");
return;
}
General.Map.UndoRedo.CreateUndo("Decrement linedef tags by 1", this, UndoGroup.LinedefTagChange, CreateSelectionCRC(selected));
General.Interface.DisplayStatus(StatusType.Action, "Incremented tag" + (selected.Count > 1 ? "s of" : " of") + selected.Count + (selected.Count > 1 ? " linedefs by 1." : " linedef by 1."));
foreach (Linedef l in selected)
{
l.Tag = Math.Min(l.Tag + 1, 65535);
l.UpdateCache();
}
// Update
General.Interface.RefreshInfo();
General.Map.IsChanged = true;
// Redraw
General.Interface.RedrawDisplay();
}
[BeginAction("decrementtag")]
public void DecrementTag()
{
// Get selection
ICollection<Linedef> selected = General.Map.Map.GetSelectedLinedefs(true);
if (selected.Count == 0 && highlighted != null && !highlighted.IsDisposed)
selected.Add(highlighted);
if (selected.Count == 0)
{
General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!");
return;
}
General.Map.UndoRedo.CreateUndo("Decrement linedef tags by 1", this, UndoGroup.LinedefTagChange, CreateSelectionCRC(selected));
General.Interface.DisplayStatus(StatusType.Action, "Decremented tag" + (selected.Count > 1 ? "s of" : " of") + selected.Count + (selected.Count > 1 ? " linedefs by 1." : " linedef by 1."));
foreach (Linedef l in selected)
{
l.Tag = Math.Max(l.Tag - 1, 0);
l.UpdateCache();
}
// Update
General.Interface.RefreshInfo();
General.Map.IsChanged = true;
// Redraw
General.Interface.RedrawDisplay();
}
#endregion #endregion
} }
} }

View file

@ -2377,6 +2377,70 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }
[BeginAction("incrementtag")]
public void IncrementTag()
{
// Get selection
ICollection<Sector> selected = General.Map.Map.GetSelectedSectors(true);
if (selected.Count == 0 && highlighted != null && !highlighted.IsDisposed)
selected.Add(highlighted);
if (selected.Count == 0)
{
General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!");
return;
}
General.Map.UndoRedo.CreateUndo("Decrement sector tags by 1", this, UndoGroup.SectorTagChange, CreateSelectionCRC(selected));
General.Interface.DisplayStatus(StatusType.Action, "Incremented tag" + (selected.Count > 1 ? "s of" : " of") + selected.Count + (selected.Count > 1 ? " sectors by 1." : " sector by 1."));
foreach (Sector s in selected)
{
s.Tag = Math.Min(s.Tag + 1, 65535);
s.UpdateNeeded = true;
s.UpdateCache();
}
// Update
General.Interface.RefreshInfo();
General.Map.IsChanged = true;
// Redraw
General.Interface.RedrawDisplay();
}
[BeginAction("decrementtag")]
public void DecrementTag()
{
// Get selection
ICollection<Sector> selected = General.Map.Map.GetSelectedSectors(true);
if (selected.Count == 0 && highlighted != null && !highlighted.IsDisposed)
selected.Add(highlighted);
if (selected.Count == 0)
{
General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!");
return;
}
General.Map.UndoRedo.CreateUndo("Decrement sector tags by 1", this, UndoGroup.SectorTagChange, CreateSelectionCRC(selected));
General.Interface.DisplayStatus(StatusType.Action, "Decremented tag" + (selected.Count > 1 ? "s of" : " of") + selected.Count + (selected.Count > 1 ? " sectors by 1." : " sector by 1."));
foreach (Sector s in selected)
{
s.Tag = Math.Max(s.Tag - 1, 0);
s.UpdateNeeded = true;
s.UpdateCache();
}
// Update
General.Interface.RefreshInfo();
General.Map.IsChanged = true;
// Redraw
General.Interface.RedrawDisplay();
}
// This clears the selection // This clears the selection
[BeginAction("clearselection", BaseAction = true)] [BeginAction("clearselection", BaseAction = true)]
public void ClearSelection() public void ClearSelection()

View file

@ -35,5 +35,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
public const int ThingAngleChange = 10; //mxd public const int ThingAngleChange = 10; //mxd
public const int ThingPitchChange = 11; //mxd public const int ThingPitchChange = 11; //mxd
public const int ThingRollChange = 12; //mxd public const int ThingRollChange = 12; //mxd
public const int SectorTagChange = 13;
public const int LinedefTagChange = 14;
} }
} }

View file

@ -763,6 +763,28 @@ raisesectorgridsize
repeat = true; repeat = true;
} }
incrementtag
{
title = "Increment tag of sector/linedef";
category = "classic";
description = "Increments the tag of all selected sectors or linedefs by 1.";
allowkeys = true;
allowmouse = true;
allowscroll = true;
repeat = true;
}
decrementtag
{
title = "Increment tag of sector/linedef";
category = "classic";
description = "Increments the tag of all selected sectors or linedefs by 1.";
allowkeys = true;
allowmouse = true;
allowscroll = true;
repeat = true;
}
//mxd //mxd
lowersectortonearest lowersectortonearest
{ {