Merge pull request #8061 from Phrohdoh/with-decoration
Implement WithDecoration and subtraits.
This commit is contained in:
@@ -627,6 +627,7 @@
|
||||
<Compile Include="Traits\Plug.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\MenuButtonsChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\LoadIngamePerfLogic.cs" />
|
||||
<Compile Include="Traits\Render\WithDecoration.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
108
OpenRA.Mods.Common/Traits/Render/WithDecoration.cs
Normal file
108
OpenRA.Mods.Common/Traits/Render/WithDecoration.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Displays a custom animation if conditions are satisfied.")]
|
||||
public class WithDecorationInfo : UpgradableTraitInfo, ITraitInfo
|
||||
{
|
||||
[Desc("Image used for this decoration. Defaults to the actor's type.")]
|
||||
public readonly string Image = null;
|
||||
|
||||
[Desc("Sequence used for this decoration (can be animated).")]
|
||||
public readonly string Sequence = null;
|
||||
|
||||
[Desc("Palette to render the sprite in. Reference the world actor's PaletteFrom* traits.")]
|
||||
public readonly string Palette = "chrome";
|
||||
|
||||
[Desc("Pixel offset relative to the top-left point of the actor's bounds.")]
|
||||
public readonly int2 Offset = int2.Zero;
|
||||
|
||||
[Desc("The Z offset to apply when rendering this decoration.")]
|
||||
public readonly int ZOffset = 1;
|
||||
|
||||
[Desc("Visual scale of the image.")]
|
||||
public readonly float Scale = 1f;
|
||||
|
||||
[Desc("Should this be visible to allied players?")]
|
||||
public readonly bool ShowToAllies = true;
|
||||
|
||||
[Desc("Should this be visible to enemy players?")]
|
||||
public readonly bool ShowToEnemies = false;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new WithDecoration(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithDecoration : UpgradableTrait<WithDecorationInfo>, IRender
|
||||
{
|
||||
readonly WithDecorationInfo info;
|
||||
readonly string image;
|
||||
readonly Animation anim;
|
||||
|
||||
public WithDecoration(Actor self, WithDecorationInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.info = info;
|
||||
image = info.Image ?? self.Info.Name;
|
||||
anim = new Animation(self.World, image);
|
||||
anim.Paused = () => self.World.Paused;
|
||||
anim.PlayRepeating(info.Sequence);
|
||||
}
|
||||
|
||||
public virtual bool ShouldRender(Actor self) { return true; }
|
||||
|
||||
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
yield break;
|
||||
|
||||
if (self.IsDead || !self.IsInWorld)
|
||||
yield break;
|
||||
|
||||
if (anim == null)
|
||||
yield break;
|
||||
|
||||
var allied = self.Owner.IsAlliedWith(self.World.RenderPlayer);
|
||||
|
||||
if (!allied && !info.ShowToEnemies)
|
||||
yield break;
|
||||
|
||||
if (allied && !info.ShowToAllies)
|
||||
yield break;
|
||||
|
||||
if (!ShouldRender(self))
|
||||
yield break;
|
||||
|
||||
if (self.World.FogObscures(self))
|
||||
yield break;
|
||||
|
||||
var pxPos = wr.ScreenPxPosition(self.CenterPosition);
|
||||
var actorBounds = self.Bounds;
|
||||
actorBounds.Offset(pxPos.X, pxPos.Y);
|
||||
pxPos = new int2(actorBounds.Left, actorBounds.Top);
|
||||
|
||||
var img = anim.Image;
|
||||
var imgSize = img.Size.ToInt2();
|
||||
pxPos = pxPos.WithX(pxPos.X + imgSize.X / 2).WithY(pxPos.Y + imgSize.Y / 2);
|
||||
|
||||
pxPos += info.Offset;
|
||||
var renderPos = wr.Position(pxPos);
|
||||
|
||||
anim.Tick();
|
||||
|
||||
yield return new SpriteRenderable(img, renderPos, WVec.Zero, info.ZOffset, wr.Palette(info.Palette), info.Scale, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,7 @@
|
||||
<Compile Include="UtilityCommands\D2kMapImporter.cs" />
|
||||
<Compile Include="UtilityCommands\ImportD2kMapCommand.cs" />
|
||||
<Compile Include="Traits\Render\WithAttackOverlay.cs" />
|
||||
<Compile Include="Traits\Render\WithDecorationCarryable.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
38
OpenRA.Mods.D2k/Traits/Render/WithDecorationCarryable.cs
Normal file
38
OpenRA.Mods.D2k/Traits/Render/WithDecorationCarryable.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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 OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
{
|
||||
[Desc("Displays a sprite when the carryable actor is waiting for pickup.")]
|
||||
public class WithDecorationCarryableInfo : WithDecorationInfo, Requires<CarryableInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new WithDecorationCarryable(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithDecorationCarryable : WithDecoration
|
||||
{
|
||||
readonly Carryable carryable;
|
||||
|
||||
public WithDecorationCarryable(Actor self, WithDecorationCarryableInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
carryable = self.Trait<Carryable>();
|
||||
}
|
||||
|
||||
public override bool ShouldRender(Actor self)
|
||||
{
|
||||
return carryable.Reserved;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,7 @@
|
||||
<Compile Include="Scripting\Properties\ParadropProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\ParatroopersProperties.cs" />
|
||||
<Compile Include="Traits\Render\WithDisguisingInfantryBody.cs" />
|
||||
<Compile Include="Traits\Render\WithDecorationDisguised.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
|
||||
42
OpenRA.Mods.RA/Traits/Render/WithDecorationDisguised.cs
Normal file
42
OpenRA.Mods.RA/Traits/Render/WithDecorationDisguised.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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 OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
public class WithDecorationDisguisedInfo : WithDecorationInfo, Requires<DisguiseInfo>
|
||||
{
|
||||
[Desc("Require an active disguise to render this decoration?")]
|
||||
public readonly bool RequireDisguise = true;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new WithDecorationDisguised(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithDecorationDisguised : WithDecoration
|
||||
{
|
||||
readonly WithDecorationDisguisedInfo info;
|
||||
readonly Disguise disguise;
|
||||
|
||||
public WithDecorationDisguised(Actor self, WithDecorationDisguisedInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
disguise = self.Trait<Disguise>();
|
||||
}
|
||||
|
||||
public override bool ShouldRender(Actor self)
|
||||
{
|
||||
return !info.RequireDisguise || disguise.Disguised;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,10 @@ harvester:
|
||||
SearchFromProcRadius: 24
|
||||
SearchFromOrderRadius: 12
|
||||
Carryable:
|
||||
WithDecorationCarryable:
|
||||
Image: pips
|
||||
Sequence: pickup-indicator
|
||||
Offset: -12, -12
|
||||
Health:
|
||||
HP: 1000
|
||||
Armor:
|
||||
|
||||
@@ -112,6 +112,8 @@ pips:
|
||||
groups: DATA.R8
|
||||
Start: 17
|
||||
Length: 10
|
||||
pickup-indicator: DATA.R8
|
||||
Start: 112
|
||||
tag-primary: DATA.R8
|
||||
Start: 110
|
||||
pip-empty: DATA.R8
|
||||
|
||||
Reference in New Issue
Block a user