diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index e3ce297206..2202642a6d 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -216,6 +216,7 @@ namespace OpenRA.Traits void AddInfluence(Actor self, IOccupySpace ios); void RemoveInfluence(Actor self, IOccupySpace ios); int AddCellTrigger(CPos[] cells, Action onEntry, Action onExit); + IEnumerable TriggerPositions(); void RemoveCellTrigger(int id); int AddProximityTrigger(WPos pos, WDist range, WDist vRange, Action onEntry, Action onExit); void RemoveProximityTrigger(int id); diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index 616ffa32b8..1ae690ebfa 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -522,6 +522,11 @@ namespace OpenRA.Mods.Common.Traits return id; } + public IEnumerable TriggerPositions() + { + return cellTriggerInfluence.Keys; + } + public void RemoveCellTrigger(int id) { if (!cellTriggers.TryGetValue(id, out var trigger)) diff --git a/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs b/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs new file mode 100644 index 0000000000..c25f6e5950 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs @@ -0,0 +1,89 @@ +#region Copyright & License Information +/* + * Copyright 2007-2022 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Commands; +using OpenRA.Mods.Common.Graphics; +using OpenRA.Primitives; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [TraitLocation(SystemActors.World)] + [Desc("Renders a debug overlay showing the script triggers. Attach this to the world actor.")] + public class CellTriggerOverlayInfo : TraitInfo + { + public readonly string Font = "BigBold"; + + public readonly Color Color = Color.Red; + + public override object Create(ActorInitializer init) { return new CellTriggerOverlay(this); } + } + + public class CellTriggerOverlay : IRenderAnnotations, IWorldLoaded, IChatCommand + { + const string CommandName = "triggers"; + const string CommandDesc = "toggles the script triggers overlay."; + + bool enabled; + + readonly SpriteFont font; + readonly Color color; + + public CellTriggerOverlay(CellTriggerOverlayInfo info) + { + font = Game.Renderer.Fonts[info.Font]; + color = info.Color; + } + + void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr) + { + var console = w.WorldActor.TraitOrDefault(); + var help = w.WorldActor.TraitOrDefault(); + + if (console == null || help == null) + return; + + console.RegisterCommand(CommandName, this); + help.RegisterHelp(CommandName, CommandDesc); + } + + void IChatCommand.InvokeCommand(string name, string arg) + { + if (name == CommandName) + enabled ^= true; + } + + IEnumerable IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr) + { + if (!enabled) + yield break; + + var triggerPositions = wr.World.ActorMap.TriggerPositions().ToHashSet(); + + foreach (var uv in wr.Viewport.VisibleCellsInsideBounds.CandidateMapCoords) + { + if (self.World.ShroudObscures(uv)) + continue; + + var cell = uv.ToCPos(wr.World.Map); + if (!triggerPositions.Contains(cell)) + continue; + + var center = wr.World.Map.CenterOfCell(cell); + yield return new TextAnnotationRenderable(font, center, 1024, color, "T"); + } + } + + bool IRenderAnnotations.SpatiallyPartitionable => false; + } +} diff --git a/mods/cnc/rules/world.yaml b/mods/cnc/rules/world.yaml index a54dd997ed..61699bcee3 100644 --- a/mods/cnc/rules/world.yaml +++ b/mods/cnc/rules/world.yaml @@ -264,6 +264,7 @@ World: LoadWidgetAtGameStart: ShellmapRoot: MENU_BACKGROUND ScriptTriggers: + CellTriggerOverlay: TimeLimitManager: ColorPickerManager: PreviewActor: fact.colorpicker diff --git a/mods/d2k/rules/world.yaml b/mods/d2k/rules/world.yaml index c9e27c3e2a..ebe873cdff 100644 --- a/mods/d2k/rules/world.yaml +++ b/mods/d2k/rules/world.yaml @@ -234,6 +234,7 @@ World: PanelName: SKIRMISH_STATS LoadWidgetAtGameStart: ScriptTriggers: + CellTriggerOverlay: StartGameNotification: TimeLimitManager: ColorPickerManager: diff --git a/mods/ra/rules/world.yaml b/mods/ra/rules/world.yaml index 4706ba683a..192c236ce0 100644 --- a/mods/ra/rules/world.yaml +++ b/mods/ra/rules/world.yaml @@ -275,6 +275,7 @@ World: PanelName: SKIRMISH_STATS LoadWidgetAtGameStart: ScriptTriggers: + CellTriggerOverlay: TimeLimitManager: TimeLimitWarnings: 40: FourtyMinutesRemaining diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index e27d4fbdc9..ccc64bded8 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -380,6 +380,7 @@ World: LoadWidgetAtGameStart: ShellmapRoot: MAINMENU_PRERELEASE_NOTIFICATION ScriptTriggers: + CellTriggerOverlay: TimeLimitManager: ColorPickerManager: PreviewActor: harv.colorpicker