diff --git a/Source/Plugins/BuilderModes/BuilderModes.csproj b/Source/Plugins/BuilderModes/BuilderModes.csproj index f8e90489dffbeb1d796d88fd29969a035b0a17c8..d4a67a16b577c1b963f28bf1ef7d5cf3f4bc33a3 100755 --- a/Source/Plugins/BuilderModes/BuilderModes.csproj +++ b/Source/Plugins/BuilderModes/BuilderModes.csproj @@ -124,6 +124,7 @@ <Compile Include="ClassicModes\FindReplaceMode.cs" /> <Compile Include="ClassicModes\MakeSectorMode.cs" /> <Compile Include="ErrorChecks\CheckClosedSectors.cs" /> + <Compile Include="ErrorChecks\CheckMissingActivations.cs" /> <Compile Include="ErrorChecks\CheckOffGridVertices.cs" /> <Compile Include="ErrorChecks\CheckStuckThings.cs" /> <Compile Include="ErrorChecks\CheckLineReferences.cs" /> @@ -133,6 +134,7 @@ <Compile Include="ErrorChecks\ResultLineNotDoubleSided.cs" /> <Compile Include="ErrorChecks\ResultLineMissingFront.cs" /> <Compile Include="ErrorChecks\ResultLineMissingSides.cs" /> + <Compile Include="ErrorChecks\ResultMissingActivation.cs" /> <Compile Include="ErrorChecks\ResultOffGridVertex.cs" /> <Compile Include="ErrorChecks\ResultSectorUnclosed.cs" /> <Compile Include="ErrorChecks\ResultStuckThingInLine.cs" /> diff --git a/Source/Plugins/BuilderModes/ErrorChecks/CheckMissingActivations.cs b/Source/Plugins/BuilderModes/ErrorChecks/CheckMissingActivations.cs new file mode 100644 index 0000000000000000000000000000000000000000..70630a58ea2cf393d57d54f2083c8c7dd402036e --- /dev/null +++ b/Source/Plugins/BuilderModes/ErrorChecks/CheckMissingActivations.cs @@ -0,0 +1,71 @@ +using CodeImp.DoomBuilder.Config; +using CodeImp.DoomBuilder.Map; +using System.Collections.Generic; +using System.Threading; + +namespace CodeImp.DoomBuilder.BuilderModes +{ + [ErrorChecker("Check missing activations", true, 50)] + public class CheckMissingActivations : ErrorChecker + { + private const int PROGRESS_STEP = 1000; + + // Constructor + public CheckMissingActivations() + { + // Total progress is done when all linedefs are checked + SetTotalProgress(General.Map.Map.Linedefs.Count / PROGRESS_STEP); + } + + public override bool SkipCheck { get { return !General.Map.UDMF; } } + + // This runs the check + public override void Run() + { + int progress = 0; + int stepprogress = 0; + + //If this map isn't a UDMF then we can't reach a situation where activations are missing + if (!General.Map.UDMF) + { + return; + } + + // Go for all vertices + foreach (Linedef l in General.Map.Map.Linedefs) + { + int action = l.Action; + Dictionary<string, bool> flags = l.GetFlags(); + bool hasActivation = false; + if (action != 0 + && General.Map.Config.LinedefActions.ContainsKey(action) + && General.Map.Config.LinedefActions[action].RequiresActivation) + { + foreach (LinedefActivateInfo ai in General.Map.Config.LinedefActivates) + { + if (flags.ContainsKey(ai.Key) && flags[ai.Key] == true) + { + hasActivation = true; + break; + } + } + + if (!hasActivation) + { + SubmitResult(new ResultMissingActivation(l)); + } + } + + // Handle thread interruption + try { Thread.Sleep(0); } catch (ThreadInterruptedException) { return; } + + // We are making progress! + if ((++progress / PROGRESS_STEP) > stepprogress) + { + stepprogress = (progress / PROGRESS_STEP); + AddProgress(1); + } + } + } + } +} diff --git a/Source/Plugins/BuilderModes/ErrorChecks/ResultMissingActivation.cs b/Source/Plugins/BuilderModes/ErrorChecks/ResultMissingActivation.cs new file mode 100644 index 0000000000000000000000000000000000000000..15d09cf7b6fa7e09cd99955f4076ad81cc3b5dd5 --- /dev/null +++ b/Source/Plugins/BuilderModes/ErrorChecks/ResultMissingActivation.cs @@ -0,0 +1,104 @@ + +#region ================== Copyright (c) 2007 Pascal vd Heiden + +/* + * Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com + * This program is released under GNU General Public License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#endregion + +#region ================== Namespaces + +using System; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; +using System.Windows.Forms; +using System.Collections.Generic; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + public class ResultMissingActivation : ErrorResult + { + #region ================== Variables + + private readonly Linedef line; + + #endregion + + #region ================== Properties + + public override int Buttons { get { return 1; } } + public override string Button1Text { get { return "Edit Linedef"; } } + + #endregion + + #region ================== Constructor / Destructor + + // Constructor + public ResultMissingActivation(Linedef l) + { + // Initialize + this.line = l; + this.viewobjects.Add(l); + this.hidden = l.IgnoredErrorChecks.Contains(this.GetType()); + this.description = "This linedef has an assigned action, but no way to activate it has been set."; + } + + #endregion + + #region ================== Methods + + // This sets if this result is displayed in ErrorCheckForm (mxd) + internal override void Hide(bool hide) + { + hidden = hide; + Type t = this.GetType(); + if (hide) + { + line.IgnoredErrorChecks.Add(t); + } + else if (line.IgnoredErrorChecks.Contains(t)) + { + line.IgnoredErrorChecks.Remove(t); + } + } + + // This must return the string that is displayed in the listbox + public override string ToString() + { + return "Linedef " + line.Index + " has an action with no activation"; + } + + // Rendering + public override void PlotSelection(IRenderer2D renderer) + { + renderer.PlotLinedef(line, General.Colors.Selection); + renderer.PlotVertex(line.Start, ColorCollection.VERTICES); + renderer.PlotVertex(line.End, ColorCollection.VERTICES); + } + + // Fix by prompting to edit the linedef + public override bool Button1Click(bool batchMode) + { + if (!batchMode) General.Map.UndoRedo.CreateUndo("Edit linedef"); + + if (General.Interface.ShowEditLinedefs(new List<Linedef> { line }) == DialogResult.OK) + { + General.Map.Map.Update(); + return true; + } + + return false; + } + #endregion + } +}