diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index b38db302fa..0731e10ace 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -439,6 +439,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs index 016700e0ad..6a496a3374 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly int ZOffset = 1; [Desc("Player stances who can view the decoration.")] - public readonly Stance Stances = Stance.Ally; + public readonly Stance ValidStances = Stance.Ally; [Desc("Should this be visible only when selected?")] public readonly bool RequiresSelection = false; @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits.Render if (self.World.RenderPlayer != null) { var stance = self.Owner.Stances[self.World.RenderPlayer]; - if (!Info.Stances.HasStance(stance)) + if (!Info.ValidStances.HasStance(stance)) return Enumerable.Empty(); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs new file mode 100644 index 0000000000..c6d10790eb --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs @@ -0,0 +1,133 @@ +#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; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits.Render +{ + [Desc("Displays a text overlay relative to the selection box.")] + public class WithTextDecorationInfo : UpgradableTraitInfo + { + [FieldLoader.Require] [Translate] public readonly string Text = null; + + public readonly string Font = "TinyBold"; + + [Desc("Display in this color when not using the player color.")] + public readonly Color Color = Color.White; + + [Desc("Use the player color of the current owner.")] + public readonly bool UsePlayerColor = false; + + [Desc("Point in the actor's selection box used as reference for offsetting the decoration image. " + + "Possible values are combinations of Center, Top, Bottom, Left, Right.")] + public readonly ReferencePoints ReferencePoint = ReferencePoints.Top | ReferencePoints.Left; + + [Desc("The Z offset to apply when rendering this decoration.")] + public readonly int ZOffset = 1; + + [Desc("Player stances who can view the decoration.")] + public readonly Stance ValidStances = Stance.Ally; + + [Desc("Should this be visible only when selected?")] + public readonly bool RequiresSelection = false; + + public override object Create(ActorInitializer init) { return new WithTextDecoration(init.Self, this); } + } + + public class WithTextDecoration : UpgradableTrait, IRender, IPostRenderSelection, INotifyCapture + { + readonly Actor self; + readonly SpriteFont font; + + Color color; + + public WithTextDecoration(Actor self, WithTextDecorationInfo info) + : base(info) + { + this.self = self; + + if (!Game.Renderer.Fonts.TryGetValue(info.Font, out font)) + throw new YamlException("Could not find font '{0}'".F(info.Font)); + + color = Info.UsePlayerColor ? self.Owner.Color.RGB : Info.Color; + } + + public virtual bool ShouldRender(Actor self) { return true; } + + public IEnumerable Render(Actor self, WorldRenderer wr) + { + return !Info.RequiresSelection ? RenderInner(self, wr) : Enumerable.Empty(); + } + + public IEnumerable RenderAfterWorld(WorldRenderer wr) + { + return Info.RequiresSelection ? RenderInner(self, wr) : Enumerable.Empty(); + } + + IEnumerable RenderInner(Actor self, WorldRenderer wr) + { + if (IsTraitDisabled || self.IsDead || !self.IsInWorld) + return Enumerable.Empty(); + + if (self.World.RenderPlayer != null) + { + var stance = self.Owner.Stances[self.World.RenderPlayer]; + if (!Info.ValidStances.HasStance(stance)) + return Enumerable.Empty(); + } + + if (!ShouldRender(self) || self.World.FogObscures(self)) + return Enumerable.Empty(); + + var bounds = self.VisualBounds; + var halfSize = font.Measure(Info.Text) / 2; + + var boundsOffset = new int2(bounds.Left + bounds.Right, bounds.Top + bounds.Bottom) / 2; + var sizeOffset = new int2(); + if (Info.ReferencePoint.HasFlag(ReferencePoints.Top)) + { + boundsOffset -= new int2(0, bounds.Height / 2); + sizeOffset += new int2(0, halfSize.Y); + } + else if (Info.ReferencePoint.HasFlag(ReferencePoints.Bottom)) + { + boundsOffset += new int2(0, bounds.Height / 2); + sizeOffset -= new int2(0, halfSize.Y); + } + + if (Info.ReferencePoint.HasFlag(ReferencePoints.Left)) + { + boundsOffset -= new int2(bounds.Width / 2, 0); + sizeOffset += new int2(halfSize.X, 0); + } + else if (Info.ReferencePoint.HasFlag(ReferencePoints.Right)) + { + boundsOffset += new int2(bounds.Width / 2, 0); + sizeOffset -= new int2(halfSize.X, 0); + } + + var screenPos = wr.ScreenPxPosition(self.CenterPosition) + boundsOffset + sizeOffset; + return new IRenderable[] { new TextRenderable(font, wr.ProjectedPosition(screenPos), Info.ZOffset, color, Info.Text) }; + } + + void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) + { + if (Info.UsePlayerColor) + color = newOwner.Color.RGB; + } + } +} diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 5678ecb606..48aebb832f 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -212,6 +212,16 @@ namespace OpenRA.Mods.Common.UtilityCommands } } + if (engineVersion < 20160703) + { + if (node.Key.StartsWith("WithDecoration") || node.Key.StartsWith("WithRankDecoration") || node.Key.StartsWith("WithDecorationCarryable")) + { + var stancesNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Stances"); + if (stancesNode != null) + stancesNode.Key = "ValidStances"; + } + } + UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); } diff --git a/mods/d2k/bits/primary.shp b/mods/d2k/bits/primary.shp deleted file mode 100644 index b997a9d136..0000000000 Binary files a/mods/d2k/bits/primary.shp and /dev/null differ diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 2b88b6d041..9de2511fdb 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -97,10 +97,9 @@ construction_yard: ZOffset: 256 UpgradeTypes: stardecoration UpgradeMinEnabledLevel: 1 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary + Text: PRIMARY ReferencePoint: Top ZOffset: 256 UpgradeTypes: primary @@ -212,10 +211,9 @@ barracks: ZOffset: 256 UpgradeTypes: stardecoration UpgradeMinEnabledLevel: 1 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary + Text: PRIMARY ReferencePoint: Top ZOffset: 256 UpgradeTypes: primary @@ -394,10 +392,9 @@ light_factory: ZOffset: 256 UpgradeTypes: stardecoration UpgradeMinEnabledLevel: 1 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary + Text: PRIMARY ReferencePoint: Top ZOffset: 256 UpgradeTypes: primary @@ -476,10 +473,9 @@ heavy_factory: ZOffset: 256 UpgradeTypes: stardecoration UpgradeMinEnabledLevel: 1 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary + Text: PRIMARY ReferencePoint: Top ZOffset: 256 UpgradeTypes: primary @@ -593,10 +589,9 @@ starport: Power: Amount: -150 ProvidesPrerequisite@buildingname: - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary + Text: PRIMARY ReferencePoint: Top ZOffset: 256 UpgradeTypes: primary diff --git a/mods/d2k/sequences/misc.yaml b/mods/d2k/sequences/misc.yaml index 84a8854d1e..0aa57f9730 100644 --- a/mods/d2k/sequences/misc.yaml +++ b/mods/d2k/sequences/misc.yaml @@ -126,8 +126,6 @@ pips: Length: 10 pickup-indicator: DATA.R8 Start: 112 - tag-primary: primary.shp - Offset: 0, 2 pip-empty: DATA.R8 Start: 15 pip-green: DATA.R8 diff --git a/mods/ts/rules/gdi-structures.yaml b/mods/ts/rules/gdi-structures.yaml index 94fcc3e01a..ac9749791b 100644 --- a/mods/ts/rules/gdi-structures.yaml +++ b/mods/ts/rules/gdi-structures.yaml @@ -109,12 +109,11 @@ GAPILE: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 88, 56, 0, -8 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary - Palette: pips - ReferencePoint: Center + Text: PRIMARY + ReferencePoint: Top + Color: E0D048 ZOffset: 256 UpgradeTypes: primary UpgradeMinEnabledLevel: 1 @@ -171,12 +170,11 @@ GAWEAP: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 154, 100, -2, -12 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary - Palette: pips - ReferencePoint: Center + Text: PRIMARY + ReferencePoint: Top + Color: E0D048 ZOffset: 256 UpgradeTypes: primary UpgradeMinEnabledLevel: 1 @@ -224,12 +222,11 @@ GAHPAD: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 88, 66, 0, -5 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary - Palette: pips - ReferencePoint: Center + Text: PRIMARY + ReferencePoint: Top + Color: E0D048 ZOffset: 256 UpgradeTypes: primary UpgradeMinEnabledLevel: 1 diff --git a/mods/ts/rules/nod-structures.yaml b/mods/ts/rules/nod-structures.yaml index e3eff83574..e86c58e768 100644 --- a/mods/ts/rules/nod-structures.yaml +++ b/mods/ts/rules/nod-structures.yaml @@ -118,12 +118,11 @@ NAHAND: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 116, 78, 3, -8 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary - Palette: pips - ReferencePoint: Center + Text: PRIMARY + ReferencePoint: Top + Color: E0D048 ZOffset: 256 UpgradeTypes: primary UpgradeMinEnabledLevel: 1 @@ -176,12 +175,11 @@ NAWEAP: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 149, 116, -3, -20 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary - Palette: pips - ReferencePoint: Center + Text: PRIMARY + ReferencePoint: Top + Color: E0D048 ZOffset: 256 UpgradeTypes: primary UpgradeMinEnabledLevel: 1 @@ -229,12 +227,11 @@ NAHPAD: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 78, 54, 0, -8 - WithDecoration@primary: + WithTextDecoration@primary: RequiresSelection: true - Image: pips - Sequence: tag-primary - Palette: pips - ReferencePoint: Center + Text: PRIMARY + ReferencePoint: Top + Color: E0D048 ZOffset: 256 UpgradeTypes: primary UpgradeMinEnabledLevel: 1 diff --git a/mods/ts/sequences/misc.yaml b/mods/ts/sequences/misc.yaml index 324d14058c..a96d89845e 100644 --- a/mods/ts/sequences/misc.yaml +++ b/mods/ts/sequences/misc.yaml @@ -90,9 +90,6 @@ pips: groups: pipsra #TODO: backfall to RA asset Start: 8 Length: 10 - tag-primary: pipsra #TODO: backfall to RA asset - Start: 2 - Offset: 0, 2 pip-empty: pips2 pip-green: pips2 Start: 1