Add a debug visualization for muzzle positions.
This commit is contained in:
62
OpenRA.Mods.RA/DebugMuzzlePositions.cs
Executable file
62
OpenRA.Mods.RA/DebugMuzzlePositions.cs
Executable file
@@ -0,0 +1,62 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class DebugMuzzlePositionsInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new DebugFiringOffsets(init.self); }
|
||||
}
|
||||
|
||||
public class DebugFiringOffsets : IPostRender
|
||||
{
|
||||
Lazy<IEnumerable<Armament>> armaments;
|
||||
|
||||
public DebugFiringOffsets(Actor self)
|
||||
{
|
||||
armaments = Lazy.New(() => self.TraitsImplementing<Armament>()
|
||||
.Where(a => a.Info.OffsetModel == CoordinateModel.World));
|
||||
}
|
||||
|
||||
public void RenderAfterWorld(WorldRenderer wr, Actor self)
|
||||
{
|
||||
if (self.World.LocalPlayer == null || !self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().ShowMuzzles)
|
||||
return;
|
||||
|
||||
var wlr = Game.Renderer.WorldLineRenderer;
|
||||
var c = Color.White;
|
||||
|
||||
foreach (var a in armaments.Value)
|
||||
foreach (var b in a.Barrels)
|
||||
{
|
||||
var muzzle = self.CenterPosition + a.MuzzleOffset(self, b);
|
||||
var dirOffset = new WVec(0,-224,0).Rotate(a.MuzzleOrientation(self, b));
|
||||
|
||||
var sm = wr.ScreenPosition(muzzle);
|
||||
var sd = wr.ScreenPosition(muzzle + dirOffset);
|
||||
wlr.DrawLine(sm, sd, c, c);
|
||||
wlr.DrawLine(sm + new float2(-1, -1), sm + new float2(-1, 1), c, c);
|
||||
wlr.DrawLine(sm + new float2(-1, 1), sm + new float2(1, 1), c, c);
|
||||
wlr.DrawLine(sm + new float2(1, 1), sm + new float2(1, -1), c, c);
|
||||
wlr.DrawLine(sm + new float2(1, -1), sm + new float2(-1, -1), c, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,6 +420,7 @@
|
||||
<Compile Include="FogPalette.cs" />
|
||||
<Compile Include="Infiltrates.cs" />
|
||||
<Compile Include="Armament.cs" />
|
||||
<Compile Include="DebugMuzzlePositions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
fastChargeCheckbox.IsChecked = () => devTrait.FastCharge;
|
||||
fastChargeCheckbox.OnClick = () => Order(world, "DevFastCharge");
|
||||
|
||||
var showMuzzlesCheckbox = widget.Get<CheckboxWidget>("SHOW_MUZZLES");
|
||||
showMuzzlesCheckbox.IsChecked = () => devTrait.ShowMuzzles;
|
||||
showMuzzlesCheckbox.OnClick = () => devTrait.ShowMuzzles ^= true;
|
||||
|
||||
var allTechCheckbox = widget.Get<CheckboxWidget>("ENABLE_TECH");
|
||||
allTechCheckbox.IsChecked = () => devTrait.AllTech;
|
||||
allTechCheckbox.OnClick = () => Order(world, "DevEnableTech");
|
||||
|
||||
Reference in New Issue
Block a user