From 5ec5aeeb62fc8bad3ef3291912843bfca4aae2f6 Mon Sep 17 00:00:00 2001 From: Andre Mohren Date: Tue, 6 Nov 2018 19:47:51 +0100 Subject: [PATCH] Implemented trait defined Rollovers. --- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 ++ .../Traits/Render/SelectionDecorations.cs | 8 +++++++- .../Widgets/WorldInteractionControllerWidget.cs | 12 +++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 435c44aa43e1..abf1a57e058a 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -287,6 +287,8 @@ public interface IPips { IEnumerable GetPips(Actor self); } [RequireExplicitImplementation] public interface ISelectionBar { float GetValue(); Color GetColor(); bool DisplayWhenEmpty { get; } } + public interface ISelectionDecorations { void DrawRollover(Actor self, WorldRenderer worldRenderer); } + public interface IOccupySpaceInfo : ITraitInfoInterface { IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); diff --git a/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs b/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs index 14b06bb0b285..81b0c842c874 100644 --- a/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs +++ b/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs @@ -34,7 +34,7 @@ public class SelectionDecorationsInfo : ITraitInfo, Requires DrawDecorations(Actor self, WorldRenderer wr) yield return r; } + public void DrawRollover(Actor self, WorldRenderer worldRenderer) + { + var bounds = decorationBounds.FirstNonEmptyBounds(self, worldRenderer); + new SelectionBarsRenderable(self, bounds, true, true).Render(worldRenderer); + } + IEnumerable DrawPips(Actor self, Rectangle bounds, WorldRenderer wr) { if (pipSources.Length == 0) diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index 7d76fc8ac9c3..170b030b3c8d 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -14,7 +14,6 @@ using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Effects; -using OpenRA.Mods.Common.Graphics; using OpenRA.Orders; using OpenRA.Traits; using OpenRA.Widgets; @@ -48,12 +47,11 @@ public WorldInteractionControllerWidget(World world, WorldRenderer worldRenderer void DrawRollover(Actor unit) { - // TODO: Integrate this with SelectionDecorations to unhardcode the *Renderable - if (unit.Info.HasTraitInfo()) - { - var bounds = unit.TraitsImplementing().FirstNonEmptyBounds(unit, worldRenderer); - new SelectionBarsRenderable(unit, bounds, true, true).Render(worldRenderer); - } + var selectionDecorations = unit.TraitOrDefault(); + if (selectionDecorations == null) + return; + + selectionDecorations.DrawRollover(unit, worldRenderer); } public override void Draw()