From 9b6e15ea7803062bd4a68bf13d523c30b0f51a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 1 May 2016 15:47:13 +0200 Subject: [PATCH] Add a CustomTerrain debug overlay. --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../Render/CustomTerrainDebugOverlay.cs | 79 +++++++++++++++++++ .../Widgets/Logic/Ingame/DebugMenuLogic.cs | 12 +++ mods/cnc/chrome/ingame-debug.yaml | 7 ++ mods/cnc/chrome/ingame-info.yaml | 2 +- mods/cnc/rules/world.yaml | 1 + mods/d2k/rules/world.yaml | 1 + mods/ra/chrome/ingame-debug.yaml | 7 ++ mods/ra/chrome/ingame-info.yaml | 2 +- mods/ra/rules/world.yaml | 1 + mods/ts/chrome/ingame-debug.yaml | 7 ++ mods/ts/rules/world.yaml | 1 + 12 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 OpenRA.Mods.Common/Traits/Render/CustomTerrainDebugOverlay.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 1df8f64e23..13c38beea1 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -405,6 +405,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Render/CustomTerrainDebugOverlay.cs b/OpenRA.Mods.Common/Traits/Render/CustomTerrainDebugOverlay.cs new file mode 100644 index 0000000000..45ec70d906 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Render/CustomTerrainDebugOverlay.cs @@ -0,0 +1,79 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 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 System.Drawing; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Commands; +using OpenRA.Mods.Common.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Displays custom terrain types.")] + class CustomTerrainDebugOverlayInfo : ITraitInfo + { + public readonly string Font = "TinyBold"; + + public object Create(ActorInitializer init) { return new CustomTerrainDebugOverlay(init.Self, this); } + } + + class CustomTerrainDebugOverlay : IWorldLoaded, IChatCommand, IRender + { + const string CommandName = "debugcustomterrain"; + const string CommandDesc = "Toggles the custom terrain debug overlay."; + + public bool Enabled; + + readonly SpriteFont font; + + public CustomTerrainDebugOverlay(Actor self, CustomTerrainDebugOverlayInfo info) + { + font = Game.Renderer.Fonts[info.Font]; + } + + 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 IRender.Render(Actor self, WorldRenderer wr) + { + if (!Enabled) + yield break; + + foreach (var uv in wr.Viewport.VisibleCellsInsideBounds.CandidateMapCoords) + { + var cell = uv.ToCPos(wr.World.Map); + var center = wr.World.Map.CenterOfCell(cell); + var terrainType = self.World.Map.CustomTerrain[cell]; + if (terrainType == byte.MaxValue) + continue; + + var info = wr.World.Map.GetTerrainInfo(cell); + yield return new TextRenderable(font, center, 0, info.Color, info.Type); + } + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs index 62808fb2bb..0498b5fe70 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs @@ -134,6 +134,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic showActorTagsCheckbox.IsChecked = () => devTrait.ShowActorTags; showActorTagsCheckbox.OnClick = () => devTrait.ShowActorTags ^= true; } + + var showCustomTerrainCheckbox = widget.GetOrNull("SHOW_CUSTOMTERRAIN_OVERLAY"); + if (showCustomTerrainCheckbox != null) + { + var customTerrainDebugTrait = world.WorldActor.TraitOrDefault(); + showCustomTerrainCheckbox.Disabled = customTerrainDebugTrait == null; + if (customTerrainDebugTrait != null) + { + showCustomTerrainCheckbox.IsChecked = () => customTerrainDebugTrait.Enabled; + showCustomTerrainCheckbox.OnClick = () => customTerrainDebugTrait.Enabled ^= true; + } + } } public void Order(World world, string order) diff --git a/mods/cnc/chrome/ingame-debug.yaml b/mods/cnc/chrome/ingame-debug.yaml index 81e2dd07b8..e7885236c0 100644 --- a/mods/cnc/chrome/ingame-debug.yaml +++ b/mods/cnc/chrome/ingame-debug.yaml @@ -123,3 +123,10 @@ Container@DEBUG_PANEL: Width: 200 Font: Regular Text: Show Actor Tags + Checkbox@SHOW_CUSTOMTERRAIN_OVERLAY: + X: 290 + Y: 365 + Height: 20 + Width: 200 + Font: Regular + Text: Show Custom Terrain diff --git a/mods/cnc/chrome/ingame-info.yaml b/mods/cnc/chrome/ingame-info.yaml index 24299c750f..e664f3debf 100644 --- a/mods/cnc/chrome/ingame-info.yaml +++ b/mods/cnc/chrome/ingame-info.yaml @@ -2,7 +2,7 @@ Container@GAME_INFO_PANEL: X: (WINDOW_RIGHT - WIDTH) / 2 Y: (WINDOW_BOTTOM - HEIGHT) / 2 Width: 512 - Height: 375 + Height: 405 Logic: GameInfoLogic Visible: False Children: diff --git a/mods/cnc/rules/world.yaml b/mods/cnc/rules/world.yaml index e2a00fcc76..11bd49f3e2 100644 --- a/mods/cnc/rules/world.yaml +++ b/mods/cnc/rules/world.yaml @@ -72,6 +72,7 @@ World: ResourceClaimLayer: PathfinderDebugOverlay: WarheadDebugOverlay: + CustomTerrainDebugOverlay: MapCreeps: SpawnMapActors: MapBuildRadius: diff --git a/mods/d2k/rules/world.yaml b/mods/d2k/rules/world.yaml index 2e37e11d88..190c715e4e 100644 --- a/mods/d2k/rules/world.yaml +++ b/mods/d2k/rules/world.yaml @@ -79,6 +79,7 @@ World: BuildableTerrainLayer: D2kResourceLayer: ResourceClaimLayer: + CustomTerrainDebugOverlay: SmudgeLayer@Rock: Type: RockCrater Sequence: rockcraters diff --git a/mods/ra/chrome/ingame-debug.yaml b/mods/ra/chrome/ingame-debug.yaml index a8050e2031..647ca36cf9 100644 --- a/mods/ra/chrome/ingame-debug.yaml +++ b/mods/ra/chrome/ingame-debug.yaml @@ -128,3 +128,10 @@ Container@DEBUG_PANEL: Width: 200 Font: Regular Text: Show Actor Tags + Checkbox@SHOW_CUSTOMTERRAIN_OVERLAY: + X: 290 + Y: 365 + Height: 20 + Width: 200 + Font: Regular + Text: Show Custom Terrain diff --git a/mods/ra/chrome/ingame-info.yaml b/mods/ra/chrome/ingame-info.yaml index ffe21675d0..8a31c2a537 100644 --- a/mods/ra/chrome/ingame-info.yaml +++ b/mods/ra/chrome/ingame-info.yaml @@ -2,7 +2,7 @@ Container@GAME_INFO_PANEL: X: (WINDOW_RIGHT - WIDTH) / 2 Y: (WINDOW_BOTTOM - HEIGHT) / 2 Width: 522 - Height: 455 + Height: 485 Logic: GameInfoLogic Visible: False Children: diff --git a/mods/ra/rules/world.yaml b/mods/ra/rules/world.yaml index 41cc39316e..9a4ddb5acf 100644 --- a/mods/ra/rules/world.yaml +++ b/mods/ra/rules/world.yaml @@ -99,6 +99,7 @@ World: ProductionPaletteWidget: PRODUCTION_PALETTE BridgeLayer: Bridges: bridge1, bridge2, br1, br2, br3, sbridge1, sbridge2, sbridge3, sbridge4 + CustomTerrainDebugOverlay: CrateSpawner: DeliveryAircraft: badr QuantizedFacings: 16 diff --git a/mods/ts/chrome/ingame-debug.yaml b/mods/ts/chrome/ingame-debug.yaml index 7cc5150341..96a2bc5e9c 100644 --- a/mods/ts/chrome/ingame-debug.yaml +++ b/mods/ts/chrome/ingame-debug.yaml @@ -135,3 +135,10 @@ Container@DEBUG_PANEL: Width: 200 Font: Regular Text: Show Actor Tags + Checkbox@SHOW_CUSTOMTERRAIN_OVERLAY: + X: 290 + Y: 365 + Height: 20 + Width: 200 + Font: Regular + Text: Show Custom Terrain diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index a191b9d10e..a4b22ab0fe 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -94,6 +94,7 @@ World: SmokeType: largesmoke Sequence: largecraters ResourceLayer: + CustomTerrainDebugOverlay: ResourceClaimLayer: PathfinderDebugOverlay: WarheadDebugOverlay: