From a6e42823e5d8de9af1a1c0b55c29a946e65e20be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 3 Jul 2016 11:32:10 +0200 Subject: [PATCH 1/4] Add WithTextDecoration. --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../Traits/Render/WithTextDecoration.cs | 133 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index aad4f5aa23..02cffa4795 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/WithTextDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs new file mode 100644 index 0000000000..b4bde0cf26 --- /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 Stances = 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.Stances.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; + } + } +} From 2b67a53f7ef0f9eba6e5c5c7526885f101f3aaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 3 Jul 2016 11:33:41 +0200 Subject: [PATCH 2/4] Remove Red Alert primary sprite font from Dune 2000. --- mods/d2k/bits/primary.shp | Bin 142 -> 0 bytes mods/d2k/rules/structures.yaml | 25 ++++++++++--------------- mods/d2k/sequences/misc.yaml | 2 -- 3 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 mods/d2k/bits/primary.shp diff --git a/mods/d2k/bits/primary.shp b/mods/d2k/bits/primary.shp deleted file mode 100644 index b997a9d136b60ca70a74146d7739f7f48d31312d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 142 zcmZQ%00AWiE-0h=44MvdCuTDUI0>*T Date: Sun, 3 Jul 2016 11:37:38 +0200 Subject: [PATCH 3/4] Remove Red Alert primary sprite font from Tiberian Sun. --- mods/ts/rules/gdi-structures.yaml | 27 ++++++++++++--------------- mods/ts/rules/nod-structures.yaml | 27 ++++++++++++--------------- mods/ts/sequences/misc.yaml | 3 --- 3 files changed, 24 insertions(+), 33 deletions(-) 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 72438f9c55..361b1fdc83 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 From 6148e8d8a3845d28d0174861fe2b11a92fb7590b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 3 Jul 2016 16:00:31 +0200 Subject: [PATCH 4/4] Rename Stances to ValidStances. --- OpenRA.Mods.Common/Traits/Render/WithDecoration.cs | 4 ++-- OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs | 4 ++-- OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) 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 index b4bde0cf26..c6d10790eb 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs @@ -40,7 +40,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; @@ -86,7 +86,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/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); }